wrangler 2.8.0 → 2.9.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 (95) hide show
  1. package/package.json +1 -1
  2. package/src/__tests__/d1/d1.test.ts +24 -62
  3. package/src/__tests__/d1/migrate.test.ts +48 -0
  4. package/src/__tests__/deployments.test.ts +4 -4
  5. package/src/__tests__/dev.test.tsx +5 -4
  6. package/src/__tests__/helpers/msw/handlers/deployments.ts +10 -18
  7. package/src/__tests__/helpers/msw/handlers/namespaces.ts +18 -41
  8. package/src/__tests__/helpers/msw/handlers/r2.ts +14 -34
  9. package/src/__tests__/helpers/msw/handlers/script.ts +9 -28
  10. package/src/__tests__/helpers/msw/handlers/user.ts +13 -24
  11. package/src/__tests__/helpers/msw/handlers/zones.ts +6 -8
  12. package/src/__tests__/index.test.ts +35 -28
  13. package/src/__tests__/kv.test.ts +55 -44
  14. package/src/__tests__/pages.test.ts +61 -57
  15. package/src/__tests__/parse.test.ts +106 -0
  16. package/src/__tests__/publish.test.ts +126 -0
  17. package/src/__tests__/pubsub.test.ts +15 -12
  18. package/src/__tests__/queues.test.ts +35 -28
  19. package/src/__tests__/r2.test.ts +36 -55
  20. package/src/__tests__/tail.test.ts +6 -18
  21. package/src/__tests__/tsconfig.tsbuildinfo +1 -1
  22. package/src/__tests__/user.test.ts +0 -1
  23. package/src/__tests__/whoami.test.tsx +6 -17
  24. package/src/__tests__/worker-namespace.test.ts +81 -68
  25. package/src/api/dev.ts +80 -11
  26. package/src/api/index.ts +1 -0
  27. package/src/api/pages/index.ts +5 -0
  28. package/src/api/pages/publish.tsx +324 -0
  29. package/src/bundle.ts +63 -11
  30. package/src/cli.ts +2 -2
  31. package/src/config/config.ts +7 -0
  32. package/src/config/environment.ts +12 -10
  33. package/src/config/index.ts +24 -20
  34. package/src/d1/backups.tsx +20 -24
  35. package/src/d1/create.tsx +6 -5
  36. package/src/d1/delete.ts +7 -10
  37. package/src/d1/execute.tsx +82 -84
  38. package/src/d1/index.ts +5 -6
  39. package/src/d1/list.tsx +21 -9
  40. package/src/d1/migrations/apply.tsx +7 -5
  41. package/src/d1/migrations/create.tsx +7 -10
  42. package/src/d1/migrations/list.tsx +7 -5
  43. package/src/d1/migrations/options.ts +2 -2
  44. package/src/d1/options.ts +3 -3
  45. package/src/d1/utils.ts +1 -1
  46. package/src/delete.ts +5 -8
  47. package/src/deployments.ts +16 -6
  48. package/src/deprecated/index.ts +7 -8
  49. package/src/dev/local.tsx +1 -10
  50. package/src/dev/start-server.ts +5 -10
  51. package/src/dev/use-esbuild.ts +1 -0
  52. package/src/dev.tsx +42 -80
  53. package/src/dispatch-namespace.ts +20 -16
  54. package/src/docs/index.ts +7 -8
  55. package/src/entry.ts +1 -2
  56. package/src/generate/index.ts +5 -7
  57. package/src/index.ts +23 -22
  58. package/src/init.ts +5 -7
  59. package/src/kv/index.ts +15 -17
  60. package/src/metrics/send-event.ts +2 -1
  61. package/src/pages/build.ts +9 -127
  62. package/src/pages/buildFunctions.ts +129 -0
  63. package/src/pages/deployment-tails.ts +7 -10
  64. package/src/pages/deployments.tsx +6 -4
  65. package/src/pages/dev.ts +27 -19
  66. package/src/pages/functions/buildPlugin.ts +1 -0
  67. package/src/pages/functions/buildWorker.ts +8 -2
  68. package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
  69. package/src/pages/functions.ts +8 -4
  70. package/src/pages/index.ts +3 -3
  71. package/src/pages/projects.tsx +7 -12
  72. package/src/pages/publish.tsx +15 -239
  73. package/src/pages/types.ts +5 -0
  74. package/src/pages/upload.tsx +6 -4
  75. package/src/parse.ts +23 -1
  76. package/src/publish/index.ts +19 -15
  77. package/src/publish/publish.ts +3 -2
  78. package/src/pubsub/pubsub-commands.ts +18 -19
  79. package/src/queues/cli/commands/consumer/add.ts +18 -24
  80. package/src/queues/cli/commands/consumer/index.ts +3 -6
  81. package/src/queues/cli/commands/consumer/remove.ts +11 -18
  82. package/src/queues/cli/commands/create.ts +8 -8
  83. package/src/queues/cli/commands/delete.ts +8 -8
  84. package/src/queues/cli/commands/index.ts +3 -4
  85. package/src/queues/cli/commands/list.ts +8 -8
  86. package/src/r2/index.ts +28 -28
  87. package/src/secret/index.ts +9 -14
  88. package/src/tail/index.ts +6 -8
  89. package/src/yargs-types.ts +18 -5
  90. package/templates/checked-fetch.js +9 -1
  91. package/templates/d1-beta-facade.js +1 -1
  92. package/templates/middleware/loader-modules.ts +2 -0
  93. package/templates/tsconfig.tsbuildinfo +1 -1
  94. package/wrangler-dist/cli.d.ts +132 -10
  95. package/wrangler-dist/cli.js +2474 -1635
package/src/kv/index.ts CHANGED
@@ -25,12 +25,10 @@ import {
25
25
  putKVKeyValue,
26
26
  unexpectedKVKeyValueProps,
27
27
  } from "./helpers";
28
- import type { ConfigPath } from "../index";
29
- import type { CommonYargsOptions } from "../yargs-types";
28
+ import type { CommonYargsArgv } from "../yargs-types";
30
29
  import type { KeyValue } from "./helpers";
31
- import type { Argv } from "yargs";
32
30
 
33
- export const kvNamespace = (kvYargs: Argv<CommonYargsOptions>) => {
31
+ export function kvNamespace(kvYargs: CommonYargsArgv) {
34
32
  return kvYargs
35
33
  .command(
36
34
  "create <namespace>",
@@ -56,7 +54,7 @@ export const kvNamespace = (kvYargs: Argv<CommonYargsOptions>) => {
56
54
  );
57
55
  }
58
56
 
59
- const config = readConfig(args.config as ConfigPath, args);
57
+ const config = readConfig(args.config, args);
60
58
  if (!config.name) {
61
59
  logger.warn(
62
60
  "No configured name present, using `worker` as a prefix for the title"
@@ -94,9 +92,9 @@ export const kvNamespace = (kvYargs: Argv<CommonYargsOptions>) => {
94
92
  .command(
95
93
  "list",
96
94
  "Outputs a list of all KV namespaces associated with your account id.",
97
- {},
95
+ (listArgs) => listArgs,
98
96
  async (args) => {
99
- const config = readConfig(args.config as ConfigPath, args);
97
+ const config = readConfig(args.config, args);
100
98
 
101
99
  const accountId = await requireAuth(config);
102
100
 
@@ -133,7 +131,7 @@ export const kvNamespace = (kvYargs: Argv<CommonYargsOptions>) => {
133
131
  },
134
132
  async (args) => {
135
133
  await printWranglerBanner();
136
- const config = readConfig(args.config as ConfigPath, args);
134
+ const config = readConfig(args.config, args);
137
135
 
138
136
  let id;
139
137
  try {
@@ -172,9 +170,9 @@ export const kvNamespace = (kvYargs: Argv<CommonYargsOptions>) => {
172
170
  // TODO: delete the preview namespace as well?
173
171
  }
174
172
  );
175
- };
173
+ }
176
174
 
177
- export const kvKey = (kvYargs: Argv<CommonYargsOptions>) => {
175
+ export const kvKey = (kvYargs: CommonYargsArgv) => {
178
176
  return kvYargs
179
177
  .command(
180
178
  "put <key> [value]",
@@ -231,7 +229,7 @@ export const kvKey = (kvYargs: Argv<CommonYargsOptions>) => {
231
229
  },
232
230
  async ({ key, ttl, expiration, metadata, ...args }) => {
233
231
  await printWranglerBanner();
234
- const config = readConfig(args.config as ConfigPath, args);
232
+ const config = readConfig(args.config, args);
235
233
  const namespaceId = getKVNamespaceId(args, config);
236
234
  // One of `args.path` and `args.value` must be defined
237
235
  const value = args.path
@@ -297,7 +295,7 @@ export const kvKey = (kvYargs: Argv<CommonYargsOptions>) => {
297
295
  },
298
296
  async ({ prefix, ...args }) => {
299
297
  // TODO: support for limit+cursor (pagination)
300
- const config = readConfig(args.config as ConfigPath, args);
298
+ const config = readConfig(args.config, args);
301
299
  const namespaceId = getKVNamespaceId(args, config);
302
300
 
303
301
  const accountId = await requireAuth(config);
@@ -351,7 +349,7 @@ export const kvKey = (kvYargs: Argv<CommonYargsOptions>) => {
351
349
  });
352
350
  },
353
351
  async ({ key, ...args }) => {
354
- const config = readConfig(args.config as ConfigPath, args);
352
+ const config = readConfig(args.config, args);
355
353
  const namespaceId = getKVNamespaceId(args, config);
356
354
 
357
355
  const accountId = await requireAuth(config);
@@ -398,7 +396,7 @@ export const kvKey = (kvYargs: Argv<CommonYargsOptions>) => {
398
396
  },
399
397
  async ({ key, ...args }) => {
400
398
  await printWranglerBanner();
401
- const config = readConfig(args.config as ConfigPath, args);
399
+ const config = readConfig(args.config, args);
402
400
  const namespaceId = getKVNamespaceId(args, config);
403
401
 
404
402
  logger.log(`Deleting the key "${key}" on namespace ${namespaceId}.`);
@@ -413,7 +411,7 @@ export const kvKey = (kvYargs: Argv<CommonYargsOptions>) => {
413
411
  );
414
412
  };
415
413
 
416
- export const kvBulk = (kvYargs: Argv<CommonYargsOptions>) => {
414
+ export const kvBulk = (kvYargs: CommonYargsArgv) => {
417
415
  return kvYargs
418
416
  .command(
419
417
  "put <filename>",
@@ -447,7 +445,7 @@ export const kvBulk = (kvYargs: Argv<CommonYargsOptions>) => {
447
445
  // This could be made more efficient with a streaming parser/uploader
448
446
  // but we'll do that in the future if needed.
449
447
 
450
- const config = readConfig(args.config as ConfigPath, args);
448
+ const config = readConfig(args.config, args);
451
449
  const namespaceId = getKVNamespaceId(args, config);
452
450
  const content = parseJSON(readFileSync(filename), filename);
453
451
 
@@ -541,7 +539,7 @@ export const kvBulk = (kvYargs: Argv<CommonYargsOptions>) => {
541
539
  },
542
540
  async ({ filename, ...args }) => {
543
541
  await printWranglerBanner();
544
- const config = readConfig(args.config as ConfigPath, args);
542
+ const config = readConfig(args.config, args);
545
543
  const namespaceId = getKVNamespaceId(args, config);
546
544
 
547
545
  if (!args.force) {
@@ -56,7 +56,8 @@ export type EventNames =
56
56
  | "run dev"
57
57
  | "run dev (api)"
58
58
  | "run pages dev"
59
- | "view docs";
59
+ | "view docs"
60
+ | "view deployments";
60
61
 
61
62
  /**
62
63
  * Send a metrics event, with no extra properties, to Cloudflare, if usage tracking is enabled.
@@ -1,29 +1,23 @@
1
- import { writeFileSync } from "node:fs";
2
- import { tmpdir } from "node:os";
3
- import { dirname, join, resolve } from "node:path";
1
+ import { dirname } from "node:path";
4
2
  import { FatalError } from "../errors";
5
3
  import { logger } from "../logger";
6
4
  import * as metrics from "../metrics";
7
- import { toUrlPath } from "../paths";
5
+ import { buildFunctions } from "./buildFunctions";
8
6
  import { isInPagesCI } from "./constants";
9
7
  import {
10
8
  EXIT_CODE_FUNCTIONS_NO_ROUTES_ERROR,
11
9
  FunctionsNoRoutesError,
12
10
  getFunctionsNoRoutesWarning,
13
11
  } from "./errors";
14
- import { buildPlugin } from "./functions/buildPlugin";
15
- import { buildWorker } from "./functions/buildWorker";
16
- import { generateConfigFromFileTree } from "./functions/filepath-routing";
17
- import { writeRoutesModule } from "./functions/routes";
18
- import { convertRoutesToRoutesJSONSpec } from "./functions/routes-transformation";
19
- import { pagesBetaWarning, RUNNING_BUILDERS } from "./utils";
20
- import type { YargsOptionsToInterface } from "../yargs-types";
21
- import type { Config } from "./functions/routes";
22
- import type { Argv } from "yargs";
12
+ import { pagesBetaWarning } from "./utils";
13
+ import type {
14
+ CommonYargsArgv,
15
+ StrictYargsOptionsToInterface,
16
+ } from "../yargs-types";
23
17
 
24
- type PagesBuildArgs = YargsOptionsToInterface<typeof Options>;
18
+ export type PagesBuildArgs = StrictYargsOptionsToInterface<typeof Options>;
25
19
 
26
- export function Options(yargs: Argv) {
20
+ export function Options(yargs: CommonYargsArgv) {
27
21
  return yargs
28
22
  .positional("directory", {
29
23
  type: "string",
@@ -156,115 +150,3 @@ export const Handler = async ({
156
150
  }
157
151
  await metrics.sendMetricsEvent("build pages functions");
158
152
  };
159
-
160
- /**
161
- * Builds a Functions worker based on the functions directory, with filepath and handler based routing.
162
- * @throws FunctionsNoRoutesError when there are no routes found in the functions directory
163
- */
164
- export async function buildFunctions({
165
- outfile,
166
- outputConfigPath,
167
- functionsDirectory,
168
- minify = false,
169
- sourcemap = false,
170
- fallbackService = "ASSETS",
171
- watch = false,
172
- onEnd,
173
- plugin = false,
174
- buildOutputDirectory,
175
- routesOutputPath,
176
- nodeCompat,
177
- local,
178
- d1Databases,
179
- }: Partial<
180
- Pick<
181
- PagesBuildArgs,
182
- | "outputConfigPath"
183
- | "minify"
184
- | "sourcemap"
185
- | "fallbackService"
186
- | "watch"
187
- | "plugin"
188
- | "buildOutputDirectory"
189
- | "nodeCompat"
190
- >
191
- > & {
192
- functionsDirectory: string;
193
- onEnd?: () => void;
194
- outfile: Required<PagesBuildArgs>["outfile"];
195
- routesOutputPath?: PagesBuildArgs["outputRoutesPath"];
196
- local: boolean;
197
- d1Databases?: string[];
198
- }) {
199
- RUNNING_BUILDERS.forEach(
200
- (runningBuilder) => runningBuilder.stop && runningBuilder.stop()
201
- );
202
-
203
- const routesModule = join(tmpdir(), `./functionsRoutes-${Math.random()}.mjs`);
204
- const baseURL = toUrlPath("/");
205
-
206
- const config: Config = await generateConfigFromFileTree({
207
- baseDir: functionsDirectory,
208
- baseURL,
209
- });
210
-
211
- if (!config.routes || config.routes.length === 0) {
212
- throw new FunctionsNoRoutesError(
213
- `Failed to find any routes while compiling Functions in: ${functionsDirectory}`
214
- );
215
- }
216
-
217
- if (routesOutputPath) {
218
- const routesJSON = convertRoutesToRoutesJSONSpec(config.routes);
219
- writeFileSync(routesOutputPath, JSON.stringify(routesJSON, null, 2));
220
- }
221
-
222
- if (outputConfigPath) {
223
- writeFileSync(
224
- outputConfigPath,
225
- JSON.stringify({ ...config, baseURL }, null, 2)
226
- );
227
- }
228
-
229
- await writeRoutesModule({
230
- config,
231
- srcDir: functionsDirectory,
232
- outfile: routesModule,
233
- });
234
-
235
- const absoluteFunctionsDirectory = resolve(functionsDirectory);
236
-
237
- if (plugin) {
238
- RUNNING_BUILDERS.push(
239
- await buildPlugin({
240
- routesModule,
241
- outfile,
242
- minify,
243
- sourcemap,
244
- watch,
245
- nodeCompat,
246
- functionsDirectory: absoluteFunctionsDirectory,
247
- local,
248
- betaD1Shims: d1Databases,
249
- onEnd,
250
- })
251
- );
252
- } else {
253
- RUNNING_BUILDERS.push(
254
- await buildWorker({
255
- routesModule,
256
- outfile,
257
- minify,
258
- sourcemap,
259
- fallbackService,
260
- watch,
261
- functionsDirectory: absoluteFunctionsDirectory,
262
- local,
263
- betaD1Shims: d1Databases,
264
- onEnd,
265
- buildOutputDirectory,
266
- nodeCompat,
267
- })
268
- );
269
- }
270
- }
@@ -0,0 +1,129 @@
1
+ import { writeFileSync } from "node:fs";
2
+ import { tmpdir } from "node:os";
3
+ import { join, resolve } from "node:path";
4
+ import { toUrlPath } from "../paths";
5
+ import { FunctionsNoRoutesError } from "./errors";
6
+ import { buildPlugin } from "./functions/buildPlugin";
7
+ import { buildWorker } from "./functions/buildWorker";
8
+ import { generateConfigFromFileTree } from "./functions/filepath-routing";
9
+ import { writeRoutesModule } from "./functions/routes";
10
+ import { convertRoutesToRoutesJSONSpec } from "./functions/routes-transformation";
11
+ import { RUNNING_BUILDERS } from "./utils";
12
+ import type { PagesBuildArgs } from "./build";
13
+ import type { Config } from "./functions/routes";
14
+
15
+ /**
16
+ * Builds a Functions worker based on the functions directory, with filepath and handler based routing.
17
+ * @throws FunctionsNoRoutesError when there are no routes found in the functions directory
18
+ */
19
+
20
+ export async function buildFunctions({
21
+ outfile,
22
+ outputConfigPath,
23
+ functionsDirectory,
24
+ minify = false,
25
+ sourcemap = false,
26
+ fallbackService = "ASSETS",
27
+ watch = false,
28
+ onEnd,
29
+ plugin = false,
30
+ buildOutputDirectory,
31
+ routesOutputPath,
32
+ nodeCompat,
33
+ local,
34
+ d1Databases,
35
+ experimentalWorkerBundle = false,
36
+ }: Partial<
37
+ Pick<
38
+ PagesBuildArgs,
39
+ | "outputConfigPath"
40
+ | "minify"
41
+ | "sourcemap"
42
+ | "fallbackService"
43
+ | "watch"
44
+ | "plugin"
45
+ | "buildOutputDirectory"
46
+ | "nodeCompat"
47
+ >
48
+ > & {
49
+ functionsDirectory: string;
50
+ onEnd?: () => void;
51
+ outfile: Required<PagesBuildArgs>["outfile"];
52
+ routesOutputPath?: PagesBuildArgs["outputRoutesPath"];
53
+ local: boolean;
54
+ d1Databases?: string[];
55
+ experimentalWorkerBundle?: boolean;
56
+ }) {
57
+ RUNNING_BUILDERS.forEach(
58
+ (runningBuilder) => runningBuilder.stop && runningBuilder.stop()
59
+ );
60
+
61
+ const routesModule = join(tmpdir(), `./functionsRoutes-${Math.random()}.mjs`);
62
+ const baseURL = toUrlPath("/");
63
+
64
+ const config: Config = await generateConfigFromFileTree({
65
+ baseDir: functionsDirectory,
66
+ baseURL,
67
+ });
68
+
69
+ if (!config.routes || config.routes.length === 0) {
70
+ throw new FunctionsNoRoutesError(
71
+ `Failed to find any routes while compiling Functions in: ${functionsDirectory}`
72
+ );
73
+ }
74
+
75
+ if (routesOutputPath) {
76
+ const routesJSON = convertRoutesToRoutesJSONSpec(config.routes);
77
+ writeFileSync(routesOutputPath, JSON.stringify(routesJSON, null, 2));
78
+ }
79
+
80
+ if (outputConfigPath) {
81
+ writeFileSync(
82
+ outputConfigPath,
83
+ JSON.stringify({ ...config, baseURL }, null, 2)
84
+ );
85
+ }
86
+
87
+ await writeRoutesModule({
88
+ config,
89
+ srcDir: functionsDirectory,
90
+ outfile: routesModule,
91
+ });
92
+
93
+ const absoluteFunctionsDirectory = resolve(functionsDirectory);
94
+
95
+ if (plugin) {
96
+ RUNNING_BUILDERS.push(
97
+ await buildPlugin({
98
+ routesModule,
99
+ outfile,
100
+ minify,
101
+ sourcemap,
102
+ watch,
103
+ nodeCompat,
104
+ functionsDirectory: absoluteFunctionsDirectory,
105
+ local,
106
+ betaD1Shims: d1Databases,
107
+ onEnd,
108
+ })
109
+ );
110
+ } else {
111
+ RUNNING_BUILDERS.push(
112
+ await buildWorker({
113
+ routesModule,
114
+ outfile,
115
+ minify,
116
+ sourcemap,
117
+ fallbackService,
118
+ watch,
119
+ functionsDirectory: absoluteFunctionsDirectory,
120
+ local,
121
+ betaD1Shims: d1Databases,
122
+ onEnd,
123
+ buildOutputDirectory,
124
+ nodeCompat,
125
+ experimentalWorkerBundle,
126
+ })
127
+ );
128
+ }
129
+ }
@@ -18,15 +18,12 @@ import { requireAuth } from "../user";
18
18
  import { PAGES_CONFIG_CACHE_FILENAME } from "./constants";
19
19
  import { promptSelectProject } from "./prompt-select-project";
20
20
  import { isUrl } from "./utils";
21
- import type { ConfigPath } from "..";
22
- import type { YargsOptionsToInterface } from "../yargs-types";
21
+ import type {
22
+ CommonYargsArgv,
23
+ StrictYargsOptionsToInterface,
24
+ } from "../yargs-types";
23
25
  import type { Deployment, PagesConfigCache } from "./types";
24
- import type { Argv } from "yargs";
25
26
 
26
- type Options = YargsOptionsToInterface<typeof Options> & {
27
- // Global flag
28
- config?: string;
29
- };
30
27
  const statusChoices = ["ok", "error", "canceled"] as const;
31
28
  type StatusChoice = typeof statusChoices[number];
32
29
  const isStatusChoiceList = (
@@ -35,7 +32,7 @@ const isStatusChoiceList = (
35
32
  ): data is StatusChoice[] =>
36
33
  data?.every((d) => statusChoices.includes(d)) ?? false;
37
34
 
38
- export function Options(yargs: Argv) {
35
+ export function Options(yargs: CommonYargsArgv) {
39
36
  return (
40
37
  yargs
41
38
  .positional("deployment", {
@@ -122,7 +119,7 @@ export async function Handler({
122
119
  format = "pretty",
123
120
  debug,
124
121
  ...args
125
- }: Options) {
122
+ }: StrictYargsOptionsToInterface<typeof Options>) {
126
123
  if (status && !isStatusChoiceList(status)) {
127
124
  throw new FatalError(
128
125
  "Invalid value for `--status`. Valid options: " + statusChoices.join(", ")
@@ -133,7 +130,7 @@ export async function Handler({
133
130
  await printWranglerBanner();
134
131
  }
135
132
 
136
- const config = readConfig(args.config as ConfigPath, args);
133
+ const config = readConfig(args.config, args);
137
134
  const pagesConfig = getConfigCache<PagesConfigCache>(
138
135
  PAGES_CONFIG_CACHE_FILENAME
139
136
  );
@@ -10,13 +10,15 @@ import { requireAuth } from "../user";
10
10
  import { PAGES_CONFIG_CACHE_FILENAME } from "./constants";
11
11
  import { promptSelectProject } from "./prompt-select-project";
12
12
  import { pagesBetaWarning } from "./utils";
13
- import type { YargsOptionsToInterface } from "../yargs-types";
13
+ import type {
14
+ CommonYargsArgv,
15
+ StrictYargsOptionsToInterface,
16
+ } from "../yargs-types";
14
17
  import type { Deployment, PagesConfigCache } from "./types";
15
- import type { Argv } from "yargs";
16
18
 
17
- type ListArgs = YargsOptionsToInterface<typeof ListOptions>;
19
+ type ListArgs = StrictYargsOptionsToInterface<typeof ListOptions>;
18
20
 
19
- export function ListOptions(yargs: Argv) {
21
+ export function ListOptions(yargs: CommonYargsArgv) {
20
22
  return yargs
21
23
  .options({
22
24
  "project-name": {
package/src/pages/dev.ts CHANGED
@@ -10,24 +10,24 @@ import { FatalError } from "../errors";
10
10
  import { logger } from "../logger";
11
11
  import * as metrics from "../metrics";
12
12
  import { getBasePath } from "../paths";
13
- import { buildFunctions } from "./build";
13
+ import { buildFunctions } from "./buildFunctions";
14
14
  import { ROUTES_SPEC_VERSION, SECONDS_TO_WAIT_FOR_PROXY } from "./constants";
15
15
  import { FunctionsNoRoutesError, getFunctionsNoRoutesWarning } from "./errors";
16
16
  import { buildRawWorker, checkRawWorker } from "./functions/buildWorker";
17
17
  import { validateRoutes } from "./functions/routes-validation";
18
18
  import { CLEANUP, CLEANUP_CALLBACKS, pagesBetaWarning } from "./utils";
19
19
  import type { AdditionalDevProps } from "../dev";
20
- import type { YargsOptionsToInterface } from "../yargs-types";
20
+ import type {
21
+ CommonYargsArgv,
22
+ StrictYargsOptionsToInterface,
23
+ } from "../yargs-types";
21
24
  import type { RoutesJSONSpec } from "./functions/routes-transformation";
22
- import type { Argv } from "yargs";
23
25
 
24
26
  const DURABLE_OBJECTS_BINDING_REGEXP = new RegExp(
25
27
  /^(?<binding>[^=]+)=(?<className>[^@\s]+)(@(?<scriptName>.*)$)?$/
26
28
  );
27
29
 
28
- type PagesDevArgs = YargsOptionsToInterface<typeof Options>;
29
-
30
- export function Options(yargs: Argv) {
30
+ export function Options(yargs: CommonYargsArgv) {
31
31
  return yargs
32
32
  .positional("directory", {
33
33
  type: "string",
@@ -89,6 +89,13 @@ export function Options(yargs: Argv) {
89
89
  default: true,
90
90
  description: "Whether to run bundling on `_worker.js`",
91
91
  },
92
+ "experimental-worker-bundle": {
93
+ type: "boolean",
94
+ default: false,
95
+ hidden: true,
96
+ description:
97
+ "Whether to process non-JS module imports or not, such as wasm/text/binary, when we run bundling on `functions` or `_worker.js`",
98
+ },
92
99
  binding: {
93
100
  type: "array",
94
101
  description: "Bind variable/secret (KEY=VALUE)",
@@ -166,38 +173,37 @@ export function Options(yargs: Argv) {
166
173
  export const Handler = async ({
167
174
  local,
168
175
  directory,
169
- "compatibility-date": compatibilityDate,
170
- "compatibility-flags": compatibilityFlags,
176
+ compatibilityDate,
177
+ compatibilityFlags,
171
178
  ip,
172
179
  port,
173
- "inspector-port": inspectorPort,
180
+ inspectorPort,
174
181
  proxy: requestedProxyPort,
175
- "script-path": singleWorkerScriptPath,
176
182
  bundle,
177
183
  noBundle,
184
+ experimentalWorkerBundle,
185
+ scriptPath: singleWorkerScriptPath,
178
186
  binding: bindings = [],
179
187
  kv: kvs = [],
180
188
  do: durableObjects = [],
181
189
  d1: d1s = [],
182
190
  r2: r2s = [],
183
- "live-reload": liveReload,
184
- "local-protocol": localProtocol,
191
+ liveReload,
192
+ localProtocol,
185
193
  experimentalEnableLocalPersistence,
186
194
  persist,
187
195
  persistTo,
188
- "node-compat": nodeCompat,
189
- "experimental-local": experimentalLocal,
196
+ nodeCompat,
197
+ experimentalLocal,
190
198
  config: config,
191
199
  _: [_pages, _dev, ...remaining],
192
200
  logLevel,
193
- }: PagesDevArgs) => {
201
+ }: StrictYargsOptionsToInterface<typeof Options>) => {
194
202
  // Beta message for `wrangler pages <commands>` usage
195
203
  logger.log(pagesBetaWarning);
196
204
 
197
- type LogLevelArg = "debug" | "info" | "log" | "warn" | "error" | "none";
198
205
  if (logLevel) {
199
- // The YargsOptionsToInterface doesn't handle the passing in of Unions from choices in Yargs
200
- logger.loggerLevel = logLevel as LogLevelArg;
206
+ logger.loggerLevel = logLevel;
201
207
  }
202
208
 
203
209
  if (!local) {
@@ -270,7 +276,7 @@ export const Handler = async ({
270
276
  await checkRawWorker(workerScriptPath, () => scriptReadyResolve());
271
277
  };
272
278
 
273
- const enableBundling = bundle || !noBundle;
279
+ const enableBundling = bundle || !noBundle || experimentalWorkerBundle;
274
280
  if (enableBundling) {
275
281
  // We want to actually run the `_worker.js` script through the bundler
276
282
  // So update the final path to the script that will be uploaded and
@@ -286,6 +292,7 @@ export const Handler = async ({
286
292
  sourcemap: true,
287
293
  watch: true,
288
294
  onEnd: () => scriptReadyResolve(),
295
+ experimentalWorkerBundle,
289
296
  });
290
297
  } catch (e: unknown) {
291
298
  logger.warn("Failed to bundle _worker.js.", e);
@@ -323,6 +330,7 @@ export const Handler = async ({
323
330
  buildOutputDirectory: directory,
324
331
  nodeCompat,
325
332
  local: true,
333
+ experimentalWorkerBundle,
326
334
  });
327
335
  await metrics.sendMetricsEvent("build pages functions");
328
336
  };
@@ -37,6 +37,7 @@ export function buildPlugin({
37
37
  betaD1Shims: (betaD1Shims || []).map(
38
38
  (binding) => `${D1_BETA_PREFIX}${binding}`
39
39
  ),
40
+ doBindings: [], // Pages functions don't support internal Durable Objects
40
41
  plugins: [
41
42
  buildNotifierPlugin(onEnd),
42
43
  {
@@ -21,6 +21,7 @@ export type Options = {
21
21
  functionsDirectory: string;
22
22
  local: boolean;
23
23
  betaD1Shims?: string[];
24
+ experimentalWorkerBundle?: boolean;
24
25
  };
25
26
 
26
27
  export function buildWorker({
@@ -36,6 +37,7 @@ export function buildWorker({
36
37
  functionsDirectory,
37
38
  local,
38
39
  betaD1Shims,
40
+ experimentalWorkerBundle = false,
39
41
  }: Options) {
40
42
  return bundleWorker(
41
43
  {
@@ -60,6 +62,7 @@ export function buildWorker({
60
62
  betaD1Shims: (betaD1Shims || []).map(
61
63
  (binding) => `${D1_BETA_PREFIX}${binding}`
62
64
  ),
65
+ doBindings: [], // Pages functions don't support internal Durable Objects
63
66
  plugins: [
64
67
  buildNotifierPlugin(onEnd),
65
68
  {
@@ -139,7 +142,7 @@ export function buildWorker({
139
142
  ],
140
143
  isOutfile: true,
141
144
  serveAssetsFromWorker: false,
142
- disableModuleCollection: true,
145
+ disableModuleCollection: experimentalWorkerBundle ? false : true,
143
146
  rules: [],
144
147
  checkFetch: local,
145
148
  targetConsumer: local ? "dev" : "publish",
@@ -162,6 +165,7 @@ export type RawOptions = {
162
165
  nodeCompat?: boolean;
163
166
  local: boolean;
164
167
  betaD1Shims?: string[];
168
+ experimentalWorkerBundle?: boolean;
165
169
  };
166
170
 
167
171
  /**
@@ -183,6 +187,7 @@ export function buildRawWorker({
183
187
  nodeCompat,
184
188
  local,
185
189
  betaD1Shims,
190
+ experimentalWorkerBundle = false,
186
191
  }: RawOptions) {
187
192
  return bundleWorker(
188
193
  {
@@ -204,10 +209,11 @@ export function buildRawWorker({
204
209
  betaD1Shims: (betaD1Shims || []).map(
205
210
  (binding) => `${D1_BETA_PREFIX}${binding}`
206
211
  ),
212
+ doBindings: [], // Pages functions don't support internal Durable Objects
207
213
  plugins: [...plugins, buildNotifierPlugin(onEnd)],
208
214
  isOutfile: true,
209
215
  serveAssetsFromWorker: false,
210
- disableModuleCollection: true,
216
+ disableModuleCollection: experimentalWorkerBundle ? false : true,
211
217
  rules: [],
212
218
  checkFetch: local,
213
219
  targetConsumer: local ? "dev" : "publish",