wrangler 0.0.0-e33294b0 → 0.0.0-e33bea9b

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 (63) hide show
  1. package/bin/wrangler.js +1 -1
  2. package/miniflare-dist/index.mjs +21 -4
  3. package/package.json +8 -8
  4. package/src/__tests__/configuration.test.ts +235 -6
  5. package/src/__tests__/d1/execute.test.ts +1 -1
  6. package/src/__tests__/dev.test.tsx +16 -1
  7. package/src/__tests__/guess-worker-format.test.ts +35 -0
  8. package/src/__tests__/init.test.ts +9 -8
  9. package/src/__tests__/middleware.test.ts +2 -1
  10. package/src/__tests__/pages/functions-build.test.ts +91 -41
  11. package/src/__tests__/pages/publish.test.ts +136 -61
  12. package/src/__tests__/publish.test.ts +169 -14
  13. package/src/__tests__/test-old-node-version.js +3 -3
  14. package/src/__tests__/tsconfig.tsbuildinfo +1 -1
  15. package/src/__tests__/type-generation.test.ts +1 -0
  16. package/src/__tests__/user.test.ts +1 -1
  17. package/src/api/dev.ts +3 -4
  18. package/src/api/pages/publish.tsx +38 -51
  19. package/src/bundle.ts +27 -9
  20. package/src/config/environment.ts +9 -4
  21. package/src/config/index.ts +12 -2
  22. package/src/config/validation-helpers.ts +1 -1
  23. package/src/config/validation.ts +58 -4
  24. package/src/create-worker-preview.ts +19 -8
  25. package/src/create-worker-upload-form.ts +10 -2
  26. package/src/dev/dev.tsx +4 -4
  27. package/src/dev/local.tsx +18 -21
  28. package/src/dev/start-server.ts +10 -8
  29. package/src/dev/use-esbuild.ts +9 -5
  30. package/src/dev/validate-dev-props.ts +9 -0
  31. package/src/dev.tsx +27 -13
  32. package/src/entry.ts +1 -2
  33. package/src/index.ts +1 -1
  34. package/src/init.ts +1 -0
  35. package/src/inspect.ts +16 -1
  36. package/src/miniflare-cli/assets.ts +8 -7
  37. package/src/miniflare-cli/index.ts +1 -1
  38. package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -1
  39. package/src/pages/build.ts +277 -99
  40. package/src/pages/buildFunctions.ts +20 -10
  41. package/src/pages/dev.ts +21 -21
  42. package/src/pages/errors.ts +1 -0
  43. package/src/pages/functions/buildPlugin.ts +56 -34
  44. package/src/pages/functions/buildWorker.ts +32 -23
  45. package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
  46. package/src/pages/publish.tsx +1 -10
  47. package/src/pages/upload.tsx +5 -5
  48. package/src/paths.ts +1 -1
  49. package/src/publish/index.ts +1 -1
  50. package/src/publish/publish.ts +19 -8
  51. package/src/r2/helpers.ts +1 -0
  52. package/src/secret/index.ts +1 -1
  53. package/src/type-generation.ts +1 -1
  54. package/src/user/user.ts +1 -1
  55. package/src/worker.ts +8 -1
  56. package/templates/d1-beta-facade.js +5 -2
  57. package/templates/gitignore +1 -0
  58. package/templates/middleware/middleware-miniflare3-json-error.ts +17 -5
  59. package/templates/pages-template-plugin.ts +7 -3
  60. package/templates/tsconfig.init.json +1 -2
  61. package/templates/tsconfig.tsbuildinfo +1 -1
  62. package/wrangler-dist/cli.d.ts +523 -14
  63. package/wrangler-dist/cli.js +11473 -4544
