Skip to content

Getting the dependencies gathered by esbuild #1535

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

Open
unilynx opened this issue Aug 19, 2021 · 2 comments
Open

Getting the dependencies gathered by esbuild #1535

unilynx opened this issue Aug 19, 2021 · 2 comments

Comments

@unilynx
Copy link

unilynx commented Aug 19, 2021

I'm trying to implement my own watch/incremental build system om top of esbuild. For this, I need to figure out which files should trigger recompilation of a bundle.

Is there a way to get a list of all the input dependencies used by esbuild? I'm looking for something more-or-less equivalent to webpack's fileDependencies and missingDependencies. I presume esbuild has these lists somewhere to implement its own watchlists but is not exporting it yet.

I've tried to set 'incremental:true' to esbuild but that doesn't return any further information.

I'm also looking at metafile: true which might allow me to simulate fileDependencies but not missingDependencies, and it looks like the information is incomplete when an onResolve intercepted the lookup (eg for esbuild-plugin-sass I'm seeing temporary files instead of the source files, but maybe that's something I need to fix in esbuild-plugin-sass.)

EDIT: oh, and a failed compilation due to a syntax error doesn't give me a metafile, so I don't know what files to watch to know if I can retry the compilation.

@unilynx unilynx changed the title Getting the dependencies gathered by esbuil Getting the dependencies gathered by esbuild Aug 19, 2021
@unilynx
Copy link
Author

unilynx commented Aug 19, 2021

Ah, I see #1527 (comment) has made a similar request.

@unilynx
Copy link
Author

unilynx commented Aug 23, 2021

as a workaround I've added the following plugin to capture most of the dependencies, even when compilation fails

class captureLoadPlugin
{
  constructor(loadcache)
  {
    this.loadcache = new Set;
  }
  getPlugin()
  {
    return { name: 'captureloads'
           , setup: build => this.setup(build)
           };
  }
  setup(build)
  {
    build.onLoad({filter:/./}, args =>
    {
      this.loadcache.add(args.path);
    });
  }
}

....

  let captureplugin = new captureLoadPlugin;

....

      , plugins: [ captureplugin.getPlugin(), .... ]

....

let fileDepencies = Array.from(captureplugin.loadcache);

after swapping esbuild-plugin-sass to esbuild-sass-plugin, I seem to have gotten reasonably close to what I had with webpack. this will probably not be compatible with all plugins and I haven't started working with incremental:true yet, I probably need to clear the 'loadcache' at some point then.

@arcanis maybe this helps you in your issue #1527 too?

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

No branches or pull requests

1 participant