Skip to content

Commit

Permalink
feat: split worker bundle with esbuild
Browse files Browse the repository at this point in the history
  • Loading branch information
threepointone committed Oct 3, 2024
1 parent 917ef60 commit ab19bb0
Show file tree
Hide file tree
Showing 5 changed files with 302 additions and 237 deletions.
100 changes: 50 additions & 50 deletions packages/wrangler/src/__tests__/pages/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2140,12 +2140,12 @@ describe("pages deploy", () => {
`Content-Disposition: form-data; name="metadata"`
);
expect(workerBundleWithConstantData).toContain(
`{"main_module":"functionsWorker-0.test.js"}`
`{"main_module":"pages-template-worker.js"}`
);

// check we appended the compiled Worker
expect(workerBundleWithConstantData).toContain(
`Content-Disposition: form-data; name="functionsWorker-0.test.js"; filename="functionsWorker-0.test.js"`
`Content-Disposition: form-data; name="pages-template-worker.js"; filename="pages-template-worker.js"`
);
expect(workerBundleWithConstantData).toContain(`
import wasm from "./test-hello.wasm";
Expand Down Expand Up @@ -3203,9 +3203,9 @@ Failed to publish your Function. Got error: Uncaught TypeError: a is not a funct
"------formdata-undici-0.test
Content-Disposition: form-data; name=\\"metadata\\"
{\\"main_module\\":\\"bundledWorker-0.test.mjs\\"}
{\\"main_module\\":\\"_worker.js\\"}
------formdata-undici-0.test
Content-Disposition: form-data; name=\\"bundledWorker-0.test.mjs\\"; filename=\\"bundledWorker-0.test.mjs\\"
Content-Disposition: form-data; name=\\"_worker.js\\"; filename=\\"_worker.js\\"
Content-Type: application/javascript+module
// _worker.js
Expand All @@ -3228,7 +3228,7 @@ Failed to publish your Function. Got error: Uncaught TypeError: a is not a funct
export {
worker_default as default
};
//# sourceMappingURL=bundledWorker-0.test.mjs.map
//# sourceMappingURL=_worker.js.map
------formdata-undici-0.test
Content-Disposition: form-data; name=\\"./test-hello.wasm\\"; filename=\\"./test-hello.wasm\\"
Expand Down Expand Up @@ -3481,28 +3481,28 @@ Failed to publish your Function. Got error: Uncaught TypeError: a is not a funct
// `bundledWorker`, the wasm import, etc., and since `workerBundle` is
// small enough, let's go ahead and snapshot test the whole thing
expect(workerBundleWithConstantData).toMatchInlineSnapshot(`
"------formdata-undici-0.test
Content-Disposition: form-data; name=\\"metadata\\"
{\\"main_module\\":\\"bundledWorker-0.test.mjs\\"}
------formdata-undici-0.test
Content-Disposition: form-data; name=\\"bundledWorker-0.test.mjs\\"; filename=\\"bundledWorker-0.test.mjs\\"
Content-Type: application/javascript+module
// _worker.js
var worker_default = {
async fetch(request, env) {
const url = new URL(request.url);
return url.pathname.startsWith(\\"/api/\\") ? new Response(\\"Ok\\") : env.ASSETS.fetch(request);
}
};
export {
worker_default as default
};
//# sourceMappingURL=bundledWorker-0.test.mjs.map
"------formdata-undici-0.test
Content-Disposition: form-data; name=\\"metadata\\"
------formdata-undici-0.test--"
`);
{\\"main_module\\":\\"_worker.js\\"}
------formdata-undici-0.test
Content-Disposition: form-data; name=\\"_worker.js\\"; filename=\\"_worker.js\\"
Content-Type: application/javascript+module
// _worker.js
var worker_default = {
async fetch(request, env) {
const url = new URL(request.url);
return url.pathname.startsWith(\\"/api/\\") ? new Response(\\"Ok\\") : env.ASSETS.fetch(request);
}
};
export {
worker_default as default
};
//# sourceMappingURL=_worker.js.map
------formdata-undici-0.test--"
`);

expect(JSON.parse(customRoutesJSON)).toMatchObject({
version: ROUTES_SPEC_VERSION,
Expand Down Expand Up @@ -3850,28 +3850,28 @@ and that at least one include rule is provided.
// `bundledWorker`, the wasm import, etc., and since `workerBundle` is
// small enough, let's go ahead and snapshot test the whole thing
expect(workerBundleWithConstantData).toMatchInlineSnapshot(`
"------formdata-undici-0.test
Content-Disposition: form-data; name=\\"metadata\\"
{\\"main_module\\":\\"bundledWorker-0.test.mjs\\"}
------formdata-undici-0.test
Content-Disposition: form-data; name=\\"bundledWorker-0.test.mjs\\"; filename=\\"bundledWorker-0.test.mjs\\"
Content-Type: application/javascript+module
// _worker.js
var worker_default = {
async fetch(request, env) {
const url = new URL(request.url);
return url.pathname.startsWith(\\"/api/\\") ? new Response(\\"Ok\\") : env.ASSETS.fetch(request);
}
};
export {
worker_default as default
};
//# sourceMappingURL=bundledWorker-0.test.mjs.map
"------formdata-undici-0.test
Content-Disposition: form-data; name=\\"metadata\\"
------formdata-undici-0.test--"
`);
{\\"main_module\\":\\"_worker.js\\"}
------formdata-undici-0.test
Content-Disposition: form-data; name=\\"_worker.js\\"; filename=\\"_worker.js\\"
Content-Type: application/javascript+module
// _worker.js
var worker_default = {
async fetch(request, env) {
const url = new URL(request.url);
return url.pathname.startsWith(\\"/api/\\") ? new Response(\\"Ok\\") : env.ASSETS.fetch(request);
}
};
export {
worker_default as default
};
//# sourceMappingURL=_worker.js.map
------formdata-undici-0.test--"
`);

return HttpResponse.json(
{
Expand Down Expand Up @@ -5293,7 +5293,7 @@ Failed to publish your Function. Got error: Uncaught TypeError: a is not a funct
const contents = await bundleString(entry);
// Ensure we get a sourcemap containing our functions file
expect(contents).toContain(
'Content-Disposition: form-data; name="functionsWorker-0.test.js.map"'
'Content-Disposition: form-data; name="pages-template-worker.js.map"; filename="pages-template-worker.js.map"'
);
expect(contents).toContain('"sources":["[[path]].ts"');
});
Expand All @@ -5317,7 +5317,7 @@ Failed to publish your Function. Got error: Uncaught TypeError: a is not a funct
const contents = await bundleString(entry);
// Ensure we get a sourcemap containing our _worker.js file
expect(contents).toContain(
'Content-Disposition: form-data; name="bundledWorker-0.test.mjs.map"'
'Content-Disposition: form-data; name="_worker.js.map"; filename="_worker.js.map"'
);
expect(contents).toContain('"sources":["_worker.js"');
});
Expand Down Expand Up @@ -5357,7 +5357,7 @@ Failed to publish your Function. Got error: Uncaught TypeError: a is not a funct

// Ensure we get a sourcemap containing our main worker file
expect(contents).toContain(
'Content-Disposition: form-data; name="bundledWorker-0.test.mjs.map"'
'Content-Disposition: form-data; name="index.js.map"; filename="index.js.map"'
);
expect(contents).toContain('"sources":["dist/_worker.js/index.js"');

Expand Down
Loading

0 comments on commit ab19bb0

Please sign in to comment.