wrangler 0.0.0-e7a0cd5b → 0.0.0-e87ad068
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 +254 -128
- 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 +797 -98
- 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 +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 +92 -72
- package/src/__tests__/init.test.ts +1033 -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 +589 -0
- package/src/__tests__/pages/deployment-list.test.ts +80 -0
- package/src/__tests__/pages/functions-build.test.ts +529 -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 +106 -0
- package/src/__tests__/publish.test.ts +2227 -1005
- 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 +313 -113
- 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__/unstableDev.test.ts +61 -0
- 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 +180 -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 +80 -0
- package/src/api/pages/index.ts +5 -0
- package/src/api/pages/publish.tsx +371 -0
- package/src/bundle.ts +315 -148
- package/src/cfetch/index.ts +0 -2
- package/src/cfetch/internal.ts +33 -33
- package/src/cli.ts +4 -4
- package/src/config/config.ts +14 -7
- package/src/config/environment.ts +120 -24
- package/src/config/index.ts +117 -35
- package/src/config/validation-helpers.ts +1 -1
- package/src/config/validation.ts +430 -19
- package/src/constellation/createProject.tsx +51 -0
- package/src/constellation/deleteProject.ts +51 -0
- package/src/constellation/deleteProjectModel.ts +76 -0
- package/src/constellation/index.ts +75 -0
- package/src/constellation/listCatalog.tsx +35 -0
- package/src/constellation/listModel.tsx +49 -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 +84 -0
- package/src/constellation/utils.ts +90 -0
- package/src/create-worker-preview.ts +19 -8
- package/src/create-worker-upload-form.ts +81 -18
- package/src/d1/backups.tsx +47 -46
- package/src/d1/constants.ts +5 -0
- package/src/d1/create.tsx +85 -37
- package/src/d1/{delete.tsx → delete.ts} +12 -15
- package/src/d1/execute.tsx +228 -156
- package/src/d1/index.ts +31 -7
- package/src/d1/list.tsx +27 -13
- package/src/d1/migrations/apply.tsx +235 -0
- package/src/d1/migrations/create.tsx +79 -0
- package/src/d1/migrations/helpers.ts +171 -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.ts +32 -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 +66 -46
- package/src/dev/local.tsx +339 -104
- package/src/dev/remote.tsx +36 -3
- package/src/dev/start-server.ts +146 -101
- package/src/dev/use-esbuild.ts +82 -56
- package/src/dev/validate-dev-props.ts +9 -0
- package/src/{dev-registry.tsx → dev-registry.ts} +13 -1
- package/src/dev.tsx +202 -125
- 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 +303 -0
- package/src/git-client.ts +15 -4
- package/src/{index.tsx → index.ts} +148 -63
- package/src/init.ts +301 -197
- package/src/inspect.ts +122 -6
- 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 +3 -3
- package/src/metrics/send-event.ts +6 -1
- package/src/miniflare-cli/assets.ts +64 -28
- package/src/miniflare-cli/index.ts +6 -9
- 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.ts +281 -0
- package/src/pages/deployments.tsx +11 -33
- package/src/pages/{dev.tsx → dev.ts} +192 -126
- package/src/pages/errors.ts +1 -0
- package/src/pages/functions/buildPlugin.ts +73 -69
- package/src/pages/functions/buildWorker.ts +342 -117
- 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 +81 -48
- 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 +18 -17
- package/src/{sites.tsx → sites.ts} +165 -53
- package/src/tail/createTail.ts +103 -3
- package/src/tail/filters.ts +1 -1
- package/src/tail/index.ts +8 -11
- package/src/tail/printing.ts +27 -0
- package/src/traverse-module-graph.ts +54 -0
- package/src/tsconfig-sanity.ts +16 -0
- package/src/type-generation.ts +85 -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} +124 -82
- package/src/utils/render.ts +93 -0
- package/src/{whoami.tsx → whoami.ts} +37 -71
- package/src/worker.ts +61 -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-dev-util.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 +902 -77
- package/wrangler-dist/cli.js +131685 -140615
- 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/d1/types.tsx +0 -14
- 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,9 +28,9 @@ 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
|
-
import type { CfWorkerInit } from "../worker";
|
|
33
|
+
import type { CfModule, CfWorkerInit } from "../worker";
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* This hooks establishes a connection with the dev registry,
|
|
@@ -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,9 +113,11 @@ 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
|
+
processEntrypoint: boolean;
|
|
120
|
+
additionalModules: CfModule[];
|
|
119
121
|
rules: Config["rules"];
|
|
120
122
|
accountId: string | undefined;
|
|
121
123
|
initialMode: "local" | "remote";
|
|
@@ -138,7 +140,8 @@ export type DevProps = {
|
|
|
138
140
|
compatibilityFlags: string[] | undefined;
|
|
139
141
|
usageModel: "bundled" | "unbound" | undefined;
|
|
140
142
|
minify: boolean | undefined;
|
|
141
|
-
|
|
143
|
+
legacyNodeCompat: boolean | undefined;
|
|
144
|
+
nodejsCompat: boolean | undefined;
|
|
142
145
|
build: Config["build"];
|
|
143
146
|
env: string | undefined;
|
|
144
147
|
legacyEnv: boolean;
|
|
@@ -146,7 +149,6 @@ export type DevProps = {
|
|
|
146
149
|
host: string | undefined;
|
|
147
150
|
routes: Route[] | undefined;
|
|
148
151
|
inspect: boolean;
|
|
149
|
-
logPrefix?: string;
|
|
150
152
|
onReady: ((ip: string, port: number) => void) | undefined;
|
|
151
153
|
showInteractiveDevSession: boolean | undefined;
|
|
152
154
|
forceLocal: boolean | undefined;
|
|
@@ -155,6 +157,7 @@ export type DevProps = {
|
|
|
155
157
|
sendMetrics: boolean | undefined;
|
|
156
158
|
testScheduled: boolean | undefined;
|
|
157
159
|
experimentalLocal: boolean | undefined;
|
|
160
|
+
experimentalLocalRemoteKv: boolean | undefined;
|
|
158
161
|
};
|
|
159
162
|
|
|
160
163
|
export function DevImplementation(props: DevProps): JSX.Element {
|
|
@@ -170,25 +173,43 @@ export function DevImplementation(props: DevProps): JSX.Element {
|
|
|
170
173
|
);
|
|
171
174
|
}
|
|
172
175
|
|
|
176
|
+
// This is a nasty hack to allow `useHotkeys` and its "[b] open a browser" feature to read these values
|
|
177
|
+
// without triggering a re-render loop when `onReady()` updates them.
|
|
178
|
+
// The initially requested port can be different than what's actually used, if, for example, you request port 0.
|
|
179
|
+
let ip: string;
|
|
180
|
+
let port: number;
|
|
181
|
+
|
|
173
182
|
function InteractiveDevSession(props: DevProps) {
|
|
174
183
|
const toggles = useHotkeys({
|
|
175
184
|
initial: {
|
|
176
185
|
local: props.initialMode === "local",
|
|
177
186
|
tunnel: false,
|
|
178
187
|
},
|
|
179
|
-
port: props.port,
|
|
180
|
-
ip: props.ip,
|
|
181
188
|
inspectorPort: props.inspectorPort,
|
|
182
189
|
inspect: props.inspect,
|
|
183
190
|
localProtocol: props.localProtocol,
|
|
184
191
|
forceLocal: props.forceLocal,
|
|
192
|
+
worker: props.name,
|
|
185
193
|
});
|
|
186
194
|
|
|
195
|
+
ip = props.initialIp;
|
|
196
|
+
port = props.initialPort;
|
|
197
|
+
|
|
187
198
|
useTunnel(toggles.tunnel);
|
|
188
199
|
|
|
200
|
+
const onReady = (newIp: string, newPort: number) => {
|
|
201
|
+
if (newIp !== props.initialIp || newPort !== props.initialPort) {
|
|
202
|
+
ip = newIp;
|
|
203
|
+
port = newPort;
|
|
204
|
+
if (props.onReady) {
|
|
205
|
+
props.onReady(newIp, newPort);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
|
|
189
210
|
return (
|
|
190
211
|
<>
|
|
191
|
-
<DevSession {...props} local={toggles.local} />
|
|
212
|
+
<DevSession {...props} local={toggles.local} onReady={onReady} />
|
|
192
213
|
<Box borderStyle="round" paddingLeft={1} paddingRight={1}>
|
|
193
214
|
<Text bold={true}>[b]</Text>
|
|
194
215
|
<Text> open a browser, </Text>
|
|
@@ -231,20 +252,6 @@ function DevSession(props: DevSessionProps) {
|
|
|
231
252
|
() => props.bindings.d1_databases?.map((db) => db.binding),
|
|
232
253
|
[props.bindings.d1_databases]
|
|
233
254
|
);
|
|
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
255
|
|
|
249
256
|
// If we are using d1 bindings, and are not bundling the worker
|
|
250
257
|
// we should error here as the d1 shim won't be added
|
|
@@ -267,6 +274,8 @@ function DevSession(props: DevSessionProps) {
|
|
|
267
274
|
entry: props.entry,
|
|
268
275
|
destination: directory,
|
|
269
276
|
jsxFactory: props.jsxFactory,
|
|
277
|
+
processEntrypoint: props.processEntrypoint,
|
|
278
|
+
additionalModules: props.additionalModules,
|
|
270
279
|
rules: props.rules,
|
|
271
280
|
jsxFragment: props.jsxFragment,
|
|
272
281
|
serveAssetsFromWorker: Boolean(
|
|
@@ -274,7 +283,8 @@ function DevSession(props: DevSessionProps) {
|
|
|
274
283
|
),
|
|
275
284
|
tsconfig: props.tsconfig,
|
|
276
285
|
minify: props.minify,
|
|
277
|
-
|
|
286
|
+
legacyNodeCompat: props.legacyNodeCompat,
|
|
287
|
+
nodejsCompat: props.nodejsCompat,
|
|
278
288
|
betaD1Shims,
|
|
279
289
|
define: props.define,
|
|
280
290
|
noBundle: props.noBundle,
|
|
@@ -287,7 +297,7 @@ function DevSession(props: DevSessionProps) {
|
|
|
287
297
|
// Enable the bundling to know whether we are using dev or publish
|
|
288
298
|
targetConsumer: "dev",
|
|
289
299
|
testScheduled: props.testScheduled ?? false,
|
|
290
|
-
|
|
300
|
+
experimentalLocal: props.experimentalLocal,
|
|
291
301
|
});
|
|
292
302
|
|
|
293
303
|
// TODO(queues) support remote wrangler dev
|
|
@@ -300,6 +310,22 @@ function DevSession(props: DevSessionProps) {
|
|
|
300
310
|
);
|
|
301
311
|
}
|
|
302
312
|
|
|
313
|
+
const announceAndOnReady: typeof props.onReady = (finalIp, finalPort) => {
|
|
314
|
+
if (process.send) {
|
|
315
|
+
process.send(
|
|
316
|
+
JSON.stringify({
|
|
317
|
+
event: "DEV_SERVER_READY",
|
|
318
|
+
ip: finalIp,
|
|
319
|
+
port: finalPort,
|
|
320
|
+
})
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
if (props.onReady) {
|
|
325
|
+
props.onReady(finalIp, finalPort);
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
|
|
303
329
|
return props.local ? (
|
|
304
330
|
<Local
|
|
305
331
|
name={props.name}
|
|
@@ -311,8 +337,8 @@ function DevSession(props: DevSessionProps) {
|
|
|
311
337
|
bindings={props.bindings}
|
|
312
338
|
workerDefinitions={workerDefinitions}
|
|
313
339
|
assetPaths={props.assetPaths}
|
|
314
|
-
|
|
315
|
-
|
|
340
|
+
initialPort={props.initialPort}
|
|
341
|
+
initialIp={props.initialIp}
|
|
316
342
|
rules={props.rules}
|
|
317
343
|
inspectorPort={props.inspectorPort}
|
|
318
344
|
localPersistencePath={props.localPersistencePath}
|
|
@@ -321,11 +347,13 @@ function DevSession(props: DevSessionProps) {
|
|
|
321
347
|
queueConsumers={props.queueConsumers}
|
|
322
348
|
localProtocol={props.localProtocol}
|
|
323
349
|
localUpstream={props.localUpstream}
|
|
324
|
-
logPrefix={props.logPrefix}
|
|
325
350
|
inspect={props.inspect}
|
|
326
|
-
onReady={
|
|
351
|
+
onReady={announceAndOnReady}
|
|
327
352
|
enablePagesAssetsServiceBinding={props.enablePagesAssetsServiceBinding}
|
|
328
353
|
experimentalLocal={props.experimentalLocal}
|
|
354
|
+
accountId={props.accountId}
|
|
355
|
+
experimentalLocalRemoteKv={props.experimentalLocalRemoteKv}
|
|
356
|
+
sourceMapPath={bundle?.sourceMapPath}
|
|
329
357
|
/>
|
|
330
358
|
) : (
|
|
331
359
|
<Remote
|
|
@@ -336,8 +364,8 @@ function DevSession(props: DevSessionProps) {
|
|
|
336
364
|
bindings={props.bindings}
|
|
337
365
|
assetPaths={props.assetPaths}
|
|
338
366
|
isWorkersSite={props.isWorkersSite}
|
|
339
|
-
port={props.
|
|
340
|
-
ip={props.
|
|
367
|
+
port={props.initialPort}
|
|
368
|
+
ip={props.initialIp}
|
|
341
369
|
localProtocol={props.localProtocol}
|
|
342
370
|
inspectorPort={props.inspectorPort}
|
|
343
371
|
// TODO: @threepointone #1167
|
|
@@ -351,7 +379,7 @@ function DevSession(props: DevSessionProps) {
|
|
|
351
379
|
zone={props.zone}
|
|
352
380
|
host={props.host}
|
|
353
381
|
routes={props.routes}
|
|
354
|
-
onReady={
|
|
382
|
+
onReady={announceAndOnReady}
|
|
355
383
|
sourceMapPath={bundle?.sourceMapPath}
|
|
356
384
|
sendMetrics={props.sendMetrics}
|
|
357
385
|
/>
|
|
@@ -405,7 +433,7 @@ function useCustomBuild(expectedEntry: Entry, build: Config["build"]): void {
|
|
|
405
433
|
}
|
|
406
434
|
|
|
407
435
|
return () => {
|
|
408
|
-
watcher?.close();
|
|
436
|
+
void watcher?.close();
|
|
409
437
|
};
|
|
410
438
|
}, [build, expectedEntry]);
|
|
411
439
|
}
|
|
@@ -500,25 +528,17 @@ type useHotkeysInitialState = {
|
|
|
500
528
|
};
|
|
501
529
|
function useHotkeys(props: {
|
|
502
530
|
initial: useHotkeysInitialState;
|
|
503
|
-
port: number;
|
|
504
|
-
ip: string;
|
|
505
531
|
inspectorPort: number;
|
|
506
532
|
inspect: boolean;
|
|
507
533
|
localProtocol: "http" | "https";
|
|
508
534
|
forceLocal: boolean | undefined;
|
|
535
|
+
worker: string | undefined;
|
|
509
536
|
}) {
|
|
510
|
-
const {
|
|
511
|
-
initial,
|
|
512
|
-
port,
|
|
513
|
-
ip,
|
|
514
|
-
inspectorPort,
|
|
515
|
-
inspect,
|
|
516
|
-
localProtocol,
|
|
517
|
-
forceLocal,
|
|
518
|
-
} = props;
|
|
537
|
+
const { initial, inspectorPort, inspect, localProtocol, forceLocal } = props;
|
|
519
538
|
// UGH, we should put port in context instead
|
|
520
539
|
const [toggles, setToggles] = useState(initial);
|
|
521
540
|
const { exit } = useApp();
|
|
541
|
+
|
|
522
542
|
useInput(
|
|
523
543
|
async (
|
|
524
544
|
input,
|
|
@@ -545,7 +565,7 @@ function useHotkeys(props: {
|
|
|
545
565
|
// toggle inspector
|
|
546
566
|
case "d": {
|
|
547
567
|
if (inspect) {
|
|
548
|
-
await openInspector(inspectorPort);
|
|
568
|
+
await openInspector(inspectorPort, props.worker);
|
|
549
569
|
}
|
|
550
570
|
break;
|
|
551
571
|
}
|