fix: clean dist/ before build:ts in TypeScript template#883
Open
winnrz wants to merge 1 commit intofastify:mainfrom
Open
fix: clean dist/ before build:ts in TypeScript template#883winnrz wants to merge 1 commit intofastify:mainfrom
winnrz wants to merge 1 commit intofastify:mainfrom
Conversation
Prevents stale compiled files from being served by @fastify/autoload after a source file is deleted from routes/ or plugins/. The dist/ directory is now removed before tsc runs. Also fixes a minor typo in logInstructions where 'npm build:ts' should have been 'npm run build:ts', and adds a log line for the new clean script. Closes fastify#878
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a
cleanscript to the generated TypeScript template and runs it beforetscinbuild:ts, so stale compiled files are removed on every build.Why
Closes #878. Without this, deleting a file from
routes/orplugins/leaves a stale.jsindist/, which@fastify/autoloadcontinues to serve — giving the misleading impression that the deletion had no effect. This is a non-obvious debugging problem for developers new to Fastify.Changes
cleanscript using inlinenode -e(no new dependency, cross-platform)build:tsto runcleanfirstlogInstructionsentry forcleanso it's discoverablelogInstructions:npm build:ts→npm run build:tsThe ESM TypeScript template inherits from
typescriptTemplatevia spread incli(), so both--lang=tsand--lang=ts --esmpick up the change.Verification
Stale file removal on a generated project:
Tests pass locally:
npm testpasses end-to-endnpm run unit:ts-cjs✓npm run unit:ts-esm✓On Node 20 the template test suites are auto-skipped by the repo's
should-skip-test-suites.js, but I ranunit:ts-cjsandunit:ts-esmdirectly and both pass.Note
npm run build:tscurrently fails on a freshly generated project due to an unrelatedTS5011rootDir error, which reproduces onmainwithout this change. This PR does not affect that behavior — thecleanstep completes successfully beforetscis invoked.Alternatives considered
rimraf: adds a dependency for what's essentially a one-linertsc --build --clean: requires incremental/project-reference builds, which the current template doesn't useChecklist
npm run test && npm run benchmark --if-present