wrangler 2.1.14 → 2.2.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.
Files changed (75) hide show
  1. package/miniflare-dist/index.mjs +3 -1
  2. package/package.json +2 -1
  3. package/src/__tests__/access.test.ts +25 -0
  4. package/src/__tests__/api-dev.test.ts +1 -1
  5. package/src/__tests__/api-devregistry.test.js +2 -2
  6. package/src/__tests__/configuration.test.ts +119 -2
  7. package/src/__tests__/d1.test.ts +2 -0
  8. package/src/__tests__/deployments.test.ts +22 -22
  9. package/src/__tests__/dev.test.tsx +167 -15
  10. package/src/__tests__/helpers/msw/handlers/access.ts +13 -0
  11. package/src/__tests__/helpers/msw/handlers/deployments.ts +22 -43
  12. package/src/__tests__/helpers/msw/handlers/zones.ts +22 -0
  13. package/src/__tests__/helpers/msw/index.ts +4 -0
  14. package/src/__tests__/index.test.ts +42 -33
  15. package/src/__tests__/init.test.ts +88 -4
  16. package/src/__tests__/jest.setup.ts +11 -0
  17. package/src/__tests__/kv.test.ts +400 -400
  18. package/src/__tests__/pages.test.ts +140 -28
  19. package/src/__tests__/publish.test.ts +1161 -647
  20. package/src/__tests__/pubsub.test.ts +3 -0
  21. package/src/__tests__/queues.test.ts +371 -0
  22. package/src/__tests__/r2.test.ts +57 -52
  23. package/src/__tests__/worker-namespace.test.ts +15 -10
  24. package/src/bundle-reporter.tsx +41 -2
  25. package/src/bundle.ts +59 -30
  26. package/src/cli.ts +0 -1
  27. package/src/config/environment.ts +50 -0
  28. package/src/config/index.ts +41 -0
  29. package/src/config/validation.ts +173 -0
  30. package/src/create-worker-preview.ts +10 -3
  31. package/src/create-worker-upload-form.ts +12 -0
  32. package/src/d1/backups.tsx +11 -5
  33. package/src/d1/execute.tsx +52 -47
  34. package/src/d1/index.ts +2 -1
  35. package/src/delete.ts +7 -10
  36. package/src/deployments.ts +73 -0
  37. package/src/deprecated/index.ts +9 -24
  38. package/src/dev/dev-vars.ts +11 -8
  39. package/src/dev/dev.tsx +12 -0
  40. package/src/dev/local.tsx +26 -0
  41. package/src/dev/remote.tsx +2 -0
  42. package/src/dev/start-server.ts +7 -0
  43. package/src/dev/use-esbuild.ts +12 -5
  44. package/src/dev.tsx +12 -9
  45. package/src/dispatch-namespace.ts +4 -3
  46. package/src/index.tsx +61 -45
  47. package/src/init.ts +4 -4
  48. package/src/inspect.ts +21 -1
  49. package/src/is-interactive.ts +4 -0
  50. package/src/kv/index.ts +5 -54
  51. package/src/logger.ts +12 -0
  52. package/src/pages/constants.ts +2 -0
  53. package/src/pages/upload.tsx +42 -15
  54. package/src/proxy.ts +38 -6
  55. package/src/publish/index.ts +11 -8
  56. package/src/publish/publish.ts +151 -30
  57. package/src/pubsub/pubsub-commands.tsx +3 -2
  58. package/src/queues/cli/commands/consumer/add.ts +71 -0
  59. package/src/queues/cli/commands/consumer/index.ts +22 -0
  60. package/src/queues/cli/commands/consumer/remove.ts +38 -0
  61. package/src/queues/cli/commands/create.ts +25 -0
  62. package/src/queues/cli/commands/delete.ts +26 -0
  63. package/src/queues/cli/commands/index.ts +33 -0
  64. package/src/queues/cli/commands/list.ts +25 -0
  65. package/src/queues/client.ts +135 -0
  66. package/src/secret/index.ts +14 -39
  67. package/src/tail/index.ts +5 -8
  68. package/src/user/access.ts +69 -0
  69. package/src/worker.ts +7 -0
  70. package/src/yargs-types.ts +15 -2
  71. package/src/zones.ts +31 -5
  72. package/templates/pages-template-plugin.ts +4 -0
  73. package/templates/pages-template-worker.ts +21 -4
  74. package/wrangler-dist/cli.d.ts +42 -0
  75. package/wrangler-dist/cli.js +4559 -3228
