Additional directories to watch
My project structure is as following:
src/common/.. .ts files
src/project1/main.ts
src/project2/main.ts
when bundling src/project1/main.ts or src/project2/main.ts which depend on files in src/common folder using esbuild.context().watch() does not register changes in src/common. It seems the built-in logic only looks for changes in entryPoint directory and its subdirectories.
Is there any build option or watch option to extend the watch over more folders? In my case I would add src/common.
If not, I can see WatchOptions being an empty interface, seems like a good place to extend?
My current workaround is:
const context = await esbuild.context(options);
const rebuild = async () => {
try {
return await context.rebuild();
} catch(error) {}
}
await rebuild();
fs.watch("src/common", {recursive:true}).addListener("change", rebuild);
when bundling
src/project1/main.tsorsrc/project2/main.tswhich depend on files insrc/commonfolder usingesbuild.context().watch()does not register changes insrc/common
I can't reproduce this. Here's what I tried:
$ cat src/project1/main.ts
import '../common/example'
$ cat src/common/example.ts
console.log(1)
$ esbuild --bundle src/project1/main.ts --watch
(() => {
// src/common/example.ts
console.log(1);
})();
[watch] build finished, watching for changes...
[watch] build started (change: "src/common/example.ts")
(() => {
// src/common/example.ts
console.log(2);
})();
[watch] build finished
In the above sequence, I changed src/common/example.ts from console.log(1) to console.log(2) while esbuild was watching it.
I'm marking this issue as unactionable because the issue reporting instructions were not followed. Reproduction instructions were omitted and I cannot reproduce your issue. This issue may be closed if a reproduction is not provided.
The setup for reproduction is as follows:
$ cat src/project1/main.ts
import '../common/example'
const a:MyType = "x";
$ cat src/common/example.ts
export type MyType = "a";
$ esbuild --bundle src/project1/main.ts --watch
(() => {
})();
[watch] build finished, watching for changes...
In the above sequence, change content of example.ts, i.e. change type name etc.
My idea was having tsc running inside esbuild watch:
const context = await esbuild.context({
plugins: [{
name: "main",
setup(build) {
build.onEnd(result => {
childProcess.execSync(`tsc -p ${tsConfigPath} --noEmit`, {stdio:"inherit"});
}}}]});
await context.watch();
I understand that esbuild ignores ts types, and so is not interested in triggering watch on type change. However, running tsc at the time of esbuild built-in watch, would end up ignoring important change events.
So my idea was having a bit more extensible esbuild watch via parameters, or having the watch api exposed?
@evanw can you please have a look?