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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wrangler",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "author": "wrangler@cloudflare.com",
5
5
  "description": "Command-line interface for all things Cloudflare Workers",
6
6
  "bin": {
@@ -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. */
@@ -117,62 +117,67 @@ export default function createModuleCollector(props: {
117
117
  });
118
118
  });
119
119
 
120
- build.onResolve(
121
- {
122
- filter: new RegExp(
123
- [...props.wrangler1xlegacyModuleReferences.fileNames]
124
- .map((fileName) => `^${fileName}$`)
125
- .join("|")
126
- ),
127
- },
128
- async (args: esbuild.OnResolveArgs) => {
129
- if (
130
- args.kind !== "import-statement" &&
131
- args.kind !== "require-call"
132
- ) {
133
- return;
134
- }
135
- // In the future, this will simply throw an error
136
- console.warn(
137
- `Deprecation warning: detected a legacy module import in "./${path.relative(
138
- process.cwd(),
139
- args.importer
140
- )}". This will stop working in the future. Replace references to "${
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
- }" with "./${args.path}";`
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
- // take the file and massage it to a
146
- // transportable/manageable format
147
- const filePath = path.join(
148
- props.wrangler1xlegacyModuleReferences.rootDirectory,
149
- args.path
150
- );
151
- const fileContent = await readFile(filePath);
152
- const fileHash = crypto
153
- .createHash("sha1")
154
- .update(fileContent)
155
- .digest("hex");
156
- const fileName = `./${fileHash}-${path.basename(args.path)}`;
157
-
158
- const { rule } =
159
- rulesMatchers.find(({ regex }) => regex.test(fileName)) || {};
160
- if (rule) {
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) => {
@@ -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.21";
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
- build5.onResolve({
138098
- filter: new RegExp([...props.wrangler1xlegacyModuleReferences.fileNames].map((fileName) => `^${fileName}$`).join("|"))
138099
- }, async (args2) => {
138100
- if (args2.kind !== "import-statement" && args2.kind !== "require-call") {
138101
- return;
138102
- }
138103
- 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}";`);
138104
- const filePath = import_node_path12.default.join(props.wrangler1xlegacyModuleReferences.rootDirectory, args2.path);
138105
- const fileContent = await (0, import_promises2.readFile)(filePath);
138106
- const fileHash = import_node_crypto2.default.createHash("sha1").update(fileContent).digest("hex");
138107
- const fileName = `./${fileHash}-${import_node_path12.default.basename(args2.path)}`;
138108
- const { rule } = rulesMatchers.find(({ regex }) => regex.test(fileName)) || {};
138109
- if (rule) {
138110
- modules.push({
138111
- name: fileName,
138112
- content: fileContent,
138113
- type: RuleTypeToModuleType[rule.type]
138114
- });
138115
- return {
138116
- path: fileName,
138117
- external: props.format === "modules",
138118
- namespace: `wrangler-module-${rule.type}`,
138119
- watchFiles: [filePath]
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;