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/deprecated/index.ts
CHANGED
|
@@ -1,310 +1,16 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
1
|
import { DeprecationError } from "../errors";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
CommandLineArgsError,
|
|
7
|
-
createCLIParser,
|
|
8
|
-
printWranglerBanner,
|
|
9
|
-
} from "../index";
|
|
10
|
-
import { initHandler } from "../init";
|
|
2
|
+
import { createCLIParser } from "../index";
|
|
11
3
|
import { logger } from "../logger";
|
|
12
4
|
import { formatMessage } from "../parse";
|
|
13
5
|
import type {
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
CommonYargsArgv,
|
|
7
|
+
StrictYargsOptionsToInterface,
|
|
16
8
|
} from "../yargs-types";
|
|
17
|
-
import type { Argv, ArgumentsCamelCase, BuilderCallback } from "yargs";
|
|
18
9
|
|
|
19
|
-
|
|
20
|
-
interface GenerateArgs {
|
|
21
|
-
name?: string;
|
|
22
|
-
template?: string;
|
|
23
|
-
type?: string;
|
|
24
|
-
site?: boolean;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function generateOptions(yargs: Argv<CommonYargsOptions>) {
|
|
28
|
-
return yargs
|
|
29
|
-
.positional("name", {
|
|
30
|
-
describe: "Name of the Workers project",
|
|
31
|
-
type: "string",
|
|
32
|
-
})
|
|
33
|
-
.positional("template", {
|
|
34
|
-
type: "string",
|
|
35
|
-
describe: "The URL of a GitHub template",
|
|
36
|
-
})
|
|
37
|
-
.option("type", {
|
|
38
|
-
alias: "t",
|
|
39
|
-
type: "string",
|
|
40
|
-
hidden: true,
|
|
41
|
-
deprecated: true,
|
|
42
|
-
})
|
|
43
|
-
.option("site", {
|
|
44
|
-
alias: "s",
|
|
45
|
-
type: "boolean",
|
|
46
|
-
hidden: true,
|
|
47
|
-
deprecated: true,
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export async function generateHandler({
|
|
52
|
-
// somehow, `init` marks name as required but then also runs fine
|
|
53
|
-
// with the name omitted, and then substitutes it at runtime with ""
|
|
54
|
-
name = "",
|
|
55
|
-
template,
|
|
56
|
-
type,
|
|
57
|
-
site,
|
|
58
|
-
...args
|
|
59
|
-
}: ArgumentsCamelCase<GenerateArgs>) {
|
|
60
|
-
// delegate to `wrangler init` if no template is specified
|
|
61
|
-
if (template === undefined) {
|
|
62
|
-
return initHandler({ name, ...args });
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// print down here cuz `init` prints it own its own
|
|
66
|
-
await printWranglerBanner();
|
|
67
|
-
|
|
68
|
-
if (type) {
|
|
69
|
-
let message = "The --type option is no longer supported.";
|
|
70
|
-
if (args.type === "webpack") {
|
|
71
|
-
message +=
|
|
72
|
-
"\nIf you wish to use webpack then you will need to create a custom build.";
|
|
73
|
-
// TODO: Add a link to docs
|
|
74
|
-
}
|
|
75
|
-
throw new CommandLineArgsError(message);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (isRemote(name)) {
|
|
79
|
-
[template, name] = [name, template];
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const creationDirectory = generateWorkerDirectoryName(name);
|
|
83
|
-
|
|
84
|
-
if (site) {
|
|
85
|
-
const gitDirectory =
|
|
86
|
-
creationDirectory !== process.cwd()
|
|
87
|
-
? path.basename(creationDirectory)
|
|
88
|
-
: "my-site";
|
|
89
|
-
const message =
|
|
90
|
-
"The --site option is no longer supported.\n" +
|
|
91
|
-
"If you wish to create a brand new Worker Sites project then clone the `worker-sites-template` starter repository:\n\n" +
|
|
92
|
-
"```\n" +
|
|
93
|
-
`git clone --depth=1 --branch=wrangler2 https://github.com/cloudflare/worker-sites-template ${gitDirectory}\n` +
|
|
94
|
-
`cd ${gitDirectory}\n` +
|
|
95
|
-
"```\n\n" +
|
|
96
|
-
"Find out more about how to create and maintain Sites projects at https://developers.cloudflare.com/workers/platform/sites.\n" +
|
|
97
|
-
"Have you considered using Cloudflare Pages instead? See https://pages.cloudflare.com/.";
|
|
98
|
-
throw new CommandLineArgsError(message);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
logger.log(
|
|
102
|
-
`Creating a worker in ${path.basename(creationDirectory)} from ${template}`
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
const { remote, subdirectory } = parseTemplatePath(template);
|
|
106
|
-
|
|
107
|
-
await cloneIntoDirectory(remote, creationDirectory, subdirectory);
|
|
108
|
-
await initializeGit(creationDirectory);
|
|
109
|
-
|
|
110
|
-
logger.log("✨ Success!");
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Creates a path based on the current working directory and a worker name.
|
|
115
|
-
* Automatically increments a counter when searching for an available directory.
|
|
116
|
-
*
|
|
117
|
-
* Running `wrangler generate worker https://some-git-repo` in a directory
|
|
118
|
-
* with the structure:
|
|
119
|
-
* ```
|
|
120
|
-
* - workers
|
|
121
|
-
* |
|
|
122
|
-
* | - worker
|
|
123
|
-
* | | - wrangler.toml
|
|
124
|
-
* | | ...
|
|
125
|
-
* |
|
|
126
|
-
* | - worker-1
|
|
127
|
-
* | | - wrangler.toml
|
|
128
|
-
* | | ...
|
|
129
|
-
* ```
|
|
130
|
-
*
|
|
131
|
-
* will result in a new worker called `worker-2` being generated.
|
|
132
|
-
*
|
|
133
|
-
* @param workerName the name of the generated worker
|
|
134
|
-
* @returns an absolute path to the directory to generate the worker into
|
|
135
|
-
*/
|
|
136
|
-
function generateWorkerDirectoryName(workerName: string): string {
|
|
137
|
-
let workerDirectoryPath = path.resolve(process.cwd(), workerName);
|
|
138
|
-
let i = 1;
|
|
139
|
-
|
|
140
|
-
while (fs.existsSync(workerDirectoryPath)) {
|
|
141
|
-
workerDirectoryPath = path.resolve(process.cwd(), `${workerName}-${i}`);
|
|
142
|
-
i++;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
return workerDirectoryPath;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Checks if an arg is a template, which can be useful if the order
|
|
150
|
-
* of template & worker name args is switched
|
|
151
|
-
*
|
|
152
|
-
* @param arg a template to generate from, or a folder to generate into
|
|
153
|
-
* @returns true if the given arg was remote (a template)
|
|
154
|
-
*/
|
|
155
|
-
function isRemote(arg: string) {
|
|
156
|
-
return /^(https?|ftps?|file|git|ssh):\/\//.test(arg) || arg.includes(":");
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* unreadable regex basically copied from degit. i put some named capture groups in,
|
|
161
|
-
* but uhh...there's not much to do short of using pomsky or some other tool.
|
|
162
|
-
*
|
|
163
|
-
* notably: this only supports `https://` and `git@` urls,
|
|
164
|
-
* and is missing support for:
|
|
165
|
-
* - `http`
|
|
166
|
-
* - `ftp(s)`
|
|
167
|
-
* - `file`
|
|
168
|
-
* - `ssh`
|
|
169
|
-
*/
|
|
170
|
-
const TEMPLATE_REGEX =
|
|
171
|
-
/^(?:(?:https:\/\/)?(?<httpsUrl>[^:/]+\.[^:/]+)\/|git@(?<gitUrl>[^:/]+)[:/]|(?<shorthandUrl>[^/]+):)?(?<user>[^/\s]+)\/(?<repository>[^/\s#]+)(?:(?<subdirectoryPath>(?:\/[^/\s#]+)+))?(?:\/)?(?:#(?<tag>.+))?/;
|
|
172
|
-
|
|
173
|
-
// there are a few URL formats we support:
|
|
174
|
-
// - `user/repo` -> assume github, use "https://github.com/user/repo.git"
|
|
175
|
-
// - `https://<httpsUrl>
|
|
176
|
-
// - `git@<gitUrl>`
|
|
177
|
-
// - `(bb|bitbucket|gh|github|gl|gitlab):user/repo` -> parse shorthand into https url
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* There's no URL, so assume a github repo
|
|
181
|
-
*/
|
|
182
|
-
type NoUrl = {
|
|
183
|
-
httpsUrl: undefined;
|
|
184
|
-
gitUrl: undefined;
|
|
185
|
-
shorthandUrl: undefined;
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* A https url (e.g. https://bitbucket.org/user/repo)
|
|
190
|
-
*/
|
|
191
|
-
type HttpsUrl = Omit<NoUrl, "httpsUrl"> & { httpsUrl: string };
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* A git url (e.g. git@gitlab.com:user/repo)
|
|
195
|
-
*/
|
|
196
|
-
type GitUrl = Omit<NoUrl, "gitUrl"> & { gitUrl: string };
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* A shorthand url (e.g. github:user/repo)
|
|
200
|
-
*/
|
|
201
|
-
type ShorthandUrl = Omit<NoUrl, "shorthandUrl"> & { shorthandUrl: string };
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Union of all possible URL groups. Exactly one will be present, the rest
|
|
205
|
-
* will be `undefined`.
|
|
206
|
-
*/
|
|
207
|
-
type TemplateRegexUrlGroup = NoUrl | HttpsUrl | GitUrl | ShorthandUrl;
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Possible matches of `TEMPLATE_REGEX` against a passed-in template arg
|
|
211
|
-
*/
|
|
212
|
-
type TemplateRegexGroups = {
|
|
213
|
-
/** The user the repo is under */
|
|
214
|
-
user: string;
|
|
215
|
-
|
|
216
|
-
/** The repo name */
|
|
217
|
-
repository: string;
|
|
218
|
-
|
|
219
|
-
/** Optional, path to subdirectory containing template. Begins with `/` */
|
|
220
|
-
subdirectoryPath?: string;
|
|
221
|
-
|
|
222
|
-
/** Optional tag (or branch, etc.) to clone */
|
|
223
|
-
tag?: string;
|
|
224
|
-
} & TemplateRegexUrlGroup;
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* Parses a regex match on any of the URL groups into a URL base
|
|
228
|
-
*
|
|
229
|
-
* @param urlGroup a regex hit for a URL of any sort
|
|
230
|
-
* @returns the protocol and domain name of the url to clone from
|
|
231
|
-
*/
|
|
232
|
-
function toUrlBase({ httpsUrl, gitUrl, shorthandUrl }: TemplateRegexUrlGroup) {
|
|
233
|
-
if (httpsUrl !== undefined) {
|
|
234
|
-
return `https://${httpsUrl}`;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
if (gitUrl !== undefined) {
|
|
238
|
-
return `git@${gitUrl}`;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
if (shorthandUrl !== undefined) {
|
|
242
|
-
switch (shorthandUrl) {
|
|
243
|
-
case "github":
|
|
244
|
-
case "gh":
|
|
245
|
-
return "https://github.com";
|
|
246
|
-
case "gitlab":
|
|
247
|
-
case "gl":
|
|
248
|
-
return "https://gitlab.com";
|
|
249
|
-
case "bitbucket":
|
|
250
|
-
case "bb":
|
|
251
|
-
return "https://bitbucket.org";
|
|
252
|
-
default:
|
|
253
|
-
throw new Error(
|
|
254
|
-
`Unable to parse shorthand ${shorthandUrl}. Supported options are "bitbucket" ("bb"), "github" ("gh"), and "gitlab" ("gl")`
|
|
255
|
-
);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
return "https://github.com";
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Parses a template string (e.g. "user/repo", "github:user/repo/path/to/subdirectory")
|
|
264
|
-
* into a remote URL to clone from and an optional subdirectory to filter for
|
|
265
|
-
*
|
|
266
|
-
* @param templatePath the template string to parse
|
|
267
|
-
* @returns an object containing the remote url and an optional subdirectory to clone
|
|
268
|
-
*/
|
|
269
|
-
function parseTemplatePath(templatePath: string): {
|
|
270
|
-
remote: string;
|
|
271
|
-
subdirectory?: string;
|
|
272
|
-
} {
|
|
273
|
-
if (!templatePath.includes("/")) {
|
|
274
|
-
// template is a cloudflare canonical template, it doesn't include a slash in the name
|
|
275
|
-
return {
|
|
276
|
-
remote: "https://github.com/cloudflare/templates.git",
|
|
277
|
-
subdirectory: templatePath,
|
|
278
|
-
};
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
const groups = TEMPLATE_REGEX.exec(templatePath)?.groups as unknown as
|
|
282
|
-
| TemplateRegexGroups
|
|
283
|
-
| undefined;
|
|
284
|
-
|
|
285
|
-
if (!groups) {
|
|
286
|
-
throw new Error(`Unable to parse ${templatePath} as a template`);
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
const { user, repository, subdirectoryPath, tag, ...urlGroups } = groups;
|
|
290
|
-
|
|
291
|
-
const urlBase = toUrlBase(urlGroups);
|
|
292
|
-
const isHttp = urlBase.startsWith("http");
|
|
293
|
-
|
|
294
|
-
const remote = `${urlBase}${isHttp ? "/" : ":"}${user}/${repository}.git${
|
|
295
|
-
tag ? `#${tag}` : ""
|
|
296
|
-
}`;
|
|
297
|
-
|
|
298
|
-
// remove starting /
|
|
299
|
-
const subdirectory = subdirectoryPath?.slice(1);
|
|
300
|
-
|
|
301
|
-
return { remote, subdirectory };
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
export function buildOptions(yargs: Argv<CommonYargsOptions>) {
|
|
10
|
+
export function buildOptions(yargs: CommonYargsArgv) {
|
|
305
11
|
return yargs;
|
|
306
12
|
}
|
|
307
|
-
type BuildArgs =
|
|
13
|
+
type BuildArgs = StrictYargsOptionsToInterface<typeof buildOptions>;
|
|
308
14
|
export async function buildHandler(buildArgs: BuildArgs) {
|
|
309
15
|
// "[DEPRECATED] 🦀 Build your project (if applicable)",
|
|
310
16
|
|
|
@@ -340,7 +46,7 @@ export const configHandler = () => {
|
|
|
340
46
|
);
|
|
341
47
|
};
|
|
342
48
|
|
|
343
|
-
export function previewOptions(yargs:
|
|
49
|
+
export function previewOptions(yargs: CommonYargsArgv) {
|
|
344
50
|
return yargs
|
|
345
51
|
.positional("method", {
|
|
346
52
|
type: "string",
|
|
@@ -364,7 +70,7 @@ export function previewHandler() {
|
|
|
364
70
|
);
|
|
365
71
|
}
|
|
366
72
|
|
|
367
|
-
export const route
|
|
73
|
+
export const route = (routeYargs: CommonYargsArgv) => {
|
|
368
74
|
return routeYargs
|
|
369
75
|
.command(
|
|
370
76
|
"list",
|
|
@@ -427,7 +133,7 @@ export const routeHandler = () => {
|
|
|
427
133
|
throw new DeprecationError(`${deprecationNotice}\n${shouldDo}`);
|
|
428
134
|
};
|
|
429
135
|
|
|
430
|
-
export const subdomainOptions = (yargs:
|
|
136
|
+
export const subdomainOptions = (yargs: CommonYargsArgv) => {
|
|
431
137
|
return yargs.positional("name", { type: "string" });
|
|
432
138
|
};
|
|
433
139
|
|
package/src/dev/dev.tsx
CHANGED
|
@@ -28,7 +28,7 @@ import type { Config } from "../config";
|
|
|
28
28
|
import type { Route } from "../config/environment";
|
|
29
29
|
import type { WorkerRegistry } from "../dev-registry";
|
|
30
30
|
import type { Entry } from "../entry";
|
|
31
|
-
import type { EnablePagesAssetsServiceBindingOptions } from "../miniflare-cli";
|
|
31
|
+
import type { EnablePagesAssetsServiceBindingOptions } from "../miniflare-cli/types";
|
|
32
32
|
import type { AssetPaths } from "../sites";
|
|
33
33
|
import type { CfWorkerInit } from "../worker";
|
|
34
34
|
|
|
@@ -55,7 +55,7 @@ function useDevRegistry(
|
|
|
55
55
|
|
|
56
56
|
const interval =
|
|
57
57
|
// TODO: enable this for remote mode as well
|
|
58
|
-
// https://github.com/cloudflare/
|
|
58
|
+
// https://github.com/cloudflare/workers-sdk/issues/1182
|
|
59
59
|
mode === "local"
|
|
60
60
|
? setInterval(() => {
|
|
61
61
|
getBoundRegisteredWorkers({
|
|
@@ -116,6 +116,7 @@ export type DevProps = {
|
|
|
116
116
|
initialPort: number;
|
|
117
117
|
initialIp: string;
|
|
118
118
|
inspectorPort: number;
|
|
119
|
+
processEntrypoint: boolean;
|
|
119
120
|
rules: Config["rules"];
|
|
120
121
|
accountId: string | undefined;
|
|
121
122
|
initialMode: "local" | "remote";
|
|
@@ -138,7 +139,8 @@ export type DevProps = {
|
|
|
138
139
|
compatibilityFlags: string[] | undefined;
|
|
139
140
|
usageModel: "bundled" | "unbound" | undefined;
|
|
140
141
|
minify: boolean | undefined;
|
|
141
|
-
|
|
142
|
+
legacyNodeCompat: boolean | undefined;
|
|
143
|
+
nodejsCompat: boolean | undefined;
|
|
142
144
|
build: Config["build"];
|
|
143
145
|
env: string | undefined;
|
|
144
146
|
legacyEnv: boolean;
|
|
@@ -146,7 +148,6 @@ export type DevProps = {
|
|
|
146
148
|
host: string | undefined;
|
|
147
149
|
routes: Route[] | undefined;
|
|
148
150
|
inspect: boolean;
|
|
149
|
-
logPrefix?: string;
|
|
150
151
|
onReady: ((ip: string, port: number) => void) | undefined;
|
|
151
152
|
showInteractiveDevSession: boolean | undefined;
|
|
152
153
|
forceLocal: boolean | undefined;
|
|
@@ -187,6 +188,7 @@ function InteractiveDevSession(props: DevProps) {
|
|
|
187
188
|
inspect: props.inspect,
|
|
188
189
|
localProtocol: props.localProtocol,
|
|
189
190
|
forceLocal: props.forceLocal,
|
|
191
|
+
worker: props.name,
|
|
190
192
|
});
|
|
191
193
|
|
|
192
194
|
ip = props.initialIp;
|
|
@@ -249,20 +251,6 @@ function DevSession(props: DevSessionProps) {
|
|
|
249
251
|
() => props.bindings.d1_databases?.map((db) => db.binding),
|
|
250
252
|
[props.bindings.d1_databases]
|
|
251
253
|
);
|
|
252
|
-
const everyD1BindingHasPreview = props.bindings.d1_databases?.every(
|
|
253
|
-
(binding) => binding.preview_database_id
|
|
254
|
-
);
|
|
255
|
-
if (
|
|
256
|
-
betaD1Shims &&
|
|
257
|
-
betaD1Shims.length > 0 &&
|
|
258
|
-
!(props.local || everyD1BindingHasPreview)
|
|
259
|
-
) {
|
|
260
|
-
handleError(
|
|
261
|
-
new Error(
|
|
262
|
-
"D1 bindings require dev --local or preview_database_id for now"
|
|
263
|
-
)
|
|
264
|
-
);
|
|
265
|
-
}
|
|
266
254
|
|
|
267
255
|
// If we are using d1 bindings, and are not bundling the worker
|
|
268
256
|
// we should error here as the d1 shim won't be added
|
|
@@ -285,6 +273,7 @@ function DevSession(props: DevSessionProps) {
|
|
|
285
273
|
entry: props.entry,
|
|
286
274
|
destination: directory,
|
|
287
275
|
jsxFactory: props.jsxFactory,
|
|
276
|
+
processEntrypoint: props.processEntrypoint,
|
|
288
277
|
rules: props.rules,
|
|
289
278
|
jsxFragment: props.jsxFragment,
|
|
290
279
|
serveAssetsFromWorker: Boolean(
|
|
@@ -292,7 +281,8 @@ function DevSession(props: DevSessionProps) {
|
|
|
292
281
|
),
|
|
293
282
|
tsconfig: props.tsconfig,
|
|
294
283
|
minify: props.minify,
|
|
295
|
-
|
|
284
|
+
legacyNodeCompat: props.legacyNodeCompat,
|
|
285
|
+
nodejsCompat: props.nodejsCompat,
|
|
296
286
|
betaD1Shims,
|
|
297
287
|
define: props.define,
|
|
298
288
|
noBundle: props.noBundle,
|
|
@@ -355,13 +345,13 @@ function DevSession(props: DevSessionProps) {
|
|
|
355
345
|
queueConsumers={props.queueConsumers}
|
|
356
346
|
localProtocol={props.localProtocol}
|
|
357
347
|
localUpstream={props.localUpstream}
|
|
358
|
-
logPrefix={props.logPrefix}
|
|
359
348
|
inspect={props.inspect}
|
|
360
349
|
onReady={announceAndOnReady}
|
|
361
350
|
enablePagesAssetsServiceBinding={props.enablePagesAssetsServiceBinding}
|
|
362
351
|
experimentalLocal={props.experimentalLocal}
|
|
363
352
|
accountId={props.accountId}
|
|
364
353
|
experimentalLocalRemoteKv={props.experimentalLocalRemoteKv}
|
|
354
|
+
sourceMapPath={bundle?.sourceMapPath}
|
|
365
355
|
/>
|
|
366
356
|
) : (
|
|
367
357
|
<Remote
|
|
@@ -441,7 +431,7 @@ function useCustomBuild(expectedEntry: Entry, build: Config["build"]): void {
|
|
|
441
431
|
}
|
|
442
432
|
|
|
443
433
|
return () => {
|
|
444
|
-
watcher?.close();
|
|
434
|
+
void watcher?.close();
|
|
445
435
|
};
|
|
446
436
|
}, [build, expectedEntry]);
|
|
447
437
|
}
|
|
@@ -540,6 +530,7 @@ function useHotkeys(props: {
|
|
|
540
530
|
inspect: boolean;
|
|
541
531
|
localProtocol: "http" | "https";
|
|
542
532
|
forceLocal: boolean | undefined;
|
|
533
|
+
worker: string | undefined;
|
|
543
534
|
}) {
|
|
544
535
|
const { initial, inspectorPort, inspect, localProtocol, forceLocal } = props;
|
|
545
536
|
// UGH, we should put port in context instead
|
|
@@ -572,7 +563,7 @@ function useHotkeys(props: {
|
|
|
572
563
|
// toggle inspector
|
|
573
564
|
case "d": {
|
|
574
565
|
if (inspect) {
|
|
575
|
-
await openInspector(inspectorPort);
|
|
566
|
+
await openInspector(inspectorPort, props.worker);
|
|
576
567
|
}
|
|
577
568
|
break;
|
|
578
569
|
}
|