wrangler 0.0.0-cc2adc2e → 0.0.0-cc335ee1

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 (45) hide show
  1. package/package.json +5 -5
  2. package/src/__tests__/configuration.test.ts +95 -0
  3. package/src/__tests__/constellation.test.ts +10 -10
  4. package/src/__tests__/index.test.ts +2 -2
  5. package/src/__tests__/init.test.ts +102 -3
  6. package/src/__tests__/mtls-certificates.test.ts +1 -1
  7. package/src/__tests__/pages/functions-build.test.ts +1 -0
  8. package/src/__tests__/tsconfig.tsbuildinfo +1 -1
  9. package/src/api/dev.ts +9 -2
  10. package/src/api/pages/create-worker-bundle-contents.ts +1 -0
  11. package/src/bundle.ts +28 -5
  12. package/src/cfetch/internal.ts +19 -14
  13. package/src/config/environment.ts +16 -0
  14. package/src/config/index.ts +13 -0
  15. package/src/config/validation.ts +51 -0
  16. package/src/constellation/utils.ts +1 -1
  17. package/src/create-worker-upload-form.ts +9 -0
  18. package/src/d1/constants.ts +2 -0
  19. package/src/d1/create.tsx +25 -3
  20. package/src/d1/execute.tsx +26 -12
  21. package/src/d1/migrations/apply.tsx +28 -5
  22. package/src/d1/migrations/helpers.ts +3 -1
  23. package/src/d1/types.ts +7 -7
  24. package/src/dev/dev.tsx +3 -1
  25. package/src/dev/start-server.ts +15 -2
  26. package/src/dev/use-esbuild.ts +18 -3
  27. package/src/dev.tsx +14 -3
  28. package/src/generate/index.ts +5 -0
  29. package/src/index.ts +2 -1
  30. package/src/init.ts +37 -9
  31. package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -1
  32. package/src/pages/dev.ts +29 -4
  33. package/src/pages/functions/buildWorker.ts +35 -4
  34. package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
  35. package/src/publish/publish.ts +1 -0
  36. package/src/secret/index.ts +1 -0
  37. package/src/traverse-module-graph.ts +1 -1
  38. package/src/type-generation.ts +6 -0
  39. package/src/user/user.ts +1 -1
  40. package/src/worker.ts +6 -0
  41. package/templates/__tests__/tsconfig.tsbuildinfo +1 -1
  42. package/templates/pages-dev-util.ts +4 -1
  43. package/templates/tsconfig.tsbuildinfo +1 -1
  44. package/wrangler-dist/cli.d.ts +53 -2
  45. package/wrangler-dist/cli.js +63457 -63224
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wrangler",
3
- "version": "0.0.0-cc2adc2e",
3
+ "version": "0.0.0-cc335ee1",
4
4
  "description": "Command-line interface for all things Cloudflare Workers",