@@ -326,7 +326,7 @@ describe("publish", () => {
326
326
  await expect(runWrangler("publish index.js")).rejects.toThrowError();
327
327
 
328
328
  expect(std.err).toMatchInlineSnapshot(`
329
- "X [ERROR] In 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/tokens/create/ for instructions on how to create an api token, and assign its value to CLOUDFLARE_API_TOKEN.
329
+ "X [ERROR] In 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.
330
330
 
331
331
  "
332
332
  `);
@@ -1649,7 +1649,7 @@ addEventListener('fetch', event => {});`
1649
1649
  };
1650
1650
  writeAssets(assets);
1651
1651
  mockUploadWorkerRequest({
1652
- expectedMainModule: "serve-static-assets.entry.js",
1652
+ expectedMainModule: "no-op-worker.js",
1653
1653
  });
1654
1654
  mockSubDomainRequest();
1655
1655
  mockListKVNamespacesRequest(kvNamespace);
@@ -1740,7 +1740,7 @@ addEventListener('fetch', event => {});`
1740
1740
  writeWorkerSource();
1741
1741
  writeAssets(assets);
1742
1742
  mockUploadWorkerRequest({
1743
- expectedMainModule: "serve-static-assets.entry.js",
1743
+ expectedMainModule: "index.js",
1744
1744
  });
1745
1745
  mockSubDomainRequest();
1746
1746
  mockListKVNamespacesRequest(kvNamespace);
@@ -1925,7 +1925,7 @@ addEventListener('fetch', event => {});`
1925
1925
  writeWorkerSource();
1926
1926
  writeAssets(assets);
1927
1927
  mockUploadWorkerRequest({
1928
- expectedMainModule: "serve-static-assets.entry.js",
1928
+ expectedMainModule: "index.js",
1929
1929
  });
1930
1930
  mockSubDomainRequest();
1931
1931
  mockListKVNamespacesRequest(kvNamespace);
@@ -1972,7 +1972,7 @@ addEventListener('fetch', event => {});`
1972
1972
  writeWorkerSource();
1973
1973
  writeAssets(assets);
1974
1974
  mockUploadWorkerRequest({
1975
- expectedMainModule: "serve-static-assets.entry.js",
1975
+ expectedMainModule: "index.js",
1976
1976
  });
1977
1977
  mockSubDomainRequest();
1978
1978
  mockListKVNamespacesRequest(kvNamespace);
@@ -3015,7 +3015,7 @@ addEventListener('fetch', event => {});`
3015
3015
  writeWorkerSource();
3016
3016
  writeAssets(assets, "my-assets");
3017
3017
  mockUploadWorkerRequest({
3018
- expectedMainModule: "serve-static-assets.entry.js",
3018
+ expectedMainModule: "index.js",
3019
3019
  });
3020
3020
  mockSubDomainRequest();
3021
3021
  mockListKVNamespacesRequest(kvNamespace);
@@ -4559,6 +4559,10 @@ addEventListener('fetch', event => {});`
4559
4559
  data: 1337,
4560
4560
  },
4561
4561
  ],
4562
+ metadata: {
4563
+ extra_data: "interesting value",
4564
+ more_data: "dubious value",
4565
+ },
4562
4566
  },
4563
4567
  vars: {
4564
4568
  ENV_VAR_ONE: 123,
@@ -4603,6 +4607,10 @@ addEventListener('fetch', event => {});`
4603
4607
 
4604
4608
  mockUploadWorkerRequest({
4605
4609
  expectedType: "sw",
4610
+ expectedUnsafeMetaData: {
4611
+ extra_data: "interesting value",
4612
+ more_data: "dubious value",
4613
+ },
4606
4614
  expectedBindings: [
4607
4615
  { json: 123, name: "ENV_VAR_ONE", type: "json" },
4608
4616
  {
@@ -4726,6 +4734,9 @@ addEventListener('fetch', event => {});`
4726
4734
  - Wasm Modules:
4727
4735
  - WASM_MODULE_ONE: some_wasm.wasm
4728
4736
  - WASM_MODULE_TWO: more_wasm.wasm
4737
+ - Unsafe Metadata:
4738
+ - extra_data: interesting value
4739
+ - more_data: dubious value
4729
4740
  Uploaded test-name (TIMINGS)
4730
4741
  Published test-name (TIMINGS)
4731
4742
  https://test-name.test-sub-domain.workers.dev
@@ -4794,6 +4805,7 @@ addEventListener('fetch', event => {});`
4794
4805
  data: 1337,
4795
4806
  },
4796
4807
  ],
4808
+ metadata: undefined,
4797
4809
  },
4798
4810
  vars: {
4799
4811
  ENV_VAR_ONE: 123,
@@ -4907,6 +4919,7 @@ addEventListener('fetch', event => {});`
4907
4919
  data: 1337,
4908
4920
  },
4909
4921
  ],
4922
+ metadata: undefined,
4910
4923
  },
4911
4924
  // text_blobs, vars, wasm_modules and data_blobs are fine because they're object literals,
4912
4925
  // and by definition cannot have two keys of the same name
