aws/aws-pdk

[BUG] typesafe-api code generation script doesn't handle spaces in the directory path

julianpitt opened this issue · 2 comments

Describe the bug

Running pnpm build in a directory that contains spaces in the path will cause the typesafe-api generate task to fail.

Expected Behavior

@redacted/api-model: 👾 build » compile » generate | npx --yes -p @aws/pdk@$AWS_PDK_VERSION type-safe-api.parse-openapi-spec --spec-path build/smithyprojections/@redacted-api-model/openapi/openapi/api.openapi.json --output-path .api.json --smithy-json-path build/smithyprojections/@redacted-api-model/openapi/model/model.json
@redacted/api-model: package manager :: pnpm
@redacted/api-model: parse-openapi-spec :: tmp_dir :: /var/folders/xk/wd42j4dj3w58p0n9bzsf3th00000gs/T/parse-openapi-spec.ej1C8Q8uZ
@redacted/api-model: installing packages :: typescript@5.0.4 @types/node@20.1.5 ts-node@10.9.1 ts-command-line-args@2.4.2 @redocly/cli@1.0.0-beta.126 reregexp@1.6.1 @faker-js/faker@8.1.0 @openapitools/openapi-generator-cli@2.6.0 lodash@4.17.21 @types/lodash@4.14.197 @apidevtools/swagger-parser@10.1.0 openapi-types@12.1.0 projen@0.73.8
@redacted/api-model: running command pnpm exec ts-node parse-openapi-spec.ts --specPath=/Users/myusername/Repos/prototyping/aws-anz-redacted/packages/api/model/build/smithyprojections/@redacted-api-model/openapi/openapi/api.openapi.json --outputPath=/Users/myusername/Repos/prototyping/aws-anz-redacted/packages/api/model/.api.json --smithyJsonPath=/Users/myusername/Repos/prototyping/aws-anz-redacted/packages/api/model/build/smithyprojections/@redacted-api-model/openapi/model/model.json
@redacted/api-model: openapi-spec parsed

The previous output is from a project without a space in the directory, the openapi file is parsed correctly and the build continues.

Current Behavior

The following terminal output occurs when there is a space in the directory name. Then the build fails

@redacted/api-model: 👾 build » compile » generate | npx --yes -p @aws/pdk@$AWS_PDK_VERSION type-safe-api.parse-openapi-spec --spec-path build/smithyprojections/@redacted-api-model/openapi/openapi/api.openapi.json --output-path .api.json --smithy-json-path build/smithyprojections/@redacted-api-model/openapi/model/model.json
@redacted/api-model: /Users/myusername/Downloads/PROTOTYPE CODE/redactedcode/node_modules/.bin/../@aws/pdk/scripts/type-safe-api/parser/parse-openapi-spec: line 19: /Users/myusername/Downloads/PROTOTYPE CODE/redactedcode/packages/api/model/../common/common.sh: No such file or directory
@redacted/api-model: 👾 Task "build » compile » generate" failed when executing "npx --yes -p @aws/pdk@$AWS_PDK_VERSION type-safe-api.parse-openapi-spec --spec-path build/smithyprojections/@redacted-api-model/openapi/openapi/api.openapi.json --output-path .api.json --smithy-json-path build/smithyprojections/@redacted-api-model/openapi/model/model.json" (cwd: /Users/myusername/Downloads/PROTOTYPE CODE/redactedcode/packages/api/model)
@redacted/api-model: Warning: run-commands command "pnpm dlx projen build" exited with non-zero status code

Reproduction Steps

  1. Create a new project in a directory that contains a space in the directory name
  2. Run pnpm build

Possible Solution

The generate task parsing script may have an error at the following line or above

script_dir="$( cd -- "$(dirname $([ -L "${BASH_SOURCE[0]:-$0}" ] && readlink -f "${BASH_SOURCE[0]:-$0}" || echo "${BASH_SOURCE[0]:-$0}"))" >/dev/null 2>&1 ; pwd -P )";

Additional Information/Context

No response

PDK version used

0.23.16

What languages are you seeing this issue on?

No response

Environment details (OS name and version, etc.)

MacOS 14.5, OpenJDK Runtime Environment Corretto-17.0.11.9.1, pnpm 8.15.8, (build 17.0.11+9-LTS), npm 10.7.0, node 18.20.3