Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] npx projen build doesn't remove corresponding files in packages/api/handlers/typescript/test (and other files, see detailed issue) #779

Closed
teddyaryono opened this issue May 7, 2024 · 3 comments
Labels
bug Something isn't working needs-triage stale

Comments

@teddyaryono
Copy link

teddyaryono commented May 7, 2024

Describe the bug

I followed the getting started guide to build a shopping list application.

Ran npx projen build to build. Build failed because of failed test.

Expected Behavior

pdk to version and remove corresponding unused test and other files (see current behaviour).

Current Behavior

pdk left some un-used files in packages/api/handlers/typescript/test and packages/api/handlers/typescript/lib. Users need to handpick and remove leftover files manually.

Reproduction Steps

  1. Follow a getting started guide here to build a shopping list application.
  2. Add 5 files: types/shopping-list.smithy, types/pagination.smithy, operations/put-shopping-list.smithy, operations/delete-shopping-list.smithy, operations/get-shopping-list.smithy.
  3. Update main.smithy to include GetShoppingLists, PutShoppingList, DeleteShoppingList.
  4. Remove packages/api/model/src/main/smithy/operations/say-hello.smithy and packages/api/handlers/typescript/src/say-hello.ts
  5. Run npx projen build
  6. Build failed with the following error:
myapi-typescript-handlers: 👾 build » compile | tsc --build
myapi-typescript-handlers: 👾 build » test | jest --passWithNoTests --updateSnapshot
myapi-typescript-handlers:  FAIL  test/say-hello.test.ts
myapi-typescript-handlers:   ● Test suite failed to run
myapi-typescript-handlers:     test/say-hello.test.ts:3:3 - error TS2724: '"myapi-typescript-runtime"' has no exported member named 'SayHelloChainedRequestInput'. Did you mean 'ChainedRequestInput'?
myapi-typescript-handlers:     3   SayHelloChainedRequestInput,
myapi-typescript-handlers:         ~~~~~~~~~~~~~~~~~~~~~~~~~~~
myapi-typescript-handlers:     test/say-hello.test.ts:5:26 - error TS2307: Cannot find module '../src/say-hello' or its corresponding type declarations.
myapi-typescript-handlers:     5 import { sayHello } from "../src/say-hello";
myapi-typescript-handlers:                                ~~~~~~~~~~~~~~~~~~
myapi-typescript-handlers:  PASS  test/delete-shopping-list.test.ts
myapi-typescript-handlers:  PASS  test/get-shopping-lists.test.ts
myapi-typescript-handlers:  PASS  test/put-shopping-list.test.ts
myapi-typescript-handlers: -------------------------|---------|----------|---------|---------|-------------------
myapi-typescript-handlers: File                     | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
myapi-typescript-handlers: -------------------------|---------|----------|---------|---------|-------------------
myapi-typescript-handlers: All files                |     100 |      100 |     100 |     100 |                   
myapi-typescript-handlers:  delete-shopping-list.ts |     100 |      100 |     100 |     100 |                   
myapi-typescript-handlers:  get-shopping-lists.ts   |     100 |      100 |     100 |     100 |                   
myapi-typescript-handlers:  put-shopping-list.ts    |     100 |      100 |     100 |     100 |                   
myapi-typescript-handlers: -------------------------|---------|----------|---------|---------|-------------------
myapi-typescript-handlers: Test Suites: 1 failed, 3 passed, 4 total
myapi-typescript-handlers: Tests:       3 passed, 3 total
myapi-typescript-handlers: Snapshots:   0 total
myapi-typescript-handlers: Time:        1.729 s, estimated 2 s
myapi-typescript-handlers: Ran all test suites.
myapi-typescript-handlers: 👾 Task "build » test" failed when executing "jest --passWithNoTests --updateSnapshot" (cwd: /Users/taryono/Code/projects/prototyping-sandbox/transurban-v2/packages/api/handlers/typescript)
myapi-typescript-handlers: Warning: run-commands command "pnpm exec projen build" exited with non-zero status code

 ———————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

 >  NX   Running target build for 9 projects failed

   Tasks not run because their dependencies failed or --nx-bail=true:
   
   - infra:build
   
   Failed tasks:
   
   - myapi-typescript-handlers:build

👾 Task "build" failed when executing "pnpm exec nx run-many --target=build --output-style=stream --nx-bail" (cwd: /Users/taryono/Code/projects/prototyping-sandbox/transurban-v2)

Possible Solution

No response

Additional Information/Context

No response

PDK version used

0.23.37

What languages are you seeing this issue on?

Typescript

Environment details (OS name and version, etc.)

Apple M1 Pro, MacOS Sonoma 14.4.1

@teddyaryono teddyaryono added bug Something isn't working needs-triage labels May 7, 2024
@teddyaryono teddyaryono changed the title [BUG] npx projen build doesn't remove corresponding files in packages/api/handlers/typescript/test [BUG] npx projen build doesn't remove corresponding files in packages/api/handlers/typescript/test (and other files, see detailed issue) May 7, 2024
Copy link

github-actions bot commented Jul 8, 2024

This issue is now marked as stale because it hasn't seen activity for a while. Add a comment or it will be closed soon. If you wish to exclude this issue from being marked as stale, add the "backlog" label.

@github-actions github-actions bot added the stale label Jul 8, 2024
Copy link

Closing this issue as it hasn't seen activity for a while. Please add a comment @mentioning a maintainer to reopen. If you wish to exclude this issue from being marked as stale, add the "backlog" label.

@cogwirrel
Copy link
Member

Hey Teddy!

Sorry for the slow response on this one - I'm now back from leave!

The handlers and tests are generated the first time you add an operation, but after that they're managed by you - therefore we don't want to delete anything if you change your API, just in case there's code in there you want to keep! I could potentially see it being ok to delete a handler/test file for an operation if it matches what we would have generated, but it gets quite complicated to implement as we'd likely need to keep some kind of state to remember old operations that were deleted... So I'm going to leave this closed for now.

The files in packages/api/handlers/typescript/lib are build output so they should hopefully disappear if you delete your unused handler and rebuild!

Hope this helps!

Cheers,
Jack

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-triage stale
Projects
None yet
Development

No branches or pull requests

2 participants