wrangler 0.0.21 → 0.0.22
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/package.json +1 -1
- package/src/__tests__/publish.test.ts +24 -0
- package/src/module-collection.ts +58 -53
- package/wrangler-dist/cli.js +29 -27
- package/wrangler-dist/cli.js.map +2 -2
package/package.json
CHANGED
|
@@ -2362,6 +2362,30 @@ export default{
|
|
|
2362
2362
|
`"Deprecation warning: detected a legacy module import in \\"./index.js\\". This will stop working in the future. Replace references to \\"index.wasm\\" with \\"./index.wasm\\";"`
|
|
2363
2363
|
);
|
|
2364
2364
|
});
|
|
2365
|
+
|
|
2366
|
+
it("should not match regular module specifiers when there aren't any possible legacy module matches", async () => {
|
|
2367
|
+
// see https://github.com/cloudflare/wrangler2/issues/655 for bug details
|
|
2368
|
+
|
|
2369
|
+
fs.writeFileSync(
|
|
2370
|
+
"./index.js",
|
|
2371
|
+
`import inner from './inner/index.js'; export default {};`
|
|
2372
|
+
);
|
|
2373
|
+
fs.mkdirSync("./inner", { recursive: true });
|
|
2374
|
+
fs.writeFileSync("./inner/index.js", `export default 123`);
|
|
2375
|
+
mockSubDomainRequest();
|
|
2376
|
+
mockUploadWorkerRequest();
|
|
2377
|
+
|
|
2378
|
+
await runWrangler(
|
|
2379
|
+
"publish index.js --compatibility-date 2022-03-17 --name test-name"
|
|
2380
|
+
);
|
|
2381
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
2382
|
+
"Uploaded test-name (TIMINGS)
|
|
2383
|
+
Published test-name (TIMINGS)
|
|
2384
|
+
test-name.test-sub-domain.workers.dev"
|
|
2385
|
+
`);
|
|
2386
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
2387
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
2388
|
+
});
|
|
2365
2389
|
});
|
|
2366
2390
|
|
|
2367
2391
|
/** Write a mock Worker script to disk. */
|
package/src/module-collection.ts
CHANGED
|
@@ -117,62 +117,67 @@ export default function createModuleCollector(props: {
|
|
|
117
117
|
});
|
|
118
118
|
});
|
|
119
119
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
120
|
+
if (props.wrangler1xlegacyModuleReferences.fileNames.size > 0) {
|
|
121
|
+
build.onResolve(
|
|
122
|
+
{
|
|
123
|
+
filter: new RegExp(
|
|
124
|
+
"^(" +
|
|
125
|
+
[...props.wrangler1xlegacyModuleReferences.fileNames].join(
|
|
126
|
+
"|"
|
|
127
|
+
) +
|
|
128
|
+
")$"
|
|
129
|
+
),
|
|
130
|
+
},
|
|
131
|
+
async (args: esbuild.OnResolveArgs) => {
|
|
132
|
+
if (
|
|
133
|
+
args.kind !== "import-statement" &&
|
|
134
|
+
args.kind !== "require-call"
|
|
135
|
+
) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
// In the future, this will simply throw an error
|
|
139
|
+
console.warn(
|
|
140
|
+
`Deprecation warning: detected a legacy module import in "./${path.relative(
|
|
141
|
+
process.cwd(),
|
|
142
|
+
args.importer
|
|
143
|
+
)}". This will stop working in the future. Replace references to "${
|
|
144
|
+
args.path
|
|
145
|
+
}" with "./${args.path}";`
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
// take the file and massage it to a
|
|
149
|
+
// transportable/manageable format
|
|
150
|
+
const filePath = path.join(
|
|
151
|
+
props.wrangler1xlegacyModuleReferences.rootDirectory,
|
|
141
152
|
args.path
|
|
142
|
-
|
|
143
|
-
|
|
153
|
+
);
|
|
154
|
+
const fileContent = await readFile(filePath);
|
|
155
|
+
const fileHash = crypto
|
|
156
|
+
.createHash("sha1")
|
|
157
|
+
.update(fileContent)
|
|
158
|
+
.digest("hex");
|
|
159
|
+
const fileName = `./${fileHash}-${path.basename(args.path)}`;
|
|
144
160
|
|
|
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
|
-
};
|
|
161
|
+
const { rule } =
|
|
162
|
+
rulesMatchers.find(({ regex }) => regex.test(fileName)) || {};
|
|
163
|
+
if (rule) {
|
|
164
|
+
// add the module to the array
|
|
165
|
+
modules.push({
|
|
166
|
+
name: fileName,
|
|
167
|
+
content: fileContent,
|
|
168
|
+
type: RuleTypeToModuleType[rule.type],
|
|
169
|
+
});
|
|
170
|
+
return {
|
|
171
|
+
path: fileName, // change the reference to the changed module
|
|
172
|
+
external: props.format === "modules", // mark it as external in the bundle
|
|
173
|
+
namespace: `wrangler-module-${rule.type}`, // just a tag, this isn't strictly necessary
|
|
174
|
+
watchFiles: [filePath], // we also add the file to esbuild's watch list
|
|
175
|
+
};
|
|
176
|
+
}
|
|
173
177
|
}
|
|
174
|
-
|
|
175
|
-
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
|
|
176
181
|
// ~ end legacy module specifier support ~
|
|
177
182
|
|
|
178
183
|
rules?.forEach((rule) => {
|
package/wrangler-dist/cli.js
CHANGED
|
@@ -131708,7 +131708,7 @@ var import_prompts = __toESM(require_prompts3());
|
|
|
131708
131708
|
|
|
131709
131709
|
// package.json
|
|
131710
131710
|
var name = "wrangler";
|
|
131711
|
-
var version = "0.0.
|
|
131711
|
+
var version = "0.0.22";
|
|
131712
131712
|
|
|
131713
131713
|
// src/reporting.ts
|
|
131714
131714
|
function initReporting() {
|
|
@@ -138094,32 +138094,34 @@ function createModuleCollector(props) {
|
|
|
138094
138094
|
};
|
|
138095
138095
|
});
|
|
138096
138096
|
});
|
|
138097
|
-
|
|
138098
|
-
|
|
138099
|
-
|
|
138100
|
-
|
|
138101
|
-
|
|
138102
|
-
|
|
138103
|
-
|
|
138104
|
-
|
|
138105
|
-
|
|
138106
|
-
|
|
138107
|
-
|
|
138108
|
-
|
|
138109
|
-
|
|
138110
|
-
|
|
138111
|
-
|
|
138112
|
-
|
|
138113
|
-
|
|
138114
|
-
|
|
138115
|
-
|
|
138116
|
-
|
|
138117
|
-
|
|
138118
|
-
|
|
138119
|
-
|
|
138120
|
-
|
|
138121
|
-
|
|
138122
|
-
|
|
138097
|
+
if (props.wrangler1xlegacyModuleReferences.fileNames.size > 0) {
|
|
138098
|
+
build5.onResolve({
|
|
138099
|
+
filter: new RegExp("^(" + [...props.wrangler1xlegacyModuleReferences.fileNames].join("|") + ")$")
|
|
138100
|
+
}, async (args2) => {
|
|
138101
|
+
if (args2.kind !== "import-statement" && args2.kind !== "require-call") {
|
|
138102
|
+
return;
|
|
138103
|
+
}
|
|
138104
|
+
console.warn(`Deprecation warning: detected a legacy module import in "./${import_node_path12.default.relative(process.cwd(), args2.importer)}". This will stop working in the future. Replace references to "${args2.path}" with "./${args2.path}";`);
|
|
138105
|
+
const filePath = import_node_path12.default.join(props.wrangler1xlegacyModuleReferences.rootDirectory, args2.path);
|
|
138106
|
+
const fileContent = await (0, import_promises2.readFile)(filePath);
|
|
138107
|
+
const fileHash = import_node_crypto2.default.createHash("sha1").update(fileContent).digest("hex");
|
|
138108
|
+
const fileName = `./${fileHash}-${import_node_path12.default.basename(args2.path)}`;
|
|
138109
|
+
const { rule } = rulesMatchers.find(({ regex }) => regex.test(fileName)) || {};
|
|
138110
|
+
if (rule) {
|
|
138111
|
+
modules.push({
|
|
138112
|
+
name: fileName,
|
|
138113
|
+
content: fileContent,
|
|
138114
|
+
type: RuleTypeToModuleType[rule.type]
|
|
138115
|
+
});
|
|
138116
|
+
return {
|
|
138117
|
+
path: fileName,
|
|
138118
|
+
external: props.format === "modules",
|
|
138119
|
+
namespace: `wrangler-module-${rule.type}`,
|
|
138120
|
+
watchFiles: [filePath]
|
|
138121
|
+
};
|
|
138122
|
+
}
|
|
138123
|
+
});
|
|
138124
|
+
}
|
|
138123
138125
|
rules?.forEach((rule) => {
|
|
138124
138126
|
if (rule.type === "ESModule" || rule.type === "CommonJS")
|
|
138125
138127
|
return;
|