wrangler 0.0.0-e043479 → 0.0.0-e09abbc
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/Cloudflare_CA.pem +18 -0
- package/README.md +33 -14
- package/bin/wrangler.js +160 -28
- package/kv-asset-handler.js +1 -0
- package/miniflare-dist/index.mjs +5354 -0
- package/package.json +166 -136
- package/src/__tests__/config-cache-without-cache-dir.test.ts +38 -0
- package/src/__tests__/config-cache.test.ts +42 -0
- package/src/__tests__/configuration.test.ts +3942 -2178
- package/src/__tests__/dev.test.tsx +1191 -235
- package/src/__tests__/guess-worker-format.test.ts +76 -57
- package/src/__tests__/helpers/cmd-shim.d.ts +6 -6
- package/src/__tests__/helpers/mock-account-id.ts +26 -22
- package/src/__tests__/helpers/mock-bin.ts +20 -20
- package/src/__tests__/helpers/mock-cfetch.ts +96 -92
- package/src/__tests__/helpers/mock-console.ts +59 -32
- package/src/__tests__/helpers/mock-dialogs.ts +121 -33
- package/src/__tests__/helpers/mock-http-server.ts +46 -0
- package/src/__tests__/helpers/mock-istty.ts +74 -0
- package/src/__tests__/helpers/mock-kv.ts +28 -35
- package/src/__tests__/helpers/mock-oauth-flow.ts +250 -0
- package/src/__tests__/helpers/mock-process.ts +39 -0
- package/src/__tests__/helpers/mock-stdin.ts +82 -77
- package/src/__tests__/helpers/mock-web-socket.ts +21 -21
- package/src/__tests__/helpers/run-in-tmp.ts +29 -20
- package/src/__tests__/helpers/run-wrangler.ts +8 -8
- package/src/__tests__/helpers/write-worker-source.ts +31 -0
- package/src/__tests__/helpers/write-wrangler-toml.ts +9 -9
- package/src/__tests__/https-options.test.ts +163 -0
- package/src/__tests__/index.test.ts +246 -850
- package/src/__tests__/init.test.ts +1992 -0
- package/src/__tests__/jest.setup.ts +85 -34
- package/src/__tests__/kv.test.ts +1402 -1139
- package/src/__tests__/logger.test.ts +141 -0
- package/src/__tests__/metrics.test.ts +445 -0
- package/src/__tests__/package-manager.test.ts +312 -165
- package/src/__tests__/pages.test.ts +1261 -0
- package/src/__tests__/parse.test.ts +253 -245
- package/src/__tests__/publish.test.ts +6611 -2079
- package/src/__tests__/pubsub.test.ts +367 -0
- package/src/__tests__/r2.test.ts +184 -149
- package/src/__tests__/route.test.ts +45 -0
- package/src/__tests__/secret.test.ts +474 -407
- package/src/__tests__/tail.test.ts +565 -431
- package/src/__tests__/test-old-node-version.js +31 -0
- package/src/__tests__/user.test.ts +143 -0
- package/src/__tests__/whoami.test.tsx +219 -75
- package/src/__tests__/worker-namespace.test.ts +327 -0
- package/src/abort.d.ts +3 -0
- package/src/api/dev.ts +86 -0
- package/src/api/index.ts +1 -0
- package/src/bundle-reporter.tsx +29 -0
- package/src/bundle.ts +196 -93
- package/src/cfetch/index.ts +83 -66
- package/src/cfetch/internal.ts +100 -84
- package/src/cli.ts +22 -14
- package/src/config/README.md +7 -7
- package/src/config/config.ts +223 -242
- package/src/config/diagnostics.ts +61 -61
- package/src/config/environment.ts +404 -256
- package/src/config/index.ts +218 -32
- package/src/config/validation-helpers.ts +436 -222
- package/src/config/validation.ts +1642 -907
- package/src/config-cache.ts +84 -0
- package/src/create-worker-preview.ts +255 -0
- package/src/create-worker-upload-form.ts +263 -0
- package/src/dev/dev-vars.ts +36 -0
- package/src/dev/dev.tsx +452 -0
- package/src/dev/local.tsx +373 -0
- package/src/dev/remote.tsx +386 -0
- package/src/dev/use-esbuild.ts +150 -0
- package/src/dev.tsx +576 -943
- package/src/dialogs.tsx +115 -57
- package/src/durable.ts +102 -0
- package/src/entry.ts +308 -37
- package/src/environment-variables.ts +25 -23
- package/src/errors.ts +11 -0
- package/src/faye-websocket.d.ts +6 -0
- package/src/generate.ts +33 -0
- package/src/git-client.ts +42 -0
- package/src/global-wrangler-config-path.ts +26 -0
- package/src/https-options.ts +127 -0
- package/src/index.tsx +1910 -2241
- package/src/init.ts +549 -0
- package/src/inspect.ts +603 -550
- package/src/intl-polyfill.d.ts +139 -0
- package/src/is-interactive.ts +12 -0
- package/src/kv.ts +430 -0
- package/src/logger.ts +73 -0
- package/src/metrics/index.ts +4 -0
- package/src/metrics/is-ci.ts +14 -0
- package/src/metrics/metrics-config.ts +239 -0
- package/src/metrics/metrics-dispatcher.ts +95 -0
- package/src/metrics/send-event.ts +92 -0
- package/src/miniflare-cli/README.md +30 -0
- package/src/miniflare-cli/assets.ts +543 -0
- package/src/miniflare-cli/enum-keys.ts +17 -0
- package/src/miniflare-cli/index.ts +85 -0
- package/src/miniflare-cli/request-context.ts +40 -0
- package/src/module-collection.ts +234 -146
- package/src/open-in-browser.ts +10 -6
- package/src/package-manager.ts +183 -90
- package/src/pages/build.tsx +204 -0
- package/src/pages/constants.ts +7 -0
- package/src/pages/deployments.tsx +106 -0
- package/src/pages/dev.tsx +401 -0
- package/src/pages/functions/buildPlugin.ts +105 -0
- package/src/pages/functions/buildWorker.ts +151 -0
- package/src/pages/functions/filepath-routing.test.ts +234 -0
- package/src/pages/functions/filepath-routing.ts +189 -0
- package/src/pages/functions/identifiers.ts +78 -0
- package/src/pages/functions/routes.ts +151 -0
- package/src/pages/index.tsx +84 -0
- package/src/pages/projects.tsx +163 -0
- package/src/pages/publish.tsx +338 -0
- package/src/pages/types.ts +40 -0
- package/src/pages/upload.tsx +396 -0
- package/src/pages/utils.ts +12 -0
- package/src/parse.ts +224 -121
- package/src/paths.ts +6 -6
- package/src/preview.ts +31 -0
- package/src/proxy.ts +413 -313
- package/src/publish.ts +773 -343
- package/src/pubsub/index.ts +286 -0
- package/src/pubsub/pubsub-commands.tsx +623 -0
- package/src/r2.ts +19 -19
- package/src/selfsigned.d.ts +29 -0
- package/src/sites.tsx +285 -151
- package/src/tail/filters.ts +108 -108
- package/src/tail/index.ts +217 -217
- package/src/tail/printing.ts +51 -46
- package/src/update-check.ts +19 -0
- package/src/user/choose-account.tsx +69 -0
- package/src/user/env-vars.ts +46 -0
- package/src/user/generate-auth-url.ts +33 -0
- package/src/user/generate-random-state.ts +16 -0
- package/src/user/index.ts +3 -0
- package/src/user/user.tsx +1171 -0
- package/src/whoami.tsx +63 -41
- package/src/worker-namespace.ts +206 -0
- package/src/worker.ts +191 -0
- package/src/zones.ts +76 -0
- package/templates/checked-fetch.js +17 -0
- package/templates/gitignore +171 -0
- package/templates/new-worker-scheduled.js +17 -0
- package/templates/new-worker-scheduled.ts +32 -0
- package/templates/new-worker.js +3 -3
- package/templates/new-worker.ts +18 -3
- package/templates/no-op-worker.js +10 -0
- package/templates/pages-shim.ts +9 -0
- package/templates/pages-template-plugin.ts +155 -0
- package/templates/pages-template-worker.ts +161 -0
- package/templates/static-asset-facade.js +38 -36
- package/templates/tsconfig.json +95 -95
- package/wrangler-dist/cli.d.ts +327 -0
- package/wrangler-dist/cli.js +94947 -111199
- package/pages/functions/buildWorker.ts +0 -62
- package/pages/functions/filepath-routing.test.ts +0 -123
- package/pages/functions/filepath-routing.ts +0 -178
- package/pages/functions/identifiers.ts +0 -78
- package/pages/functions/routes.ts +0 -151
- package/pages/functions/template-worker.ts +0 -130
- package/src/__tests__/helpers/faye-websocket.d.ts +0 -6
- 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/api/form_data.ts +0 -217
- package/src/api/preview.ts +0 -147
- package/src/api/worker.ts +0 -186
- package/src/guess-worker-format.ts +0 -68
- package/src/kv.tsx +0 -339
- package/src/pages.tsx +0 -1045
- package/src/reporting.ts +0 -115
- package/src/user.tsx +0 -1063
- package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
- package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
- package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
- package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
- package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
- package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
- package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
- package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
- package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
- package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
- package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
- package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
- package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
- package/vendor/wrangler-mime/CHANGELOG.md +0 -289
- package/vendor/wrangler-mime/LICENSE +0 -21
- package/vendor/wrangler-mime/Mime.js +0 -97
- package/vendor/wrangler-mime/README.md +0 -187
- package/vendor/wrangler-mime/cli.js +0 -46
- package/vendor/wrangler-mime/index.js +0 -4
- package/vendor/wrangler-mime/lite.js +0 -4
- package/vendor/wrangler-mime/package.json +0 -52
- package/vendor/wrangler-mime/types/other.js +0 -1
- package/vendor/wrangler-mime/types/standard.js +0 -1
- package/wrangler-dist/cli.js.map +0 -7
package/src/module-collection.ts
CHANGED
|
@@ -2,16 +2,17 @@ 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
|
|
5
|
+
import { logger } from "./logger";
|
|
6
6
|
import type { Config, ConfigModuleRuleType } from "./config";
|
|
7
|
+
import type { CfModule, CfModuleType, CfScriptFormat } from "./worker";
|
|
7
8
|
import type esbuild from "esbuild";
|
|
8
9
|
|
|
9
10
|
const RuleTypeToModuleType: Record<ConfigModuleRuleType, CfModuleType> = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
ESModule: "esm",
|
|
12
|
+
CommonJS: "commonjs",
|
|
13
|
+
CompiledWasm: "compiled-wasm",
|
|
14
|
+
Data: "buffer",
|
|
15
|
+
Text: "text",
|
|
15
16
|
};
|
|
16
17
|
|
|
17
18
|
// This is a combination of an esbuild plugin and a mutable array
|
|
@@ -23,148 +24,235 @@ const RuleTypeToModuleType: Record<ConfigModuleRuleType, CfModuleType> = {
|
|
|
23
24
|
// them correctly in the bundle, and add them to the form upload.
|
|
24
25
|
|
|
25
26
|
export const DEFAULT_MODULE_RULES: Config["rules"] = [
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
{ type: "Text", globs: ["**/*.txt", "**/*.html"] },
|
|
28
|
+
{ type: "Data", globs: ["**/*.bin"] },
|
|
29
|
+
{ type: "CompiledWasm", globs: ["**/*.wasm"] },
|
|
29
30
|
];
|
|
30
31
|
|
|
31
|
-
export default function
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
export default function createModuleCollector(props: {
|
|
33
|
+
format: CfScriptFormat;
|
|
34
|
+
rules?: Config["rules"];
|
|
35
|
+
// a collection of "legacy" style module references, which are just file names
|
|
36
|
+
// we will eventually deprecate this functionality, hence the verbose greppable name
|
|
37
|
+
wrangler1xlegacyModuleReferences: {
|
|
38
|
+
rootDirectory: string;
|
|
39
|
+
fileNames: Set<string>;
|
|
40
|
+
};
|
|
34
41
|
}): {
|
|
35
|
-
|
|
36
|
-
|
|
42
|
+
modules: CfModule[];
|
|
43
|
+
plugin: esbuild.Plugin;
|
|
37
44
|
} {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
45
|
+
const rules: Config["rules"] = [
|
|
46
|
+
...(props.rules || []),
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
48
|
+
...DEFAULT_MODULE_RULES!,
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
// First, we want to add some validations to the module rules
|
|
52
|
+
// We want to warn if rules are accidentally configured in such a way that
|
|
53
|
+
// subsequent rules will never match because `fallthrough` hasn't been set
|
|
54
|
+
|
|
55
|
+
const completedRuleLocations: Record<string, number> = {};
|
|
56
|
+
let index = 0;
|
|
57
|
+
const rulesToRemove: Config["rules"] = [];
|
|
58
|
+
for (const rule of rules) {
|
|
59
|
+
if (rule.type in completedRuleLocations) {
|
|
60
|
+
if (rules[completedRuleLocations[rule.type]].fallthrough !== false) {
|
|
61
|
+
if (index < (props.rules || []).length) {
|
|
62
|
+
logger.warn(
|
|
63
|
+
`The module rule at position ${index} (${JSON.stringify(
|
|
64
|
+
rule
|
|
65
|
+
)}) has the same type as a previous rule (at position ${
|
|
66
|
+
completedRuleLocations[rule.type]
|
|
67
|
+
}, ${JSON.stringify(
|
|
68
|
+
rules[completedRuleLocations[rule.type]]
|
|
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.`
|
|
70
|
+
);
|
|
71
|
+
} else {
|
|
72
|
+
logger.warn(
|
|
73
|
+
`The default module rule ${JSON.stringify(
|
|
74
|
+
rule
|
|
75
|
+
)} has the same type as a previous rule (at position ${
|
|
76
|
+
completedRuleLocations[rule.type]
|
|
77
|
+
}, ${JSON.stringify(
|
|
78
|
+
rules[completedRuleLocations[rule.type]]
|
|
79
|
+
)}). This rule will be ignored. To the previous rule, add \`fallthrough = true\` to allow the default one to also be used, or \`fallthrough = false\` to silence this warning.`
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
rulesToRemove.push(rule);
|
|
85
|
+
}
|
|
86
|
+
if (!(rule.type in completedRuleLocations) && rule.fallthrough !== true) {
|
|
87
|
+
completedRuleLocations[rule.type] = index;
|
|
88
|
+
}
|
|
89
|
+
index++;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
93
|
+
rulesToRemove.forEach((rule) => rules!.splice(rules!.indexOf(rule), 1));
|
|
94
|
+
|
|
95
|
+
const modules: CfModule[] = [];
|
|
96
|
+
return {
|
|
97
|
+
modules,
|
|
98
|
+
plugin: {
|
|
99
|
+
name: "wrangler-module-collector",
|
|
100
|
+
setup(build) {
|
|
101
|
+
build.onStart(() => {
|
|
102
|
+
// reset the module collection array
|
|
103
|
+
modules.splice(0);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// ~ start legacy module specifier support ~
|
|
107
|
+
|
|
108
|
+
// This section detects usage of "legacy" 1.x style module specifiers
|
|
109
|
+
// and modifies them so they "work" in wrangler v2, but with a warning
|
|
110
|
+
|
|
111
|
+
const rulesMatchers = rules.flatMap((rule) => {
|
|
112
|
+
return rule.globs.map((glob) => {
|
|
113
|
+
const regex = globToRegExp(glob);
|
|
114
|
+
return {
|
|
115
|
+
regex,
|
|
116
|
+
rule,
|
|
117
|
+
};
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
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,
|
|
153
|
+
args.path
|
|
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)}`;
|
|
161
|
+
|
|
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
|
+
}
|
|
178
|
+
}
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// ~ end legacy module specifier support ~
|
|
183
|
+
|
|
184
|
+
rules?.forEach((rule) => {
|
|
185
|
+
if (rule.type === "ESModule" || rule.type === "CommonJS") return; // TODO: we should treat these as js files, and use the jsx loader
|
|
186
|
+
|
|
187
|
+
rule.globs.forEach((glob) => {
|
|
188
|
+
build.onResolve(
|
|
189
|
+
{ filter: globToRegExp(glob) },
|
|
190
|
+
async (args: esbuild.OnResolveArgs) => {
|
|
191
|
+
// take the file and massage it to a
|
|
192
|
+
// transportable/manageable format
|
|
193
|
+
|
|
194
|
+
const filePath = path.join(args.resolveDir, args.path);
|
|
195
|
+
const fileContent = await readFile(filePath);
|
|
196
|
+
const fileHash = crypto
|
|
197
|
+
.createHash("sha1")
|
|
198
|
+
.update(fileContent)
|
|
199
|
+
.digest("hex");
|
|
200
|
+
const fileName = `./${fileHash}-${path.basename(args.path)}`;
|
|
201
|
+
|
|
202
|
+
// add the module to the array
|
|
203
|
+
modules.push({
|
|
204
|
+
name: fileName,
|
|
205
|
+
content: fileContent,
|
|
206
|
+
type: RuleTypeToModuleType[rule.type],
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
return {
|
|
210
|
+
path: fileName, // change the reference to the changed module
|
|
211
|
+
external: props.format === "modules", // mark it as external in the bundle
|
|
212
|
+
namespace: `wrangler-module-${rule.type}`, // just a tag, this isn't strictly necessary
|
|
213
|
+
watchFiles: [filePath], // we also add the file to esbuild's watch list
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
if (props.format === "service-worker") {
|
|
219
|
+
build.onLoad(
|
|
220
|
+
{ filter: globToRegExp(glob) },
|
|
221
|
+
async (args: esbuild.OnLoadArgs) => {
|
|
222
|
+
return {
|
|
223
|
+
// We replace the the module with an identifier
|
|
224
|
+
// that we'll separately add to the form upload
|
|
225
|
+
// as part of [wasm_modules]/[text_blobs]/[data_blobs]. This identifier has to be a valid
|
|
226
|
+
// JS identifier, so we replace all non alphanumeric characters
|
|
227
|
+
// with an underscore.
|
|
228
|
+
contents: `export default ${args.path.replace(
|
|
229
|
+
/[^a-zA-Z0-9_$]/g,
|
|
230
|
+
"_"
|
|
231
|
+
)};`,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
rulesToRemove.forEach((rule) => {
|
|
240
|
+
rule.globs.forEach((glob) => {
|
|
241
|
+
build.onResolve(
|
|
242
|
+
{ filter: globToRegExp(glob) },
|
|
243
|
+
async (args: esbuild.OnResolveArgs) => {
|
|
244
|
+
throw new Error(
|
|
245
|
+
`The file ${
|
|
246
|
+
args.path
|
|
247
|
+
} matched a module rule in your configuration (${JSON.stringify(
|
|
248
|
+
rule
|
|
249
|
+
)}), but was ignored because a previous rule with the same type was not marked as \`fallthrough = true\`.`
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
);
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
};
|
|
170
258
|
}
|
package/src/open-in-browser.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import open from "open";
|
|
2
|
+
import { logger } from "./logger";
|
|
3
|
+
|
|
2
4
|
/**
|
|
3
5
|
* An extremely simple wrapper around the open command.
|
|
4
6
|
* Specifically, it adds an 'error' event handler so that when this function
|
|
5
|
-
* is called in environments where we can't open the browser (e.g.
|
|
6
|
-
*
|
|
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.
|
|
9
|
+
*
|
|
10
|
+
* @param url the URL to point the browser at
|
|
7
11
|
*/
|
|
8
12
|
export default async function openInBrowser(url: string): Promise<void> {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
const childProcess = await open(url);
|
|
14
|
+
childProcess.on("error", () => {
|
|
15
|
+
logger.warn("Failed to open");
|
|
16
|
+
});
|
|
13
17
|
}
|