5
5
  "keywords": [
6
6
  "wrangler",
@@ -102,13 +102,13 @@
102
102
  "@cloudflare/kv-asset-handler": "^0.2.0",
103
103
  "@esbuild-plugins/node-globals-polyfill": "^0.1.1",
104
104
  "@esbuild-plugins/node-modules-polyfill": "^0.1.4",
105
- "@miniflare/core": "2.13.0",
106
- "@miniflare/d1": "2.13.0",
107
- "@miniflare/durable-objects": "2.13.0",
105
+ "@miniflare/core": "2.14.0",
106
+ "@miniflare/d1": "2.14.0",
107
+ "@miniflare/durable-objects": "2.14.0",
108
108
  "blake3-wasm": "^2.1.5",
109
109
  "chokidar": "^3.5.3",
110
110
  "esbuild": "0.16.3",
111
- "miniflare": "2.13.0",
111
+ "miniflare": "2.14.0",
112
112
  "nanoid": "^3.3.3",
113
113
  "path-to-regexp": "^6.2.0",
114
114
  "selfsigned": "^2.0.1",
@@ -26,6 +26,7 @@ describe("normalizeAndValidateConfig()", () => {
26
26
  compatibility_flags: [],
27
27
  configPath: undefined,
28
28
  d1_databases: [],
29
+ constellation: [],
29
30
  dev: {
30
31
  ip: "0.0.0.0",
31
32
  local_protocol: "http",
@@ -1831,6 +1832,100 @@ describe("normalizeAndValidateConfig()", () => {
1831
1832
  });
1832
1833
  });
1833
1834
 
1835
+ describe("[constellation]", () => {
1836
+ it("should error if constellation is an object", () => {
1837
+ const { diagnostics } = normalizeAndValidateConfig(
1838
+ { constellation: {} } as unknown as RawConfig,
1839
+ undefined,
1840
+ { env: undefined }
1841
+ );
1842
+
1843
+ expect(diagnostics.hasWarnings()).toBe(false);
1844
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1845
+ "Processing wrangler configuration:
1846
+ - The field \\"constellation\\" should be an array but got {}."
1847
+ `);
1848
+ });
1849
+
1850
+ it("should error if constellation is a string", () => {
1851
+ const { diagnostics } = normalizeAndValidateConfig(
1852
+ { constellation: "BAD" } as unknown as RawConfig,
1853
+ undefined,
1854
+ { env: undefined }
1855
+ );
1856
+
1857
+ expect(diagnostics.hasWarnings()).toBe(false);
1858
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1859
+ "Processing wrangler configuration:
1860
+ - The field \\"constellation\\" should be an array but got \\"BAD\\"."
1861
+ `);
1862
+ });
1863
+
1864
+ it("should error if constellation is a number", () => {
1865
+ const { diagnostics } = normalizeAndValidateConfig(
1866
+ { constellation: 999 } as unknown as RawConfig,
1867
+ undefined,
1868
+ { env: undefined }
1869
+ );
1870
+
1871
+ expect(diagnostics.hasWarnings()).toBe(false);
1872
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1873
+ "Processing wrangler configuration:
1874
+ - The field \\"constellation\\" should be an array but got 999."
1875
+ `);
1876
+ });
1877
+
1878
+ it("should error if constellation is null", () => {
1879
+ const { diagnostics } = normalizeAndValidateConfig(
1880
+ { constellation: null } as unknown as RawConfig,
1881
+ undefined,
1882
+ { env: undefined }
1883
+ );
1884
+
1885
+ expect(diagnostics.hasWarnings()).toBe(false);
1886
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1887
+ "Processing wrangler configuration:
1888
+ - The field \\"constellation\\" should be an array but got null."
1889
+ `);
1890
+ });
1891
+
1892
+ it("should accept valid bindings", () => {
1893
+ const { diagnostics } = normalizeAndValidateConfig(
1894
+ {
1895
+ constellation: [{ binding: "VALID", project_id: "ID" }],
1896
+ } as unknown as RawConfig,
1897
+ undefined,
1898
+ { env: undefined }
1899
+ );
1900
+
1901
+ expect(diagnostics.hasErrors()).toBe(false);
1902
+ });
1903
+
1904
+ it("should error if constellation.bindings are not valid", () => {
1905
+ const { diagnostics } = normalizeAndValidateConfig(
1906
+ {
1907
+ constellation: [
1908
+ {},
1909
+ { binding: "VALID" },
1910
+ { binding: 2000, project: 2111 },
1911
+ ],
1912
+ } as unknown as RawConfig,
1913
+ undefined,
1914
+ { env: undefined }
1915
+ );
1916
+
1917
+ expect(diagnostics.hasWarnings()).toBe(false);
1918
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1919
+ "Processing wrangler configuration:
1920
+ - \\"constellation[0]\\" bindings should have a string \\"binding\\" field but got {}.
1921
+ - \\"constellation[0]\\" bindings must have a \\"project_id\\" field but got {}.
1922
+ - \\"constellation[1]\\" bindings must have a \\"project_id\\" field but got {\\"binding\\":\\"VALID\\"}.
1923
+ - \\"constellation[2]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":2000,\\"project\\":2111}.
1924
+ - \\"constellation[2]\\" bindings must have a \\"project_id\\" field but got {\\"binding\\":2000,\\"project\\":2111}."
1925
+ `);
1926
+ });
1927
+ });
1928
+
1834
1929
  describe("[queues]", () => {
1835
1930
  it("should error if queues is not an object", () => {
1836
1931
  const { config, diagnostics } = normalizeAndValidateConfig(
@@ -20,7 +20,7 @@ describe("constellation help", () => {
20
20
  expect(std.out).toMatchInlineSnapshot(`
21
21
  "wrangler constellation
22
22
 
23
- 🤖 Interact with Constellation AI models
23
+ 🤖 Interact with Constellation models
24
24
 
25
25
  Commands:
26
26
  wrangler constellation project Manage your projects
@@ -51,7 +51,7 @@ describe("constellation help", () => {
51
51
  "
52
52
  wrangler constellation
53
53
 
54
- 🤖 Interact with Constellation AI models
54
+ 🤖 Interact with Constellation models
55
55
 
56
56
  Commands:
57
57
  wrangler constellation project Manage your projects
@@ -94,7 +94,7 @@ describe("constellation commands", () => {
94
94
  await runWrangler("constellation project create new_project ONNX");
95
95
  expect(std.out).toMatchInlineSnapshot(`
96
96
  "--------------------
97
- 🚧 Constellation AI is currently in open alpha and is not recommended for production data and traffic
97
+ 🚧 Constellation is currently in open alpha and is not recommended for production data and traffic
98
98
  🚧 Please report any bugs to https://github.com/cloudflare/workers-sdk/issues/new/choose
99
99
  🚧 To give feedback, visit https://discord.gg/cloudflaredev
100
100
  --------------------
@@ -108,7 +108,7 @@ describe("constellation commands", () => {
108
108
  await runWrangler("constellation project list");
109
109
  expect(std.out).toMatchInlineSnapshot(`
110
110
  "--------------------
111
- 🚧 Constellation AI is currently in open alpha and is not recommended for production data and traffic
111
+ 🚧 Constellation is currently in open alpha and is not recommended for production data and traffic
112
112
  🚧 Please report any bugs to https://github.com/cloudflare/workers-sdk/issues/new/choose
113
113
  🚧 To give feedback, visit https://discord.gg/cloudflaredev
114
114
  --------------------
@@ -131,7 +131,7 @@ describe("constellation commands", () => {
131
131
  await runWrangler("constellation project delete new_project3");
132
132
  expect(std.out).toMatchInlineSnapshot(`
133
133
  "--------------------
134
- 🚧 Constellation AI is currently in open alpha and is not recommended for production data and traffic
134
+ 🚧 Constellation is currently in open alpha and is not recommended for production data and traffic
135
135
  🚧 Please report any bugs to https://github.com/cloudflare/workers-sdk/issues/new/choose
136
136
  🚧 To give feedback, visit https://discord.gg/cloudflaredev
137
137
  --------------------
@@ -147,7 +147,7 @@ describe("constellation commands", () => {
147
147
  await runWrangler("constellation catalog list");
148
148
  expect(std.out).toMatchInlineSnapshot(`
149
149
  "--------------------
150
- 🚧 Constellation AI is currently in open alpha and is not recommended for production data and traffic
150
+ 🚧 Constellation is currently in open alpha and is not recommended for production data and traffic
151
151
  🚧 Please report any bugs to https://github.com/cloudflare/workers-sdk/issues/new/choose
152
152
  🚧 To give feedback, visit https://discord.gg/cloudflaredev
153
153
  --------------------
@@ -165,7 +165,7 @@ describe("constellation commands", () => {
165
165
  await runWrangler("constellation runtime list");
166
166
  expect(std.out).toMatchInlineSnapshot(`
167
167
  "--------------------
168
- 🚧 Constellation AI is currently in open alpha and is not recommended for production data and traffic
168
+ 🚧 Constellation is currently in open alpha and is not recommended for production data and traffic
169
169
  🚧 Please report any bugs to https://github.com/cloudflare/workers-sdk/issues/new/choose
170
170
  🚧 To give feedback, visit https://discord.gg/cloudflaredev
171
171
  --------------------
@@ -188,7 +188,7 @@ describe("constellation commands", () => {
188
188
  );
189
189
  expect(std.out).toMatchInlineSnapshot(`
190
190
  "--------------------
191
- 🚧 Constellation AI is currently in open alpha and is not recommended for production data and traffic
191
+ 🚧 Constellation is currently in open alpha and is not recommended for production data and traffic
192
192
  🚧 Please report any bugs to https://github.com/cloudflare/workers-sdk/issues/new/choose
193
193
  🚧 To give feedback, visit https://discord.gg/cloudflaredev
194
194
  --------------------
@@ -202,7 +202,7 @@ describe("constellation commands", () => {
202
202
  await runWrangler("constellation model list new_project3");
203
203
  expect(std.out).toMatchInlineSnapshot(`
204
204
  "--------------------
205
- 🚧 Constellation AI is currently in open alpha and is not recommended for production data and traffic
205
+ 🚧 Constellation is currently in open alpha and is not recommended for production data and traffic
206
206
  🚧 Please report any bugs to https://github.com/cloudflare/workers-sdk/issues/new/choose
207
207
  🚧 To give feedback, visit https://discord.gg/cloudflaredev
208
208
  --------------------
@@ -227,7 +227,7 @@ describe("constellation commands", () => {
227
227
  await runWrangler("constellation model delete new_project3 model2");
228
228
  expect(std.out).toMatchInlineSnapshot(`
229
229
  "--------------------
230
- 🚧 Constellation AI is currently in open alpha and is not recommended for production data and traffic
230
+ 🚧 Constellation is currently in open alpha and is not recommended for production data and traffic
231
231
  🚧 Please report any bugs to https://github.com/cloudflare/workers-sdk/issues/new/choose
232
232
  🚧 To give feedback, visit https://discord.gg/cloudflaredev
233
233
  --------------------
@@ -49,7 +49,7 @@ describe("wrangler", () => {
49
49
  wrangler r2 📦 Interact with an R2 store
50
50
  wrangler dispatch-namespace 📦 Interact with a dispatch namespace
51
51
  wrangler d1 🗄 Interact with a D1 database
52
- wrangler constellation 🤖 Interact with Constellation AI models
52
+ wrangler constellation 🤖 Interact with Constellation models
53
53
  wrangler pubsub 📮 Interact and manage Pub/Sub Brokers
54
54
  wrangler mtls-certificate 🪪 Manage certificates used for mTLS connections
55
55
  wrangler login 🔓 Login to Cloudflare
@@ -103,7 +103,7 @@ describe("wrangler", () => {
103
103
  wrangler r2 📦 Interact with an R2 store
104
104
  wrangler dispatch-namespace 📦 Interact with a dispatch namespace
105
105
  wrangler d1 🗄 Interact with a D1 database
106
- wrangler constellation 🤖 Interact with Constellation AI models
106
+ wrangler constellation 🤖 Interact with Constellation models
107
107
  wrangler pubsub 📮 Interact and manage Pub/Sub Brokers
108
108
  wrangler mtls-certificate 🪪 Manage certificates used for mTLS connections
109
109
  wrangler login 🔓 Login to Cloudflare
@@ -4,6 +4,7 @@ import * as TOML from "@iarna/toml";
4
4
  import { execa, execaSync } from "execa";
5
5
  import { rest } from "msw";
6
6
  import { parseConfigFileTextToJson } from "typescript";
7
+ import { FormData } from "undici";
7
8
  import { version as wranglerVersion } from "../../package.json";
8
9
  import { getPackageManager } from "../package-manager";
9
10
  import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
@@ -2235,6 +2236,12 @@ describe("init", () => {
2235
2236
  },
2236
2237
  };
2237
2238
  `;
2239
+ afterEach(() => {
2240
+ // some test has a side-effect which is overwriting the compatibility_date
2241
+ mockServiceMetadata.default_environment.script.compatibility_date =
2242
+ "1987-9-27";
2243
+ mockConfigExpected.compatibility_date = "1987-9-27";
2244
+ });
2238
2245
  const mockServiceMetadata = {
2239
2246
  id: "memory-crystal",
2240
2247
  default_environment: {
@@ -3001,7 +3008,7 @@ describe("init", () => {
3001
3008
  success: true,
3002
3009
  errors: [],
3003
3010
  messages: [],
3004
- result: mockServiceMetadata.default_environment,
3011
+ result: mockData.default_environment,
3005
3012
  })
3006
3013
  );
3007
3014
  }
@@ -3074,6 +3081,72 @@ describe("init", () => {
3074
3081
  },
3075
3082
  });
3076
3083
  });
3084
+
3085
+ it("should download multi-module source scripts from dashboard", async () => {
3086
+ mockSupportingDashRequests({
3087
+ expectedAccountId: "LCARS",
3088
+ expectedScriptName: "isolinear-optical-chip",
3089
+ expectedEnvironment: "test",
3090
+ expectedCompatDate: "1987-9-27",
3091
+ });
3092
+ const indexjs = `
3093
+ import handleRequest from './handleRequest.js';
3094
+
3095
+ export default {
3096
+ async fetch(request, env, ctx) {
3097
+ return handleRequest(request, env, ctx);
3098
+ },
3099
+ };
3100
+ `;
3101
+ const otherjs = `
3102
+ export default function (request, env, ctx) {
3103
+ return new Response("Hello World!");
3104
+ }
3105
+ `;
3106
+ setMockFetchDashScript([
3107
+ { name: "index.js", contents: indexjs },
3108
+ { name: "nested/other.js", contents: otherjs },
3109
+ ]);
3110
+ mockConfirm(
3111
+ {
3112
+ text: "Would you like to use git to manage this Worker?",
3113
+ result: false,
3114
+ },
3115
+ {
3116
+ text: "No package.json found. Would you like to create one?",
3117
+ result: true,
3118
+ },
3119
+ {
3120
+ text: "Would you like to use TypeScript?",
3121
+ result: false,
3122
+ }
3123
+ );
3124
+
3125
+ await runWrangler("init --from-dash isolinear-optical-chip");
3126
+
3127
+ checkFiles({
3128
+ items: {
3129
+ "isolinear-optical-chip/src/index.js": {
3130
+ contents: indexjs,
3131
+ },
3132
+ "isolinear-optical-chip/src/nested/other.js": {
3133
+ contents: otherjs,
3134
+ },
3135
+ "isolinear-optical-chip/src/index.ts": false,
3136
+ "isolinear-optical-chip/package.json": {
3137
+ contents: expect.objectContaining({
3138
+ name: "isolinear-optical-chip",
3139
+ }),
3140
+ },
3141
+ "isolinear-optical-chip/tsconfig.json": false,
3142
+ "isolinear-optical-chip/wrangler.toml": wranglerToml({
3143
+ ...mockConfigExpected,
3144
+ name: "isolinear-optical-chip",
3145
+ main: "src/index.js",
3146
+ }),
3147
+ },
3148
+ });
3149
+ });
3077
3150
  });
3078
3151
  });
3079
3152
 
@@ -3095,12 +3168,38 @@ function getDefaultBranchName() {
3095
3168
  /**
3096
3169
  * Mock setter for usage within test blocks for dashboard script
3097
3170
  */
3098
- export function setMockFetchDashScript(mockResponse: string) {
3171
+ export function setMockFetchDashScript(
3172
+ mockResponse: string | { name: string; contents: string }[]
3173
+ ) {
3099
3174
  msw.use(
3100
3175
  rest.get(
3101
3176
  `*/accounts/:accountId/workers/services/:fromDashScriptName/environments/:environment/content`,
3102
3177
  (_, res, ctx) => {
3103
- return res(ctx.text(mockResponse));
3178
+ if (typeof mockResponse === "string") {
3179
+ return res(ctx.text(mockResponse));
3180
+ }
3181
+
3182
+ const fd = new FormData();
3183
+
3184
+ for (const { name, contents } of mockResponse) {
3185
+ fd.set(name, contents);
3186
+ }
3187
+
3188
+ const boundary = "--------boundary-12761293712";
3189
+ const responseText =
3190
+ `--${boundary}\r\n` +
3191
+ mockResponse
3192
+ .map(
3193
+ ({ name, contents }) =>
3194
+ `Content-Disposition: form-data; name="${name}"\r\n\r\n${contents}`
3195
+ )
3196
+ .join(`\r\n--${boundary}\r\n`) +
3197
+ `\r\n--${boundary}--`;
3198
+
3199
+ return res(
3200
+ ctx.set("Content-Type", `multipart/form-data; boundary=${boundary}`),
3201
+ ctx.body(responseText)
3202
+ );
3104
3203
  }
3105
3204
  )
3106
3205
  );
@@ -379,7 +379,7 @@ describe("wrangler", () => {
379
379
  wrangler r2 📦 Interact with an R2 store
380
380
  wrangler dispatch-namespace 📦 Interact with a dispatch namespace
381
381
  wrangler d1 🗄 Interact with a D1 database
382
- wrangler constellation 🤖 Interact with Constellation AI models
382
+ wrangler constellation 🤖 Interact with Constellation models
383
383
  wrangler pubsub 📮 Interact and manage Pub/Sub Brokers
384
384
  wrangler mtls-certificate 🪪 Manage certificates used for mTLS connections
385
385
  wrangler login 🔓 Login to Cloudflare
@@ -503,6 +503,7 @@ export const cat = "cat";`
503
503
  Content-Disposition: form-data; name=\\"bundledWorker-0.test.mjs\\"; filename=\\"bundledWorker-0.test.mjs\\"
504
504
  Content-Type: application/javascript+module
505
505
 
506
+ // _worker.js/index.js
506
507
  import { cat } from \\"./cat.js\\";
507
508
  var worker_default = {
508
509
  async fetch(request, env) {