-
Notifications
You must be signed in to change notification settings - Fork 914
reimplement module aliasing with esbuild plugin #6482
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
Conversation
🦋 Changeset detectedLatest commit: d6a2a3e The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
A wrangler prerelease is available for testing. You can install this latest build in your project with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10373037841/npm-package-wrangler-6482 You can reference the automatically updated head of this PR with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/6482/npm-package-wrangler-6482 Or you can use npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10373037841/npm-package-wrangler-6482 dev path/to/script.js Additional artifacts:npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10373037841/npm-package-create-cloudflare-6482 --no-auto-update npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10373037841/npm-package-cloudflare-kv-asset-handler-6482 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10373037841/npm-package-miniflare-6482 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10373037841/npm-package-cloudflare-pages-shared-6482 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10373037841/npm-package-cloudflare-vitest-pool-workers-6482 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10373037841/npm-package-cloudflare-workers-editor-shared-6482 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10373037841/npm-package-cloudflare-workers-shared-6482 Note that these links will no longer work once the GitHub Actions artifact expires.
Please ensure constraints are pinned, and |
cannot use ":" in filenames on windows
// resolve with node resolution | ||
path: require.resolve(aliasPath, { | ||
// From the esbuild alias docs: "Note that when an import path is substituted using an alias, the resulting import path is resolved in the working directory instead of in the directory containing the source file with the import path." | ||
// https://esbuild.github.io/api/#alias:~:text=Note%20that%20when%20an%20import%20path%20is%20substituted%20using%20an%20alias%2C%20the%20resulting%20import%20path%20is%20resolved%20in%20the%20working%20directory%20instead%20of%20in%20the%20directory%20containing%20the%20source%20file%20with%20the%20import%20path. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: perhaps just link to https://esbuild.github.io/api/#alias? We already have the relevant text in the comment above this one
loader: { | ||
...COMMON_ESBUILD_OPTIONS.loader, | ||
...(loader || {}), | ||
}, | ||
plugins: [ | ||
aliasPlugin, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the order in which these plugins are executed? Is first to last in the plugins
array, or the other way around? I can't find that mentioned in the esbuild docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First to last. I confirmed by playing with my repro linked in the issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in that case, what happens if aliasPlugin
and the unenv one are trying to alias the same module? In that case, won't unenv override the user alias? which is not what we want, unless I'm misunderstanding smth
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. esbuild runs the onResolve hooks on each plugin in order until one returns a path. It only runs the next plugin's onResolve hook if it receives undefined from the current plugin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL! thx for clarifying that 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if we want to capture this use case in a test, I'll leave that up to you
Thank you @RamIdeas! |
What this PR solves / how to test
Fixes #6448
Author has addressed the following