wrangler 0.0.0-e7cf0caa → 0.0.0-e87ad068
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 +167 -93
- package/package.json +6 -6
- package/src/__tests__/configuration.test.ts +218 -0
- package/src/__tests__/constellation.test.ts +371 -0
- package/src/__tests__/d1/migrate.test.ts +100 -0
- package/src/__tests__/index.test.ts +4 -2
- package/src/__tests__/init.test.ts +109 -3
- package/src/__tests__/mtls-certificates.test.ts +2 -1
- package/src/__tests__/pages/functions-build.test.ts +77 -0
- package/src/__tests__/pages-deployment-tail.test.ts +2 -0
- package/src/__tests__/publish.test.ts +646 -187
- package/src/__tests__/tail.test.ts +49 -7
- package/src/__tests__/tsconfig.tsbuildinfo +1 -1
- package/src/__tests__/unstableDev.test.ts +61 -0
- package/src/__tests__/user.test.ts +1 -1
- package/src/api/dev.ts +12 -0
- package/src/api/pages/create-worker-bundle-contents.ts +4 -0
- package/src/api/pages/publish.tsx +28 -12
- package/src/bundle.ts +58 -14
- package/src/cfetch/internal.ts +19 -14
- package/src/config/environment.ts +41 -0
- package/src/config/index.ts +21 -0
- package/src/config/validation.ts +182 -0
- package/src/constellation/createProject.tsx +51 -0
- package/src/constellation/deleteProject.ts +51 -0
- package/src/constellation/deleteProjectModel.ts +76 -0
- package/src/constellation/index.ts +75 -0
- package/src/constellation/listCatalog.tsx +35 -0
- package/src/constellation/listModel.tsx +49 -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 +84 -0
- package/src/constellation/utils.ts +90 -0
- package/src/create-worker-upload-form.ts +25 -0
- package/src/d1/backups.tsx +4 -4
- package/src/d1/constants.ts +3 -0
- package/src/d1/create.tsx +77 -43
- package/src/d1/delete.ts +1 -1
- package/src/d1/execute.tsx +27 -13
- package/src/d1/list.tsx +13 -11
- package/src/d1/migrations/apply.tsx +29 -6
- package/src/d1/migrations/helpers.ts +8 -9
- package/src/d1/types.ts +7 -0
- package/src/dev/dev.tsx +9 -2
- package/src/dev/local.tsx +52 -20
- package/src/dev/remote.tsx +4 -0
- package/src/dev/start-server.ts +64 -40
- package/src/dev/use-esbuild.ts +70 -43
- package/src/dev-registry.ts +11 -0
- package/src/dev.tsx +23 -6
- package/src/docs/helpers.ts +50 -0
- package/src/docs/index.ts +25 -68
- package/src/entry.ts +8 -1
- package/src/environment-variables/factory.ts +2 -1
- package/src/generate/index.ts +5 -0
- package/src/index.ts +12 -1
- package/src/init.ts +52 -10
- package/src/inspect.ts +107 -6
- package/src/kv/helpers.ts +7 -4
- package/src/logger.ts +5 -1
- package/src/miniflare-cli/index.ts +2 -2
- package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -1
- package/src/module-collection.ts +1 -1
- package/src/pages/build.ts +30 -17
- package/src/pages/dev.ts +51 -8
- package/src/pages/functions/buildPlugin.ts +1 -0
- package/src/pages/functions/buildWorker.ts +92 -2
- package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
- package/src/publish/publish.ts +9 -1
- package/src/secret/index.ts +4 -0
- package/src/sites.ts +164 -52
- package/src/tail/createTail.ts +9 -0
- package/src/tail/printing.ts +12 -0
- package/src/traverse-module-graph.ts +2 -1
- package/src/type-generation.ts +6 -0
- package/src/user/user.ts +1 -0
- package/src/utils/render.ts +1 -1
- package/src/worker.ts +26 -0
- package/templates/__tests__/tsconfig.tsbuildinfo +1 -1
- package/templates/pages-dev-util.ts +4 -1
- package/templates/tsconfig.tsbuildinfo +1 -1
- package/wrangler-dist/cli.d.ts +78 -2
- package/wrangler-dist/cli.js +65057 -63883
|
@@ -4,7 +4,7 @@ import { confirm } from "../../dialogs";
|
|
|
4
4
|
import { CI } from "../../is-ci";
|
|
5
5
|
import isInteractive from "../../is-interactive";
|
|
6
6
|
import { logger } from "../../logger";
|
|
7
|
-
import { DEFAULT_MIGRATION_PATH } from "../constants";
|
|
7
|
+
import { DEFAULT_MIGRATION_PATH, DEFAULT_BATCH_SIZE } from "../constants";
|
|
8
8
|
import { executeSql } from "../execute";
|
|
9
9
|
import type { ConfigFields, DevConfig, Environment } from "../../config";
|
|
10
10
|
import type { QueryResult } from "../execute";
|
|
@@ -100,6 +100,7 @@ const listAppliedMigrations = async (
|
|
|
100
100
|
file: undefined,
|
|
101
101
|
json: undefined,
|
|
102
102
|
preview,
|
|
103
|
+
batchSize: DEFAULT_BATCH_SIZE,
|
|
103
104
|
});
|
|
104
105
|
|
|
105
106
|
if (!response || response[0].results.length === 0) return [];
|
|
@@ -157,16 +158,14 @@ export const initMigrationsTable = async ({
|
|
|
157
158
|
name,
|
|
158
159
|
shouldPrompt: isInteractive() && !CI.isCI(),
|
|
159
160
|
persistTo,
|
|
160
|
-
command: `
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
applied_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
|
|
166
|
-
);
|
|
167
|
-
`,
|
|
161
|
+
command: `CREATE TABLE IF NOT EXISTS ${migrationsTableName}(
|
|
162
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
163
|
+
name TEXT UNIQUE,
|
|
164
|
+
applied_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
|
|
165
|
+
);`,
|
|
168
166
|
file: undefined,
|
|
169
167
|
json: undefined,
|
|
170
168
|
preview,
|
|
169
|
+
batchSize: DEFAULT_BATCH_SIZE,
|
|
171
170
|
});
|
|
172
171
|
};
|
package/src/d1/types.ts
CHANGED
|
@@ -8,6 +8,13 @@ export type Database = {
|
|
|
8
8
|
migrationsFolderPath: string;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
+
export type DatabaseCreationResult = {
|
|
12
|
+
uuid: string;
|
|
13
|
+
name: string;
|
|
14
|
+
primary_location_hint?: string;
|
|
15
|
+
created_in_region?: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
11
18
|
export type Backup = {
|
|
12
19
|
id: string;
|
|
13
20
|
database_id: string;
|
package/src/dev/dev.tsx
CHANGED
|
@@ -30,7 +30,7 @@ import type { WorkerRegistry } from "../dev-registry";
|
|
|
30
30
|
import type { Entry } from "../entry";
|
|
31
31
|
import type { EnablePagesAssetsServiceBindingOptions } from "../miniflare-cli/types";
|
|
32
32
|
import type { AssetPaths } from "../sites";
|
|
33
|
-
import type { CfWorkerInit } from "../worker";
|
|
33
|
+
import type { CfModule, CfWorkerInit } from "../worker";
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* This hooks establishes a connection with the dev registry,
|
|
@@ -116,6 +116,8 @@ export type DevProps = {
|
|
|
116
116
|
initialPort: number;
|
|
117
117
|
initialIp: string;
|
|
118
118
|
inspectorPort: number;
|
|
119
|
+
processEntrypoint: boolean;
|
|
120
|
+
additionalModules: CfModule[];
|
|
119
121
|
rules: Config["rules"];
|
|
120
122
|
accountId: string | undefined;
|
|
121
123
|
initialMode: "local" | "remote";
|
|
@@ -187,6 +189,7 @@ function InteractiveDevSession(props: DevProps) {
|
|
|
187
189
|
inspect: props.inspect,
|
|
188
190
|
localProtocol: props.localProtocol,
|
|
189
191
|
forceLocal: props.forceLocal,
|
|
192
|
+
worker: props.name,
|
|
190
193
|
});
|
|
191
194
|
|
|
192
195
|
ip = props.initialIp;
|
|
@@ -271,6 +274,8 @@ function DevSession(props: DevSessionProps) {
|
|
|
271
274
|
entry: props.entry,
|
|
272
275
|
destination: directory,
|
|
273
276
|
jsxFactory: props.jsxFactory,
|
|
277
|
+
processEntrypoint: props.processEntrypoint,
|
|
278
|
+
additionalModules: props.additionalModules,
|
|
274
279
|
rules: props.rules,
|
|
275
280
|
jsxFragment: props.jsxFragment,
|
|
276
281
|
serveAssetsFromWorker: Boolean(
|
|
@@ -348,6 +353,7 @@ function DevSession(props: DevSessionProps) {
|
|
|
348
353
|
experimentalLocal={props.experimentalLocal}
|
|
349
354
|
accountId={props.accountId}
|
|
350
355
|
experimentalLocalRemoteKv={props.experimentalLocalRemoteKv}
|
|
356
|
+
sourceMapPath={bundle?.sourceMapPath}
|
|
351
357
|
/>
|
|
352
358
|
) : (
|
|
353
359
|
<Remote
|
|
@@ -526,6 +532,7 @@ function useHotkeys(props: {
|
|
|
526
532
|
inspect: boolean;
|
|
527
533
|
localProtocol: "http" | "https";
|
|
528
534
|
forceLocal: boolean | undefined;
|
|
535
|
+
worker: string | undefined;
|
|
529
536
|
}) {
|
|
530
537
|
const { initial, inspectorPort, inspect, localProtocol, forceLocal } = props;
|
|
531
538
|
// UGH, we should put port in context instead
|
|
@@ -558,7 +565,7 @@ function useHotkeys(props: {
|
|
|
558
565
|
// toggle inspector
|
|
559
566
|
case "d": {
|
|
560
567
|
if (inspect) {
|
|
561
|
-
await openInspector(inspectorPort);
|
|
568
|
+
await openInspector(inspectorPort, props.worker);
|
|
562
569
|
}
|
|
563
570
|
break;
|
|
564
571
|
}
|
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
|
}
|
|
@@ -695,6 +699,7 @@ export function setupMiniflareOptions({
|
|
|
695
699
|
durableObjectsPersist: true,
|
|
696
700
|
kvPersist: true,
|
|
697
701
|
r2Persist: true,
|
|
702
|
+
d1Persist: true,
|
|
698
703
|
}),
|
|
699
704
|
|
|
700
705
|
liveReload,
|
|
@@ -792,6 +797,18 @@ export async function buildMiniflare3Logger(): Promise<Miniflare3LogType> {
|
|
|
792
797
|
return logLevel === LogLevel.NONE ? new NoOpLog() : new Log(logLevel);
|
|
793
798
|
}
|
|
794
799
|
|
|
800
|
+
function transformMf2PersistToMf3(persist?: boolean | string) {
|
|
801
|
+
// Wrangler reuses Miniflare 3 instances between reloads but not Miniflare 2
|
|
802
|
+
// ones. We previously set `*Persist` options to `true` by default to
|
|
803
|
+
// persist data between reloads in the temporary script directory (Miniflare
|
|
804
|
+
// 2's working directory). However, with Miniflare 3, the working directory
|
|
805
|
+
// is the current working directory, so we want to set these to `false`
|
|
806
|
+
// and use Miniflare 3's native in-memory persistence.
|
|
807
|
+
//
|
|
808
|
+
// See https://github.com/cloudflare/workers-sdk/issues/2995.
|
|
809
|
+
return persist === true ? false : persist;
|
|
810
|
+
}
|
|
811
|
+
|
|
795
812
|
export async function transformMf2OptionsToMf3Options({
|
|
796
813
|
miniflare2Options,
|
|
797
814
|
format,
|
|
@@ -819,8 +836,9 @@ export async function transformMf2OptionsToMf3Options({
|
|
|
819
836
|
};
|
|
820
837
|
}
|
|
821
838
|
|
|
822
|
-
|
|
839
|
+
let options: Partial<Miniflare3Options> = {
|
|
823
840
|
...miniflare2Options,
|
|
841
|
+
|
|
824
842
|
// Miniflare 3 distinguishes between binding name and namespace/bucket IDs.
|
|
825
843
|
kvNamespaces: Object.fromEntries(
|
|
826
844
|
kvNamespaces?.map(({ binding, id }) => [binding, id]) ?? []
|
|
@@ -834,8 +852,17 @@ export async function transformMf2OptionsToMf3Options({
|
|
|
834
852
|
preview_database_id ?? database_id,
|
|
835
853
|
]) ?? []
|
|
836
854
|
),
|
|
855
|
+
|
|
856
|
+
cachePersist: transformMf2PersistToMf3(miniflare2Options.cachePersist),
|
|
857
|
+
durableObjectsPersist: transformMf2PersistToMf3(
|
|
858
|
+
miniflare2Options.durableObjectsPersist
|
|
859
|
+
),
|
|
860
|
+
kvPersist: transformMf2PersistToMf3(miniflare2Options.kvPersist),
|
|
861
|
+
r2Persist: transformMf2PersistToMf3(miniflare2Options.r2Persist),
|
|
862
|
+
d1Persist: transformMf2PersistToMf3(miniflare2Options.d1Persist),
|
|
863
|
+
|
|
837
864
|
inspectorPort,
|
|
838
|
-
verbose:
|
|
865
|
+
verbose: logger.loggerLevel === "debug",
|
|
839
866
|
cloudflareFetch,
|
|
840
867
|
log,
|
|
841
868
|
};
|
|
@@ -873,22 +900,27 @@ export async function transformMf2OptionsToMf3Options({
|
|
|
873
900
|
const root = path.dirname(bundle.path);
|
|
874
901
|
|
|
875
902
|
assert.strictEqual(bundle.type, "esm");
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
903
|
+
options = {
|
|
904
|
+
// Creating a new options object ensures types check (Miniflare's
|
|
905
|
+
// options type requires source code to be specified)
|
|
906
|
+
...options,
|
|
907
|
+
// Required for source mapped paths to resolve correctly
|
|
908
|
+
modulesRoot: root,
|
|
909
|
+
modules: [
|
|
910
|
+
// Entrypoint
|
|
911
|
+
{
|
|
912
|
+
type: "ESModule",
|
|
913
|
+
path: bundle.path,
|
|
914
|
+
contents: await readFile(bundle.path, "utf-8"),
|
|
915
|
+
},
|
|
916
|
+
// Misc (WebAssembly, etc, ...)
|
|
917
|
+
...bundle.modules.map((module) => ({
|
|
918
|
+
type: ModuleTypeToRuleType[module.type ?? "esm"],
|
|
919
|
+
path: path.resolve(root, module.name),
|
|
920
|
+
contents: module.content,
|
|
921
|
+
})),
|
|
922
|
+
],
|
|
923
|
+
};
|
|
892
924
|
}
|
|
893
925
|
|
|
894
926
|
if (kvRemote) {
|
|
@@ -906,7 +938,7 @@ export async function transformMf2OptionsToMf3Options({
|
|
|
906
938
|
options.kvPersist = `remote:?cache=${encodeURIComponent(kvRemoteCache)}`;
|
|
907
939
|
}
|
|
908
940
|
|
|
909
|
-
return options;
|
|
941
|
+
return options as Miniflare3Options;
|
|
910
942
|
}
|
|
911
943
|
|
|
912
944
|
// Caching of the `npx-import`ed `@miniflare/tre` package
|
|
@@ -916,5 +948,5 @@ export async function getMiniflare3(): Promise<
|
|
|
916
948
|
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
|
|
917
949
|
typeof import("@miniflare/tre")
|
|
918
950
|
> {
|
|
919
|
-
return (miniflare3Module ??= await npxImport("@miniflare/tre@3.0.0-next.
|
|
951
|
+
return (miniflare3Module ??= await npxImport("@miniflare/tre@3.0.0-next.13"));
|
|
920
952
|
}
|
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,8 @@ 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
|
|
580
|
+
tail_consumers: undefined, // no tail consumers in dev - TODO revist?
|
|
577
581
|
};
|
|
578
582
|
|
|
579
583
|
return init;
|
package/src/dev/start-server.ts
CHANGED
|
@@ -4,7 +4,7 @@ import * as path from "node:path";
|
|
|
4
4
|
import * as util from "node:util";
|
|
5
5
|
import onExit from "signal-exit";
|
|
6
6
|
import tmp from "tmp-promise";
|
|
7
|
-
import { bundleWorker } from "../bundle";
|
|
7
|
+
import { bundleWorker, dedupeModulesByName } from "../bundle";
|
|
8
8
|
import {
|
|
9
9
|
getBoundRegisteredWorkers,
|
|
10
10
|
registerWorker,
|
|
@@ -30,6 +30,7 @@ import type { Config } from "../config";
|
|
|
30
30
|
import type { DurableObjectBindings } from "../config/environment";
|
|
31
31
|
import type { WorkerRegistry } from "../dev-registry";
|
|
32
32
|
import type { Entry } from "../entry";
|
|
33
|
+
import type { CfModule } from "../worker";
|
|
33
34
|
import type { DevProps, DirectorySyncResult } from "./dev";
|
|
34
35
|
import type { LocalProps } from "./local";
|
|
35
36
|
import type { EsbuildBundle } from "./use-esbuild";
|
|
@@ -92,6 +93,8 @@ export async function startDevServer(
|
|
|
92
93
|
entry: props.entry,
|
|
93
94
|
destination: directory.name,
|
|
94
95
|
jsxFactory: props.jsxFactory,
|
|
96
|
+
processEntrypoint: props.processEntrypoint,
|
|
97
|
+
additionalModules: props.additionalModules,
|
|
95
98
|
rules: props.rules,
|
|
96
99
|
jsxFragment: props.jsxFragment,
|
|
97
100
|
serveAssetsFromWorker: Boolean(
|
|
@@ -141,6 +144,7 @@ export async function startDevServer(
|
|
|
141
144
|
experimentalLocal: props.experimentalLocal,
|
|
142
145
|
accountId: props.accountId,
|
|
143
146
|
experimentalLocalRemoteKv: props.experimentalLocalRemoteKv,
|
|
147
|
+
sourceMapPath: bundle?.sourceMapPath,
|
|
144
148
|
});
|
|
145
149
|
|
|
146
150
|
return {
|
|
@@ -205,6 +209,8 @@ async function runEsbuild({
|
|
|
205
209
|
destination,
|
|
206
210
|
jsxFactory,
|
|
207
211
|
jsxFragment,
|
|
212
|
+
processEntrypoint,
|
|
213
|
+
additionalModules,
|
|
208
214
|
rules,
|
|
209
215
|
assets,
|
|
210
216
|
betaD1Shims,
|
|
@@ -227,6 +233,8 @@ async function runEsbuild({
|
|
|
227
233
|
destination: string | undefined;
|
|
228
234
|
jsxFactory: string | undefined;
|
|
229
235
|
jsxFragment: string | undefined;
|
|
236
|
+
processEntrypoint: boolean;
|
|
237
|
+
additionalModules: CfModule[];
|
|
230
238
|
rules: Config["rules"];
|
|
231
239
|
assets: Config["assets"];
|
|
232
240
|
betaD1Shims?: string[];
|
|
@@ -247,49 +255,65 @@ async function runEsbuild({
|
|
|
247
255
|
}): Promise<EsbuildBundle | undefined> {
|
|
248
256
|
if (!destination) return;
|
|
249
257
|
|
|
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
|
-
|
|
258
|
+
let traverseModuleGraphResult:
|
|
259
|
+
| Awaited<ReturnType<typeof bundleWorker>>
|
|
260
|
+
| undefined;
|
|
261
|
+
let bundleResult: Awaited<ReturnType<typeof bundleWorker>> | undefined;
|
|
262
|
+
if (noBundle) {
|
|
263
|
+
traverseModuleGraphResult = await traverseModuleGraph(entry, rules);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (processEntrypoint || !noBundle) {
|
|
267
|
+
bundleResult = await bundleWorker(entry, destination, {
|
|
268
|
+
bundle: !noBundle,
|
|
269
|
+
disableModuleCollection: noBundle,
|
|
270
|
+
serveAssetsFromWorker,
|
|
271
|
+
jsxFactory,
|
|
272
|
+
jsxFragment,
|
|
273
|
+
rules,
|
|
274
|
+
tsconfig,
|
|
275
|
+
minify,
|
|
276
|
+
legacyNodeCompat,
|
|
277
|
+
nodejsCompat,
|
|
278
|
+
define,
|
|
279
|
+
checkFetch: true,
|
|
280
|
+
assets: assets && {
|
|
281
|
+
...assets,
|
|
282
|
+
// disable the cache in dev
|
|
283
|
+
bypassCache: true,
|
|
284
|
+
},
|
|
285
|
+
betaD1Shims,
|
|
286
|
+
workerDefinitions,
|
|
287
|
+
services,
|
|
288
|
+
firstPartyWorkerDevFacade,
|
|
289
|
+
targetConsumer: "dev", // We are starting a dev server
|
|
290
|
+
testScheduled,
|
|
291
|
+
local,
|
|
292
|
+
experimentalLocal,
|
|
293
|
+
doBindings,
|
|
294
|
+
additionalModules: dedupeModulesByName([
|
|
295
|
+
...(traverseModuleGraphResult?.modules ?? []),
|
|
296
|
+
...additionalModules,
|
|
297
|
+
]),
|
|
298
|
+
});
|
|
299
|
+
}
|
|
284
300
|
|
|
285
301
|
return {
|
|
286
302
|
id: 0,
|
|
287
303
|
entry,
|
|
288
|
-
path: resolvedEntryPointPath,
|
|
289
|
-
type:
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
304
|
+
path: bundleResult?.resolvedEntryPointPath ?? entry.file,
|
|
305
|
+
type:
|
|
306
|
+
bundleResult?.bundleType ??
|
|
307
|
+
(entry.format === "modules" ? "esm" : "commonjs"),
|
|
308
|
+
modules: bundleResult
|
|
309
|
+
? bundleResult.modules
|
|
310
|
+
: dedupeModulesByName([
|
|
311
|
+
...(traverseModuleGraphResult?.modules ?? []),
|
|
312
|
+
...additionalModules,
|
|
313
|
+
]),
|
|
314
|
+
dependencies: bundleResult?.dependencies ?? {},
|
|
315
|
+
sourceMapPath: bundleResult?.sourceMapPath,
|
|
316
|
+
sourceMapMetadata: bundleResult?.sourceMapMetadata,
|
|
293
317
|
};
|
|
294
318
|
}
|
|
295
319
|
|
package/src/dev/use-esbuild.ts
CHANGED
|
@@ -2,12 +2,17 @@ import assert from "node:assert";
|
|
|
2
2
|
import { watch } from "chokidar";
|
|
3
3
|
import { useApp } from "ink";
|
|
4
4
|
import { useState, useEffect } from "react";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
bundleWorker,
|
|
7
|
+
dedupeModulesByName,
|
|
8
|
+
rewriteNodeCompatBuildFailure,
|
|
9
|
+
} from "../bundle";
|
|
6
10
|
import { logBuildFailure, logger } from "../logger";
|
|
7
11
|
import traverseModuleGraph from "../traverse-module-graph";
|
|
8
12
|
import type { Config } from "../config";
|
|
9
13
|
import type { WorkerRegistry } from "../dev-registry";
|
|
10
14
|
import type { Entry } from "../entry";
|
|
15
|
+
import type { SourceMapMetadata } from "../inspect";
|
|
11
16
|
import type { CfModule } from "../worker";
|
|
12
17
|
import type { WatchMode, Metafile } from "esbuild";
|
|
13
18
|
|
|
@@ -19,6 +24,7 @@ export type EsbuildBundle = {
|
|
|
19
24
|
modules: CfModule[];
|
|
20
25
|
dependencies: Metafile["outputs"][string]["inputs"];
|
|
21
26
|
sourceMapPath: string | undefined;
|
|
27
|
+
sourceMapMetadata: SourceMapMetadata | undefined;
|
|
22
28
|
};
|
|
23
29
|
|
|
24
30
|
export function useEsbuild({
|
|
@@ -26,6 +32,8 @@ export function useEsbuild({
|
|
|
26
32
|
destination,
|
|
27
33
|
jsxFactory,
|
|
28
34
|
jsxFragment,
|
|
35
|
+
processEntrypoint,
|
|
36
|
+
additionalModules,
|
|
29
37
|
rules,
|
|
30
38
|
assets,
|
|
31
39
|
serveAssetsFromWorker,
|
|
@@ -49,6 +57,8 @@ export function useEsbuild({
|
|
|
49
57
|
destination: string | undefined;
|
|
50
58
|
jsxFactory: string | undefined;
|
|
51
59
|
jsxFragment: string | undefined;
|
|
60
|
+
processEntrypoint: boolean;
|
|
61
|
+
additionalModules: CfModule[];
|
|
52
62
|
rules: Config["rules"];
|
|
53
63
|
assets: Config["assets"];
|
|
54
64
|
define: Config["define"];
|
|
@@ -100,45 +110,52 @@ export function useEsbuild({
|
|
|
100
110
|
async function build() {
|
|
101
111
|
if (!destination) return;
|
|
102
112
|
|
|
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
|
-
|
|
113
|
+
let traverseModuleGraphResult:
|
|
114
|
+
| Awaited<ReturnType<typeof bundleWorker>>
|
|
115
|
+
| undefined;
|
|
116
|
+
let bundleResult: Awaited<ReturnType<typeof bundleWorker>> | undefined;
|
|
117
|
+
if (noBundle) {
|
|
118
|
+
traverseModuleGraphResult = await traverseModuleGraph(entry, rules);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (processEntrypoint || !noBundle) {
|
|
122
|
+
bundleResult = await bundleWorker(entry, destination, {
|
|
123
|
+
bundle: !noBundle,
|
|
124
|
+
disableModuleCollection: noBundle,
|
|
125
|
+
serveAssetsFromWorker,
|
|
126
|
+
jsxFactory,
|
|
127
|
+
jsxFragment,
|
|
128
|
+
rules,
|
|
129
|
+
watch: watchMode,
|
|
130
|
+
tsconfig,
|
|
131
|
+
minify,
|
|
132
|
+
legacyNodeCompat,
|
|
133
|
+
nodejsCompat,
|
|
134
|
+
betaD1Shims,
|
|
135
|
+
doBindings: durableObjects.bindings,
|
|
136
|
+
define,
|
|
137
|
+
checkFetch: true,
|
|
138
|
+
assets: assets && {
|
|
139
|
+
...assets,
|
|
140
|
+
// disable the cache in dev
|
|
141
|
+
bypassCache: true,
|
|
142
|
+
},
|
|
143
|
+
workerDefinitions,
|
|
144
|
+
services,
|
|
145
|
+
firstPartyWorkerDevFacade,
|
|
146
|
+
local,
|
|
147
|
+
targetConsumer,
|
|
148
|
+
testScheduled,
|
|
149
|
+
experimentalLocal,
|
|
150
|
+
additionalModules: dedupeModulesByName([
|
|
151
|
+
...(traverseModuleGraphResult?.modules ?? []),
|
|
152
|
+
...additionalModules,
|
|
153
|
+
]),
|
|
154
|
+
});
|
|
155
|
+
}
|
|
139
156
|
|
|
140
157
|
// Capture the `stop()` method to use as the `useEffect()` destructor.
|
|
141
|
-
stopWatching = stop;
|
|
158
|
+
stopWatching = bundleResult?.stop;
|
|
142
159
|
|
|
143
160
|
// if "noBundle" is true, then we need to manually watch the entry point and
|
|
144
161
|
// trigger "builds" when it changes
|
|
@@ -156,11 +173,19 @@ export function useEsbuild({
|
|
|
156
173
|
setBundle({
|
|
157
174
|
id: 0,
|
|
158
175
|
entry,
|
|
159
|
-
path: resolvedEntryPointPath,
|
|
160
|
-
type:
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
176
|
+
path: bundleResult?.resolvedEntryPointPath ?? entry.file,
|
|
177
|
+
type:
|
|
178
|
+
bundleResult?.bundleType ??
|
|
179
|
+
(entry.format === "modules" ? "esm" : "commonjs"),
|
|
180
|
+
modules: bundleResult
|
|
181
|
+
? bundleResult.modules
|
|
182
|
+
: dedupeModulesByName([
|
|
183
|
+
...(traverseModuleGraphResult?.modules ?? []),
|
|
184
|
+
...additionalModules,
|
|
185
|
+
]),
|
|
186
|
+
dependencies: bundleResult?.dependencies ?? {},
|
|
187
|
+
sourceMapPath: bundleResult?.sourceMapPath,
|
|
188
|
+
sourceMapMetadata: bundleResult?.sourceMapMetadata,
|
|
164
189
|
});
|
|
165
190
|
}
|
|
166
191
|
|
|
@@ -180,6 +205,8 @@ export function useEsbuild({
|
|
|
180
205
|
jsxFactory,
|
|
181
206
|
jsxFragment,
|
|
182
207
|
serveAssetsFromWorker,
|
|
208
|
+
processEntrypoint,
|
|
209
|
+
additionalModules,
|
|
183
210
|
rules,
|
|
184
211
|
tsconfig,
|
|
185
212
|
exit,
|
package/src/dev-registry.ts
CHANGED
|
@@ -94,6 +94,13 @@ export async function startWorkerRegistry() {
|
|
|
94
94
|
throw err;
|
|
95
95
|
}
|
|
96
96
|
});
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The registry server may close. Reset the server to null for restart.
|
|
100
|
+
*/
|
|
101
|
+
server.on("close", () => {
|
|
102
|
+
server = null;
|
|
103
|
+
});
|
|
97
104
|
}
|
|
98
105
|
}
|
|
99
106
|
|
|
@@ -112,6 +119,10 @@ export async function registerWorker(
|
|
|
112
119
|
name: string,
|
|
113
120
|
definition: WorkerDefinition
|
|
114
121
|
) {
|
|
122
|
+
/**
|
|
123
|
+
* Prevent the dev registry be closed.
|
|
124
|
+
*/
|
|
125
|
+
await startWorkerRegistry();
|
|
115
126
|
try {
|
|
116
127
|
return await fetch(`${DEV_REGISTRY_HOST}/workers/${name}`, {
|
|
117
128
|
method: "POST",
|