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
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
import { getBasePath } from "../paths";
|
|
3
|
+
|
|
4
|
+
describe("paths", () => {
|
|
5
|
+
describe("getBasePath()", () => {
|
|
6
|
+
it("should return the path to the wrangler package", () => {
|
|
7
|
+
expect(getBasePath()).toMatch(/packages[/\\]wrangler$/);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it("should use the __RELATIVE_PACKAGE_PATH__ as defined on the global context to compute the base path", () => {
|
|
11
|
+
(
|
|
12
|
+
global as unknown as { __RELATIVE_PACKAGE_PATH__: string }
|
|
13
|
+
).__RELATIVE_PACKAGE_PATH__ = "/foo/bar";
|
|
14
|
+
expect(getBasePath()).toEqual(path.resolve("/foo/bar"));
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
});
|
package/src/api/dev.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { startDev } from "../dev";
|
|
1
|
+
import { startApiDev, startDev } from "../dev";
|
|
2
2
|
import { logger } from "../logger";
|
|
3
3
|
|
|
4
4
|
import type { EnablePagesAssetsServiceBindingOptions } from "../miniflare-cli";
|
|
5
5
|
import type { RequestInit, Response } from "undici";
|
|
6
6
|
|
|
7
7
|
interface DevOptions {
|
|
8
|
+
config?: string;
|
|
8
9
|
env?: string;
|
|
9
10
|
ip?: string;
|
|
10
11
|
port?: number;
|
|
@@ -20,7 +21,7 @@ interface DevOptions {
|
|
|
20
21
|
experimentalEnableLocalPersistence?: boolean;
|
|
21
22
|
liveReload?: boolean;
|
|
22
23
|
watch?: boolean;
|
|
23
|
-
vars
|
|
24
|
+
vars?: {
|
|
24
25
|
[key: string]: unknown;
|
|
25
26
|
};
|
|
26
27
|
kv?: {
|
|
@@ -48,46 +49,91 @@ interface DevOptions {
|
|
|
48
49
|
_?: (string | number)[]; //yargs wants this
|
|
49
50
|
$0?: string; //yargs wants this
|
|
50
51
|
}
|
|
52
|
+
|
|
53
|
+
interface DevApiOptions {
|
|
54
|
+
testMode?: boolean;
|
|
55
|
+
disableExperimentalWarning?: boolean;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
interface UnstableDev {
|
|
59
|
+
stop: () => Promise<void>;
|
|
60
|
+
fetch: (init?: RequestInit) => Promise<Response | undefined>;
|
|
61
|
+
waitUntilExit: () => Promise<void>;
|
|
62
|
+
}
|
|
51
63
|
/**
|
|
52
64
|
* unstable_dev starts a wrangler dev server, and returns a promise that resolves with utility functions to interact with it.
|
|
53
65
|
* @param {string} script
|
|
54
66
|
* @param {DevOptions} options
|
|
67
|
+
* @param {DevApiOptions} apiOptions
|
|
68
|
+
* @returns {Promise<UnstableDev>}
|
|
55
69
|
*/
|
|
56
70
|
export async function unstable_dev(
|
|
57
71
|
script: string,
|
|
58
|
-
options
|
|
59
|
-
|
|
72
|
+
options?: DevOptions,
|
|
73
|
+
apiOptions?: DevApiOptions
|
|
60
74
|
) {
|
|
75
|
+
const { testMode = true, disableExperimentalWarning = false } =
|
|
76
|
+
apiOptions || {};
|
|
61
77
|
if (!disableExperimentalWarning) {
|
|
62
78
|
logger.warn(
|
|
63
79
|
`unstable_dev() is experimental\nunstable_dev()'s behaviour will likely change in future releases`
|
|
64
80
|
);
|
|
65
81
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
//due to Pages adoption of unstable_dev, we can't *just* disable rebuilds and watching. instead, we'll have two versions of startDev, which will converge.
|
|
83
|
+
if (testMode) {
|
|
84
|
+
//in testMode, we can run multiple wranglers in parallel, but rebuilds might not work out of the box
|
|
85
|
+
return new Promise<UnstableDev>((resolve) => {
|
|
86
|
+
//lmao
|
|
87
|
+
return new Promise<Awaited<ReturnType<typeof startApiDev>>>((ready) => {
|
|
88
|
+
// once the devServer is ready for requests, we resolve the inner promise
|
|
89
|
+
// (where we've named the resolve function "ready")
|
|
90
|
+
const devServer = startApiDev({
|
|
91
|
+
script: script,
|
|
92
|
+
inspect: false,
|
|
93
|
+
logLevel: "none",
|
|
94
|
+
showInteractiveDevSession: false,
|
|
95
|
+
_: [],
|
|
96
|
+
$0: "",
|
|
97
|
+
...options,
|
|
98
|
+
local: true,
|
|
99
|
+
onReady: () => ready(devServer),
|
|
100
|
+
});
|
|
101
|
+
}).then((devServer) => {
|
|
102
|
+
// now that the inner promise has resolved, we can resolve the outer promise
|
|
103
|
+
// with an object that lets you fetch and stop the dev server
|
|
104
|
+
resolve({
|
|
105
|
+
stop: devServer.stop,
|
|
106
|
+
fetch: devServer.fetch,
|
|
107
|
+
//no-op, does nothing in tests
|
|
108
|
+
waitUntilExit: async () => {
|
|
109
|
+
return;
|
|
110
|
+
},
|
|
111
|
+
});
|
|
84
112
|
});
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
113
|
+
});
|
|
114
|
+
} else {
|
|
115
|
+
//outside of test mode, rebuilds work fine, but only one instance of wrangler will work at a time
|
|
116
|
+
return new Promise<UnstableDev>((resolve) => {
|
|
117
|
+
//lmao
|
|
118
|
+
return new Promise<Awaited<ReturnType<typeof startDev>>>((ready) => {
|
|
119
|
+
const devServer = startDev({
|
|
120
|
+
script: script,
|
|
121
|
+
inspect: false,
|
|
122
|
+
logLevel: "none",
|
|
123
|
+
showInteractiveDevSession: false,
|
|
124
|
+
_: [],
|
|
125
|
+
$0: "",
|
|
126
|
+
...options,
|
|
127
|
+
local: true,
|
|
128
|
+
onReady: () => ready(devServer),
|
|
129
|
+
});
|
|
130
|
+
}).then((devServer) => {
|
|
131
|
+
resolve({
|
|
132
|
+
stop: devServer.stop,
|
|
133
|
+
fetch: devServer.fetch,
|
|
134
|
+
waitUntilExit: devServer.devReactElement.waitUntilExit,
|
|
135
|
+
});
|
|
90
136
|
});
|
|
91
137
|
});
|
|
92
|
-
}
|
|
138
|
+
}
|
|
93
139
|
}
|
package/src/bundle.ts
CHANGED
|
@@ -7,6 +7,7 @@ import NodeModulesPolyfills from "@esbuild-plugins/node-modules-polyfill";
|
|
|
7
7
|
import * as esbuild from "esbuild";
|
|
8
8
|
import tmp from "tmp-promise";
|
|
9
9
|
import createModuleCollector from "./module-collection";
|
|
10
|
+
import { getBasePath } from "./paths";
|
|
10
11
|
import type { Config } from "./config";
|
|
11
12
|
import type { WorkerRegistry } from "./dev-registry";
|
|
12
13
|
import type { Entry } from "./entry";
|
|
@@ -71,7 +72,7 @@ export async function bundleWorker(
|
|
|
71
72
|
nodeCompat: boolean | undefined;
|
|
72
73
|
define: Config["define"];
|
|
73
74
|
checkFetch: boolean;
|
|
74
|
-
services: Config["services"];
|
|
75
|
+
services: Config["services"] | undefined;
|
|
75
76
|
workerDefinitions: WorkerRegistry | undefined;
|
|
76
77
|
firstPartyWorkerDevFacade: boolean | undefined;
|
|
77
78
|
}
|
|
@@ -129,7 +130,7 @@ export async function bundleWorker(
|
|
|
129
130
|
});
|
|
130
131
|
fs.writeFileSync(
|
|
131
132
|
checkedFetchFileToInject,
|
|
132
|
-
fs.readFileSync(path.resolve(
|
|
133
|
+
fs.readFileSync(path.resolve(getBasePath(), "templates/checked-fetch.js"))
|
|
133
134
|
);
|
|
134
135
|
}
|
|
135
136
|
|
|
@@ -302,7 +303,9 @@ async function applyFormatDevErrorsFacade(
|
|
|
302
303
|
): Promise<Entry> {
|
|
303
304
|
const targetPath = path.join(tmpDirPath, "format-dev-errors.entry.js");
|
|
304
305
|
await esbuild.build({
|
|
305
|
-
entryPoints: [
|
|
306
|
+
entryPoints: [
|
|
307
|
+
path.resolve(getBasePath(), "templates/format-dev-errors.ts"),
|
|
308
|
+
],
|
|
306
309
|
bundle: true,
|
|
307
310
|
sourcemap: true,
|
|
308
311
|
format: "esm",
|
|
@@ -334,7 +337,7 @@ async function applyStaticAssetFacade(
|
|
|
334
337
|
|
|
335
338
|
await esbuild.build({
|
|
336
339
|
entryPoints: [
|
|
337
|
-
path.resolve(
|
|
340
|
+
path.resolve(getBasePath(), "templates/serve-static-assets.ts"),
|
|
338
341
|
],
|
|
339
342
|
bundle: true,
|
|
340
343
|
format: "esm",
|
|
@@ -342,7 +345,7 @@ async function applyStaticAssetFacade(
|
|
|
342
345
|
plugins: [
|
|
343
346
|
esbuildAliasExternalPlugin({
|
|
344
347
|
__ENTRY_POINT__: entry.file,
|
|
345
|
-
__KV_ASSET_HANDLER__: path.join(
|
|
348
|
+
__KV_ASSET_HANDLER__: path.join(getBasePath(), "kv-asset-handler.js"),
|
|
346
349
|
__STATIC_CONTENT_MANIFEST: "__STATIC_CONTENT_MANIFEST",
|
|
347
350
|
}),
|
|
348
351
|
],
|
|
@@ -391,10 +394,10 @@ async function applyMultiWorkerDevFacade(
|
|
|
391
394
|
await esbuild.build({
|
|
392
395
|
entryPoints: [
|
|
393
396
|
path.join(
|
|
394
|
-
|
|
397
|
+
getBasePath(),
|
|
395
398
|
entry.format === "modules"
|
|
396
|
-
? "
|
|
397
|
-
: "
|
|
399
|
+
? "templates/service-bindings-module-facade.js"
|
|
400
|
+
: "templates/service-bindings-sw-facade.js"
|
|
398
401
|
),
|
|
399
402
|
],
|
|
400
403
|
bundle: true,
|
|
@@ -440,8 +443,8 @@ async function applyFirstPartyWorkerDevFacade(
|
|
|
440
443
|
await esbuild.build({
|
|
441
444
|
entryPoints: [
|
|
442
445
|
path.resolve(
|
|
443
|
-
|
|
444
|
-
"
|
|
446
|
+
getBasePath(),
|
|
447
|
+
"templates/first-party-worker-module-facade.ts"
|
|
445
448
|
),
|
|
446
449
|
],
|
|
447
450
|
bundle: true,
|
package/src/cli.ts
CHANGED