-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Avoid blocking built-in node modules when using --no-bundle flag #4303
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
Avoid blocking built-in node modules when using --no-bundle flag #4303
Conversation
🦋 Changeset detectedLatest commit: 5fac1d2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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/7976171568/npm-package-wrangler-4303You can reference the automatically updated head of this PR with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/4303/npm-package-wrangler-4303Or you can use npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7976171568/npm-package-wrangler-4303 dev path/to/script.jsAdditional artifacts:npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7976171568/npm-package-create-cloudflare-4303 --no-auto-updatenpm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7976171568/npm-package-cloudflare-kv-asset-handler-4303npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7976171568/npm-package-miniflare-4303npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7976171568/npm-package-cloudflare-pages-shared-4303npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7976171568/npm-package-cloudflare-vitest-pool-workers-4303Note that these links will no longer work once the GitHub Actions artifact expires.
Please ensure constraints are pinned, and |
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #4303 +/- ##
==========================================
+ Coverage 70.34% 70.40% +0.05%
==========================================
Files 298 298
Lines 15463 15470 +7
Branches 3966 3969 +3
==========================================
+ Hits 10877 10891 +14
+ Misses 4586 4579 -7
|
petebacondarwin
left a comment
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.
DONT MERGE - just testing approval
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.
Thanks for the PR!
Could you add a test (see https://github.com/cloudflare/workers-sdk/blob/main/fixtures/pages-workerjs-app/tests/index.test.ts#L8), as well as a changeset (pnpx changeset in the root of the repo)
|
Apologies for the delay here—this is looking good! Before merging, could you add a unit test to https://github.com/cloudflare/workers-sdk/tree/main/packages/wrangler/src/__tests__/pages/deploy.test.ts ? I don't think this change will need a full fixture test |
|
hi @richardscarrott :) could you please add a unit test (per @penalosa 's comment)? else we'll close the PR and you can re-open when you're able to revisit and make the relevant changes. thanks! |
petebacondarwin
left a comment
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.
One small comment but otherwise LGTM!
Thanks
| // Otherwise, block any imports that the file is requesting | ||
| // If it's a node or cf built-in, mark it as external | ||
| if ( | ||
| args.path.startsWith("node:") || |
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.
OK so I think we just need a bit of care here.
We should only consider imports beginning with node: as external if the nodejs_compat flag is actually turned on.
We can pass that through to this plugin by making it a function with a parameter, I believe.
8b7a4d3 to
a20df38
Compare
petebacondarwin
left a comment
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.
I rebased, swapped out the fixture tests for unit tests, and added the check for the nodejs_compat flag.
@penalosa - PTAL
penalosa
left a comment
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.
One misplaced comment, but LGTM
8927f4c to
5fac1d2
Compare
What this PR solves / how to test:
We want to import and use the
AsyncLocalStoragepolyfil in our Remix app, deployed to CF Pages.However, to ensure Remix sourcemaps actually align with the executed code, we tell wrangler not to bundle our code and instead use Advanced Mode (_worker.js file).
This fails with:
After some discussion in Discord, I believe this is a mistake because
node:async_hooksis available to import at runtime and doesn't depend on a build step.Author has addressed the following:
Note for PR author:
We want to celebrate and highlight awesome PR review! If you think this PR received a particularly high-caliber review, please assign it the label
highlight pr reviewso future reviewers can take inspiration and learn from it.