wrangler 2.0.28 → 2.0.29
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/miniflare-dist/index.mjs +54 -46
- package/package.json +1 -1
- package/src/__tests__/api-dev.test.ts +19 -0
- package/src/__tests__/helpers/hello-world-worker.js +5 -0
- package/src/__tests__/jest.setup.ts +13 -0
- package/src/__tests__/pages.test.ts +829 -103
- package/src/__tests__/paths.test.ts +17 -0
- package/src/api/dev.ts +74 -28
- package/src/bundle.ts +13 -10
- package/src/cli.ts +1 -1
- package/src/dev/local.tsx +317 -169
- package/src/dev/start-server.ts +412 -0
- package/src/dev.tsx +325 -169
- package/src/entry.ts +2 -1
- package/src/init.ts +5 -5
- package/src/metrics/send-event.ts +1 -0
- package/src/miniflare-cli/assets.ts +4 -65
- package/src/miniflare-cli/index.ts +36 -32
- package/src/pages/constants.ts +3 -0
- package/src/pages/dev.tsx +3 -2
- package/src/pages/functions/buildPlugin.ts +2 -1
- package/src/pages/functions/buildWorker.ts +2 -1
- package/src/pages/functions/routes-transformation.test.ts +12 -1
- package/src/pages/functions/routes-transformation.ts +7 -1
- package/src/pages/publish.tsx +82 -38
- package/src/paths.ts +20 -1
- package/src/worker.ts +7 -7
- package/wrangler-dist/cli.d.ts +15 -5
- package/wrangler-dist/cli.js +2009 -1389
package/miniflare-dist/index.mjs
CHANGED
|
@@ -4934,9 +4934,57 @@ var FatalError = class extends Error {
|
|
|
4934
4934
|
};
|
|
4935
4935
|
|
|
4936
4936
|
// src/miniflare-cli/assets.ts
|
|
4937
|
-
var import_mime = __toESM(require_mime());
|
|
4938
4937
|
import { existsSync, lstatSync, readFileSync as readFileSync4 } from "node:fs";
|
|
4939
4938
|
import { join } from "node:path";
|
|
4939
|
+
|
|
4940
|
+
// ../pages-shared/src/asset-server/rulesEngine.ts
|
|
4941
|
+
var ESCAPE_REGEX_CHARACTERS = /[-/\\^$*+?.()|[\]{}]/g;
|
|
4942
|
+
var escapeRegex = (str) => {
|
|
4943
|
+
return str.replace(ESCAPE_REGEX_CHARACTERS, "\\$&");
|
|
4944
|
+
};
|
|
4945
|
+
var HOST_PLACEHOLDER_REGEX = /(?<=^https:\\\/\\\/[^/]*?):([^\\]+)(?=\\)/g;
|
|
4946
|
+
var PLACEHOLDER_REGEX = /:(\w+)/g;
|
|
4947
|
+
var replacer = (str, replacements) => {
|
|
4948
|
+
for (const [replacement, value] of Object.entries(replacements)) {
|
|
4949
|
+
str = str.replaceAll(`:${replacement}`, value);
|
|
4950
|
+
}
|
|
4951
|
+
return str;
|
|
4952
|
+
};
|
|
4953
|
+
var generateRulesMatcher = (rules, replacerFn = (match) => match) => {
|
|
4954
|
+
if (!rules)
|
|
4955
|
+
return () => [];
|
|
4956
|
+
const compiledRules = Object.entries(rules).map(([rule, match]) => {
|
|
4957
|
+
const crossHost = rule.startsWith("https://");
|
|
4958
|
+
rule = rule.split("*").map(escapeRegex).join("(?<splat>.*)");
|
|
4959
|
+
const host_matches = rule.matchAll(HOST_PLACEHOLDER_REGEX);
|
|
4960
|
+
for (const host_match of host_matches) {
|
|
4961
|
+
rule = rule.split(host_match[0]).join(`(?<${host_match[1]}>[^/.]+)`);
|
|
4962
|
+
}
|
|
4963
|
+
const path_matches = rule.matchAll(PLACEHOLDER_REGEX);
|
|
4964
|
+
for (const path_match of path_matches) {
|
|
4965
|
+
rule = rule.split(path_match[0]).join(`(?<${path_match[1]}>[^/]+)`);
|
|
4966
|
+
}
|
|
4967
|
+
rule = "^" + rule + "$";
|
|
4968
|
+
try {
|
|
4969
|
+
const regExp = new RegExp(rule);
|
|
4970
|
+
return [{ crossHost, regExp }, match];
|
|
4971
|
+
} catch {
|
|
4972
|
+
}
|
|
4973
|
+
}).filter((value) => value !== void 0);
|
|
4974
|
+
return ({ request }) => {
|
|
4975
|
+
const { pathname, host } = new URL(request.url);
|
|
4976
|
+
return compiledRules.map(([{ crossHost, regExp }, match]) => {
|
|
4977
|
+
const test = crossHost ? `https://${host}${pathname}` : pathname;
|
|
4978
|
+
const result = regExp.exec(test);
|
|
4979
|
+
if (result) {
|
|
4980
|
+
return replacerFn(match, result.groups || {});
|
|
4981
|
+
}
|
|
4982
|
+
}).filter((value) => value !== void 0);
|
|
4983
|
+
};
|
|
4984
|
+
};
|
|
4985
|
+
|
|
4986
|
+
// src/miniflare-cli/assets.ts
|
|
4987
|
+
var import_mime = __toESM(require_mime());
|
|
4940
4988
|
import { fetch as miniflareFetch } from "@miniflare/core";
|
|
4941
4989
|
import { watch } from "chokidar";
|
|
4942
4990
|
import { Response } from "miniflare";
|
|
@@ -4967,49 +5015,6 @@ async function generateASSETSBinding(options) {
|
|
|
4967
5015
|
}
|
|
4968
5016
|
};
|
|
4969
5017
|
}
|
|
4970
|
-
function escapeRegex(str) {
|
|
4971
|
-
return str.replace(/[-/\\^$*+?.()|[]{}]/g, "\\$&");
|
|
4972
|
-
}
|
|
4973
|
-
function replacer(str, replacements) {
|
|
4974
|
-
for (const [replacement, value] of Object.entries(replacements)) {
|
|
4975
|
-
str = str.replace(`:${replacement}`, value);
|
|
4976
|
-
}
|
|
4977
|
-
return str;
|
|
4978
|
-
}
|
|
4979
|
-
function generateRulesMatcher(rules, replacerFn = (match) => match) {
|
|
4980
|
-
if (!rules)
|
|
4981
|
-
return () => [];
|
|
4982
|
-
const compiledRules = Object.entries(rules).map(([rule, match]) => {
|
|
4983
|
-
const crossHost = rule.startsWith("https://");
|
|
4984
|
-
rule = rule.split("*").map(escapeRegex).join("(?<splat>.*)");
|
|
4985
|
-
const host_matches = rule.matchAll(
|
|
4986
|
-
/(?<=^https:\\\/\\\/[^/]*?):([^\\]+)(?=\\)/g
|
|
4987
|
-
);
|
|
4988
|
-
for (const hostMatch of host_matches) {
|
|
4989
|
-
rule = rule.split(hostMatch[0]).join(`(?<${hostMatch[1]}>[^/.]+)`);
|
|
4990
|
-
}
|
|
4991
|
-
const path_matches = rule.matchAll(/:(\w+)/g);
|
|
4992
|
-
for (const pathMatch of path_matches) {
|
|
4993
|
-
rule = rule.split(pathMatch[0]).join(`(?<${pathMatch[1]}>[^/]+)`);
|
|
4994
|
-
}
|
|
4995
|
-
rule = "^" + rule + "$";
|
|
4996
|
-
try {
|
|
4997
|
-
const regExp = new RegExp(rule);
|
|
4998
|
-
return [{ crossHost, regExp }, match];
|
|
4999
|
-
} catch {
|
|
5000
|
-
}
|
|
5001
|
-
}).filter((value) => value !== void 0);
|
|
5002
|
-
return ({ request }) => {
|
|
5003
|
-
const { pathname, host } = new URL(request.url);
|
|
5004
|
-
return compiledRules.map(([{ crossHost, regExp }, match]) => {
|
|
5005
|
-
const test = crossHost ? `https://${host}${pathname}` : pathname;
|
|
5006
|
-
const result = regExp.exec(test);
|
|
5007
|
-
if (result) {
|
|
5008
|
-
return replacerFn(match, result.groups || {});
|
|
5009
|
-
}
|
|
5010
|
-
}).filter((value) => value !== void 0);
|
|
5011
|
-
};
|
|
5012
|
-
}
|
|
5013
5018
|
function generateHeadersMatcher(headersFile) {
|
|
5014
5019
|
if (existsSync(headersFile)) {
|
|
5015
5020
|
const contents = readFileSync4(headersFile).toString();
|
|
@@ -5403,7 +5408,7 @@ async function main() {
|
|
|
5403
5408
|
}
|
|
5404
5409
|
config.bindings = {
|
|
5405
5410
|
...config.bindings,
|
|
5406
|
-
...Object.fromEntries(
|
|
5411
|
+
...config.externalDurableObjects && Object.fromEntries(
|
|
5407
5412
|
Object.entries(
|
|
5408
5413
|
config.externalDurableObjects
|
|
5409
5414
|
).map(([binding, { name, host, port }]) => {
|
|
@@ -5427,7 +5432,10 @@ async function main() {
|
|
|
5427
5432
|
requestFromArgs
|
|
5428
5433
|
);
|
|
5429
5434
|
request.headers.set("x-miniflare-durable-object-name", name);
|
|
5430
|
-
request.headers.set(
|
|
5435
|
+
request.headers.set(
|
|
5436
|
+
"x-miniflare-durable-object-id",
|
|
5437
|
+
id.toString()
|
|
5438
|
+
);
|
|
5431
5439
|
return fetch(request);
|
|
5432
5440
|
};
|
|
5433
5441
|
return stub;
|
package/package.json
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { unstable_dev } from "../api";
|
|
2
|
+
|
|
3
|
+
jest.unmock("undici");
|
|
4
|
+
|
|
5
|
+
describe("unstable_dev", () => {
|
|
6
|
+
it("should return Hello World", async () => {
|
|
7
|
+
const worker = await unstable_dev(
|
|
8
|
+
"src/__tests__/helpers/hello-world-worker.js",
|
|
9
|
+
{},
|
|
10
|
+
{ disableExperimentalWarning: true }
|
|
11
|
+
);
|
|
12
|
+
const resp = await worker.fetch();
|
|
13
|
+
if (resp) {
|
|
14
|
+
const text = await resp.text();
|
|
15
|
+
expect(text).toMatchInlineSnapshot(`"Hello World!"`);
|
|
16
|
+
}
|
|
17
|
+
await worker.stop();
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -15,6 +15,19 @@ import {
|
|
|
15
15
|
} from "./helpers/mock-cfetch";
|
|
16
16
|
import { MockWebSocket } from "./helpers/mock-web-socket";
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* The relative path between the bundled code and the Wrangler package.
|
|
20
|
+
* This is used as a reliable way to compute paths relative to the Wrangler package
|
|
21
|
+
* in the source files, rather than relying upon `__dirname` which can change depending
|
|
22
|
+
* on whether the source files have been bundled and the location of the outdir.
|
|
23
|
+
*
|
|
24
|
+
* This is exposed in the source via the `getBasePath()` function, which should be used
|
|
25
|
+
* in place of `__dirname` and similar Node.js constants.
|
|
26
|
+
*/
|
|
27
|
+
(
|
|
28
|
+
global as unknown as { __RELATIVE_PACKAGE_PATH__: string }
|
|
29
|
+
).__RELATIVE_PACKAGE_PATH__ = "..";
|
|
30
|
+
|
|
18
31
|
// Mock out getPort since we don't actually care about what ports are open in unit tests.
|
|
19
32
|
jest.mock("get-port", () => {
|
|
20
33
|
return {
|