wrangler 0.0.0-e95bea2 → 0.0.0-e95e5a0
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 +25 -14
- package/bin/wrangler.js +13 -1
- package/miniflare-dist/index.mjs +4886 -0
- package/package.json +33 -25
- package/pages/functions/buildPlugin.ts +92 -0
- package/pages/functions/buildWorker.ts +80 -4
- package/pages/functions/filepath-routing.test.ts +136 -25
- package/pages/functions/filepath-routing.ts +14 -3
- package/pages/functions/routes.ts +6 -1
- package/pages/functions/template-plugin.ts +146 -0
- package/pages/functions/template-worker.ts +21 -8
- package/src/__tests__/config-cache.test.ts +36 -0
- package/src/__tests__/configuration.test.ts +1179 -271
- package/src/__tests__/dev.test.tsx +382 -25
- package/src/__tests__/guess-worker-format.test.ts +28 -1
- package/src/__tests__/helpers/mock-account-id.ts +4 -0
- package/src/__tests__/helpers/mock-cfetch.ts +5 -1
- package/src/__tests__/helpers/mock-console.ts +20 -3
- package/src/__tests__/helpers/mock-dialogs.ts +26 -1
- package/src/__tests__/helpers/mock-http-server.ts +46 -0
- package/src/__tests__/helpers/mock-istty.ts +27 -0
- package/src/__tests__/helpers/mock-kv.ts +9 -16
- package/src/__tests__/helpers/mock-oauth-flow.ts +255 -0
- package/src/__tests__/helpers/run-in-tmp.ts +10 -0
- package/src/__tests__/helpers/write-worker-source.ts +31 -0
- package/src/__tests__/https-options.test.ts +5 -2
- package/src/__tests__/index.test.ts +27 -769
- package/src/__tests__/init.test.ts +1516 -0
- package/src/__tests__/jest.setup.ts +4 -4
- package/src/__tests__/kv.test.ts +172 -126
- package/src/__tests__/logger.test.ts +115 -0
- package/src/__tests__/pages.test.ts +311 -26
- package/src/__tests__/publish.test.ts +2946 -524
- package/src/__tests__/r2.test.ts +26 -10
- package/src/__tests__/route.test.ts +4 -4
- package/src/__tests__/secret.test.ts +55 -34
- package/src/__tests__/tail.test.ts +146 -20
- package/src/__tests__/user.test.ts +131 -0
- package/src/__tests__/whoami.test.tsx +26 -7
- package/src/bundle.ts +30 -3
- package/src/cfetch/internal.ts +9 -7
- package/src/cli.ts +5 -11
- package/src/config/README.md +7 -7
- package/src/config/config.ts +33 -78
- package/src/config/environment.ts +93 -4
- package/src/config/index.ts +15 -4
- package/src/config/validation-helpers.ts +202 -15
- package/src/config/validation.ts +530 -133
- package/src/config-cache.ts +45 -0
- package/src/create-worker-preview.ts +22 -13
- package/src/create-worker-upload-form.ts +32 -9
- package/src/dev/dev-vars.ts +36 -0
- package/src/dev/dev.tsx +136 -75
- package/src/dev/local.tsx +196 -125
- package/src/dev/remote.tsx +25 -13
- package/src/dev/use-esbuild.ts +23 -5
- package/src/dialogs.tsx +16 -6
- package/src/entry.ts +119 -11
- package/src/environment-variables.ts +3 -1
- package/src/errors.ts +11 -0
- package/src/https-options.ts +3 -2
- package/src/index.tsx +739 -400
- package/src/inspect.ts +17 -11
- package/src/intl-polyfill.d.ts +139 -0
- package/src/{kv/index.tsx → kv.ts} +8 -28
- package/src/logger.ts +66 -0
- package/src/miniflare-cli/README.md +30 -0
- package/src/miniflare-cli/enum-keys.ts +17 -0
- package/src/miniflare-cli/index.ts +41 -0
- package/src/miniflare-cli/request-context.ts +40 -0
- package/src/module-collection.ts +63 -58
- package/src/open-in-browser.ts +5 -4
- package/src/package-manager.ts +9 -8
- package/src/pages.tsx +883 -62
- package/src/parse.ts +1 -1
- package/src/proxy.ts +32 -21
- package/src/publish.ts +276 -161
- package/src/sites.tsx +88 -33
- package/src/tail/index.ts +2 -2
- package/src/tail/printing.ts +13 -8
- package/src/update-check.ts +19 -0
- package/src/user.tsx +231 -103
- package/src/whoami.tsx +2 -1
- package/src/worker.ts +15 -6
- package/templates/gitignore +171 -0
- package/templates/static-asset-facade.js +1 -1
- package/wrangler-dist/cli.js +22087 -49340
- package/src/__tests__/dev2.test.tsx +0 -152
- package/src/__tests__/helpers/mock-user.ts +0 -27
- package/src/__tests__/logout.test.ts +0 -50
- package/src/__tests__/sentry.test.ts +0 -146
- package/src/reporting.ts +0 -131
- package/wrangler-dist/cli.js.map +0 -7
package/src/module-collection.ts
CHANGED
|
@@ -2,6 +2,7 @@ import crypto from "node:crypto";
|
|
|
2
2
|
import { readFile } from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import globToRegExp from "glob-to-regexp";
|
|
5
|
+
import { logger } from "./logger";
|
|
5
6
|
import type { Config, ConfigModuleRuleType } from "./config";
|
|
6
7
|
import type { CfModule, CfModuleType, CfScriptFormat } from "./worker";
|
|
7
8
|
import type esbuild from "esbuild";
|
|
@@ -58,7 +59,7 @@ export default function createModuleCollector(props: {
|
|
|
58
59
|
if (rule.type in completedRuleLocations) {
|
|
59
60
|
if (rules[completedRuleLocations[rule.type]].fallthrough !== false) {
|
|
60
61
|
if (index < (props.rules || []).length) {
|
|
61
|
-
|
|
62
|
+
logger.warn(
|
|
62
63
|
`The module rule at position ${index} (${JSON.stringify(
|
|
63
64
|
rule
|
|
64
65
|
)}) has the same type as a previous rule (at position ${
|
|
@@ -68,7 +69,7 @@ export default function createModuleCollector(props: {
|
|
|
68
69
|
)}). This rule will be ignored. To the previous rule, add \`fallthrough = true\` to allow this one to also be used, or \`fallthrough = false\` to silence this warning.`
|
|
69
70
|
);
|
|
70
71
|
} else {
|
|
71
|
-
|
|
72
|
+
logger.warn(
|
|
72
73
|
`The default module rule ${JSON.stringify(
|
|
73
74
|
rule
|
|
74
75
|
)} has the same type as a previous rule (at position ${
|
|
@@ -102,7 +103,7 @@ export default function createModuleCollector(props: {
|
|
|
102
103
|
modules.splice(0);
|
|
103
104
|
});
|
|
104
105
|
|
|
105
|
-
// ~ start
|
|
106
|
+
// ~ start legacy module specifier support ~
|
|
106
107
|
|
|
107
108
|
// This section detects usage of "legacy" 1.x style module specifiers
|
|
108
109
|
// and modifies them so they "work" in wrangler v2, but with a warning
|
|
@@ -117,62 +118,67 @@ export default function createModuleCollector(props: {
|
|
|
117
118
|
});
|
|
118
119
|
});
|
|
119
120
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
121
|
+
if (props.wrangler1xlegacyModuleReferences.fileNames.size > 0) {
|
|
122
|
+
build.onResolve(
|
|
123
|
+
{
|
|
124
|
+
filter: new RegExp(
|
|
125
|
+
"^(" +
|
|
126
|
+
[...props.wrangler1xlegacyModuleReferences.fileNames].join(
|
|
127
|
+
"|"
|
|
128
|
+
) +
|
|
129
|
+
")$"
|
|
130
|
+
),
|
|
131
|
+
},
|
|
132
|
+
async (args: esbuild.OnResolveArgs) => {
|
|
133
|
+
if (
|
|
134
|
+
args.kind !== "import-statement" &&
|
|
135
|
+
args.kind !== "require-call"
|
|
136
|
+
) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
// In the future, this will simply throw an error
|
|
140
|
+
logger.warn(
|
|
141
|
+
`Deprecation: detected a legacy module import in "./${path.relative(
|
|
142
|
+
process.cwd(),
|
|
143
|
+
args.importer
|
|
144
|
+
)}". This will stop working in the future. Replace references to "${
|
|
145
|
+
args.path
|
|
146
|
+
}" with "./${args.path}";`
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
// take the file and massage it to a
|
|
150
|
+
// transportable/manageable format
|
|
151
|
+
const filePath = path.join(
|
|
152
|
+
props.wrangler1xlegacyModuleReferences.rootDirectory,
|
|
141
153
|
args.path
|
|
142
|
-
|
|
143
|
-
|
|
154
|
+
);
|
|
155
|
+
const fileContent = await readFile(filePath);
|
|
156
|
+
const fileHash = crypto
|
|
157
|
+
.createHash("sha1")
|
|
158
|
+
.update(fileContent)
|
|
159
|
+
.digest("hex");
|
|
160
|
+
const fileName = `./${fileHash}-${path.basename(args.path)}`;
|
|
144
161
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
// add the module to the array
|
|
162
|
-
modules.push({
|
|
163
|
-
name: fileName,
|
|
164
|
-
content: fileContent,
|
|
165
|
-
type: RuleTypeToModuleType[rule.type],
|
|
166
|
-
});
|
|
167
|
-
return {
|
|
168
|
-
path: fileName, // change the reference to the changed module
|
|
169
|
-
external: props.format === "modules", // mark it as external in the bundle
|
|
170
|
-
namespace: `wrangler-module-${rule.type}`, // just a tag, this isn't strictly necessary
|
|
171
|
-
watchFiles: [filePath], // we also add the file to esbuild's watch list
|
|
172
|
-
};
|
|
162
|
+
const { rule } =
|
|
163
|
+
rulesMatchers.find(({ regex }) => regex.test(fileName)) || {};
|
|
164
|
+
if (rule) {
|
|
165
|
+
// add the module to the array
|
|
166
|
+
modules.push({
|
|
167
|
+
name: fileName,
|
|
168
|
+
content: fileContent,
|
|
169
|
+
type: RuleTypeToModuleType[rule.type],
|
|
170
|
+
});
|
|
171
|
+
return {
|
|
172
|
+
path: fileName, // change the reference to the changed module
|
|
173
|
+
external: props.format === "modules", // mark it as external in the bundle
|
|
174
|
+
namespace: `wrangler-module-${rule.type}`, // just a tag, this isn't strictly necessary
|
|
175
|
+
watchFiles: [filePath], // we also add the file to esbuild's watch list
|
|
176
|
+
};
|
|
177
|
+
}
|
|
173
178
|
}
|
|
174
|
-
|
|
175
|
-
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
176
182
|
// ~ end legacy module specifier support ~
|
|
177
183
|
|
|
178
184
|
rules?.forEach((rule) => {
|
|
@@ -216,10 +222,9 @@ export default function createModuleCollector(props: {
|
|
|
216
222
|
return {
|
|
217
223
|
// We replace the the module with an identifier
|
|
218
224
|
// that we'll separately add to the form upload
|
|
219
|
-
// as part of [wasm_modules]/[text_blobs]. This identifier has to be a valid
|
|
225
|
+
// as part of [wasm_modules]/[text_blobs]/[data_blobs]. This identifier has to be a valid
|
|
220
226
|
// JS identifier, so we replace all non alphanumeric characters
|
|
221
227
|
// with an underscore.
|
|
222
|
-
// TODO: what of "Data"?
|
|
223
228
|
contents: `export default ${args.path.replace(
|
|
224
229
|
/[^a-zA-Z0-9_$]/g,
|
|
225
230
|
"_"
|
package/src/open-in-browser.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import open from "open";
|
|
2
|
+
import { logger } from "./logger";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* An extremely simple wrapper around the open command.
|
|
5
6
|
* Specifically, it adds an 'error' event handler so that when this function
|
|
6
|
-
* is called in environments where we can't open the browser (e.g.
|
|
7
|
-
*
|
|
7
|
+
* is called in environments where we can't open the browser (e.g. GitHub Codespaces,
|
|
8
|
+
* StackBlitz, remote servers), it doesn't just crash the process.
|
|
8
9
|
*
|
|
9
10
|
* @param url the URL to point the browser at
|
|
10
|
-
* @param options open a
|
|
11
|
+
* @param options open a Chromium-based browser instead of the default
|
|
11
12
|
*/
|
|
12
13
|
export default async function openInBrowser(
|
|
13
14
|
url: string,
|
|
@@ -20,6 +21,6 @@ export default async function openInBrowser(
|
|
|
20
21
|
: undefined;
|
|
21
22
|
const childProcess = await open(url, options);
|
|
22
23
|
childProcess.on("error", () => {
|
|
23
|
-
|
|
24
|
+
logger.warn(`Failed to open ${url} in a browser.`);
|
|
24
25
|
});
|
|
25
26
|
}
|
package/src/package-manager.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { execa, execaCommandSync } from "execa";
|
|
4
|
+
import { logger } from "./logger";
|
|
4
5
|
|
|
5
6
|
export interface PackageManager {
|
|
6
7
|
cwd: string;
|
|
@@ -16,26 +17,26 @@ export async function getPackageManager(cwd: string): Promise<PackageManager> {
|
|
|
16
17
|
|
|
17
18
|
if (hasNpmLock) {
|
|
18
19
|
if (hasNpm) {
|
|
19
|
-
|
|
20
|
+
logger.log(
|
|
20
21
|
"Using npm as package manager, as there is already a package-lock.json file."
|
|
21
22
|
);
|
|
22
23
|
return { ...NpmPackageManager, cwd };
|
|
23
24
|
} else if (hasYarn) {
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
logger.log("Using yarn as package manager.");
|
|
26
|
+
logger.warn(
|
|
26
27
|
"There is already a package-lock.json file but could not find npm on the PATH."
|
|
27
28
|
);
|
|
28
29
|
return { ...YarnPackageManager, cwd };
|
|
29
30
|
}
|
|
30
31
|
} else if (hasYarnLock) {
|
|
31
32
|
if (hasYarn) {
|
|
32
|
-
|
|
33
|
+
logger.log(
|
|
33
34
|
"Using yarn as package manager, as there is already a yarn.lock file."
|
|
34
35
|
);
|
|
35
36
|
return { ...YarnPackageManager, cwd };
|
|
36
37
|
} else if (hasNpm) {
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
logger.log("Using npm as package manager.");
|
|
39
|
+
logger.warn(
|
|
39
40
|
"There is already a yarn.lock file but could not find yarn on the PATH."
|
|
40
41
|
);
|
|
41
42
|
return { ...NpmPackageManager, cwd };
|
|
@@ -43,10 +44,10 @@ export async function getPackageManager(cwd: string): Promise<PackageManager> {
|
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
if (hasNpm) {
|
|
46
|
-
|
|
47
|
+
logger.log("Using npm as package manager.");
|
|
47
48
|
return { ...NpmPackageManager, cwd };
|
|
48
49
|
} else if (hasYarn) {
|
|
49
|
-
|
|
50
|
+
logger.log("Using yarn as package manager.");
|
|
50
51
|
return { ...YarnPackageManager, cwd };
|
|
51
52
|
} else {
|
|
52
53
|
throw new Error(
|