wrangler 2.10.0 → 2.11.0

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.
@@ -441,7 +441,11 @@ async function generateHandler({
441
441
  async function generateResponse() {
442
442
  const match = staticRedirectsMatcher() || generateRedirectsMatcher()({ request })[0];
443
443
  if (match) {
444
- return getResponseFromMatch(match, url);
444
+ if (match.status === 200) {
445
+ pathname = new URL(match.to, request.url).pathname;
446
+ } else {
447
+ return getResponseFromMatch(match, url);
448
+ }
445
449
  }
446
450
  if (!request.method.match(/^(get|head)$/i)) {
447
451
  return new MethodNotAllowedResponse();
@@ -5615,7 +5619,7 @@ import { join } from "node:path";
5615
5619
  var REDIRECTS_VERSION = 1;
5616
5620
  var HEADERS_VERSION = 2;
5617
5621
  var ANALYTICS_VERSION = 1;
5618
- var PERMITTED_STATUS_CODES = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
5622
+ var PERMITTED_STATUS_CODES = /* @__PURE__ */ new Set([200, 301, 302, 303, 307, 308]);
5619
5623
  var HEADER_SEPARATOR = ":";
5620
5624
  var MAX_LINE_LENGTH = 2e3;
5621
5625
  var MAX_HEADER_RULES = 100;
@@ -5994,7 +5998,7 @@ function parseRedirects(input) {
5994
5998
  invalid.push({
5995
5999
  line,
5996
6000
  lineNumber: i + 1,
5997
- message: `Valid status codes are 301, 302 (default), 303, 307, or 308. Got ${str_status}.`
6001
+ message: `Valid status codes are 200, 301, 302 (default), 303, 307, or 308. Got ${str_status}.`
5998
6002
  });
5999
6003
  continue;
6000
6004
  }
@@ -6007,6 +6011,19 @@ function parseRedirects(input) {
6007
6011
  continue;
6008
6012
  }
6009
6013
  seen_paths.add(from);
6014
+ if (status === 200) {
6015
+ const [proxyTo, error] = validateUrl(to, true, true, true);
6016
+ if (error) {
6017
+ invalid.push({
6018
+ line,
6019
+ lineNumber: i + 1,
6020
+ message: `Proxy (200) redirects can only point to relative paths. Got ${to}`
6021
+ });
6022
+ continue;
6023
+ }
6024
+ rules.push({ from, to: proxyTo, status, lineNumber: i + 1 });
6025
+ continue;
6026
+ }
6010
6027
  rules.push({ from, to, status, lineNumber: i + 1 });
6011
6028
  }
6012
6029
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wrangler",
3
- "version": "2.10.0",
3
+ "version": "2.11.0",
4
4
  "description": "Command-line interface for all things Cloudflare Workers",
5
5
  "keywords": [
6
6
  "wrangler",
@@ -63,7 +63,7 @@
63
63
  "emit-types": "tsc -p tsconfig.emit.json && node -r esbuild-register scripts/emit-types.ts",
64
64
  "prepublishOnly": "SOURCEMAPS=false npm run build",
65
65
  "start": "npm run bundle && cross-env NODE_OPTIONS=--enable-source-maps ./bin/wrangler.js",
66
- "test": "npm run assert-git-version && jest --silent=false --verbose=true",
66
+ "test": "npm run assert-git-version && jest --silent=false --verbose=true --forceExit",
67
67
  "test-watch": "npm run test -- --runInBand --testTimeout=50000 --watch",
68
68
  "test:ci": "npm run test -- --verbose=true --coverage"
69
69
  },
@@ -100,13 +100,13 @@
100
100
  "@cloudflare/kv-asset-handler": "^0.2.0",
101
101
  "@esbuild-plugins/node-globals-polyfill": "^0.1.1",
102
102
  "@esbuild-plugins/node-modules-polyfill": "^0.1.4",
103
- "@miniflare/core": "2.12.0",
104
- "@miniflare/d1": "2.12.0",
105
- "@miniflare/durable-objects": "2.12.0",
103
+ "@miniflare/core": "2.12.1",
104
+ "@miniflare/d1": "2.12.1",
105
+ "@miniflare/durable-objects": "2.12.1",
106
106
  "blake3-wasm": "^2.1.5",
107
107
  "chokidar": "^3.5.3",
108
108
  "esbuild": "0.16.3",
109
- "miniflare": "2.12.0",
109
+ "miniflare": "2.12.1",
110
110
  "nanoid": "^3.3.3",
111
111
  "path-to-regexp": "^6.2.0",
112
112
  "selfsigned": "^2.0.1",
@@ -118,7 +118,7 @@
118
118
  "@cloudflare/workers-types": "^4.20221111.1",
119
119
  "@iarna/toml": "^3.0.0",
120
120
  "@microsoft/api-extractor": "^7.28.3",
121
- "@miniflare/tre": "^3.0.0-next.8",
121
+ "@miniflare/tre": "^3.0.0-next.10",
122
122
  "@types/better-sqlite3": "^7.6.0",
123
123
  "@types/busboy": "^1.5.0",
124
124
  "@types/command-exists": "^1.2.0",
@@ -179,7 +179,7 @@
179
179
  "timeago.js": "^4.0.2",
180
180
  "tmp-promise": "^3.0.3",
181
181
  "ts-dedent": "^2.2.0",
182
- "undici": "5.11.0",
182
+ "undici": "5.20.0",
183
183
  "update-check": "^1.5.4",
184
184
  "ws": "^8.5.0",
185
185
  "xdg-app-paths": "^7.3.0",
@@ -32,6 +32,41 @@ describe("guess worker format", () => {
32
32
  expect(guess).toBe("service-worker");
33
33
  });
34
34
 
35
+ it('should detect a "service-worker" worker using `typeof module`', async () => {
36
+ await writeFile("./index.ts", "typeof module");
37
+ const guess = await guessWorkerFormat(
38
+ path.join(process.cwd(), "./index.ts"),
39
+ process.cwd(),
40
+ undefined
41
+ );
42
+ expect(guess).toBe("service-worker");
43
+ });
44
+
45
+ it('should detect a "service-worker" worker using imports', async () => {
46
+ await writeFile(
47
+ "./dep.ts",
48
+ `
49
+ const value = 'thing';
50
+ export default value;
51
+ `
52
+ );
53
+ await writeFile(
54
+ "./index.ts",
55
+ `
56
+ import value from './dep.ts';
57
+ addEventListener('fetch', (event) => {
58
+ event.respondWith(new Response(value));
59
+ });
60
+ `
61
+ );
62
+ const guess = await guessWorkerFormat(
63
+ path.join(process.cwd(), "./index.ts"),
64
+ process.cwd(),
65
+ undefined
66
+ );
67
+ expect(guess).toBe("service-worker");
68
+ });
69
+
35
70
  it("should throw an error when the hint doesn't match the guess (modules - service-worker)", async () => {
36
71
  await writeFile("./index.ts", "export default {};");
37
72
  await expect(
@@ -6489,9 +6489,22 @@ addEventListener('fetch', event => {});`
6489
6489
  `);
6490
6490
  });
6491
6491
 
6492
- it("should output to target es2020 even if tsconfig says otherwise", async () => {
6492
+ it("should output to target es2022 even if tsconfig says otherwise", async () => {
6493
6493
  writeWranglerToml();
6494
6494
  writeWorkerSource();
6495
+ fs.writeFileSync(
6496
+ "./index.js",
6497
+ `
6498
+ import { foo } from "./another";
6499
+ const topLevelAwait = await new Promise((resolve) => setTimeout(resolve, 0));
6500
+
6501
+ export default {
6502
+ async fetch(request) {
6503
+
6504
+ return new Response("Hello world!");
6505
+ },
6506
+ };`
6507
+ );
6495
6508
  fs.writeFileSync(
6496
6509
  "tsconfig.json",
6497
6510
  JSON.stringify({
@@ -6502,8 +6515,14 @@ addEventListener('fetch', event => {});`
6502
6515
  })
6503
6516
  );
6504
6517
  mockSubDomainRequest();
6518
+ /**
6519
+ * When we compile with es2022, we should preserve the export statement and top level await
6520
+ * If you attempt to target es2020 top level await will cause a build error
6521
+ * @error Build failed with 1 error:
6522
+ * index.js:3:25: ERROR: Top-level await is not available in the configured target environment ("es2020")
6523
+ */
6505
6524
  mockUploadWorkerRequest({
6506
- expectedEntry: "export {", // just check that the export is preserved
6525
+ expectedEntry: "export {", // check that the export is preserved
6507
6526
  });
6508
6527
  await runWrangler("publish index.js"); // this would throw if we tried to compile with es5
6509
6528
  expect(std).toMatchInlineSnapshot(`
@@ -7448,7 +7467,7 @@ function mockLastDeploymentRequest() {
7448
7467
  function mockUploadWorkerRequest(
7449
7468
  options: {
7450
7469
  available_on_subdomain?: boolean;
7451
- expectedEntry?: string;
7470
+ expectedEntry?: string | RegExp;
7452
7471
  expectedMainModule?: string;
7453
7472
  expectedType?: "esm" | "sw";
7454
7473
  expectedBindings?: unknown;