@@ -60,23 +60,24 @@ describe("pages", () => {
60
60
  await endEventLoop();
61
61
 
62
62
  expect(std.out).toMatchInlineSnapshot(`
63
- "wrangler pages
63
+ "wrangler pages
64
64
 
65
- ⚡️ Configure Cloudflare Pages
65
+ ⚡️ Configure Cloudflare Pages
66
66
 
67
- Commands:
68
- wrangler pages dev [directory] [-- command..] 🧑‍💻 Develop your full-stack Pages application locally
69
- wrangler pages project ⚡️ Interact with your Pages projects
70
- wrangler pages deployment 🚀 Interact with the deployments of a project
71
- wrangler pages publish [directory] 🆙 Publish a directory of static assets as a Pages deployment
67
+ Commands:
68
+ wrangler pages dev [directory] [-- command..] 🧑‍💻 Develop your full-stack Pages application locally
69
+ wrangler pages project ⚡️ Interact with your Pages projects
70
+ wrangler pages deployment 🚀 Interact with the deployments of a project
71
+ wrangler pages publish [directory] 🆙 Publish a directory of static assets as a Pages deployment
72
72
 
73
- Flags:
74
- -c, --config Path to .toml configuration file [string]
75
- -h, --help Show help [boolean]
76
- -v, --version Show version number [boolean]
73
+ Flags:
74
+ -c, --config Path to .toml configuration file [string]
75
+ -e, --env Environment to use for operations and .env files [string]
76
+ -h, --help Show help [boolean]
77
+ -v, --version Show version number [boolean]
77
78
 
78
- 🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/wrangler2/issues/new/choose"
79
- `);
79
+ 🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/wrangler2/issues/new/choose"
80
+ `);
80
81
  });
81
82
 
82
83
  describe("beta message for subcommands", () => {
@@ -315,26 +316,27 @@ describe("pages", () => {
315
316
  await endEventLoop();
316
317
 
317
318
  expect(std.out).toMatchInlineSnapshot(`
318
- "wrangler pages publish [directory]
319
+ "wrangler pages publish [directory]
319
320
 
320
- 🆙 Publish a directory of static assets as a Pages deployment
321
+ 🆙 Publish a directory of static assets as a Pages deployment
321
322
 
322
- Positionals:
323
- directory The directory of static files to upload [string]
323
+ Positionals:
324
+ directory The directory of static files to upload [string]
324
325
 
325
- Flags:
326
- -h, --help Show help [boolean]
327
- -v, --version Show version number [boolean]
326
+ Flags:
327
+ -e, --env Environment to use for operations and .env files [string]
328
+ -h, --help Show help [boolean]
329
+ -v, --version Show version number [boolean]
328
330
 
329
- Options:
330
- --project-name The name of the project you want to deploy to [string]
331
- --branch The name of the branch you want to deploy to [string]
332
- --commit-hash The SHA to attach to this deployment [string]
333
- --commit-message The commit message to attach to this deployment [string]
334
- --commit-dirty Whether or not the workspace should be considered dirty for this deployment [boolean]
331
+ Options:
332
+ --project-name The name of the project you want to deploy to [string]
333
+ --branch The name of the branch you want to deploy to [string]
334
+ --commit-hash The SHA to attach to this deployment [string]
335
+ --commit-message The commit message to attach to this deployment [string]
336
+ --commit-dirty Whether or not the workspace should be considered dirty for this deployment [boolean]
335
337
 
336
- 🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/wrangler2/issues/new/choose"
337
- `);
338
+ 🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/wrangler2/issues/new/choose"
339
+ `);
338
340
  });
339
341
 
