wrangler 2.7.1 → 2.8.1
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/package.json +1 -1
- package/src/__tests__/d1/d1.test.ts +12 -8
- package/src/__tests__/deployments.test.ts +4 -4
- package/src/__tests__/helpers/mock-dialogs.ts +2 -0
- package/src/__tests__/helpers/mock-get-zone-from-host.ts +8 -5
- package/src/__tests__/helpers/mock-known-routes.ts +7 -2
- package/src/__tests__/helpers/mock-kv.ts +29 -16
- package/src/__tests__/helpers/mock-oauth-flow.ts +90 -98
- package/src/__tests__/helpers/msw/handlers/deployments.ts +20 -10
- package/src/__tests__/helpers/msw/handlers/namespaces.ts +18 -41
- package/src/__tests__/helpers/msw/handlers/r2.ts +14 -34
- package/src/__tests__/helpers/msw/handlers/script.ts +9 -28
- package/src/__tests__/helpers/msw/handlers/user.ts +13 -24
- package/src/__tests__/helpers/msw/handlers/zones.ts +6 -8
- package/src/__tests__/helpers/msw/index.ts +30 -1
- package/src/__tests__/init.test.ts +3 -14
- package/src/__tests__/jest.setup.ts +0 -23
- package/src/__tests__/pages-deployment-tail.test.ts +72 -1
- package/src/__tests__/pages.test.ts +52 -53
- package/src/__tests__/publish.test.ts +870 -522
- package/src/__tests__/r2.test.ts +11 -35
- package/src/__tests__/secret.test.ts +1 -9
- package/src/__tests__/tail.test.ts +72 -19
- package/src/__tests__/tsconfig.tsbuildinfo +1 -1
- package/src/__tests__/user.test.ts +5 -16
- package/src/__tests__/whoami.test.tsx +6 -17
- package/src/__tests__/worker-namespace.test.ts +56 -48
- package/src/api/index.ts +1 -0
- package/src/api/pages/index.ts +5 -0
- package/src/api/pages/publish.tsx +321 -0
- package/src/bundle.ts +62 -10
- package/src/cfetch/internal.ts +0 -3
- package/src/cli.ts +2 -2
- package/src/config/environment.ts +12 -10
- package/src/d1/backups.tsx +1 -5
- package/src/d1/utils.ts +1 -1
- package/src/deployments.ts +16 -6
- package/src/dev/local.tsx +1 -10
- package/src/dev/remote.tsx +2 -0
- package/src/dev/start-server.ts +5 -10
- package/src/dev/use-esbuild.ts +1 -0
- package/src/docs/index.ts +2 -1
- package/src/entry.ts +1 -2
- package/src/index.ts +1 -1
- package/src/init.ts +1 -1
- package/src/metrics/send-event.ts +2 -1
- package/src/pages/build.ts +4 -124
- package/src/pages/buildFunctions.ts +129 -0
- package/src/pages/dev.ts +68 -63
- package/src/pages/functions/buildPlugin.ts +3 -20
- package/src/pages/functions/buildWorker.ts +143 -21
- package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
- package/src/pages/publish.tsx +21 -220
- package/src/publish/publish.ts +30 -4
- package/src/tail/createTail.ts +28 -1
- package/src/tail/printing.ts +15 -0
- package/templates/checked-fetch.js +1 -3
- package/templates/d1-beta-facade.js +1 -1
- package/templates/middleware/loader-modules.ts +2 -0
- package/templates/tsconfig.tsbuildinfo +1 -1
- package/wrangler-dist/cli.d.ts +132 -10
- package/wrangler-dist/cli.js +3532 -3330
- package/src/__tests__/helpers/mock-cfetch.ts +0 -278
package/src/__tests__/r2.test.ts
CHANGED
|
@@ -4,7 +4,7 @@ import prettyBytes from "pretty-bytes";
|
|
|
4
4
|
import { MAX_UPLOAD_SIZE } from "../r2/constants";
|
|
5
5
|
import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
|
|
6
6
|
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
7
|
-
import { msw, mswSuccessR2handlers } from "./helpers/msw";
|
|
7
|
+
import { createFetchResult, msw, mswSuccessR2handlers } from "./helpers/msw";
|
|
8
8
|
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
9
9
|
import { runWrangler } from "./helpers/run-wrangler";
|
|
10
10
|
import type { R2BucketInfo } from "../r2/helpers";
|
|
@@ -60,12 +60,8 @@ describe("r2", () => {
|
|
|
60
60
|
expect(accountId).toEqual("some-account-id");
|
|
61
61
|
expect(await request.text()).toEqual("");
|
|
62
62
|
return response.once(
|
|
63
|
-
context.
|
|
64
|
-
|
|
65
|
-
success: true,
|
|
66
|
-
errors: [],
|
|
67
|
-
messages: [],
|
|
68
|
-
result: {
|
|
63
|
+
context.json(
|
|
64
|
+
createFetchResult({
|
|
69
65
|
buckets: [
|
|
70
66
|
{
|
|
71
67
|
name: "bucket-1-local-once",
|
|
@@ -76,8 +72,8 @@ describe("r2", () => {
|
|
|
76
72
|
creation_date: "01-01-2001",
|
|
77
73
|
},
|
|
78
74
|
],
|
|
79
|
-
}
|
|
80
|
-
|
|
75
|
+
})
|
|
76
|
+
)
|
|
81
77
|
);
|
|
82
78
|
}
|
|
83
79
|
)
|
|
@@ -155,15 +151,7 @@ describe("r2", () => {
|
|
|
155
151
|
const { accountId } = request.params;
|
|
156
152
|
expect(accountId).toEqual("some-account-id");
|
|
157
153
|
expect(await request.json()).toEqual({ name: "testBucket" });
|
|
158
|
-
return response.once(
|
|
159
|
-
context.status(200),
|
|
160
|
-
context.json({
|
|
161
|
-
success: true,
|
|
162
|
-
errors: [],
|
|
163
|
-
messages: [],
|
|
164
|
-
result: {},
|
|
165
|
-
})
|
|
166
|
-
);
|
|
154
|
+
return response.once(context.json(createFetchResult({})));
|
|
167
155
|
}
|
|
168
156
|
)
|
|
169
157
|
);
|
|
@@ -245,15 +233,7 @@ describe("r2", () => {
|
|
|
245
233
|
"Bearer some-api-token"
|
|
246
234
|
);
|
|
247
235
|
|
|
248
|
-
return response.once(
|
|
249
|
-
context.status(200),
|
|
250
|
-
context.json({
|
|
251
|
-
success: true,
|
|
252
|
-
errors: [],
|
|
253
|
-
messages: [],
|
|
254
|
-
result: null,
|
|
255
|
-
})
|
|
256
|
-
);
|
|
236
|
+
return response.once(context.json(createFetchResult(null)));
|
|
257
237
|
}
|
|
258
238
|
)
|
|
259
239
|
);
|
|
@@ -333,17 +313,13 @@ describe("r2", () => {
|
|
|
333
313
|
}
|
|
334
314
|
`);
|
|
335
315
|
return response.once(
|
|
336
|
-
context.
|
|
337
|
-
|
|
338
|
-
success: true,
|
|
339
|
-
errors: [],
|
|
340
|
-
messages: [],
|
|
341
|
-
result: {
|
|
316
|
+
context.json(
|
|
317
|
+
createFetchResult({
|
|
342
318
|
accountId: "some-account-id",
|
|
343
319
|
bucketName: "bucketName-object-test",
|
|
344
320
|
objectName: "wormhole-img.png",
|
|
345
|
-
}
|
|
346
|
-
|
|
321
|
+
})
|
|
322
|
+
)
|
|
347
323
|
);
|
|
348
324
|
}
|
|
349
325
|
)
|
|
@@ -6,7 +6,7 @@ import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
|
|
|
6
6
|
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
7
7
|
import { mockConfirm, mockPrompt, clearDialogs } from "./helpers/mock-dialogs";
|
|
8
8
|
import { useMockIsTTY } from "./helpers/mock-istty";
|
|
9
|
-
|
|
9
|
+
import { mockGetMembershipsFail } from "./helpers/mock-oauth-flow";
|
|
10
10
|
import { useMockStdin } from "./helpers/mock-stdin";
|
|
11
11
|
import { msw } from "./helpers/msw";
|
|
12
12
|
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
@@ -21,14 +21,6 @@ function createFetchResult(result: unknown, success = true) {
|
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export function mockGetMembershipsFail() {
|
|
25
|
-
msw.use(
|
|
26
|
-
rest.get("*/memberships", (req, res, ctx) => {
|
|
27
|
-
return res.once(ctx.json(createFetchResult([], false)));
|
|
28
|
-
})
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
24
|
export function mockGetMemberships(
|
|
33
25
|
accounts: { id: string; account: { id: string; name: string } }[]
|
|
34
26
|
) {
|
|
@@ -5,7 +5,7 @@ import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
|
|
|
5
5
|
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
6
6
|
import { mockConfirm, clearDialogs } from "./helpers/mock-dialogs";
|
|
7
7
|
import { useMockIsTTY } from "./helpers/mock-istty";
|
|
8
|
-
import { msw, mswSucessScriptHandlers } from "./helpers/msw";
|
|
8
|
+
import { createFetchResult, msw, mswSucessScriptHandlers } from "./helpers/msw";
|
|
9
9
|
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
10
10
|
import { runWrangler } from "./helpers/run-wrangler";
|
|
11
11
|
import type {
|
|
@@ -13,6 +13,7 @@ import type {
|
|
|
13
13
|
RequestEvent,
|
|
14
14
|
ScheduledEvent,
|
|
15
15
|
AlarmEvent,
|
|
16
|
+
EmailEvent,
|
|
16
17
|
} from "../tail/createTail";
|
|
17
18
|
import type { RequestInit } from "undici";
|
|
18
19
|
import type WebSocket from "ws";
|
|
@@ -404,6 +405,18 @@ describe("tail", () => {
|
|
|
404
405
|
expect(std.out).toMatch(deserializeToJson(serializedMessage));
|
|
405
406
|
});
|
|
406
407
|
|
|
408
|
+
it("logs email messages in json format", async () => {
|
|
409
|
+
const api = mockWebsocketAPIs();
|
|
410
|
+
await runWrangler("tail test-worker --format json");
|
|
411
|
+
|
|
412
|
+
const event = generateMockEmailEvent();
|
|
413
|
+
const message = generateMockEventMessage({ event });
|
|
414
|
+
const serializedMessage = serialize(message);
|
|
415
|
+
|
|
416
|
+
api.ws.send(serializedMessage);
|
|
417
|
+
expect(std.out).toMatch(deserializeToJson(serializedMessage));
|
|
418
|
+
});
|
|
419
|
+
|
|
407
420
|
it("logs request messages in pretty format", async () => {
|
|
408
421
|
const api = mockWebsocketAPIs();
|
|
409
422
|
await runWrangler("tail test-worker --format pretty");
|
|
@@ -473,6 +486,29 @@ describe("tail", () => {
|
|
|
473
486
|
`);
|
|
474
487
|
});
|
|
475
488
|
|
|
489
|
+
it("logs email messages in pretty format", async () => {
|
|
490
|
+
const api = mockWebsocketAPIs();
|
|
491
|
+
await runWrangler("tail test-worker --format pretty");
|
|
492
|
+
|
|
493
|
+
const event = generateMockEmailEvent();
|
|
494
|
+
const message = generateMockEventMessage({ event });
|
|
495
|
+
const serializedMessage = serialize(message);
|
|
496
|
+
|
|
497
|
+
api.ws.send(serializedMessage);
|
|
498
|
+
expect(
|
|
499
|
+
std.out
|
|
500
|
+
.replace(
|
|
501
|
+
new Date(mockEventTimestamp).toLocaleString(),
|
|
502
|
+
"[mock event timestamp]"
|
|
503
|
+
)
|
|
504
|
+
.replace(mockTailExpiration.toISOString(), "[mock expiration date]")
|
|
505
|
+
).toMatchInlineSnapshot(`
|
|
506
|
+
"Successfully created tail, expires at [mock expiration date]
|
|
507
|
+
Connected to test-worker, waiting for logs...
|
|
508
|
+
Email from:${mockEmailEventFrom} to:${mockEmailEventTo} size:${mockEmailEventSize} @ [mock event timestamp] - Ok"
|
|
509
|
+
`);
|
|
510
|
+
});
|
|
511
|
+
|
|
476
512
|
it("should not crash when the tail message has a void event", async () => {
|
|
477
513
|
const api = mockWebsocketAPIs();
|
|
478
514
|
await runWrangler("tail test-worker --format pretty");
|
|
@@ -634,7 +670,13 @@ function serialize(message: TailEventMessage): WebSocket.RawData {
|
|
|
634
670
|
* @returns true if `event` is a RequestEvent
|
|
635
671
|
*/
|
|
636
672
|
function isRequest(
|
|
637
|
-
event:
|
|
673
|
+
event:
|
|
674
|
+
| ScheduledEvent
|
|
675
|
+
| RequestEvent
|
|
676
|
+
| AlarmEvent
|
|
677
|
+
| EmailEvent
|
|
678
|
+
| undefined
|
|
679
|
+
| null
|
|
638
680
|
): event is RequestEvent {
|
|
639
681
|
return Boolean(event && "request" in event);
|
|
640
682
|
}
|
|
@@ -701,17 +743,13 @@ function mockCreateTailRequest(
|
|
|
701
743
|
expect(req.params.envName).toEqual(env);
|
|
702
744
|
}
|
|
703
745
|
return res.once(
|
|
704
|
-
ctx.
|
|
705
|
-
|
|
706
|
-
success: true,
|
|
707
|
-
errors: [],
|
|
708
|
-
messages: [],
|
|
709
|
-
result: {
|
|
746
|
+
ctx.json(
|
|
747
|
+
createFetchResult({
|
|
710
748
|
url: websocketURL,
|
|
711
749
|
id: "tail-id",
|
|
712
750
|
expires_at: mockTailExpiration,
|
|
713
|
-
}
|
|
714
|
-
|
|
751
|
+
})
|
|
752
|
+
)
|
|
715
753
|
);
|
|
716
754
|
}
|
|
717
755
|
)
|
|
@@ -735,6 +773,21 @@ const mockEventTimestamp = 1645454470467;
|
|
|
735
773
|
*/
|
|
736
774
|
const mockEventScheduledTime = new Date(mockEventTimestamp).toISOString();
|
|
737
775
|
|
|
776
|
+
/**
|
|
777
|
+
* Default value for email event from
|
|
778
|
+
*/
|
|
779
|
+
const mockEmailEventFrom = "from@example.com";
|
|
780
|
+
|
|
781
|
+
/**
|
|
782
|
+
* Default value for email event to
|
|
783
|
+
*/
|
|
784
|
+
const mockEmailEventTo = "to@example.com";
|
|
785
|
+
|
|
786
|
+
/**
|
|
787
|
+
* Default value for email event mail size
|
|
788
|
+
*/
|
|
789
|
+
const mockEmailEventSize = 45416;
|
|
790
|
+
|
|
738
791
|
/**
|
|
739
792
|
* Mock out the API hit during Tail deletion
|
|
740
793
|
*
|
|
@@ -761,15 +814,7 @@ function mockDeleteTailRequest(
|
|
|
761
814
|
}
|
|
762
815
|
}
|
|
763
816
|
expect(req.params.tailId).toEqual("tail-id");
|
|
764
|
-
return res(
|
|
765
|
-
ctx.status(200),
|
|
766
|
-
ctx.json({
|
|
767
|
-
success: true,
|
|
768
|
-
errors: [],
|
|
769
|
-
messages: [],
|
|
770
|
-
result: null,
|
|
771
|
-
})
|
|
772
|
-
);
|
|
817
|
+
return res(ctx.json(createFetchResult(null)));
|
|
773
818
|
}
|
|
774
819
|
)
|
|
775
820
|
);
|
|
@@ -903,3 +948,11 @@ function generateMockAlarmEvent(opts?: Partial<AlarmEvent>): AlarmEvent {
|
|
|
903
948
|
scheduledTime: opts?.scheduledTime || mockEventScheduledTime,
|
|
904
949
|
};
|
|
905
950
|
}
|
|
951
|
+
|
|
952
|
+
function generateMockEmailEvent(opts?: Partial<EmailEvent>): EmailEvent {
|
|
953
|
+
return {
|
|
954
|
+
mailFrom: opts?.mailFrom || mockEmailEventFrom,
|
|
955
|
+
rcptTo: opts?.rcptTo || mockEmailEventTo,
|
|
956
|
+
rawSize: opts?.rawSize || mockEmailEventSize,
|
|
957
|
+
};
|
|
958
|
+
}
|