Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional directories to watch #3718

Open
jozefchutka opened this issue Apr 5, 2024 · 3 comments
Open

Additional directories to watch #3718

jozefchutka opened this issue Apr 5, 2024 · 3 comments

Comments

@jozefchutka
Copy link

jozefchutka commented Apr 5, 2024

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);
@evanw
Copy link
Owner

evanw commented Apr 5, 2024

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

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.

@jozefchutka
Copy link
Author

jozefchutka commented Apr 8, 2024

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?

@jozefchutka
Copy link
Author

@evanw can you please have a look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants