wrangler 2.2.0 → 2.2.2
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 +2 -1
- package/src/__tests__/deployments.test.ts +2 -2
- package/src/__tests__/pages.test.ts +176 -12
- package/src/__tests__/publish.test.ts +1 -1
- package/src/__tests__/r2.test.ts +18 -1
- package/src/__tests__/type-generation.test.ts +2 -2
- package/src/bundle.ts +46 -16
- package/src/deployments.ts +1 -1
- package/src/pages/build.tsx +33 -1
- package/src/pages/dev.tsx +22 -7
- package/src/pages/functions/buildPlugin.ts +83 -87
- package/src/pages/functions/buildWorker.ts +119 -110
- package/src/pages/publish.tsx +16 -6
- package/src/pages/utils.ts +2 -2
- package/src/publish/publish.ts +3 -2
- package/src/r2/constants.ts +4 -0
- package/src/r2/index.ts +12 -0
- package/src/type-generation.ts +1 -1
- package/wrangler-dist/cli.js +518 -424
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wrangler",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.2",
|
|
4
4
|
"description": "Command-line interface for all things Cloudflare Workers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"wrangler",
|
|
@@ -114,6 +114,7 @@
|
|
|
114
114
|
"xxhash-wasm": "^1.0.1"
|
|
115
115
|
},
|
|
116
116
|
"devDependencies": {
|
|
117
|
+
"@cloudflare/types": "^6.18.4",
|
|
117
118
|
"@databases/split-sql-query": "^1.0.3",
|
|
118
119
|
"@databases/sql": "^3.2.0",
|
|
119
120
|
"@iarna/toml": "^3.0.0",
|
|
@@ -66,7 +66,7 @@ describe("deployments", () => {
|
|
|
66
66
|
Created on: 2021-01-01T00:00:00.000000Z
|
|
67
67
|
Author: Jean-Luc-Picard@federation.org
|
|
68
68
|
Source: Wrangler
|
|
69
|
-
🟩Active"
|
|
69
|
+
🟩 Active"
|
|
70
70
|
`);
|
|
71
71
|
});
|
|
72
72
|
|
|
@@ -85,7 +85,7 @@ describe("deployments", () => {
|
|
|
85
85
|
Created on: 2021-01-01T00:00:00.000000Z
|
|
86
86
|
Author: Jean-Luc-Picard@federation.org
|
|
87
87
|
Source: Wrangler
|
|
88
|
-
🟩Active"
|
|
88
|
+
🟩 Active"
|
|
89
89
|
`);
|
|
90
90
|
});
|
|
91
91
|
});
|
|
@@ -401,6 +401,17 @@ describe("pages", () => {
|
|
|
401
401
|
}
|
|
402
402
|
);
|
|
403
403
|
|
|
404
|
+
setMockResponse(
|
|
405
|
+
"/accounts/:accountId/pages/projects/foo",
|
|
406
|
+
"GET",
|
|
407
|
+
async ([_url, accountId]) => {
|
|
408
|
+
assertLater(() => {
|
|
409
|
+
expect(accountId).toEqual("some-account-id");
|
|
410
|
+
});
|
|
411
|
+
return { deployment_configs: { production: {}, preview: {} } };
|
|
412
|
+
}
|
|
413
|
+
);
|
|
414
|
+
|
|
404
415
|
await runWrangler("pages publish . --project-name=foo");
|
|
405
416
|
|
|
406
417
|
expect(std.out).toMatchInlineSnapshot(`
|
|
@@ -470,6 +481,17 @@ describe("pages", () => {
|
|
|
470
481
|
}
|
|
471
482
|
);
|
|
472
483
|
|
|
484
|
+
setMockResponse(
|
|
485
|
+
"/accounts/:accountId/pages/projects/foo",
|
|
486
|
+
"GET",
|
|
487
|
+
async ([_url, accountId]) => {
|
|
488
|
+
assertLater(() => {
|
|
489
|
+
expect(accountId).toEqual("some-account-id");
|
|
490
|
+
});
|
|
491
|
+
return { deployment_configs: { production: {}, preview: {} } };
|
|
492
|
+
}
|
|
493
|
+
);
|
|
494
|
+
|
|
473
495
|
await runWrangler("pages publish . --project-name=foo");
|
|
474
496
|
|
|
475
497
|
// Assert two identical requests
|
|
@@ -564,6 +586,17 @@ describe("pages", () => {
|
|
|
564
586
|
}
|
|
565
587
|
);
|
|
566
588
|
|
|
589
|
+
setMockResponse(
|
|
590
|
+
"/accounts/:accountId/pages/projects/foo",
|
|
591
|
+
"GET",
|
|
592
|
+
async ([_url, accountId]) => {
|
|
593
|
+
assertLater(() => {
|
|
594
|
+
expect(accountId).toEqual("some-account-id");
|
|
595
|
+
});
|
|
596
|
+
return { deployment_configs: { production: {}, preview: {} } };
|
|
597
|
+
}
|
|
598
|
+
);
|
|
599
|
+
|
|
567
600
|
await runWrangler("pages publish . --project-name=foo");
|
|
568
601
|
|
|
569
602
|
// Assert two requests
|
|
@@ -658,6 +691,17 @@ describe("pages", () => {
|
|
|
658
691
|
}
|
|
659
692
|
);
|
|
660
693
|
|
|
694
|
+
setMockResponse(
|
|
695
|
+
"/accounts/:accountId/pages/projects/foo",
|
|
696
|
+
"GET",
|
|
697
|
+
async ([_url, accountId]) => {
|
|
698
|
+
assertLater(() => {
|
|
699
|
+
expect(accountId).toEqual("some-account-id");
|
|
700
|
+
});
|
|
701
|
+
return { deployment_configs: { production: {}, preview: {} } };
|
|
702
|
+
}
|
|
703
|
+
);
|
|
704
|
+
|
|
661
705
|
await runWrangler("pages publish . --project-name=foo");
|
|
662
706
|
|
|
663
707
|
// We have 3 buckets, so expect 3 uploads
|
|
@@ -772,6 +816,17 @@ describe("pages", () => {
|
|
|
772
816
|
}
|
|
773
817
|
);
|
|
774
818
|
|
|
819
|
+
setMockResponse(
|
|
820
|
+
"/accounts/:accountId/pages/projects/foo",
|
|
821
|
+
"GET",
|
|
822
|
+
async ([_url, accountId]) => {
|
|
823
|
+
assertLater(() => {
|
|
824
|
+
expect(accountId).toEqual("some-account-id");
|
|
825
|
+
});
|
|
826
|
+
return { deployment_configs: { production: {}, preview: {} } };
|
|
827
|
+
}
|
|
828
|
+
);
|
|
829
|
+
|
|
775
830
|
await runWrangler(`pages publish public --project-name=foo`);
|
|
776
831
|
|
|
777
832
|
// We have 3 buckets, so expect 3 uploads
|
|
@@ -886,6 +941,17 @@ describe("pages", () => {
|
|
|
886
941
|
}
|
|
887
942
|
);
|
|
888
943
|
|
|
944
|
+
setMockResponse(
|
|
945
|
+
"/accounts/:accountId/pages/projects/foo",
|
|
946
|
+
"GET",
|
|
947
|
+
async ([_url, accountId]) => {
|
|
948
|
+
assertLater(() => {
|
|
949
|
+
expect(accountId).toEqual("some-account-id");
|
|
950
|
+
});
|
|
951
|
+
return { deployment_configs: { production: {}, preview: {} } };
|
|
952
|
+
}
|
|
953
|
+
);
|
|
954
|
+
|
|
889
955
|
chdir("public");
|
|
890
956
|
await runWrangler(`pages publish . --project-name=foo`);
|
|
891
957
|
|
|
@@ -988,6 +1054,17 @@ describe("pages", () => {
|
|
|
988
1054
|
})
|
|
989
1055
|
);
|
|
990
1056
|
|
|
1057
|
+
setMockResponse(
|
|
1058
|
+
"/accounts/:accountId/pages/projects/foo",
|
|
1059
|
+
"GET",
|
|
1060
|
+
async ([_url, accountId]) => {
|
|
1061
|
+
assertLater(() => {
|
|
1062
|
+
expect(accountId).toEqual("some-account-id");
|
|
1063
|
+
});
|
|
1064
|
+
return { deployment_configs: { production: {}, preview: {} } };
|
|
1065
|
+
}
|
|
1066
|
+
);
|
|
1067
|
+
|
|
991
1068
|
await runWrangler("pages publish . --project-name=foo");
|
|
992
1069
|
|
|
993
1070
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
@@ -1132,6 +1209,17 @@ describe("pages", () => {
|
|
|
1132
1209
|
}
|
|
1133
1210
|
);
|
|
1134
1211
|
|
|
1212
|
+
setMockResponse(
|
|
1213
|
+
"/accounts/:accountId/pages/projects/foo",
|
|
1214
|
+
"GET",
|
|
1215
|
+
async ([_url, accountId]) => {
|
|
1216
|
+
assertLater(() => {
|
|
1217
|
+
expect(accountId).toEqual("some-account-id");
|
|
1218
|
+
});
|
|
1219
|
+
return { deployment_configs: { production: {}, preview: {} } };
|
|
1220
|
+
}
|
|
1221
|
+
);
|
|
1222
|
+
|
|
1135
1223
|
await runWrangler("pages publish public --project-name=foo");
|
|
1136
1224
|
|
|
1137
1225
|
expect(std.out).toMatchInlineSnapshot(`
|
|
@@ -1238,6 +1326,17 @@ describe("pages", () => {
|
|
|
1238
1326
|
}
|
|
1239
1327
|
);
|
|
1240
1328
|
|
|
1329
|
+
setMockResponse(
|
|
1330
|
+
"/accounts/:accountId/pages/projects/foo",
|
|
1331
|
+
"GET",
|
|
1332
|
+
async ([_url, accountId]) => {
|
|
1333
|
+
assertLater(() => {
|
|
1334
|
+
expect(accountId).toEqual("some-account-id");
|
|
1335
|
+
});
|
|
1336
|
+
return { deployment_configs: { production: {}, preview: {} } };
|
|
1337
|
+
}
|
|
1338
|
+
);
|
|
1339
|
+
|
|
1241
1340
|
await runWrangler("pages publish public --project-name=foo");
|
|
1242
1341
|
|
|
1243
1342
|
expect(std.out).toMatchInlineSnapshot(`
|
|
@@ -1389,6 +1488,17 @@ describe("pages", () => {
|
|
|
1389
1488
|
}
|
|
1390
1489
|
);
|
|
1391
1490
|
|
|
1491
|
+
setMockResponse(
|
|
1492
|
+
"/accounts/:accountId/pages/projects/foo",
|
|
1493
|
+
"GET",
|
|
1494
|
+
async ([_url, accountId]) => {
|
|
1495
|
+
assertLater(() => {
|
|
1496
|
+
expect(accountId).toEqual("some-account-id");
|
|
1497
|
+
});
|
|
1498
|
+
return { deployment_configs: { production: {}, preview: {} } };
|
|
1499
|
+
}
|
|
1500
|
+
);
|
|
1501
|
+
|
|
1392
1502
|
await runWrangler("pages publish public --project-name=foo");
|
|
1393
1503
|
|
|
1394
1504
|
expect(std.out).toMatchInlineSnapshot(`
|
|
@@ -1475,6 +1585,17 @@ describe("pages", () => {
|
|
|
1475
1585
|
});
|
|
1476
1586
|
});
|
|
1477
1587
|
|
|
1588
|
+
setMockResponse(
|
|
1589
|
+
"/accounts/:accountId/pages/projects/foo",
|
|
1590
|
+
"GET",
|
|
1591
|
+
async ([_url, accountId]) => {
|
|
1592
|
+
assertLater(() => {
|
|
1593
|
+
expect(accountId).toEqual("some-account-id");
|
|
1594
|
+
});
|
|
1595
|
+
return { deployment_configs: { production: {}, preview: {} } };
|
|
1596
|
+
}
|
|
1597
|
+
);
|
|
1598
|
+
|
|
1478
1599
|
await expect(runWrangler("pages publish public --project-name=foo"))
|
|
1479
1600
|
.rejects
|
|
1480
1601
|
.toThrow(`Invalid _routes.json file found at: public/_routes.json
|
|
@@ -1627,6 +1748,17 @@ and that at least one include rule is provided.
|
|
|
1627
1748
|
}
|
|
1628
1749
|
);
|
|
1629
1750
|
|
|
1751
|
+
setMockResponse(
|
|
1752
|
+
"/accounts/:accountId/pages/projects/foo",
|
|
1753
|
+
"GET",
|
|
1754
|
+
async ([_url, accountId]) => {
|
|
1755
|
+
assertLater(() => {
|
|
1756
|
+
expect(accountId).toEqual("some-account-id");
|
|
1757
|
+
});
|
|
1758
|
+
return { deployment_configs: { production: {}, preview: {} } };
|
|
1759
|
+
}
|
|
1760
|
+
);
|
|
1761
|
+
|
|
1630
1762
|
await runWrangler("pages publish public --project-name=foo");
|
|
1631
1763
|
|
|
1632
1764
|
expect(std.out).toMatchInlineSnapshot(`
|
|
@@ -1712,6 +1844,17 @@ and that at least one include rule is provided.
|
|
|
1712
1844
|
});
|
|
1713
1845
|
});
|
|
1714
1846
|
|
|
1847
|
+
setMockResponse(
|
|
1848
|
+
"/accounts/:accountId/pages/projects/foo",
|
|
1849
|
+
"GET",
|
|
1850
|
+
async ([_url, accountId]) => {
|
|
1851
|
+
assertLater(() => {
|
|
1852
|
+
expect(accountId).toEqual("some-account-id");
|
|
1853
|
+
});
|
|
1854
|
+
return { deployment_configs: { production: {}, preview: {} } };
|
|
1855
|
+
}
|
|
1856
|
+
);
|
|
1857
|
+
|
|
1715
1858
|
await expect(runWrangler("pages publish public --project-name=foo"))
|
|
1716
1859
|
.rejects
|
|
1717
1860
|
.toThrow(`Invalid _routes.json file found at: public/_routes.json
|
|
@@ -1829,6 +1972,17 @@ and that at least one include rule is provided.
|
|
|
1829
1972
|
}
|
|
1830
1973
|
);
|
|
1831
1974
|
|
|
1975
|
+
setMockResponse(
|
|
1976
|
+
"/accounts/:accountId/pages/projects/foo",
|
|
1977
|
+
"GET",
|
|
1978
|
+
async ([_url, accountId]) => {
|
|
1979
|
+
assertLater(() => {
|
|
1980
|
+
expect(accountId).toEqual("some-account-id");
|
|
1981
|
+
});
|
|
1982
|
+
return { deployment_configs: { production: {}, preview: {} } };
|
|
1983
|
+
}
|
|
1984
|
+
);
|
|
1985
|
+
|
|
1832
1986
|
await runWrangler("pages publish public --project-name=foo");
|
|
1833
1987
|
|
|
1834
1988
|
expect(std.out).toMatchInlineSnapshot(`
|
|
@@ -1957,29 +2111,37 @@ and that at least one include rule is provided.
|
|
|
1957
2111
|
assertLater(() => {
|
|
1958
2112
|
expect(requests.length).toBe(3);
|
|
1959
2113
|
|
|
1960
|
-
|
|
2114
|
+
const sortedRequests = requests.sort((a, b) => {
|
|
2115
|
+
return (JSON.parse(a.body as string)[0].key as string).localeCompare(
|
|
2116
|
+
JSON.parse(b.body as string)[0].key as string
|
|
2117
|
+
);
|
|
2118
|
+
});
|
|
2119
|
+
|
|
2120
|
+
expect(sortedRequests[0].headers).toMatchObject({
|
|
1961
2121
|
Authorization: "Bearer <<funfetti-auth-jwt>>",
|
|
1962
2122
|
});
|
|
1963
2123
|
|
|
1964
2124
|
let body = JSON.parse(
|
|
1965
|
-
|
|
2125
|
+
sortedRequests[0].body as string
|
|
1966
2126
|
) as UploadPayloadFile[];
|
|
1967
2127
|
expect(body).toMatchObject([
|
|
1968
2128
|
{
|
|
1969
|
-
key: "
|
|
1970
|
-
value: Buffer.from("
|
|
2129
|
+
key: "09a79777abda8ccc8bdd51dd3ff8e9e9",
|
|
2130
|
+
value: Buffer.from("func").toString("base64"),
|
|
1971
2131
|
metadata: {
|
|
1972
|
-
contentType: "application/
|
|
2132
|
+
contentType: "application/javascript",
|
|
1973
2133
|
},
|
|
1974
2134
|
base64: true,
|
|
1975
2135
|
},
|
|
1976
2136
|
]);
|
|
1977
2137
|
|
|
1978
|
-
expect(
|
|
2138
|
+
expect(sortedRequests[1].headers).toMatchObject({
|
|
1979
2139
|
Authorization: "Bearer <<funfetti-auth-jwt>>",
|
|
1980
2140
|
});
|
|
1981
2141
|
|
|
1982
|
-
body = JSON.parse(
|
|
2142
|
+
body = JSON.parse(
|
|
2143
|
+
sortedRequests[1].body as string
|
|
2144
|
+
) as UploadPayloadFile[];
|
|
1983
2145
|
expect(body).toMatchObject([
|
|
1984
2146
|
{
|
|
1985
2147
|
key: "2082190357cfd3617ccfe04f340c6247",
|
|
@@ -1991,17 +2153,19 @@ and that at least one include rule is provided.
|
|
|
1991
2153
|
},
|
|
1992
2154
|
]);
|
|
1993
2155
|
|
|
1994
|
-
expect(
|
|
2156
|
+
expect(sortedRequests[2].headers).toMatchObject({
|
|
1995
2157
|
Authorization: "Bearer <<funfetti-auth-jwt>>",
|
|
1996
2158
|
});
|
|
1997
2159
|
|
|
1998
|
-
body = JSON.parse(
|
|
2160
|
+
body = JSON.parse(
|
|
2161
|
+
sortedRequests[2].body as string
|
|
2162
|
+
) as UploadPayloadFile[];
|
|
1999
2163
|
expect(body).toMatchObject([
|
|
2000
2164
|
{
|
|
2001
|
-
key: "
|
|
2002
|
-
value: Buffer.from("
|
|
2165
|
+
key: "95dedb64e6d4940fc2e0f11f711cc2f4",
|
|
2166
|
+
value: Buffer.from("headersfile").toString("base64"),
|
|
2003
2167
|
metadata: {
|
|
2004
|
-
contentType: "application/
|
|
2168
|
+
contentType: "application/octet-stream",
|
|
2005
2169
|
},
|
|
2006
2170
|
base64: true,
|
|
2007
2171
|
},
|
|
@@ -7607,7 +7607,7 @@ function mockGetQueueMissing(expectedQueueName: string) {
|
|
|
7607
7607
|
`/accounts/:accountId/workers/queues/${expectedQueueName}`,
|
|
7608
7608
|
"GET",
|
|
7609
7609
|
([_url, _accountId]) => {
|
|
7610
|
-
throw { code:
|
|
7610
|
+
throw { code: 11000 };
|
|
7611
7611
|
}
|
|
7612
7612
|
);
|
|
7613
7613
|
return requests;
|
package/src/__tests__/r2.test.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
import { rest } from "msw";
|
|
3
|
+
import prettyBytes from "pretty-bytes";
|
|
4
|
+
import { MAX_UPLOAD_SIZE } from "../r2/constants";
|
|
3
5
|
import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
|
|
4
6
|
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
5
7
|
import { msw, mswSuccessR2handlers } from "./helpers/msw";
|
|
@@ -276,7 +278,7 @@ describe("r2", () => {
|
|
|
276
278
|
`);
|
|
277
279
|
});
|
|
278
280
|
|
|
279
|
-
it("should upload R2 object
|
|
281
|
+
it("should upload R2 object to bucket", async () => {
|
|
280
282
|
fs.writeFileSync("wormhole-img.png", "passageway");
|
|
281
283
|
await runWrangler(
|
|
282
284
|
`r2 object put bucketName-object-test/wormhole-img.png --file ./wormhole-img.png`
|
|
@@ -288,6 +290,21 @@ describe("r2", () => {
|
|
|
288
290
|
`);
|
|
289
291
|
});
|
|
290
292
|
|
|
293
|
+
it("should fail to upload R2 object to bucket if too large", async () => {
|
|
294
|
+
const TOO_BIG_FILE_SIZE = MAX_UPLOAD_SIZE + 1024 * 1024;
|
|
295
|
+
fs.writeFileSync("wormhole-img.png", Buffer.alloc(TOO_BIG_FILE_SIZE));
|
|
296
|
+
await expect(
|
|
297
|
+
runWrangler(
|
|
298
|
+
`r2 object put bucketName-object-test/wormhole-img.png --file ./wormhole-img.png`
|
|
299
|
+
)
|
|
300
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
301
|
+
"Error: Wrangler only supports uploading files up to ${prettyBytes(
|
|
302
|
+
MAX_UPLOAD_SIZE
|
|
303
|
+
)} in size
|
|
304
|
+
wormhole-img.png is ${prettyBytes(TOO_BIG_FILE_SIZE)} in size"
|
|
305
|
+
`);
|
|
306
|
+
});
|
|
307
|
+
|
|
291
308
|
it("should pass all fetch option flags into requestInit & check request inputs", async () => {
|
|
292
309
|
msw.use(
|
|
293
310
|
rest.put(
|
|
@@ -100,8 +100,8 @@ describe("generateTypes()", () => {
|
|
|
100
100
|
expect(std.out).toMatchInlineSnapshot(`
|
|
101
101
|
"interface Env {
|
|
102
102
|
TEST_KV_NAMESPACE: KVNamespace;
|
|
103
|
-
SOMETHING: asdasdfasdf;
|
|
104
|
-
ANOTHER: thing;
|
|
103
|
+
SOMETHING: \\"asdasdfasdf\\";
|
|
104
|
+
ANOTHER: \\"thing\\";
|
|
105
105
|
OBJECT_VAR: {\\"enterprise\\":\\"1701-D\\",\\"activeDuty\\":true,\\"captian\\":\\"Picard\\"};
|
|
106
106
|
DURABLE_TEST1: DurableObjectNamespace;
|
|
107
107
|
DURABLE_TEST2: DurableObjectNamespace;
|
package/src/bundle.ts
CHANGED
|
@@ -13,7 +13,7 @@ import type { WorkerRegistry } from "./dev-registry";
|
|
|
13
13
|
import type { Entry } from "./entry";
|
|
14
14
|
import type { CfModule } from "./worker";
|
|
15
15
|
|
|
16
|
-
type BundleResult = {
|
|
16
|
+
export type BundleResult = {
|
|
17
17
|
modules: CfModule[];
|
|
18
18
|
dependencies: esbuild.Metafile["outputs"][string]["inputs"];
|
|
19
19
|
resolvedEntryPointPath: string;
|
|
@@ -80,24 +80,31 @@ export async function bundleWorker(
|
|
|
80
80
|
destination: string,
|
|
81
81
|
options: {
|
|
82
82
|
serveAssetsFromWorker: boolean;
|
|
83
|
-
assets
|
|
83
|
+
assets?: StaticAssetsConfig;
|
|
84
84
|
betaD1Shims?: string[];
|
|
85
|
-
jsxFactory
|
|
86
|
-
jsxFragment
|
|
85
|
+
jsxFactory?: string;
|
|
86
|
+
jsxFragment?: string;
|
|
87
87
|
rules: Config["rules"];
|
|
88
|
-
watch?: esbuild.WatchMode;
|
|
89
|
-
tsconfig
|
|
90
|
-
minify
|
|
91
|
-
nodeCompat
|
|
88
|
+
watch?: esbuild.WatchMode | boolean;
|
|
89
|
+
tsconfig?: string;
|
|
90
|
+
minify?: boolean;
|
|
91
|
+
nodeCompat?: boolean;
|
|
92
92
|
define: Config["define"];
|
|
93
93
|
checkFetch: boolean;
|
|
94
|
-
services
|
|
95
|
-
workerDefinitions
|
|
96
|
-
firstPartyWorkerDevFacade
|
|
94
|
+
services?: Config["services"];
|
|
95
|
+
workerDefinitions?: WorkerRegistry;
|
|
96
|
+
firstPartyWorkerDevFacade?: boolean;
|
|
97
97
|
targetConsumer: "dev" | "publish";
|
|
98
98
|
local: boolean;
|
|
99
|
-
testScheduled?: boolean
|
|
100
|
-
experimentalLocalStubCache
|
|
99
|
+
testScheduled?: boolean;
|
|
100
|
+
experimentalLocalStubCache?: boolean;
|
|
101
|
+
inject?: string[];
|
|
102
|
+
loader?: Record<string, string>;
|
|
103
|
+
sourcemap?: esbuild.CommonOptions["sourcemap"];
|
|
104
|
+
plugins?: esbuild.Plugin[];
|
|
105
|
+
// TODO: Rip these out https://github.com/cloudflare/wrangler2/issues/2153
|
|
106
|
+
disableModuleCollection?: boolean;
|
|
107
|
+
isOutfile?: boolean;
|
|
101
108
|
}
|
|
102
109
|
): Promise<BundleResult> {
|
|
103
110
|
const {
|
|
@@ -119,6 +126,12 @@ export async function bundleWorker(
|
|
|
119
126
|
targetConsumer,
|
|
120
127
|
testScheduled,
|
|
121
128
|
experimentalLocalStubCache,
|
|
129
|
+
inject: injectOption,
|
|
130
|
+
loader,
|
|
131
|
+
sourcemap,
|
|
132
|
+
plugins,
|
|
133
|
+
disableModuleCollection,
|
|
134
|
+
isOutfile,
|
|
122
135
|
} = options;
|
|
123
136
|
|
|
124
137
|
// We create a temporary directory for any oneoff files we
|
|
@@ -127,7 +140,7 @@ export async function bundleWorker(
|
|
|
127
140
|
const tmpDir = await tmp.dir({ unsafeCleanup: true });
|
|
128
141
|
|
|
129
142
|
const entryDirectory = path.dirname(entry.file);
|
|
130
|
-
|
|
143
|
+
let moduleCollector = createModuleCollector({
|
|
131
144
|
wrangler1xlegacyModuleReferences: {
|
|
132
145
|
rootDirectory: entryDirectory,
|
|
133
146
|
fileNames: new Set(
|
|
@@ -143,6 +156,15 @@ export async function bundleWorker(
|
|
|
143
156
|
format: entry.format,
|
|
144
157
|
rules,
|
|
145
158
|
});
|
|
159
|
+
if (disableModuleCollection) {
|
|
160
|
+
moduleCollector = {
|
|
161
|
+
modules: [],
|
|
162
|
+
plugin: {
|
|
163
|
+
name: moduleCollector.plugin.name,
|
|
164
|
+
setup: () => {},
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
}
|
|
146
168
|
|
|
147
169
|
// In dev, we want to patch `fetch()` with a special version that looks
|
|
148
170
|
// for bad usages and can warn the user about them; so we inject
|
|
@@ -253,7 +275,7 @@ export async function bundleWorker(
|
|
|
253
275
|
|
|
254
276
|
// At this point, inputEntry points to the entry point we want to build.
|
|
255
277
|
|
|
256
|
-
const inject: string[] = [];
|
|
278
|
+
const inject: string[] = injectOption ?? [];
|
|
257
279
|
if (checkFetch) inject.push(checkedFetchFileToInject);
|
|
258
280
|
if (experimentalLocalStubCache) {
|
|
259
281
|
inject.push(
|
|
@@ -266,11 +288,17 @@ export async function bundleWorker(
|
|
|
266
288
|
bundle: true,
|
|
267
289
|
absWorkingDir: entry.directory,
|
|
268
290
|
outdir: destination,
|
|
291
|
+
...(isOutfile
|
|
292
|
+
? {
|
|
293
|
+
outdir: undefined,
|
|
294
|
+
outfile: destination,
|
|
295
|
+
}
|
|
296
|
+
: {}),
|
|
269
297
|
inject,
|
|
270
298
|
external: ["__STATIC_CONTENT_MANIFEST"],
|
|
271
299
|
format: entry.format === "modules" ? "esm" : "iife",
|
|
272
300
|
target: "es2020",
|
|
273
|
-
sourcemap: true,
|
|
301
|
+
sourcemap: sourcemap ?? true, // this needs to use ?? to accept false
|
|
274
302
|
// Include a reference to the output folder in the sourcemap.
|
|
275
303
|
// This is omitted by default, but we need it to properly resolve source paths in error output.
|
|
276
304
|
sourceRoot: destination,
|
|
@@ -291,6 +319,7 @@ export async function bundleWorker(
|
|
|
291
319
|
".js": "jsx",
|
|
292
320
|
".mjs": "jsx",
|
|
293
321
|
".cjs": "jsx",
|
|
322
|
+
...(loader || {}),
|
|
294
323
|
},
|
|
295
324
|
plugins: [
|
|
296
325
|
// We run the moduleCollector plugin for service workers as part of the middleware loader
|
|
@@ -301,6 +330,7 @@ export async function bundleWorker(
|
|
|
301
330
|
...(nodeCompat
|
|
302
331
|
? [NodeGlobalsPolyfills({ buffer: true }), NodeModulesPolyfills()]
|
|
303
332
|
: []),
|
|
333
|
+
...(plugins || []),
|
|
304
334
|
],
|
|
305
335
|
...(jsxFactory && { jsxFactory }),
|
|
306
336
|
...(jsxFragment && { jsxFragment }),
|
package/src/deployments.ts
CHANGED
package/src/pages/build.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { writeFileSync } from "node:fs";
|
|
2
2
|
import { tmpdir } from "node:os";
|
|
3
|
-
import { dirname, join } from "node:path";
|
|
3
|
+
import { dirname, join, resolve } from "node:path";
|
|
4
4
|
import { FatalError } from "../errors";
|
|
5
5
|
import { logger } from "../logger";
|
|
6
6
|
import * as metrics from "../metrics";
|
|
@@ -81,6 +81,13 @@ export function Options(yargs: Argv) {
|
|
|
81
81
|
type: "boolean",
|
|
82
82
|
hidden: true,
|
|
83
83
|
},
|
|
84
|
+
bindings: {
|
|
85
|
+
type: "string",
|
|
86
|
+
describe:
|
|
87
|
+
"Bindings used in Functions (used to register beta product shims)",
|
|
88
|
+
deprecated: true,
|
|
89
|
+
hidden: true,
|
|
90
|
+
},
|
|
84
91
|
})
|
|
85
92
|
.epilogue(pagesBetaWarning);
|
|
86
93
|
}
|
|
@@ -97,6 +104,7 @@ export const Handler = async ({
|
|
|
97
104
|
plugin,
|
|
98
105
|
buildOutputDirectory,
|
|
99
106
|
nodeCompat,
|
|
107
|
+
bindings,
|
|
100
108
|
}: PagesBuildArgs) => {
|
|
101
109
|
if (!isInPagesCI) {
|
|
102
110
|
// Beta message for `wrangler pages <commands>` usage
|
|
@@ -109,6 +117,16 @@ export const Handler = async ({
|
|
|
109
117
|
);
|
|
110
118
|
}
|
|
111
119
|
|
|
120
|
+
let d1Databases: string[] | undefined = undefined;
|
|
121
|
+
if (bindings) {
|
|
122
|
+
try {
|
|
123
|
+
const decodedBindings = JSON.parse(bindings);
|
|
124
|
+
d1Databases = Object.keys(decodedBindings?.d1_databases || {});
|
|
125
|
+
} catch {
|
|
126
|
+
throw new FatalError("Could not parse a valid set of 'bindings'.", 1);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
112
130
|
buildOutputDirectory ??= dirname(outfile);
|
|
113
131
|
try {
|
|
114
132
|
await buildFunctions({
|
|
@@ -123,6 +141,8 @@ export const Handler = async ({
|
|
|
123
141
|
buildOutputDirectory,
|
|
124
142
|
nodeCompat,
|
|
125
143
|
routesOutputPath,
|
|
144
|
+
local: false,
|
|
145
|
+
d1Databases,
|
|
126
146
|
});
|
|
127
147
|
} catch (e) {
|
|
128
148
|
if (e instanceof FunctionsNoRoutesError) {
|
|
@@ -154,6 +174,8 @@ export async function buildFunctions({
|
|
|
154
174
|
buildOutputDirectory,
|
|
155
175
|
routesOutputPath,
|
|
156
176
|
nodeCompat,
|
|
177
|
+
local,
|
|
178
|
+
d1Databases,
|
|
157
179
|
}: Partial<
|
|
158
180
|
Pick<
|
|
159
181
|
PagesBuildArgs,
|
|
@@ -171,6 +193,8 @@ export async function buildFunctions({
|
|
|
171
193
|
onEnd?: () => void;
|
|
172
194
|
outfile: Required<PagesBuildArgs>["outfile"];
|
|
173
195
|
routesOutputPath?: PagesBuildArgs["outputRoutesPath"];
|
|
196
|
+
local: boolean;
|
|
197
|
+
d1Databases?: string[];
|
|
174
198
|
}) {
|
|
175
199
|
RUNNING_BUILDERS.forEach(
|
|
176
200
|
(runningBuilder) => runningBuilder.stop && runningBuilder.stop()
|
|
@@ -208,6 +232,8 @@ export async function buildFunctions({
|
|
|
208
232
|
outfile: routesModule,
|
|
209
233
|
});
|
|
210
234
|
|
|
235
|
+
const absoluteFunctionsDirectory = resolve(functionsDirectory);
|
|
236
|
+
|
|
211
237
|
if (plugin) {
|
|
212
238
|
RUNNING_BUILDERS.push(
|
|
213
239
|
await buildPlugin({
|
|
@@ -217,6 +243,9 @@ export async function buildFunctions({
|
|
|
217
243
|
sourcemap,
|
|
218
244
|
watch,
|
|
219
245
|
nodeCompat,
|
|
246
|
+
functionsDirectory: absoluteFunctionsDirectory,
|
|
247
|
+
local,
|
|
248
|
+
betaD1Shims: d1Databases,
|
|
220
249
|
onEnd,
|
|
221
250
|
})
|
|
222
251
|
);
|
|
@@ -229,6 +258,9 @@ export async function buildFunctions({
|
|
|
229
258
|
sourcemap,
|
|
230
259
|
fallbackService,
|
|
231
260
|
watch,
|
|
261
|
+
functionsDirectory: absoluteFunctionsDirectory,
|
|
262
|
+
local,
|
|
263
|
+
betaD1Shims: d1Databases,
|
|
232
264
|
onEnd,
|
|
233
265
|
buildOutputDirectory,
|
|
234
266
|
nodeCompat,
|