wrangler 2.18.0 → 2.20.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.
- package/miniflare-dist/index.mjs +1 -1
- package/package.json +1 -1
- package/src/__tests__/configuration.test.ts +8 -0
- package/src/__tests__/constellation.test.ts +371 -0
- package/src/__tests__/index.test.ts +2 -0
- package/src/__tests__/mtls-certificates.test.ts +1 -0
- package/src/__tests__/pages/functions-build.test.ts +76 -0
- package/src/__tests__/pages-deployment-tail.test.ts +2 -0
- package/src/__tests__/publish.test.ts +3 -3
- package/src/__tests__/tail.test.ts +38 -7
- package/src/__tests__/tsconfig.tsbuildinfo +1 -1
- package/src/__tests__/user.test.ts +1 -1
- package/src/api/dev.ts +5 -0
- package/src/api/pages/create-worker-bundle-contents.ts +1 -0
- package/src/api/pages/publish.tsx +28 -12
- package/src/bundle.ts +28 -7
- package/src/config/environment.ts +7 -0
- package/src/config/validation.ts +27 -0
- package/src/constellation/createProject.tsx +51 -0
- package/src/constellation/deleteProject.ts +51 -0
- package/src/constellation/deleteProjectModel.ts +68 -0
- package/src/constellation/index.ts +75 -0
- package/src/constellation/listCatalog.tsx +35 -0
- package/src/constellation/listModel.tsx +41 -0
- package/src/constellation/listProject.tsx +28 -0
- package/src/constellation/listRuntime.tsx +28 -0
- package/src/constellation/options.ts +17 -0
- package/src/constellation/types.ts +17 -0
- package/src/constellation/uploadModel.tsx +64 -0
- package/src/constellation/utils.ts +90 -0
- package/src/create-worker-upload-form.ts +4 -0
- package/src/dev/dev.tsx +6 -1
- package/src/dev/local.tsx +4 -0
- package/src/dev/remote.tsx +3 -0
- package/src/dev/start-server.ts +50 -39
- package/src/dev/use-esbuild.ts +54 -42
- package/src/dev.tsx +9 -4
- package/src/entry.ts +8 -1
- package/src/environment-variables/factory.ts +2 -1
- package/src/index.ts +10 -0
- package/src/init.ts +5 -0
- package/src/inspect.ts +107 -6
- package/src/logger.ts +5 -1
- package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -1
- package/src/pages/build.ts +30 -17
- package/src/pages/dev.ts +24 -6
- package/src/pages/functions/buildPlugin.ts +1 -0
- package/src/pages/functions/buildWorker.ts +59 -0
- package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
- package/src/publish/publish.ts +6 -1
- package/src/secret/index.ts +1 -0
- package/src/tail/createTail.ts +9 -0
- package/src/tail/printing.ts +10 -0
- package/src/traverse-module-graph.ts +1 -0
- package/src/user/user.ts +1 -0
- package/src/utils/render.ts +1 -1
- package/src/worker.ts +5 -0
- package/wrangler-dist/cli.d.ts +13 -2
- package/wrangler-dist/cli.js +3879 -3264
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { withConfig } from "../config";
|
|
2
|
+
import { logger } from "../logger";
|
|
3
|
+
import { requireAuth } from "../user";
|
|
4
|
+
import { asJson } from "./options";
|
|
5
|
+
import { constellationBetaWarning, listRuntimes } from "./utils";
|
|
6
|
+
import type {
|
|
7
|
+
CommonYargsArgv,
|
|
8
|
+
StrictYargsOptionsToInterface,
|
|
9
|
+
} from "../yargs-types";
|
|
10
|
+
|
|
11
|
+
export function options(yargs: CommonYargsArgv) {
|
|
12
|
+
return asJson(yargs).epilogue(constellationBetaWarning);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type HandlerOptions = StrictYargsOptionsToInterface<typeof options>;
|
|
16
|
+
export const handler = withConfig<HandlerOptions>(
|
|
17
|
+
async ({ json, config }): Promise<void> => {
|
|
18
|
+
const accountId = await requireAuth(config);
|
|
19
|
+
const runtimes = await listRuntimes(accountId);
|
|
20
|
+
|
|
21
|
+
if (json) {
|
|
22
|
+
logger.log(JSON.stringify(runtimes, null, 2));
|
|
23
|
+
} else {
|
|
24
|
+
logger.log(constellationBetaWarning);
|
|
25
|
+
logger.table(runtimes.map((runtime) => ({ name: runtime })));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { CommonYargsArgv } from "../yargs-types";
|
|
2
|
+
|
|
3
|
+
export function takeName(yargs: CommonYargsArgv) {
|
|
4
|
+
return yargs.positional("name", {
|
|
5
|
+
describe: "The name of the project",
|
|
6
|
+
type: "string",
|
|
7
|
+
demandOption: true,
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function asJson(yargs: CommonYargsArgv) {
|
|
12
|
+
return yargs.option("json", {
|
|
13
|
+
describe: "return output as clean JSON",
|
|
14
|
+
type: "boolean",
|
|
15
|
+
default: false,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type Project = {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
runtime: string;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export type Model = {
|
|
8
|
+
id: string;
|
|
9
|
+
project_id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
description: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type CatalogEntry = {
|
|
15
|
+
project: Project;
|
|
16
|
+
models: Model[];
|
|
17
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { FormData, File } from "undici";
|
|
3
|
+
import { fetchResult } from "../cfetch";
|
|
4
|
+
import { withConfig } from "../config";
|
|
5
|
+
import { logger } from "../logger";
|
|
6
|
+
import { requireAuth } from "../user";
|
|
7
|
+
import { takeName } from "./options";
|
|
8
|
+
import { constellationBetaWarning, getProjectByName } from "./utils";
|
|
9
|
+
import type {
|
|
10
|
+
CommonYargsArgv,
|
|
11
|
+
StrictYargsOptionsToInterface,
|
|
12
|
+
} from "../yargs-types";
|
|
13
|
+
import type { Model } from "./types";
|
|
14
|
+
|
|
15
|
+
export function options(yargs: CommonYargsArgv) {
|
|
16
|
+
return takeName(yargs)
|
|
17
|
+
.positional("modelName", {
|
|
18
|
+
describe: "The name of the uploaded model",
|
|
19
|
+
type: "string",
|
|
20
|
+
demandOption: true,
|
|
21
|
+
})
|
|
22
|
+
.positional("modelFile", {
|
|
23
|
+
describe: "The name of the local file with the model contents",
|
|
24
|
+
type: "string",
|
|
25
|
+
demandOption: true,
|
|
26
|
+
})
|
|
27
|
+
.epilogue(constellationBetaWarning);
|
|
28
|
+
}
|
|
29
|
+
type HandlerOptions = StrictYargsOptionsToInterface<typeof options>;
|
|
30
|
+
export const handler = withConfig<HandlerOptions>(
|
|
31
|
+
async ({ name, modelName, modelFile, config }): Promise<void> => {
|
|
32
|
+
const accountId = await requireAuth(config);
|
|
33
|
+
logger.log(constellationBetaWarning);
|
|
34
|
+
|
|
35
|
+
const proj = await getProjectByName(config, accountId, name);
|
|
36
|
+
|
|
37
|
+
const formData = new FormData();
|
|
38
|
+
formData.set(
|
|
39
|
+
"file",
|
|
40
|
+
new File([readFileSync(modelFile)], modelFile, {
|
|
41
|
+
type: "application/octet-stream",
|
|
42
|
+
})
|
|
43
|
+
);
|
|
44
|
+
formData.set("name", modelName);
|
|
45
|
+
|
|
46
|
+
let model: Model;
|
|
47
|
+
try {
|
|
48
|
+
model = await fetchResult(
|
|
49
|
+
`/accounts/${accountId}/constellation/project/${proj.id}/model`,
|
|
50
|
+
{
|
|
51
|
+
method: "POST",
|
|
52
|
+
body: formData,
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
} catch (e) {
|
|
56
|
+
if ((e as { code: number }).code === 7408) {
|
|
57
|
+
throw new Error("A model with that name already exists");
|
|
58
|
+
}
|
|
59
|
+
throw e;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
logger.log(`✅ Successfully uploaded Model "${model.name}"!`);
|
|
63
|
+
}
|
|
64
|
+
);
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { fetchResult } from "../cfetch";
|
|
2
|
+
import { getEnvironmentVariableFactory } from "../environment-variables/factory";
|
|
3
|
+
import type { Config } from "../config";
|
|
4
|
+
import type { Project, Model, CatalogEntry } from "./types";
|
|
5
|
+
|
|
6
|
+
export const getConstellationWarningFromEnv = getEnvironmentVariableFactory({
|
|
7
|
+
variableName: "NO_CONSTELLATION_WARNING",
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export const constellationBetaWarning =
|
|
11
|
+
getConstellationWarningFromEnv() !== undefined
|
|
12
|
+
? ""
|
|
13
|
+
: "--------------------\n🚧 Constellation AI is currently in open alpha and is not recommended for production data and traffic\n🚧 Please report any bugs to https://github.com/cloudflare/workers-sdk/issues/new/choose\n🚧 To give feedback, visit https://discord.gg/cloudflaredev\n--------------------\n";
|
|
14
|
+
|
|
15
|
+
export const getProjectByName = async (
|
|
16
|
+
config: Config,
|
|
17
|
+
accountId: string,
|
|
18
|
+
name: string
|
|
19
|
+
): Promise<Project> => {
|
|
20
|
+
const allProjects = await listProjects(accountId);
|
|
21
|
+
const matchingProj = allProjects.find((proj) => proj.name === name);
|
|
22
|
+
if (!matchingProj) {
|
|
23
|
+
throw new Error(`Couldn't find Project with name '${name}'`);
|
|
24
|
+
}
|
|
25
|
+
return matchingProj;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const getProjectModelByName = async (
|
|
29
|
+
config: Config,
|
|
30
|
+
accountId: string,
|
|
31
|
+
proj: Project,
|
|
32
|
+
modelName: string
|
|
33
|
+
): Promise<Model> => {
|
|
34
|
+
const allModels = await listModels(accountId, proj);
|
|
35
|
+
const matchingModel = allModels.find((model) => model.name === modelName);
|
|
36
|
+
if (!matchingModel) {
|
|
37
|
+
throw new Error(`Couldn't find Model with name '${modelName}'`);
|
|
38
|
+
}
|
|
39
|
+
return matchingModel;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export async function constellationList<ResponseType>(
|
|
43
|
+
accountId: string,
|
|
44
|
+
partialUrl: string
|
|
45
|
+
): Promise<Array<ResponseType>> {
|
|
46
|
+
const pageSize = 50;
|
|
47
|
+
let page = 1;
|
|
48
|
+
const results = [];
|
|
49
|
+
while (results.length % pageSize === 0) {
|
|
50
|
+
const json: Array<ResponseType> = await fetchResult(
|
|
51
|
+
`/accounts/${accountId}/constellation/${partialUrl}`,
|
|
52
|
+
{},
|
|
53
|
+
new URLSearchParams({
|
|
54
|
+
per_page: pageSize.toString(),
|
|
55
|
+
page: page.toString(),
|
|
56
|
+
})
|
|
57
|
+
);
|
|
58
|
+
page++;
|
|
59
|
+
results.push(...json);
|
|
60
|
+
if (json.length < pageSize) {
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return results;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export const listCatalogEntries = async (
|
|
68
|
+
accountId: string
|
|
69
|
+
): Promise<Array<CatalogEntry>> => {
|
|
70
|
+
return await constellationList(accountId, "catalog");
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export const listModels = async (
|
|
74
|
+
accountId: string,
|
|
75
|
+
proj: Project
|
|
76
|
+
): Promise<Array<Model>> => {
|
|
77
|
+
return constellationList(accountId, `project/${proj.id}/model`);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export const listProjects = async (
|
|
81
|
+
accountId: string
|
|
82
|
+
): Promise<Array<Project>> => {
|
|
83
|
+
return await constellationList(accountId, "project");
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export const listRuntimes = async (
|
|
87
|
+
accountId: string
|
|
88
|
+
): Promise<Array<string>> => {
|
|
89
|
+
return await constellationList(accountId, "runtime");
|
|
90
|
+
};
|
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
CfWorkerInit,
|
|
5
5
|
CfModuleType,
|
|
6
6
|
CfDurableObjectMigrations,
|
|
7
|
+
CfPlacement,
|
|
7
8
|
} from "./worker.js";
|
|
8
9
|
|
|
9
10
|
export function toMimeType(type: CfModuleType): string {
|
|
@@ -71,6 +72,7 @@ export interface WorkerMetadata {
|
|
|
71
72
|
bindings: WorkerMetadataBinding[];
|
|
72
73
|
keep_bindings?: WorkerMetadataBinding["type"][];
|
|
73
74
|
logpush?: boolean;
|
|
75
|
+
placement?: CfPlacement;
|
|
74
76
|
// Allow unsafe.metadata to add arbitary properties at runtime
|
|
75
77
|
[key: string]: unknown;
|
|
76
78
|
}
|
|
@@ -89,6 +91,7 @@ export function createWorkerUploadForm(worker: CfWorkerInit): FormData {
|
|
|
89
91
|
compatibility_flags,
|
|
90
92
|
keepVars,
|
|
91
93
|
logpush,
|
|
94
|
+
placement,
|
|
92
95
|
} = worker;
|
|
93
96
|
|
|
94
97
|
let { modules } = worker;
|
|
@@ -320,6 +323,7 @@ export function createWorkerUploadForm(worker: CfWorkerInit): FormData {
|
|
|
320
323
|
capnp_schema: bindings.logfwdr?.schema,
|
|
321
324
|
...(keepVars && { keep_bindings: ["plain_text", "json"] }),
|
|
322
325
|
...(logpush !== undefined && { logpush }),
|
|
326
|
+
...(placement && { placement }),
|
|
323
327
|
};
|
|
324
328
|
|
|
325
329
|
if (bindings.unsafe?.metadata !== undefined) {
|
package/src/dev/dev.tsx
CHANGED
|
@@ -116,6 +116,7 @@ export type DevProps = {
|
|
|
116
116
|
initialPort: number;
|
|
117
117
|
initialIp: string;
|
|
118
118
|
inspectorPort: number;
|
|
119
|
+
processEntrypoint: boolean;
|
|
119
120
|
rules: Config["rules"];
|
|
120
121
|
accountId: string | undefined;
|
|
121
122
|
initialMode: "local" | "remote";
|
|
@@ -187,6 +188,7 @@ function InteractiveDevSession(props: DevProps) {
|
|
|
187
188
|
inspect: props.inspect,
|
|
188
189
|
localProtocol: props.localProtocol,
|
|
189
190
|
forceLocal: props.forceLocal,
|
|
191
|
+
worker: props.name,
|
|
190
192
|
});
|
|
191
193
|
|
|
192
194
|
ip = props.initialIp;
|
|
@@ -271,6 +273,7 @@ function DevSession(props: DevSessionProps) {
|
|
|
271
273
|
entry: props.entry,
|
|
272
274
|
destination: directory,
|
|
273
275
|
jsxFactory: props.jsxFactory,
|
|
276
|
+
processEntrypoint: props.processEntrypoint,
|
|
274
277
|
rules: props.rules,
|
|
275
278
|
jsxFragment: props.jsxFragment,
|
|
276
279
|
serveAssetsFromWorker: Boolean(
|
|
@@ -348,6 +351,7 @@ function DevSession(props: DevSessionProps) {
|
|
|
348
351
|
experimentalLocal={props.experimentalLocal}
|
|
349
352
|
accountId={props.accountId}
|
|
350
353
|
experimentalLocalRemoteKv={props.experimentalLocalRemoteKv}
|
|
354
|
+
sourceMapPath={bundle?.sourceMapPath}
|
|
351
355
|
/>
|
|
352
356
|
) : (
|
|
353
357
|
<Remote
|
|
@@ -526,6 +530,7 @@ function useHotkeys(props: {
|
|
|
526
530
|
inspect: boolean;
|
|
527
531
|
localProtocol: "http" | "https";
|
|
528
532
|
forceLocal: boolean | undefined;
|
|
533
|
+
worker: string | undefined;
|
|
529
534
|
}) {
|
|
530
535
|
const { initial, inspectorPort, inspect, localProtocol, forceLocal } = props;
|
|
531
536
|
// UGH, we should put port in context instead
|
|
@@ -558,7 +563,7 @@ function useHotkeys(props: {
|
|
|
558
563
|
// toggle inspector
|
|
559
564
|
case "d": {
|
|
560
565
|
if (inspect) {
|
|
561
|
-
await openInspector(inspectorPort);
|
|
566
|
+
await openInspector(inspectorPort, props.worker);
|
|
562
567
|
}
|
|
563
568
|
break;
|
|
564
569
|
}
|
package/src/dev/local.tsx
CHANGED
|
@@ -75,6 +75,7 @@ export interface LocalProps {
|
|
|
75
75
|
experimentalLocal: boolean | undefined;
|
|
76
76
|
accountId: string | undefined; // Account ID? In local mode??? :exploding_head:
|
|
77
77
|
experimentalLocalRemoteKv: boolean | undefined;
|
|
78
|
+
sourceMapPath: string | undefined;
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
type InspectorJSON = {
|
|
@@ -95,6 +96,9 @@ export function Local(props: LocalProps) {
|
|
|
95
96
|
inspectorUrl,
|
|
96
97
|
port: props.inspectorPort,
|
|
97
98
|
logToTerminal: props.experimentalLocal ?? false,
|
|
99
|
+
sourceMapPath: props.sourceMapPath,
|
|
100
|
+
name: props.name,
|
|
101
|
+
sourceMapMetadata: props.bundle?.sourceMapMetadata,
|
|
98
102
|
});
|
|
99
103
|
return null;
|
|
100
104
|
}
|
package/src/dev/remote.tsx
CHANGED
|
@@ -107,6 +107,8 @@ export function Remote(props: RemoteProps) {
|
|
|
107
107
|
logToTerminal: true,
|
|
108
108
|
sourceMapPath: props.sourceMapPath,
|
|
109
109
|
host: previewToken?.host,
|
|
110
|
+
name: props.name,
|
|
111
|
+
sourceMapMetadata: props.bundle?.sourceMapMetadata,
|
|
110
112
|
});
|
|
111
113
|
|
|
112
114
|
const errorHandler = useErrorHandler();
|
|
@@ -574,6 +576,7 @@ async function createRemoteWorkerInit(props: {
|
|
|
574
576
|
usage_model: props.usageModel,
|
|
575
577
|
keepVars: true,
|
|
576
578
|
logpush: false,
|
|
579
|
+
placement: undefined, // no placement in dev
|
|
577
580
|
};
|
|
578
581
|
|
|
579
582
|
return init;
|
package/src/dev/start-server.ts
CHANGED
|
@@ -92,6 +92,7 @@ export async function startDevServer(
|
|
|
92
92
|
entry: props.entry,
|
|
93
93
|
destination: directory.name,
|
|
94
94
|
jsxFactory: props.jsxFactory,
|
|
95
|
+
processEntrypoint: props.processEntrypoint,
|
|
95
96
|
rules: props.rules,
|
|
96
97
|
jsxFragment: props.jsxFragment,
|
|
97
98
|
serveAssetsFromWorker: Boolean(
|
|
@@ -141,6 +142,7 @@ export async function startDevServer(
|
|
|
141
142
|
experimentalLocal: props.experimentalLocal,
|
|
142
143
|
accountId: props.accountId,
|
|
143
144
|
experimentalLocalRemoteKv: props.experimentalLocalRemoteKv,
|
|
145
|
+
sourceMapPath: bundle?.sourceMapPath,
|
|
144
146
|
});
|
|
145
147
|
|
|
146
148
|
return {
|
|
@@ -205,6 +207,7 @@ async function runEsbuild({
|
|
|
205
207
|
destination,
|
|
206
208
|
jsxFactory,
|
|
207
209
|
jsxFragment,
|
|
210
|
+
processEntrypoint,
|
|
208
211
|
rules,
|
|
209
212
|
assets,
|
|
210
213
|
betaD1Shims,
|
|
@@ -227,6 +230,7 @@ async function runEsbuild({
|
|
|
227
230
|
destination: string | undefined;
|
|
228
231
|
jsxFactory: string | undefined;
|
|
229
232
|
jsxFragment: string | undefined;
|
|
233
|
+
processEntrypoint: boolean;
|
|
230
234
|
rules: Config["rules"];
|
|
231
235
|
assets: Config["assets"];
|
|
232
236
|
betaD1Shims?: string[];
|
|
@@ -247,49 +251,56 @@ async function runEsbuild({
|
|
|
247
251
|
}): Promise<EsbuildBundle | undefined> {
|
|
248
252
|
if (!destination) return;
|
|
249
253
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
254
|
+
let traverseModuleGraphResult:
|
|
255
|
+
| Awaited<ReturnType<typeof bundleWorker>>
|
|
256
|
+
| undefined;
|
|
257
|
+
let bundleResult: Awaited<ReturnType<typeof bundleWorker>> | undefined;
|
|
258
|
+
if (noBundle) {
|
|
259
|
+
traverseModuleGraphResult = await traverseModuleGraph(entry, rules);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (processEntrypoint || !noBundle) {
|
|
263
|
+
bundleResult = await bundleWorker(entry, destination, {
|
|
264
|
+
bundle: !noBundle,
|
|
265
|
+
disableModuleCollection: noBundle,
|
|
266
|
+
serveAssetsFromWorker,
|
|
267
|
+
jsxFactory,
|
|
268
|
+
jsxFragment,
|
|
269
|
+
rules,
|
|
270
|
+
tsconfig,
|
|
271
|
+
minify,
|
|
272
|
+
legacyNodeCompat,
|
|
273
|
+
nodejsCompat,
|
|
274
|
+
define,
|
|
275
|
+
checkFetch: true,
|
|
276
|
+
assets: assets && {
|
|
277
|
+
...assets,
|
|
278
|
+
// disable the cache in dev
|
|
279
|
+
bypassCache: true,
|
|
280
|
+
},
|
|
281
|
+
betaD1Shims,
|
|
282
|
+
workerDefinitions,
|
|
283
|
+
services,
|
|
284
|
+
firstPartyWorkerDevFacade,
|
|
285
|
+
targetConsumer: "dev", // We are starting a dev server
|
|
286
|
+
testScheduled,
|
|
287
|
+
local,
|
|
288
|
+
experimentalLocal,
|
|
289
|
+
doBindings,
|
|
290
|
+
});
|
|
291
|
+
}
|
|
284
292
|
|
|
285
293
|
return {
|
|
286
294
|
id: 0,
|
|
287
295
|
entry,
|
|
288
|
-
path: resolvedEntryPointPath,
|
|
289
|
-
type:
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
296
|
+
path: bundleResult?.resolvedEntryPointPath ?? entry.file,
|
|
297
|
+
type:
|
|
298
|
+
bundleResult?.bundleType ??
|
|
299
|
+
(entry.format === "modules" ? "esm" : "commonjs"),
|
|
300
|
+
modules: traverseModuleGraphResult?.modules ?? bundleResult?.modules ?? [],
|
|
301
|
+
dependencies: bundleResult?.dependencies ?? {},
|
|
302
|
+
sourceMapPath: bundleResult?.sourceMapPath,
|
|
303
|
+
sourceMapMetadata: bundleResult?.sourceMapMetadata,
|
|
293
304
|
};
|
|
294
305
|
}
|
|
295
306
|
|
package/src/dev/use-esbuild.ts
CHANGED
|
@@ -8,6 +8,7 @@ import traverseModuleGraph from "../traverse-module-graph";
|
|
|
8
8
|
import type { Config } from "../config";
|
|
9
9
|
import type { WorkerRegistry } from "../dev-registry";
|
|
10
10
|
import type { Entry } from "../entry";
|
|
11
|
+
import type { SourceMapMetadata } from "../inspect";
|
|
11
12
|
import type { CfModule } from "../worker";
|
|
12
13
|
import type { WatchMode, Metafile } from "esbuild";
|
|
13
14
|
|
|
@@ -19,6 +20,7 @@ export type EsbuildBundle = {
|
|
|
19
20
|
modules: CfModule[];
|
|
20
21
|
dependencies: Metafile["outputs"][string]["inputs"];
|
|
21
22
|
sourceMapPath: string | undefined;
|
|
23
|
+
sourceMapMetadata: SourceMapMetadata | undefined;
|
|
22
24
|
};
|
|
23
25
|
|
|
24
26
|
export function useEsbuild({
|
|
@@ -26,6 +28,7 @@ export function useEsbuild({
|
|
|
26
28
|
destination,
|
|
27
29
|
jsxFactory,
|
|
28
30
|
jsxFragment,
|
|
31
|
+
processEntrypoint,
|
|
29
32
|
rules,
|
|
30
33
|
assets,
|
|
31
34
|
serveAssetsFromWorker,
|
|
@@ -49,6 +52,7 @@ export function useEsbuild({
|
|
|
49
52
|
destination: string | undefined;
|
|
50
53
|
jsxFactory: string | undefined;
|
|
51
54
|
jsxFragment: string | undefined;
|
|
55
|
+
processEntrypoint: boolean;
|
|
52
56
|
rules: Config["rules"];
|
|
53
57
|
assets: Config["assets"];
|
|
54
58
|
define: Config["define"];
|
|
@@ -100,45 +104,48 @@ export function useEsbuild({
|
|
|
100
104
|
async function build() {
|
|
101
105
|
if (!destination) return;
|
|
102
106
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
107
|
+
let traverseModuleGraphResult:
|
|
108
|
+
| Awaited<ReturnType<typeof bundleWorker>>
|
|
109
|
+
| undefined;
|
|
110
|
+
let bundleResult: Awaited<ReturnType<typeof bundleWorker>> | undefined;
|
|
111
|
+
if (noBundle) {
|
|
112
|
+
traverseModuleGraphResult = await traverseModuleGraph(entry, rules);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (processEntrypoint || !noBundle) {
|
|
116
|
+
bundleResult = await bundleWorker(entry, destination, {
|
|
117
|
+
bundle: !noBundle,
|
|
118
|
+
disableModuleCollection: noBundle,
|
|
119
|
+
serveAssetsFromWorker,
|
|
120
|
+
jsxFactory,
|
|
121
|
+
jsxFragment,
|
|
122
|
+
rules,
|
|
123
|
+
watch: watchMode,
|
|
124
|
+
tsconfig,
|
|
125
|
+
minify,
|
|
126
|
+
legacyNodeCompat,
|
|
127
|
+
nodejsCompat,
|
|
128
|
+
betaD1Shims,
|
|
129
|
+
doBindings: durableObjects.bindings,
|
|
130
|
+
define,
|
|
131
|
+
checkFetch: true,
|
|
132
|
+
assets: assets && {
|
|
133
|
+
...assets,
|
|
134
|
+
// disable the cache in dev
|
|
135
|
+
bypassCache: true,
|
|
136
|
+
},
|
|
137
|
+
workerDefinitions,
|
|
138
|
+
services,
|
|
139
|
+
firstPartyWorkerDevFacade,
|
|
140
|
+
local,
|
|
141
|
+
targetConsumer,
|
|
142
|
+
testScheduled,
|
|
143
|
+
experimentalLocal,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
139
146
|
|
|
140
147
|
// Capture the `stop()` method to use as the `useEffect()` destructor.
|
|
141
|
-
stopWatching = stop;
|
|
148
|
+
stopWatching = bundleResult?.stop;
|
|
142
149
|
|
|
143
150
|
// if "noBundle" is true, then we need to manually watch the entry point and
|
|
144
151
|
// trigger "builds" when it changes
|
|
@@ -156,11 +163,15 @@ export function useEsbuild({
|
|
|
156
163
|
setBundle({
|
|
157
164
|
id: 0,
|
|
158
165
|
entry,
|
|
159
|
-
path: resolvedEntryPointPath,
|
|
160
|
-
type:
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
166
|
+
path: bundleResult?.resolvedEntryPointPath ?? entry.file,
|
|
167
|
+
type:
|
|
168
|
+
bundleResult?.bundleType ??
|
|
169
|
+
(entry.format === "modules" ? "esm" : "commonjs"),
|
|
170
|
+
modules:
|
|
171
|
+
traverseModuleGraphResult?.modules ?? bundleResult?.modules ?? [],
|
|
172
|
+
dependencies: bundleResult?.dependencies ?? {},
|
|
173
|
+
sourceMapPath: bundleResult?.sourceMapPath,
|
|
174
|
+
sourceMapMetadata: bundleResult?.sourceMapMetadata,
|
|
164
175
|
});
|
|
165
176
|
}
|
|
166
177
|
|
|
@@ -180,6 +191,7 @@ export function useEsbuild({
|
|
|
180
191
|
jsxFactory,
|
|
181
192
|
jsxFragment,
|
|
182
193
|
serveAssetsFromWorker,
|
|
194
|
+
processEntrypoint,
|
|
183
195
|
rules,
|
|
184
196
|
tsconfig,
|
|
185
197
|
exit,
|
package/src/dev.tsx
CHANGED
|
@@ -28,7 +28,7 @@ import {
|
|
|
28
28
|
printWranglerBanner,
|
|
29
29
|
} from "./index";
|
|
30
30
|
import type { Config, Environment } from "./config";
|
|
31
|
-
import type { Route } from "./config/environment";
|
|
31
|
+
import type { Route, Rule } from "./config/environment";
|
|
32
32
|
import type { LoggerLevel } from "./logger";
|
|
33
33
|
import type { EnablePagesAssetsServiceBindingOptions } from "./miniflare-cli/types";
|
|
34
34
|
import type { CfWorkerInit } from "./worker";
|
|
@@ -334,6 +334,9 @@ export type AdditionalDevProps = {
|
|
|
334
334
|
preview_bucket_name?: string;
|
|
335
335
|
}[];
|
|
336
336
|
d1Databases?: Environment["d1_databases"];
|
|
337
|
+
processEntrypoint?: boolean;
|
|
338
|
+
moduleRoot?: string;
|
|
339
|
+
rules?: Rule[];
|
|
337
340
|
};
|
|
338
341
|
|
|
339
342
|
type StartDevOptions = DevArguments &
|
|
@@ -424,7 +427,8 @@ export async function startDev(args: StartDevOptions) {
|
|
|
424
427
|
zone={zoneId}
|
|
425
428
|
host={host}
|
|
426
429
|
routes={routes}
|
|
427
|
-
|
|
430
|
+
processEntrypoint={!!args.processEntrypoint}
|
|
431
|
+
rules={args.rules ?? getRules(configParam)}
|
|
428
432
|
legacyEnv={isLegacyEnv(configParam)}
|
|
429
433
|
minify={args.minify ?? configParam.minify}
|
|
430
434
|
legacyNodeCompat={legacyNodeCompat}
|
|
@@ -560,7 +564,8 @@ export async function startApiDev(args: StartDevOptions) {
|
|
|
560
564
|
zone: zoneId,
|
|
561
565
|
host: host,
|
|
562
566
|
routes: routes,
|
|
563
|
-
|
|
567
|
+
processEntrypoint: !!args.processEntrypoint,
|
|
568
|
+
rules: args.rules ?? getRules(configParam),
|
|
564
569
|
legacyEnv: isLegacyEnv(configParam),
|
|
565
570
|
minify: args.minify ?? configParam.minify,
|
|
566
571
|
legacyNodeCompat,
|
|
@@ -687,7 +692,7 @@ async function validateDevServerSettings(
|
|
|
687
692
|
config: Config
|
|
688
693
|
) {
|
|
689
694
|
const entry = await getEntry(
|
|
690
|
-
{ assets: args.assets, script: args.script },
|
|
695
|
+
{ assets: args.assets, script: args.script, moduleRoot: args.moduleRoot },
|
|
691
696
|
config,
|
|
692
697
|
"dev"
|
|
693
698
|
);
|
package/src/entry.ts
CHANGED
|
@@ -25,6 +25,11 @@ export type Entry = {
|
|
|
25
25
|
format: CfScriptFormat;
|
|
26
26
|
/** The directory that contains all of a `--no-bundle` worker's modules. Usually `${directory}/src`. Defaults to path.dirname(file) */
|
|
27
27
|
moduleRoot: string;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A worker's name
|
|
31
|
+
*/
|
|
32
|
+
name?: string | undefined;
|
|
28
33
|
};
|
|
29
34
|
|
|
30
35
|
/**
|
|
@@ -35,6 +40,7 @@ export async function getEntry(
|
|
|
35
40
|
script?: string;
|
|
36
41
|
format?: CfScriptFormat | undefined;
|
|
37
42
|
assets?: string | undefined;
|
|
43
|
+
moduleRoot?: string;
|
|
38
44
|
},
|
|
39
45
|
config: Config,
|
|
40
46
|
command: "dev" | "publish" | "types"
|
|
@@ -113,7 +119,8 @@ export async function getEntry(
|
|
|
113
119
|
file,
|
|
114
120
|
directory,
|
|
115
121
|
format,
|
|
116
|
-
moduleRoot: config.base_dir ?? path.dirname(file),
|
|
122
|
+
moduleRoot: args.moduleRoot ?? config.base_dir ?? path.dirname(file),
|
|
123
|
+
name: config.name ?? "worker",
|
|
117
124
|
};
|
|
118
125
|
}
|
|
119
126
|
|