wrangler 0.0.0-e6e1daba → 0.0.0-e7cf0caa
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 +1 -1
- package/package.json +14 -9
- package/src/__tests__/api-devregistry.test.ts +121 -0
- package/src/__tests__/api.test.ts +27 -5
- package/src/__tests__/configuration.test.ts +294 -18
- package/src/__tests__/d1/execute.test.ts +3 -1
- package/src/__tests__/d1/migrate.test.ts +2 -0
- package/src/__tests__/delete.test.ts +6 -0
- package/src/__tests__/deployments.test.ts +335 -95
- package/src/__tests__/dev.test.tsx +87 -57
- package/src/__tests__/generate.test.ts +3 -4
- package/src/__tests__/helpers/mock-console.ts +6 -0
- package/src/__tests__/helpers/msw/handlers/deployments.ts +70 -3
- package/src/__tests__/helpers/msw/index.ts +4 -2
- package/src/__tests__/helpers/worker-scripts/parent-worker.js +4 -1
- package/src/__tests__/index.test.ts +10 -4
- package/src/__tests__/init.test.ts +136 -104
- package/src/__tests__/jest.setup.ts +4 -0
- package/src/__tests__/kv.test.ts +9 -9
- package/src/__tests__/logger.test.ts +68 -2
- package/src/__tests__/middleware.scheduled.test.ts +2 -2
- package/src/__tests__/middleware.test.ts +4 -3
- package/src/__tests__/mtls-certificates.test.ts +5 -2
- package/src/__tests__/pages/deployment-list.test.ts +2 -0
- package/src/__tests__/pages/functions-build.test.ts +91 -41
- package/src/__tests__/pages/project-list.test.ts +2 -0
- package/src/__tests__/pages/project-upload.test.ts +43 -24
- package/src/__tests__/pages/publish.test.ts +267 -148
- package/src/__tests__/publish.test.ts +420 -164
- package/src/__tests__/pubsub.test.ts +3 -0
- package/src/__tests__/queues.test.ts +5 -2
- package/src/__tests__/test-old-node-version.js +3 -3
- package/src/__tests__/traverse-module-graph.test.ts +220 -0
- 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/__tests__/worker-namespace.test.ts +1 -0
- package/src/api/dev.ts +10 -22
- package/src/api/pages/create-worker-bundle-contents.ts +1 -0
- package/src/api/pages/publish.tsx +38 -51
- package/src/bundle.ts +44 -13
- package/src/config/environment.ts +36 -4
- package/src/config/index.ts +30 -2
- package/src/config/validation-helpers.ts +1 -1
- package/src/config/validation.ts +149 -5
- package/src/create-worker-upload-form.ts +28 -3
- package/src/d1/backups.tsx +15 -11
- package/src/d1/create.tsx +20 -16
- package/src/d1/execute.tsx +22 -19
- package/src/d1/list.tsx +2 -2
- package/src/d1/migrations/apply.tsx +35 -29
- package/src/d1/migrations/create.tsx +15 -12
- package/src/d1/migrations/list.tsx +10 -7
- package/src/deployments.ts +260 -8
- package/src/dev/dev.tsx +4 -4
- package/src/dev/local.tsx +14 -16
- package/src/dev/start-server.ts +12 -16
- package/src/dev/use-esbuild.ts +11 -13
- package/src/dev/validate-dev-props.ts +9 -0
- package/src/dev-registry.ts +2 -1
- package/src/dev.tsx +28 -13
- package/src/entry.ts +18 -8
- package/src/generate/index.ts +2 -2
- package/src/index.ts +76 -23
- package/src/init.ts +144 -134
- package/src/logger.ts +18 -3
- package/src/metrics/send-event.ts +2 -1
- package/src/miniflare-cli/index.ts +1 -1
- package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -1
- package/src/module-collection.ts +91 -25
- package/src/pages/build.ts +277 -99
- package/src/pages/buildFunctions.ts +20 -10
- package/src/pages/deployments.tsx +3 -5
- package/src/pages/dev.ts +21 -21
- package/src/pages/errors.ts +1 -0
- package/src/pages/functions/buildPlugin.ts +57 -34
- package/src/pages/functions/buildWorker.ts +34 -31
- package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
- package/src/pages/projects.tsx +2 -5
- package/src/pages/publish.tsx +1 -10
- package/src/pages/upload.tsx +29 -9
- package/src/paths.ts +1 -1
- package/src/publish/index.ts +1 -1
- package/src/publish/publish.ts +29 -34
- package/src/queues/cli/commands/consumer/add.ts +6 -0
- package/src/queues/client.ts +1 -0
- package/src/secret/index.ts +2 -1
- package/src/traverse-module-graph.ts +53 -0
- package/src/type-generation.ts +1 -1
- package/src/user/user.ts +1 -1
- package/src/utils/render.ts +93 -0
- package/src/worker.ts +18 -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/tsconfig.init.json +1 -2
- package/templates/tsconfig.tsbuildinfo +1 -1
- package/wrangler-dist/cli.d.ts +33 -13
- package/wrangler-dist/cli.js +20732 -19984
- package/src/__tests__/api-devregistry.test.js +0 -64
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
createFetchResult,
|
|
33
33
|
msw,
|
|
34
34
|
mswSuccessDeployments,
|
|
35
|
-
|
|
35
|
+
mswSuccessDeploymentScriptMetadata,
|
|
36
36
|
} from "./helpers/msw";
|
|
37
37
|
import { FileReaderSync } from "./helpers/msw/read-file-sync";
|
|
38
38
|
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
@@ -89,7 +89,7 @@ describe("publish", () => {
|
|
|
89
89
|
);
|
|
90
90
|
writeWorkerSource();
|
|
91
91
|
mockSubDomainRequest();
|
|
92
|
-
mockUploadWorkerRequest({ expectedType: "esm"
|
|
92
|
+
mockUploadWorkerRequest({ expectedType: "esm" });
|
|
93
93
|
mockOAuthServerCallback();
|
|
94
94
|
|
|
95
95
|
await runWrangler("publish ./index");
|
|
@@ -98,6 +98,7 @@ describe("publish", () => {
|
|
|
98
98
|
Object {
|
|
99
99
|
"debug": "",
|
|
100
100
|
"err": "",
|
|
101
|
+
"info": "",
|
|
101
102
|
"out": "Total Upload: xx KiB / gzip: xx KiB
|
|
102
103
|
Worker ID: abc12345
|
|
103
104
|
Worker ETag: etag98765
|
|
@@ -326,7 +327,7 @@ describe("publish", () => {
|
|
|
326
327
|
await expect(runWrangler("publish index.js")).rejects.toThrowError();
|
|
327
328
|
|
|
328
329
|
expect(std.err).toMatchInlineSnapshot(`
|
|
329
|
-
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mIn a non-interactive environment, it's necessary to set a CLOUDFLARE_API_TOKEN environment variable for wrangler to work. Please go to https://developers.cloudflare.com/api/
|
|
330
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mIn a non-interactive environment, it's necessary to set a CLOUDFLARE_API_TOKEN environment variable for wrangler to work. Please go to https://developers.cloudflare.com/fundamentals/api/get-started/create-token/ for instructions on how to create an api token, and assign its value to CLOUDFLARE_API_TOKEN.[0m
|
|
330
331
|
|
|
331
332
|
"
|
|
332
333
|
`);
|
|
@@ -617,6 +618,7 @@ describe("publish", () => {
|
|
|
617
618
|
Object {
|
|
618
619
|
"debug": "",
|
|
619
620
|
"err": "",
|
|
621
|
+
"info": "",
|
|
620
622
|
"out": "Total Upload: xx KiB / gzip: xx KiB
|
|
621
623
|
Uploaded test-name (TIMINGS)
|
|
622
624
|
Published test-name (TIMINGS)
|
|
@@ -664,6 +666,7 @@ describe("publish", () => {
|
|
|
664
666
|
Object {
|
|
665
667
|
"debug": "",
|
|
666
668
|
"err": "",
|
|
669
|
+
"info": "",
|
|
667
670
|
"out": "Total Upload: xx KiB / gzip: xx KiB
|
|
668
671
|
Uploaded test-name (TIMINGS)
|
|
669
672
|
Published test-name (TIMINGS)
|
|
@@ -726,6 +729,7 @@ describe("publish", () => {
|
|
|
726
729
|
Object {
|
|
727
730
|
"debug": "",
|
|
728
731
|
"err": "",
|
|
732
|
+
"info": "",
|
|
729
733
|
"out": "Total Upload: xx KiB / gzip: xx KiB
|
|
730
734
|
Uploaded test-name (staging) (TIMINGS)
|
|
731
735
|
Published test-name (staging) (TIMINGS)
|
|
@@ -1337,6 +1341,32 @@ export default{
|
|
|
1337
1341
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1338
1342
|
});
|
|
1339
1343
|
|
|
1344
|
+
it("should allow cloudflare module import", async () => {
|
|
1345
|
+
writeWranglerToml();
|
|
1346
|
+
fs.writeFileSync(
|
|
1347
|
+
"./index.js",
|
|
1348
|
+
`
|
|
1349
|
+
import { EmailMessage } from "cloudflare:email";
|
|
1350
|
+
export default{
|
|
1351
|
+
fetch(){
|
|
1352
|
+
return new Response("all done");
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
`
|
|
1356
|
+
);
|
|
1357
|
+
mockUploadWorkerRequest();
|
|
1358
|
+
mockSubDomainRequest();
|
|
1359
|
+
await runWrangler("publish index.js");
|
|
1360
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
1361
|
+
"Total Upload: xx KiB / gzip: xx KiB
|
|
1362
|
+
Uploaded test-name (TIMINGS)
|
|
1363
|
+
Published test-name (TIMINGS)
|
|
1364
|
+
https://test-name.test-sub-domain.workers.dev
|
|
1365
|
+
Current Deployment ID: Galaxy-Class"
|
|
1366
|
+
`);
|
|
1367
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1368
|
+
});
|
|
1369
|
+
|
|
1340
1370
|
it("should be able to transpile entry-points in sub-directories (esm)", async () => {
|
|
1341
1371
|
writeWranglerToml();
|
|
1342
1372
|
writeWorkerSource({ basePath: "./src" });
|
|
@@ -1387,6 +1417,7 @@ export default {};`
|
|
|
1387
1417
|
Object {
|
|
1388
1418
|
"debug": "",
|
|
1389
1419
|
"err": "",
|
|
1420
|
+
"info": "",
|
|
1390
1421
|
"out": "Total Upload: xx KiB / gzip: xx KiB
|
|
1391
1422
|
--dry-run: exiting now.",
|
|
1392
1423
|
"warn": "",
|
|
@@ -1420,6 +1451,7 @@ addEventListener('fetch', event => {});`
|
|
|
1420
1451
|
Object {
|
|
1421
1452
|
"debug": "",
|
|
1422
1453
|
"err": "",
|
|
1454
|
+
"info": "",
|
|
1423
1455
|
"out": "Total Upload: xx KiB / gzip: xx KiB
|
|
1424
1456
|
--dry-run: exiting now.",
|
|
1425
1457
|
"warn": "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mThe entrypoint index.js has exports like an ES Module, but hasn't defined a default export like a module worker normally would. Building the worker using \\"service-worker\\" format...[0m
|
|
@@ -1519,6 +1551,7 @@ addEventListener('fetch', event => {});`
|
|
|
1519
1551
|
Object {
|
|
1520
1552
|
"debug": "",
|
|
1521
1553
|
"err": "",
|
|
1554
|
+
"info": "",
|
|
1522
1555
|
"out": "Reading file-1.txt...
|
|
1523
1556
|
Uploading as file-1.2ca234f380.txt...
|
|
1524
1557
|
Reading file-2.txt...
|
|
@@ -1649,7 +1682,7 @@ addEventListener('fetch', event => {});`
|
|
|
1649
1682
|
};
|
|
1650
1683
|
writeAssets(assets);
|
|
1651
1684
|
mockUploadWorkerRequest({
|
|
1652
|
-
expectedMainModule: "
|
|
1685
|
+
expectedMainModule: "no-op-worker.js",
|
|
1653
1686
|
});
|
|
1654
1687
|
mockSubDomainRequest();
|
|
1655
1688
|
mockListKVNamespacesRequest(kvNamespace);
|
|
@@ -1662,6 +1695,7 @@ addEventListener('fetch', event => {});`
|
|
|
1662
1695
|
Object {
|
|
1663
1696
|
"debug": "",
|
|
1664
1697
|
"err": "",
|
|
1698
|
+
"info": "",
|
|
1665
1699
|
"out": "Reading file-1.txt...
|
|
1666
1700
|
Uploading as file-1.2ca234f380.txt...
|
|
1667
1701
|
Reading file-2.txt...
|
|
@@ -1740,7 +1774,7 @@ addEventListener('fetch', event => {});`
|
|
|
1740
1774
|
writeWorkerSource();
|
|
1741
1775
|
writeAssets(assets);
|
|
1742
1776
|
mockUploadWorkerRequest({
|
|
1743
|
-
expectedMainModule: "
|
|
1777
|
+
expectedMainModule: "index.js",
|
|
1744
1778
|
});
|
|
1745
1779
|
mockSubDomainRequest();
|
|
1746
1780
|
mockListKVNamespacesRequest(kvNamespace);
|
|
@@ -1752,6 +1786,7 @@ addEventListener('fetch', event => {});`
|
|
|
1752
1786
|
Object {
|
|
1753
1787
|
"debug": "",
|
|
1754
1788
|
"err": "",
|
|
1789
|
+
"info": "",
|
|
1755
1790
|
"out": "Reading file-1.txt...
|
|
1756
1791
|
Uploading as file-1.2ca234f380.txt...
|
|
1757
1792
|
Reading file-2.txt...
|
|
@@ -1781,18 +1816,19 @@ addEventListener('fetch', event => {});`
|
|
|
1781
1816
|
);
|
|
1782
1817
|
|
|
1783
1818
|
expect(std).toMatchInlineSnapshot(`
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1819
|
+
Object {
|
|
1820
|
+
"debug": "",
|
|
1821
|
+
"err": "[31mX [41;31m[[41;97mERROR[41;31m][0m [1mYou cannot use the service-worker format with an \`assets\` directory yet. For information on how to migrate to the module-worker format, see: https://developers.cloudflare.com/workers/learning/migrating-to-module-workers/[0m
|
|
1787
1822
|
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1823
|
+
",
|
|
1824
|
+
"info": "",
|
|
1825
|
+
"out": "
|
|
1826
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose[0m",
|
|
1827
|
+
"warn": "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mThe --assets argument is experimental and may change or break at any time[0m
|
|
1792
1828
|
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1829
|
+
",
|
|
1830
|
+
}
|
|
1831
|
+
`);
|
|
1796
1832
|
});
|
|
1797
1833
|
|
|
1798
1834
|
it("should error if --assets and --site are used together", async () => {
|
|
@@ -1807,16 +1843,17 @@ addEventListener('fetch', event => {});`
|
|
|
1807
1843
|
);
|
|
1808
1844
|
|
|
1809
1845
|
expect(std).toMatchInlineSnapshot(`
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1846
|
+
Object {
|
|
1847
|
+
"debug": "",
|
|
1848
|
+
"err": "[31mX [41;31m[[41;97mERROR[41;31m][0m [1mCannot use Assets and Workers Sites in the same Worker.[0m
|
|
1849
|
+
|
|
1850
|
+
",
|
|
1851
|
+
"info": "",
|
|
1852
|
+
"out": "
|
|
1853
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose[0m",
|
|
1854
|
+
"warn": "",
|
|
1855
|
+
}
|
|
1856
|
+
`);
|
|
1820
1857
|
});
|
|
1821
1858
|
|
|
1822
1859
|
it("should error if --assets and config.site are used together", async () => {
|
|
@@ -1834,16 +1871,17 @@ addEventListener('fetch', event => {});`
|
|
|
1834
1871
|
);
|
|
1835
1872
|
|
|
1836
1873
|
expect(std).toMatchInlineSnapshot(`
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1874
|
+
Object {
|
|
1875
|
+
"debug": "",
|
|
1876
|
+
"err": "[31mX [41;31m[[41;97mERROR[41;31m][0m [1mCannot use Assets and Workers Sites in the same Worker.[0m
|
|
1877
|
+
|
|
1878
|
+
",
|
|
1879
|
+
"info": "",
|
|
1880
|
+
"out": "
|
|
1881
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose[0m",
|
|
1882
|
+
"warn": "",
|
|
1883
|
+
}
|
|
1884
|
+
`);
|
|
1847
1885
|
});
|
|
1848
1886
|
|
|
1849
1887
|
it("should error if config.assets and --site are used together", async () => {
|
|
@@ -1860,20 +1898,21 @@ addEventListener('fetch', event => {});`
|
|
|
1860
1898
|
);
|
|
1861
1899
|
|
|
1862
1900
|
expect(std).toMatchInlineSnapshot(`
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1901
|
+
Object {
|
|
1902
|
+
"debug": "",
|
|
1903
|
+
"err": "[31mX [41;31m[[41;97mERROR[41;31m][0m [1mCannot use Assets and Workers Sites in the same Worker.[0m
|
|
1866
1904
|
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1905
|
+
",
|
|
1906
|
+
"info": "",
|
|
1907
|
+
"out": "
|
|
1908
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose[0m",
|
|
1909
|
+
"warn": "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mProcessing wrangler.toml configuration:[0m
|
|
1871
1910
|
|
|
1872
|
-
|
|
1911
|
+
- \\"assets\\" fields are experimental and may change or break at any time.
|
|
1873
1912
|
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1913
|
+
",
|
|
1914
|
+
}
|
|
1915
|
+
`);
|
|
1877
1916
|
});
|
|
1878
1917
|
|
|
1879
1918
|
it("should error if config.assets and config.site are used together", async () => {
|
|
@@ -1893,20 +1932,21 @@ addEventListener('fetch', event => {});`
|
|
|
1893
1932
|
);
|
|
1894
1933
|
|
|
1895
1934
|
expect(std).toMatchInlineSnapshot(`
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1935
|
+
Object {
|
|
1936
|
+
"debug": "",
|
|
1937
|
+
"err": "[31mX [41;31m[[41;97mERROR[41;31m][0m [1mCannot use Assets and Workers Sites in the same Worker.[0m
|
|
1899
1938
|
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1939
|
+
",
|
|
1940
|
+
"info": "",
|
|
1941
|
+
"out": "
|
|
1942
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose[0m",
|
|
1943
|
+
"warn": "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mProcessing wrangler.toml configuration:[0m
|
|
1904
1944
|
|
|
1905
|
-
|
|
1945
|
+
- \\"assets\\" fields are experimental and may change or break at any time.
|
|
1906
1946
|
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1947
|
+
",
|
|
1948
|
+
}
|
|
1949
|
+
`);
|
|
1910
1950
|
});
|
|
1911
1951
|
|
|
1912
1952
|
it("should warn if --assets is used", async () => {
|
|
@@ -1925,7 +1965,7 @@ addEventListener('fetch', event => {});`
|
|
|
1925
1965
|
writeWorkerSource();
|
|
1926
1966
|
writeAssets(assets);
|
|
1927
1967
|
mockUploadWorkerRequest({
|
|
1928
|
-
expectedMainModule: "
|
|
1968
|
+
expectedMainModule: "index.js",
|
|
1929
1969
|
});
|
|
1930
1970
|
mockSubDomainRequest();
|
|
1931
1971
|
mockListKVNamespacesRequest(kvNamespace);
|
|
@@ -1937,6 +1977,7 @@ addEventListener('fetch', event => {});`
|
|
|
1937
1977
|
Object {
|
|
1938
1978
|
"debug": "",
|
|
1939
1979
|
"err": "",
|
|
1980
|
+
"info": "",
|
|
1940
1981
|
"out": "Reading subdir/file-1.txt...
|
|
1941
1982
|
Uploading as subdir/file-1.2ca234f380.txt...
|
|
1942
1983
|
Reading subdir/file-2.txt...
|
|
@@ -1972,7 +2013,7 @@ addEventListener('fetch', event => {});`
|
|
|
1972
2013
|
writeWorkerSource();
|
|
1973
2014
|
writeAssets(assets);
|
|
1974
2015
|
mockUploadWorkerRequest({
|
|
1975
|
-
expectedMainModule: "
|
|
2016
|
+
expectedMainModule: "index.js",
|
|
1976
2017
|
});
|
|
1977
2018
|
mockSubDomainRequest();
|
|
1978
2019
|
mockListKVNamespacesRequest(kvNamespace);
|
|
@@ -1984,6 +2025,7 @@ addEventListener('fetch', event => {});`
|
|
|
1984
2025
|
Object {
|
|
1985
2026
|
"debug": "",
|
|
1986
2027
|
"err": "",
|
|
2028
|
+
"info": "",
|
|
1987
2029
|
"out": "Reading subdir/file-1.txt...
|
|
1988
2030
|
Uploading as subdir/file-1.2ca234f380.txt...
|
|
1989
2031
|
Reading subdir/file-2.txt...
|
|
@@ -2752,6 +2794,7 @@ addEventListener('fetch', event => {});`
|
|
|
2752
2794
|
Object {
|
|
2753
2795
|
"debug": "",
|
|
2754
2796
|
"err": "",
|
|
2797
|
+
"info": "",
|
|
2755
2798
|
"out": "Reading file-00.txt...
|
|
2756
2799
|
Uploading as file-00.be5be5dd26.txt...
|
|
2757
2800
|
Reading file-01.txt...
|
|
@@ -2985,6 +3028,7 @@ addEventListener('fetch', event => {});`
|
|
|
2985
3028
|
Object {
|
|
2986
3029
|
"debug": "",
|
|
2987
3030
|
"err": "",
|
|
3031
|
+
"info": "",
|
|
2988
3032
|
"out": "Reading file-1.txt...
|
|
2989
3033
|
Uploading as file-1.2ca234f380.txt...
|
|
2990
3034
|
Reading file-2.txt...
|
|
@@ -3015,7 +3059,7 @@ addEventListener('fetch', event => {});`
|
|
|
3015
3059
|
writeWorkerSource();
|
|
3016
3060
|
writeAssets(assets, "my-assets");
|
|
3017
3061
|
mockUploadWorkerRequest({
|
|
3018
|
-
expectedMainModule: "
|
|
3062
|
+
expectedMainModule: "index.js",
|
|
3019
3063
|
});
|
|
3020
3064
|
mockSubDomainRequest();
|
|
3021
3065
|
mockListKVNamespacesRequest(kvNamespace);
|
|
@@ -3028,6 +3072,7 @@ addEventListener('fetch', event => {});`
|
|
|
3028
3072
|
Object {
|
|
3029
3073
|
"debug": "",
|
|
3030
3074
|
"err": "",
|
|
3075
|
+
"info": "",
|
|
3031
3076
|
"out": "Reading file-1.txt...
|
|
3032
3077
|
Uploading as file-1.2ca234f380.txt...
|
|
3033
3078
|
Reading file-2.txt...
|
|
@@ -3840,7 +3885,7 @@ addEventListener('fetch', event => {});`
|
|
|
3840
3885
|
it("should run a custom build before publishing", async () => {
|
|
3841
3886
|
writeWranglerToml({
|
|
3842
3887
|
build: {
|
|
3843
|
-
command: `node -e "
|
|
3888
|
+
command: `node -e "4+4; require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')"`,
|
|
3844
3889
|
},
|
|
3845
3890
|
});
|
|
3846
3891
|
|
|
@@ -3851,7 +3896,7 @@ addEventListener('fetch', event => {});`
|
|
|
3851
3896
|
|
|
3852
3897
|
await runWrangler("publish index.js");
|
|
3853
3898
|
expect(std.out).toMatchInlineSnapshot(`
|
|
3854
|
-
"Running custom build: node -e \\"
|
|
3899
|
+
"Running custom build: node -e \\"4+4; require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')\\"
|
|
3855
3900
|
Total Upload: xx KiB / gzip: xx KiB
|
|
3856
3901
|
Uploaded test-name (TIMINGS)
|
|
3857
3902
|
Published test-name (TIMINGS)
|
|
@@ -3866,7 +3911,7 @@ addEventListener('fetch', event => {});`
|
|
|
3866
3911
|
it("should run a custom build of multiple steps combined by && before publishing", async () => {
|
|
3867
3912
|
writeWranglerToml({
|
|
3868
3913
|
build: {
|
|
3869
|
-
command: `echo "
|
|
3914
|
+
command: `echo "export default { fetch(){ return new Response(123) } }" > index.js`,
|
|
3870
3915
|
},
|
|
3871
3916
|
});
|
|
3872
3917
|
|
|
@@ -3877,7 +3922,7 @@ addEventListener('fetch', event => {});`
|
|
|
3877
3922
|
|
|
3878
3923
|
await runWrangler("publish index.js");
|
|
3879
3924
|
expect(std.out).toMatchInlineSnapshot(`
|
|
3880
|
-
"Running custom build: echo \\"
|
|
3925
|
+
"Running custom build: echo \\"export default { fetch(){ return new Response(123) } }\\" > index.js
|
|
3881
3926
|
Total Upload: xx KiB / gzip: xx KiB
|
|
3882
3927
|
Uploaded test-name (TIMINGS)
|
|
3883
3928
|
Published test-name (TIMINGS)
|
|
@@ -3893,22 +3938,22 @@ addEventListener('fetch', event => {});`
|
|
|
3893
3938
|
writeWranglerToml({
|
|
3894
3939
|
main: "index.js",
|
|
3895
3940
|
build: {
|
|
3896
|
-
command: `node -e "
|
|
3941
|
+
command: `node -e "4+4;"`,
|
|
3897
3942
|
},
|
|
3898
3943
|
});
|
|
3899
3944
|
|
|
3900
3945
|
await expect(runWrangler("publish index.js")).rejects
|
|
3901
3946
|
.toThrowErrorMatchingInlineSnapshot(`
|
|
3902
|
-
"The expected output file at \\"index.js\\" was not found after running custom build: node -e \\"
|
|
3947
|
+
"The expected output file at \\"index.js\\" was not found after running custom build: node -e \\"4+4;\\".
|
|
3903
3948
|
The \`main\` property in wrangler.toml should point to the file generated by the custom build."
|
|
3904
3949
|
`);
|
|
3905
3950
|
expect(std.out).toMatchInlineSnapshot(`
|
|
3906
|
-
"Running custom build: node -e \\"
|
|
3951
|
+
"Running custom build: node -e \\"4+4;\\"
|
|
3907
3952
|
|
|
3908
3953
|
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose[0m"
|
|
3909
3954
|
`);
|
|
3910
3955
|
expect(std.err).toMatchInlineSnapshot(`
|
|
3911
|
-
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mThe expected output file at \\"index.js\\" was not found after running custom build: node -e \\"
|
|
3956
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mThe expected output file at \\"index.js\\" was not found after running custom build: node -e \\"4+4;\\".[0m
|
|
3912
3957
|
|
|
3913
3958
|
The \`main\` property in wrangler.toml should point to the file generated by the custom build.
|
|
3914
3959
|
|
|
@@ -3921,7 +3966,7 @@ addEventListener('fetch', event => {});`
|
|
|
3921
3966
|
writeWranglerToml({
|
|
3922
3967
|
main: "./",
|
|
3923
3968
|
build: {
|
|
3924
|
-
command: `node -e "
|
|
3969
|
+
command: `node -e "4+4;"`,
|
|
3925
3970
|
},
|
|
3926
3971
|
});
|
|
3927
3972
|
|
|
@@ -3931,7 +3976,7 @@ addEventListener('fetch', event => {});`
|
|
|
3931
3976
|
|
|
3932
3977
|
await expect(runWrangler("publish")).rejects
|
|
3933
3978
|
.toThrowErrorMatchingInlineSnapshot(`
|
|
3934
|
-
"The expected output file at \\".\\" was not found after running custom build: node -e \\"
|
|
3979
|
+
"The expected output file at \\".\\" was not found after running custom build: node -e \\"4+4;\\".
|
|
3935
3980
|
The \`main\` property in wrangler.toml should point to the file generated by the custom build.
|
|
3936
3981
|
The provided entry-point path, \\".\\", points to a directory, rather than a file.
|
|
3937
3982
|
|
|
@@ -3942,12 +3987,12 @@ addEventListener('fetch', event => {});`
|
|
|
3942
3987
|
\`\`\`"
|
|
3943
3988
|
`);
|
|
3944
3989
|
expect(std.out).toMatchInlineSnapshot(`
|
|
3945
|
-
"Running custom build: node -e \\"
|
|
3990
|
+
"Running custom build: node -e \\"4+4;\\"
|
|
3946
3991
|
|
|
3947
3992
|
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose[0m"
|
|
3948
3993
|
`);
|
|
3949
3994
|
expect(std.err).toMatchInlineSnapshot(`
|
|
3950
|
-
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mThe expected output file at \\".\\" was not found after running custom build: node -e \\"
|
|
3995
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mThe expected output file at \\".\\" was not found after running custom build: node -e \\"4+4;\\".[0m
|
|
3951
3996
|
|
|
3952
3997
|
The \`main\` property in wrangler.toml should point to the file generated by the custom build.
|
|
3953
3998
|
The provided entry-point path, \\".\\", points to a directory, rather than a file.
|
|
@@ -4197,6 +4242,7 @@ addEventListener('fetch', event => {});`
|
|
|
4197
4242
|
Object {
|
|
4198
4243
|
"debug": "",
|
|
4199
4244
|
"err": "",
|
|
4245
|
+
"info": "",
|
|
4200
4246
|
"out": "Total Upload: xx KiB / gzip: xx KiB
|
|
4201
4247
|
Your worker has access to the following bindings:
|
|
4202
4248
|
- Durable Objects:
|
|
@@ -4242,6 +4288,7 @@ addEventListener('fetch', event => {});`
|
|
|
4242
4288
|
Object {
|
|
4243
4289
|
"debug": "",
|
|
4244
4290
|
"err": "",
|
|
4291
|
+
"info": "",
|
|
4245
4292
|
"out": "Total Upload: xx KiB / gzip: xx KiB
|
|
4246
4293
|
Your worker has access to the following bindings:
|
|
4247
4294
|
- Durable Objects:
|
|
@@ -4415,6 +4462,7 @@ addEventListener('fetch', event => {});`
|
|
|
4415
4462
|
Object {
|
|
4416
4463
|
"debug": "",
|
|
4417
4464
|
"err": "",
|
|
4465
|
+
"info": "",
|
|
4418
4466
|
"out": "Total Upload: xx KiB / gzip: xx KiB
|
|
4419
4467
|
Your worker has access to the following bindings:
|
|
4420
4468
|
- Durable Objects:
|
|
@@ -4485,6 +4533,7 @@ addEventListener('fetch', event => {});`
|
|
|
4485
4533
|
Object {
|
|
4486
4534
|
"debug": "",
|
|
4487
4535
|
"err": "",
|
|
4536
|
+
"info": "",
|
|
4488
4537
|
"out": "Total Upload: xx KiB / gzip: xx KiB
|
|
4489
4538
|
Your worker has access to the following bindings:
|
|
4490
4539
|
- Durable Objects:
|
|
@@ -4559,6 +4608,10 @@ addEventListener('fetch', event => {});`
|
|
|
4559
4608
|
data: 1337,
|
|
4560
4609
|
},
|
|
4561
4610
|
],
|
|
4611
|
+
metadata: {
|
|
4612
|
+
extra_data: "interesting value",
|
|
4613
|
+
more_data: "dubious value",
|
|
4614
|
+
},
|
|
4562
4615
|
},
|
|
4563
4616
|
vars: {
|
|
4564
4617
|
ENV_VAR_ONE: 123,
|
|
@@ -4603,6 +4656,10 @@ addEventListener('fetch', event => {});`
|
|
|
4603
4656
|
|
|
4604
4657
|
mockUploadWorkerRequest({
|
|
4605
4658
|
expectedType: "sw",
|
|
4659
|
+
expectedUnsafeMetaData: {
|
|
4660
|
+
extra_data: "interesting value",
|
|
4661
|
+
more_data: "dubious value",
|
|
4662
|
+
},
|
|
4606
4663
|
expectedBindings: [
|
|
4607
4664
|
{ json: 123, name: "ENV_VAR_ONE", type: "json" },
|
|
4608
4665
|
{
|
|
@@ -4726,6 +4783,9 @@ addEventListener('fetch', event => {});`
|
|
|
4726
4783
|
- Wasm Modules:
|
|
4727
4784
|
- WASM_MODULE_ONE: some_wasm.wasm
|
|
4728
4785
|
- WASM_MODULE_TWO: more_wasm.wasm
|
|
4786
|
+
- Unsafe Metadata:
|
|
4787
|
+
- extra_data: interesting value
|
|
4788
|
+
- more_data: dubious value
|
|
4729
4789
|
Uploaded test-name (TIMINGS)
|
|
4730
4790
|
Published test-name (TIMINGS)
|
|
4731
4791
|
https://test-name.test-sub-domain.workers.dev
|
|
@@ -4794,6 +4854,7 @@ addEventListener('fetch', event => {});`
|
|
|
4794
4854
|
data: 1337,
|
|
4795
4855
|
},
|
|
4796
4856
|
],
|
|
4857
|
+
metadata: undefined,
|
|
4797
4858
|
},
|
|
4798
4859
|
vars: {
|
|
4799
4860
|
ENV_VAR_ONE: 123,
|
|
@@ -4907,6 +4968,7 @@ addEventListener('fetch', event => {});`
|
|
|
4907
4968
|
data: 1337,
|
|
4908
4969
|
},
|
|
4909
4970
|
],
|
|
4971
|
+
metadata: undefined,
|
|
4910
4972
|
},
|
|
4911
4973
|
// text_blobs, vars, wasm_modules and data_blobs are fine because they're object literals,
|
|
4912
4974
|
// and by definition cannot have two keys of the same name
|
|
@@ -5055,6 +5117,7 @@ addEventListener('fetch', event => {});`
|
|
|
5055
5117
|
data: null,
|
|
5056
5118
|
},
|
|
5057
5119
|
],
|
|
5120
|
+
metadata: undefined,
|
|
5058
5121
|
},
|
|
5059
5122
|
vars: {
|
|
5060
5123
|
ENV_VAR_ONE: 123,
|
|
@@ -5541,6 +5604,7 @@ addEventListener('fetch', event => {});`
|
|
|
5541
5604
|
Object {
|
|
5542
5605
|
"debug": "",
|
|
5543
5606
|
"err": "",
|
|
5607
|
+
"info": "",
|
|
5544
5608
|
"out": "Total Upload: xx KiB / gzip: xx KiB
|
|
5545
5609
|
Your worker has access to the following bindings:
|
|
5546
5610
|
- Vars:
|
|
@@ -5832,7 +5896,7 @@ addEventListener('fetch', event => {});`
|
|
|
5832
5896
|
|
|
5833
5897
|
"
|
|
5834
5898
|
`);
|
|
5835
|
-
const output = fs.readFileSync("tmp/
|
|
5899
|
+
const output = fs.readFileSync("tmp/index.js", "utf-8");
|
|
5836
5900
|
expect(output).toContain(
|
|
5837
5901
|
`var ExampleDurableObject2 = maskDurableObjectDefinition(ExampleDurableObject);`
|
|
5838
5902
|
);
|
|
@@ -5992,6 +6056,7 @@ addEventListener('fetch', event => {});`
|
|
|
5992
6056
|
param: "binding-param",
|
|
5993
6057
|
},
|
|
5994
6058
|
],
|
|
6059
|
+
metadata: undefined,
|
|
5995
6060
|
},
|
|
5996
6061
|
});
|
|
5997
6062
|
writeWorkerSource();
|
|
@@ -6036,6 +6101,7 @@ addEventListener('fetch', event => {});`
|
|
|
6036
6101
|
text: "text",
|
|
6037
6102
|
},
|
|
6038
6103
|
],
|
|
6104
|
+
metadata: undefined,
|
|
6039
6105
|
},
|
|
6040
6106
|
});
|
|
6041
6107
|
writeWorkerSource();
|
|
@@ -6479,6 +6545,7 @@ addEventListener('fetch', event => {});`
|
|
|
6479
6545
|
Object {
|
|
6480
6546
|
"debug": "",
|
|
6481
6547
|
"err": "",
|
|
6548
|
+
"info": "",
|
|
6482
6549
|
"out": "Total Upload: xx KiB / gzip: xx KiB
|
|
6483
6550
|
Uploaded test-name (TIMINGS)
|
|
6484
6551
|
Published test-name (TIMINGS)
|
|
@@ -6529,6 +6596,7 @@ addEventListener('fetch', event => {});`
|
|
|
6529
6596
|
Object {
|
|
6530
6597
|
"debug": "",
|
|
6531
6598
|
"err": "",
|
|
6599
|
+
"info": "",
|
|
6532
6600
|
"out": "Total Upload: xx KiB / gzip: xx KiB
|
|
6533
6601
|
Uploaded test-name (TIMINGS)
|
|
6534
6602
|
Published test-name (TIMINGS)
|
|
@@ -6553,6 +6621,7 @@ addEventListener('fetch', event => {});`
|
|
|
6553
6621
|
Object {
|
|
6554
6622
|
"debug": "",
|
|
6555
6623
|
"err": "",
|
|
6624
|
+
"info": "",
|
|
6556
6625
|
"out": "Total Upload: xx KiB / gzip: xx KiB
|
|
6557
6626
|
Uploaded test-name (TIMINGS)
|
|
6558
6627
|
Published test-name (TIMINGS)
|
|
@@ -6563,6 +6632,48 @@ addEventListener('fetch', event => {});`
|
|
|
6563
6632
|
`);
|
|
6564
6633
|
});
|
|
6565
6634
|
|
|
6635
|
+
it("should preserve the entry point file name, even when using a facade", async () => {
|
|
6636
|
+
writeWranglerToml();
|
|
6637
|
+
writeWorkerSource();
|
|
6638
|
+
mockSubDomainRequest();
|
|
6639
|
+
mockUploadWorkerRequest();
|
|
6640
|
+
const assets = [
|
|
6641
|
+
{ filePath: "file-1.txt", content: "Content of file-1" },
|
|
6642
|
+
{ filePath: "file-2.txt", content: "Content of file-2" },
|
|
6643
|
+
];
|
|
6644
|
+
const kvNamespace = {
|
|
6645
|
+
title: "__test-name-workers_sites_assets",
|
|
6646
|
+
id: "__test-name-workers_sites_assets-id",
|
|
6647
|
+
};
|
|
6648
|
+
writeAssets(assets);
|
|
6649
|
+
mockListKVNamespacesRequest(kvNamespace);
|
|
6650
|
+
mockKeyListRequest(kvNamespace.id, []);
|
|
6651
|
+
mockUploadAssetsToKVRequest(kvNamespace.id, assets);
|
|
6652
|
+
await runWrangler("publish index.js --outdir some-dir --assets assets");
|
|
6653
|
+
expect(fs.existsSync("some-dir/index.js")).toBe(true);
|
|
6654
|
+
expect(fs.existsSync("some-dir/index.js.map")).toBe(true);
|
|
6655
|
+
expect(std).toMatchInlineSnapshot(`
|
|
6656
|
+
Object {
|
|
6657
|
+
"debug": "",
|
|
6658
|
+
"err": "",
|
|
6659
|
+
"info": "",
|
|
6660
|
+
"out": "Reading file-1.txt...
|
|
6661
|
+
Uploading as file-1.2ca234f380.txt...
|
|
6662
|
+
Reading file-2.txt...
|
|
6663
|
+
Uploading as file-2.5938485188.txt...
|
|
6664
|
+
↗️ Done syncing assets
|
|
6665
|
+
Total Upload: xx KiB / gzip: xx KiB
|
|
6666
|
+
Uploaded test-name (TIMINGS)
|
|
6667
|
+
Published test-name (TIMINGS)
|
|
6668
|
+
https://test-name.test-sub-domain.workers.dev
|
|
6669
|
+
Current Deployment ID: Galaxy-Class",
|
|
6670
|
+
"warn": "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mThe --assets argument is experimental and may change or break at any time[0m
|
|
6671
|
+
|
|
6672
|
+
",
|
|
6673
|
+
}
|
|
6674
|
+
`);
|
|
6675
|
+
});
|
|
6676
|
+
|
|
6566
6677
|
it("should copy any module imports related assets to --outdir if specified", async () => {
|
|
6567
6678
|
writeWranglerToml();
|
|
6568
6679
|
fs.writeFileSync(
|
|
@@ -6608,6 +6719,7 @@ export default{
|
|
|
6608
6719
|
Object {
|
|
6609
6720
|
"debug": "",
|
|
6610
6721
|
"err": "",
|
|
6722
|
+
"info": "",
|
|
6611
6723
|
"out": "Total Upload: xx KiB / gzip: xx KiB
|
|
6612
6724
|
Uploaded test-name (TIMINGS)
|
|
6613
6725
|
Published test-name (TIMINGS)
|
|
@@ -6636,6 +6748,7 @@ export default{
|
|
|
6636
6748
|
Object {
|
|
6637
6749
|
"debug": "",
|
|
6638
6750
|
"err": "",
|
|
6751
|
+
"info": "",
|
|
6639
6752
|
"out": "Total Upload: xx KiB / gzip: xx KiB
|
|
6640
6753
|
Your worker has access to the following bindings:
|
|
6641
6754
|
- Durable Objects:
|
|
@@ -6653,16 +6766,17 @@ export default{
|
|
|
6653
6766
|
writeWorkerSource();
|
|
6654
6767
|
await runWrangler("publish index.js --node-compat --dry-run");
|
|
6655
6768
|
expect(std).toMatchInlineSnapshot(`
|
|
6656
|
-
|
|
6657
|
-
|
|
6658
|
-
|
|
6659
|
-
|
|
6660
|
-
|
|
6661
|
-
|
|
6662
|
-
|
|
6663
|
-
|
|
6664
|
-
|
|
6665
|
-
|
|
6769
|
+
Object {
|
|
6770
|
+
"debug": "",
|
|
6771
|
+
"err": "",
|
|
6772
|
+
"info": "",
|
|
6773
|
+
"out": "Total Upload: xx KiB / gzip: xx KiB
|
|
6774
|
+
--dry-run: exiting now.",
|
|
6775
|
+
"warn": "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mEnabling Node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.[0m
|
|
6776
|
+
|
|
6777
|
+
",
|
|
6778
|
+
}
|
|
6779
|
+
`);
|
|
6666
6780
|
});
|
|
6667
6781
|
|
|
6668
6782
|
it("should recommend node compatibility mode when using node builtins and node-compat isn't enabled", async () => {
|
|
@@ -6700,16 +6814,90 @@ export default{
|
|
|
6700
6814
|
);
|
|
6701
6815
|
await runWrangler("publish index.js --node-compat --dry-run"); // this would throw if node compatibility didn't exist
|
|
6702
6816
|
expect(std).toMatchInlineSnapshot(`
|
|
6703
|
-
|
|
6704
|
-
|
|
6705
|
-
|
|
6706
|
-
|
|
6707
|
-
|
|
6708
|
-
|
|
6709
|
-
|
|
6710
|
-
|
|
6711
|
-
|
|
6712
|
-
|
|
6817
|
+
Object {
|
|
6818
|
+
"debug": "",
|
|
6819
|
+
"err": "",
|
|
6820
|
+
"info": "",
|
|
6821
|
+
"out": "Total Upload: xx KiB / gzip: xx KiB
|
|
6822
|
+
--dry-run: exiting now.",
|
|
6823
|
+
"warn": "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mEnabling Node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.[0m
|
|
6824
|
+
|
|
6825
|
+
",
|
|
6826
|
+
}
|
|
6827
|
+
`);
|
|
6828
|
+
});
|
|
6829
|
+
});
|
|
6830
|
+
|
|
6831
|
+
describe("`nodejs_compat` compatibility flag", () => {
|
|
6832
|
+
it('when absent, should error on any "external" `node:*` imports', async () => {
|
|
6833
|
+
writeWranglerToml();
|
|
6834
|
+
fs.writeFileSync(
|
|
6835
|
+
"index.js",
|
|
6836
|
+
`
|
|
6837
|
+
import AsyncHooks from 'node:async_hooks';
|
|
6838
|
+
console.log(AsyncHooks);
|
|
6839
|
+
export default {}
|
|
6840
|
+
`
|
|
6841
|
+
);
|
|
6842
|
+
let err: esbuild.BuildFailure | undefined;
|
|
6843
|
+
try {
|
|
6844
|
+
await runWrangler("publish index.js --dry-run"); // expecting this to throw, as node compatibility isn't enabled
|
|
6845
|
+
} catch (e) {
|
|
6846
|
+
err = e as esbuild.BuildFailure;
|
|
6847
|
+
}
|
|
6848
|
+
expect(
|
|
6849
|
+
esbuild.formatMessagesSync(err?.errors ?? [], { kind: "error" }).join()
|
|
6850
|
+
).toMatch(/Could not resolve "node:async_hooks"/);
|
|
6851
|
+
});
|
|
6852
|
+
|
|
6853
|
+
it('when present, should support any "external" `node:*` imports', async () => {
|
|
6854
|
+
writeWranglerToml();
|
|
6855
|
+
fs.writeFileSync(
|
|
6856
|
+
"index.js",
|
|
6857
|
+
`
|
|
6858
|
+
import AsyncHooks from 'node:async_hooks';
|
|
6859
|
+
console.log(AsyncHooks);
|
|
6860
|
+
export default {}
|
|
6861
|
+
`
|
|
6862
|
+
);
|
|
6863
|
+
|
|
6864
|
+
await runWrangler(
|
|
6865
|
+
"publish index.js --dry-run --outdir=dist --compatibility-flag=nodejs_compat"
|
|
6866
|
+
);
|
|
6867
|
+
|
|
6868
|
+
expect(std).toMatchInlineSnapshot(`
|
|
6869
|
+
Object {
|
|
6870
|
+
"debug": "",
|
|
6871
|
+
"err": "",
|
|
6872
|
+
"info": "",
|
|
6873
|
+
"out": "Total Upload: xx KiB / gzip: xx KiB
|
|
6874
|
+
--dry-run: exiting now.",
|
|
6875
|
+
"warn": "",
|
|
6876
|
+
}
|
|
6877
|
+
`);
|
|
6878
|
+
expect(fs.readFileSync("dist/index.js", { encoding: "utf-8" })).toContain(
|
|
6879
|
+
`import AsyncHooks from "node:async_hooks";`
|
|
6880
|
+
);
|
|
6881
|
+
});
|
|
6882
|
+
|
|
6883
|
+
it("should conflict with the --node-compat option", async () => {
|
|
6884
|
+
writeWranglerToml();
|
|
6885
|
+
fs.writeFileSync(
|
|
6886
|
+
"index.js",
|
|
6887
|
+
`
|
|
6888
|
+
import AsyncHooks from 'node:async_hooks';
|
|
6889
|
+
console.log(AsyncHooks);
|
|
6890
|
+
export default {}
|
|
6891
|
+
`
|
|
6892
|
+
);
|
|
6893
|
+
|
|
6894
|
+
await expect(
|
|
6895
|
+
runWrangler(
|
|
6896
|
+
"publish index.js --dry-run --outdir=dist --compatibility-flag=nodejs_compat --node-compat"
|
|
6897
|
+
)
|
|
6898
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
6899
|
+
`"The \`nodejs_compat\` compatibility flag cannot be used in conjunction with the legacy \`--node-compat\` flag. If you want to use the Workers runtime Node.js compatibility features, please remove the \`--node-compat\` argument from your CLI command or \`node_compat = true\` from your config file."`
|
|
6900
|
+
);
|
|
6713
6901
|
});
|
|
6714
6902
|
});
|
|
6715
6903
|
|
|
@@ -6754,6 +6942,7 @@ export default{
|
|
|
6754
6942
|
Object {
|
|
6755
6943
|
"debug": "",
|
|
6756
6944
|
"err": "",
|
|
6945
|
+
"info": "",
|
|
6757
6946
|
"out": "Total Upload: xx KiB / gzip: xx KiB
|
|
6758
6947
|
Uploaded test-name (TIMINGS)
|
|
6759
6948
|
Published test-name (TIMINGS)
|
|
@@ -6816,23 +7005,24 @@ export default{
|
|
|
6816
7005
|
`[ParseError: A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name) failed.]`
|
|
6817
7006
|
);
|
|
6818
7007
|
expect(std).toMatchInlineSnapshot(`
|
|
6819
|
-
|
|
6820
|
-
|
|
6821
|
-
|
|
6822
|
-
|
|
7008
|
+
Object {
|
|
7009
|
+
"debug": "",
|
|
7010
|
+
"err": "",
|
|
7011
|
+
"info": "",
|
|
7012
|
+
"out": "Total Upload: xx KiB / gzip: xx KiB
|
|
6823
7013
|
|
|
6824
|
-
|
|
7014
|
+
[31mX [41;31m[[41;97mERROR[41;31m][0m [1mA request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name) failed.[0m
|
|
6825
7015
|
|
|
6826
|
-
|
|
6827
|
-
|
|
7016
|
+
Script startup timed out. This could be due to script exceeding size limits or expensive code in
|
|
7017
|
+
the global scope. [code: 11337]
|
|
6828
7018
|
|
|
6829
|
-
|
|
6830
|
-
|
|
7019
|
+
If you think this is a bug, please open an issue at:
|
|
7020
|
+
[4mhttps://github.com/cloudflare/workers-sdk/issues/new/choose[0m
|
|
6831
7021
|
|
|
6832
|
-
|
|
6833
|
-
|
|
6834
|
-
|
|
6835
|
-
|
|
7022
|
+
",
|
|
7023
|
+
"warn": "",
|
|
7024
|
+
}
|
|
7025
|
+
`);
|
|
6836
7026
|
});
|
|
6837
7027
|
|
|
6838
7028
|
test("should check biggest dependencies when upload fails with script size error", async () => {
|
|
@@ -6882,6 +7072,7 @@ export default{
|
|
|
6882
7072
|
Object {
|
|
6883
7073
|
"debug": "",
|
|
6884
7074
|
"err": "",
|
|
7075
|
+
"info": "",
|
|
6885
7076
|
"out": "Total Upload: xx KiB / gzip: xx KiB
|
|
6886
7077
|
|
|
6887
7078
|
[31mX [41;31m[[41;97mERROR[41;31m][0m [1mA request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name) failed.[0m
|
|
@@ -6948,6 +7139,7 @@ export default{
|
|
|
6948
7139
|
Object {
|
|
6949
7140
|
"debug": "",
|
|
6950
7141
|
"err": "",
|
|
7142
|
+
"info": "",
|
|
6951
7143
|
"out": "Total Upload: xx KiB / gzip: xx KiB
|
|
6952
7144
|
|
|
6953
7145
|
[31mX [41;31m[[41;97mERROR[41;31m][0m [1mA request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name) failed.[0m
|
|
@@ -6986,6 +7178,7 @@ export default{
|
|
|
6986
7178
|
Object {
|
|
6987
7179
|
"debug": "",
|
|
6988
7180
|
"err": "",
|
|
7181
|
+
"info": "",
|
|
6989
7182
|
"out": "Total Upload: xx KiB / gzip: xx KiB",
|
|
6990
7183
|
"warn": "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mWe recommend keeping your script less than 1MiB (1024 KiB) after gzip. Exceeding past this can affect cold start time[0m
|
|
6991
7184
|
|
|
@@ -7008,6 +7201,7 @@ export default{
|
|
|
7008
7201
|
Object {
|
|
7009
7202
|
"debug": "",
|
|
7010
7203
|
"err": "",
|
|
7204
|
+
"info": "",
|
|
7011
7205
|
"out": "Total Upload: xx KiB / gzip: xx KiB",
|
|
7012
7206
|
"warn": "",
|
|
7013
7207
|
}
|
|
@@ -7036,6 +7230,7 @@ export default{
|
|
|
7036
7230
|
Object {
|
|
7037
7231
|
"debug": "",
|
|
7038
7232
|
"err": "",
|
|
7233
|
+
"info": "",
|
|
7039
7234
|
"out": "",
|
|
7040
7235
|
"warn": "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mHere are the 5 largest dependencies included in your script:[0m
|
|
7041
7236
|
|
|
@@ -7125,7 +7320,7 @@ export default{
|
|
|
7125
7320
|
"publish index.js --no-bundle --node-compat --dry-run --outdir dist"
|
|
7126
7321
|
);
|
|
7127
7322
|
expect(std.warn).toMatchInlineSnapshot(`
|
|
7128
|
-
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mEnabling
|
|
7323
|
+
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mEnabling Node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.[0m
|
|
7129
7324
|
|
|
7130
7325
|
|
|
7131
7326
|
[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1m\`--node-compat\` and \`--no-bundle\` can't be used together. If you want to polyfill Node.js built-ins and disable Wrangler's bundling, please polyfill as part of your own bundling process.[0m
|
|
@@ -7145,7 +7340,7 @@ export default{
|
|
|
7145
7340
|
fs.writeFileSync("index.js", scriptContent);
|
|
7146
7341
|
await runWrangler("publish index.js --dry-run --outdir dist");
|
|
7147
7342
|
expect(std.warn).toMatchInlineSnapshot(`
|
|
7148
|
-
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mEnabling
|
|
7343
|
+
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mEnabling Node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.[0m
|
|
7149
7344
|
|
|
7150
7345
|
|
|
7151
7346
|
[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1m\`--node-compat\` and \`--no-bundle\` can't be used together. If you want to polyfill Node.js built-ins and disable Wrangler's bundling, please polyfill as part of your own bundling process.[0m
|
|
@@ -7155,53 +7350,6 @@ export default{
|
|
|
7155
7350
|
});
|
|
7156
7351
|
});
|
|
7157
7352
|
|
|
7158
|
-
it("should publish if the last deployed source check fails", async () => {
|
|
7159
|
-
writeWorkerSource();
|
|
7160
|
-
writeWranglerToml();
|
|
7161
|
-
mockSubDomainRequest();
|
|
7162
|
-
mockUploadWorkerRequest();
|
|
7163
|
-
msw.use(
|
|
7164
|
-
rest.get(
|
|
7165
|
-
"*/accounts/:accountId/workers/deployments/by-script/:scriptTag",
|
|
7166
|
-
(_, res, ctx) => {
|
|
7167
|
-
return res(
|
|
7168
|
-
ctx.json(
|
|
7169
|
-
createFetchResult({
|
|
7170
|
-
latest: { number: "2" },
|
|
7171
|
-
})
|
|
7172
|
-
)
|
|
7173
|
-
);
|
|
7174
|
-
}
|
|
7175
|
-
),
|
|
7176
|
-
rest.get(
|
|
7177
|
-
"*/accounts/:accountId/workers/services/:scriptName",
|
|
7178
|
-
(_, res, ctx) => {
|
|
7179
|
-
return res(
|
|
7180
|
-
ctx.json(
|
|
7181
|
-
createFetchResult(null, false, [
|
|
7182
|
-
{ code: 10090, message: "workers.api.error.service_not_found" },
|
|
7183
|
-
])
|
|
7184
|
-
)
|
|
7185
|
-
);
|
|
7186
|
-
}
|
|
7187
|
-
)
|
|
7188
|
-
);
|
|
7189
|
-
|
|
7190
|
-
await runWrangler("publish index.js");
|
|
7191
|
-
expect(std).toMatchInlineSnapshot(`
|
|
7192
|
-
Object {
|
|
7193
|
-
"debug": "",
|
|
7194
|
-
"err": "",
|
|
7195
|
-
"out": "Total Upload: xx KiB / gzip: xx KiB
|
|
7196
|
-
Uploaded test-name (TIMINGS)
|
|
7197
|
-
Published test-name (TIMINGS)
|
|
7198
|
-
https://test-name.test-sub-domain.workers.dev
|
|
7199
|
-
Current Deployment ID: undefined",
|
|
7200
|
-
"warn": "",
|
|
7201
|
-
}
|
|
7202
|
-
`);
|
|
7203
|
-
});
|
|
7204
|
-
|
|
7205
7353
|
it("should not publish if there's any other kind of error when checking deployment source", async () => {
|
|
7206
7354
|
writeWorkerSource();
|
|
7207
7355
|
writeWranglerToml();
|
|
@@ -7311,6 +7459,83 @@ export default{
|
|
|
7311
7459
|
`);
|
|
7312
7460
|
});
|
|
7313
7461
|
|
|
7462
|
+
it("should support queue consumer concurrency with a max concurrency specified", async () => {
|
|
7463
|
+
writeWranglerToml({
|
|
7464
|
+
queues: {
|
|
7465
|
+
consumers: [
|
|
7466
|
+
{
|
|
7467
|
+
queue: "queue1",
|
|
7468
|
+
dead_letter_queue: "myDLQ",
|
|
7469
|
+
max_batch_size: 5,
|
|
7470
|
+
max_batch_timeout: 3,
|
|
7471
|
+
max_retries: 10,
|
|
7472
|
+
max_concurrency: 5,
|
|
7473
|
+
},
|
|
7474
|
+
],
|
|
7475
|
+
},
|
|
7476
|
+
});
|
|
7477
|
+
await fs.promises.writeFile("index.js", `export default {};`);
|
|
7478
|
+
mockSubDomainRequest();
|
|
7479
|
+
mockUploadWorkerRequest();
|
|
7480
|
+
mockGetQueue("queue1");
|
|
7481
|
+
mockPutQueueConsumer("queue1", "test-name", {
|
|
7482
|
+
dead_letter_queue: "myDLQ",
|
|
7483
|
+
settings: {
|
|
7484
|
+
batch_size: 5,
|
|
7485
|
+
max_retries: 10,
|
|
7486
|
+
max_wait_time_ms: 3000,
|
|
7487
|
+
max_concurrency: 5,
|
|
7488
|
+
},
|
|
7489
|
+
});
|
|
7490
|
+
await runWrangler("publish index.js");
|
|
7491
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
7492
|
+
"Total Upload: xx KiB / gzip: xx KiB
|
|
7493
|
+
Uploaded test-name (TIMINGS)
|
|
7494
|
+
Published test-name (TIMINGS)
|
|
7495
|
+
https://test-name.test-sub-domain.workers.dev
|
|
7496
|
+
Consumer for queue1
|
|
7497
|
+
Current Deployment ID: Galaxy-Class"
|
|
7498
|
+
`);
|
|
7499
|
+
});
|
|
7500
|
+
|
|
7501
|
+
it("should support queue consumer concurrency with a null max concurrency", async () => {
|
|
7502
|
+
writeWranglerToml({
|
|
7503
|
+
queues: {
|
|
7504
|
+
consumers: [
|
|
7505
|
+
{
|
|
7506
|
+
queue: "queue1",
|
|
7507
|
+
dead_letter_queue: "myDLQ",
|
|
7508
|
+
max_batch_size: 5,
|
|
7509
|
+
max_batch_timeout: 3,
|
|
7510
|
+
max_retries: 10,
|
|
7511
|
+
max_concurrency: null,
|
|
7512
|
+
},
|
|
7513
|
+
],
|
|
7514
|
+
},
|
|
7515
|
+
});
|
|
7516
|
+
await fs.promises.writeFile("index.js", `export default {};`);
|
|
7517
|
+
mockSubDomainRequest();
|
|
7518
|
+
mockUploadWorkerRequest();
|
|
7519
|
+
mockGetQueue("queue1");
|
|
7520
|
+
mockPutQueueConsumer("queue1", "test-name", {
|
|
7521
|
+
dead_letter_queue: "myDLQ",
|
|
7522
|
+
settings: {
|
|
7523
|
+
batch_size: 5,
|
|
7524
|
+
max_retries: 10,
|
|
7525
|
+
max_wait_time_ms: 3000,
|
|
7526
|
+
},
|
|
7527
|
+
});
|
|
7528
|
+
await runWrangler("publish index.js");
|
|
7529
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
7530
|
+
"Total Upload: xx KiB / gzip: xx KiB
|
|
7531
|
+
Uploaded test-name (TIMINGS)
|
|
7532
|
+
Published test-name (TIMINGS)
|
|
7533
|
+
https://test-name.test-sub-domain.workers.dev
|
|
7534
|
+
Consumer for queue1
|
|
7535
|
+
Current Deployment ID: Galaxy-Class"
|
|
7536
|
+
`);
|
|
7537
|
+
});
|
|
7538
|
+
|
|
7314
7539
|
it("consumer should error when a queue doesn't exist", async () => {
|
|
7315
7540
|
writeWranglerToml({
|
|
7316
7541
|
queues: {
|
|
@@ -7439,6 +7664,33 @@ export default{
|
|
|
7439
7664
|
`);
|
|
7440
7665
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
7441
7666
|
});
|
|
7667
|
+
|
|
7668
|
+
it("should send keepVars when `keep_vars = true`", async () => {
|
|
7669
|
+
process.env = {
|
|
7670
|
+
CLOUDFLARE_API_TOKEN: "hunter2",
|
|
7671
|
+
CLOUDFLARE_ACCOUNT_ID: "some-account-id",
|
|
7672
|
+
};
|
|
7673
|
+
setIsTTY(false);
|
|
7674
|
+
writeWranglerToml({
|
|
7675
|
+
keep_vars: true,
|
|
7676
|
+
});
|
|
7677
|
+
writeWorkerSource();
|
|
7678
|
+
mockSubDomainRequest();
|
|
7679
|
+
mockUploadWorkerRequest({ keepVars: true });
|
|
7680
|
+
mockOAuthServerCallback();
|
|
7681
|
+
mockGetMemberships([]);
|
|
7682
|
+
|
|
7683
|
+
await runWrangler("publish index.js");
|
|
7684
|
+
|
|
7685
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
7686
|
+
"Total Upload: xx KiB / gzip: xx KiB
|
|
7687
|
+
Uploaded test-name (TIMINGS)
|
|
7688
|
+
Published test-name (TIMINGS)
|
|
7689
|
+
https://test-name.test-sub-domain.workers.dev
|
|
7690
|
+
Current Deployment ID: Galaxy-Class"
|
|
7691
|
+
`);
|
|
7692
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
7693
|
+
});
|
|
7442
7694
|
});
|
|
7443
7695
|
});
|
|
7444
7696
|
|
|
@@ -7460,7 +7712,7 @@ function mockDeploymentsListRequest() {
|
|
|
7460
7712
|
}
|
|
7461
7713
|
|
|
7462
7714
|
function mockLastDeploymentRequest() {
|
|
7463
|
-
msw.use(...
|
|
7715
|
+
msw.use(...mswSuccessDeploymentScriptMetadata);
|
|
7464
7716
|
}
|
|
7465
7717
|
|
|
7466
7718
|
/** Create a mock handler for the request to upload a worker script. */
|
|
@@ -7475,9 +7727,9 @@ function mockUploadWorkerRequest(
|
|
|
7475
7727
|
expectedCompatibilityDate?: string;
|
|
7476
7728
|
expectedCompatibilityFlags?: string[];
|
|
7477
7729
|
expectedMigrations?: CfWorkerInit["migrations"];
|
|
7730
|
+
expectedUnsafeMetaData?: Record<string, string>;
|
|
7478
7731
|
env?: string;
|
|
7479
7732
|
legacyEnv?: boolean;
|
|
7480
|
-
sendScriptIds?: boolean;
|
|
7481
7733
|
keepVars?: boolean;
|
|
7482
7734
|
tag?: string;
|
|
7483
7735
|
} = {}
|
|
@@ -7494,7 +7746,7 @@ function mockUploadWorkerRequest(
|
|
|
7494
7746
|
env = undefined,
|
|
7495
7747
|
legacyEnv = false,
|
|
7496
7748
|
expectedMigrations,
|
|
7497
|
-
|
|
7749
|
+
expectedUnsafeMetaData,
|
|
7498
7750
|
keepVars,
|
|
7499
7751
|
} = options;
|
|
7500
7752
|
if (env && !legacyEnv) {
|
|
@@ -7563,6 +7815,11 @@ function mockUploadWorkerRequest(
|
|
|
7563
7815
|
if ("expectedMigrations" in options) {
|
|
7564
7816
|
expect(metadata.migrations).toEqual(expectedMigrations);
|
|
7565
7817
|
}
|
|
7818
|
+
if (expectedUnsafeMetaData !== undefined) {
|
|
7819
|
+
Object.keys(expectedUnsafeMetaData).forEach((key) => {
|
|
7820
|
+
expect(metadata[key]).toEqual(expectedUnsafeMetaData[key]);
|
|
7821
|
+
});
|
|
7822
|
+
}
|
|
7566
7823
|
for (const [name, content] of Object.entries(expectedModules)) {
|
|
7567
7824
|
expect(formBody.get(name)).toEqual(content);
|
|
7568
7825
|
}
|
|
@@ -7571,12 +7828,11 @@ function mockUploadWorkerRequest(
|
|
|
7571
7828
|
ctx.json(
|
|
7572
7829
|
createFetchResult({
|
|
7573
7830
|
available_on_subdomain,
|
|
7574
|
-
|
|
7575
|
-
|
|
7576
|
-
|
|
7577
|
-
|
|
7578
|
-
|
|
7579
|
-
}),
|
|
7831
|
+
id: "abc12345",
|
|
7832
|
+
etag: "etag98765",
|
|
7833
|
+
pipeline_hash: "hash9999",
|
|
7834
|
+
tag: "sample-tag",
|
|
7835
|
+
deployment_id: "Galaxy-Class",
|
|
7580
7836
|
})
|
|
7581
7837
|
)
|
|
7582
7838
|
);
|