Can we add a compiler option to also glob-delete a target file when the source file is removed? We run into this constantly and have to gulp clean frequently - it makes the usage of tsc -watch
pointless as we have to constantly purge the output directory.
For tsc --watch
we have a list of output files from the previous iteration, we just need to diff that with the current list, and delete the old outputs.
Is there a recommended way to work around this today? We have prepended rimraf lib/
to our build scripts, which removes the folder containing the compiled JS files.
But this is caused problems with sym-linked modules. The importing project's watch then gets broken with TS2307: Cannot find module
, as it only seem to register the disappearance of the lib
folder, but not the new one put in its place.
Can someone provide some pointers where I can help implement this? @mhegazy?
Things have gotten a bit more complicated with the addition of the Builder the and the WatchProgram (see https://github.com/Microsoft/TypeScript/pull/20234), there is not really a place to keep this information, since it is always partial, and we are not rebuilding the information after every change as we used to do. I suppose we could investigate restarting the builder if a file was removed. but we will need a way to detect that in the first place..
Hi!
This is constantly biting us during development. A file is removed - but nightwatch / some other library still picks it up and runs tests based on code that should not be there.
Last activity on this was more than 8 months ago, but I hope there is still a possibility for this to be added?
Thanks!
If you're using jest, you can use ts-jest
My 'solution' is obviously not the full thing that is trying to be implemented right now, it's just some very basic behavior I need myself, But I think it might help some people that need something like this right now. So if it's alright, I will just leave a link here for now: https://www.npmjs.com/package/ts-cleaner
This functionality would also be helpful on a simple --clean
, this is effecting us in CI and when switching between branches locally
ts-cleaner
didn't work for me, so I wrote ts-purify. It works exactly the same way as ts-cleaner
but uses fb-watchman
(its only dependency) instead of chokidar. This makes it very small and very efficient at watching, but on the other hand, you'll need to install watchman
to use it.
Hello!!
I solved this issue with watch
, diff-file-tree
and rimraf
:
tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"rootDir": "./src",
"outDir": "./.tmp",
"preserveSymlinks": true,
"sourceMap": true,
"declaration": true,
"module": "umd",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es6",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es6"
]
},
"include": [
"./src/**/*.*"
]
}
package.json
{
"name": "diff-tree",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "tsc && npm run build:copy",
"build:copy": "node -e \"(d = require('diff-file-tree')).diff('./.tmp', './dist').then((ch)=>d.applyRight('./.tmp', './dist', ch)).finally(()=>process.exit(0));\" && rimraf ./.tmp",
"watch": "watch \"npm run build\" ./src --interval 1 --wait 0.1"
},
"author": "",
"license": "ISC",
"devDpendencies": {
"diff-file-tree": "^2.3.2",
"rimraf": "^3.0.0",
"typescript": "^3.6.4",
"watch": "^1.0.2"
}
}
For cleaning up of not actual compilation results I use this https://github.com/whitecolor/ts-clean-built
Most helpful comment
Hi!
This is constantly biting us during development. A file is removed - but nightwatch / some other library still picks it up and runs tests based on code that should not be there.
Last activity on this was more than 8 months ago, but I hope there is still a possibility for this to be added?
Thanks!