cli
cli copied to clipboard
Watch mode writes to output twice when using relative paths
Describe the bug
When I run the command npx swc ./src/index.js -o ./dist/output.js --watch
the output.js
file contains the output as expected on the first compilation.
When I alter index.js
and then save, the watch mode triggers a re-compile. This time, the file contains the output from the first compile, and the output from the altered file.
If I remove the relative paths and instead do this: npx swc src/index.js -o dist/output.js --watch
the output contains only the current altered file's compilation as expected.
Note: I used directories here but the behaviour is the same if you are just compiling and outputting at the root level i.e. npx swc ./index.js -o ./output.js --watch
Expected Behaviour
--watch
mode does not include any previous compilations and only includes compiled output from the current file save even when using relative paths in command.
index.js:
console.log('Speedy Web Compiler');
output.js:
console.log('Speedy Web Compiler');
Updated index.js and Save:
console.log('Speedy Web Compiler is speedy');
Updated output.js:
console.log('Speedy Web Compiler is speedy');
Actual Behaviour
--watch
mode includes first compiled output in output.js
when relative paths are used in the command.
index.js:
console.log('Speedy Web Compiler');
output.js:
console.log('Speedy Web Compiler');
Updated index.js and Save:
console.log('Speedy Web Compiler is speedy');
Updated output.js:
console.log('Speedy Web Compiler');
console.log('Speedy Web Compiler is speedy');
This is confusing because the documentation uses relative paths in the usage section so I would expect that they would work everywhere.
see: https://swc.rs/docs/usage/cli#usage
May be related to #99 but I thought the extra detail may be helpful for context.