@@ -5055,6 +5068,7 @@ addEventListener('fetch', event => {});`
5055
5068
  data: null,
5056
5069
  },
5057
5070
  ],
5071
+ metadata: undefined,
5058
5072
  },
5059
5073
  vars: {
5060
5074
  ENV_VAR_ONE: 123,
@@ -5832,7 +5846,7 @@ addEventListener('fetch', event => {});`
5832
5846
 
5833
5847
  "
5834
5848
  `);
5835
- const output = fs.readFileSync("tmp/d1-beta-facade.entry.js", "utf-8");
5849
+ const output = fs.readFileSync("tmp/index.js", "utf-8");
5836
5850
  expect(output).toContain(
5837
5851
  `var ExampleDurableObject2 = maskDurableObjectDefinition(ExampleDurableObject);`
5838
5852
  );
@@ -5992,6 +6006,7 @@ addEventListener('fetch', event => {});`
5992
6006
  param: "binding-param",
5993
6007
  },
5994
6008
  ],
6009
+ metadata: undefined,
5995
6010
  },
5996
6011
  });
5997
6012
  writeWorkerSource();
@@ -6036,6 +6051,7 @@ addEventListener('fetch', event => {});`
6036
6051
  text: "text",
6037
6052
  },
6038
6053
  ],
6054
+ metadata: undefined,
6039
6055
  },
6040
6056
  });
6041
6057
  writeWorkerSource();
@@ -6489,9 +6505,22 @@ addEventListener('fetch', event => {});`
6489
6505
  `);
6490
6506
  });
6491
6507
 
6492
- it("should output to target es2020 even if tsconfig says otherwise", async () => {
6508
+ it("should output to target es2022 even if tsconfig says otherwise", async () => {
6493
6509
  writeWranglerToml();
6494
6510
  writeWorkerSource();
6511
+ fs.writeFileSync(
6512
+ "./index.js",
6513
+ `
6514
+ import { foo } from "./another";
6515
+ const topLevelAwait = await new Promise((resolve) => setTimeout(resolve, 0));
6516
+
6517
+ export default {
6518
+ async fetch(request) {
6519
+
6520
+ return new Response("Hello world!");
6521
+ },
6522
+ };`
6523
+ );
6495
6524
  fs.writeFileSync(
6496
6525
  "tsconfig.json",
6497
6526
  JSON.stringify({
@@ -6502,8 +6531,14 @@ addEventListener('fetch', event => {});`
6502
6531
  })
6503
6532
  );
6504
6533
  mockSubDomainRequest();
6534
+ /**
6535
+ * When we compile with es2022, we should preserve the export statement and top level await
6536
+ * If you attempt to target es2020 top level await will cause a build error
6537
+ * @error Build failed with 1 error:
6538
+ * index.js:3:25: ERROR: Top-level await is not available in the configured target environment ("es2020")
6539
+ */
6505
6540
  mockUploadWorkerRequest({
6506
- expectedEntry: "export {", // just check that the export is preserved
6541
+ expectedEntry: "export {", // check that the export is preserved
6507
6542
  });
6508
6543
  await runWrangler("publish index.js"); // this would throw if we tried to compile with es5
