wrangler 0.0.0-e98613f8 → 0.0.0-e9a45766c
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/README.md +10 -4
- package/bin/wrangler.js +10 -2
- package/miniflare-dist/index.mjs +257 -132
- package/package.json +26 -19
- package/src/__tests__/api-dev.test.ts +65 -36
- package/src/__tests__/api-devregistry.test.ts +121 -0
- package/src/__tests__/api.test.ts +27 -5
- package/src/__tests__/configuration.test.ts +575 -39
- package/src/__tests__/constellation.test.ts +371 -0
- package/src/__tests__/d1/d1.test.ts +82 -0
- package/src/__tests__/d1/execute.test.ts +66 -0
- package/src/__tests__/d1/migrate.test.ts +257 -0
- package/src/__tests__/d1/splitter.test.ts +255 -0
- package/src/__tests__/delete.test.ts +11 -2
- package/src/__tests__/deployments.test.ts +330 -52
- package/src/__tests__/dev.test.tsx +146 -82
- package/src/__tests__/generate.test.ts +10 -8
- package/src/__tests__/guess-worker-format.test.ts +35 -0
- package/src/__tests__/helpers/end-event-loop.ts +6 -0
- package/src/__tests__/helpers/mock-auth-domain.ts +20 -0
- package/src/__tests__/helpers/mock-console.ts +6 -0
- package/src/__tests__/helpers/mock-dialogs.ts +71 -85
- package/src/__tests__/helpers/mock-get-pages-upload-token.ts +25 -0
- package/src/__tests__/helpers/mock-get-zone-from-host.ts +8 -5
- package/src/__tests__/helpers/mock-known-routes.ts +7 -2
- package/src/__tests__/helpers/mock-kv.ts +29 -16
- package/src/__tests__/helpers/mock-oauth-flow.ts +99 -92
- package/src/__tests__/helpers/mock-process.ts +8 -13
- package/src/__tests__/helpers/mock-set-timeout.ts +16 -0
- package/src/__tests__/helpers/msw/blob-worker.cjs +19 -0
- package/src/__tests__/helpers/msw/handlers/deployments.ts +127 -26
- package/src/__tests__/helpers/msw/handlers/namespaces.ts +18 -41
- package/src/__tests__/helpers/msw/handlers/r2.ts +14 -34
- package/src/__tests__/helpers/msw/handlers/script.ts +9 -28
- package/src/__tests__/helpers/msw/handlers/user.ts +13 -24
- package/src/__tests__/helpers/msw/handlers/zones.ts +6 -8
- package/src/__tests__/helpers/msw/index.ts +32 -1
- package/src/__tests__/helpers/msw/read-file-sync.js +61 -0
- package/src/__tests__/helpers/string-dynamic-values-matcher.ts +28 -0
- package/src/__tests__/helpers/worker-scripts/parent-worker.js +4 -1
- package/src/__tests__/index.test.ts +92 -74
- package/src/__tests__/init.test.ts +909 -628
- package/src/__tests__/jest.setup.ts +19 -42
- package/src/__tests__/kv.test.ts +355 -231
- package/src/__tests__/logger.test.ts +68 -2
- package/src/__tests__/logout.test.ts +1 -1
- package/src/__tests__/metrics.test.ts +93 -50
- package/src/__tests__/middleware.scheduled.test.ts +42 -32
- package/src/__tests__/middleware.test.ts +212 -122
- package/src/__tests__/mtls-certificates.test.ts +589 -0
- package/src/__tests__/pages/deployment-list.test.ts +80 -0
- package/src/__tests__/pages/functions-build.test.ts +528 -0
- package/src/__tests__/pages/pages.test.ts +81 -0
- package/src/__tests__/pages/project-create.test.ts +63 -0
- package/src/__tests__/pages/project-list.test.ts +110 -0
- package/src/__tests__/pages/project-upload.test.ts +500 -0
- package/src/__tests__/pages/publish.test.ts +2864 -0
- package/src/__tests__/pages-deployment-tail.test.ts +239 -102
- package/src/__tests__/parse.test.ts +106 -0
- package/src/__tests__/publish.test.ts +2218 -1002
- package/src/__tests__/pubsub.test.ts +226 -100
- package/src/__tests__/queues.test.ts +42 -32
- package/src/__tests__/r2.test.ts +37 -56
- package/src/__tests__/secret.test.ts +179 -130
- package/src/__tests__/tail.test.ts +113 -23
- package/src/__tests__/test-old-node-version.js +3 -3
- package/src/__tests__/traverse-module-graph.test.ts +220 -0
- package/src/__tests__/tsconfig-sanity.ts +12 -0
- package/src/__tests__/tsconfig.json +8 -0
- package/src/__tests__/tsconfig.tsbuildinfo +1 -0
- package/src/__tests__/type-generation.test.ts +8 -0
- package/src/__tests__/user.test.ts +7 -18
- package/src/__tests__/whoami.test.tsx +8 -114
- package/src/__tests__/worker-namespace.test.ts +83 -69
- package/src/api/dev.ts +172 -61
- package/src/api/index.ts +10 -1
- package/src/api/mtls-certificate.ts +148 -0
- package/src/api/pages/create-worker-bundle-contents.ts +77 -0
- package/src/api/pages/index.ts +5 -0
- package/src/api/pages/publish.tsx +371 -0
- package/src/bundle.ts +139 -33
- package/src/cfetch/index.ts +0 -2
- package/src/cfetch/internal.ts +16 -21
- package/src/cli.ts +4 -4
- package/src/config/config.ts +14 -7
- package/src/config/environment.ts +80 -16
- package/src/config/index.ts +99 -30
- package/src/config/validation-helpers.ts +1 -1
- package/src/config/validation.ts +275 -9
- package/src/constellation/createProject.tsx +51 -0
- package/src/constellation/deleteProject.ts +51 -0
- package/src/constellation/deleteProjectModel.ts +68 -0
- package/src/constellation/index.ts +75 -0
- package/src/constellation/listCatalog.tsx +35 -0
- package/src/constellation/listModel.tsx +41 -0
- package/src/constellation/listProject.tsx +28 -0
- package/src/constellation/listRuntime.tsx +28 -0
- package/src/constellation/options.ts +17 -0
- package/src/constellation/types.ts +17 -0
- package/src/constellation/uploadModel.tsx +64 -0
- package/src/constellation/utils.ts +90 -0
- package/src/create-worker-preview.ts +19 -8
- package/src/create-worker-upload-form.ts +52 -5
- package/src/d1/backups.tsx +40 -44
- package/src/d1/create.tsx +50 -43
- package/src/d1/{delete.tsx → delete.ts} +8 -11
- package/src/d1/execute.tsx +171 -166
- package/src/d1/index.ts +5 -6
- package/src/d1/list.tsx +27 -13
- package/src/d1/migrations/apply.tsx +92 -64
- package/src/d1/migrations/create.tsx +31 -29
- package/src/d1/migrations/helpers.ts +66 -44
- package/src/d1/migrations/list.tsx +47 -31
- package/src/d1/migrations/options.ts +7 -2
- package/src/d1/options.ts +3 -3
- package/src/d1/splitter.ts +161 -0
- package/src/d1/{types.tsx → types.ts} +1 -0
- package/src/d1/utils.ts +2 -1
- package/src/delete.ts +8 -16
- package/src/deployments.ts +333 -42
- package/src/deprecated/index.ts +8 -302
- package/src/dev/dev.tsx +13 -22
- package/src/dev/local.tsx +131 -69
- package/src/dev/remote.tsx +35 -3
- package/src/dev/start-server.ts +83 -77
- package/src/dev/use-esbuild.ts +63 -52
- package/src/dev/validate-dev-props.ts +9 -0
- package/src/{dev-registry.tsx → dev-registry.ts} +9 -8
- package/src/dev.tsx +131 -110
- package/src/dialogs.ts +136 -0
- package/src/dispatch-namespace.ts +21 -17
- package/src/docs/helpers.ts +50 -0
- package/src/docs/index.ts +54 -0
- package/src/entry.ts +26 -11
- package/src/environment-variables/factory.ts +89 -0
- package/src/environment-variables/misc-variables.ts +30 -0
- package/src/generate/index.ts +298 -0
- package/src/{index.tsx → index.ts} +137 -56
- package/src/init.ts +254 -187
- package/src/inspect.ts +170 -9
- package/src/jest.d.ts +4 -0
- package/src/kv/helpers.ts +7 -4
- package/src/kv/index.ts +15 -17
- package/src/logger.ts +36 -5
- package/src/metrics/metrics-config.ts +1 -1
- package/src/metrics/send-event.ts +4 -1
- package/src/miniflare-cli/assets.ts +66 -31
- package/src/miniflare-cli/index.ts +5 -8
- package/src/miniflare-cli/tsconfig.json +9 -0
- package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -0
- package/src/miniflare-cli/types.ts +11 -0
- package/src/module-collection.ts +92 -26
- package/src/mtls-certificate/cli.ts +155 -0
- package/src/pages/build.ts +423 -0
- package/src/pages/buildFunctions.ts +140 -0
- package/src/pages/{deployment-tails.tsx → deployment-tails.ts} +7 -10
- package/src/pages/deployments.tsx +9 -9
- package/src/pages/{dev.tsx → dev.ts} +167 -139
- package/src/pages/errors.ts +1 -0
- package/src/pages/functions/buildPlugin.ts +61 -54
- package/src/pages/functions/buildWorker.ts +217 -33
- package/src/pages/functions/tsconfig.json +8 -0
- package/src/pages/functions/tsconfig.tsbuildinfo +1 -0
- package/src/pages/{functions.tsx → functions.ts} +8 -4
- package/src/pages/{index.tsx → index.ts} +3 -3
- package/src/pages/projects.tsx +12 -22
- package/src/pages/publish.tsx +43 -227
- package/src/pages/types.ts +5 -0
- package/src/pages/upload.tsx +57 -14
- package/src/pages/utils.ts +1 -1
- package/src/parse.ts +23 -1
- package/src/paths.ts +1 -1
- package/src/publish/index.ts +20 -16
- package/src/publish/publish.ts +76 -46
- package/src/pubsub/{pubsub-commands.tsx → pubsub-commands.ts} +19 -20
- package/src/queues/cli/commands/consumer/add.ts +24 -24
- package/src/queues/cli/commands/consumer/index.ts +3 -6
- package/src/queues/cli/commands/consumer/remove.ts +11 -18
- package/src/queues/cli/commands/create.ts +8 -8
- package/src/queues/cli/commands/delete.ts +8 -8
- package/src/queues/cli/commands/index.ts +3 -4
- package/src/queues/cli/commands/list.ts +8 -8
- package/src/queues/client.ts +1 -0
- package/src/r2/helpers.ts +1 -0
- package/src/r2/index.ts +28 -28
- package/src/secret/index.ts +15 -16
- package/src/{sites.tsx → sites.ts} +165 -53
- package/src/tail/createTail.ts +37 -1
- package/src/tail/filters.ts +1 -1
- package/src/tail/index.ts +8 -11
- package/src/tail/printing.ts +25 -0
- package/src/traverse-module-graph.ts +54 -0
- package/src/tsconfig-sanity.ts +16 -0
- package/src/type-generation.ts +11 -3
- package/src/user/access.ts +0 -1
- package/src/user/auth-variables.ts +113 -0
- package/src/user/choose-account.tsx +1 -31
- package/src/user/index.ts +0 -1
- package/src/user/{user.tsx → user.ts} +114 -77
- package/src/utils/render.ts +93 -0
- package/src/{whoami.tsx → whoami.ts} +37 -71
- package/src/worker.ts +35 -1
- package/src/yargs-types.ts +18 -5
- package/templates/__tests__/tsconfig-sanity.ts +12 -0
- package/templates/__tests__/tsconfig.json +8 -0
- package/templates/__tests__/tsconfig.tsbuildinfo +1 -0
- package/templates/checked-fetch.js +9 -3
- package/templates/d1-beta-facade.js +42 -3
- package/templates/facade.d.ts +14 -0
- package/templates/first-party-worker-module-facade.ts +4 -3
- package/templates/format-dev-errors.ts +8 -6
- package/templates/gitignore +1 -0
- package/templates/init-tests/test-jest-new-worker.js +3 -5
- package/templates/init-tests/test-vitest-new-worker.js +3 -5
- package/templates/init-tests/test-vitest-new-worker.ts +25 -0
- package/templates/middleware/loader-modules.ts +2 -2
- package/templates/middleware/loader-sw.ts +6 -0
- package/templates/middleware/middleware-miniflare3-json-error.ts +17 -5
- package/templates/new-worker.ts +3 -0
- package/templates/pages-dev-pipeline.ts +4 -1
- package/templates/pages-shim.ts +4 -1
- package/templates/pages-template-plugin.ts +19 -10
- package/templates/serve-static-assets.ts +17 -14
- package/templates/service-bindings-module-facade.js +1 -0
- package/templates/tsconfig-sanity.ts +11 -0
- package/templates/tsconfig.init.json +105 -0
- package/templates/tsconfig.json +5 -103
- package/templates/tsconfig.tsbuildinfo +1 -0
- package/wrangler-dist/cli.d.ts +871 -73
- package/wrangler-dist/cli.js +80512 -90686
- package/wrangler-dist/wasm-sync.wasm +0 -0
- package/src/__tests__/api-devregistry.test.js +0 -56
- package/src/__tests__/d1.test.ts +0 -80
- package/src/__tests__/dialogs.test.tsx +0 -40
- package/src/__tests__/helpers/mock-cfetch.ts +0 -333
- package/src/__tests__/pages.test.ts +0 -2442
- package/src/dialogs.tsx +0 -168
- package/src/environment-variables.ts +0 -50
- package/src/pages/build.tsx +0 -270
- package/src/user/env-vars.ts +0 -46
- /package/src/{bundle-reporter.tsx → bundle-reporter.ts} +0 -0
- /package/src/d1/migrations/{index.tsx → index.ts} +0 -0
- /package/src/dev/{get-local-persistence-path.tsx → get-local-persistence-path.ts} +0 -0
- /package/src/pages/{hash.tsx → hash.ts} +0 -0
package/src/pages/publish.tsx
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import { execSync } from "node:child_process";
|
|
2
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
-
import { tmpdir } from "node:os";
|
|
4
|
-
import { dirname, join } from "node:path";
|
|
5
|
-
import { cwd } from "node:process";
|
|
6
2
|
import { render, Text } from "ink";
|
|
7
3
|
import SelectInput from "ink-select-input";
|
|
8
4
|
import React from "react";
|
|
9
|
-
import {
|
|
5
|
+
import { publish } from "../api/pages/publish";
|
|
10
6
|
import { fetchResult } from "../cfetch";
|
|
11
7
|
import { getConfigCache, saveToConfigCache } from "../config-cache";
|
|
12
8
|
import { prompt } from "../dialogs";
|
|
@@ -14,22 +10,20 @@ import { FatalError } from "../errors";
|
|
|
14
10
|
import { logger } from "../logger";
|
|
15
11
|
import * as metrics from "../metrics";
|
|
16
12
|
import { requireAuth } from "../user";
|
|
17
|
-
import { buildFunctions } from "./build";
|
|
18
13
|
import { PAGES_CONFIG_CACHE_FILENAME } from "./constants";
|
|
19
|
-
import { FunctionsNoRoutesError, getFunctionsNoRoutesWarning } from "./errors";
|
|
20
|
-
import { validateRoutes } from "./functions/routes-validation";
|
|
21
14
|
import { listProjects } from "./projects";
|
|
22
15
|
import { promptSelectProject } from "./prompt-select-project";
|
|
23
|
-
import { upload } from "./upload";
|
|
24
16
|
import { pagesBetaWarning } from "./utils";
|
|
25
|
-
import type {
|
|
17
|
+
import type {
|
|
18
|
+
CommonYargsArgv,
|
|
19
|
+
StrictYargsOptionsToInterface,
|
|
20
|
+
} from "../yargs-types";
|
|
26
21
|
import type { PagesConfigCache } from "./types";
|
|
27
|
-
import type { Project
|
|
28
|
-
import type { Argv } from "yargs";
|
|
22
|
+
import type { Project } from "@cloudflare/types";
|
|
29
23
|
|
|
30
|
-
type PublishArgs =
|
|
24
|
+
type PublishArgs = StrictYargsOptionsToInterface<typeof Options>;
|
|
31
25
|
|
|
32
|
-
export function Options(yargs:
|
|
26
|
+
export function Options(yargs: CommonYargsArgv) {
|
|
33
27
|
return yargs
|
|
34
28
|
.positional("directory", {
|
|
35
29
|
type: "string",
|
|
@@ -58,6 +52,20 @@ export function Options(yargs: Argv) {
|
|
|
58
52
|
description:
|
|
59
53
|
"Whether or not the workspace should be considered dirty for this deployment",
|
|
60
54
|
},
|
|
55
|
+
"skip-caching": {
|
|
56
|
+
type: "boolean",
|
|
57
|
+
description: "Skip asset caching which speeds up builds",
|
|
58
|
+
},
|
|
59
|
+
bundle: {
|
|
60
|
+
type: "boolean",
|
|
61
|
+
default: undefined,
|
|
62
|
+
hidden: true,
|
|
63
|
+
},
|
|
64
|
+
"no-bundle": {
|
|
65
|
+
type: "boolean",
|
|
66
|
+
default: false,
|
|
67
|
+
description: "Whether to run bundling on `_worker.js` before deploying",
|
|
68
|
+
},
|
|
61
69
|
config: {
|
|
62
70
|
describe: "Pages does not support wrangler.toml",
|
|
63
71
|
type: "string",
|
|
@@ -74,6 +82,9 @@ export const Handler = async ({
|
|
|
74
82
|
commitHash,
|
|
75
83
|
commitMessage,
|
|
76
84
|
commitDirty,
|
|
85
|
+
skipCaching,
|
|
86
|
+
bundle,
|
|
87
|
+
noBundle,
|
|
77
88
|
config: wranglerConfig,
|
|
78
89
|
}: PublishArgs) => {
|
|
79
90
|
if (wranglerConfig) {
|
|
@@ -151,10 +162,11 @@ export const Handler = async ({
|
|
|
151
162
|
|
|
152
163
|
const productionBranch = await prompt(
|
|
153
164
|
"Enter the production branch name:",
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
165
|
+
{
|
|
166
|
+
defaultValue: isGitDir
|
|
167
|
+
? execSync(`git rev-parse --abbrev-ref HEAD`).toString().trim()
|
|
168
|
+
: "production",
|
|
169
|
+
}
|
|
158
170
|
);
|
|
159
171
|
|
|
160
172
|
if (!productionBranch) {
|
|
@@ -229,215 +241,19 @@ export const Handler = async ({
|
|
|
229
241
|
}
|
|
230
242
|
}
|
|
231
243
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
try {
|
|
247
|
-
/**
|
|
248
|
-
* Developers can specify a custom _routes.json file, for projects with Pages
|
|
249
|
-
* Functions or projects in Advanced Mode
|
|
250
|
-
*/
|
|
251
|
-
_routesCustom = readFileSync(join(directory, "_routes.json"), "utf-8");
|
|
252
|
-
} catch {}
|
|
253
|
-
|
|
254
|
-
try {
|
|
255
|
-
_workerJS = readFileSync(join(directory, "_worker.js"), "utf-8");
|
|
256
|
-
} catch {}
|
|
257
|
-
|
|
258
|
-
// Grab the bindings from the API, we need these for shims and other such hacky inserts
|
|
259
|
-
const project = await fetchResult<Project>(
|
|
260
|
-
`/accounts/${accountId}/pages/projects/${projectName}`
|
|
261
|
-
);
|
|
262
|
-
let isProduction = true;
|
|
263
|
-
if (branch) {
|
|
264
|
-
isProduction = project.production_branch === branch;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* Evaluate if this is an Advanced Mode or Pages Functions project. If Advanced Mode, we'll
|
|
269
|
-
* go ahead and upload `_worker.js` as is, but if Pages Functions, we need to attempt to build
|
|
270
|
-
* Functions first and exit if it failed
|
|
271
|
-
*/
|
|
272
|
-
let builtFunctions: string | undefined = undefined;
|
|
273
|
-
const functionsDirectory = join(cwd(), "functions");
|
|
274
|
-
const routesOutputPath = !existsSync(join(directory, "_routes.json"))
|
|
275
|
-
? join(tmpdir(), `_routes-${Math.random()}.json`)
|
|
276
|
-
: undefined;
|
|
277
|
-
|
|
278
|
-
// Routing configuration displayed in the Functions tab of a deployment in Dash
|
|
279
|
-
let filepathRoutingConfig: string | undefined;
|
|
280
|
-
|
|
281
|
-
if (!_workerJS && existsSync(functionsDirectory)) {
|
|
282
|
-
const outfile = join(tmpdir(), `./functionsWorker-${Math.random()}.js`);
|
|
283
|
-
const outputConfigPath = join(
|
|
284
|
-
tmpdir(),
|
|
285
|
-
`functions-filepath-routing-config-${Math.random()}.json`
|
|
286
|
-
);
|
|
287
|
-
|
|
288
|
-
try {
|
|
289
|
-
await buildFunctions({
|
|
290
|
-
outfile,
|
|
291
|
-
outputConfigPath,
|
|
292
|
-
functionsDirectory,
|
|
293
|
-
onEnd: () => {},
|
|
294
|
-
buildOutputDirectory: dirname(outfile),
|
|
295
|
-
routesOutputPath,
|
|
296
|
-
local: false,
|
|
297
|
-
d1Databases: Object.keys(
|
|
298
|
-
project.deployment_configs[isProduction ? "production" : "preview"]
|
|
299
|
-
.d1_databases ?? {}
|
|
300
|
-
),
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
builtFunctions = readFileSync(outfile, "utf-8");
|
|
304
|
-
filepathRoutingConfig = readFileSync(outputConfigPath, "utf-8");
|
|
305
|
-
} catch (e) {
|
|
306
|
-
if (e instanceof FunctionsNoRoutesError) {
|
|
307
|
-
logger.warn(
|
|
308
|
-
getFunctionsNoRoutesWarning(functionsDirectory, "skipping")
|
|
309
|
-
);
|
|
310
|
-
} else {
|
|
311
|
-
throw e;
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
const manifest = await upload({ directory, accountId, projectName });
|
|
317
|
-
|
|
318
|
-
const formData = new FormData();
|
|
319
|
-
|
|
320
|
-
formData.append("manifest", JSON.stringify(manifest));
|
|
321
|
-
|
|
322
|
-
if (branch) {
|
|
323
|
-
formData.append("branch", branch);
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
if (commitMessage) {
|
|
327
|
-
formData.append("commit_message", commitMessage);
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
if (commitHash) {
|
|
331
|
-
formData.append("commit_hash", commitHash);
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
if (commitDirty !== undefined) {
|
|
335
|
-
formData.append("commit_dirty", commitDirty);
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
if (_headers) {
|
|
339
|
-
formData.append("_headers", new File([_headers], "_headers"));
|
|
340
|
-
logger.log(`✨ Uploading _headers`);
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
if (_redirects) {
|
|
344
|
-
formData.append("_redirects", new File([_redirects], "_redirects"));
|
|
345
|
-
logger.log(`✨ Uploading _redirects`);
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
if (filepathRoutingConfig) {
|
|
349
|
-
formData.append(
|
|
350
|
-
"functions-filepath-routing-config.json",
|
|
351
|
-
new File(
|
|
352
|
-
[filepathRoutingConfig],
|
|
353
|
-
"functions-filepath-routing-config.json"
|
|
354
|
-
)
|
|
355
|
-
);
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
/**
|
|
359
|
-
* Advanced Mode
|
|
360
|
-
* https://developers.cloudflare.com/pages/platform/functions/#advanced-mode
|
|
361
|
-
*
|
|
362
|
-
* When using a _worker.js file, the entire /functions directory is ignored
|
|
363
|
-
* – this includes its routing and middleware characteristics.
|
|
364
|
-
*/
|
|
365
|
-
if (_workerJS) {
|
|
366
|
-
formData.append("_worker.js", new File([_workerJS], "_worker.js"));
|
|
367
|
-
logger.log(`✨ Uploading _worker.js`);
|
|
368
|
-
|
|
369
|
-
if (_routesCustom) {
|
|
370
|
-
// user provided a custom _routes.json file
|
|
371
|
-
try {
|
|
372
|
-
const routesCustomJSON = JSON.parse(_routesCustom);
|
|
373
|
-
validateRoutes(routesCustomJSON, join(directory, "_routes.json"));
|
|
374
|
-
|
|
375
|
-
formData.append(
|
|
376
|
-
"_routes.json",
|
|
377
|
-
new File([_routesCustom], "_routes.json")
|
|
378
|
-
);
|
|
379
|
-
logger.log(`✨ Uploading _routes.json`);
|
|
380
|
-
logger.warn(
|
|
381
|
-
`_routes.json is an experimental feature and is subject to change. Please use with care.`
|
|
382
|
-
);
|
|
383
|
-
} catch (err) {
|
|
384
|
-
if (err instanceof FatalError) {
|
|
385
|
-
throw err;
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
/**
|
|
392
|
-
* Pages Functions
|
|
393
|
-
* https://developers.cloudflare.com/pages/platform/functions/
|
|
394
|
-
*/
|
|
395
|
-
if (builtFunctions && !_workerJS) {
|
|
396
|
-
// if Functions were build successfully, proceed to uploading the build file
|
|
397
|
-
formData.append("_worker.js", new File([builtFunctions], "_worker.js"));
|
|
398
|
-
logger.log(`✨ Uploading Functions`);
|
|
399
|
-
|
|
400
|
-
if (_routesCustom) {
|
|
401
|
-
// user provided a custom _routes.json file
|
|
402
|
-
try {
|
|
403
|
-
const routesCustomJSON = JSON.parse(_routesCustom);
|
|
404
|
-
validateRoutes(routesCustomJSON, join(directory, "_routes.json"));
|
|
405
|
-
|
|
406
|
-
formData.append(
|
|
407
|
-
"_routes.json",
|
|
408
|
-
new File([_routesCustom], "_routes.json")
|
|
409
|
-
);
|
|
410
|
-
logger.log(`✨ Uploading _routes.json`);
|
|
411
|
-
logger.warn(
|
|
412
|
-
`_routes.json is an experimental feature and is subject to change. Please use with care.`
|
|
413
|
-
);
|
|
414
|
-
} catch (err) {
|
|
415
|
-
if (err instanceof FatalError) {
|
|
416
|
-
throw err;
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
} else if (routesOutputPath) {
|
|
420
|
-
// no custom _routes.json file found, so fallback to the generated one
|
|
421
|
-
try {
|
|
422
|
-
_routesGenerated = readFileSync(routesOutputPath, "utf-8");
|
|
423
|
-
|
|
424
|
-
if (_routesGenerated) {
|
|
425
|
-
formData.append(
|
|
426
|
-
"_routes.json",
|
|
427
|
-
new File([_routesGenerated], "_routes.json")
|
|
428
|
-
);
|
|
429
|
-
}
|
|
430
|
-
} catch {}
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
const deploymentResponse = await fetchResult<Deployment>(
|
|
435
|
-
`/accounts/${accountId}/pages/projects/${projectName}/deployments`,
|
|
436
|
-
{
|
|
437
|
-
method: "POST",
|
|
438
|
-
body: formData,
|
|
439
|
-
}
|
|
440
|
-
);
|
|
244
|
+
const deploymentResponse = await publish({
|
|
245
|
+
directory,
|
|
246
|
+
accountId,
|
|
247
|
+
projectName,
|
|
248
|
+
branch,
|
|
249
|
+
skipCaching,
|
|
250
|
+
commitMessage,
|
|
251
|
+
commitHash,
|
|
252
|
+
commitDirty,
|
|
253
|
+
// TODO: Here lies a known bug. If you specify both `--bundle` and `--no-bundle`, this behavior is undefined and you will get unexpected results.
|
|
254
|
+
// There is no sane way to get the true value out of yargs, so here we are.
|
|
255
|
+
bundle: bundle ?? !noBundle,
|
|
256
|
+
});
|
|
441
257
|
|
|
442
258
|
saveToConfigCache<PagesConfigCache>(PAGES_CONFIG_CACHE_FILENAME, {
|
|
443
259
|
account_id: accountId,
|
package/src/pages/types.ts
CHANGED
package/src/pages/upload.tsx
CHANGED
|
@@ -22,13 +22,15 @@ import {
|
|
|
22
22
|
} from "./constants";
|
|
23
23
|
import { hashFile } from "./hash";
|
|
24
24
|
import { pagesBetaWarning } from "./utils";
|
|
25
|
-
import type {
|
|
25
|
+
import type {
|
|
26
|
+
CommonYargsArgv,
|
|
27
|
+
StrictYargsOptionsToInterface,
|
|
28
|
+
} from "../yargs-types";
|
|
26
29
|
import type { UploadPayloadFile } from "./types";
|
|
27
|
-
import type { Argv } from "yargs";
|
|
28
30
|
|
|
29
|
-
type UploadArgs =
|
|
31
|
+
type UploadArgs = StrictYargsOptionsToInterface<typeof Options>;
|
|
30
32
|
|
|
31
|
-
export function Options(yargs:
|
|
33
|
+
export function Options(yargs: CommonYargsArgv) {
|
|
32
34
|
return yargs
|
|
33
35
|
.positional("directory", {
|
|
34
36
|
type: "string",
|
|
@@ -40,6 +42,10 @@ export function Options(yargs: Argv) {
|
|
|
40
42
|
type: "string",
|
|
41
43
|
description: "The name of the project you want to deploy to",
|
|
42
44
|
},
|
|
45
|
+
"skip-caching": {
|
|
46
|
+
type: "boolean",
|
|
47
|
+
description: "Skip asset caching which speeds up builds",
|
|
48
|
+
},
|
|
43
49
|
})
|
|
44
50
|
.epilogue(pagesBetaWarning);
|
|
45
51
|
}
|
|
@@ -47,6 +53,7 @@ export function Options(yargs: Argv) {
|
|
|
47
53
|
export const Handler = async ({
|
|
48
54
|
directory,
|
|
49
55
|
outputManifestPath,
|
|
56
|
+
skipCaching,
|
|
50
57
|
}: UploadArgs) => {
|
|
51
58
|
if (!directory) {
|
|
52
59
|
throw new FatalError("Must specify a directory.", 1);
|
|
@@ -59,6 +66,7 @@ export const Handler = async ({
|
|
|
59
66
|
const manifest = await upload({
|
|
60
67
|
directory,
|
|
61
68
|
jwt: process.env.CF_PAGES_UPLOAD_JWT,
|
|
69
|
+
skipCaching: skipCaching ?? false,
|
|
62
70
|
});
|
|
63
71
|
|
|
64
72
|
if (outputManifestPath) {
|
|
@@ -74,8 +82,14 @@ export const upload = async (
|
|
|
74
82
|
| {
|
|
75
83
|
directory: string;
|
|
76
84
|
jwt: string;
|
|
85
|
+
skipCaching: boolean;
|
|
86
|
+
}
|
|
87
|
+
| {
|
|
88
|
+
directory: string;
|
|
89
|
+
accountId: string;
|
|
90
|
+
projectName: string;
|
|
91
|
+
skipCaching: boolean;
|
|
77
92
|
}
|
|
78
|
-
| { directory: string; accountId: string; projectName: string }
|
|
79
93
|
) => {
|
|
80
94
|
async function fetchJwt(): Promise<string> {
|
|
81
95
|
if ("jwt" in args) {
|
|
@@ -184,7 +198,12 @@ export const upload = async (
|
|
|
184
198
|
const start = Date.now();
|
|
185
199
|
|
|
186
200
|
let attempts = 0;
|
|
187
|
-
const getMissingHashes = async (): Promise<string[]> => {
|
|
201
|
+
const getMissingHashes = async (skipCaching: boolean): Promise<string[]> => {
|
|
202
|
+
if (skipCaching) {
|
|
203
|
+
logger.debug("Force skipping cache");
|
|
204
|
+
return files.map(({ hash }) => hash);
|
|
205
|
+
}
|
|
206
|
+
|
|
188
207
|
try {
|
|
189
208
|
return await fetchResult<string[]>(`/pages/assets/check-missing`, {
|
|
190
209
|
method: "POST",
|
|
@@ -207,13 +226,13 @@ export const upload = async (
|
|
|
207
226
|
// Looks like the JWT expired, fetch another one
|
|
208
227
|
jwt = await fetchJwt();
|
|
209
228
|
}
|
|
210
|
-
return getMissingHashes();
|
|
229
|
+
return getMissingHashes(skipCaching);
|
|
211
230
|
} else {
|
|
212
231
|
throw e;
|
|
213
232
|
}
|
|
214
233
|
}
|
|
215
234
|
};
|
|
216
|
-
const missingHashes = await getMissingHashes();
|
|
235
|
+
const missingHashes = await getMissingHashes(args.skipCaching);
|
|
217
236
|
|
|
218
237
|
const sortedFiles = files
|
|
219
238
|
.filter((file) => missingHashes.includes(file.hash))
|
|
@@ -257,9 +276,7 @@ export const upload = async (
|
|
|
257
276
|
}
|
|
258
277
|
|
|
259
278
|
let counter = fileMap.size - sortedFiles.length;
|
|
260
|
-
const { rerender, unmount } =
|
|
261
|
-
<Progress done={counter} total={fileMap.size} />
|
|
262
|
-
);
|
|
279
|
+
const { rerender, unmount } = renderProgress(counter, fileMap.size);
|
|
263
280
|
|
|
264
281
|
const queue = new PQueue({ concurrency: BULK_UPLOAD_CONCURRENCY });
|
|
265
282
|
|
|
@@ -283,7 +300,8 @@ export const upload = async (
|
|
|
283
300
|
);
|
|
284
301
|
|
|
285
302
|
try {
|
|
286
|
-
|
|
303
|
+
logger.debug("POST /pages/assets/upload");
|
|
304
|
+
const res = await fetchResult(`/pages/assets/upload`, {
|
|
287
305
|
method: "POST",
|
|
288
306
|
headers: {
|
|
289
307
|
"Content-Type": "application/json",
|
|
@@ -291,8 +309,10 @@ export const upload = async (
|
|
|
291
309
|
},
|
|
292
310
|
body: JSON.stringify(payload),
|
|
293
311
|
});
|
|
312
|
+
logger.debug("result:", res);
|
|
294
313
|
} catch (e) {
|
|
295
314
|
if (attempts < MAX_UPLOAD_ATTEMPTS) {
|
|
315
|
+
logger.debug("failed:", e, "retrying...");
|
|
296
316
|
// Exponential backoff, 1 second first time, then 2 second, then 4 second etc.
|
|
297
317
|
await new Promise((resolvePromise) =>
|
|
298
318
|
setTimeout(resolvePromise, Math.pow(2, attempts++) * 1000)
|
|
@@ -304,16 +324,17 @@ export const upload = async (
|
|
|
304
324
|
}
|
|
305
325
|
return doUpload();
|
|
306
326
|
} else {
|
|
327
|
+
logger.debug("failed:", e);
|
|
307
328
|
throw e;
|
|
308
329
|
}
|
|
309
330
|
}
|
|
310
331
|
};
|
|
311
332
|
|
|
312
|
-
queue.add(() =>
|
|
333
|
+
void queue.add(() =>
|
|
313
334
|
doUpload().then(
|
|
314
335
|
() => {
|
|
315
336
|
counter += bucket.files.length;
|
|
316
|
-
rerender(
|
|
337
|
+
rerender(counter, fileMap.size);
|
|
317
338
|
},
|
|
318
339
|
(error) => {
|
|
319
340
|
return Promise.reject(
|
|
@@ -414,6 +435,28 @@ function formatTime(duration: number) {
|
|
|
414
435
|
return `(${(duration / 1000).toFixed(2)} sec)`;
|
|
415
436
|
}
|
|
416
437
|
|
|
438
|
+
function renderProgress(done: number, total: number) {
|
|
439
|
+
if (isInteractive()) {
|
|
440
|
+
const { rerender, unmount } = render(
|
|
441
|
+
<Progress done={done} total={total} />
|
|
442
|
+
);
|
|
443
|
+
return {
|
|
444
|
+
// eslint-disable-next-line no-shadow
|
|
445
|
+
rerender(done: number, total: number) {
|
|
446
|
+
rerender(<Progress done={done} total={total} />);
|
|
447
|
+
},
|
|
448
|
+
unmount,
|
|
449
|
+
};
|
|
450
|
+
} else {
|
|
451
|
+
// eslint-disable-next-line no-shadow
|
|
452
|
+
const rerender = (done: number, total: number) => {
|
|
453
|
+
logger.log(`Uploading... (${done}/${total})`);
|
|
454
|
+
};
|
|
455
|
+
rerender(done, total);
|
|
456
|
+
return { rerender, unmount() {} };
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
417
460
|
function Progress({ done, total }: { done: number; total: number }) {
|
|
418
461
|
return (
|
|
419
462
|
<>
|
package/src/pages/utils.ts
CHANGED
|
@@ -9,7 +9,7 @@ export const CLEANUP = () => {
|
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
export const pagesBetaWarning =
|
|
12
|
-
"🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/
|
|
12
|
+
"🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose";
|
|
13
13
|
|
|
14
14
|
export function isUrl(maybeUrl?: string): maybeUrl is string {
|
|
15
15
|
if (!maybeUrl) return false;
|
package/src/parse.ts
CHANGED
|
@@ -2,8 +2,12 @@ import * as fs from "node:fs";
|
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
3
|
import TOML from "@iarna/toml";
|
|
4
4
|
import { formatMessagesSync } from "esbuild";
|
|
5
|
+
import {
|
|
6
|
+
parse as jsoncParse,
|
|
7
|
+
printParseErrorCode,
|
|
8
|
+
type ParseError as JsoncParseError,
|
|
9
|
+
} from "jsonc-parser";
|
|
5
10
|
import { logger } from "./logger";
|
|
6
|
-
|
|
7
11
|
export type Message = {
|
|
8
12
|
text: string;
|
|
9
13
|
location?: Location;
|
|
@@ -139,6 +143,24 @@ export function parseJSON<T>(input: string, file?: string): T {
|
|
|
139
143
|
}
|
|
140
144
|
}
|
|
141
145
|
|
|
146
|
+
/**
|
|
147
|
+
* A wrapper around `JSONC.parse` that throws a `ParseError`.
|
|
148
|
+
*/
|
|
149
|
+
export function parseJSONC<T>(input: string, file?: string): T {
|
|
150
|
+
const errors: JsoncParseError[] = [];
|
|
151
|
+
const data = jsoncParse(input, errors);
|
|
152
|
+
if (errors.length) {
|
|
153
|
+
throw new ParseError({
|
|
154
|
+
text: printParseErrorCode(errors[0].error),
|
|
155
|
+
location: {
|
|
156
|
+
...indexLocation({ file, fileText: input }, errors[0].offset + 1),
|
|
157
|
+
length: errors[0].length,
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
return data;
|
|
162
|
+
}
|
|
163
|
+
|
|
142
164
|
/**
|
|
143
165
|
* Reads a file into a node Buffer.
|
|
144
166
|
*/
|
package/src/paths.ts
CHANGED
|
@@ -59,7 +59,7 @@ export function readableRelative(to: string) {
|
|
|
59
59
|
declare const __RELATIVE_PACKAGE_PATH__: string;
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
|
-
* Use this function (rather than
|
|
62
|
+
* Use this function (rather than Node.js constants like `__dirname`) to specify
|
|
63
63
|
* paths that are relative to the base path of the Wrangler package.
|
|
64
64
|
*
|
|
65
65
|
* It is important to use this function because it reliably maps to the root of the package
|
package/src/publish/index.ts
CHANGED
|
@@ -13,14 +13,12 @@ import { getAssetPaths, getSiteAssetPaths } from "../sites";
|
|
|
13
13
|
import { requireAuth } from "../user";
|
|
14
14
|
import { collectKeyValues } from "../utils/collectKeyValues";
|
|
15
15
|
import publish from "./publish";
|
|
16
|
-
import type { ConfigPath } from "../index";
|
|
17
16
|
import type {
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
CommonYargsArgv,
|
|
18
|
+
StrictYargsOptionsToInterface,
|
|
20
19
|
} from "../yargs-types";
|
|
21
|
-
import type { Argv, ArgumentsCamelCase } from "yargs";
|
|
22
20
|
|
|
23
|
-
export function publishOptions(yargs:
|
|
21
|
+
export function publishOptions(yargs: CommonYargsArgv) {
|
|
24
22
|
return (
|
|
25
23
|
yargs
|
|
26
24
|
.positional("script", {
|
|
@@ -82,6 +80,13 @@ export function publishOptions(yargs: Argv<CommonYargsOptions>) {
|
|
|
82
80
|
deprecated: true,
|
|
83
81
|
hidden: true,
|
|
84
82
|
})
|
|
83
|
+
.option("public", {
|
|
84
|
+
describe: "Static assets to be served",
|
|
85
|
+
type: "string",
|
|
86
|
+
requiresArg: true,
|
|
87
|
+
deprecated: true,
|
|
88
|
+
hidden: true,
|
|
89
|
+
})
|
|
85
90
|
.option("assets", {
|
|
86
91
|
describe: "Static assets to be served",
|
|
87
92
|
type: "string",
|
|
@@ -153,7 +158,7 @@ export function publishOptions(yargs: Argv<CommonYargsOptions>) {
|
|
|
153
158
|
type: "boolean",
|
|
154
159
|
})
|
|
155
160
|
.option("node-compat", {
|
|
156
|
-
describe: "Enable
|
|
161
|
+
describe: "Enable Node.js compatibility",
|
|
157
162
|
type: "boolean",
|
|
158
163
|
})
|
|
159
164
|
.option("dry-run", {
|
|
@@ -179,14 +184,13 @@ export function publishOptions(yargs: Argv<CommonYargsOptions>) {
|
|
|
179
184
|
);
|
|
180
185
|
}
|
|
181
186
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
187
|
+
export async function publishHandler(
|
|
188
|
+
args: StrictYargsOptionsToInterface<typeof publishOptions>
|
|
189
|
+
) {
|
|
185
190
|
await printWranglerBanner();
|
|
186
191
|
|
|
187
192
|
const configPath =
|
|
188
|
-
|
|
189
|
-
(args.script && findWranglerToml(path.dirname(args.script)));
|
|
193
|
+
args.config || (args.script && findWranglerToml(path.dirname(args.script)));
|
|
190
194
|
const config = readConfig(configPath, args);
|
|
191
195
|
const entry = await getEntry(args, config, "publish");
|
|
192
196
|
await metrics.sendMetricsEvent(
|
|
@@ -202,7 +206,7 @@ export async function publishHandler(args: ArgumentsCamelCase<PublishArgs>) {
|
|
|
202
206
|
if (args.public) {
|
|
203
207
|
throw new Error("The --public field has been renamed to --assets");
|
|
204
208
|
}
|
|
205
|
-
if (args
|
|
209
|
+
if (args.experimentalPublic) {
|
|
206
210
|
throw new Error(
|
|
207
211
|
"The --experimental-public field has been renamed to --assets"
|
|
208
212
|
);
|
|
@@ -247,13 +251,13 @@ export async function publishHandler(args: ArgumentsCamelCase<PublishArgs>) {
|
|
|
247
251
|
env: args.env,
|
|
248
252
|
compatibilityDate: args.latest
|
|
249
253
|
? new Date().toISOString().substring(0, 10)
|
|
250
|
-
: args
|
|
251
|
-
compatibilityFlags: args
|
|
254
|
+
: args.compatibilityDate,
|
|
255
|
+
compatibilityFlags: args.compatibilityFlags,
|
|
252
256
|
vars: cliVars,
|
|
253
257
|
defines: cliDefines,
|
|
254
258
|
triggers: args.triggers,
|
|
255
|
-
jsxFactory: args
|
|
256
|
-
jsxFragment: args
|
|
259
|
+
jsxFactory: args.jsxFactory,
|
|
260
|
+
jsxFragment: args.jsxFragment,
|
|
257
261
|
tsconfig: args.tsconfig,
|
|
258
262
|
routes: args.routes,
|
|
259
263
|
assetPaths,
|