-
-
Notifications
You must be signed in to change notification settings - Fork 173
Add clean step to generated build:ts script to remove stale compiled routes #878
Description
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the feature has not already been requested
🚀 Feature Proposal
When using fastify generate with --lang=ts, the generated build:ts script does not clean the dist/ directory before compiling.
This means that if you delete a route file from routes/ or a plugin file from plugins/, the compiled .js file remains in dist/ and continues to be served by @fastify/autoload — even though the source file no longer exists.
Suggested Fix
Adding a dedicated clean script and using it in build:ts would prevent stale compiled files from being served:
"scripts": {
"clean": "node -e \"require('fs').rmSync('dist', {recursive:true,force:true})\"",
"build:ts": "npm run clean && tsc",
}This would make the generated template behave more intuitively out of the box, particularly for developers new to the framework who may not be aware of how tsc handles its output directory.
Motivation
The fastify generate command is designed to get developers up and running quickly. The generated template should behave intuitively out of the box, especially for developers new to the framework.
Without a clean step, deleting a file from routes/ or plugins/ gives the misleading impression that the change has had no effect — the endpoint or plugin continues to work as if the file still exists. This can cause significant confusion during development and is a non-obvious debugging problem for those unfamiliar with how tsc manages its output directory.
Many popular CLI scaffolding tools include a clean step in their generated build scripts for exactly this reason.
Example
After running fastify generate myapp --lang=ts, the generated package.json would include:
"scripts": {
"clean": "node -e \"require('fs').rmSync('dist', {recursive:true,force:true})\"",
"build:ts": "npm run clean && tsc",
}This ensures that when a developer deletes a route or plugin file, it is no longer present in dist/ after the next build, and will not be served by @fastify/autoload.