wrangler 0.0.0-e33294b0 → 0.0.0-e33bea9b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/wrangler.js +1 -1
- package/miniflare-dist/index.mjs +21 -4
- package/package.json +8 -8
- package/src/__tests__/configuration.test.ts +235 -6
- package/src/__tests__/d1/execute.test.ts +1 -1
- package/src/__tests__/dev.test.tsx +16 -1
- package/src/__tests__/guess-worker-format.test.ts +35 -0
- package/src/__tests__/init.test.ts +9 -8
- package/src/__tests__/middleware.test.ts +2 -1
- package/src/__tests__/pages/functions-build.test.ts +91 -41
- package/src/__tests__/pages/publish.test.ts +136 -61
- package/src/__tests__/publish.test.ts +169 -14
- package/src/__tests__/test-old-node-version.js +3 -3
- package/src/__tests__/tsconfig.tsbuildinfo +1 -1
- package/src/__tests__/type-generation.test.ts +1 -0
- package/src/__tests__/user.test.ts +1 -1
- package/src/api/dev.ts +3 -4
- package/src/api/pages/publish.tsx +38 -51
- package/src/bundle.ts +27 -9
- package/src/config/environment.ts +9 -4
- package/src/config/index.ts +12 -2
- package/src/config/validation-helpers.ts +1 -1
- package/src/config/validation.ts +58 -4
- package/src/create-worker-preview.ts +19 -8
- package/src/create-worker-upload-form.ts +10 -2
- package/src/dev/dev.tsx +4 -4
- package/src/dev/local.tsx +18 -21
- package/src/dev/start-server.ts +10 -8
- package/src/dev/use-esbuild.ts +9 -5
- package/src/dev/validate-dev-props.ts +9 -0
- package/src/dev.tsx +27 -13
- package/src/entry.ts +1 -2
- package/src/index.ts +1 -1
- package/src/init.ts +1 -0
- package/src/inspect.ts +16 -1
- package/src/miniflare-cli/assets.ts +8 -7
- package/src/miniflare-cli/index.ts +1 -1
- package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -1
- package/src/pages/build.ts +277 -99
- package/src/pages/buildFunctions.ts +20 -10
- package/src/pages/dev.ts +21 -21
- package/src/pages/errors.ts +1 -0
- package/src/pages/functions/buildPlugin.ts +56 -34
- package/src/pages/functions/buildWorker.ts +32 -23
- package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
- package/src/pages/publish.tsx +1 -10
- package/src/pages/upload.tsx +5 -5
- package/src/paths.ts +1 -1
- package/src/publish/index.ts +1 -1
- package/src/publish/publish.ts +19 -8
- package/src/r2/helpers.ts +1 -0
- package/src/secret/index.ts +1 -1
- package/src/type-generation.ts +1 -1
- package/src/user/user.ts +1 -1
- package/src/worker.ts +8 -1
- package/templates/d1-beta-facade.js +5 -2
- package/templates/gitignore +1 -0
- package/templates/middleware/middleware-miniflare3-json-error.ts +17 -5
- package/templates/pages-template-plugin.ts +7 -3
- package/templates/tsconfig.init.json +1 -2
- package/templates/tsconfig.tsbuildinfo +1 -1
- package/wrangler-dist/cli.d.ts +523 -14
- package/wrangler-dist/cli.js +11473 -4544
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { execSync } from "node:child_process";
|
|
1
2
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
3
|
import { endEventLoop } from "../helpers/end-event-loop";
|
|
3
4
|
import { mockConsoleMethods } from "../helpers/mock-console";
|
|
@@ -39,7 +40,7 @@ describe("functions build", () => {
|
|
|
39
40
|
/* --------------------------------- */
|
|
40
41
|
await runWrangler(`pages functions build`);
|
|
41
42
|
|
|
42
|
-
expect(existsSync("_worker.
|
|
43
|
+
expect(existsSync("_worker.bundle")).toBe(true);
|
|
43
44
|
expect(std.out).toMatchInlineSnapshot(`
|
|
44
45
|
"🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose
|
|
45
46
|
✨ Compiled Worker successfully"
|
|
@@ -47,7 +48,7 @@ describe("functions build", () => {
|
|
|
47
48
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
48
49
|
});
|
|
49
50
|
|
|
50
|
-
it("should include any external modules imported by functions in the output bundle
|
|
51
|
+
it("should include any external modules imported by functions in the output bundle", async () => {
|
|
51
52
|
/* ---------------------------- */
|
|
52
53
|
/* Set up wasm files */
|
|
53
54
|
/* ---------------------------- */
|
|
@@ -76,9 +77,7 @@ describe("functions build", () => {
|
|
|
76
77
|
/* --------------------------------- */
|
|
77
78
|
/* Run cmd & make assertions */
|
|
78
79
|
/* --------------------------------- */
|
|
79
|
-
await runWrangler(
|
|
80
|
-
`pages functions build --outfile=_worker.bundle --experimental-worker-bundle=true`
|
|
81
|
-
);
|
|
80
|
+
await runWrangler(`pages functions build --outfile=_worker.bundle`);
|
|
82
81
|
|
|
83
82
|
expect(existsSync("_worker.bundle")).toBe(true);
|
|
84
83
|
expect(std.out).toMatchInlineSnapshot(`
|
|
@@ -126,12 +125,13 @@ describe("functions build", () => {
|
|
|
126
125
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
127
126
|
});
|
|
128
127
|
|
|
129
|
-
it("should
|
|
128
|
+
it("should output a directory with --outdir", async () => {
|
|
130
129
|
/* ---------------------------- */
|
|
131
130
|
/* Set up wasm files */
|
|
132
131
|
/* ---------------------------- */
|
|
133
132
|
mkdirSync("wasm");
|
|
134
|
-
writeFileSync("wasm/greeting.wasm", "Hello
|
|
133
|
+
writeFileSync("wasm/greeting.wasm", "Hello");
|
|
134
|
+
writeFileSync("wasm/name.wasm", "wasm Functions");
|
|
135
135
|
|
|
136
136
|
/* ---------------------------- */
|
|
137
137
|
/* Set up Functions */
|
|
@@ -141,10 +141,12 @@ describe("functions build", () => {
|
|
|
141
141
|
"functions/hello.js",
|
|
142
142
|
`
|
|
143
143
|
import hello from "./../wasm/greeting.wasm";
|
|
144
|
+
import name from "./../wasm/name.wasm";
|
|
144
145
|
|
|
145
146
|
export async function onRequest() {
|
|
146
|
-
const
|
|
147
|
-
|
|
147
|
+
const greetingModule = await WebAssembly.instantiate(greeting);
|
|
148
|
+
const nameModule = await WebAssembly.instantiate(name);
|
|
149
|
+
return new Response(greetingModule.exports.hello + " " + nameModule.exports.name);
|
|
148
150
|
}
|
|
149
151
|
`
|
|
150
152
|
);
|
|
@@ -152,13 +154,23 @@ describe("functions build", () => {
|
|
|
152
154
|
/* --------------------------------- */
|
|
153
155
|
/* Run cmd & make assertions */
|
|
154
156
|
/* --------------------------------- */
|
|
155
|
-
await
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
)
|
|
157
|
+
await runWrangler(`pages functions build --outdir=dist`);
|
|
158
|
+
|
|
159
|
+
expect(existsSync("dist")).toBe(true);
|
|
160
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
161
|
+
"🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose
|
|
162
|
+
✨ Compiled Worker successfully"
|
|
163
|
+
`);
|
|
164
|
+
|
|
165
|
+
expect(execSync("ls dist", { encoding: "utf-8" })).toMatchInlineSnapshot(`
|
|
166
|
+
"e8f0f80fe25d71a0fc2b9a08c877020211192308-name.wasm
|
|
167
|
+
f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0-greeting.wasm
|
|
168
|
+
index.js
|
|
169
|
+
"
|
|
170
|
+
`);
|
|
159
171
|
});
|
|
160
172
|
|
|
161
|
-
it("should build _worker.js
|
|
173
|
+
it("should build _worker.js", async () => {
|
|
162
174
|
/* ---------------------------- */
|
|
163
175
|
/* Set up js files */
|
|
164
176
|
/* ---------------------------- */
|
|
@@ -190,7 +202,7 @@ export default {
|
|
|
190
202
|
/* Run cmd & make assertions */
|
|
191
203
|
/* --------------------------------- */
|
|
192
204
|
await runWrangler(
|
|
193
|
-
`pages functions build --build-output-directory=public --outfile=_worker.bundle
|
|
205
|
+
`pages functions build --build-output-directory=public --outfile=_worker.bundle`
|
|
194
206
|
);
|
|
195
207
|
expect(existsSync("_worker.bundle")).toBe(true);
|
|
196
208
|
expect(std.out).toMatchInlineSnapshot(`
|
|
@@ -206,7 +218,7 @@ export default {
|
|
|
206
218
|
workerBundleContents,
|
|
207
219
|
[
|
|
208
220
|
[/------formdata-undici-0.[0-9]*/g, "------formdata-undici-0.test"],
|
|
209
|
-
[/
|
|
221
|
+
[/functionsWorker-0.[0-9]*.js/g, "functionsWorker-0.test.js"],
|
|
210
222
|
]
|
|
211
223
|
);
|
|
212
224
|
|
|
@@ -214,9 +226,9 @@ export default {
|
|
|
214
226
|
"------formdata-undici-0.test
|
|
215
227
|
Content-Disposition: form-data; name=\\"metadata\\"
|
|
216
228
|
|
|
217
|
-
{\\"main_module\\":\\"
|
|
229
|
+
{\\"main_module\\":\\"functionsWorker-0.test.js\\"}
|
|
218
230
|
------formdata-undici-0.test
|
|
219
|
-
Content-Disposition: form-data; name=\\"
|
|
231
|
+
Content-Disposition: form-data; name=\\"functionsWorker-0.test.js\\"; filename=\\"functionsWorker-0.test.js\\"
|
|
220
232
|
Content-Type: application/javascript+module
|
|
221
233
|
|
|
222
234
|
// ../utils/meaning-of-life.js
|
|
@@ -231,18 +243,10 @@ export default {
|
|
|
231
243
|
export {
|
|
232
244
|
worker_default as default
|
|
233
245
|
};
|
|
234
|
-
//# sourceMappingURL=bundledWorker-0.test.mjs.map
|
|
235
246
|
|
|
236
247
|
------formdata-undici-0.test--"
|
|
237
248
|
`);
|
|
238
249
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
239
|
-
|
|
240
|
-
await expect(
|
|
241
|
-
runWrangler(`pages functions build --build-output-directory=public`)
|
|
242
|
-
).rejects.toThrowError();
|
|
243
|
-
expect(std.err).toMatch(
|
|
244
|
-
/ENOENT: no such file or directory, scandir '.*functions'/
|
|
245
|
-
);
|
|
246
250
|
});
|
|
247
251
|
|
|
248
252
|
it("should include all external modules imported by _worker.js in the output bundle, when bundling _worker.js", async () => {
|
|
@@ -275,12 +279,10 @@ export default {
|
|
|
275
279
|
/* --------------------------------- */
|
|
276
280
|
/* Run cmd & make assertions */
|
|
277
281
|
/* --------------------------------- */
|
|
278
|
-
await runWrangler(
|
|
279
|
-
`pages functions build --build-output-directory=public --experimental-worker-bundle=true`
|
|
280
|
-
);
|
|
282
|
+
await runWrangler(`pages functions build --build-output-directory=public`);
|
|
281
283
|
|
|
282
284
|
// built to _worker.js by default
|
|
283
|
-
expect(existsSync("_worker.
|
|
285
|
+
expect(existsSync("_worker.bundle")).toBe(true);
|
|
284
286
|
expect(std.out).toMatchInlineSnapshot(`
|
|
285
287
|
"🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose
|
|
286
288
|
✨ Compiled Worker successfully"
|
|
@@ -289,12 +291,12 @@ export default {
|
|
|
289
291
|
// some values in workerBundleContents, such as the undici form boundary
|
|
290
292
|
// or the file hashes, are randomly generated. Let's replace them
|
|
291
293
|
// with static values so we can test the file contents
|
|
292
|
-
const workerBundleContents = readFileSync("_worker.
|
|
294
|
+
const workerBundleContents = readFileSync("_worker.bundle", "utf-8");
|
|
293
295
|
const workerBundleWithConstantData = replaceRandomWithConstantData(
|
|
294
296
|
workerBundleContents,
|
|
295
297
|
[
|
|
296
298
|
[/------formdata-undici-0.[0-9]*/g, "------formdata-undici-0.test"],
|
|
297
|
-
[/
|
|
299
|
+
[/functionsWorker-0.[0-9]*.js/g, "functionsWorker-0.test.js"],
|
|
298
300
|
[/[0-9a-z]*-greeting.wasm/g, "test-greeting.wasm"],
|
|
299
301
|
[/[0-9a-z]*-name.wasm/g, "test-name.wasm"],
|
|
300
302
|
]
|
|
@@ -305,7 +307,7 @@ export default {
|
|
|
305
307
|
`Content-Disposition: form-data; name="metadata"`
|
|
306
308
|
);
|
|
307
309
|
expect(workerBundleWithConstantData).toContain(
|
|
308
|
-
`{"main_module":"
|
|
310
|
+
`{"main_module":"functionsWorker-0.test.js"}`
|
|
309
311
|
);
|
|
310
312
|
|
|
311
313
|
// check we appended the wasm modules
|
|
@@ -321,7 +323,7 @@ export default {
|
|
|
321
323
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
322
324
|
});
|
|
323
325
|
|
|
324
|
-
it("should build _worker.js over /functions, if both are present
|
|
326
|
+
it("should build _worker.js over /functions, if both are present", async () => {
|
|
325
327
|
/* ---------------------------- */
|
|
326
328
|
/* Set up _worker.js */
|
|
327
329
|
/* ---------------------------- */
|
|
@@ -352,9 +354,7 @@ export default {
|
|
|
352
354
|
/* --------------------------------- */
|
|
353
355
|
/* Run cmd & make assertions */
|
|
354
356
|
/* --------------------------------- */
|
|
355
|
-
await runWrangler(
|
|
356
|
-
`pages functions build --outfile=public/_worker.bundle --experimental-worker-bundle=true`
|
|
357
|
-
);
|
|
357
|
+
await runWrangler(`pages functions build --outfile=public/_worker.bundle`);
|
|
358
358
|
|
|
359
359
|
expect(existsSync("public/_worker.bundle")).toBe(true);
|
|
360
360
|
expect(std.out).toMatchInlineSnapshot(`
|
|
@@ -370,7 +370,7 @@ export default {
|
|
|
370
370
|
workerBundleContents,
|
|
371
371
|
[
|
|
372
372
|
[/------formdata-undici-0.[0-9]*/g, "------formdata-undici-0.test"],
|
|
373
|
-
[/
|
|
373
|
+
[/functionsWorker-0.[0-9]*.js/g, "functionsWorker-0.test.js"],
|
|
374
374
|
]
|
|
375
375
|
);
|
|
376
376
|
|
|
@@ -378,9 +378,9 @@ export default {
|
|
|
378
378
|
"------formdata-undici-0.test
|
|
379
379
|
Content-Disposition: form-data; name=\\"metadata\\"
|
|
380
380
|
|
|
381
|
-
{\\"main_module\\":\\"
|
|
381
|
+
{\\"main_module\\":\\"functionsWorker-0.test.js\\"}
|
|
382
382
|
------formdata-undici-0.test
|
|
383
|
-
Content-Disposition: form-data; name=\\"
|
|
383
|
+
Content-Disposition: form-data; name=\\"functionsWorker-0.test.js\\"; filename=\\"functionsWorker-0.test.js\\"
|
|
384
384
|
Content-Type: application/javascript+module
|
|
385
385
|
|
|
386
386
|
// _worker.js
|
|
@@ -392,11 +392,61 @@ export default {
|
|
|
392
392
|
export {
|
|
393
393
|
worker_default as default
|
|
394
394
|
};
|
|
395
|
-
//# sourceMappingURL=bundledWorker-0.test.mjs.map
|
|
396
395
|
|
|
397
396
|
------formdata-undici-0.test--"
|
|
398
397
|
`);
|
|
399
398
|
|
|
400
399
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
401
400
|
});
|
|
401
|
+
|
|
402
|
+
it("should leave Node.js imports when the `nodejs_compat` compatibility flag is set", async () => {
|
|
403
|
+
mkdirSync("functions");
|
|
404
|
+
writeFileSync(
|
|
405
|
+
"functions/hello.js",
|
|
406
|
+
`
|
|
407
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
408
|
+
|
|
409
|
+
export async function onRequest() {
|
|
410
|
+
console.log(AsyncLocalStorage);
|
|
411
|
+
return new Response("Hello from Pages Functions");
|
|
412
|
+
}
|
|
413
|
+
`
|
|
414
|
+
);
|
|
415
|
+
|
|
416
|
+
await runWrangler(
|
|
417
|
+
`pages functions build --outfile=public/_worker.bundle --compatibility-flag=nodejs_compat`
|
|
418
|
+
);
|
|
419
|
+
|
|
420
|
+
expect(existsSync("public/_worker.bundle")).toBe(true);
|
|
421
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
422
|
+
"🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose
|
|
423
|
+
✨ Compiled Worker successfully"
|
|
424
|
+
`);
|
|
425
|
+
|
|
426
|
+
expect(readFileSync("public/_worker.bundle", "utf-8")).toContain(
|
|
427
|
+
`import { AsyncLocalStorage } from "node:async_hooks";`
|
|
428
|
+
);
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
it("should error at Node.js imports when the `nodejs_compat` compatibility flag is not set", async () => {
|
|
432
|
+
mkdirSync("functions");
|
|
433
|
+
writeFileSync(
|
|
434
|
+
"functions/hello.js",
|
|
435
|
+
`
|
|
436
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
437
|
+
|
|
438
|
+
export async function onRequest() {
|
|
439
|
+
console.log(AsyncLocalStorage);
|
|
440
|
+
return new Response("Hello from Pages Functions");
|
|
441
|
+
}
|
|
442
|
+
`
|
|
443
|
+
);
|
|
444
|
+
|
|
445
|
+
await expect(
|
|
446
|
+
runWrangler(`pages functions build --outfile=public/_worker.bundle`)
|
|
447
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
448
|
+
"Build failed with 1 error:
|
|
449
|
+
hello.js:2:36: ERROR: Could not resolve \\"node:async_hooks\\""
|
|
450
|
+
`);
|
|
451
|
+
});
|
|
402
452
|
});
|