wrangler 0.0.0-e6e1daba → 0.0.0-e7cf0caa
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.
- package/bin/wrangler.js +1 -1
- package/miniflare-dist/index.mjs +1 -1
- package/package.json +14 -9
- package/src/__tests__/api-devregistry.test.ts +121 -0
- package/src/__tests__/api.test.ts +27 -5
- package/src/__tests__/configuration.test.ts +294 -18
- package/src/__tests__/d1/execute.test.ts +3 -1
- package/src/__tests__/d1/migrate.test.ts +2 -0
- package/src/__tests__/delete.test.ts +6 -0
- package/src/__tests__/deployments.test.ts +335 -95
- package/src/__tests__/dev.test.tsx +87 -57
- package/src/__tests__/generate.test.ts +3 -4
- package/src/__tests__/helpers/mock-console.ts +6 -0
- package/src/__tests__/helpers/msw/handlers/deployments.ts +70 -3
- package/src/__tests__/helpers/msw/index.ts +4 -2
- package/src/__tests__/helpers/worker-scripts/parent-worker.js +4 -1
- package/src/__tests__/index.test.ts +10 -4
- package/src/__tests__/init.test.ts +136 -104
- package/src/__tests__/jest.setup.ts +4 -0
- package/src/__tests__/kv.test.ts +9 -9
- package/src/__tests__/logger.test.ts +68 -2
- package/src/__tests__/middleware.scheduled.test.ts +2 -2
- package/src/__tests__/middleware.test.ts +4 -3
- package/src/__tests__/mtls-certificates.test.ts +5 -2
- package/src/__tests__/pages/deployment-list.test.ts +2 -0
- package/src/__tests__/pages/functions-build.test.ts +91 -41
- package/src/__tests__/pages/project-list.test.ts +2 -0
- package/src/__tests__/pages/project-upload.test.ts +43 -24
- package/src/__tests__/pages/publish.test.ts +267 -148
- package/src/__tests__/publish.test.ts +420 -164
- package/src/__tests__/pubsub.test.ts +3 -0
- package/src/__tests__/queues.test.ts +5 -2
- package/src/__tests__/test-old-node-version.js +3 -3
- package/src/__tests__/traverse-module-graph.test.ts +220 -0
- package/src/__tests__/tsconfig.tsbuildinfo +1 -1
- package/src/__tests__/type-generation.test.ts +1 -0
- package/src/__tests__/user.test.ts +1 -1
- package/src/__tests__/worker-namespace.test.ts +1 -0
- package/src/api/dev.ts +10 -22
- package/src/api/pages/create-worker-bundle-contents.ts +1 -0
- package/src/api/pages/publish.tsx +38 -51
- package/src/bundle.ts +44 -13
- package/src/config/environment.ts +36 -4
- package/src/config/index.ts +30 -2
- package/src/config/validation-helpers.ts +1 -1
- package/src/config/validation.ts +149 -5
- package/src/create-worker-upload-form.ts +28 -3
- package/src/d1/backups.tsx +15 -11
- package/src/d1/create.tsx +20 -16
- package/src/d1/execute.tsx +22 -19
- package/src/d1/list.tsx +2 -2
- package/src/d1/migrations/apply.tsx +35 -29
- package/src/d1/migrations/create.tsx +15 -12
- package/src/d1/migrations/list.tsx +10 -7
- package/src/deployments.ts +260 -8
- package/src/dev/dev.tsx +4 -4
- package/src/dev/local.tsx +14 -16
- package/src/dev/start-server.ts +12 -16
- package/src/dev/use-esbuild.ts +11 -13
- package/src/dev/validate-dev-props.ts +9 -0
- package/src/dev-registry.ts +2 -1
- package/src/dev.tsx +28 -13
- package/src/entry.ts +18 -8
- package/src/generate/index.ts +2 -2
- package/src/index.ts +76 -23
- package/src/init.ts +144 -134
- package/src/logger.ts +18 -3
- package/src/metrics/send-event.ts +2 -1
- package/src/miniflare-cli/index.ts +1 -1
- package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -1
- package/src/module-collection.ts +91 -25
- package/src/pages/build.ts +277 -99
- package/src/pages/buildFunctions.ts +20 -10
- package/src/pages/deployments.tsx +3 -5
- package/src/pages/dev.ts +21 -21
- package/src/pages/errors.ts +1 -0
- package/src/pages/functions/buildPlugin.ts +57 -34
- package/src/pages/functions/buildWorker.ts +34 -31
- package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
- package/src/pages/projects.tsx +2 -5
- package/src/pages/publish.tsx +1 -10
- package/src/pages/upload.tsx +29 -9
- package/src/paths.ts +1 -1
- package/src/publish/index.ts +1 -1
- package/src/publish/publish.ts +29 -34
- package/src/queues/cli/commands/consumer/add.ts +6 -0
- package/src/queues/client.ts +1 -0
- package/src/secret/index.ts +2 -1
- package/src/traverse-module-graph.ts +53 -0
- package/src/type-generation.ts +1 -1
- package/src/user/user.ts +1 -1
- package/src/utils/render.ts +93 -0
- package/src/worker.ts +18 -1
- package/templates/d1-beta-facade.js +5 -2
- package/templates/gitignore +1 -0
- package/templates/middleware/middleware-miniflare3-json-error.ts +17 -5
- package/templates/tsconfig.init.json +1 -2
- package/templates/tsconfig.tsbuildinfo +1 -1
- package/wrangler-dist/cli.d.ts +33 -13
- package/wrangler-dist/cli.js +20732 -19984
- package/src/__tests__/api-devregistry.test.js +0 -64
package/src/pages/build.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { existsSync, writeFileSync } from "node:fs";
|
|
2
|
-
import {
|
|
3
|
-
import { basename, dirname, join, resolve as resolvePath } from "node:path";
|
|
1
|
+
import { existsSync, 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,6 +7,7 @@ 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,
|
|
@@ -32,9 +32,12 @@ export function Options(yargs: CommonYargsArgv) {
|
|
|
32
32
|
.options({
|
|
33
33
|
outfile: {
|
|
34
34
|
type: "string",
|
|
35
|
-
default: "_worker.js",
|
|
36
35
|
description: "The location of the output Worker script",
|
|
37
36
|
},
|
|
37
|
+
outdir: {
|
|
38
|
+
type: "string",
|
|
39
|
+
description: "Output directory for the bundled Worker",
|
|
40
|
+
},
|
|
38
41
|
"output-config-path": {
|
|
39
42
|
type: "string",
|
|
40
43
|
description: "The location for the output config file",
|
|
@@ -75,11 +78,23 @@ export function Options(yargs: CommonYargsArgv) {
|
|
|
75
78
|
description: "The directory to output static assets to",
|
|
76
79
|
},
|
|
77
80
|
"node-compat": {
|
|
78
|
-
describe: "Enable
|
|
81
|
+
describe: "Enable Node.js compatibility",
|
|
79
82
|
default: false,
|
|
80
83
|
type: "boolean",
|
|
81
84
|
hidden: true,
|
|
82
85
|
},
|
|
86
|
+
"compatibility-date": {
|
|
87
|
+
describe: "Date to use for compatibility checks",
|
|
88
|
+
type: "string",
|
|
89
|
+
requiresArg: true,
|
|
90
|
+
},
|
|
91
|
+
"compatibility-flags": {
|
|
92
|
+
describe: "Flags to use for compatibility checks",
|
|
93
|
+
alias: "compatibility-flag",
|
|
94
|
+
type: "string",
|
|
95
|
+
requiresArg: true,
|
|
96
|
+
array: true,
|
|
97
|
+
},
|
|
83
98
|
bindings: {
|
|
84
99
|
type: "string",
|
|
85
100
|
describe:
|
|
@@ -87,97 +102,36 @@ export function Options(yargs: CommonYargsArgv) {
|
|
|
87
102
|
deprecated: true,
|
|
88
103
|
hidden: true,
|
|
89
104
|
},
|
|
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
105
|
})
|
|
98
106
|
.epilogue(pagesBetaWarning);
|
|
99
107
|
}
|
|
100
108
|
|
|
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) => {
|
|
109
|
+
export const Handler = async (args: PagesBuildArgs) => {
|
|
116
110
|
if (!isInPagesCI) {
|
|
117
111
|
// Beta message for `wrangler pages <commands>` usage
|
|
118
112
|
logger.log(pagesBetaWarning);
|
|
119
113
|
}
|
|
120
114
|
|
|
121
|
-
|
|
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
|
-
}
|
|
126
|
-
|
|
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);
|
|
115
|
+
const validatedArgs = validateArgs(args);
|
|
138
116
|
|
|
139
|
-
const workerScriptPath = resolvePath(buildOutputDirectory, "_worker.js");
|
|
140
|
-
const foundWorkerScript = existsSync(workerScriptPath);
|
|
141
117
|
let bundle: BundleResult | undefined = undefined;
|
|
142
118
|
|
|
143
|
-
if (
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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;
|
|
119
|
+
if (validatedArgs.plugin) {
|
|
120
|
+
const {
|
|
121
|
+
directory,
|
|
122
|
+
outfile,
|
|
123
|
+
outdir,
|
|
124
|
+
outputConfigPath,
|
|
125
|
+
outputRoutesPath: routesOutputPath,
|
|
126
|
+
minify,
|
|
127
|
+
sourcemap,
|
|
128
|
+
fallbackService,
|
|
129
|
+
watch,
|
|
130
|
+
plugin,
|
|
131
|
+
nodejsCompat,
|
|
132
|
+
legacyNodeCompat,
|
|
133
|
+
} = validatedArgs;
|
|
168
134
|
|
|
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
135
|
try {
|
|
182
136
|
/**
|
|
183
137
|
* `buildFunctions` builds `/functions`, but doesn't give us the bundle
|
|
@@ -185,12 +139,9 @@ We first looked inside the build output directory (${basename(
|
|
|
185
139
|
* binary, text). Let's output that build result to memory and only write
|
|
186
140
|
* to disk once we have the final bundle
|
|
187
141
|
*/
|
|
188
|
-
const functionsOutfile = experimentalWorkerBundle
|
|
189
|
-
? join(tmpdir(), `./functionsWorker-${Math.random()}.js`)
|
|
190
|
-
: outfile;
|
|
191
|
-
|
|
192
142
|
bundle = await buildFunctions({
|
|
193
|
-
outfile
|
|
143
|
+
outfile,
|
|
144
|
+
outdir,
|
|
194
145
|
outputConfigPath,
|
|
195
146
|
functionsDirectory: directory,
|
|
196
147
|
minify,
|
|
@@ -198,12 +149,10 @@ We first looked inside the build output directory (${basename(
|
|
|
198
149
|
fallbackService,
|
|
199
150
|
watch,
|
|
200
151
|
plugin,
|
|
201
|
-
|
|
202
|
-
|
|
152
|
+
legacyNodeCompat,
|
|
153
|
+
nodejsCompat,
|
|
203
154
|
routesOutputPath,
|
|
204
155
|
local: false,
|
|
205
|
-
d1Databases,
|
|
206
|
-
experimentalWorkerBundle,
|
|
207
156
|
});
|
|
208
157
|
} catch (e) {
|
|
209
158
|
if (e instanceof FunctionsNoRoutesError) {
|
|
@@ -215,18 +164,247 @@ We first looked inside the build output directory (${basename(
|
|
|
215
164
|
throw e;
|
|
216
165
|
}
|
|
217
166
|
}
|
|
167
|
+
|
|
168
|
+
if (outfile && outfile !== bundle.resolvedEntryPointPath) {
|
|
169
|
+
writeFileSync(
|
|
170
|
+
outfile,
|
|
171
|
+
`export { default } from './${relative(
|
|
172
|
+
dirname(outfile),
|
|
173
|
+
bundle.resolvedEntryPointPath
|
|
174
|
+
)}'`
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
} else {
|
|
178
|
+
const {
|
|
179
|
+
directory,
|
|
180
|
+
outfile,
|
|
181
|
+
outdir,
|
|
182
|
+
outputConfigPath,
|
|
183
|
+
outputRoutesPath: routesOutputPath,
|
|
184
|
+
minify,
|
|
185
|
+
sourcemap,
|
|
186
|
+
fallbackService,
|
|
187
|
+
watch,
|
|
188
|
+
plugin,
|
|
189
|
+
buildOutputDirectory,
|
|
190
|
+
nodejsCompat,
|
|
191
|
+
legacyNodeCompat,
|
|
192
|
+
bindings,
|
|
193
|
+
workerScriptPath,
|
|
194
|
+
} = validatedArgs;
|
|
195
|
+
|
|
196
|
+
let d1Databases: string[] | undefined = undefined;
|
|
197
|
+
if (bindings) {
|
|
198
|
+
try {
|
|
199
|
+
const decodedBindings = JSON.parse(bindings);
|
|
200
|
+
d1Databases = Object.keys(decodedBindings?.d1_databases || {});
|
|
201
|
+
} catch {
|
|
202
|
+
throw new FatalError("Could not parse a valid set of 'bindings'.", 1);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* prioritize building `_worker.js` over Pages Functions, if both exist
|
|
208
|
+
* and if we were able to resolve _worker.js
|
|
209
|
+
*/
|
|
210
|
+
if (workerScriptPath) {
|
|
211
|
+
/**
|
|
212
|
+
* `buildRawWorker` builds `_worker.js`, but doesn't give us the bundle
|
|
213
|
+
* we want to return, which includes the external dependencies (like wasm,
|
|
214
|
+
* binary, text). Let's output that build result to memory and only write
|
|
215
|
+
* to disk once we have the final bundle
|
|
216
|
+
*/
|
|
217
|
+
bundle = await buildRawWorker({
|
|
218
|
+
workerScriptPath,
|
|
219
|
+
outdir,
|
|
220
|
+
directory: buildOutputDirectory,
|
|
221
|
+
local: false,
|
|
222
|
+
sourcemap,
|
|
223
|
+
watch,
|
|
224
|
+
betaD1Shims: d1Databases,
|
|
225
|
+
});
|
|
226
|
+
} else {
|
|
227
|
+
try {
|
|
228
|
+
/**
|
|
229
|
+
* `buildFunctions` builds `/functions`, but doesn't give us the bundle
|
|
230
|
+
* we want to return, which includes the external dependencies (like wasm,
|
|
231
|
+
* binary, text). Let's output that build result to memory and only write
|
|
232
|
+
* to disk once we have the final bundle
|
|
233
|
+
*/
|
|
234
|
+
bundle = await buildFunctions({
|
|
235
|
+
outdir,
|
|
236
|
+
outputConfigPath,
|
|
237
|
+
functionsDirectory: directory,
|
|
238
|
+
minify,
|
|
239
|
+
sourcemap,
|
|
240
|
+
fallbackService,
|
|
241
|
+
watch,
|
|
242
|
+
plugin,
|
|
243
|
+
buildOutputDirectory,
|
|
244
|
+
legacyNodeCompat,
|
|
245
|
+
nodejsCompat,
|
|
246
|
+
routesOutputPath,
|
|
247
|
+
local: false,
|
|
248
|
+
d1Databases,
|
|
249
|
+
});
|
|
250
|
+
} catch (e) {
|
|
251
|
+
if (e instanceof FunctionsNoRoutesError) {
|
|
252
|
+
throw new FatalError(
|
|
253
|
+
getFunctionsNoRoutesWarning(directory),
|
|
254
|
+
EXIT_CODE_FUNCTIONS_NO_ROUTES_ERROR
|
|
255
|
+
);
|
|
256
|
+
} else {
|
|
257
|
+
throw e;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (outfile) {
|
|
263
|
+
const workerBundleContents = await createUploadWorkerBundleContents(
|
|
264
|
+
bundle as BundleResult
|
|
265
|
+
);
|
|
266
|
+
|
|
267
|
+
mkdirSync(dirname(outfile), { recursive: true });
|
|
268
|
+
writeFileSync(
|
|
269
|
+
outfile,
|
|
270
|
+
Buffer.from(await workerBundleContents.arrayBuffer())
|
|
271
|
+
);
|
|
272
|
+
}
|
|
218
273
|
}
|
|
219
274
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
275
|
+
await metrics.sendMetricsEvent("build pages functions");
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
type WorkerBundleArgs = Omit<PagesBuildArgs, "nodeCompat"> & {
|
|
279
|
+
plugin: false;
|
|
280
|
+
buildOutputDirectory: string;
|
|
281
|
+
legacyNodeCompat: boolean;
|
|
282
|
+
nodejsCompat: boolean;
|
|
283
|
+
|
|
284
|
+
workerScriptPath: string;
|
|
285
|
+
};
|
|
286
|
+
type PluginArgs = Omit<
|
|
287
|
+
PagesBuildArgs,
|
|
288
|
+
"buildOutputDirectory" | "bindings" | "nodeCompat"
|
|
289
|
+
> & {
|
|
290
|
+
plugin: true;
|
|
291
|
+
outdir: string;
|
|
292
|
+
legacyNodeCompat: boolean;
|
|
293
|
+
nodejsCompat: boolean;
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
type ValidatedArgs = WorkerBundleArgs | PluginArgs;
|
|
297
|
+
|
|
298
|
+
const validateArgs = (args: PagesBuildArgs): ValidatedArgs => {
|
|
299
|
+
if (args.outdir && args.outfile) {
|
|
300
|
+
throw new FatalError(
|
|
301
|
+
"Cannot specify both an `--outdir` and an `--outfile`.",
|
|
302
|
+
1
|
|
223
303
|
);
|
|
304
|
+
}
|
|
224
305
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
306
|
+
if (args.plugin) {
|
|
307
|
+
if (args.outfile) {
|
|
308
|
+
// Explicit old behavior. Encourage to migrate to `--outdir` instead.
|
|
309
|
+
logger.warn(
|
|
310
|
+
"Creating a Pages Plugin with `--outfile` is now deprecated. Please use `--outdir` instead."
|
|
311
|
+
);
|
|
312
|
+
|
|
313
|
+
args.outdir = dirname(resolvePath(args.outfile));
|
|
314
|
+
} else if (!args.outfile && !args.outdir) {
|
|
315
|
+
// Didn't specify `--outfile`, but didn't specify `--outdir` either. Implicit old behavior defaults. Encourage to migrate to `--outdir`.
|
|
316
|
+
args.outfile ??= "_worker.js";
|
|
317
|
+
args.outdir = ".";
|
|
318
|
+
|
|
319
|
+
logger.warn(
|
|
320
|
+
"Creating a Pages Plugin without `--outdir` is now deprecated. Please add an `--outdir` argument."
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
if (args.bindings) {
|
|
325
|
+
throw new FatalError(
|
|
326
|
+
"The `--bindings` flag cannot be used when creating a Pages Plugin with `--plugin`.",
|
|
327
|
+
1
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
if (args.buildOutputDirectory) {
|
|
332
|
+
throw new FatalError(
|
|
333
|
+
"The `--build-output-directory` flag cannot be used when creating a Pages Plugin with `--plugin`.",
|
|
334
|
+
1
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
} else {
|
|
338
|
+
if (!args.outdir) {
|
|
339
|
+
args.outfile ??= "_worker.bundle";
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
args.buildOutputDirectory ??= args.outfile ? dirname(args.outfile) : ".";
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
if (args.buildOutputDirectory) {
|
|
346
|
+
args.buildOutputDirectory = resolvePath(args.buildOutputDirectory);
|
|
347
|
+
}
|
|
348
|
+
if (args.outdir) {
|
|
349
|
+
args.outdir = resolvePath(args.outdir);
|
|
350
|
+
}
|
|
351
|
+
if (args.outfile) {
|
|
352
|
+
args.outfile = resolvePath(args.outfile);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
const { nodeCompat: legacyNodeCompat, ...argsExceptNodeCompat } = args;
|
|
356
|
+
if (legacyNodeCompat) {
|
|
357
|
+
console.warn(
|
|
358
|
+
"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."
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
const nodejsCompat = !!args.compatibilityFlags?.includes("nodejs_compat");
|
|
362
|
+
if (legacyNodeCompat && nodejsCompat) {
|
|
363
|
+
throw new Error(
|
|
364
|
+
"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
365
|
);
|
|
229
366
|
}
|
|
230
367
|
|
|
231
|
-
|
|
368
|
+
let workerScriptPath: string | undefined;
|
|
369
|
+
|
|
370
|
+
if (args.buildOutputDirectory) {
|
|
371
|
+
const prospectiveWorkerScriptPath = resolvePath(
|
|
372
|
+
args.buildOutputDirectory,
|
|
373
|
+
"_worker.js"
|
|
374
|
+
);
|
|
375
|
+
|
|
376
|
+
const foundWorkerScript = existsSync(prospectiveWorkerScriptPath);
|
|
377
|
+
|
|
378
|
+
if (foundWorkerScript) {
|
|
379
|
+
workerScriptPath = prospectiveWorkerScriptPath;
|
|
380
|
+
} else if (!foundWorkerScript && !existsSync(args.directory)) {
|
|
381
|
+
throw new FatalError(
|
|
382
|
+
`Could not find anything to build.
|
|
383
|
+
We first looked inside the build output directory (${basename(
|
|
384
|
+
resolvePath(args.buildOutputDirectory)
|
|
385
|
+
)}), then looked for the Functions directory (${basename(
|
|
386
|
+
args.directory
|
|
387
|
+
)}) but couldn't find anything to build.
|
|
388
|
+
➤ If you are trying to build _worker.js, please make sure you provide the [--build-output-directory] containing your static files.
|
|
389
|
+
➤ If you are trying to build Pages Functions, please make sure [directory] points to the location of your Functions files.`,
|
|
390
|
+
EXIT_CODE_FUNCTIONS_NOTHING_TO_BUILD_ERROR
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
} else if (!existsSync(args.directory)) {
|
|
394
|
+
throw new FatalError(
|
|
395
|
+
`Could not find anything to build.
|
|
396
|
+
We looked for the Functions directory (${basename(
|
|
397
|
+
args.directory
|
|
398
|
+
)}) but couldn't find anything to build.
|
|
399
|
+
➤ Please make sure [directory] points to the location of your Functions files.`,
|
|
400
|
+
EXIT_CODE_FUNCTIONS_NOTHING_TO_BUILD_ERROR
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
return {
|
|
405
|
+
...argsExceptNodeCompat,
|
|
406
|
+
workerScriptPath,
|
|
407
|
+
nodejsCompat,
|
|
408
|
+
legacyNodeCompat,
|
|
409
|
+
} as ValidatedArgs;
|
|
232
410
|
};
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
110
|
+
outdir,
|
|
101
111
|
minify,
|
|
102
112
|
sourcemap,
|
|
103
113
|
watch,
|
|
104
|
-
|
|
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
|
-
|
|
124
|
-
|
|
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
|
-
|
|
82
|
-
patchConsole: false,
|
|
83
|
-
});
|
|
84
|
-
unmount();
|
|
82
|
+
logger.log(renderToString(<Table data={data}></Table>));
|
|
85
83
|
await metrics.sendMetricsEvent("list pages deployments");
|
|
86
84
|
}
|
package/src/pages/dev.ts
CHANGED
|
@@ -85,16 +85,9 @@ export function Options(yargs: CommonYargsArgv) {
|
|
|
85
85
|
hidden: true,
|
|
86
86
|
},
|
|
87
87
|
"no-bundle": {
|
|
88
|
-
type: "boolean",
|
|
89
|
-
default: true,
|
|
90
|
-
description: "Whether to run bundling on `_worker.js`",
|
|
91
|
-
},
|
|
92
|
-
"experimental-worker-bundle": {
|
|
93
88
|
type: "boolean",
|
|
94
89
|
default: false,
|
|
95
|
-
|
|
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`",
|
|
90
|
+
description: "Whether to run bundling on `_worker.js`",
|
|
98
91
|
},
|
|
99
92
|
binding: {
|
|
100
93
|
type: "array",
|
|
@@ -147,7 +140,7 @@ export function Options(yargs: CommonYargsArgv) {
|
|
|
147
140
|
requiresArg: true,
|
|
148
141
|
},
|
|
149
142
|
"node-compat": {
|
|
150
|
-
describe: "Enable
|
|
143
|
+
describe: "Enable Node.js compatibility",
|
|
151
144
|
default: false,
|
|
152
145
|
type: "boolean",
|
|
153
146
|
hidden: true,
|
|
@@ -181,7 +174,6 @@ export const Handler = async ({
|
|
|
181
174
|
proxy: requestedProxyPort,
|
|
182
175
|
bundle,
|
|
183
176
|
noBundle,
|
|
184
|
-
experimentalWorkerBundle,
|
|
185
177
|
scriptPath: singleWorkerScriptPath,
|
|
186
178
|
binding: bindings = [],
|
|
187
179
|
kv: kvs = [],
|
|
@@ -193,7 +185,7 @@ export const Handler = async ({
|
|
|
193
185
|
experimentalEnableLocalPersistence,
|
|
194
186
|
persist,
|
|
195
187
|
persistTo,
|
|
196
|
-
nodeCompat,
|
|
188
|
+
nodeCompat: legacyNodeCompat,
|
|
197
189
|
experimentalLocal,
|
|
198
190
|
config: config,
|
|
199
191
|
_: [_pages, _dev, ...remaining],
|
|
@@ -270,6 +262,8 @@ export const Handler = async ({
|
|
|
270
262
|
|
|
271
263
|
let scriptPath = "";
|
|
272
264
|
|
|
265
|
+
const nodejsCompat = compatibilityFlags?.includes("nodejs_compat");
|
|
266
|
+
|
|
273
267
|
if (usingWorkerScript) {
|
|
274
268
|
scriptPath = workerScriptPath;
|
|
275
269
|
let runBuild = async () => {
|
|
@@ -278,7 +272,7 @@ export const Handler = async ({
|
|
|
278
272
|
|
|
279
273
|
// TODO: Here lies a known bug. If you specify both `--bundle` and `--no-bundle`, this behavior is undefined and you will get unexpected results.
|
|
280
274
|
// There is no sane way to get the true value out of yargs, so here we are.
|
|
281
|
-
const enableBundling =
|
|
275
|
+
const enableBundling = bundle ?? !noBundle;
|
|
282
276
|
if (enableBundling) {
|
|
283
277
|
// We want to actually run the `_worker.js` script through the bundler
|
|
284
278
|
// So update the final path to the script that will be uploaded and
|
|
@@ -290,11 +284,11 @@ export const Handler = async ({
|
|
|
290
284
|
workerScriptPath,
|
|
291
285
|
outfile: scriptPath,
|
|
292
286
|
directory: directory ?? ".",
|
|
287
|
+
nodejsCompat,
|
|
293
288
|
local: true,
|
|
294
289
|
sourcemap: true,
|
|
295
290
|
watch: true,
|
|
296
291
|
onEnd: () => scriptReadyResolve(),
|
|
297
|
-
experimentalWorkerBundle,
|
|
298
292
|
});
|
|
299
293
|
} catch (e: unknown) {
|
|
300
294
|
logger.warn("Failed to bundle _worker.js.", e);
|
|
@@ -303,7 +297,7 @@ export const Handler = async ({
|
|
|
303
297
|
}
|
|
304
298
|
|
|
305
299
|
await runBuild();
|
|
306
|
-
watch([
|
|
300
|
+
watch([workerScriptPath], {
|
|
307
301
|
persistent: true,
|
|
308
302
|
ignoreInitial: true,
|
|
309
303
|
}).on("all", async () => {
|
|
@@ -313,9 +307,16 @@ export const Handler = async ({
|
|
|
313
307
|
// Try to use Functions
|
|
314
308
|
scriptPath = join(tmpdir(), `./functionsWorker-${Math.random()}.mjs`);
|
|
315
309
|
|
|
316
|
-
if (
|
|
310
|
+
if (legacyNodeCompat) {
|
|
317
311
|
console.warn(
|
|
318
|
-
"Enabling
|
|
312
|
+
"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."
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
if (legacyNodeCompat && nodejsCompat) {
|
|
317
|
+
throw new FatalError(
|
|
318
|
+
"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.",
|
|
319
|
+
1
|
|
319
320
|
);
|
|
320
321
|
}
|
|
321
322
|
|
|
@@ -330,9 +331,9 @@ export const Handler = async ({
|
|
|
330
331
|
watch: true,
|
|
331
332
|
onEnd,
|
|
332
333
|
buildOutputDirectory: directory,
|
|
333
|
-
|
|
334
|
+
legacyNodeCompat,
|
|
335
|
+
nodejsCompat,
|
|
334
336
|
local: true,
|
|
335
|
-
experimentalWorkerBundle,
|
|
336
337
|
});
|
|
337
338
|
await metrics.sendMetricsEvent("build pages functions");
|
|
338
339
|
};
|
|
@@ -503,7 +504,7 @@ export const Handler = async ({
|
|
|
503
504
|
localProtocol,
|
|
504
505
|
compatibilityDate,
|
|
505
506
|
compatibilityFlags,
|
|
506
|
-
nodeCompat,
|
|
507
|
+
nodeCompat: legacyNodeCompat,
|
|
507
508
|
vars: Object.fromEntries(
|
|
508
509
|
bindings
|
|
509
510
|
.map((binding) => binding.toString().split("="))
|
|
@@ -540,8 +541,7 @@ export const Handler = async ({
|
|
|
540
541
|
persist,
|
|
541
542
|
persistTo,
|
|
542
543
|
inspect: undefined,
|
|
543
|
-
|
|
544
|
-
logLevel: logLevel ?? "warn",
|
|
544
|
+
logLevel,
|
|
545
545
|
experimental: {
|
|
546
546
|
d1Databases: d1s.map((binding) => ({
|
|
547
547
|
binding: binding.toString(),
|