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

Pages Functions Wasm cleanup #2806

Merged
merged 10 commits into from
Mar 7, 2023
Merged

Pages Functions Wasm cleanup #2806

merged 10 commits into from
Mar 7, 2023

Conversation

GregBrimble
Copy link
Member

@GregBrimble GregBrimble commented Feb 27, 2023

What this PR solves / how to test:

This does two big things (and one little one):

  • It removes the --experimental-worker-bundle option from Pages Functions. We now just always do this. It was temporarily added for us to test the new _worker.bundle upload format.
  • It enables --bundle by default in pages dev and pages publish. This means that you're able to use Wasm etc. in _worker.js projects.
  • Finally, it marks .wasm and .bin files as external when building a Plugin. We already do this with assets:, so there's prior art here, but this is ultimately only a stop-gap until we change the output format to an --outdir rather than an --outfile for Plugins. We'll follow up soon-ish with that.

Associated docs issues/PR:

Author has included the following, where applicable:

  • Tests
  • Changeset

Reviewer has performed the following, where applicable:

  • Checked for inclusion of relevant tests
  • Checked for inclusion of a relevant changeset
  • Checked for creation of associated docs updates
  • Manually pulled down the changes and spot-tested

Fixes # [insert issue number].

@changeset-bot
Copy link

changeset-bot bot commented Feb 27, 2023

🦋 Changeset detected

Latest commit: b410c49

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
wrangler Patch

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

@github-actions
Copy link
Contributor

github-actions bot commented Feb 27, 2023

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/4354494434/npm-package-wrangler-2806

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/2806/npm-package-wrangler-2806

Or you can use npx with this latest build directly:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/4354494434/npm-package-wrangler-2806 dev path/to/script.js
Additional artifacts:
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/4354494434/npm-package-cloudflare-pages-shared-2806

Note that these links will no longer work once the GitHub Actions artifact expires.

@GregBrimble GregBrimble force-pushed the pages-functions-wasm-cleanup branch 11 times, most recently from 133238f to 970c80b Compare February 28, 2023 14:23
@codecov
Copy link

codecov bot commented Feb 28, 2023

Codecov Report

Merging #2806 (b410c49) into main (226e63f) will decrease coverage by 0.10%.
The diff coverage is 61.46%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2806      +/-   ##
==========================================
- Coverage   74.05%   73.96%   -0.10%     
==========================================
  Files         166      166              
  Lines       10218    10250      +32     
  Branches     2734     2744      +10     
==========================================
+ Hits         7567     7581      +14     
- Misses       2651     2669      +18     
Impacted Files Coverage Δ
packages/wrangler/src/bundle.ts 92.95% <ø> (-0.94%) ⬇️
packages/wrangler/src/pages/dev.ts 18.77% <0.00%> (ø)
packages/wrangler/src/pages/publish.tsx 47.05% <ø> (ø)
...ckages/wrangler/src/pages/functions/buildPlugin.ts 19.35% <6.66%> (-0.65%) ⬇️
packages/wrangler/src/pages/buildFunctions.ts 90.24% <33.33%> (-2.07%) ⬇️
packages/wrangler/src/pages/build.ts 67.03% <66.19%> (-17.88%) ⬇️
...ckages/wrangler/src/pages/functions/buildWorker.ts 64.55% <87.50%> (+6.86%) ⬆️
packages/wrangler/src/api/pages/publish.tsx 88.18% <100.00%> (-1.08%) ⬇️
packages/wrangler/src/pages/errors.ts 77.77% <100.00%> (+0.85%) ⬆️
... and 4 more

const functionsOutfile = experimentalWorkerBundle
? join(tmpdir(), `./functionsWorker-${Math.random()}.js`)
: outfile;
const functionsOutfile = plugin
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to keep this conditional in for building Pages Plugins. I'll follow up with another PR soon which produces a outdir rather than a single file in the case of a Plugin.

const workerBundleContents = await createUploadWorkerBundleContents(
bundle as BundleResult
);

mkdirSync(dirname(outfile), { recursive: true });
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I specify wrangler pages functions build --outfile=some/dir/that/doesnt/exist.js it would fail which is unlike the previous pre-bundling behavior.

@GregBrimble GregBrimble marked this pull request as ready for review March 1, 2023 08:56
@GregBrimble GregBrimble requested review from a team as code owners March 1, 2023 08:56
Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Just one suggestion.

packages/wrangler/src/pages/functions/buildPlugin.ts Outdated Show resolved Hide resolved
@GregBrimble GregBrimble force-pushed the pages-functions-wasm-cleanup branch 7 times, most recently from 2c7bcc6 to 50abac0 Compare March 5, 2023 12:06
@GregBrimble
Copy link
Member Author

Related: #2836

@GregBrimble GregBrimble force-pushed the pages-functions-wasm-cleanup branch 2 times, most recently from 3a27392 to 6f79b09 Compare March 6, 2023 10:30
@GregBrimble GregBrimble force-pushed the pages-functions-wasm-cleanup branch 2 times, most recently from 8e637ff to 9295957 Compare March 6, 2023 15:19
@CarmenPopoviciu
Copy link
Contributor

reviewed one more time and LGTM

@GregBrimble GregBrimble merged commit 8d462c0 into main Mar 7, 2023
@GregBrimble GregBrimble deleted the pages-functions-wasm-cleanup branch March 7, 2023 14:05
@github-actions github-actions bot mentioned this pull request Mar 7, 2023
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 this pull request may close these issues.

None yet

3 participants