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

Allow package.json dependencies to be selectively transpiled / bundled #38

Open
tjunnone opened this issue Oct 23, 2021 · 1 comment · May be fixed by #60
Open

Allow package.json dependencies to be selectively transpiled / bundled #38

tjunnone opened this issue Oct 23, 2021 · 1 comment · May be fixed by #60

Comments

@tjunnone
Copy link

tjunnone commented Oct 23, 2021

The esbuild-node-externals plugin allows you to specify an allowList parameter for including dependencies into the bundle.

Why would you want this? For example:

  • A project (typically a monorepo) that uses internal dependencies of type "foo": "link:.src/some/path/foo" in the package.json. These aren't really external dependencies and they should be bundled/transpiled, they're just a convenient way to make bits of the source appear as top-level packages for import.
  • Creating single-file deployments, where the entire node_modules is intentionally bundled. It's possible and convenient if you have no native binary dependencies.
  • Bundling only selected (perhaps vendored) node_modules packages.

In our case, the first bullet prevents us from using esbuild-runner for some of our tools: our source tree is pure ESM, esr transpiles to CJS for running under node except the internally linked entries defined in packages.json aren't being bundled, so the result doesn't run.

I would like to suggest one or two options:

  • Add an esr config option allowList or externalsAllowList, specifying dependencies that should be transpiled/bundled.
  • Add an esr config option to disable the default externalizing of node_modules entirely. Then I could presumably add the esbuild-node-externals plugin myself to the config, or write my own plugin like in the esbuild docs, which supports fine-grained control of which dependencies to include or exclude.

If this is something you'd consider, I could try to make a PR.

@xfournet
Copy link

xfournet commented Nov 15, 2021

I had the same problem when upgrading from node-fetch 2.x (non ESM) to node-fetch 3.x (ESM). It's quite surprisingly that esbuild-runner automatically externalize direct dependencies in package.json which is not the behavior of esbuild.
Moreover the behavior is not the same for indirect dependencies which are not externalized. So the final behavior is quite strange, and i was forced to patch esbuild-runner to be able to fully control the external parameter.
I would suggest to remove the reading of package.json so that we can have full control on the external list, and be able to use other alternative like @tjunnone is suggesting

@codetheweb codetheweb linked a pull request May 11, 2022 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants