wrangler 2.19.0 → 2.20.0
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/miniflare-dist/index.mjs +1 -1
- package/package.json +1 -1
- package/src/__tests__/configuration.test.ts +8 -0
- package/src/__tests__/pages/functions-build.test.ts +76 -0
- package/src/__tests__/pages-deployment-tail.test.ts +2 -0
- package/src/__tests__/publish.test.ts +1 -1
- package/src/__tests__/tail.test.ts +38 -7
- package/src/__tests__/tsconfig.tsbuildinfo +1 -1
- package/src/api/dev.ts +5 -0
- package/src/api/pages/create-worker-bundle-contents.ts +1 -0
- package/src/api/pages/publish.tsx +28 -12
- package/src/bundle.ts +28 -7
- package/src/config/environment.ts +7 -0
- package/src/config/validation.ts +27 -0
- package/src/create-worker-upload-form.ts +4 -0
- package/src/dev/dev.tsx +6 -1
- package/src/dev/local.tsx +4 -0
- package/src/dev/remote.tsx +3 -0
- package/src/dev/start-server.ts +50 -39
- package/src/dev/use-esbuild.ts +54 -42
- package/src/dev.tsx +9 -4
- package/src/entry.ts +8 -1
- package/src/init.ts +5 -0
- package/src/inspect.ts +107 -6
- package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -1
- package/src/pages/build.ts +30 -17
- package/src/pages/dev.ts +24 -6
- package/src/pages/functions/buildPlugin.ts +1 -0
- package/src/pages/functions/buildWorker.ts +59 -0
- package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
- package/src/publish/publish.ts +6 -1
- package/src/secret/index.ts +1 -0
- package/src/tail/createTail.ts +9 -0
- package/src/tail/printing.ts +10 -0
- package/src/traverse-module-graph.ts +1 -0
- package/src/utils/render.ts +1 -1
- package/src/worker.ts +5 -0
- package/wrangler-dist/cli.d.ts +12 -1
- package/wrangler-dist/cli.js +1296 -1084
package/miniflare-dist/index.mjs
CHANGED
|
@@ -180,7 +180,7 @@ function mergeHeaders(base, extra) {
|
|
|
180
180
|
});
|
|
181
181
|
}
|
|
182
182
|
function stripLeadingDoubleSlashes(location) {
|
|
183
|
-
return location.replace(/^(\/|%2F|%2f|%5C|%5c|%09|\s|\\)+(.*)
|
|
183
|
+
return location.replace(/^(\/|%2F|%2f|%5C|%5c|%09|\s|\\)+(.*)/, "/$2");
|
|
184
184
|
}
|
|
185
185
|
var OkResponse, MovedPermanentlyResponse, FoundResponse, NotModifiedResponse, PermanentRedirectResponse, NotFoundResponse, MethodNotAllowedResponse, NotAcceptableResponse, InternalServerErrorResponse, SeeOtherResponse, TemporaryRedirectResponse;
|
|
186
186
|
var init_responses = __esm({
|
package/package.json
CHANGED
|
@@ -84,6 +84,7 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
84
84
|
first_party_worker: undefined,
|
|
85
85
|
keep_vars: undefined,
|
|
86
86
|
logpush: undefined,
|
|
87
|
+
placement: undefined,
|
|
87
88
|
});
|
|
88
89
|
expect(diagnostics.hasErrors()).toBe(false);
|
|
89
90
|
expect(diagnostics.hasWarnings()).toBe(false);
|
|
@@ -955,6 +956,9 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
955
956
|
node_compat: true,
|
|
956
957
|
first_party_worker: true,
|
|
957
958
|
logpush: true,
|
|
959
|
+
placement: {
|
|
960
|
+
mode: "smart",
|
|
961
|
+
},
|
|
958
962
|
};
|
|
959
963
|
|
|
960
964
|
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
@@ -1030,6 +1034,9 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
1030
1034
|
node_compat: "INVALID",
|
|
1031
1035
|
first_party_worker: "INVALID",
|
|
1032
1036
|
logpush: "INVALID",
|
|
1037
|
+
placement: {
|
|
1038
|
+
mode: "INVALID",
|
|
1039
|
+
},
|
|
1033
1040
|
} as unknown as RawEnvironment;
|
|
1034
1041
|
|
|
1035
1042
|
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
@@ -1093,6 +1100,7 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
1093
1100
|
- Expected \\"name\\" to be of type string, alphanumeric and lowercase with dashes only but got 111.
|
|
1094
1101
|
- Expected \\"main\\" to be of type string but got 1333.
|
|
1095
1102
|
- Expected \\"usage_model\\" field to be one of [\\"bundled\\",\\"unbound\\"] but got \\"INVALID\\".
|
|
1103
|
+
- Expected \\"placement.mode\\" field to be one of [\\"off\\",\\"smart\\"] but got \\"INVALID\\".
|
|
1096
1104
|
- The field \\"define.DEF1\\" should be a string but got 1777.
|
|
1097
1105
|
- Expected \\"no_bundle\\" to be of type boolean but got \\"INVALID\\".
|
|
1098
1106
|
- Expected \\"minify\\" to be of type boolean but got \\"INVALID\\".
|
|
@@ -448,5 +448,81 @@ export default {
|
|
|
448
448
|
"Build failed with 1 error:
|
|
449
449
|
hello.js:2:36: ERROR: Could not resolve \\"node:async_hooks\\""
|
|
450
450
|
`);
|
|
451
|
+
expect(std.err).toContain(
|
|
452
|
+
'The package "node:async_hooks" wasn\'t found on the file system but is built into node.'
|
|
453
|
+
);
|
|
454
|
+
expect(std.err).toContain(
|
|
455
|
+
'Add the "nodejs_compat" compatibility flag to your Pages project to enable Node.js compatibility.'
|
|
456
|
+
);
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
it("should compile a _worker.js/ directory", async () => {
|
|
460
|
+
mkdirSync("public");
|
|
461
|
+
mkdirSync("public/_worker.js");
|
|
462
|
+
writeFileSync(
|
|
463
|
+
"public/_worker.js/index.js",
|
|
464
|
+
`
|
|
465
|
+
import { cat } from "./cat.js";
|
|
466
|
+
|
|
467
|
+
export default {
|
|
468
|
+
async fetch(request, env) {
|
|
469
|
+
return new Response("Hello from _worker.js/index.js" + cat);
|
|
470
|
+
},
|
|
471
|
+
};`
|
|
472
|
+
);
|
|
473
|
+
writeFileSync(
|
|
474
|
+
"public/_worker.js/cat.js",
|
|
475
|
+
`
|
|
476
|
+
export const cat = "cat";`
|
|
477
|
+
);
|
|
478
|
+
|
|
479
|
+
await runWrangler(`pages functions build --outfile=public/_worker.bundle`);
|
|
480
|
+
|
|
481
|
+
expect(existsSync("public/_worker.bundle")).toBe(true);
|
|
482
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
483
|
+
"🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose
|
|
484
|
+
✨ Compiled Worker successfully"
|
|
485
|
+
`);
|
|
486
|
+
|
|
487
|
+
const workerBundleContents = readFileSync("public/_worker.bundle", "utf-8");
|
|
488
|
+
const workerBundleWithConstantData = replaceRandomWithConstantData(
|
|
489
|
+
workerBundleContents,
|
|
490
|
+
[
|
|
491
|
+
[/------formdata-undici-0.[0-9]*/g, "------formdata-undici-0.test"],
|
|
492
|
+
[/bundledWorker-0.[0-9]*.mjs/g, "bundledWorker-0.test.mjs"],
|
|
493
|
+
[/bundledWorker-0.[0-9]*.map/g, "bundledWorker-0.test.map"],
|
|
494
|
+
]
|
|
495
|
+
);
|
|
496
|
+
|
|
497
|
+
expect(workerBundleWithConstantData).toMatchInlineSnapshot(`
|
|
498
|
+
"------formdata-undici-0.test
|
|
499
|
+
Content-Disposition: form-data; name=\\"metadata\\"
|
|
500
|
+
|
|
501
|
+
{\\"main_module\\":\\"bundledWorker-0.test.mjs\\"}
|
|
502
|
+
------formdata-undici-0.test
|
|
503
|
+
Content-Disposition: form-data; name=\\"bundledWorker-0.test.mjs\\"; filename=\\"bundledWorker-0.test.mjs\\"
|
|
504
|
+
Content-Type: application/javascript+module
|
|
505
|
+
|
|
506
|
+
import { cat } from \\"./cat.js\\";
|
|
507
|
+
var worker_default = {
|
|
508
|
+
async fetch(request, env) {
|
|
509
|
+
return new Response(\\"Hello from _worker.js/index.js\\" + cat);
|
|
510
|
+
}
|
|
511
|
+
};
|
|
512
|
+
export {
|
|
513
|
+
worker_default as default
|
|
514
|
+
};
|
|
515
|
+
//# sourceMappingURL=bundledWorker-0.test.mjs.map
|
|
516
|
+
|
|
517
|
+
------formdata-undici-0.test
|
|
518
|
+
Content-Disposition: form-data; name=\\"cat.js\\"; filename=\\"cat.js\\"
|
|
519
|
+
Content-Type: application/javascript+module
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
export const cat = \\"cat\\";
|
|
523
|
+
------formdata-undici-0.test--"
|
|
524
|
+
`);
|
|
525
|
+
|
|
526
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
451
527
|
});
|
|
452
528
|
});
|
|
@@ -13,6 +13,7 @@ import type {
|
|
|
13
13
|
ScheduledEvent,
|
|
14
14
|
AlarmEvent,
|
|
15
15
|
EmailEvent,
|
|
16
|
+
TailInfo,
|
|
16
17
|
} from "../tail/createTail";
|
|
17
18
|
import type { RequestInit } from "undici";
|
|
18
19
|
import type WebSocket from "ws";
|
|
@@ -655,6 +656,7 @@ function isRequest(
|
|
|
655
656
|
| RequestEvent
|
|
656
657
|
| AlarmEvent
|
|
657
658
|
| EmailEvent
|
|
659
|
+
| TailInfo
|
|
658
660
|
| undefined
|
|
659
661
|
| null
|
|
660
662
|
): event is RequestEvent {
|
|
@@ -7224,7 +7224,7 @@ export default{
|
|
|
7224
7224
|
expect(
|
|
7225
7225
|
esbuild.formatMessagesSync(err?.errors ?? [], { kind: "error" }).join()
|
|
7226
7226
|
).toMatch(
|
|
7227
|
-
/The package "path" wasn't found on the file system but is built into node\.\s+Add "node_compat = true" to your wrangler\.toml file to enable Node compatibility\./
|
|
7227
|
+
/The package "path" wasn't found on the file system but is built into node\.\s+Add "node_compat = true" to your wrangler\.toml file to enable Node.js compatibility\./
|
|
7228
7228
|
);
|
|
7229
7229
|
});
|
|
7230
7230
|
|
|
@@ -14,6 +14,7 @@ import type {
|
|
|
14
14
|
ScheduledEvent,
|
|
15
15
|
AlarmEvent,
|
|
16
16
|
EmailEvent,
|
|
17
|
+
TailInfo,
|
|
17
18
|
} from "../tail/createTail";
|
|
18
19
|
import type { RequestInit } from "undici";
|
|
19
20
|
import type WebSocket from "ws";
|
|
@@ -56,10 +57,10 @@ describe("tail", () => {
|
|
|
56
57
|
await runWrangler("tail durable-object--websocket--response");
|
|
57
58
|
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
58
59
|
expect(std.warn).toMatchInlineSnapshot(`
|
|
59
|
-
"[33mâ–² [43;33m[[43;30mWARNING[43;33m][0m [1mBeginning log collection requires restarting the Durable Objects associated with durable-object--websocket--response. Any WebSocket connections or other non-persisted state will be lost as part of this restart.[0m
|
|
60
|
+
"[33mâ–² [43;33m[[43;30mWARNING[43;33m][0m [1mBeginning log collection requires restarting the Durable Objects associated with durable-object--websocket--response. Any WebSocket connections or other non-persisted state will be lost as part of this restart.[0m
|
|
60
61
|
|
|
61
|
-
"
|
|
62
|
-
`);
|
|
62
|
+
"
|
|
63
|
+
`);
|
|
63
64
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
64
65
|
});
|
|
65
66
|
it("creates and then delete tails", async () => {
|
|
@@ -503,10 +504,31 @@ describe("tail", () => {
|
|
|
503
504
|
)
|
|
504
505
|
.replace(mockTailExpiration.toISOString(), "[mock expiration date]")
|
|
505
506
|
).toMatchInlineSnapshot(`
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
507
|
+
"Successfully created tail, expires at [mock expiration date]
|
|
508
|
+
Connected to test-worker, waiting for logs...
|
|
509
|
+
Email from:from@example.com to:to@example.com size:45416 @ [mock event timestamp] - Ok"
|
|
510
|
+
`);
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
it("logs tail overload message", async () => {
|
|
514
|
+
const api = mockWebsocketAPIs();
|
|
515
|
+
await runWrangler("tail test-worker --format pretty");
|
|
516
|
+
|
|
517
|
+
const event = generateTailInfo();
|
|
518
|
+
const message = generateMockEventMessage({ event });
|
|
519
|
+
const serializedMessage = serialize(message);
|
|
520
|
+
|
|
521
|
+
api.ws.send(serializedMessage);
|
|
522
|
+
expect(
|
|
523
|
+
std.out.replace(
|
|
524
|
+
mockTailExpiration.toISOString(),
|
|
525
|
+
"[mock expiration date]"
|
|
526
|
+
)
|
|
527
|
+
).toMatchInlineSnapshot(`
|
|
528
|
+
"Successfully created tail, expires at [mock expiration date]
|
|
529
|
+
Connected to test-worker, waiting for logs...
|
|
530
|
+
Tail is currently in sampling mode due to the high volume of messages. To prevent messages from being dropped consider adding filters."
|
|
531
|
+
`);
|
|
510
532
|
});
|
|
511
533
|
|
|
512
534
|
it("should not crash when the tail message has a void event", async () => {
|
|
@@ -675,6 +697,7 @@ function isRequest(
|
|
|
675
697
|
| RequestEvent
|
|
676
698
|
| AlarmEvent
|
|
677
699
|
| EmailEvent
|
|
700
|
+
| TailInfo
|
|
678
701
|
| undefined
|
|
679
702
|
| null
|
|
680
703
|
): event is RequestEvent {
|
|
@@ -956,3 +979,11 @@ function generateMockEmailEvent(opts?: Partial<EmailEvent>): EmailEvent {
|
|
|
956
979
|
rawSize: opts?.rawSize || mockEmailEventSize,
|
|
957
980
|
};
|
|
958
981
|
}
|
|
982
|
+
|
|
983
|
+
function generateTailInfo(): TailInfo {
|
|
984
|
+
return {
|
|
985
|
+
message:
|
|
986
|
+
"Tail is currently in sampling mode due to the high volume of messages. To prevent messages from being dropped consider adding filters.",
|
|
987
|
+
type: "overload",
|
|
988
|
+
};
|
|
989
|
+
}
|