wrangler 0.0.0-e33294b0 → 0.0.0-e33bea9b
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/bin/wrangler.js +1 -1
- package/miniflare-dist/index.mjs +21 -4
- package/package.json +8 -8
- package/src/__tests__/configuration.test.ts +235 -6
- package/src/__tests__/d1/execute.test.ts +1 -1
- package/src/__tests__/dev.test.tsx +16 -1
- package/src/__tests__/guess-worker-format.test.ts +35 -0
- package/src/__tests__/init.test.ts +9 -8
- package/src/__tests__/middleware.test.ts +2 -1
- package/src/__tests__/pages/functions-build.test.ts +91 -41
- package/src/__tests__/pages/publish.test.ts +136 -61
- package/src/__tests__/publish.test.ts +169 -14
- package/src/__tests__/test-old-node-version.js +3 -3
- package/src/__tests__/tsconfig.tsbuildinfo +1 -1
- package/src/__tests__/type-generation.test.ts +1 -0
- package/src/__tests__/user.test.ts +1 -1
- package/src/api/dev.ts +3 -4
- package/src/api/pages/publish.tsx +38 -51
- package/src/bundle.ts +27 -9
- package/src/config/environment.ts +9 -4
- package/src/config/index.ts +12 -2
- package/src/config/validation-helpers.ts +1 -1
- package/src/config/validation.ts +58 -4
- package/src/create-worker-preview.ts +19 -8
- package/src/create-worker-upload-form.ts +10 -2
- package/src/dev/dev.tsx +4 -4
- package/src/dev/local.tsx +18 -21
- package/src/dev/start-server.ts +10 -8
- package/src/dev/use-esbuild.ts +9 -5
- package/src/dev/validate-dev-props.ts +9 -0
- package/src/dev.tsx +27 -13
- package/src/entry.ts +1 -2
- package/src/index.ts +1 -1
- package/src/init.ts +1 -0
- package/src/inspect.ts +16 -1
- package/src/miniflare-cli/assets.ts +8 -7
- package/src/miniflare-cli/index.ts +1 -1
- package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -1
- package/src/pages/build.ts +277 -99
- package/src/pages/buildFunctions.ts +20 -10
- package/src/pages/dev.ts +21 -21
- package/src/pages/errors.ts +1 -0
- package/src/pages/functions/buildPlugin.ts +56 -34
- package/src/pages/functions/buildWorker.ts +32 -23
- package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
- package/src/pages/publish.tsx +1 -10
- package/src/pages/upload.tsx +5 -5
- package/src/paths.ts +1 -1
- package/src/publish/index.ts +1 -1
- package/src/publish/publish.ts +19 -8
- package/src/r2/helpers.ts +1 -0
- package/src/secret/index.ts +1 -1
- package/src/type-generation.ts +1 -1
- package/src/user/user.ts +1 -1
- package/src/worker.ts +8 -1
- package/templates/d1-beta-facade.js +5 -2
- package/templates/gitignore +1 -0
- package/templates/middleware/middleware-miniflare3-json-error.ts +17 -5
- package/templates/pages-template-plugin.ts +7 -3
- package/templates/tsconfig.init.json +1 -2
- package/templates/tsconfig.tsbuildinfo +1 -1
- package/wrangler-dist/cli.d.ts +523 -14
- package/wrangler-dist/cli.js +11473 -4544
package/src/dev/local.tsx
CHANGED
|
@@ -47,7 +47,6 @@ import type {
|
|
|
47
47
|
} from "@miniflare/tre";
|
|
48
48
|
import type { MiniflareOptions } from "miniflare";
|
|
49
49
|
import type { ChildProcess } from "node:child_process";
|
|
50
|
-
import type { RequestInit } from "undici";
|
|
51
50
|
|
|
52
51
|
export interface LocalProps {
|
|
53
52
|
name: string | undefined;
|
|
@@ -71,7 +70,6 @@ export interface LocalProps {
|
|
|
71
70
|
localUpstream: string | undefined;
|
|
72
71
|
inspect: boolean;
|
|
73
72
|
onReady: ((ip: string, port: number) => void) | undefined;
|
|
74
|
-
logPrefix?: string;
|
|
75
73
|
enablePagesAssetsServiceBinding?: EnablePagesAssetsServiceBindingOptions;
|
|
76
74
|
testScheduled?: boolean;
|
|
77
75
|
experimentalLocal: boolean | undefined;
|
|
@@ -122,7 +120,6 @@ function useLocalWorker({
|
|
|
122
120
|
localUpstream,
|
|
123
121
|
inspect,
|
|
124
122
|
onReady,
|
|
125
|
-
logPrefix,
|
|
126
123
|
enablePagesAssetsServiceBinding,
|
|
127
124
|
experimentalLocal,
|
|
128
125
|
accountId,
|
|
@@ -217,13 +214,12 @@ function useLocalWorker({
|
|
|
217
214
|
dataBlobBindings,
|
|
218
215
|
crons,
|
|
219
216
|
upstream,
|
|
220
|
-
logPrefix,
|
|
221
217
|
workerDefinitions,
|
|
222
218
|
enablePagesAssetsServiceBinding,
|
|
223
219
|
});
|
|
224
220
|
|
|
225
221
|
if (experimentalLocal) {
|
|
226
|
-
const log = await buildMiniflare3Logger(
|
|
222
|
+
const log = await buildMiniflare3Logger();
|
|
227
223
|
const mf3Options = await transformMf2OptionsToMf3Options({
|
|
228
224
|
miniflare2Options: options,
|
|
229
225
|
format,
|
|
@@ -232,6 +228,7 @@ function useLocalWorker({
|
|
|
232
228
|
enablePagesAssetsServiceBinding,
|
|
233
229
|
kvNamespaces: bindings?.kv_namespaces,
|
|
234
230
|
r2Buckets: bindings?.r2_buckets,
|
|
231
|
+
d1Databases: bindings?.d1_databases,
|
|
235
232
|
authenticatedAccountId: accountId,
|
|
236
233
|
kvRemote: experimentalLocalRemoteKv,
|
|
237
234
|
inspectorPort: runtimeInspectorPort,
|
|
@@ -438,7 +435,6 @@ function useLocalWorker({
|
|
|
438
435
|
localProtocol,
|
|
439
436
|
localUpstream,
|
|
440
437
|
inspect,
|
|
441
|
-
logPrefix,
|
|
442
438
|
onReady,
|
|
443
439
|
enablePagesAssetsServiceBinding,
|
|
444
440
|
experimentalLocal,
|
|
@@ -577,7 +573,6 @@ interface SetupMiniflareOptionsProps {
|
|
|
577
573
|
dataBlobBindings: Record<string, string>;
|
|
578
574
|
crons: Config["triggers"]["crons"];
|
|
579
575
|
upstream: string | undefined;
|
|
580
|
-
logPrefix: string | undefined;
|
|
581
576
|
workerDefinitions: WorkerRegistry | undefined;
|
|
582
577
|
enablePagesAssetsServiceBinding?: EnablePagesAssetsServiceBindingOptions;
|
|
583
578
|
}
|
|
@@ -609,7 +604,6 @@ export function setupMiniflareOptions({
|
|
|
609
604
|
dataBlobBindings,
|
|
610
605
|
crons,
|
|
611
606
|
upstream,
|
|
612
|
-
logPrefix,
|
|
613
607
|
workerDefinitions,
|
|
614
608
|
enablePagesAssetsServiceBinding,
|
|
615
609
|
}: SetupMiniflareOptionsProps): {
|
|
@@ -722,7 +716,6 @@ export function setupMiniflareOptions({
|
|
|
722
716
|
crons,
|
|
723
717
|
upstream,
|
|
724
718
|
logLevel: logger.loggerLevel,
|
|
725
|
-
logOptions: logPrefix ? { prefix: logPrefix } : undefined,
|
|
726
719
|
enablePagesAssetsServiceBinding,
|
|
727
720
|
};
|
|
728
721
|
// The path to the Miniflare CLI assumes that this file is being run from
|
|
@@ -777,6 +770,7 @@ export interface SetupMiniflare3Options {
|
|
|
777
770
|
// we need actual namespace IDs to connect to.
|
|
778
771
|
kvNamespaces: CfKvNamespace[] | undefined;
|
|
779
772
|
r2Buckets: CfR2Bucket[] | undefined;
|
|
773
|
+
d1Databases: CfD1Database[] | undefined;
|
|
780
774
|
|
|
781
775
|
// Account ID to use for authenticated Cloudflare fetch. If true, prompt
|
|
782
776
|
// user for ID if multiple available.
|
|
@@ -788,18 +782,14 @@ export interface SetupMiniflare3Options {
|
|
|
788
782
|
inspectorPort: number;
|
|
789
783
|
}
|
|
790
784
|
|
|
791
|
-
export async function buildMiniflare3Logger(
|
|
792
|
-
logPrefix?: string
|
|
793
|
-
): Promise<Miniflare3LogType> {
|
|
785
|
+
export async function buildMiniflare3Logger(): Promise<Miniflare3LogType> {
|
|
794
786
|
const { Log, NoOpLog, LogLevel } = await getMiniflare3();
|
|
795
787
|
|
|
796
788
|
let level = logger.loggerLevel.toUpperCase() as Uppercase<LoggerLevel>;
|
|
797
789
|
if (level === "LOG") level = "INFO";
|
|
798
790
|
const logLevel = LogLevel[level];
|
|
799
791
|
|
|
800
|
-
return logLevel === LogLevel.NONE
|
|
801
|
-
? new NoOpLog()
|
|
802
|
-
: new Log(logLevel, { prefix: logPrefix });
|
|
792
|
+
return logLevel === LogLevel.NONE ? new NoOpLog() : new Log(logLevel);
|
|
803
793
|
}
|
|
804
794
|
|
|
805
795
|
export async function transformMf2OptionsToMf3Options({
|
|
@@ -810,6 +800,7 @@ export async function transformMf2OptionsToMf3Options({
|
|
|
810
800
|
enablePagesAssetsServiceBinding,
|
|
811
801
|
kvNamespaces,
|
|
812
802
|
r2Buckets,
|
|
803
|
+
d1Databases,
|
|
813
804
|
authenticatedAccountId,
|
|
814
805
|
kvRemote,
|
|
815
806
|
inspectorPort,
|
|
@@ -817,14 +808,14 @@ export async function transformMf2OptionsToMf3Options({
|
|
|
817
808
|
// Build authenticated Cloudflare API fetch function if required
|
|
818
809
|
let cloudflareFetch: CloudflareFetch | undefined;
|
|
819
810
|
if (kvRemote && authenticatedAccountId !== undefined) {
|
|
811
|
+
const { Response: Miniflare3Response } = await getMiniflare3();
|
|
820
812
|
const preferredAccountId =
|
|
821
813
|
authenticatedAccountId === true ? undefined : authenticatedAccountId;
|
|
822
814
|
const accountId = await requireAuth({ account_id: preferredAccountId });
|
|
823
|
-
cloudflareFetch = (resource, searchParams, init) => {
|
|
815
|
+
cloudflareFetch = async (resource, searchParams, init) => {
|
|
824
816
|
resource = `/accounts/${accountId}/${resource}`;
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
return performApiFetch(resource, init as RequestInit, searchParams);
|
|
817
|
+
const response = await performApiFetch(resource, init, searchParams);
|
|
818
|
+
return new Miniflare3Response(response.body, response);
|
|
828
819
|
};
|
|
829
820
|
}
|
|
830
821
|
|
|
@@ -837,6 +828,12 @@ export async function transformMf2OptionsToMf3Options({
|
|
|
837
828
|
r2Buckets: Object.fromEntries(
|
|
838
829
|
r2Buckets?.map(({ binding, bucket_name }) => [binding, bucket_name]) ?? []
|
|
839
830
|
),
|
|
831
|
+
d1Databases: Object.fromEntries(
|
|
832
|
+
d1Databases?.map(({ binding, database_id, preview_database_id }) => [
|
|
833
|
+
binding,
|
|
834
|
+
preview_database_id ?? database_id,
|
|
835
|
+
]) ?? []
|
|
836
|
+
),
|
|
840
837
|
inspectorPort,
|
|
841
838
|
verbose: true,
|
|
842
839
|
cloudflareFetch,
|
|
@@ -853,7 +850,7 @@ export async function transformMf2OptionsToMf3Options({
|
|
|
853
850
|
// relies on the fact that `require` is untyped.
|
|
854
851
|
//
|
|
855
852
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
856
|
-
const generateASSETSBinding = require("../miniflare-cli/assets");
|
|
853
|
+
const generateASSETSBinding = require("../miniflare-cli/assets").default;
|
|
857
854
|
options.serviceBindings = {
|
|
858
855
|
...options.serviceBindings,
|
|
859
856
|
ASSETS: (await generateASSETSBinding({
|
|
@@ -919,5 +916,5 @@ export async function getMiniflare3(): Promise<
|
|
|
919
916
|
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
|
|
920
917
|
typeof import("@miniflare/tre")
|
|
921
918
|
> {
|
|
922
|
-
return (miniflare3Module ??= await npxImport("@miniflare/tre@3.0.0-next.
|
|
919
|
+
return (miniflare3Module ??= await npxImport("@miniflare/tre@3.0.0-next.12"));
|
|
923
920
|
}
|
package/src/dev/start-server.ts
CHANGED
|
@@ -98,7 +98,8 @@ export async function startDevServer(
|
|
|
98
98
|
),
|
|
99
99
|
tsconfig: props.tsconfig,
|
|
100
100
|
minify: props.minify,
|
|
101
|
-
|
|
101
|
+
legacyNodeCompat: props.legacyNodeCompat,
|
|
102
|
+
nodejsCompat: props.nodejsCompat,
|
|
102
103
|
define: props.define,
|
|
103
104
|
noBundle: props.noBundle,
|
|
104
105
|
assets: props.assetsConfig,
|
|
@@ -131,7 +132,6 @@ export async function startDevServer(
|
|
|
131
132
|
queueConsumers: props.queueConsumers,
|
|
132
133
|
localProtocol: props.localProtocol,
|
|
133
134
|
localUpstream: props.localUpstream,
|
|
134
|
-
logPrefix: props.logPrefix,
|
|
135
135
|
inspect: props.inspect,
|
|
136
136
|
onReady: props.onReady,
|
|
137
137
|
enablePagesAssetsServiceBinding: props.enablePagesAssetsServiceBinding,
|
|
@@ -210,7 +210,8 @@ async function runEsbuild({
|
|
|
210
210
|
serveAssetsFromWorker,
|
|
211
211
|
tsconfig,
|
|
212
212
|
minify,
|
|
213
|
-
|
|
213
|
+
legacyNodeCompat,
|
|
214
|
+
nodejsCompat,
|
|
214
215
|
define,
|
|
215
216
|
noBundle,
|
|
216
217
|
workerDefinitions,
|
|
@@ -233,7 +234,8 @@ async function runEsbuild({
|
|
|
233
234
|
serveAssetsFromWorker: boolean;
|
|
234
235
|
tsconfig: string | undefined;
|
|
235
236
|
minify: boolean | undefined;
|
|
236
|
-
|
|
237
|
+
legacyNodeCompat: boolean | undefined;
|
|
238
|
+
nodejsCompat: boolean | undefined;
|
|
237
239
|
noBundle: boolean;
|
|
238
240
|
workerDefinitions: WorkerRegistry;
|
|
239
241
|
firstPartyWorkerDevFacade: boolean | undefined;
|
|
@@ -266,7 +268,8 @@ async function runEsbuild({
|
|
|
266
268
|
rules,
|
|
267
269
|
tsconfig,
|
|
268
270
|
minify,
|
|
269
|
-
|
|
271
|
+
legacyNodeCompat,
|
|
272
|
+
nodejsCompat,
|
|
270
273
|
define,
|
|
271
274
|
checkFetch: true,
|
|
272
275
|
assets: assets && {
|
|
@@ -318,7 +321,6 @@ export async function startLocalServer({
|
|
|
318
321
|
localUpstream,
|
|
319
322
|
inspect,
|
|
320
323
|
onReady,
|
|
321
|
-
logPrefix,
|
|
322
324
|
enablePagesAssetsServiceBinding,
|
|
323
325
|
experimentalLocal,
|
|
324
326
|
accountId,
|
|
@@ -398,13 +400,12 @@ export async function startLocalServer({
|
|
|
398
400
|
dataBlobBindings,
|
|
399
401
|
crons,
|
|
400
402
|
upstream,
|
|
401
|
-
logPrefix,
|
|
402
403
|
workerDefinitions,
|
|
403
404
|
enablePagesAssetsServiceBinding,
|
|
404
405
|
});
|
|
405
406
|
|
|
406
407
|
if (experimentalLocal) {
|
|
407
|
-
const log = await buildMiniflare3Logger(
|
|
408
|
+
const log = await buildMiniflare3Logger();
|
|
408
409
|
const mf3Options = await transformMf2OptionsToMf3Options({
|
|
409
410
|
miniflare2Options: options,
|
|
410
411
|
format,
|
|
@@ -412,6 +413,7 @@ export async function startLocalServer({
|
|
|
412
413
|
log,
|
|
413
414
|
kvNamespaces: bindings?.kv_namespaces,
|
|
414
415
|
r2Buckets: bindings?.r2_buckets,
|
|
416
|
+
d1Databases: bindings?.d1_databases,
|
|
415
417
|
authenticatedAccountId: accountId,
|
|
416
418
|
kvRemote: experimentalLocalRemoteKv,
|
|
417
419
|
inspectorPort,
|
package/src/dev/use-esbuild.ts
CHANGED
|
@@ -30,7 +30,8 @@ export function useEsbuild({
|
|
|
30
30
|
serveAssetsFromWorker,
|
|
31
31
|
tsconfig,
|
|
32
32
|
minify,
|
|
33
|
-
|
|
33
|
+
legacyNodeCompat,
|
|
34
|
+
nodejsCompat,
|
|
34
35
|
betaD1Shims,
|
|
35
36
|
define,
|
|
36
37
|
noBundle,
|
|
@@ -54,7 +55,8 @@ export function useEsbuild({
|
|
|
54
55
|
serveAssetsFromWorker: boolean;
|
|
55
56
|
tsconfig: string | undefined;
|
|
56
57
|
minify: boolean | undefined;
|
|
57
|
-
|
|
58
|
+
legacyNodeCompat: boolean | undefined;
|
|
59
|
+
nodejsCompat: boolean | undefined;
|
|
58
60
|
betaD1Shims?: string[];
|
|
59
61
|
noBundle: boolean;
|
|
60
62
|
workerDefinitions: WorkerRegistry;
|
|
@@ -85,7 +87,7 @@ export function useEsbuild({
|
|
|
85
87
|
const watchMode: WatchMode = {
|
|
86
88
|
async onRebuild(error) {
|
|
87
89
|
if (error !== null) {
|
|
88
|
-
if (!
|
|
90
|
+
if (!legacyNodeCompat) rewriteNodeCompatBuildFailure(error);
|
|
89
91
|
logBuildFailure(error);
|
|
90
92
|
logger.error("Watch build failed:", error.message);
|
|
91
93
|
} else {
|
|
@@ -121,7 +123,8 @@ export function useEsbuild({
|
|
|
121
123
|
watch: watchMode,
|
|
122
124
|
tsconfig,
|
|
123
125
|
minify,
|
|
124
|
-
|
|
126
|
+
legacyNodeCompat,
|
|
127
|
+
nodejsCompat,
|
|
125
128
|
betaD1Shims,
|
|
126
129
|
doBindings: durableObjects.bindings,
|
|
127
130
|
define,
|
|
@@ -188,7 +191,8 @@ export function useEsbuild({
|
|
|
188
191
|
exit,
|
|
189
192
|
noBundle,
|
|
190
193
|
minify,
|
|
191
|
-
|
|
194
|
+
legacyNodeCompat,
|
|
195
|
+
nodejsCompat,
|
|
192
196
|
define,
|
|
193
197
|
assets,
|
|
194
198
|
services,
|
|
@@ -28,4 +28,13 @@ export function validateDevProps(props: DevProps) {
|
|
|
28
28
|
"You cannot configure [data_blobs] with an ES module worker. Instead, import the file directly in your code, and optionally configure `[rules]` in your wrangler.toml"
|
|
29
29
|
);
|
|
30
30
|
}
|
|
31
|
+
|
|
32
|
+
if (
|
|
33
|
+
props.compatibilityFlags?.includes("nodejs_compat") &&
|
|
34
|
+
props.legacyNodeCompat
|
|
35
|
+
) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
"You cannot use the `nodejs_compat` compatibility flag in conjunction with the legacy `--node-compat` flag. If you want to use the new runtime Node.js compatibility features, please remove the `--node-compat` argument from your CLI command or your config file."
|
|
38
|
+
);
|
|
39
|
+
}
|
|
31
40
|
}
|
package/src/dev.tsx
CHANGED
|
@@ -229,7 +229,7 @@ export function devOptions(yargs: CommonYargsArgv) {
|
|
|
229
229
|
type: "boolean",
|
|
230
230
|
})
|
|
231
231
|
.option("node-compat", {
|
|
232
|
-
describe: "Enable
|
|
232
|
+
describe: "Enable Node.js compatibility",
|
|
233
233
|
type: "boolean",
|
|
234
234
|
})
|
|
235
235
|
.option("experimental-enable-local-persistence", {
|
|
@@ -344,7 +344,6 @@ type StartDevOptions = DevArguments &
|
|
|
344
344
|
disableDevRegistry?: boolean;
|
|
345
345
|
enablePagesAssetsServiceBinding?: EnablePagesAssetsServiceBindingOptions;
|
|
346
346
|
onReady?: (ip: string, port: number) => void;
|
|
347
|
-
logPrefix?: string;
|
|
348
347
|
showInteractiveDevSession?: boolean;
|
|
349
348
|
};
|
|
350
349
|
|
|
@@ -388,7 +387,8 @@ export async function startDev(args: StartDevOptions) {
|
|
|
388
387
|
|
|
389
388
|
const {
|
|
390
389
|
entry,
|
|
391
|
-
|
|
390
|
+
legacyNodeCompat,
|
|
391
|
+
nodejsCompat,
|
|
392
392
|
upstreamProtocol,
|
|
393
393
|
zoneId,
|
|
394
394
|
host,
|
|
@@ -427,7 +427,8 @@ export async function startDev(args: StartDevOptions) {
|
|
|
427
427
|
rules={getRules(configParam)}
|
|
428
428
|
legacyEnv={isLegacyEnv(configParam)}
|
|
429
429
|
minify={args.minify ?? configParam.minify}
|
|
430
|
-
|
|
430
|
+
legacyNodeCompat={legacyNodeCompat}
|
|
431
|
+
nodejsCompat={nodejsCompat}
|
|
431
432
|
build={configParam.build || {}}
|
|
432
433
|
define={{ ...configParam.define, ...cliDefines }}
|
|
433
434
|
initialMode={
|
|
@@ -465,7 +466,6 @@ export async function startDev(args: StartDevOptions) {
|
|
|
465
466
|
bindings={bindings}
|
|
466
467
|
crons={configParam.triggers.crons}
|
|
467
468
|
queueConsumers={configParam.queues.consumers}
|
|
468
|
-
logPrefix={args.logPrefix}
|
|
469
469
|
onReady={args.onReady}
|
|
470
470
|
inspect={args.inspect ?? true}
|
|
471
471
|
showInteractiveDevSession={args.showInteractiveDevSession}
|
|
@@ -523,7 +523,8 @@ export async function startApiDev(args: StartDevOptions) {
|
|
|
523
523
|
|
|
524
524
|
const {
|
|
525
525
|
entry,
|
|
526
|
-
|
|
526
|
+
legacyNodeCompat,
|
|
527
|
+
nodejsCompat,
|
|
527
528
|
upstreamProtocol,
|
|
528
529
|
zoneId,
|
|
529
530
|
host,
|
|
@@ -562,7 +563,8 @@ export async function startApiDev(args: StartDevOptions) {
|
|
|
562
563
|
rules: getRules(configParam),
|
|
563
564
|
legacyEnv: isLegacyEnv(configParam),
|
|
564
565
|
minify: args.minify ?? configParam.minify,
|
|
565
|
-
|
|
566
|
+
legacyNodeCompat,
|
|
567
|
+
nodejsCompat,
|
|
566
568
|
build: configParam.build || {},
|
|
567
569
|
define: { ...config.define, ...cliDefines },
|
|
568
570
|
initialMode: args.local ? "local" : "remote",
|
|
@@ -596,7 +598,6 @@ export async function startApiDev(args: StartDevOptions) {
|
|
|
596
598
|
bindings: bindings,
|
|
597
599
|
crons: configParam.triggers.crons,
|
|
598
600
|
queueConsumers: configParam.queues.consumers,
|
|
599
|
-
logPrefix: args.logPrefix,
|
|
600
601
|
onReady: args.onReady,
|
|
601
602
|
inspect: args.inspect ?? true,
|
|
602
603
|
showInteractiveDevSession: args.showInteractiveDevSession,
|
|
@@ -742,10 +743,19 @@ async function validateDevServerSettings(
|
|
|
742
743
|
"https://github.com/cloudflare/workers-sdk/issues/583."
|
|
743
744
|
);
|
|
744
745
|
}
|
|
745
|
-
const
|
|
746
|
-
if (
|
|
746
|
+
const legacyNodeCompat = args.nodeCompat ?? config.node_compat;
|
|
747
|
+
if (legacyNodeCompat) {
|
|
747
748
|
logger.warn(
|
|
748
|
-
"Enabling
|
|
749
|
+
"Enabling Node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details."
|
|
750
|
+
);
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
const compatibilityFlags =
|
|
754
|
+
args.compatibilityFlags ?? config.compatibility_flags;
|
|
755
|
+
const nodejsCompat = compatibilityFlags?.includes("nodejs_compat");
|
|
756
|
+
if (legacyNodeCompat && nodejsCompat) {
|
|
757
|
+
throw new Error(
|
|
758
|
+
"The `nodejs_compat` compatibility flag cannot be used in conjunction with the legacy `--node-compat` flag. If you want to use the Workers runtime Node.js compatibility features, please remove the `--node-compat` argument from your CLI command or `node_compat = true` from your config file."
|
|
749
759
|
);
|
|
750
760
|
}
|
|
751
761
|
|
|
@@ -768,7 +778,8 @@ async function validateDevServerSettings(
|
|
|
768
778
|
return {
|
|
769
779
|
entry,
|
|
770
780
|
upstreamProtocol,
|
|
771
|
-
|
|
781
|
+
legacyNodeCompat,
|
|
782
|
+
nodejsCompat,
|
|
772
783
|
getLocalPort,
|
|
773
784
|
getInspectorPort,
|
|
774
785
|
zoneId,
|
|
@@ -882,7 +893,10 @@ function getBindings(
|
|
|
882
893
|
mtls_certificates: configParam.mtls_certificates,
|
|
883
894
|
services: configParam.services,
|
|
884
895
|
analytics_engine_datasets: configParam.analytics_engine_datasets,
|
|
885
|
-
unsafe:
|
|
896
|
+
unsafe: {
|
|
897
|
+
bindings: configParam.unsafe.bindings,
|
|
898
|
+
metadata: configParam.unsafe.metadata,
|
|
899
|
+
},
|
|
886
900
|
logfwdr: configParam.logfwdr,
|
|
887
901
|
d1_databases: identifyD1BindingsAsBeta([
|
|
888
902
|
...(configParam.d1_databases ?? []).map((d1Db) => {
|
package/src/entry.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -567,7 +567,7 @@ export function createCLIParser(argv: string[]) {
|
|
|
567
567
|
analytics_engine_datasets: config.analytics_engine_datasets,
|
|
568
568
|
dispatch_namespaces: config.dispatch_namespaces,
|
|
569
569
|
logfwdr: config.logfwdr,
|
|
570
|
-
unsafe:
|
|
570
|
+
unsafe: config.unsafe,
|
|
571
571
|
rules: config.rules,
|
|
572
572
|
queues: config.queues,
|
|
573
573
|
};
|
package/src/init.ts
CHANGED
package/src/inspect.ts
CHANGED
|
@@ -151,6 +151,18 @@ export default function useInspector(props: InspectorProps) {
|
|
|
151
151
|
);
|
|
152
152
|
ws.close(1013, "Too many clients; only one can be connected at a time");
|
|
153
153
|
} else {
|
|
154
|
+
// Since Wrangler proxies the inspector, reloading Chrome DevTools won't trigger debugger initialisation events (because it's connecting to an extant session).
|
|
155
|
+
// This sends a `Debugger.disable` message to the remote when a new WebSocket connection is initialised,
|
|
156
|
+
// with the assumption that the new connection will shortly send a `Debugger.enable` event and trigger re-initialisation.
|
|
157
|
+
// The key initialisation messages that are needed are the `Debugger.scriptParsed events`.
|
|
158
|
+
remoteWebSocket?.send(
|
|
159
|
+
JSON.stringify({
|
|
160
|
+
// This number is arbitrary, and is chosen to be high so as not to conflict with messages that DevTools might actually send.
|
|
161
|
+
// For completeness, these options don't work: 0, -1, or Number.MAX_SAFE_INTEGER
|
|
162
|
+
id: 100_000_000,
|
|
163
|
+
method: "Debugger.disable",
|
|
164
|
+
})
|
|
165
|
+
);
|
|
154
166
|
// As promised, save the created websocket in a state hook
|
|
155
167
|
setLocalWebSocket(ws);
|
|
156
168
|
|
|
@@ -733,7 +745,7 @@ function logConsoleMessage(evt: Protocol.Runtime.ConsoleAPICalledEvent): void {
|
|
|
733
745
|
* Opens the chrome debugger
|
|
734
746
|
*/
|
|
735
747
|
export const openInspector = async (inspectorPort: number) => {
|
|
736
|
-
const url = `https://
|
|
748
|
+
const url = `https://devtools.devprod.cloudflare.dev/js_app?theme=systemPreferred&ws=localhost:${inspectorPort}/ws`;
|
|
737
749
|
const errorMessage =
|
|
738
750
|
"Failed to open inspector.\nInspector depends on having a Chromium-based browser installed, maybe you need to install one?";
|
|
739
751
|
|
|
@@ -759,6 +771,9 @@ export const openInspector = async (inspectorPort: number) => {
|
|
|
759
771
|
{
|
|
760
772
|
name: open.apps.edge,
|
|
761
773
|
},
|
|
774
|
+
{
|
|
775
|
+
name: open.apps.firefox,
|
|
776
|
+
},
|
|
762
777
|
],
|
|
763
778
|
});
|
|
764
779
|
childProcess.on("error", () => {
|
|
@@ -12,9 +12,10 @@ import type {
|
|
|
12
12
|
ParsedHeaders,
|
|
13
13
|
} from "@cloudflare/pages-shared/metadata-generator/types";
|
|
14
14
|
import type {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
Request as MiniflareRequest,
|
|
16
|
+
RequestInfo as MiniflareRequestInfo,
|
|
17
|
+
RequestInit as MiniflareRequestInit,
|
|
18
|
+
} from "@miniflare/core";
|
|
18
19
|
|
|
19
20
|
interface Logger {
|
|
20
21
|
log: (message: string) => void;
|
|
@@ -39,7 +40,7 @@ export default async function generateASSETSBinding(options: Options) {
|
|
|
39
40
|
? await import("@miniflare/tre")
|
|
40
41
|
: await import("@miniflare/core");
|
|
41
42
|
|
|
42
|
-
const Request = miniflare.Request;
|
|
43
|
+
const Request = miniflare.Request as typeof MiniflareRequest;
|
|
43
44
|
const Response = miniflare.Response;
|
|
44
45
|
// WebSockets won't work with `--experimental-local` until we expose something like `upgradingFetch` from `@miniflare/tre`.
|
|
45
46
|
const fetch = (
|
|
@@ -108,7 +109,7 @@ async function generateAssetsFetch(
|
|
|
108
109
|
const miniflare = tre
|
|
109
110
|
? await import("@miniflare/tre")
|
|
110
111
|
: await import("@miniflare/core");
|
|
111
|
-
const Request = miniflare.Request;
|
|
112
|
+
const Request = miniflare.Request as typeof MiniflareRequest;
|
|
112
113
|
|
|
113
114
|
const { generateHandler, parseQualityWeightedList } = await import(
|
|
114
115
|
"@cloudflare/pages-shared/asset-server/handler"
|
|
@@ -237,10 +238,10 @@ async function generateAssetsFetch(
|
|
|
237
238
|
});
|
|
238
239
|
};
|
|
239
240
|
|
|
240
|
-
return
|
|
241
|
+
return async (input: MiniflareRequestInfo, init?: MiniflareRequestInit) => {
|
|
241
242
|
const request = new Request(input, init);
|
|
242
243
|
return await generateResponse(request as unknown as Request);
|
|
243
|
-
}
|
|
244
|
+
};
|
|
244
245
|
}
|
|
245
246
|
|
|
246
247
|
const invalidAssetsFetch: typeof fetch = () => {
|
|
@@ -47,7 +47,7 @@ async function main() {
|
|
|
47
47
|
config.log =
|
|
48
48
|
logLevel === MiniflareLogLevel.NONE
|
|
49
49
|
? new MiniflareNoOpLog()
|
|
50
|
-
: new MiniflareLog(logLevel
|
|
50
|
+
: new MiniflareLog(logLevel);
|
|
51
51
|
|
|
52
52
|
if (logLevel === MiniflareLogLevel.DEBUG) {
|
|
53
53
|
console.log("MINIFLARE OPTIONS:\n", JSON.stringify(config, null, 2));
|