wrangler 0.0.0-e61fba8 → 0.0.0-e665ccc3
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 +24 -4
- package/bin/wrangler.js +170 -62
- package/miniflare-dist/index.mjs +1643 -83
- package/package.json +198 -154
- package/src/__tests__/access.test.ts +25 -0
- package/src/__tests__/api-dev.test.ts +238 -0
- package/src/__tests__/api-devregistry.test.ts +121 -0
- package/src/__tests__/api.test.ts +102 -0
- package/src/__tests__/config-cache-without-cache-dir.test.ts +38 -0
- package/src/__tests__/config-cache.test.ts +30 -24
- package/src/__tests__/configuration.test.ts +4506 -3476
- 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 +272 -0
- package/src/__tests__/deployments.test.ts +369 -0
- package/src/__tests__/dev.test.tsx +1590 -983
- package/src/__tests__/generate.test.ts +237 -0
- package/src/__tests__/get-host-from-url.test.ts +16 -0
- package/src/__tests__/guess-worker-format.test.ts +103 -68
- package/src/__tests__/helpers/cmd-shim.d.ts +6 -6
- package/src/__tests__/helpers/end-event-loop.ts +6 -0
- package/src/__tests__/helpers/mock-account-id.ts +24 -24
- package/src/__tests__/helpers/mock-auth-domain.ts +20 -0
- package/src/__tests__/helpers/mock-bin.ts +20 -20
- package/src/__tests__/helpers/mock-console.ts +64 -39
- package/src/__tests__/helpers/mock-dialogs.ts +88 -79
- package/src/__tests__/helpers/mock-get-pages-upload-token.ts +25 -0
- package/src/__tests__/helpers/mock-get-zone-from-host.ts +11 -0
- package/src/__tests__/helpers/mock-http-server.ts +30 -30
- package/src/__tests__/helpers/mock-istty.ts +65 -18
- package/src/__tests__/helpers/mock-known-routes.ts +12 -0
- package/src/__tests__/helpers/mock-kv.ts +41 -28
- package/src/__tests__/helpers/mock-oauth-flow.ts +241 -233
- package/src/__tests__/helpers/mock-process.ts +34 -0
- package/src/__tests__/helpers/mock-set-timeout.ts +16 -0
- package/src/__tests__/helpers/mock-stdin.ts +82 -77
- package/src/__tests__/helpers/mock-web-socket.ts +21 -21
- package/src/__tests__/helpers/msw/blob-worker.cjs +19 -0
- package/src/__tests__/helpers/msw/handlers/access.ts +13 -0
- package/src/__tests__/helpers/msw/handlers/deployments.ts +160 -0
- package/src/__tests__/helpers/msw/handlers/namespaces.ts +81 -0
- package/src/__tests__/helpers/msw/handlers/oauth.ts +31 -0
- package/src/__tests__/helpers/msw/handlers/r2.ts +60 -0
- package/src/__tests__/helpers/msw/handlers/script.ts +56 -0
- package/src/__tests__/helpers/msw/handlers/user.ts +52 -0
- package/src/__tests__/helpers/msw/handlers/zones.ts +20 -0
- package/src/__tests__/helpers/msw/index.ts +52 -0
- package/src/__tests__/helpers/msw/read-file-sync.js +61 -0
- package/src/__tests__/helpers/run-in-tmp.ts +27 -28
- package/src/__tests__/helpers/run-wrangler.ts +8 -8
- package/src/__tests__/helpers/string-dynamic-values-matcher.ts +28 -0
- package/src/__tests__/helpers/worker-scripts/child-wrangler.toml +1 -0
- package/src/__tests__/helpers/worker-scripts/hello-world-worker.js +5 -0
- package/src/__tests__/helpers/worker-scripts/hello-world-wrangler.toml +1 -0
- package/src/__tests__/helpers/worker-scripts/parent-worker.js +11 -0
- package/src/__tests__/helpers/worker-scripts/parent-wrangler.toml +5 -0
- package/src/__tests__/helpers/write-worker-source.ts +16 -16
- package/src/__tests__/helpers/write-wrangler-toml.ts +9 -9
- package/src/__tests__/https-options.test.ts +142 -109
- package/src/__tests__/index.test.ts +262 -237
- package/src/__tests__/init.test.ts +3167 -1608
- package/src/__tests__/jest.setup.ts +152 -50
- package/src/__tests__/kv.test.ts +1789 -1492
- package/src/__tests__/logger.test.ts +167 -75
- package/src/__tests__/logout.test.ts +47 -0
- package/src/__tests__/metrics.test.ts +493 -0
- package/src/__tests__/middleware.scheduled.test.ts +145 -0
- package/src/__tests__/middleware.test.ts +816 -0
- package/src/__tests__/mtls-certificates.test.ts +589 -0
- package/src/__tests__/package-manager.test.ts +303 -303
- 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 +957 -0
- package/src/__tests__/parse.test.ts +358 -252
- package/src/__tests__/paths.test.ts +39 -0
- package/src/__tests__/publish.test.ts +8716 -5687
- package/src/__tests__/pubsub.test.ts +496 -0
- package/src/__tests__/queues.test.ts +532 -0
- package/src/__tests__/r2.test.ts +369 -228
- package/src/__tests__/route.test.ts +18 -18
- package/src/__tests__/secret.test.ts +681 -469
- package/src/__tests__/tail.test.ts +866 -567
- package/src/__tests__/test-old-node-version.js +31 -0
- 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 +234 -0
- package/src/__tests__/user.test.ts +107 -120
- package/src/__tests__/utils-collectKeyValues.test.ts +47 -0
- package/src/__tests__/validate-dev-props.test.ts +56 -0
- package/src/__tests__/version.test.ts +35 -0
- package/src/__tests__/whoami.test.tsx +165 -132
- package/src/__tests__/worker-namespace.test.ts +340 -0
- package/src/abort.d.ts +1 -1
- package/src/api/dev.ts +321 -0
- package/src/api/index.ts +11 -0
- 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-reporter.ts +68 -0
- package/src/bundle.ts +890 -165
- package/src/cfetch/index.ts +120 -83
- package/src/cfetch/internal.ts +208 -92
- package/src/cli.ts +23 -8
- package/src/config/config.ts +244 -196
- package/src/config/diagnostics.ts +61 -61
- package/src/config/environment.ts +562 -357
- package/src/config/index.ts +374 -196
- package/src/config/validation-helpers.ts +379 -366
- package/src/config/validation.ts +2197 -1376
- package/src/config-cache.ts +81 -41
- 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 +250 -142
- package/src/create-worker-upload-form.ts +347 -238
- package/src/d1/backups.tsx +219 -0
- package/src/d1/constants.ts +2 -0
- package/src/d1/create.tsx +70 -0
- package/src/d1/delete.ts +53 -0
- package/src/d1/execute.tsx +357 -0
- package/src/d1/formatTimeAgo.ts +14 -0
- package/src/d1/index.ts +100 -0
- package/src/d1/list.tsx +62 -0
- package/src/d1/migrations/apply.tsx +212 -0
- package/src/d1/migrations/create.tsx +79 -0
- package/src/d1/migrations/helpers.ts +169 -0
- package/src/d1/migrations/index.ts +3 -0
- package/src/d1/migrations/list.tsx +95 -0
- package/src/d1/migrations/options.ts +23 -0
- package/src/d1/options.ts +22 -0
- package/src/d1/splitter.ts +161 -0
- package/src/d1/types.ts +25 -0
- package/src/d1/utils.ts +49 -0
- package/src/delete.ts +100 -0
- package/src/deployments.ts +368 -0
- package/src/deprecated/index.ts +144 -0
- package/src/dev/dev-vars.ts +20 -17
- package/src/dev/dev.tsx +535 -325
- package/src/dev/get-local-persistence-path.ts +31 -0
- package/src/dev/local.tsx +932 -301
- package/src/dev/remote.tsx +623 -228
- package/src/dev/start-server.ts +545 -0
- package/src/dev/use-esbuild.ts +194 -94
- package/src/dev/validate-dev-props.ts +40 -0
- package/src/dev-registry.ts +202 -0
- package/src/dev.tsx +934 -0
- package/src/dialogs.ts +136 -0
- package/src/dispatch-namespace.ts +211 -0
- package/src/docs/helpers.ts +50 -0
- package/src/docs/index.ts +54 -0
- package/src/durable.ts +87 -87
- package/src/entry.ts +253 -231
- package/src/environment-variables/factory.ts +89 -0
- package/src/environment-variables/misc-variables.ts +30 -0
- package/src/errors.ts +6 -6
- package/src/generate/index.ts +298 -0
- package/src/git-client.ts +135 -0
- package/src/global-wrangler-config-path.ts +26 -0
- package/src/https-options.ts +84 -80
- package/src/index.ts +768 -0
- package/src/init.ts +1037 -0
- package/src/inspect.ts +816 -595
- package/src/intl-polyfill.d.ts +123 -123
- package/src/is-ci.ts +14 -0
- package/src/is-interactive.ts +16 -0
- package/src/jest.d.ts +4 -0
- package/src/kv/helpers.ts +433 -0
- package/src/kv/index.ts +594 -0
- package/src/logger.ts +100 -43
- package/src/metrics/index.ts +5 -0
- package/src/metrics/metrics-config.ts +239 -0
- package/src/metrics/metrics-dispatcher.ts +96 -0
- package/src/metrics/metrics-usage-headers.ts +24 -0
- package/src/metrics/send-event.ts +99 -0
- package/src/miniflare-cli/assets.ts +255 -0
- package/src/miniflare-cli/index.ts +202 -33
- package/src/miniflare-cli/request-context.ts +18 -18
- 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 +290 -215
- package/src/mtls-certificate/cli.ts +155 -0
- package/src/open-in-browser.ts +4 -6
- package/src/package-manager.ts +173 -128
- package/src/pages/build.ts +423 -0
- package/src/pages/buildFunctions.ts +140 -0
- package/src/pages/constants.ts +18 -0
- package/src/pages/deployment-tails.ts +281 -0
- package/src/pages/deployments.tsx +84 -0
- package/src/pages/dev.ts +734 -0
- package/src/pages/errors.ts +67 -0
- package/src/pages/functions/buildPlugin.ts +114 -0
- package/src/pages/functions/buildWorker.ts +350 -0
- package/{pages → src/pages}/functions/filepath-routing.test.ts +113 -113
- package/src/pages/functions/filepath-routing.ts +189 -0
- package/src/pages/functions/identifiers.ts +78 -0
- package/src/pages/functions/routes-consolidation.test.ts +250 -0
- package/src/pages/functions/routes-consolidation.ts +73 -0
- package/src/pages/functions/routes-transformation.test.ts +282 -0
- package/src/pages/functions/routes-transformation.ts +115 -0
- package/src/pages/functions/routes-validation.test.ts +403 -0
- package/src/pages/functions/routes-validation.ts +202 -0
- package/src/pages/functions/routes.ts +151 -0
- package/src/pages/functions/tsconfig.json +8 -0
- package/src/pages/functions/tsconfig.tsbuildinfo +1 -0
- package/src/pages/functions.ts +86 -0
- package/src/pages/hash.ts +13 -0
- package/src/pages/index.ts +102 -0
- package/src/pages/projects.tsx +159 -0
- package/src/pages/prompt-select-project.tsx +31 -0
- package/src/pages/publish.tsx +267 -0
- package/src/pages/types.ts +46 -0
- package/src/pages/upload.tsx +469 -0
- package/src/pages/utils.ts +23 -0
- package/src/parse.ts +225 -139
- package/src/paths.ts +53 -8
- package/src/proxy.ts +623 -407
- package/src/publish/index.ts +274 -0
- package/src/publish/publish.ts +1065 -0
- package/src/pubsub/index.ts +286 -0
- package/src/pubsub/pubsub-commands.ts +623 -0
- package/src/queues/cli/commands/consumer/add.ts +71 -0
- package/src/queues/cli/commands/consumer/index.ts +19 -0
- package/src/queues/cli/commands/consumer/remove.ts +31 -0
- package/src/queues/cli/commands/create.ts +25 -0
- package/src/queues/cli/commands/delete.ts +26 -0
- package/src/queues/cli/commands/index.ts +35 -0
- package/src/queues/cli/commands/list.ts +25 -0
- package/src/queues/client.ts +136 -0
- package/src/queues/utils.ts +18 -0
- package/src/r2/constants.ts +4 -0
- package/src/r2/helpers.ts +132 -0
- package/src/r2/index.ts +289 -0
- package/src/routes.ts +140 -0
- package/src/secret/index.ts +377 -0
- package/src/selfsigned.d.ts +23 -23
- package/src/sites.ts +484 -0
- package/src/tail/createTail.ts +415 -0
- package/src/tail/filters.ts +109 -111
- package/src/tail/index.ts +208 -296
- package/src/tail/printing.ts +116 -51
- package/src/traverse-module-graph.ts +54 -0
- package/src/tsconfig-sanity.ts +16 -0
- package/src/type-generation.ts +181 -0
- package/src/update-check.ts +11 -11
- package/src/user/access.ts +68 -0
- package/src/user/auth-variables.ts +113 -0
- package/src/user/choose-account.tsx +39 -0
- package/src/user/generate-auth-url.ts +33 -0
- package/src/user/generate-random-state.ts +16 -0
- package/src/user/index.ts +2 -0
- package/src/user/user.ts +1234 -0
- package/src/utils/collectKeyValues.ts +14 -0
- package/src/utils/render.ts +93 -0
- package/src/whoami.ts +135 -0
- package/src/worker.ts +205 -107
- package/src/yargs-types.ts +37 -0
- package/src/zones.ts +158 -40
- package/templates/__tests__/pages-dev-util.test.ts +128 -0
- 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 +23 -0
- package/templates/d1-beta-facade.js +244 -0
- package/templates/facade.d.ts +14 -0
- package/templates/first-party-worker-module-facade.ts +19 -0
- package/templates/format-dev-errors.ts +34 -0
- package/templates/gitignore +1 -0
- package/templates/init-tests/test-jest-new-worker.js +23 -0
- package/templates/init-tests/test-vitest-new-worker.js +24 -0
- package/templates/init-tests/test-vitest-new-worker.ts +25 -0
- package/templates/middleware/common.ts +62 -0
- package/templates/middleware/loader-modules.ts +84 -0
- package/templates/middleware/loader-sw.ts +233 -0
- package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
- package/templates/middleware/middleware-pretty-error.ts +40 -0
- package/templates/middleware/middleware-scheduled.ts +15 -0
- package/templates/new-worker-scheduled.js +3 -3
- package/templates/new-worker-scheduled.ts +15 -15
- package/templates/new-worker.js +3 -3
- package/templates/new-worker.ts +18 -15
- package/templates/no-op-worker.js +10 -0
- package/templates/pages-dev-pipeline.ts +31 -0
- package/templates/pages-dev-util.ts +52 -0
- package/templates/pages-shim.ts +12 -0
- package/templates/pages-template-plugin.ts +180 -0
- package/templates/pages-template-worker.ts +189 -0
- package/templates/serve-static-assets.ts +66 -0
- package/templates/service-bindings-module-facade.js +55 -0
- package/templates/service-bindings-sw-facade.js +42 -0
- package/templates/tsconfig-sanity.ts +11 -0
- package/templates/tsconfig.init.json +105 -0
- package/templates/tsconfig.json +6 -103
- package/templates/tsconfig.tsbuildinfo +1 -0
- package/wrangler-dist/cli.d.ts +1652 -0
- package/wrangler-dist/cli.js +139094 -111923
- package/wrangler-dist/wasm-sync.wasm +0 -0
- package/pages/functions/buildPlugin.ts +0 -105
- package/pages/functions/buildWorker.ts +0 -151
- package/pages/functions/filepath-routing.ts +0 -189
- package/pages/functions/identifiers.ts +0 -78
- package/pages/functions/routes.ts +0 -156
- package/pages/functions/template-plugin.ts +0 -147
- package/pages/functions/template-worker.ts +0 -143
- package/src/__tests__/helpers/faye-websocket.d.ts +0 -6
- package/src/__tests__/helpers/mock-cfetch.ts +0 -211
- package/src/__tests__/pages.test.ts +0 -754
- package/src/dialogs.tsx +0 -135
- package/src/environment-variables.ts +0 -35
- package/src/index.tsx +0 -2859
- package/src/kv.ts +0 -408
- package/src/miniflare-cli/enum-keys.ts +0 -17
- package/src/pages.tsx +0 -2093
- package/src/publish.ts +0 -721
- package/src/r2.ts +0 -50
- package/src/sites.tsx +0 -326
- package/src/user.tsx +0 -1214
- package/src/whoami.tsx +0 -71
- package/templates/static-asset-facade.js +0 -43
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { isValidIdentifier, normalizeIdentifier } from "./identifiers";
|
|
4
|
+
import type { UrlPath } from "../../paths";
|
|
5
|
+
|
|
6
|
+
export const HTTP_METHODS = [
|
|
7
|
+
"HEAD",
|
|
8
|
+
"OPTIONS",
|
|
9
|
+
"GET",
|
|
10
|
+
"POST",
|
|
11
|
+
"PUT",
|
|
12
|
+
"PATCH",
|
|
13
|
+
"DELETE",
|
|
14
|
+
] as const;
|
|
15
|
+
export type HTTPMethod = typeof HTTP_METHODS[number];
|
|
16
|
+
|
|
17
|
+
export type RoutesCollection = Array<{
|
|
18
|
+
routePath: UrlPath;
|
|
19
|
+
mountPath: UrlPath;
|
|
20
|
+
method?: HTTPMethod;
|
|
21
|
+
modules: string[];
|
|
22
|
+
middlewares: string[];
|
|
23
|
+
}>;
|
|
24
|
+
|
|
25
|
+
export type Config = {
|
|
26
|
+
routes?: RouteConfig[];
|
|
27
|
+
schedules?: unknown;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type RouteConfig = {
|
|
31
|
+
routePath: UrlPath;
|
|
32
|
+
mountPath: UrlPath;
|
|
33
|
+
method?: HTTPMethod;
|
|
34
|
+
middleware?: string | string[];
|
|
35
|
+
module?: string | string[];
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
type ImportMap = Map<
|
|
39
|
+
string,
|
|
40
|
+
{
|
|
41
|
+
filepath: string;
|
|
42
|
+
name: string;
|
|
43
|
+
identifier: string;
|
|
44
|
+
}
|
|
45
|
+
>;
|
|
46
|
+
|
|
47
|
+
type Arguments = {
|
|
48
|
+
config: Config;
|
|
49
|
+
outfile: string;
|
|
50
|
+
srcDir: string;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export async function writeRoutesModule({
|
|
54
|
+
config,
|
|
55
|
+
srcDir,
|
|
56
|
+
outfile = "_routes.js",
|
|
57
|
+
}: Arguments) {
|
|
58
|
+
const { importMap, routes } = parseConfig(config, srcDir);
|
|
59
|
+
const routesModule = generateRoutesModule(importMap, routes);
|
|
60
|
+
|
|
61
|
+
await fs.writeFile(outfile, routesModule);
|
|
62
|
+
|
|
63
|
+
return outfile;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function parseConfig(config: Config, baseDir: string) {
|
|
67
|
+
const routes: RoutesCollection = [];
|
|
68
|
+
const importMap: ImportMap = new Map();
|
|
69
|
+
const identifierCount = new Map<string, number>(); // to keep track of identifier collisions
|
|
70
|
+
|
|
71
|
+
function parseModuleIdentifiers(paths: string | string[] | undefined) {
|
|
72
|
+
if (typeof paths === "undefined") {
|
|
73
|
+
paths = [];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (typeof paths === "string") {
|
|
77
|
+
paths = [paths];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return paths.map((modulePath) => {
|
|
81
|
+
const [filepath, name = "default"] = modulePath.split(":");
|
|
82
|
+
let { identifier } = importMap.get(modulePath) ?? {};
|
|
83
|
+
|
|
84
|
+
const resolvedPath = path.resolve(baseDir, filepath);
|
|
85
|
+
|
|
86
|
+
// ensure the filepath isn't attempting to resolve to anything outside of the project
|
|
87
|
+
if (path.relative(baseDir, resolvedPath).startsWith("..")) {
|
|
88
|
+
throw new Error(`Invalid module path "${filepath}"`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// ensure the module name (if provided) is a valid identifier to guard against injection attacks
|
|
92
|
+
if (name !== "default" && !isValidIdentifier(name)) {
|
|
93
|
+
throw new Error(`Invalid module identifier "${name}"`);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (!identifier) {
|
|
97
|
+
identifier = normalizeIdentifier(`__${filepath}_${name}`);
|
|
98
|
+
|
|
99
|
+
let count = identifierCount.get(identifier) ?? 0;
|
|
100
|
+
identifierCount.set(identifier, ++count);
|
|
101
|
+
|
|
102
|
+
if (count > 1) {
|
|
103
|
+
identifier += `_${count}`;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
importMap.set(modulePath, { filepath: resolvedPath, name, identifier });
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return identifier;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
for (const { routePath, mountPath, method, ...props } of config.routes ??
|
|
114
|
+
[]) {
|
|
115
|
+
routes.push({
|
|
116
|
+
routePath,
|
|
117
|
+
mountPath,
|
|
118
|
+
method,
|
|
119
|
+
middlewares: parseModuleIdentifiers(props.middleware),
|
|
120
|
+
modules: parseModuleIdentifiers(props.module),
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return { routes, importMap };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function generateRoutesModule(
|
|
128
|
+
importMap: ImportMap,
|
|
129
|
+
routes: RoutesCollection
|
|
130
|
+
) {
|
|
131
|
+
return `${[...importMap.values()]
|
|
132
|
+
.map(
|
|
133
|
+
({ filepath, name, identifier }) =>
|
|
134
|
+
`import { ${name} as ${identifier} } from ${JSON.stringify(filepath)}`
|
|
135
|
+
)
|
|
136
|
+
.join("\n")}
|
|
137
|
+
|
|
138
|
+
export const routes = [
|
|
139
|
+
${routes
|
|
140
|
+
.map(
|
|
141
|
+
(route) => ` {
|
|
142
|
+
routePath: "${route.routePath}",
|
|
143
|
+
mountPath: "${route.mountPath}",
|
|
144
|
+
method: "${route.method}",
|
|
145
|
+
middlewares: [${route.middlewares.join(", ")}],
|
|
146
|
+
modules: [${route.modules.join(", ")}],
|
|
147
|
+
},`
|
|
148
|
+
)
|
|
149
|
+
.join("\n")}
|
|
150
|
+
]`;
|
|
151
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"program":{"fileNames":["../../../../../node_modules/typescript/lib/lib.es5.d.ts","../../../../../node_modules/typescript/lib/lib.es2015.d.ts","../../../../../node_modules/typescript/lib/lib.es2016.d.ts","../../../../../node_modules/typescript/lib/lib.es2017.d.ts","../../../../../node_modules/typescript/lib/lib.es2018.d.ts","../../../../../node_modules/typescript/lib/lib.es2019.d.ts","../../../../../node_modules/typescript/lib/lib.es2020.d.ts","../../../../../node_modules/typescript/lib/lib.es2021.d.ts","../../../../../node_modules/typescript/lib/lib.es2022.d.ts","../../../../../node_modules/typescript/lib/lib.esnext.d.ts","../../../../../node_modules/typescript/lib/lib.es2015.core.d.ts","../../../../../node_modules/typescript/lib/lib.es2015.collection.d.ts","../../../../../node_modules/typescript/lib/lib.es2015.generator.d.ts","../../../../../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../../../../node_modules/typescript/lib/lib.es2015.promise.d.ts","../../../../../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../../../../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../../../../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../../../../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../../../../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../../../../node_modules/typescript/lib/lib.es2017.object.d.ts","../../../../../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../../../../node_modules/typescript/lib/lib.es2017.string.d.ts","../../../../../node_modules/typescript/lib/lib.es2017.intl.d.ts","../../../../../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../../../../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../../../../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../../../../node_modules/typescript/lib/lib.es2018.intl.d.ts","../../../../../node_modules/typescript/lib/lib.es2018.promise.d.ts","../../../../../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../../../../node_modules/typescript/lib/lib.es2019.array.d.ts","../../../../../node_modules/typescript/lib/lib.es2019.object.d.ts","../../../../../node_modules/typescript/lib/lib.es2019.string.d.ts","../../../../../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../../../../node_modules/typescript/lib/lib.es2020.bigint.d.ts","../../../../../node_modules/typescript/lib/lib.es2020.date.d.ts","../../../../../node_modules/typescript/lib/lib.es2020.promise.d.ts","../../../../../node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../../../../../node_modules/typescript/lib/lib.es2020.string.d.ts","../../../../../node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../../../../../node_modules/typescript/lib/lib.es2020.intl.d.ts","../../../../../node_modules/typescript/lib/lib.es2020.number.d.ts","../../../../../node_modules/typescript/lib/lib.es2021.promise.d.ts","../../../../../node_modules/typescript/lib/lib.es2021.string.d.ts","../../../../../node_modules/typescript/lib/lib.es2021.weakref.d.ts","../../../../../node_modules/typescript/lib/lib.es2021.intl.d.ts","../../../../../node_modules/typescript/lib/lib.es2022.array.d.ts","../../../../../node_modules/typescript/lib/lib.es2022.error.d.ts","../../../../../node_modules/typescript/lib/lib.es2022.intl.d.ts","../../../../../node_modules/typescript/lib/lib.es2022.object.d.ts","../../../../../node_modules/typescript/lib/lib.es2022.sharedmemory.d.ts","../../../../../node_modules/typescript/lib/lib.es2022.string.d.ts","../../../../../node_modules/typescript/lib/lib.esnext.intl.d.ts","../../../node_modules/@iarna/toml/index.d.ts","../../../../../node_modules/@webcontainer/env/dist/environment.d.ts","../../../../../node_modules/@webcontainer/env/dist/url.d.ts","../../../../../node_modules/@webcontainer/env/dist/index.d.ts","../../../../../node_modules/buffer/index.d.ts","../../../../../node_modules/undici/types/header.d.ts","../../../../../node_modules/undici/types/readable.d.ts","../../../../../node_modules/@types/node/assert.d.ts","../../../../../node_modules/@types/node/assert/strict.d.ts","../../../../../node_modules/@types/node/globals.d.ts","../../../../../node_modules/@types/node/async_hooks.d.ts","../../../../../node_modules/@types/node/buffer.d.ts","../../../../../node_modules/@types/node/child_process.d.ts","../../../../../node_modules/@types/node/cluster.d.ts","../../../../../node_modules/@types/node/console.d.ts","../../../../../node_modules/@types/node/constants.d.ts","../../../../../node_modules/@types/node/crypto.d.ts","../../../../../node_modules/@types/node/dgram.d.ts","../../../../../node_modules/@types/node/diagnostics_channel.d.ts","../../../../../node_modules/@types/node/dns.d.ts","../../../../../node_modules/@types/node/dns/promises.d.ts","../../../../../node_modules/@types/node/domain.d.ts","../../../../../node_modules/@types/node/events.d.ts","../../../../../node_modules/@types/node/fs.d.ts","../../../../../node_modules/@types/node/fs/promises.d.ts","../../../../../node_modules/@types/node/http.d.ts","../../../../../node_modules/@types/node/http2.d.ts","../../../../../node_modules/@types/node/https.d.ts","../../../../../node_modules/@types/node/inspector.d.ts","../../../../../node_modules/@types/node/module.d.ts","../../../../../node_modules/@types/node/net.d.ts","../../../../../node_modules/@types/node/os.d.ts","../../../../../node_modules/@types/node/path.d.ts","../../../../../node_modules/@types/node/perf_hooks.d.ts","../../../../../node_modules/@types/node/process.d.ts","../../../../../node_modules/@types/node/punycode.d.ts","../../../../../node_modules/@types/node/querystring.d.ts","../../../../../node_modules/@types/node/readline.d.ts","../../../../../node_modules/@types/node/repl.d.ts","../../../../../node_modules/@types/node/stream.d.ts","../../../../../node_modules/@types/node/stream/promises.d.ts","../../../../../node_modules/@types/node/stream/consumers.d.ts","../../../../../node_modules/@types/node/stream/web.d.ts","../../../../../node_modules/@types/node/string_decoder.d.ts","../../../../../node_modules/@types/node/timers.d.ts","../../../../../node_modules/@types/node/timers/promises.d.ts","../../../../../node_modules/@types/node/tls.d.ts","../../../../../node_modules/@types/node/trace_events.d.ts","../../../../../node_modules/@types/node/tty.d.ts","../../../../../node_modules/@types/node/url.d.ts","../../../../../node_modules/@types/node/util.d.ts","../../../../../node_modules/@types/node/v8.d.ts","../../../../../node_modules/@types/node/vm.d.ts","../../../../../node_modules/@types/node/wasi.d.ts","../../../../../node_modules/@types/node/worker_threads.d.ts","../../../../../node_modules/@types/node/zlib.d.ts","../../../../../node_modules/@types/node/globals.global.d.ts","../../../../../node_modules/@types/node/index.d.ts","../../../../../node_modules/undici/types/file.d.ts","../../../../../node_modules/undici/types/fetch.d.ts","../../../../../node_modules/undici/types/formdata.d.ts","../../../../../node_modules/undici/types/connector.d.ts","../../../../../node_modules/undici/types/client.d.ts","../../../../../node_modules/undici/types/errors.d.ts","../../../../../node_modules/undici/types/dispatcher.d.ts","../../../../../node_modules/undici/types/global-dispatcher.d.ts","../../../../../node_modules/undici/types/global-origin.d.ts","../../../../../node_modules/undici/types/pool-stats.d.ts","../../../../../node_modules/undici/types/pool.d.ts","../../../../../node_modules/undici/types/handlers.d.ts","../../../../../node_modules/undici/types/balanced-pool.d.ts","../../../../../node_modules/undici/types/agent.d.ts","../../../../../node_modules/undici/types/mock-interceptor.d.ts","../../../../../node_modules/undici/types/mock-agent.d.ts","../../../../../node_modules/undici/types/mock-client.d.ts","../../../../../node_modules/undici/types/mock-pool.d.ts","../../../../../node_modules/undici/types/mock-errors.d.ts","../../../../../node_modules/undici/types/proxy-agent.d.ts","../../../../../node_modules/undici/types/api.d.ts","../../../../../node_modules/undici/types/cookies.d.ts","../../../../../node_modules/undici/types/patch.d.ts","../../../../../node_modules/undici/types/filereader.d.ts","../../../../../node_modules/undici/types/diagnostics-channel.d.ts","../../../../../node_modules/undici/types/websocket.d.ts","../../../../../node_modules/undici/types/content-type.d.ts","../../../../../node_modules/undici/types/interceptors.d.ts","../../../../../node_modules/undici/index.d.ts","../../../node_modules/locate-path/index.d.ts","../../../node_modules/find-up/index.d.ts","../../../../../node_modules/ci-info/index.d.ts","../../../../../node_modules/@types/is-ci/index.d.ts","../../is-ci.ts","../../is-interactive.ts","../../../../../node_modules/chalk/types/index.d.ts","../../../../../node_modules/cli-table3/index.d.ts","../../../../../node_modules/esbuild/lib/main.d.ts","../../environment-variables/factory.ts","../../logger.ts","../../config-cache.ts","../../../../../node_modules/@types/prompts/index.d.ts","../../dialogs.ts","../../../../../node_modules/xdg-app-paths/dist/types/mod.d.ts","../../global-wrangler-config-path.ts","../../../../../node_modules/open/index.d.ts","../../open-in-browser.ts","../../../../../node_modules/jsonc-parser/lib/umd/main.d.ts","../../parse.ts","../../user/access.ts","../../environment-variables/misc-variables.ts","../../user/auth-variables.ts","../../../package.json","../../cfetch/internal.ts","../../cfetch/index.ts","../../user/choose-account.tsx","../../user/generate-auth-url.ts","../../user/generate-random-state.ts","../../user/user.ts","../../user/index.ts","../../__tests__/helpers/run-in-tmp.ts","../../paths.ts","./identifiers.ts","./routes.ts","./filepath-routing.ts","./filepath-routing.test.ts","../constants.ts","./routes-consolidation.ts","./routes-consolidation.test.ts","./routes-transformation.ts","./routes-transformation.test.ts","../../errors.ts","./routes-validation.ts","../errors.ts","./routes-validation.test.ts","../../intl-polyfill.d.ts","../../../../../node_modules/@types/jest/node_modules/chalk/index.d.ts","../../../../../node_modules/@sinclair/typebox/typebox.d.ts","../../../../../node_modules/@jest/schemas/build/index.d.ts","../../../../../node_modules/@types/jest/node_modules/pretty-format/build/index.d.ts","../../../../../node_modules/@types/jest/node_modules/jest-diff/build/index.d.ts","../../../../../node_modules/@types/jest/node_modules/jest-matcher-utils/build/index.d.ts","../../../../../node_modules/@types/jest/index.d.ts"],"fileInfos":[{"version":"f20c05dbfe50a208301d2a1da37b9931bce0466eb5a1f4fe240971b4ecc82b67","affectsGlobalScope":true},"dc47c4fa66b9b9890cf076304de2a9c5201e94b740cffdf09f87296d877d71f6","7a387c58583dfca701b6c85e0adaf43fb17d590fb16d5b2dc0a2fbd89f35c467","8a12173c586e95f4433e0c6dc446bc88346be73ffe9ca6eec7aa63c8f3dca7f9","5f4e733ced4e129482ae2186aae29fde948ab7182844c3a5a51dd346182c7b06","e6b724280c694a9f588847f754198fb96c43d805f065c3a5b28bbc9594541c84","1fc5ab7a764205c68fa10d381b08417795fc73111d6dd16b5b1ed36badb743d9","746d62152361558ea6d6115cf0da4dd10ede041d14882ede3568bce5dc4b4f1f","d11a03592451da2d1065e09e61f4e2a9bf68f780f4f6623c18b57816a9679d17","aea179452def8a6152f98f63b191b84e7cbd69b0e248c91e61fb2e52328abe8c",{"version":"adb996790133eb33b33aadb9c09f15c2c575e71fb57a62de8bf74dbf59ec7dfb","affectsGlobalScope":true},{"version":"8cc8c5a3bac513368b0157f3d8b31cfdcfe78b56d3724f30f80ed9715e404af8","affectsGlobalScope":true},{"version":"cdccba9a388c2ee3fd6ad4018c640a471a6c060e96f1232062223063b0a5ac6a","affectsGlobalScope":true},{"version":"c5c05907c02476e4bde6b7e76a79ffcd948aedd14b6a8f56e4674221b0417398","affectsGlobalScope":true},{"version":"0d5f52b3174bee6edb81260ebcd792692c32c81fd55499d69531496f3f2b25e7","affectsGlobalScope":true},{"version":"55f400eec64d17e888e278f4def2f254b41b89515d3b88ad75d5e05f019daddd","affectsGlobalScope":true},{"version":"181f1784c6c10b751631b24ce60c7f78b20665db4550b335be179217bacc0d5f","affectsGlobalScope":true},{"version":"3013574108c36fd3aaca79764002b3717da09725a36a6fc02eac386593110f93","affectsGlobalScope":true},{"version":"75ec0bdd727d887f1b79ed6619412ea72ba3c81d92d0787ccb64bab18d261f14","affectsGlobalScope":true},{"version":"3be5a1453daa63e031d266bf342f3943603873d890ab8b9ada95e22389389006","affectsGlobalScope":true},{"version":"17bb1fc99591b00515502d264fa55dc8370c45c5298f4a5c2083557dccba5a2a","affectsGlobalScope":true},{"version":"7ce9f0bde3307ca1f944119f6365f2d776d281a393b576a18a2f2893a2d75c98","affectsGlobalScope":true},{"version":"6a6b173e739a6a99629a8594bfb294cc7329bfb7b227f12e1f7c11bc163b8577","affectsGlobalScope":true},{"version":"81cac4cbc92c0c839c70f8ffb94eb61e2d32dc1c3cf6d95844ca099463cf37ea","affectsGlobalScope":true},{"version":"b0124885ef82641903d232172577f2ceb5d3e60aed4da1153bab4221e1f6dd4e","affectsGlobalScope":true},{"version":"0eb85d6c590b0d577919a79e0084fa1744c1beba6fd0d4e951432fa1ede5510a","affectsGlobalScope":true},{"version":"da233fc1c8a377ba9e0bed690a73c290d843c2c3d23a7bd7ec5cd3d7d73ba1e0","affectsGlobalScope":true},{"version":"d154ea5bb7f7f9001ed9153e876b2d5b8f5c2bb9ec02b3ae0d239ec769f1f2ae","affectsGlobalScope":true},{"version":"bb2d3fb05a1d2ffbca947cc7cbc95d23e1d053d6595391bd325deb265a18d36c","affectsGlobalScope":true},{"version":"c80df75850fea5caa2afe43b9949338ce4e2de086f91713e9af1a06f973872b8","affectsGlobalScope":true},{"version":"9d57b2b5d15838ed094aa9ff1299eecef40b190722eb619bac4616657a05f951","affectsGlobalScope":true},{"version":"6c51b5dd26a2c31dbf37f00cfc32b2aa6a92e19c995aefb5b97a3a64f1ac99de","affectsGlobalScope":true},{"version":"6e7997ef61de3132e4d4b2250e75343f487903ddf5370e7ce33cf1b9db9a63ed","affectsGlobalScope":true},{"version":"2ad234885a4240522efccd77de6c7d99eecf9b4de0914adb9a35c0c22433f993","affectsGlobalScope":true},{"version":"09aa50414b80c023553090e2f53827f007a301bc34b0495bfb2c3c08ab9ad1eb","affectsGlobalScope":true},{"version":"d7f680a43f8cd12a6b6122c07c54ba40952b0c8aa140dcfcf32eb9e6cb028596","affectsGlobalScope":true},{"version":"3787b83e297de7c315d55d4a7c546ae28e5f6c0a361b7a1dcec1f1f50a54ef11","affectsGlobalScope":true},{"version":"e7e8e1d368290e9295ef18ca23f405cf40d5456fa9f20db6373a61ca45f75f40","affectsGlobalScope":true},{"version":"faf0221ae0465363c842ce6aa8a0cbda5d9296940a8e26c86e04cc4081eea21e","affectsGlobalScope":true},{"version":"06393d13ea207a1bfe08ec8d7be562549c5e2da8983f2ee074e00002629d1871","affectsGlobalScope":true},{"version":"775d9c9fd150d5de79e0450f35bc8b8f94ae64e3eb5da12725ff2a649dccc777","affectsGlobalScope":true},{"version":"b248e32ca52e8f5571390a4142558ae4f203ae2f94d5bac38a3084d529ef4e58","affectsGlobalScope":true},{"version":"6c55633c733c8378db65ac3da7a767c3cf2cf3057f0565a9124a16a3a2019e87","affectsGlobalScope":true},{"version":"fb4416144c1bf0323ccbc9afb0ab289c07312214e8820ad17d709498c865a3fe","affectsGlobalScope":true},{"version":"5b0ca94ec819d68d33da516306c15297acec88efeb0ae9e2b39f71dbd9685ef7","affectsGlobalScope":true},{"version":"34c839eaaa6d78c8674ae2c37af2236dee6831b13db7b4ef4df3ec889a04d4f2","affectsGlobalScope":true},{"version":"34478567f8a80171f88f2f30808beb7da15eac0538ae91282dd33dce928d98ed","affectsGlobalScope":true},{"version":"ab7d58e6161a550ff92e5aff755dc37fe896245348332cd5f1e1203479fe0ed1","affectsGlobalScope":true},{"version":"6bda95ea27a59a276e46043b7065b55bd4b316c25e70e29b572958fa77565d43","affectsGlobalScope":true},{"version":"aedb8de1abb2ff1095c153854a6df7deae4a5709c37297f9d6e9948b6806fa66","affectsGlobalScope":true},{"version":"a4da0551fd39b90ca7ce5f68fb55d4dc0c1396d589b612e1902f68ee090aaada","affectsGlobalScope":true},{"version":"11ffe3c281f375fff9ffdde8bbec7669b4dd671905509079f866f2354a788064","affectsGlobalScope":true},{"version":"52d1bb7ab7a3306fd0375c8bff560feed26ed676a5b0457fa8027b563aecb9a4","affectsGlobalScope":true},"72c6cda658c066bfd9f51a34a077648f11a0d8867050733f2cef365729043bf0","363f9ef6f21d68fb8daa0ec3127ea3fb2567c5583999d4846bdbbdeb6f386eb7","b49e007575f7087f2d8718cceea62a309dad06552d539c65d0bbd418b33a33b6","7a317ff3b65c289d4344ea7b6e0a9793168703a79bf1ee889b3ce379b58a54a3","4967529644e391115ca5592184d4b63980569adf60ee685f968fd59ab1557188","5929864ce17fba74232584d90cb721a89b7ad277220627cc97054ba15a98ea8f","0589c85b507c2b90458bf7f87c2aebb0879a251fa119f2464350113d93113a32","0d5a2ee1fdfa82740e0103389b9efd6bfe145a20018a2da3c02b89666181f4d9","a69c09dbea52352f479d3e7ac949fde3d17b195abe90b045d619f747b38d6d1a",{"version":"92d63add669d18ebc349efbacd88966d6f2ccdddfb1b880b2db98ae3aa7bf7c4","affectsGlobalScope":true},"ccc94049a9841fe47abe5baef6be9a38fc6228807974ae675fb15dc22531b4be",{"version":"9acfe4d1ff027015151ce81d60797b04b52bffe97ad8310bb0ec2e8fd61e1303","affectsGlobalScope":true},"95843d5cfafced8f3f8a5ce57d2335f0bcd361b9483587d12a25e4bd403b8216","afc6e96061af46bcff47246158caee7e056f5288783f2d83d6858cd25be1c565",{"version":"34f5bcac12b36d70304b73de5f5aab3bb91bd9919f984be80579ebcad03a624e","affectsGlobalScope":true},"82408ed3e959ddc60d3e9904481b5a8dc16469928257af22a3f7d1a3bc7fd8c4","2f520601649a893e6a49a8851ebfcf4be8ce090dc1281c2a08a871cb04e8251f","f50c975ab7b50e25a69e3d8a3773894125b44e9698924105f23b812bf7488baf","2b8c764f856a1dd0a9a2bf23e5efddbff157de8138b0754010be561ae5fcaa90","76650408392bf49a8fbf3e2b6b302712a92d76af77b06e2da1cc8077359c4409","0af3121e68297b2247dd331c0d24dba599e50736a7517a5622d5591aae4a3122","6972fca26f6e9bd56197568d4379f99071a90766e06b4fcb5920a0130a9202be",{"version":"4a2628e95962c8ab756121faa3ac2ed348112ff7a87b5c286dd2cc3326546b4c","affectsGlobalScope":true},"80793b2277f31baa199234daed806fff0fb11491d1ebd3357e520c3558063f00","a049a59a02009fc023684fcfaf0ac526fe36c35dcc5d2b7d620c1750ba11b083","196fee5541bfd59699dab615fee2ae7a6f5fe0a6337bcbbfd656ebf1ae329a63","160cc6e3d06938535bc887754afe5798c22d81ce83a9792ebfe2371a70f2ffc2","4b9a003b5c556c96784132945bb41c655ea11273b1917f5c8d0c154dd5fd20dd","a458dc78104cc80048ac24fdc02fe6dce254838094c2f25641b3f954d9721241",{"version":"e8b18c6385ff784228a6f369694fcf1a6b475355ba89090a88de13587a9391d5","affectsGlobalScope":true},"eecd493fc62c4dba3d988e2d7dff63299bf12ab49f5c9021dfef8dcc1ff2089e","abc1c425b2ad6720433f40f1877abfa4223f0f3dd486c9c28c492179ca183cb6","945a841f9a591197154c85386bc5a1467d42d325104bb36db51bc566bbb240be","10c39ce1df102994b47d4bc0c71aa9a6aea76f4651a5ec51914431f50bc883a1",{"version":"8207e7e6db9aa5fc7e61c8f17ba74cf9c115d26f51f91ee93f790815a7ea9dfb","affectsGlobalScope":true},"9f1069b9e2c051737b1f9b4f1baf50e4a63385a6a89c32235549ae87fc3d5492","ee18f2da7a037c6ceeb112a084e485aead9ea166980bf433474559eac1b46553","29c2706fa0cc49a2bd90c83234da33d08bb9554ecec675e91c1f85087f5a5324","0acbf26bf958f9e80c1ffa587b74749d2697b75b484062d36e103c137c562bc3","d7838022c7dab596357a9604b9c6adffe37dc34085ce0779c958ce9545bd7139","1b952304137851e45bc009785de89ada562d9376177c97e37702e39e60c2f1ff",{"version":"806ef4cac3b3d9fa4a48d849c8e084d7c72fcd7b16d76e06049a9ed742ff79c0","affectsGlobalScope":true},"a7971f9fb2a32ec7788ec6cda9d7a33c02023dfe9a62db2030ad1359649d8050","c33a6ea7147af60d8e98f1ac127047f4b0d4e2ce28b8f08ff3de07ca7cc00637",{"version":"b42b47e17b8ece2424ae8039feb944c2e3ba4b262986aebd582e51efbdca93dc","affectsGlobalScope":true},"664d8f2d59164f2e08c543981453893bc7e003e4dfd29651ce09db13e9457980","2408611d9b4146e35d1dbd1f443ccd8e187c74614a54b80300728277529dbf11","998a3de5237518c0b3ac00a11b3b4417affb008aa20aedee52f3fdae3cb86151","ad41008ffe077206e1811fc873f4d9005b5fd7f6ab52bb6118fef600815a5cb4",{"version":"daa2956e185fbca0591cb8cbe075c115301cbac7863092103f2aed6078dfb612","affectsGlobalScope":true},"badae0df9a8016ac36994b0a0e7b82ba6aaa3528e175a8c3cb161e4683eec03e","c3db860bcaaaeb3bbc23f353bbda1f8ab82756c8d5e973bebb3953cb09ea68f2","235a53595bd20b0b0eeb1a29cb2887c67c48375e92f03749b2488fbd46d0b1a0","bc09393cd4cd13f69cf1366d4236fbae5359bb550f0de4e15767e9a91d63dfb1","9c266243b01545e11d2733a55ad02b4c00ecdbda99c561cd1674f96e89cdc958","c71155c05fc76ff948a4759abc1cb9feec036509f500174bc18dad4c7827a60c",{"version":"ab9b9a36e5284fd8d3bf2f7d5fcbc60052f25f27e4d20954782099282c60d23e","affectsGlobalScope":true},"1503a452a67127e5c2da794d1c7c44344d5038373aae16c9b03ac964db159edd","25c8056edf4314820382a5fdb4bb7816999acdcb929c8f75e3f39473b87e85bc","54cb85a47d760da1c13c00add10d26b5118280d44d58e6908d8e89abbd9d7725","3e4825171442666d31c845aeb47fcd34b62e14041bb353ae2b874285d78482aa","db6c2d64e5c642b4e08a136a15ef7155452fc7072513ac5b18a03b8e8107fe45","d9bf99a360cb3dfdc87b7e4988d63115cb30bf180f2bcfd56f425d2aee49925f","2e98c8d346012b9ac4f372d5a0ba7930ec413e45822d52a833dcde4a1cca91eb","85b5d54fc8586dc83c99934f02df83954282725ffcbd6631d4aa0ec81afb8671","cadc8aced301244057c4e7e73fbcae534b0f5b12a37b150d80e5a45aa4bebcbd","385aab901643aa54e1c36f5ef3107913b10d1b5bb8cbcd933d4263b80a0d7f20","9670d44354bab9d9982eca21945686b5c24a3f893db73c0dae0fd74217a4c219","db3435f3525cd785bf21ec6769bf8da7e8a776be1a99e2e7efb5f244a2ef5fee","c3b170c45fc031db31f782e612adf7314b167e60439d304b49e704010e7bafe5","8b23b832eb8547e6ef837f2c86a2354bcc4a52f5a51b6f0c82da48dd71961bf1","80ad053918e96087d9da8d092ff9f90520c9fc199c8bfd9340266dd8f38f364e","3a84b7cb891141824bd00ef8a50b6a44596aded4075da937f180c90e362fe5f6","13f6f39e12b1518c6650bbb220c8985999020fe0f21d818e28f512b7771d00f9","9b5369969f6e7175740bf51223112ff209f94ba43ecd3bb09eefff9fd675624a","4fe9e626e7164748e8769bbf74b538e09607f07ed17c2f20af8d680ee49fc1da","24515859bc0b836719105bb6cc3d68255042a9f02a6022b3187948b204946bd2","cf01820a6625d372b406150fc8bbaaf82326dad57088a09d546df4619fcf4d2e","0db18c6e78ea846316c012478888f33c11ffadab9efd1cc8bcc12daded7a60b6","89167d696a849fce5ca508032aabfe901c0868f833a8625d5a9c6e861ef935d2","e53a3c2a9f624d90f24bf4588aacd223e7bec1b9d0d479b68d2f4a9e6011147f","339dc5265ee5ed92e536a93a04c4ebbc2128f45eeec6ed29f379e0085283542c","9f0a92164925aa37d4a5d9dd3e0134cff8177208dba55fd2310cd74beea40ee2","f436b69387a990543d96787d1671b601a1ca624c420edc53560cb3d742f132fb","2e85db9e6fd73cfa3d7f28e0ab6b55417ea18931423bd47b409a96e4a169e8e6","d32275be3546f252e3ad33976caf8c5e842c09cb87d468cb40d5f4cf092d1acc","e4da0dc0982bc3ecaed637009f74a847b8d3fe06cbcf9f5e83b8ce8b0ed5d393","51cac533b4031fe5d4fecef5635afac9c0dca87c11f5b325e49e1600a9c51117","8b5baae22d64e1c47b88bdf16025396940393cfa830c66d9f330c1701e91ba91","913754f9281683f22d98d0ba7796896cee30c302baefa3dda69f61af8de244d8","a3e5b8b86e7bd38d9afdc294875c4445c535319e288d3a13c1e2e41f9af934f2","07a8b121d8256d717a496d25387a6f6a1218a49cd3d9dc7acc210382b1425a98","c824a031b54133fd5630aa0b295668d8b26df8ce0fcd1df639f2b3baf048a510","091f417275a51ab3c47b949723e9e8a193012157ecc64a96e2d7b1505e82f395","e6d2c107b358421399671d5afc04f9a0993833121c74bcbd3648ac3a65770936","6a93055f8327fa93dd414b15b3722657ea7c12d6052367d4ff303af29aa0ac76","1302a6a8c1a2f8f0efb923f254b8bed0d8692be7f1a6cd85c5c6e59a1f366fa9","f1814927210ac162c5ae64856a992cdc62e1eec5ef41782b5996626fafba0481","65a8bb855c73a06382ee35ef73c97eb825d5a7d8958eaddeeea4838f17c8078f","5f7614d60b32dc66e5d665eafd10d7619eedca3a20f0e876e9ec73141735e364","368597e75744b2e15fc12bd72ac54a4601f6d9021c6ad8b51d428be4e2d7278d","d46671fe4a68752899ca1ebd86d30a5ec8b8f7bf8c237c5e5d25f3642afa0626","ea8b0f6227604e008a0a77929b3adb5090c34aea3a0a5de5b353952a7301c4ba","ac0e45806dfb87684696b8a268697c8e789c50e29fd285fec047830e773f9832","045748197508c31fd7bf7027b2b4a42f4c5f4f84ec39ce1e1af55ca779313456","06c179a5025fef9432eaf716e55cd080020d2710cd98bb0c3d4340e8c866ab59","beaf45afe4bc9ba652ab6d73240c5e88bc3f34b0e0161742fcf354459a7a3c3f","1d6ad485ca9dc7c5d9e2b61f20e4bd3facbeb4ef56af8f68d71ba6e4a9b9f6eb","9eecb248ca8e33c2b5b5674237bc2b8607f5662bcc03a3e025a55fbfdf069cdc","513f467aabe4b358a7a1e8391b6853bae204ab1e0eeab09278a3681a0e817873","4b0a88e606b8cca09862a7032ea969b4513fc2001c9db075c0ef15ed7625ca49","7c0ba9a5132b0fbdea735875c2990ceb36cdf2d617b0cb7e106c06b7cab53952","e4cd60d669bc6592b8bf26bfe3be5dd8a3c8038a2f86f74af9123033641c0a4c","8180a44d92e7f618789a4b26af4522321df8e8d4482445faf6d2cc6a85c95467","d1e35f1b3ee738c6cefabd665de7fcd72e3462b34c9f942fa685302d0be25922","f720a94058231196b81855293bbf4c6ee5226708e2c986d38f1fb9697f504f8a","9eda98844857a798df683958f7e57e0956cf18b4f8102bc90a3e7a8eb01189da","b7d3249cbee977a046efe0f325dc7f553f767b4a26c2360635b81ce800e7e913","539ea2f344e4fce2e77580cd7a5d7f4339926f589321231bc279960e3400772c","2e3343eebd7f317f0f12ebda5d455ece53c10b01df1cbc472c9a6425232bae2d","a4a4d800663fe45e65640e784a5973d7f56b544b7e2effbc478edc77610189f5","bb9bc38371e0c0d524420594c4128d4ec39c218f823c936e6b9892839b8ad126","1cf790bc4bef026b98cd90370d12d5d68cd845e7d055102a35ad2afa236c3d0c","e12caf7b64fa0c90bb21d5a29c17664c34a4b06cd432e4925bc4003b42e502d5","903456a035d80598a398c89af6fb6752c49703c4048af0c610fdebd2bcfd7b0c","cd95632585111aa5c5e76dc49b7781f8cdacc7660f8028c8482278c34c248fa0","ea97c663f8c9e5c5b33b008d036d901c342745cc9c0876e822d7f1ecbb87f8d0","64c55e5bbd1580a436bd34bee04f170ae2dca48cfc967fdf71aadf6171b27e64","da3ccf68e9f57491231c52b9127ec5d96c19fd4ee95a91fdb643bac31bc9a2f5","8526249c4486650b51b73ef9ae452fb6ef3254b2e73a1625c68889a9a3bfc070","44fef001b60bc425df2a36e532e867918012e5b50f5a6948c84974a25f93c99a","13756676a5ca4e5c4f0a75221a6f994a1c336cc99966a8c59fdb7ac5cbcd8f90","66d1ad7b4b9beb88809845c71ec64b8044b41700a436ec5136fcc5e0dfacdb05",{"version":"d50d5f2cc94307f9b6681ea4c48bbc28101faaaa87edfc64aab5a0a66414b586","affectsGlobalScope":true},"0d14fa22c41fdc7277e6f71473b20ebc07f40f00e38875142335d5b63cdfc9d2","d982cdd2610155b3cbcbfa62ccabcf2d2b739f821518ef113348d160ef0010d9","ffcc5500e77223169833fc6eb59b3a507944a1f89574e0a1276b0ea7fc22c4a4","22f13de9e2fe5f0f4724797abd3d34a1cdd6e47ef81fc4933fea3b8bf4ad524b","e3ba509d3dce019b3190ceb2f3fc88e2610ab717122dabd91a9efaa37804040d","cda0cb09b995489b7f4c57f168cd31b83dcbaa7aad49612734fb3c9c73f6e4f2",{"version":"1de1ad6a1929317171d8cfcd55bb2732257680c1bf89bcd53e1d46a4d8dbda22","affectsGlobalScope":true}],"options":{"allowSyntheticDefaultImports":true,"alwaysStrict":false,"esModuleInterop":true,"jsx":2,"module":1,"skipLibCheck":true,"strict":true,"target":99},"fileIdsList":[[104,189],[104],[104,143],[104,191,193],[104,191],[104,188,192],[104,190],[61,104],[64,104],[65,70,104],[66,76,77,84,93,103,104],[66,67,76,84,104],[68,104],[69,70,77,85,104],[70,93,100,104],[71,73,76,84,104],[72,104],[73,74,104],[75,76,104],[76,104],[76,77,78,93,103,104],[76,77,78,93,104],[79,84,93,103,104],[76,77,79,80,84,93,100,103,104],[79,81,93,100,103,104],[61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110],[76,82,104],[83,103,104],[73,76,84,93,104],[85,104],[86,104],[64,87,104],[88,102,104,108],[89,104],[90,104],[76,91,104],[91,92,104,106],[76,93,94,95,104],[93,95,104],[93,94,104],[96,104],[97,104],[76,98,99,104],[98,99,104],[70,84,100,104],[101,104],[84,102,104],[65,79,90,103,104],[70,104],[93,104,105],[104,106],[104,107],[65,70,76,78,87,93,103,104,106,108],[93,104,109],[93,104,111],[55,56,104],[66,104],[104,112,113,114,115,116,117,118,119,120,122,123,124,125,126,127,128,129,130,131,132,133,135,136,137,138,139],[103,104,118,122],[93,103,104,118],[100,103,104,115,118],[84,100,104],[104,111],[104,111,113],[84,103,104,115,118],[59,60,65,76,93,103,104,114,117],[59,104,116],[65,96,103,104,111,114,118],[65,104,111],[65,104,111,134],[104,111,112,113],[104,118],[104,118,125,126],[104,116,118,126,127],[104,117],[59,104,113,118],[104,118,122,126,127],[104,122],[103,104,116,118,121],[59,104,115,118,125],[65,93,104],[104,111,134],[93,104],[104,141],[77,85,86,104,171],[103,104,140,151,160,165],[61,103,104,140,151,160,162,164,171],[77,86,104,142,145,146,151],[104,145,146,147,151,153],[104,151],[104,150],[77,85,86,104,155],[104,144],[104,147,148,149,150],[104,151,157],[104,164],[104,178,184],[77,104,172,173,175,176],[78,86,104,149,173,175],[104,179],[104,178],[104,173,178,181],[86,104,173,175,178,179],[104,178,181,183,184,185],[104,178,181,183,185],[78,86,104,173,174],[54,77,86,104,149,151,159],[68,86,104],[66,104,140,151],[104,150,161,162],[104,163,166],[70,104,171],[104,167,170],[54,57,61,70,77,79,86,90,103,104,140,145,146,151,152,154,156,158,160,161,163,167,168,169]],"referencedMap":[[190,1],[189,2],[144,3],[194,4],[188,2],[192,5],[193,6],[191,7],[61,8],[62,8],[64,9],[65,10],[66,11],[67,12],[68,13],[69,14],[70,15],[71,16],[72,17],[73,18],[74,18],[75,19],[76,20],[77,21],[78,22],[63,2],[110,2],[79,23],[80,24],[81,25],[111,26],[82,27],[83,28],[84,29],[85,30],[86,31],[87,32],[88,33],[89,34],[90,35],[91,36],[92,37],[93,38],[95,39],[94,40],[96,41],[97,42],[98,43],[99,44],[100,45],[101,46],[102,47],[103,48],[104,49],[105,50],[106,51],[107,52],[108,53],[109,54],[153,55],[55,2],[57,56],[56,2],[58,2],[147,2],[143,2],[148,2],[149,2],[159,2],[157,57],[12,2],[11,2],[2,2],[13,2],[14,2],[15,2],[16,2],[17,2],[18,2],[19,2],[20,2],[3,2],[4,2],[24,2],[21,2],[22,2],[23,2],[25,2],[26,2],[27,2],[5,2],[28,2],[29,2],[30,2],[31,2],[6,2],[32,2],[33,2],[34,2],[35,2],[7,2],[36,2],[41,2],[42,2],[37,2],[38,2],[39,2],[40,2],[8,2],[46,2],[43,2],[44,2],[45,2],[47,2],[9,2],[48,2],[49,2],[50,2],[51,2],[52,2],[1,2],[10,2],[53,2],[140,58],[125,59],[132,60],[124,59],[116,61],[115,62],[138,63],[133,64],[136,65],[118,66],[117,67],[113,68],[112,69],[135,70],[114,71],[119,72],[120,2],[123,72],[59,2],[139,72],[127,73],[128,74],[130,75],[126,76],[129,77],[134,63],[121,78],[122,79],[131,80],[60,81],[137,82],[155,2],[54,83],[142,84],[141,2],[164,2],[172,85],[166,86],[165,87],[152,88],[154,89],[150,90],[162,91],[183,2],[156,92],[187,2],[145,93],[146,2],[151,94],[158,95],[178,96],[185,97],[177,98],[176,99],[174,2],[180,100],[179,101],[182,102],[181,103],[186,104],[184,105],[175,106],[160,107],[173,108],[161,109],[163,110],[167,111],[168,2],[169,112],[171,113],[170,114]],"exportedModulesMap":[[190,1],[189,2],[144,3],[194,4],[188,2],[192,5],[193,6],[191,7],[61,8],[62,8],[64,9],[65,10],[66,11],[67,12],[68,13],[69,14],[70,15],[71,16],[72,17],[73,18],[74,18],[75,19],[76,20],[77,21],[78,22],[63,2],[110,2],[79,23],[80,24],[81,25],[111,26],[82,27],[83,28],[84,29],[85,30],[86,31],[87,32],[88,33],[89,34],[90,35],[91,36],[92,37],[93,38],[95,39],[94,40],[96,41],[97,42],[98,43],[99,44],[100,45],[101,46],[102,47],[103,48],[104,49],[105,50],[106,51],[107,52],[108,53],[109,54],[153,55],[55,2],[57,56],[56,2],[58,2],[147,2],[143,2],[148,2],[149,2],[159,2],[157,57],[12,2],[11,2],[2,2],[13,2],[14,2],[15,2],[16,2],[17,2],[18,2],[19,2],[20,2],[3,2],[4,2],[24,2],[21,2],[22,2],[23,2],[25,2],[26,2],[27,2],[5,2],[28,2],[29,2],[30,2],[31,2],[6,2],[32,2],[33,2],[34,2],[35,2],[7,2],[36,2],[41,2],[42,2],[37,2],[38,2],[39,2],[40,2],[8,2],[46,2],[43,2],[44,2],[45,2],[47,2],[9,2],[48,2],[49,2],[50,2],[51,2],[52,2],[1,2],[10,2],[53,2],[140,58],[125,59],[132,60],[124,59],[116,61],[115,62],[138,63],[133,64],[136,65],[118,66],[117,67],[113,68],[112,69],[135,70],[114,71],[119,72],[120,2],[123,72],[59,2],[139,72],[127,73],[128,74],[130,75],[126,76],[129,77],[134,63],[121,78],[122,79],[131,80],[60,81],[137,82],[155,2],[54,83],[142,84],[141,2],[164,2],[172,85],[166,86],[165,87],[152,88],[154,89],[150,90],[162,91],[183,2],[156,92],[187,2],[145,93],[146,2],[151,94],[158,95],[178,96],[185,97],[177,98],[176,99],[174,2],[180,100],[179,101],[182,102],[181,103],[186,104],[184,105],[175,106],[160,107],[173,108],[161,109],[163,110],[167,111],[168,2],[169,112],[171,113],[170,114]],"semanticDiagnosticsPerFile":[190,189,144,194,188,192,193,191,61,62,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,63,110,79,80,81,111,82,83,84,85,86,87,88,89,90,91,92,93,95,94,96,97,98,99,100,101,102,103,104,105,106,107,108,109,153,55,57,56,58,147,143,148,149,159,157,12,11,2,13,14,15,16,17,18,19,20,3,4,24,21,22,23,25,26,27,5,28,29,30,31,6,32,33,34,35,7,36,41,42,37,38,39,40,8,46,43,44,45,47,9,48,49,50,51,52,1,10,53,140,125,132,124,116,115,138,133,136,118,117,113,112,135,114,119,120,123,59,139,127,128,130,126,129,134,121,122,131,60,137,155,54,142,141,164,172,166,165,152,154,150,162,183,156,187,145,146,151,158,178,185,177,176,174,180,179,182,181,186,184,175,160,173,161,163,167,168,169,171,170],"affectedFilesPendingEmit":[[190,1],[189,1],[144,1],[194,1],[188,1],[192,1],[193,1],[191,1],[61,1],[62,1],[64,1],[65,1],[66,1],[67,1],[68,1],[69,1],[70,1],[71,1],[72,1],[73,1],[74,1],[75,1],[76,1],[77,1],[78,1],[63,1],[110,1],[79,1],[80,1],[81,1],[111,1],[82,1],[83,1],[84,1],[85,1],[86,1],[87,1],[88,1],[89,1],[90,1],[91,1],[92,1],[93,1],[95,1],[94,1],[96,1],[97,1],[98,1],[99,1],[100,1],[101,1],[102,1],[103,1],[104,1],[105,1],[106,1],[107,1],[108,1],[109,1],[153,1],[55,1],[57,1],[56,1],[58,1],[147,1],[143,1],[148,1],[149,1],[159,1],[157,1],[2,1],[3,1],[4,1],[5,1],[6,1],[7,1],[8,1],[9,1],[10,1],[140,1],[125,1],[132,1],[124,1],[116,1],[115,1],[138,1],[133,1],[136,1],[118,1],[117,1],[113,1],[112,1],[135,1],[114,1],[119,1],[120,1],[123,1],[59,1],[139,1],[127,1],[128,1],[130,1],[126,1],[129,1],[134,1],[121,1],[122,1],[131,1],[60,1],[137,1],[155,1],[54,1],[142,1],[141,1],[164,1],[172,1],[166,1],[165,1],[152,1],[154,1],[150,1],[162,1],[183,1],[156,1],[187,1],[145,1],[146,1],[151,1],[158,1],[178,1],[185,1],[177,1],[176,1],[174,1],[180,1],[179,1],[182,1],[181,1],[186,1],[184,1],[175,1],[160,1],[173,1],[161,1],[163,1],[167,1],[168,1],[169,1],[171,1],[170,1]]},"version":"4.8.4"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { existsSync, lstatSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { FatalError } from "../errors";
|
|
4
|
+
import { logger } from "../logger";
|
|
5
|
+
import { isInPagesCI } from "./constants";
|
|
6
|
+
import { optimizeRoutesJSONSpec } from "./functions/routes-transformation";
|
|
7
|
+
import { validateRoutes } from "./functions/routes-validation";
|
|
8
|
+
import { pagesBetaWarning } from "./utils";
|
|
9
|
+
import type {
|
|
10
|
+
CommonYargsArgv,
|
|
11
|
+
StrictYargsOptionsToInterface,
|
|
12
|
+
} from "../yargs-types";
|
|
13
|
+
|
|
14
|
+
type OptimizeRoutesArgs = StrictYargsOptionsToInterface<
|
|
15
|
+
typeof OptimizeRoutesOptions
|
|
16
|
+
>;
|
|
17
|
+
|
|
18
|
+
export function OptimizeRoutesOptions(yargs: CommonYargsArgv) {
|
|
19
|
+
return yargs
|
|
20
|
+
.options({
|
|
21
|
+
"routes-path": {
|
|
22
|
+
type: "string",
|
|
23
|
+
demandOption: true,
|
|
24
|
+
description: "The location of the _routes.json file",
|
|
25
|
+
},
|
|
26
|
+
})
|
|
27
|
+
.options({
|
|
28
|
+
"output-routes-path": {
|
|
29
|
+
type: "string",
|
|
30
|
+
demandOption: true,
|
|
31
|
+
description: "The location of the optimized output routes file",
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function OptimizeRoutesHandler({
|
|
37
|
+
routesPath,
|
|
38
|
+
outputRoutesPath,
|
|
39
|
+
}: OptimizeRoutesArgs) {
|
|
40
|
+
if (!isInPagesCI) {
|
|
41
|
+
// Beta message for `wrangler pages <commands>` usage
|
|
42
|
+
logger.log(pagesBetaWarning);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
let routesFileContents: string;
|
|
46
|
+
const routesOutputDirectory = path.dirname(outputRoutesPath);
|
|
47
|
+
|
|
48
|
+
if (!existsSync(routesPath)) {
|
|
49
|
+
throw new FatalError(
|
|
50
|
+
`Oops! File ${routesPath} does not exist. Please make sure --routes-path is a valid file path (for example "/public/_routes.json").`,
|
|
51
|
+
1
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (
|
|
56
|
+
!existsSync(routesOutputDirectory) ||
|
|
57
|
+
!lstatSync(routesOutputDirectory).isDirectory()
|
|
58
|
+
) {
|
|
59
|
+
throw new FatalError(
|
|
60
|
+
`Oops! Folder ${routesOutputDirectory} does not exist. Please make sure --output-routes-path is a valid file path (for example "/public/_routes.json").`,
|
|
61
|
+
1
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
try {
|
|
66
|
+
routesFileContents = readFileSync(routesPath, "utf-8");
|
|
67
|
+
} catch (err) {
|
|
68
|
+
throw new FatalError(`Error while reading ${routesPath} file: ${err}`);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const routes = JSON.parse(routesFileContents);
|
|
72
|
+
|
|
73
|
+
validateRoutes(routes, routesPath);
|
|
74
|
+
|
|
75
|
+
const optimizedRoutes = optimizeRoutesJSONSpec(routes);
|
|
76
|
+
const optimizedRoutesContents = JSON.stringify(optimizedRoutes);
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
writeFileSync(outputRoutesPath, optimizedRoutesContents);
|
|
80
|
+
} catch (err) {
|
|
81
|
+
throw new FatalError(
|
|
82
|
+
`Error writing to ${outputRoutesPath} file: ${err}`,
|
|
83
|
+
1
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { extname } from "node:path";
|
|
3
|
+
import { hash as blake3hash } from "blake3-wasm";
|
|
4
|
+
|
|
5
|
+
export const hashFile = (filepath: string) => {
|
|
6
|
+
const contents = readFileSync(filepath);
|
|
7
|
+
const base64Contents = contents.toString("base64");
|
|
8
|
+
const extension = extname(filepath).substring(1);
|
|
9
|
+
|
|
10
|
+
return blake3hash(base64Contents + extension)
|
|
11
|
+
.toString("hex")
|
|
12
|
+
.slice(0, 32);
|
|
13
|
+
};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/* eslint-disable no-shadow */
|
|
2
|
+
|
|
3
|
+
import * as Build from "./build";
|
|
4
|
+
import * as DeploymentTails from "./deployment-tails";
|
|
5
|
+
import * as Deployments from "./deployments";
|
|
6
|
+
import * as Dev from "./dev";
|
|
7
|
+
import * as Functions from "./functions";
|
|
8
|
+
import * as Projects from "./projects";
|
|
9
|
+
import * as Publish from "./publish";
|
|
10
|
+
import * as Upload from "./upload";
|
|
11
|
+
import { CLEANUP, pagesBetaWarning } from "./utils";
|
|
12
|
+
import type { CommonYargsArgv } from "../yargs-types";
|
|
13
|
+
|
|
14
|
+
process.on("SIGINT", () => {
|
|
15
|
+
CLEANUP();
|
|
16
|
+
process.exit();
|
|
17
|
+
});
|
|
18
|
+
process.on("SIGTERM", () => {
|
|
19
|
+
CLEANUP();
|
|
20
|
+
process.exit();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export function pages(yargs: CommonYargsArgv) {
|
|
24
|
+
return (
|
|
25
|
+
yargs
|
|
26
|
+
.command(
|
|
27
|
+
"dev [directory] [-- command..]",
|
|
28
|
+
"🧑💻 Develop your full-stack Pages application locally",
|
|
29
|
+
Dev.Options,
|
|
30
|
+
Dev.Handler
|
|
31
|
+
)
|
|
32
|
+
/**
|
|
33
|
+
* `wrangler pages functions` is meant for internal use only for now,
|
|
34
|
+
* so let's hide this command from the help output
|
|
35
|
+
*/
|
|
36
|
+
.command("functions", false, (yargs) =>
|
|
37
|
+
yargs
|
|
38
|
+
.command(
|
|
39
|
+
"build [directory]",
|
|
40
|
+
"Compile a folder of Cloudflare Pages Functions into a single Worker",
|
|
41
|
+
Build.Options,
|
|
42
|
+
Build.Handler
|
|
43
|
+
)
|
|
44
|
+
.command(
|
|
45
|
+
"optimize-routes [routesPath] [outputRoutesPath]",
|
|
46
|
+
"Consolidate and optimize the route paths declared in _routes.json",
|
|
47
|
+
Functions.OptimizeRoutesOptions,
|
|
48
|
+
Functions.OptimizeRoutesHandler
|
|
49
|
+
)
|
|
50
|
+
)
|
|
51
|
+
.command("project", "⚡️ Interact with your Pages projects", (yargs) =>
|
|
52
|
+
yargs
|
|
53
|
+
.command(
|
|
54
|
+
"list",
|
|
55
|
+
"List your Cloudflare Pages projects",
|
|
56
|
+
Projects.ListOptions,
|
|
57
|
+
Projects.ListHandler
|
|
58
|
+
)
|
|
59
|
+
.command(
|
|
60
|
+
"create [project-name]",
|
|
61
|
+
"Create a new Cloudflare Pages project",
|
|
62
|
+
Projects.CreateOptions,
|
|
63
|
+
Projects.CreateHandler
|
|
64
|
+
)
|
|
65
|
+
.command("upload [directory]", false, Upload.Options, Upload.Handler)
|
|
66
|
+
.epilogue(pagesBetaWarning)
|
|
67
|
+
)
|
|
68
|
+
.command(
|
|
69
|
+
"deployment",
|
|
70
|
+
"🚀 Interact with the deployments of a project",
|
|
71
|
+
(yargs) =>
|
|
72
|
+
yargs
|
|
73
|
+
.command(
|
|
74
|
+
"list",
|
|
75
|
+
"List deployments in your Cloudflare Pages project",
|
|
76
|
+
Deployments.ListOptions,
|
|
77
|
+
Deployments.ListHandler
|
|
78
|
+
)
|
|
79
|
+
.command(
|
|
80
|
+
"create [directory]",
|
|
81
|
+
"🆙 Publish a directory of static assets as a Pages deployment",
|
|
82
|
+
Publish.Options,
|
|
83
|
+
Publish.Handler
|
|
84
|
+
)
|
|
85
|
+
.command(
|
|
86
|
+
"tail [deployment]",
|
|
87
|
+
"Start a tailing session for a project's deployment and " +
|
|
88
|
+
"livestream logs from your Functions",
|
|
89
|
+
DeploymentTails.Options,
|
|
90
|
+
DeploymentTails.Handler
|
|
91
|
+
)
|
|
92
|
+
.epilogue(pagesBetaWarning)
|
|
93
|
+
)
|
|
94
|
+
.command(
|
|
95
|
+
"publish [directory]",
|
|
96
|
+
"🆙 Publish a directory of static assets as a Pages deployment",
|
|
97
|
+
Publish.Options,
|
|
98
|
+
Publish.Handler
|
|
99
|
+
)
|
|
100
|
+
.epilogue(pagesBetaWarning)
|
|
101
|
+
);
|
|
102
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { execSync } from "node:child_process";
|
|
2
|
+
import Table from "ink-table";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { format as timeagoFormat } from "timeago.js";
|
|
5
|
+
import { fetchResult } from "../cfetch";
|
|
6
|
+
import { getConfigCache, saveToConfigCache } from "../config-cache";
|
|
7
|
+
import { prompt } from "../dialogs";
|
|
8
|
+
import { FatalError } from "../errors";
|
|
9
|
+
import { logger } from "../logger";
|
|
10
|
+
import * as metrics from "../metrics";
|
|
11
|
+
import { requireAuth } from "../user";
|
|
12
|
+
import { renderToString } from "../utils/render";
|
|
13
|
+
import { PAGES_CONFIG_CACHE_FILENAME } from "./constants";
|
|
14
|
+
import { pagesBetaWarning } from "./utils";
|
|
15
|
+
import type {
|
|
16
|
+
CommonYargsArgv,
|
|
17
|
+
StrictYargsOptionsToInterface,
|
|
18
|
+
} from "../yargs-types";
|
|
19
|
+
import type { PagesConfigCache, Project } from "./types";
|
|
20
|
+
|
|
21
|
+
export function ListOptions(yargs: CommonYargsArgv) {
|
|
22
|
+
return yargs.epilogue(pagesBetaWarning);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function ListHandler() {
|
|
26
|
+
const config = getConfigCache<PagesConfigCache>(PAGES_CONFIG_CACHE_FILENAME);
|
|
27
|
+
|
|
28
|
+
const accountId = await requireAuth(config);
|
|
29
|
+
|
|
30
|
+
const projects: Array<Project> = await listProjects({ accountId });
|
|
31
|
+
|
|
32
|
+
const data = projects.map((project) => {
|
|
33
|
+
return {
|
|
34
|
+
"Project Name": project.name,
|
|
35
|
+
"Project Domains": `${project.domains.join(", ")}`,
|
|
36
|
+
"Git Provider": project.source ? "Yes" : "No",
|
|
37
|
+
"Last Modified": project.latest_deployment
|
|
38
|
+
? timeagoFormat(project.latest_deployment.modified_on)
|
|
39
|
+
: timeagoFormat(project.created_on),
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
saveToConfigCache<PagesConfigCache>(PAGES_CONFIG_CACHE_FILENAME, {
|
|
44
|
+
account_id: accountId,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
logger.log(renderToString(<Table data={data}></Table>));
|
|
48
|
+
await metrics.sendMetricsEvent("list pages projects");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const listProjects = async ({
|
|
52
|
+
accountId,
|
|
53
|
+
}: {
|
|
54
|
+
accountId: string;
|
|
55
|
+
}): Promise<Array<Project>> => {
|
|
56
|
+
const pageSize = 10;
|
|
57
|
+
let page = 1;
|
|
58
|
+
const results = [];
|
|
59
|
+
while (results.length % pageSize === 0) {
|
|
60
|
+
const json: Array<Project> = await fetchResult(
|
|
61
|
+
`/accounts/${accountId}/pages/projects`,
|
|
62
|
+
{},
|
|
63
|
+
new URLSearchParams({
|
|
64
|
+
per_page: pageSize.toString(),
|
|
65
|
+
page: page.toString(),
|
|
66
|
+
})
|
|
67
|
+
);
|
|
68
|
+
page++;
|
|
69
|
+
results.push(...json);
|
|
70
|
+
if (json.length < pageSize) {
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return results;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export function CreateOptions(yargs: CommonYargsArgv) {
|
|
78
|
+
return yargs
|
|
79
|
+
.positional("project-name", {
|
|
80
|
+
type: "string",
|
|
81
|
+
demandOption: true,
|
|
82
|
+
description: "The name of your Pages project",
|
|
83
|
+
})
|
|
84
|
+
.options({
|
|
85
|
+
"production-branch": {
|
|
86
|
+
type: "string",
|
|
87
|
+
description: "The name of the production branch of your project",
|
|
88
|
+
},
|
|
89
|
+
})
|
|
90
|
+
.epilogue(pagesBetaWarning);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export async function CreateHandler({
|
|
94
|
+
productionBranch,
|
|
95
|
+
projectName,
|
|
96
|
+
}: StrictYargsOptionsToInterface<typeof CreateOptions>) {
|
|
97
|
+
const config = getConfigCache<PagesConfigCache>(PAGES_CONFIG_CACHE_FILENAME);
|
|
98
|
+
const accountId = await requireAuth(config);
|
|
99
|
+
|
|
100
|
+
const isInteractive = process.stdin.isTTY;
|
|
101
|
+
if (!projectName && isInteractive) {
|
|
102
|
+
projectName = await prompt("Enter the name of your new project:");
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (!projectName) {
|
|
106
|
+
throw new FatalError("Must specify a project name.", 1);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (!productionBranch && isInteractive) {
|
|
110
|
+
let isGitDir = true;
|
|
111
|
+
try {
|
|
112
|
+
execSync(`git rev-parse --is-inside-work-tree`, {
|
|
113
|
+
stdio: "ignore",
|
|
114
|
+
});
|
|
115
|
+
} catch (err) {
|
|
116
|
+
isGitDir = false;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (isGitDir) {
|
|
120
|
+
try {
|
|
121
|
+
productionBranch = execSync(`git rev-parse --abbrev-ref HEAD`)
|
|
122
|
+
.toString()
|
|
123
|
+
.trim();
|
|
124
|
+
} catch (err) {}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
productionBranch = await prompt("Enter the production branch name:", {
|
|
128
|
+
defaultValue: productionBranch ?? "production",
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (!productionBranch) {
|
|
133
|
+
throw new FatalError("Must specify a production branch.", 1);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const { subdomain } = await fetchResult<Project>(
|
|
137
|
+
`/accounts/${accountId}/pages/projects`,
|
|
138
|
+
{
|
|
139
|
+
method: "POST",
|
|
140
|
+
body: JSON.stringify({
|
|
141
|
+
name: projectName,
|
|
142
|
+
production_branch: productionBranch,
|
|
143
|
+
}),
|
|
144
|
+
}
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
saveToConfigCache<PagesConfigCache>(PAGES_CONFIG_CACHE_FILENAME, {
|
|
148
|
+
account_id: accountId,
|
|
149
|
+
project_name: projectName,
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
logger.log(
|
|
153
|
+
`✨ Successfully created the '${projectName}' project. It will be available at https://${subdomain}/ once you create your first deployment.`
|
|
154
|
+
);
|
|
155
|
+
logger.log(
|
|
156
|
+
`To deploy a folder of assets, run 'wrangler pages publish [directory]'.`
|
|
157
|
+
);
|
|
158
|
+
await metrics.sendMetricsEvent("create pages project");
|
|
159
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { render, Text } from "ink";
|
|
2
|
+
import SelectInput from "ink-select-input";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { listProjects } from "./projects";
|
|
5
|
+
|
|
6
|
+
export async function promptSelectProject({
|
|
7
|
+
accountId,
|
|
8
|
+
}: {
|
|
9
|
+
accountId: string;
|
|
10
|
+
}): Promise<string> {
|
|
11
|
+
const projects = await listProjects({ accountId });
|
|
12
|
+
|
|
13
|
+
return new Promise((resolve) => {
|
|
14
|
+
const { unmount } = render(
|
|
15
|
+
<>
|
|
16
|
+
<Text>Select a project:</Text>
|
|
17
|
+
<SelectInput
|
|
18
|
+
items={projects.map((project) => ({
|
|
19
|
+
key: project.name,
|
|
20
|
+
label: project.name,
|
|
21
|
+
value: project,
|
|
22
|
+
}))}
|
|
23
|
+
onSelect={async (selected) => {
|
|
24
|
+
resolve(selected.value.name);
|
|
25
|
+
unmount();
|
|
26
|
+
}}
|
|
27
|
+
/>
|
|
28
|
+
</>
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
}
|