wrangler 0.0.0-e7a0cd5b → 0.0.0-e7cf0caa
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/bin/wrangler.js +30 -10
- package/miniflare-dist/index.mjs +126 -74
- package/package.json +27 -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 +567 -86
- 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 +157 -0
- package/src/__tests__/d1/splitter.test.ts +255 -0
- package/src/__tests__/delete.test.ts +91 -49
- package/src/__tests__/deployments.test.ts +330 -56
- package/src/__tests__/dev.test.tsx +198 -90
- package/src/__tests__/generate.test.ts +12 -10
- 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 +103 -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 +128 -27
- package/src/__tests__/helpers/msw/handlers/namespaces.ts +18 -41
- package/src/__tests__/helpers/msw/handlers/oauth.ts +13 -18
- 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 +90 -72
- package/src/__tests__/init.test.ts +927 -631
- 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 +47 -0
- package/src/__tests__/metrics.test.ts +94 -51
- package/src/__tests__/middleware.scheduled.test.ts +42 -32
- package/src/__tests__/middleware.test.ts +212 -122
- package/src/__tests__/mtls-certificates.test.ts +588 -0
- package/src/__tests__/pages/deployment-list.test.ts +80 -0
- package/src/__tests__/pages/functions-build.test.ts +452 -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 +955 -0
- package/src/__tests__/parse.test.ts +106 -0
- package/src/__tests__/publish.test.ts +1615 -852
- package/src/__tests__/pubsub.test.ts +226 -100
- package/src/__tests__/queues.test.ts +238 -77
- package/src/__tests__/r2.test.ts +55 -57
- package/src/__tests__/secret.test.ts +179 -130
- package/src/__tests__/tail.test.ts +267 -109
- 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 +43 -26
- package/src/__tests__/user.test.ts +35 -72
- package/src/__tests__/whoami.test.tsx +8 -114
- package/src/__tests__/worker-namespace.test.ts +83 -69
- package/src/api/dev.ts +168 -60
- package/src/api/index.ts +10 -1
- package/src/api/mtls-certificate.ts +148 -0
- package/src/api/pages/create-worker-bundle-contents.ts +76 -0
- package/src/api/pages/index.ts +5 -0
- package/src/api/pages/publish.tsx +355 -0
- package/src/bundle.ts +263 -140
- 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 +79 -24
- package/src/config/index.ts +99 -38
- package/src/config/validation-helpers.ts +1 -1
- package/src/config/validation.ts +248 -19
- package/src/create-worker-preview.ts +19 -8
- package/src/create-worker-upload-form.ts +60 -22
- package/src/d1/backups.tsx +43 -42
- package/src/d1/constants.ts +2 -0
- package/src/d1/create.tsx +44 -30
- package/src/d1/{delete.tsx → delete.ts} +11 -14
- package/src/d1/execute.tsx +209 -151
- package/src/d1/index.ts +31 -7
- package/src/d1/list.tsx +22 -10
- package/src/d1/migrations/apply.tsx +212 -0
- package/src/d1/migrations/create.tsx +79 -0
- package/src/d1/migrations/helpers.ts +172 -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 +12 -2
- package/src/d1/splitter.ts +161 -0
- package/src/d1/{types.tsx → types.ts} +11 -0
- package/src/d1/utils.ts +12 -2
- package/src/delete.ts +8 -16
- package/src/deployments.ts +340 -46
- package/src/deprecated/index.ts +8 -302
- package/src/dev/dev.tsx +57 -44
- package/src/dev/local.tsx +294 -91
- package/src/dev/remote.tsx +32 -3
- package/src/dev/start-server.ts +89 -68
- package/src/dev/use-esbuild.ts +17 -18
- package/src/dev/validate-dev-props.ts +9 -0
- package/src/{dev-registry.tsx → dev-registry.ts} +2 -1
- package/src/dev.tsx +178 -118
- package/src/dialogs.ts +136 -0
- package/src/dispatch-namespace.ts +21 -17
- package/src/docs/index.ts +97 -0
- package/src/entry.ts +19 -11
- package/src/environment-variables/factory.ts +88 -0
- package/src/environment-variables/misc-variables.ts +30 -0
- package/src/generate/index.ts +298 -0
- package/src/git-client.ts +15 -4
- package/src/{index.tsx → index.ts} +137 -63
- package/src/init.ts +249 -187
- package/src/inspect.ts +16 -1
- package/src/jest.d.ts +4 -0
- package/src/kv/index.ts +15 -17
- package/src/logger.ts +32 -5
- package/src/metrics/metrics-config.ts +3 -3
- package/src/metrics/send-event.ts +6 -1
- package/src/miniflare-cli/assets.ts +64 -28
- package/src/miniflare-cli/index.ts +4 -7
- 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 +91 -25
- package/src/mtls-certificate/cli.ts +155 -0
- package/src/pages/build.ts +410 -0
- package/src/pages/buildFunctions.ts +140 -0
- package/src/pages/deployment-tails.ts +281 -0
- package/src/pages/deployments.tsx +11 -33
- package/src/pages/{dev.tsx → dev.ts} +147 -124
- package/src/pages/errors.ts +1 -0
- package/src/pages/functions/buildPlugin.ts +72 -69
- package/src/pages/functions/buildWorker.ts +249 -114
- 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} +11 -3
- package/src/pages/projects.tsx +12 -22
- package/src/pages/prompt-select-project.tsx +31 -0
- package/src/pages/publish.tsx +45 -214
- package/src/pages/types.ts +6 -9
- package/src/pages/upload.tsx +58 -14
- package/src/pages/utils.ts +14 -3
- package/src/parse.ts +23 -1
- package/src/paths.ts +1 -1
- package/src/proxy.ts +5 -0
- package/src/publish/index.ts +20 -16
- package/src/publish/publish.ts +72 -47
- 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 +6 -4
- package/src/queues/cli/commands/list.ts +8 -8
- package/src/queues/client.ts +1 -0
- package/src/queues/utils.ts +18 -0
- package/src/r2/constants.ts +4 -0
- package/src/r2/helpers.ts +1 -0
- package/src/r2/index.ts +40 -28
- package/src/secret/index.ts +14 -17
- package/src/{sites.tsx → sites.ts} +1 -1
- package/src/tail/createTail.ts +94 -3
- package/src/tail/filters.ts +1 -1
- package/src/tail/index.ts +8 -11
- package/src/tail/printing.ts +15 -0
- package/src/traverse-module-graph.ts +53 -0
- package/src/tsconfig-sanity.ts +16 -0
- package/src/type-generation.ts +79 -57
- 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} +123 -82
- package/src/utils/render.ts +93 -0
- package/src/{whoami.tsx → whoami.ts} +37 -71
- package/src/worker.ts +35 -3
- package/src/yargs-types.ts +22 -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 +95 -25
- 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 +51 -31
- package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
- 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 +826 -77
- package/wrangler-dist/cli.js +130734 -140838
- package/wrangler-dist/wasm-sync.wasm +0 -0
- package/src/__tests__/api-devregistry.test.js +0 -57
- package/src/__tests__/d1.test.ts +0 -72
- package/src/__tests__/dialogs.test.tsx +0 -40
- package/src/__tests__/helpers/mock-cfetch.ts +0 -333
- package/src/__tests__/pages.test.ts +0 -2223
- package/src/dialogs.tsx +0 -163
- package/src/environment-variables.ts +0 -50
- package/src/pages/build.tsx +0 -238
- package/src/user/env-vars.ts +0 -46
- package/templates/experimental-local-cache-stubs.js +0 -27
- /package/src/{bundle-reporter.tsx → bundle-reporter.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({
|
|
@@ -113,8 +113,8 @@ export type DevProps = {
|
|
|
113
113
|
name: string | undefined;
|
|
114
114
|
noBundle: boolean;
|
|
115
115
|
entry: Entry;
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
initialPort: number;
|
|
117
|
+
initialIp: string;
|
|
118
118
|
inspectorPort: number;
|
|
119
119
|
rules: Config["rules"];
|
|
120
120
|
accountId: string | undefined;
|
|
@@ -138,7 +138,8 @@ export type DevProps = {
|
|
|
138
138
|
compatibilityFlags: string[] | undefined;
|
|
139
139
|
usageModel: "bundled" | "unbound" | undefined;
|
|
140
140
|
minify: boolean | undefined;
|
|
141
|
-
|
|
141
|
+
legacyNodeCompat: boolean | undefined;
|
|
142
|
+
nodejsCompat: boolean | undefined;
|
|
142
143
|
build: Config["build"];
|
|
143
144
|
env: string | undefined;
|
|
144
145
|
legacyEnv: boolean;
|
|
@@ -146,7 +147,6 @@ export type DevProps = {
|
|
|
146
147
|
host: string | undefined;
|
|
147
148
|
routes: Route[] | undefined;
|
|
148
149
|
inspect: boolean;
|
|
149
|
-
logPrefix?: string;
|
|
150
150
|
onReady: ((ip: string, port: number) => void) | undefined;
|
|
151
151
|
showInteractiveDevSession: boolean | undefined;
|
|
152
152
|
forceLocal: boolean | undefined;
|
|
@@ -155,6 +155,7 @@ export type DevProps = {
|
|
|
155
155
|
sendMetrics: boolean | undefined;
|
|
156
156
|
testScheduled: boolean | undefined;
|
|
157
157
|
experimentalLocal: boolean | undefined;
|
|
158
|
+
experimentalLocalRemoteKv: boolean | undefined;
|
|
158
159
|
};
|
|
159
160
|
|
|
160
161
|
export function DevImplementation(props: DevProps): JSX.Element {
|
|
@@ -170,25 +171,42 @@ export function DevImplementation(props: DevProps): JSX.Element {
|
|
|
170
171
|
);
|
|
171
172
|
}
|
|
172
173
|
|
|
174
|
+
// This is a nasty hack to allow `useHotkeys` and its "[b] open a browser" feature to read these values
|
|
175
|
+
// without triggering a re-render loop when `onReady()` updates them.
|
|
176
|
+
// The initially requested port can be different than what's actually used, if, for example, you request port 0.
|
|
177
|
+
let ip: string;
|
|
178
|
+
let port: number;
|
|
179
|
+
|
|
173
180
|
function InteractiveDevSession(props: DevProps) {
|
|
174
181
|
const toggles = useHotkeys({
|
|
175
182
|
initial: {
|
|
176
183
|
local: props.initialMode === "local",
|
|
177
184
|
tunnel: false,
|
|
178
185
|
},
|
|
179
|
-
port: props.port,
|
|
180
|
-
ip: props.ip,
|
|
181
186
|
inspectorPort: props.inspectorPort,
|
|
182
187
|
inspect: props.inspect,
|
|
183
188
|
localProtocol: props.localProtocol,
|
|
184
189
|
forceLocal: props.forceLocal,
|
|
185
190
|
});
|
|
186
191
|
|
|
192
|
+
ip = props.initialIp;
|
|
193
|
+
port = props.initialPort;
|
|
194
|
+
|
|
187
195
|
useTunnel(toggles.tunnel);
|
|
188
196
|
|
|
197
|
+
const onReady = (newIp: string, newPort: number) => {
|
|
198
|
+
if (newIp !== props.initialIp || newPort !== props.initialPort) {
|
|
199
|
+
ip = newIp;
|
|
200
|
+
port = newPort;
|
|
201
|
+
if (props.onReady) {
|
|
202
|
+
props.onReady(newIp, newPort);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
|
|
189
207
|
return (
|
|
190
208
|
<>
|
|
191
|
-
<DevSession {...props} local={toggles.local} />
|
|
209
|
+
<DevSession {...props} local={toggles.local} onReady={onReady} />
|
|
192
210
|
<Box borderStyle="round" paddingLeft={1} paddingRight={1}>
|
|
193
211
|
<Text bold={true}>[b]</Text>
|
|
194
212
|
<Text> open a browser, </Text>
|
|
@@ -231,20 +249,6 @@ function DevSession(props: DevSessionProps) {
|
|
|
231
249
|
() => props.bindings.d1_databases?.map((db) => db.binding),
|
|
232
250
|
[props.bindings.d1_databases]
|
|
233
251
|
);
|
|
234
|
-
const everyD1BindingHasPreview = props.bindings.d1_databases?.every(
|
|
235
|
-
(binding) => binding.preview_database_id
|
|
236
|
-
);
|
|
237
|
-
if (
|
|
238
|
-
betaD1Shims &&
|
|
239
|
-
betaD1Shims.length > 0 &&
|
|
240
|
-
!(props.local || everyD1BindingHasPreview)
|
|
241
|
-
) {
|
|
242
|
-
handleError(
|
|
243
|
-
new Error(
|
|
244
|
-
"D1 bindings require dev --local or preview_database_id for now"
|
|
245
|
-
)
|
|
246
|
-
);
|
|
247
|
-
}
|
|
248
252
|
|
|
249
253
|
// If we are using d1 bindings, and are not bundling the worker
|
|
250
254
|
// we should error here as the d1 shim won't be added
|
|
@@ -274,7 +278,8 @@ function DevSession(props: DevSessionProps) {
|
|
|
274
278
|
),
|
|
275
279
|
tsconfig: props.tsconfig,
|
|
276
280
|
minify: props.minify,
|
|
277
|
-
|
|
281
|
+
legacyNodeCompat: props.legacyNodeCompat,
|
|
282
|
+
nodejsCompat: props.nodejsCompat,
|
|
278
283
|
betaD1Shims,
|
|
279
284
|
define: props.define,
|
|
280
285
|
noBundle: props.noBundle,
|
|
@@ -287,7 +292,7 @@ function DevSession(props: DevSessionProps) {
|
|
|
287
292
|
// Enable the bundling to know whether we are using dev or publish
|
|
288
293
|
targetConsumer: "dev",
|
|
289
294
|
testScheduled: props.testScheduled ?? false,
|
|
290
|
-
|
|
295
|
+
experimentalLocal: props.experimentalLocal,
|
|
291
296
|
});
|
|
292
297
|
|
|
293
298
|
// TODO(queues) support remote wrangler dev
|
|
@@ -300,6 +305,22 @@ function DevSession(props: DevSessionProps) {
|
|
|
300
305
|
);
|
|
301
306
|
}
|
|
302
307
|
|
|
308
|
+
const announceAndOnReady: typeof props.onReady = (finalIp, finalPort) => {
|
|
309
|
+
if (process.send) {
|
|
310
|
+
process.send(
|
|
311
|
+
JSON.stringify({
|
|
312
|
+
event: "DEV_SERVER_READY",
|
|
313
|
+
ip: finalIp,
|
|
314
|
+
port: finalPort,
|
|
315
|
+
})
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
if (props.onReady) {
|
|
320
|
+
props.onReady(finalIp, finalPort);
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
|
|
303
324
|
return props.local ? (
|
|
304
325
|
<Local
|
|
305
326
|
name={props.name}
|
|
@@ -311,8 +332,8 @@ function DevSession(props: DevSessionProps) {
|
|
|
311
332
|
bindings={props.bindings}
|
|
312
333
|
workerDefinitions={workerDefinitions}
|
|
313
334
|
assetPaths={props.assetPaths}
|
|
314
|
-
|
|
315
|
-
|
|
335
|
+
initialPort={props.initialPort}
|
|
336
|
+
initialIp={props.initialIp}
|
|
316
337
|
rules={props.rules}
|
|
317
338
|
inspectorPort={props.inspectorPort}
|
|
318
339
|
localPersistencePath={props.localPersistencePath}
|
|
@@ -321,11 +342,12 @@ function DevSession(props: DevSessionProps) {
|
|
|
321
342
|
queueConsumers={props.queueConsumers}
|
|
322
343
|
localProtocol={props.localProtocol}
|
|
323
344
|
localUpstream={props.localUpstream}
|
|
324
|
-
logPrefix={props.logPrefix}
|
|
325
345
|
inspect={props.inspect}
|
|
326
|
-
onReady={
|
|
346
|
+
onReady={announceAndOnReady}
|
|
327
347
|
enablePagesAssetsServiceBinding={props.enablePagesAssetsServiceBinding}
|
|
328
348
|
experimentalLocal={props.experimentalLocal}
|
|
349
|
+
accountId={props.accountId}
|
|
350
|
+
experimentalLocalRemoteKv={props.experimentalLocalRemoteKv}
|
|
329
351
|
/>
|
|
330
352
|
) : (
|
|
331
353
|
<Remote
|
|
@@ -336,8 +358,8 @@ function DevSession(props: DevSessionProps) {
|
|
|
336
358
|
bindings={props.bindings}
|
|
337
359
|
assetPaths={props.assetPaths}
|
|
338
360
|
isWorkersSite={props.isWorkersSite}
|
|
339
|
-
port={props.
|
|
340
|
-
ip={props.
|
|
361
|
+
port={props.initialPort}
|
|
362
|
+
ip={props.initialIp}
|
|
341
363
|
localProtocol={props.localProtocol}
|
|
342
364
|
inspectorPort={props.inspectorPort}
|
|
343
365
|
// TODO: @threepointone #1167
|
|
@@ -351,7 +373,7 @@ function DevSession(props: DevSessionProps) {
|
|
|
351
373
|
zone={props.zone}
|
|
352
374
|
host={props.host}
|
|
353
375
|
routes={props.routes}
|
|
354
|
-
onReady={
|
|
376
|
+
onReady={announceAndOnReady}
|
|
355
377
|
sourceMapPath={bundle?.sourceMapPath}
|
|
356
378
|
sendMetrics={props.sendMetrics}
|
|
357
379
|
/>
|
|
@@ -405,7 +427,7 @@ function useCustomBuild(expectedEntry: Entry, build: Config["build"]): void {
|
|
|
405
427
|
}
|
|
406
428
|
|
|
407
429
|
return () => {
|
|
408
|
-
watcher?.close();
|
|
430
|
+
void watcher?.close();
|
|
409
431
|
};
|
|
410
432
|
}, [build, expectedEntry]);
|
|
411
433
|
}
|
|
@@ -500,25 +522,16 @@ type useHotkeysInitialState = {
|
|
|
500
522
|
};
|
|
501
523
|
function useHotkeys(props: {
|
|
502
524
|
initial: useHotkeysInitialState;
|
|
503
|
-
port: number;
|
|
504
|
-
ip: string;
|
|
505
525
|
inspectorPort: number;
|
|
506
526
|
inspect: boolean;
|
|
507
527
|
localProtocol: "http" | "https";
|
|
508
528
|
forceLocal: boolean | undefined;
|
|
509
529
|
}) {
|
|
510
|
-
const {
|
|
511
|
-
initial,
|
|
512
|
-
port,
|
|
513
|
-
ip,
|
|
514
|
-
inspectorPort,
|
|
515
|
-
inspect,
|
|
516
|
-
localProtocol,
|
|
517
|
-
forceLocal,
|
|
518
|
-
} = props;
|
|
530
|
+
const { initial, inspectorPort, inspect, localProtocol, forceLocal } = props;
|
|
519
531
|
// UGH, we should put port in context instead
|
|
520
532
|
const [toggles, setToggles] = useState(initial);
|
|
521
533
|
const { exit } = useApp();
|
|
534
|
+
|
|
522
535
|
useInput(
|
|
523
536
|
async (
|
|
524
537
|
input,
|