340
342
  it("should upload a directory of files", async () => {
@@ -1905,6 +1907,116 @@ and that at least one include rule is provided.
1905
1907
  `);
1906
1908
  });
1907
1909
 
1910
+ it("should avoid uploading some files", async () => {
1911
+ mkdirSync("some_dir/node_modules", { recursive: true });
1912
+ mkdirSync("some_dir/functions", { recursive: true });
1913
+
1914
+ writeFileSync("logo.png", "foobar");
1915
+ writeFileSync("some_dir/functions/foo.js", "func");
1916
+ writeFileSync("some_dir/_headers", "headersfile");
1917
+
1918
+ writeFileSync("_headers", "headersfile");
1919
+ writeFileSync("_redirects", "redirectsfile");
1920
+ writeFileSync("_worker.js", "workerfile");
1921
+ writeFileSync("_routes.json", "routesfile");
1922
+ mkdirSync(".git");
1923
+ writeFileSync(".git/foo", "gitfile");
1924
+ writeFileSync("some_dir/node_modules/some_package", "nodefile");
1925
+ mkdirSync("functions");
1926
+ writeFileSync("functions/foo.js", "func");
1927
+
1928
+ setMockResponse(
1929
+ "/pages/assets/check-missing",
1930
+ "POST",
1931
+ async (_, init) => {
1932
+ const body = JSON.parse(init.body as string) as { hashes: string[] };
1933
+ assertLater(() => {
1934
+ expect(init.headers).toMatchObject({
1935
+ Authorization: "Bearer <<funfetti-auth-jwt>>",
1936
+ });
1937
+ expect(body).toMatchObject({
1938
+ hashes: [
1939
+ "2082190357cfd3617ccfe04f340c6247",
1940
+ "95dedb64e6d4940fc2e0f11f711cc2f4",
1941
+ "09a79777abda8ccc8bdd51dd3ff8e9e9",
1942
+ ],
1943
+ });
1944
+ });
1945
+ return body.hashes;
1946
+ }
1947
+ );
1948
+
1949
+ // Accumulate multiple requests then assert afterwards
1950
+ const requests: RequestInit[] = [];
1951
+ setMockRawResponse("/pages/assets/upload", "POST", async (_, init) => {
1952
+ requests.push(init);
1953
+
1954
+ return createFetchResult(null, true);
1955
+ });
1956
+
1957
+ assertLater(() => {
1958
+ expect(requests.length).toBe(3);
1959
+
1960
+ expect(requests[0].headers).toMatchObject({
1961
+ Authorization: "Bearer <<funfetti-auth-jwt>>",
1962
+ });
1963
+
1964
+ let body = JSON.parse(
1965
+ requests[0].body as string
1966
+ ) as UploadPayloadFile[];
1967
+ expect(body).toMatchObject([
1968
+ {
1969
+ key: "95dedb64e6d4940fc2e0f11f711cc2f4",
1970
+ value: Buffer.from("headersfile").toString("base64"),
1971
+ metadata: {
1972
+ contentType: "application/octet-stream",
1973
+ },
1974
+ base64: true,
1975
+ },
1976
+ ]);
1977
+
1978
+ expect(requests[1].headers).toMatchObject({
1979
+ Authorization: "Bearer <<funfetti-auth-jwt>>",
1980
+ });
1981
+
1982
+ body = JSON.parse(requests[1].body as string) as UploadPayloadFile[];
1983
+ expect(body).toMatchObject([
1984
+ {
1985
+ key: "2082190357cfd3617ccfe04f340c6247",
1986
+ value: Buffer.from("foobar").toString("base64"),
1987
+ metadata: {
1988
+ contentType: "image/png",
1989
+ },
1990
+ base64: true,
1991
+ },
1992
+ ]);
1993
+
1994
+ expect(requests[2].headers).toMatchObject({
1995
+ Authorization: "Bearer <<funfetti-auth-jwt>>",
1996
+ });
1997
+
1998
+ body = JSON.parse(requests[2].body as string) as UploadPayloadFile[];
1999
+ expect(body).toMatchObject([
2000
+ {
2001
+ key: "09a79777abda8ccc8bdd51dd3ff8e9e9",
2002
+ value: Buffer.from("func").toString("base64"),
2003
+ metadata: {
2004
+ contentType: "application/javascript",
2005
+ },
2006
+ base64: true,
2007
+ },
2008
+ ]);
2009
+ });
2010
+
2011
+ await runWrangler("pages project upload .");
2012
+
2013
+ expect(std.out).toMatchInlineSnapshot(`
2014
+ "✨ Success! Uploaded 3 files (TIMINGS)
2015
+
2016
+ ✨ Upload complete!"
2017
+ `);
2018
+ });
2019
+
1908
2020
  it("should retry uploads", async () => {
1909
2021
  writeFileSync("logo.txt", "foobar");
1910
2022