6509
6544
  expect(std).toMatchInlineSnapshot(`
@@ -6544,6 +6579,47 @@ addEventListener('fetch', event => {});`
6544
6579
  `);
6545
6580
  });
6546
6581
 
6582
+ it("should preserve the entry point file name, even when using a facade", async () => {
6583
+ writeWranglerToml();
6584
+ writeWorkerSource();
6585
+ mockSubDomainRequest();
6586
+ mockUploadWorkerRequest();
6587
+ const assets = [
6588
+ { filePath: "file-1.txt", content: "Content of file-1" },
6589
+ { filePath: "file-2.txt", content: "Content of file-2" },
6590
+ ];
6591
+ const kvNamespace = {
6592
+ title: "__test-name-workers_sites_assets",
6593
+ id: "__test-name-workers_sites_assets-id",
6594
+ };
6595
+ writeAssets(assets);
6596
+ mockListKVNamespacesRequest(kvNamespace);
6597
+ mockKeyListRequest(kvNamespace.id, []);
6598
+ mockUploadAssetsToKVRequest(kvNamespace.id, assets);
6599
+ await runWrangler("publish index.js --outdir some-dir --assets assets");
6600
+ expect(fs.existsSync("some-dir/index.js")).toBe(true);
6601
+ expect(fs.existsSync("some-dir/index.js.map")).toBe(true);
6602
+ expect(std).toMatchInlineSnapshot(`
6603
+ Object {
6604
+ "debug": "",
6605
+ "err": "",
6606
+ "out": "Reading file-1.txt...
6607
+ Uploading as file-1.2ca234f380.txt...
6608
+ Reading file-2.txt...
6609
+ Uploading as file-2.5938485188.txt...
6610
+ ↗️ Done syncing assets
6611
+ Total Upload: xx KiB / gzip: xx KiB
6612
+ Uploaded test-name (TIMINGS)
6613
+ Published test-name (TIMINGS)
6614
+ https://test-name.test-sub-domain.workers.dev
6615
+ Current Deployment ID: Galaxy-Class",
6616
+ "warn": "▲ [WARNING] The --assets argument is experimental and may change or break at any time
6617
+
6618
+ ",
6619
+ }
6620
+ `);
6621
+ });
6622
+
6547
6623
  it("should copy any module imports related assets to --outdir if specified", async () => {
6548
6624
  writeWranglerToml();
6549
6625
  fs.writeFileSync(
@@ -6639,7 +6715,7 @@ export default{
6639
6715
  "err": "",
6640
6716
  "out": "Total Upload: xx KiB / gzip: xx KiB
6641
6717
  --dry-run: exiting now.",
6642
- "warn": "▲ [WARNING] Enabling 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.
6718
+ "warn": "▲ [WARNING] Enabling 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.
6643
6719
 
6644
6720
  ",
6645
6721
  }
@@ -6686,7 +6762,7 @@ export default{
6686
6762
  "err": "",
6687
6763
  "out": "Total Upload: xx KiB / gzip: xx KiB
6688
6764
  --dry-run: exiting now.",
6689
- "warn": "▲ [WARNING] Enabling 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.
6765
+ "warn": "▲ [WARNING] Enabling 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.
6690
6766
 
6691
6767
  ",
6692
6768
  }
@@ -6694,6 +6770,78 @@ export default{
6694
6770
  });
6695
6771
  });
6696
6772
 
6773
+ describe("`nodejs_compat` compatibility flag", () => {
6774
+ it('when absent, should error on any "external" `node:*` imports', async () => {
6775
+ writeWranglerToml();
6776
+ fs.writeFileSync(
6777
+ "index.js",
6778
+ `
6779
+ import AsyncHooks from 'node:async_hooks';
6780
+ console.log(AsyncHooks);
6781
+ export default {}
6782
+ `
6783
+ );
6784
+ let err: esbuild.BuildFailure | undefined;
6785
+ try {
6786
+ await runWrangler("publish index.js --dry-run"); // expecting this to throw, as node compatibility isn't enabled
6787
+ } catch (e) {
6788
+ err = e as esbuild.BuildFailure;
6789
+ }
6790
+ expect(
6791
+ esbuild.formatMessagesSync(err?.errors ?? [], { kind: "error" }).join()
6792
+ ).toMatch(/Could not resolve "node:async_hooks"/);
6793
+ });
6794
+
6795
+ it('when present, should support any "external" `node:*` imports', async () => {
6796
+ writeWranglerToml();
6797
+ fs.writeFileSync(
6798
+ "index.js",
6799
+ `
6800
+ import AsyncHooks from 'node:async_hooks';
6801
+ console.log(AsyncHooks);
6802
+ export default {}
6803
+ `
6804
+ );
6805
+
6806
+ await runWrangler(
6807
+ "publish index.js --dry-run --outdir=dist --compatibility-flag=nodejs_compat"
6808
+ );
6809
+
6810
+ expect(std).toMatchInlineSnapshot(`
6811
+ Object {
6812
+ "debug": "",
6813
+ "err": "",
6814
+ "out": "Total Upload: xx KiB / gzip: xx KiB
6815
+ --dry-run: exiting now.",
6816
+ "warn": "",
6817
+ }
6818
+ `);
6819
+ expect(fs.readFileSync("dist/index.js", { encoding: "utf-8" })).toContain(
6820
+ `import AsyncHooks from "node:async_hooks";`
6821
+ );
6822
+ });
6823
+
6824
+ it("should conflict with the --node-compat option", async () => {
6825
+ writeWranglerToml();
6826
+ fs.writeFileSync(
6827
+ "index.js",
6828
+ `
6829
+ import AsyncHooks from 'node:async_hooks';
6830
+ console.log(AsyncHooks);
6831
+ export default {}
6832
+ `
6833
+ );
6834
+
6835
+ await expect(
6836
+ runWrangler(
6837
+ "publish index.js --dry-run --outdir=dist --compatibility-flag=nodejs_compat --node-compat"
6838
+ )
6839
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
6840
+ `"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."`
6841
+ );
6842
+ });
6843
+ });
6844
+
6697
6845
  describe("bundle reporter", () => {
6698
6846
  it("should print the bundle size", async () => {
6699
6847
  fs.writeFileSync(
@@ -7106,7 +7254,7 @@ export default{
7106
7254
  "publish index.js --no-bundle --node-compat --dry-run --outdir dist"
7107
7255
  );
7108
7256
  expect(std.warn).toMatchInlineSnapshot(`
7109
- "▲ [WARNING] Enabling 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.
7257
+ "▲ [WARNING] Enabling 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.
7110
7258
 
7111
7259
 
7112
7260
  ▲ [WARNING] \`--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.
@@ -7126,7 +7274,7 @@ export default{
7126
7274
  fs.writeFileSync("index.js", scriptContent);
7127
7275
  await runWrangler("publish index.js --dry-run --outdir dist");
7128
7276
  expect(std.warn).toMatchInlineSnapshot(`
7129
- "▲ [WARNING] Enabling 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.
7277
+ "▲ [WARNING] Enabling 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.
7130
7278
 
7131
7279
 
7132
7280
  ▲ [WARNING] \`--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.
@@ -7448,7 +7596,7 @@ function mockLastDeploymentRequest() {
7448
7596
  function mockUploadWorkerRequest(
7449
7597
  options: {
7450
7598
  available_on_subdomain?: boolean;
7451
- expectedEntry?: string;
7599
+ expectedEntry?: string | RegExp;
7452
7600
  expectedMainModule?: string;
7453
7601
  expectedType?: "esm" | "sw";
7454
7602
  expectedBindings?: unknown;
@@ -7456,6 +7604,7 @@ function mockUploadWorkerRequest(
7456
7604
  expectedCompatibilityDate?: string;
7457
7605
  expectedCompatibilityFlags?: string[];
7458
7606
  expectedMigrations?: CfWorkerInit["migrations"];
7607
+ expectedUnsafeMetaData?: Record<string, string>;
7459
7608
  env?: string;
7460
7609
  legacyEnv?: boolean;
7461
7610
  sendScriptIds?: boolean;
@@ -7475,6 +7624,7 @@ function mockUploadWorkerRequest(
7475
7624
  env = undefined,
7476
7625
  legacyEnv = false,
7477
7626
  expectedMigrations,
7627
+ expectedUnsafeMetaData,
7478
7628
  sendScriptIds,
7479
7629
  keepVars,
7480
7630
  } = options;
@@ -7544,6 +7694,11 @@ function mockUploadWorkerRequest(
7544
7694
  if ("expectedMigrations" in options) {
7545
7695
  expect(metadata.migrations).toEqual(expectedMigrations);
7546
7696
  }
7697
+ if (expectedUnsafeMetaData !== undefined) {
7698
+ Object.keys(expectedUnsafeMetaData).forEach((key) => {
7699
+ expect(metadata[key]).toEqual(expectedUnsafeMetaData[key]);
7700
+ });
7701
+ }
7547
7702
  for (const [name, content] of Object.entries(expectedModules)) {
7548
7703
  expect(formBody.get(name)).toEqual(content);
7549
7704
  }
@@ -1,4 +1,4 @@
1
- // this test has to be run with a version of node.js older than 16.13 to pass
1
+ // this test has to be run with a version of Node.js older than 16.13 to pass
2
2
 
3
3
  const { spawn } = require("child_process");
4
4
  const path = require("path");
@@ -11,7 +11,7 @@ const wranglerProcess = spawn(
11
11
  { stdio: "pipe" }
12
12
  );
13
13
 
14
- const messageToMatch = "Wrangler requires at least node.js v16.13.0";
14
+ const messageToMatch = "Wrangler requires at least Node.js v16.13.0";
15
15
 
16
16
  wranglerProcess.once("exit", (code) => {
17
17
  try {
@@ -25,7 +25,7 @@ wranglerProcess.once("exit", (code) => {
25
25
  } catch (err) {
26
26
  console.error("Error:", err);
27
27
  throw new Error(
28
- "This test has to be run with a version of node.js under 16.13 to pass"
28
+ "This test has to be run with a version of Node.js under 16.13 to pass"
29
29
  );
30
30
  }
31
31
  });