-
Notifications
You must be signed in to change notification settings - Fork 732
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
_worker.js/
directory support in Pages
#2966
Conversation
🦋 Changeset detectedLatest commit: 6853fb7 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/4862724294/npm-package-wrangler-2966 You can reference the automatically updated head of this PR with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/2966/npm-package-wrangler-2966 Or you can use npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/4862724294/npm-package-wrangler-2966 dev path/to/script.js Additional artifacts:npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/4862724294/npm-package-cloudflare-pages-shared-2966 Note that these links will no longer work once the GitHub Actions artifact expires. |
eff07ee
to
84a6fa4
Compare
Codecov Report
@@ Coverage Diff @@
## main #2966 +/- ##
==========================================
+ Coverage 73.54% 74.42% +0.87%
==========================================
Files 167 168 +1
Lines 10499 10624 +125
Branches 2807 2855 +48
==========================================
+ Hits 7722 7907 +185
+ Misses 2777 2717 -60
|
7830ccd
to
1966c9d
Compare
0551501
to
1b16312
Compare
1b16312
to
6733524
Compare
_worker.js/
directory support in Pages
4f632cb
to
8a93d66
Compare
8a93d66
to
dd54629
Compare
dd54629
to
da29860
Compare
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.
Looks good to me 😄 (based on my almost nonexistent knowledge of the codebase 😅)
async fetch(request, env) { | ||
return new Response("Hello from _worker.js/index.js" + cat); | ||
}, | ||
};` |
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.
.trim()
packages/wrangler/src/pages/build.ts
Outdated
if (lstatSync(workerScriptPath).isDirectory()) { | ||
const entrypoint = resolve(join(workerScriptPath, "index.js")); | ||
|
||
const traverseModuleGraphResult = await traverseModuleGraph( | ||
{ | ||
file: entrypoint, | ||
directory: resolve(workerScriptPath), | ||
format: "modules", | ||
moduleRoot: resolve(workerScriptPath), | ||
}, | ||
[ | ||
{ | ||
type: "ESModule", | ||
globs: ["**/*.js"], | ||
}, | ||
] | ||
); | ||
|
||
const bundleResult = await buildRawWorker({ | ||
workerScriptPath: entrypoint, | ||
bundle: false, | ||
outdir, | ||
directory: buildOutputDirectory, | ||
local: false, | ||
sourcemap, | ||
watch, | ||
betaD1Shims: d1Databases, | ||
}); | ||
|
||
bundle = { | ||
modules: (traverseModuleGraphResult?.modules ?? | ||
bundleResult?.modules) as BundleResult["modules"], | ||
dependencies: (bundleResult?.dependencies ?? | ||
traverseModuleGraphResult?.dependencies) as BundleResult["dependencies"], | ||
resolvedEntryPointPath: (bundleResult?.resolvedEntryPointPath ?? | ||
traverseModuleGraphResult?.resolvedEntryPointPath) as BundleResult["resolvedEntryPointPath"], | ||
bundleType: (bundleResult?.bundleType ?? | ||
traverseModuleGraphResult?.bundleType) as BundleResult["bundleType"], | ||
stop: bundleResult?.stop, | ||
sourceMapPath: bundleResult?.sourceMapPath, | ||
}; | ||
} else { | ||
/** | ||
* `buildRawWorker` builds `_worker.js`, but doesn't give us the bundle | ||
* we want to return, which includes the external dependencies (like wasm, | ||
* binary, text). Let's output that build result to memory and only write | ||
* to disk once we have the final bundle | ||
*/ | ||
bundle = await buildRawWorker({ | ||
workerScriptPath, | ||
outdir, | ||
directory: buildOutputDirectory, | ||
local: false, | ||
sourcemap, | ||
watch, | ||
betaD1Shims: d1Databases, | ||
}); | ||
} |
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.
It feels like a lot of this is the same as pages/dev
. Could it be pulled out into a common helper function?
74b10f2
to
780817d
Compare
ad6fd0f
to
7616ffc
Compare
b66bda9
to
045c3df
Compare
}); | ||
|
||
return { | ||
modules: traverseModuleGraphResult?.modules ?? bundleResult?.modules ?? [], |
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.
Under what case would it use bundleResult?.modules
? Mind adding a comment explaining what is happening here? I'm not as familiar with esbuild/etc and the way we're doing the traversal and then bundling (but not bundling) is confusing
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.
Yeah, good shout. This was me copy-pasting from elsewhere, but you're right. It'll never fallback to bundleResult
s.
045c3df
to
a79049b
Compare
a79049b
to
6853fb7
Compare
"wrangler": minor | ||
--- | ||
|
||
feat: Add support for the undocumented `_worker.js/` directory in Pages |
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.
Should it be documented?
What this PR solves / how to test:
This PR adds support for an
_worker.js/
directory in Pages. It adds support for:wrangler pages dev
wrangler pages functions build
wrangler pages publish
The entrypoint (
_worker.js/index.js
) is bundled, and the rest of the files in the_worker.js/
directory are uploaded with the default rules + all.js
files are treated as ESM.This will be treated as an undocumented API for the time being.
Author has included the following, where applicable:
Reviewer has performed the following, where applicable: