wrangler 0.0.0-e33294b0 → 0.0.0-e351afcf

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 (127) hide show
  1. package/bin/wrangler.js +1 -1
  2. package/miniflare-dist/index.mjs +183 -92
  3. package/package.json +15 -10
  4. package/src/__tests__/api-devregistry.test.ts +121 -0
  5. package/src/__tests__/api.test.ts +27 -5
  6. package/src/__tests__/configuration.test.ts +294 -18
  7. package/src/__tests__/constellation.test.ts +371 -0
  8. package/src/__tests__/d1/execute.test.ts +3 -1
  9. package/src/__tests__/d1/migrate.test.ts +102 -0
  10. package/src/__tests__/delete.test.ts +6 -0
  11. package/src/__tests__/deployments.test.ts +335 -95
  12. package/src/__tests__/dev.test.tsx +87 -57
  13. package/src/__tests__/generate.test.ts +3 -4
  14. package/src/__tests__/guess-worker-format.test.ts +35 -0
  15. package/src/__tests__/helpers/mock-console.ts +6 -0
  16. package/src/__tests__/helpers/msw/handlers/deployments.ts +70 -3
  17. package/src/__tests__/helpers/msw/index.ts +4 -2
  18. package/src/__tests__/helpers/worker-scripts/parent-worker.js +4 -1
  19. package/src/__tests__/index.test.ts +14 -6
  20. package/src/__tests__/init.test.ts +136 -104
  21. package/src/__tests__/jest.setup.ts +4 -0
  22. package/src/__tests__/kv.test.ts +9 -9
  23. package/src/__tests__/logger.test.ts +68 -2
  24. package/src/__tests__/middleware.scheduled.test.ts +2 -2
  25. package/src/__tests__/middleware.test.ts +4 -3
  26. package/src/__tests__/mtls-certificates.test.ts +7 -3
  27. package/src/__tests__/pages/deployment-list.test.ts +2 -0
  28. package/src/__tests__/pages/functions-build.test.ts +159 -39
  29. package/src/__tests__/pages/project-list.test.ts +2 -0
  30. package/src/__tests__/pages/project-upload.test.ts +43 -24
  31. package/src/__tests__/pages/publish.test.ts +267 -148
  32. package/src/__tests__/publish.test.ts +1040 -339
  33. package/src/__tests__/pubsub.test.ts +3 -0
  34. package/src/__tests__/queues.test.ts +5 -2
  35. package/src/__tests__/test-old-node-version.js +3 -3
  36. package/src/__tests__/traverse-module-graph.test.ts +220 -0
  37. package/src/__tests__/tsconfig.tsbuildinfo +1 -1
  38. package/src/__tests__/type-generation.test.ts +1 -0
  39. package/src/__tests__/user.test.ts +2 -2
  40. package/src/__tests__/worker-namespace.test.ts +1 -0
  41. package/src/api/dev.ts +15 -22
  42. package/src/api/pages/create-worker-bundle-contents.ts +1 -0
  43. package/src/api/pages/publish.tsx +64 -61
  44. package/src/bundle.ts +51 -16
  45. package/src/config/environment.ts +36 -4
  46. package/src/config/index.ts +30 -2
  47. package/src/config/validation-helpers.ts +1 -1
  48. package/src/config/validation.ts +149 -5
  49. package/src/constellation/createProject.tsx +51 -0
  50. package/src/constellation/deleteProject.ts +51 -0
  51. package/src/constellation/deleteProjectModel.ts +68 -0
  52. package/src/constellation/index.ts +75 -0
  53. package/src/constellation/listCatalog.tsx +35 -0
  54. package/src/constellation/listModel.tsx +41 -0
  55. package/src/constellation/listProject.tsx +28 -0
  56. package/src/constellation/listRuntime.tsx +28 -0
  57. package/src/constellation/options.ts +17 -0
  58. package/src/constellation/types.ts +17 -0
  59. package/src/constellation/uploadModel.tsx +64 -0
  60. package/src/constellation/utils.ts +90 -0
  61. package/src/create-worker-preview.ts +19 -8
  62. package/src/create-worker-upload-form.ts +28 -3
  63. package/src/d1/backups.tsx +19 -15
  64. package/src/d1/create.tsx +45 -39
  65. package/src/d1/delete.ts +1 -1
  66. package/src/d1/execute.tsx +23 -20
  67. package/src/d1/list.tsx +14 -12
  68. package/src/d1/migrations/apply.tsx +36 -30
  69. package/src/d1/migrations/create.tsx +15 -12
  70. package/src/d1/migrations/helpers.ts +5 -8
  71. package/src/d1/migrations/list.tsx +10 -7
  72. package/src/deployments.ts +260 -8
  73. package/src/dev/dev.tsx +6 -4
  74. package/src/dev/local.tsx +65 -40
  75. package/src/dev/start-server.ts +57 -52
  76. package/src/dev/use-esbuild.ts +59 -52
  77. package/src/dev/validate-dev-props.ts +9 -0
  78. package/src/dev-registry.ts +2 -1
  79. package/src/dev.tsx +38 -18
  80. package/src/docs/helpers.ts +50 -0
  81. package/src/docs/index.ts +25 -68
  82. package/src/entry.ts +19 -9
  83. package/src/environment-variables/factory.ts +2 -1
  84. package/src/generate/index.ts +2 -2
  85. package/src/index.ts +87 -24
  86. package/src/init.ts +144 -134
  87. package/src/inspect.ts +16 -1
  88. package/src/kv/helpers.ts +7 -4
  89. package/src/logger.ts +23 -4
  90. package/src/metrics/send-event.ts +2 -1
  91. package/src/miniflare-cli/assets.ts +8 -7
  92. package/src/miniflare-cli/index.ts +3 -3
  93. package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -1
  94. package/src/module-collection.ts +92 -26
  95. package/src/pages/build.ts +290 -100
  96. package/src/pages/buildFunctions.ts +20 -10
  97. package/src/pages/deployments.tsx +3 -5
  98. package/src/pages/dev.ts +44 -26
  99. package/src/pages/errors.ts +1 -0
  100. package/src/pages/functions/buildPlugin.ts +57 -34
  101. package/src/pages/functions/buildWorker.ts +91 -31
  102. package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
  103. package/src/pages/projects.tsx +2 -5
  104. package/src/pages/publish.tsx +1 -10
  105. package/src/pages/upload.tsx +29 -9
  106. package/src/paths.ts +1 -1
  107. package/src/publish/index.ts +1 -1
  108. package/src/publish/publish.ts +29 -34
  109. package/src/queues/cli/commands/consumer/add.ts +6 -0
  110. package/src/queues/client.ts +1 -0
  111. package/src/r2/helpers.ts +1 -0
  112. package/src/secret/index.ts +2 -1
  113. package/src/sites.ts +164 -52
  114. package/src/traverse-module-graph.ts +53 -0
  115. package/src/type-generation.ts +1 -1
  116. package/src/user/user.ts +2 -1
  117. package/src/utils/render.ts +93 -0
  118. package/src/worker.ts +18 -1
  119. package/templates/d1-beta-facade.js +5 -2
  120. package/templates/gitignore +1 -0
  121. package/templates/middleware/middleware-miniflare3-json-error.ts +17 -5
  122. package/templates/pages-template-plugin.ts +7 -3
  123. package/templates/tsconfig.init.json +1 -2
  124. package/templates/tsconfig.tsbuildinfo +1 -1
  125. package/wrangler-dist/cli.d.ts +552 -16
  126. package/wrangler-dist/cli.js +32141 -24052
  127. package/src/__tests__/api-devregistry.test.js +0 -64
@@ -1,6 +1,5 @@
1
- import { existsSync, writeFileSync } from "node:fs";
2
- import { tmpdir } from "node:os";
3
- import { basename, dirname, join, resolve as resolvePath } from "node:path";
1
+ import { existsSync, lstatSync, mkdirSync, writeFileSync } from "node:fs";
2
+ import { basename, dirname, relative, resolve as resolvePath } from "node:path";
4
3
  import { createUploadWorkerBundleContents } from "../api/pages/create-worker-bundle-contents";
5
4
  import { FatalError } from "../errors";
6
5
  import { logger } from "../logger";
@@ -8,11 +7,15 @@ import * as metrics from "../metrics";
8
7
  import { buildFunctions } from "./buildFunctions";
9
8
  import { isInPagesCI } from "./constants";
10
9
  import {
10
+ EXIT_CODE_FUNCTIONS_NOTHING_TO_BUILD_ERROR,
11
11
  EXIT_CODE_FUNCTIONS_NO_ROUTES_ERROR,
12
12
  FunctionsNoRoutesError,
13
13
  getFunctionsNoRoutesWarning,
14
14
  } from "./errors";
15
- import { buildRawWorker } from "./functions/buildWorker";
15
+ import {
16
+ buildRawWorker,
17
+ traverseAndBuildWorkerJSDirectory,
18
+ } from "./functions/buildWorker";
16
19
  import { pagesBetaWarning } from "./utils";
17
20
  import type { BundleResult } from "../bundle";
18
21
  import type {
@@ -32,9 +35,12 @@ export function Options(yargs: CommonYargsArgv) {
32
35
  .options({
33
36
  outfile: {
34
37
  type: "string",
35
- default: "_worker.js",
36
38
  description: "The location of the output Worker script",
37
39
  },
40
+ outdir: {
41
+ type: "string",
42
+ description: "Output directory for the bundled Worker",
43
+ },
38
44
  "output-config-path": {
39
45
  type: "string",
40
46
  description: "The location for the output config file",
@@ -75,11 +81,23 @@ export function Options(yargs: CommonYargsArgv) {
75
81
  description: "The directory to output static assets to",
76
82
  },
77
83
  "node-compat": {
78
- describe: "Enable node.js compatibility",
84
+ describe: "Enable Node.js compatibility",
79
85
  default: false,
80
86
  type: "boolean",
81
87
  hidden: true,
82
88
  },
89
+ "compatibility-date": {
90
+ describe: "Date to use for compatibility checks",
91
+ type: "string",
92
+ requiresArg: true,
93
+ },
94
+ "compatibility-flags": {
95
+ describe: "Flags to use for compatibility checks",
96
+ alias: "compatibility-flag",
97
+ type: "string",
98
+ requiresArg: true,
99
+ array: true,
100
+ },
83
101
  bindings: {
84
102
  type: "string",
85
103
  describe:
@@ -87,97 +105,36 @@ export function Options(yargs: CommonYargsArgv) {
87
105
  deprecated: true,
88
106
  hidden: true,
89
107
  },
90
- "experimental-worker-bundle": {
91
- type: "boolean",
92
- default: false,
93
- hidden: true,
94
- description:
95
- "Whether to process non-JS module imports or not, such as wasm/text/binary, when we run bundling on `functions` or `_worker.js`",
96
- },
97
108
  })
98
109
  .epilogue(pagesBetaWarning);
99
110
  }
100
111
 
101
- export const Handler = async ({
102
- directory,
103
- outfile,
104
- outputConfigPath,
105
- outputRoutesPath: routesOutputPath,
106
- minify,
107
- sourcemap,
108
- fallbackService,
109
- watch,
110
- plugin,
111
- buildOutputDirectory,
112
- nodeCompat,
113
- bindings,
114
- experimentalWorkerBundle,
115
- }: PagesBuildArgs) => {
112
+ export const Handler = async (args: PagesBuildArgs) => {
116
113
  if (!isInPagesCI) {
117
114
  // Beta message for `wrangler pages <commands>` usage
118
115
  logger.log(pagesBetaWarning);
119
116
  }
120
117
 
121
- if (nodeCompat) {
122
- console.warn(
123
- "Enabling node.js compatibility mode for builtins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details."
124
- );
125
- }
118
+ const validatedArgs = validateArgs(args);
126
119
 
127
- let d1Databases: string[] | undefined = undefined;
128
- if (bindings) {
129
- try {
130
- const decodedBindings = JSON.parse(bindings);
131
- d1Databases = Object.keys(decodedBindings?.d1_databases || {});
132
- } catch {
133
- throw new FatalError("Could not parse a valid set of 'bindings'.", 1);
134
- }
135
- }
136
-
137
- buildOutputDirectory ??= dirname(outfile);
138
-
139
- const workerScriptPath = resolvePath(buildOutputDirectory, "_worker.js");
140
- const foundWorkerScript = existsSync(workerScriptPath);
141
120
  let bundle: BundleResult | undefined = undefined;
142
121
 
143
- if (!foundWorkerScript && !existsSync(directory)) {
144
- throw new FatalError(`Could not find anything to build.
145
- We first looked inside the build output directory (${basename(
146
- resolvePath(buildOutputDirectory)
147
- )}), then looked for the Functions directory (${basename(
148
- directory
149
- )}) but couldn't find anything to build.
150
- ➤ If you are trying to build _worker.js, please make sure you provide the [--build-output-directory] containing your static files.
151
- ➤ If you are trying to build Pages Functions, please make sure [--directory] points to the location of your Functions files.`);
152
- }
153
-
154
- /**
155
- * prioritize building `_worker.js` over Pages Functions, if both exist
156
- * and if we were able to resolve _worker.js
157
- */
158
- if (experimentalWorkerBundle && foundWorkerScript) {
159
- /**
160
- * `buildRawWorker` builds `_worker.js`, but doesn't give us the bundle
161
- * we want to return, which includes the external dependencies (like wasm,
162
- * binary, text). Let's output that build result to memory and only write
163
- * to disk once we have the final bundle
164
- */
165
- const workerOutfile = experimentalWorkerBundle
166
- ? join(tmpdir(), `./bundledWorker-${Math.random()}.mjs`)
167
- : outfile;
122
+ if (validatedArgs.plugin) {
123
+ const {
124
+ directory,
125
+ outfile,
126
+ outdir,
127
+ outputConfigPath,
128
+ outputRoutesPath: routesOutputPath,
129
+ minify,
130
+ sourcemap,
131
+ fallbackService,
132
+ watch,
133
+ plugin,
134
+ nodejsCompat,
135
+ legacyNodeCompat,
136
+ } = validatedArgs;
168
137
 
169
- bundle = await buildRawWorker({
170
- workerScriptPath,
171
- outfile: workerOutfile,
172
- directory: buildOutputDirectory,
173
- local: false,
174
- sourcemap: true,
175
- watch: false,
176
- onEnd: () => {},
177
- betaD1Shims: d1Databases,
178
- experimentalWorkerBundle,
179
- });
180
- } else {
181
138
  try {
182
139
  /**
183
140
  * `buildFunctions` builds `/functions`, but doesn't give us the bundle
@@ -185,12 +142,9 @@ We first looked inside the build output directory (${basename(
185
142
  * binary, text). Let's output that build result to memory and only write
186
143
  * to disk once we have the final bundle
187
144
  */
188
- const functionsOutfile = experimentalWorkerBundle
189
- ? join(tmpdir(), `./functionsWorker-${Math.random()}.js`)
190
- : outfile;
191
-
192
145
  bundle = await buildFunctions({
193
- outfile: functionsOutfile,
146
+ outfile,
147
+ outdir,
194
148
  outputConfigPath,
195
149
  functionsDirectory: directory,
196
150
  minify,
@@ -198,12 +152,10 @@ We first looked inside the build output directory (${basename(
198
152
  fallbackService,
199
153
  watch,
200
154
  plugin,
201
- buildOutputDirectory,
202
- nodeCompat,
155
+ legacyNodeCompat,
156
+ nodejsCompat,
203
157
  routesOutputPath,
204
158
  local: false,
205
- d1Databases,
206
- experimentalWorkerBundle,
207
159
  });
208
160
  } catch (e) {
209
161
  if (e instanceof FunctionsNoRoutesError) {
@@ -215,18 +167,256 @@ We first looked inside the build output directory (${basename(
215
167
  throw e;
216
168
  }
217
169
  }
170
+
171
+ if (outfile && outfile !== bundle.resolvedEntryPointPath) {
172
+ writeFileSync(
173
+ outfile,
174
+ `export { default } from './${relative(
175
+ dirname(outfile),
176
+ bundle.resolvedEntryPointPath
177
+ )}'`
178
+ );
179
+ }
180
+ } else {
181
+ const {
182
+ directory,
183
+ outfile,
184
+ outdir,
185
+ outputConfigPath,
186
+ outputRoutesPath: routesOutputPath,
187
+ minify,
188
+ sourcemap,
189
+ fallbackService,
190
+ watch,
191
+ plugin,
192
+ buildOutputDirectory,
193
+ nodejsCompat,
194
+ legacyNodeCompat,
195
+ bindings,
196
+ workerScriptPath,
197
+ } = validatedArgs;
198
+
199
+ let d1Databases: string[] | undefined = undefined;
200
+ if (bindings) {
201
+ try {
202
+ const decodedBindings = JSON.parse(bindings);
203
+ d1Databases = Object.keys(decodedBindings?.d1_databases || {});
204
+ } catch {
205
+ throw new FatalError("Could not parse a valid set of 'bindings'.", 1);
206
+ }
207
+ }
208
+
209
+ /**
210
+ * prioritize building `_worker.js` over Pages Functions, if both exist
211
+ * and if we were able to resolve _worker.js
212
+ */
213
+ if (workerScriptPath) {
214
+ if (lstatSync(workerScriptPath).isDirectory()) {
215
+ bundle = await traverseAndBuildWorkerJSDirectory({
216
+ workerJSDirectory: workerScriptPath,
217
+ buildOutputDirectory,
218
+ d1Databases,
219
+ nodejsCompat,
220
+ });
221
+ } else {
222
+ /**
223
+ * `buildRawWorker` builds `_worker.js`, but doesn't give us the bundle
224
+ * we want to return, which includes the external dependencies (like wasm,
225
+ * binary, text). Let's output that build result to memory and only write
226
+ * to disk once we have the final bundle
227
+ */
228
+ bundle = await buildRawWorker({
229
+ workerScriptPath,
230
+ outdir,
231
+ directory: buildOutputDirectory,
232
+ local: false,
233
+ sourcemap,
234
+ watch,
235
+ betaD1Shims: d1Databases,
236
+ });
237
+ }
238
+ } else {
239
+ try {
240
+ /**
241
+ * `buildFunctions` builds `/functions`, but doesn't give us the bundle
242
+ * we want to return, which includes the external dependencies (like wasm,
243
+ * binary, text). Let's output that build result to memory and only write
244
+ * to disk once we have the final bundle
245
+ */
246
+ bundle = await buildFunctions({
247
+ outdir,
248
+ outputConfigPath,
249
+ functionsDirectory: directory,
250
+ minify,
251
+ sourcemap,
252
+ fallbackService,
253
+ watch,
254
+ plugin,
255
+ buildOutputDirectory,
256
+ legacyNodeCompat,
257
+ nodejsCompat,
258
+ routesOutputPath,
259
+ local: false,
260
+ d1Databases,
261
+ });
262
+ } catch (e) {
263
+ if (e instanceof FunctionsNoRoutesError) {
264
+ throw new FatalError(
265
+ getFunctionsNoRoutesWarning(directory),
266
+ EXIT_CODE_FUNCTIONS_NO_ROUTES_ERROR
267
+ );
268
+ } else {
269
+ throw e;
270
+ }
271
+ }
272
+ }
273
+
274
+ if (outfile) {
275
+ const workerBundleContents = await createUploadWorkerBundleContents(
276
+ bundle as BundleResult
277
+ );
278
+
279
+ mkdirSync(dirname(outfile), { recursive: true });
280
+ writeFileSync(
281
+ outfile,
282
+ Buffer.from(await workerBundleContents.arrayBuffer())
283
+ );
284
+ }
218
285
  }
219
286
 
220
- if (experimentalWorkerBundle) {
221
- const workerBundleContents = await createUploadWorkerBundleContents(
222
- bundle as BundleResult
287
+ await metrics.sendMetricsEvent("build pages functions");
288
+ };
289
+
290
+ type WorkerBundleArgs = Omit<PagesBuildArgs, "nodeCompat"> & {
291
+ plugin: false;
292
+ buildOutputDirectory: string;
293
+ legacyNodeCompat: boolean;
294
+ nodejsCompat: boolean;
295
+
296
+ workerScriptPath: string;
297
+ };
298
+ type PluginArgs = Omit<
299
+ PagesBuildArgs,
300
+ "buildOutputDirectory" | "bindings" | "nodeCompat"
301
+ > & {
302
+ plugin: true;
303
+ outdir: string;
304
+ legacyNodeCompat: boolean;
305
+ nodejsCompat: boolean;
306
+ };
307
+
308
+ type ValidatedArgs = WorkerBundleArgs | PluginArgs;
309
+
310
+ const validateArgs = (args: PagesBuildArgs): ValidatedArgs => {
311
+ if (args.outdir && args.outfile) {
312
+ throw new FatalError(
313
+ "Cannot specify both an `--outdir` and an `--outfile`.",
314
+ 1
223
315
  );
316
+ }
224
317
 
225
- writeFileSync(
226
- outfile,
227
- Buffer.from(await workerBundleContents.arrayBuffer())
318
+ if (args.plugin) {
319
+ if (args.outfile) {
320
+ // Explicit old behavior. Encourage to migrate to `--outdir` instead.
321
+ logger.warn(
322
+ "Creating a Pages Plugin with `--outfile` is now deprecated. Please use `--outdir` instead."
323
+ );
324
+
325
+ args.outdir = dirname(resolvePath(args.outfile));
326
+ } else if (!args.outfile && !args.outdir) {
327
+ // Didn't specify `--outfile`, but didn't specify `--outdir` either. Implicit old behavior defaults. Encourage to migrate to `--outdir`.
328
+ args.outfile ??= "_worker.js";
329
+ args.outdir = ".";
330
+
331
+ logger.warn(
332
+ "Creating a Pages Plugin without `--outdir` is now deprecated. Please add an `--outdir` argument."
333
+ );
334
+ }
335
+
336
+ if (args.bindings) {
337
+ throw new FatalError(
338
+ "The `--bindings` flag cannot be used when creating a Pages Plugin with `--plugin`.",
339
+ 1
340
+ );
341
+ }
342
+
343
+ if (args.buildOutputDirectory) {
344
+ throw new FatalError(
345
+ "The `--build-output-directory` flag cannot be used when creating a Pages Plugin with `--plugin`.",
346
+ 1
347
+ );
348
+ }
349
+ } else {
350
+ if (!args.outdir) {
351
+ args.outfile ??= "_worker.bundle";
352
+ }
353
+
354
+ args.buildOutputDirectory ??= args.outfile ? dirname(args.outfile) : ".";
355
+ }
356
+
357
+ if (args.buildOutputDirectory) {
358
+ args.buildOutputDirectory = resolvePath(args.buildOutputDirectory);
359
+ }
360
+ if (args.outdir) {
361
+ args.outdir = resolvePath(args.outdir);
362
+ }
363
+ if (args.outfile) {
364
+ args.outfile = resolvePath(args.outfile);
365
+ }
366
+
367
+ const { nodeCompat: legacyNodeCompat, ...argsExceptNodeCompat } = args;
368
+ if (legacyNodeCompat) {
369
+ console.warn(
370
+ "Enabling Node.js compatibility mode for builtins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details."
371
+ );
372
+ }
373
+ const nodejsCompat = !!args.compatibilityFlags?.includes("nodejs_compat");
374
+ if (legacyNodeCompat && nodejsCompat) {
375
+ throw new Error(
376
+ "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."
228
377
  );
229
378
  }
230
379
 
231
- await metrics.sendMetricsEvent("build pages functions");
380
+ let workerScriptPath: string | undefined;
381
+
382
+ if (args.buildOutputDirectory) {
383
+ const prospectiveWorkerScriptPath = resolvePath(
384
+ args.buildOutputDirectory,
385
+ "_worker.js"
386
+ );
387
+
388
+ const foundWorkerScript = existsSync(prospectiveWorkerScriptPath);
389
+
390
+ if (foundWorkerScript) {
391
+ workerScriptPath = prospectiveWorkerScriptPath;
392
+ } else if (!foundWorkerScript && !existsSync(args.directory)) {
393
+ throw new FatalError(
394
+ `Could not find anything to build.
395
+ We first looked inside the build output directory (${basename(
396
+ resolvePath(args.buildOutputDirectory)
397
+ )}), then looked for the Functions directory (${basename(
398
+ args.directory
399
+ )}) but couldn't find anything to build.
400
+ ➤ If you are trying to build _worker.js, please make sure you provide the [--build-output-directory] containing your static files.
401
+ ➤ If you are trying to build Pages Functions, please make sure [directory] points to the location of your Functions files.`,
402
+ EXIT_CODE_FUNCTIONS_NOTHING_TO_BUILD_ERROR
403
+ );
404
+ }
405
+ } else if (!existsSync(args.directory)) {
406
+ throw new FatalError(
407
+ `Could not find anything to build.
408
+ We looked for the Functions directory (${basename(
409
+ args.directory
410
+ )}) but couldn't find anything to build.
411
+ ➤ Please make sure [directory] points to the location of your Functions files.`,
412
+ EXIT_CODE_FUNCTIONS_NOTHING_TO_BUILD_ERROR
413
+ );
414
+ }
415
+
416
+ return {
417
+ ...argsExceptNodeCompat,
418
+ workerScriptPath,
419
+ nodejsCompat,
420
+ legacyNodeCompat,
421
+ } as ValidatedArgs;
232
422
  };
@@ -1,6 +1,7 @@
1
1
  import { writeFileSync } from "node:fs";
2
2
  import { tmpdir } from "node:os";
3
3
  import { join, resolve } from "node:path";
4
+ import { FatalError } from "../errors";
4
5
  import { toUrlPath } from "../paths";
5
6
  import { FunctionsNoRoutesError } from "./errors";
6
7
  import { buildPlugin } from "./functions/buildPlugin";
@@ -20,6 +21,7 @@ import type { Config } from "./functions/routes";
20
21
 
21
22
  export async function buildFunctions({
22
23
  outfile,
24
+ outdir,
23
25
  outputConfigPath,
24
26
  functionsDirectory,
25
27
  minify = false,
@@ -30,13 +32,15 @@ export async function buildFunctions({
30
32
  plugin = false,
31
33
  buildOutputDirectory,
32
34
  routesOutputPath,
33
- nodeCompat,
35
+ legacyNodeCompat,
36
+ nodejsCompat,
34
37
  local,
35
38
  d1Databases,
36
- experimentalWorkerBundle = false,
37
39
  }: Partial<
38
40
  Pick<
39
41
  PagesBuildArgs,
42
+ | "outfile"
43
+ | "outdir"
40
44
  | "outputConfigPath"
41
45
  | "minify"
42
46
  | "sourcemap"
@@ -44,16 +48,15 @@ export async function buildFunctions({
44
48
  | "watch"
45
49
  | "plugin"
46
50
  | "buildOutputDirectory"
47
- | "nodeCompat"
48
51
  >
49
52
  > & {
50
53
  functionsDirectory: string;
51
54
  onEnd?: () => void;
52
- outfile: Required<PagesBuildArgs>["outfile"];
53
55
  routesOutputPath?: PagesBuildArgs["outputRoutesPath"];
54
56
  local: boolean;
55
57
  d1Databases?: string[];
56
- experimentalWorkerBundle?: boolean;
58
+ legacyNodeCompat?: boolean;
59
+ nodejsCompat?: boolean;
57
60
  }) {
58
61
  RUNNING_BUILDERS.forEach(
59
62
  (runningBuilder) => runningBuilder.stop && runningBuilder.stop()
@@ -95,22 +98,29 @@ export async function buildFunctions({
95
98
  let bundle: BundleResult;
96
99
 
97
100
  if (plugin) {
101
+ if (outdir === undefined) {
102
+ throw new FatalError(
103
+ "Must specify an output directory when building a Plugin.",
104
+ 1
105
+ );
106
+ }
107
+
98
108
  bundle = await buildPlugin({
99
109
  routesModule,
100
- outfile,
110
+ outdir,
101
111
  minify,
102
112
  sourcemap,
103
113
  watch,
104
- nodeCompat,
114
+ legacyNodeCompat,
105
115
  functionsDirectory: absoluteFunctionsDirectory,
106
116
  local,
107
117
  betaD1Shims: d1Databases,
108
- onEnd,
109
118
  });
110
119
  } else {
111
120
  bundle = await buildWorker({
112
121
  routesModule,
113
122
  outfile,
123
+ outdir,
114
124
  minify,
115
125
  sourcemap,
116
126
  fallbackService,
@@ -120,8 +130,8 @@ export async function buildFunctions({
120
130
  betaD1Shims: d1Databases,
121
131
  onEnd,
122
132
  buildOutputDirectory,
123
- nodeCompat,
124
- experimentalWorkerBundle,
133
+ legacyNodeCompat,
134
+ nodejsCompat,
125
135
  });
126
136
  }
127
137
 
@@ -1,12 +1,13 @@
1
- import { render } from "ink";
2
1
  import Table from "ink-table";
3
2
  import React from "react";
4
3
  import { format as timeagoFormat } from "timeago.js";
5
4
  import { fetchResult } from "../cfetch";
6
5
  import { getConfigCache, saveToConfigCache } from "../config-cache";
7
6
  import { FatalError } from "../errors";
7
+ import { logger } from "../logger";
8
8
  import * as metrics from "../metrics";
9
9
  import { requireAuth } from "../user";
10
+ import { renderToString } from "../utils/render";
10
11
  import { PAGES_CONFIG_CACHE_FILENAME } from "./constants";
11
12
  import { promptSelectProject } from "./prompt-select-project";
12
13
  import { pagesBetaWarning } from "./utils";
@@ -78,9 +79,6 @@ export async function ListHandler({ projectName }: ListArgs) {
78
79
  account_id: accountId,
79
80
  });
80
81
 
81
- const { unmount } = render(<Table data={data}></Table>, {
82
- patchConsole: false,
83
- });
84
- unmount();
82
+ logger.log(renderToString(<Table data={data}></Table>));
85
83
  await metrics.sendMetricsEvent("list pages deployments");
86
84
  }