wrangler 0.0.0-e7a0cd5b → 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/README.md +3 -3
- package/bin/wrangler.js +30 -10
- package/miniflare-dist/index.mjs +254 -128
- package/package.json +27 -19
- package/src/__tests__/api-dev.test.ts +65 -36
- package/src/__tests__/api-devregistry.test.ts +121 -0
- package/src/__tests__/api.test.ts +27 -5
- package/src/__tests__/configuration.test.ts +797 -98
- package/src/__tests__/constellation.test.ts +371 -0
- package/src/__tests__/d1/d1.test.ts +82 -0
- package/src/__tests__/d1/execute.test.ts +66 -0
- package/src/__tests__/d1/migrate.test.ts +257 -0
- package/src/__tests__/d1/splitter.test.ts +255 -0
- package/src/__tests__/delete.test.ts +91 -49
- package/src/__tests__/deployments.test.ts +330 -56
- package/src/__tests__/dev.test.tsx +198 -90
- package/src/__tests__/generate.test.ts +12 -10
- package/src/__tests__/guess-worker-format.test.ts +35 -0
- package/src/__tests__/helpers/end-event-loop.ts +6 -0
- package/src/__tests__/helpers/mock-auth-domain.ts +20 -0
- package/src/__tests__/helpers/mock-console.ts +6 -0
- package/src/__tests__/helpers/mock-dialogs.ts +71 -85
- package/src/__tests__/helpers/mock-get-pages-upload-token.ts +25 -0
- package/src/__tests__/helpers/mock-get-zone-from-host.ts +8 -5
- package/src/__tests__/helpers/mock-known-routes.ts +7 -2
- package/src/__tests__/helpers/mock-kv.ts +29 -16
- package/src/__tests__/helpers/mock-oauth-flow.ts +103 -92
- package/src/__tests__/helpers/mock-process.ts +8 -13
- package/src/__tests__/helpers/mock-set-timeout.ts +16 -0
- package/src/__tests__/helpers/msw/blob-worker.cjs +19 -0
- package/src/__tests__/helpers/msw/handlers/deployments.ts +128 -27
- package/src/__tests__/helpers/msw/handlers/namespaces.ts +18 -41
- package/src/__tests__/helpers/msw/handlers/oauth.ts +13 -18
- package/src/__tests__/helpers/msw/handlers/r2.ts +14 -34
- package/src/__tests__/helpers/msw/handlers/script.ts +9 -28
- package/src/__tests__/helpers/msw/handlers/user.ts +13 -24
- package/src/__tests__/helpers/msw/handlers/zones.ts +6 -8
- package/src/__tests__/helpers/msw/index.ts +32 -1
- package/src/__tests__/helpers/msw/read-file-sync.js +61 -0
- package/src/__tests__/helpers/string-dynamic-values-matcher.ts +28 -0
- package/src/__tests__/helpers/worker-scripts/parent-worker.js +4 -1
- package/src/__tests__/index.test.ts +92 -72
- package/src/__tests__/init.test.ts +1033 -631
- package/src/__tests__/jest.setup.ts +19 -42
- package/src/__tests__/kv.test.ts +355 -231
- package/src/__tests__/logger.test.ts +68 -2
- package/src/__tests__/logout.test.ts +47 -0
- package/src/__tests__/metrics.test.ts +94 -51
- package/src/__tests__/middleware.scheduled.test.ts +42 -32
- package/src/__tests__/middleware.test.ts +212 -122
- package/src/__tests__/mtls-certificates.test.ts +589 -0
- package/src/__tests__/pages/deployment-list.test.ts +80 -0
- package/src/__tests__/pages/functions-build.test.ts +529 -0
- package/src/__tests__/pages/pages.test.ts +81 -0
- package/src/__tests__/pages/project-create.test.ts +63 -0
- package/src/__tests__/pages/project-list.test.ts +110 -0
- package/src/__tests__/pages/project-upload.test.ts +500 -0
- package/src/__tests__/pages/publish.test.ts +2864 -0
- package/src/__tests__/pages-deployment-tail.test.ts +957 -0
- package/src/__tests__/parse.test.ts +106 -0
- package/src/__tests__/publish.test.ts +2227 -1005
- package/src/__tests__/pubsub.test.ts +226 -100
- package/src/__tests__/queues.test.ts +238 -77
- package/src/__tests__/r2.test.ts +55 -57
- package/src/__tests__/secret.test.ts +179 -130
- package/src/__tests__/tail.test.ts +313 -113
- package/src/__tests__/test-old-node-version.js +3 -3
- package/src/__tests__/traverse-module-graph.test.ts +220 -0
- package/src/__tests__/tsconfig-sanity.ts +12 -0
- package/src/__tests__/tsconfig.json +8 -0
- package/src/__tests__/tsconfig.tsbuildinfo +1 -0
- package/src/__tests__/type-generation.test.ts +43 -26
- package/src/__tests__/unstableDev.test.ts +61 -0
- package/src/__tests__/user.test.ts +35 -72
- package/src/__tests__/whoami.test.tsx +8 -114
- package/src/__tests__/worker-namespace.test.ts +83 -69
- package/src/api/dev.ts +180 -60
- package/src/api/index.ts +10 -1
- package/src/api/mtls-certificate.ts +148 -0
- package/src/api/pages/create-worker-bundle-contents.ts +80 -0
- package/src/api/pages/index.ts +5 -0
- package/src/api/pages/publish.tsx +371 -0
- package/src/bundle.ts +315 -148
- package/src/cfetch/index.ts +0 -2
- package/src/cfetch/internal.ts +33 -33
- package/src/cli.ts +4 -4
- package/src/config/config.ts +14 -7
- package/src/config/environment.ts +120 -24
- package/src/config/index.ts +117 -35
- package/src/config/validation-helpers.ts +1 -1
- package/src/config/validation.ts +430 -19
- 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-preview.ts +19 -8
- package/src/create-worker-upload-form.ts +81 -18
- package/src/d1/backups.tsx +47 -46
- package/src/d1/constants.ts +5 -0
- package/src/d1/create.tsx +85 -37
- package/src/d1/{delete.tsx → delete.ts} +12 -15
- package/src/d1/execute.tsx +228 -156
- package/src/d1/index.ts +31 -7
- package/src/d1/list.tsx +27 -13
- package/src/d1/migrations/apply.tsx +235 -0
- package/src/d1/migrations/create.tsx +79 -0
- package/src/d1/migrations/helpers.ts +171 -0
- package/src/d1/migrations/index.ts +3 -0
- package/src/d1/migrations/list.tsx +95 -0
- package/src/d1/migrations/options.ts +23 -0
- package/src/d1/options.ts +12 -2
- package/src/d1/splitter.ts +161 -0
- package/src/d1/types.ts +32 -0
- package/src/d1/utils.ts +12 -2
- package/src/delete.ts +8 -16
- package/src/deployments.ts +340 -46
- package/src/deprecated/index.ts +8 -302
- package/src/dev/dev.tsx +66 -46
- package/src/dev/local.tsx +339 -104
- package/src/dev/remote.tsx +36 -3
- package/src/dev/start-server.ts +146 -101
- package/src/dev/use-esbuild.ts +82 -56
- package/src/dev/validate-dev-props.ts +9 -0
- package/src/{dev-registry.tsx → dev-registry.ts} +13 -1
- package/src/dev.tsx +202 -125
- package/src/dialogs.ts +136 -0
- package/src/dispatch-namespace.ts +21 -17
- package/src/docs/helpers.ts +50 -0
- package/src/docs/index.ts +54 -0
- package/src/entry.ts +26 -11
- package/src/environment-variables/factory.ts +89 -0
- package/src/environment-variables/misc-variables.ts +30 -0
- package/src/generate/index.ts +303 -0
- package/src/git-client.ts +15 -4
- package/src/{index.tsx → index.ts} +148 -63
- package/src/init.ts +301 -197
- package/src/inspect.ts +122 -6
- package/src/jest.d.ts +4 -0
- package/src/kv/helpers.ts +7 -4
- package/src/kv/index.ts +15 -17
- package/src/logger.ts +36 -5
- package/src/metrics/metrics-config.ts +3 -3
- package/src/metrics/send-event.ts +6 -1
- package/src/miniflare-cli/assets.ts +64 -28
- package/src/miniflare-cli/index.ts +6 -9
- package/src/miniflare-cli/tsconfig.json +9 -0
- package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -0
- package/src/miniflare-cli/types.ts +11 -0
- package/src/module-collection.ts +92 -26
- package/src/mtls-certificate/cli.ts +155 -0
- package/src/pages/build.ts +423 -0
- package/src/pages/buildFunctions.ts +140 -0
- package/src/pages/deployment-tails.ts +281 -0
- package/src/pages/deployments.tsx +11 -33
- package/src/pages/{dev.tsx → dev.ts} +192 -126
- package/src/pages/errors.ts +1 -0
- package/src/pages/functions/buildPlugin.ts +73 -69
- package/src/pages/functions/buildWorker.ts +342 -117
- package/src/pages/functions/tsconfig.json +8 -0
- package/src/pages/functions/tsconfig.tsbuildinfo +1 -0
- package/src/pages/{functions.tsx → functions.ts} +8 -4
- package/src/pages/{index.tsx → index.ts} +11 -3
- package/src/pages/projects.tsx +12 -22
- package/src/pages/prompt-select-project.tsx +31 -0
- package/src/pages/publish.tsx +45 -214
- package/src/pages/types.ts +6 -9
- package/src/pages/upload.tsx +58 -14
- package/src/pages/utils.ts +14 -3
- package/src/parse.ts +23 -1
- package/src/paths.ts +1 -1
- package/src/proxy.ts +5 -0
- package/src/publish/index.ts +20 -16
- package/src/publish/publish.ts +81 -48
- package/src/pubsub/{pubsub-commands.tsx → pubsub-commands.ts} +19 -20
- package/src/queues/cli/commands/consumer/add.ts +24 -24
- package/src/queues/cli/commands/consumer/index.ts +3 -6
- package/src/queues/cli/commands/consumer/remove.ts +11 -18
- package/src/queues/cli/commands/create.ts +8 -8
- package/src/queues/cli/commands/delete.ts +8 -8
- package/src/queues/cli/commands/index.ts +6 -4
- package/src/queues/cli/commands/list.ts +8 -8
- package/src/queues/client.ts +1 -0
- package/src/queues/utils.ts +18 -0
- package/src/r2/constants.ts +4 -0
- package/src/r2/helpers.ts +1 -0
- package/src/r2/index.ts +40 -28
- package/src/secret/index.ts +18 -17
- package/src/{sites.tsx → sites.ts} +165 -53
- package/src/tail/createTail.ts +103 -3
- package/src/tail/filters.ts +1 -1
- package/src/tail/index.ts +8 -11
- package/src/tail/printing.ts +27 -0
- package/src/traverse-module-graph.ts +54 -0
- package/src/tsconfig-sanity.ts +16 -0
- package/src/type-generation.ts +85 -57
- package/src/user/access.ts +0 -1
- package/src/user/auth-variables.ts +113 -0
- package/src/user/choose-account.tsx +1 -31
- package/src/user/index.ts +0 -1
- package/src/user/{user.tsx → user.ts} +124 -82
- package/src/utils/render.ts +93 -0
- package/src/{whoami.tsx → whoami.ts} +37 -71
- package/src/worker.ts +61 -3
- package/src/yargs-types.ts +22 -5
- package/templates/__tests__/tsconfig-sanity.ts +12 -0
- package/templates/__tests__/tsconfig.json +8 -0
- package/templates/__tests__/tsconfig.tsbuildinfo +1 -0
- package/templates/checked-fetch.js +9 -3
- package/templates/d1-beta-facade.js +95 -25
- package/templates/facade.d.ts +14 -0
- package/templates/first-party-worker-module-facade.ts +4 -3
- package/templates/format-dev-errors.ts +8 -6
- package/templates/gitignore +1 -0
- package/templates/init-tests/test-jest-new-worker.js +3 -5
- package/templates/init-tests/test-vitest-new-worker.js +3 -5
- package/templates/init-tests/test-vitest-new-worker.ts +25 -0
- package/templates/middleware/loader-modules.ts +2 -2
- package/templates/middleware/loader-sw.ts +51 -31
- package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
- package/templates/new-worker.ts +3 -0
- package/templates/pages-dev-pipeline.ts +4 -1
- package/templates/pages-dev-util.ts +4 -1
- package/templates/pages-shim.ts +4 -1
- package/templates/pages-template-plugin.ts +19 -10
- package/templates/serve-static-assets.ts +17 -14
- package/templates/service-bindings-module-facade.js +1 -0
- package/templates/tsconfig-sanity.ts +11 -0
- package/templates/tsconfig.init.json +105 -0
- package/templates/tsconfig.json +5 -103
- package/templates/tsconfig.tsbuildinfo +1 -0
- package/wrangler-dist/cli.d.ts +902 -77
- package/wrangler-dist/cli.js +131685 -140615
- package/wrangler-dist/wasm-sync.wasm +0 -0
- package/src/__tests__/api-devregistry.test.js +0 -57
- package/src/__tests__/d1.test.ts +0 -72
- package/src/__tests__/dialogs.test.tsx +0 -40
- package/src/__tests__/helpers/mock-cfetch.ts +0 -333
- package/src/__tests__/pages.test.ts +0 -2223
- package/src/d1/types.tsx +0 -14
- package/src/dialogs.tsx +0 -163
- package/src/environment-variables.ts +0 -50
- package/src/pages/build.tsx +0 -238
- package/src/user/env-vars.ts +0 -46
- package/templates/experimental-local-cache-stubs.js +0 -27
- /package/src/{bundle-reporter.tsx → bundle-reporter.ts} +0 -0
- /package/src/dev/{get-local-persistence-path.tsx → get-local-persistence-path.ts} +0 -0
- /package/src/pages/{hash.tsx → hash.ts} +0 -0
package/src/dev/remote.tsx
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import { Text } from "ink";
|
|
4
|
+
import SelectInput from "ink-select-input";
|
|
3
5
|
import React, { useState, useEffect, useRef } from "react";
|
|
4
6
|
import { useErrorHandler } from "react-error-boundary";
|
|
5
7
|
import { printBundleSize } from "../bundle-reporter";
|
|
@@ -10,9 +12,9 @@ import {
|
|
|
10
12
|
import useInspector from "../inspect";
|
|
11
13
|
import { logger } from "../logger";
|
|
12
14
|
import { startPreviewServer, usePreviewServer } from "../proxy";
|
|
15
|
+
import { helpIfErrorIsSizeOrScriptStartup } from "../publish/publish";
|
|
13
16
|
import { syncAssets } from "../sites";
|
|
14
17
|
import {
|
|
15
|
-
ChooseAccount,
|
|
16
18
|
getAccountChoices,
|
|
17
19
|
requireApiToken,
|
|
18
20
|
saveAccountToCache,
|
|
@@ -105,6 +107,8 @@ export function Remote(props: RemoteProps) {
|
|
|
105
107
|
logToTerminal: true,
|
|
106
108
|
sourceMapPath: props.sourceMapPath,
|
|
107
109
|
host: previewToken?.host,
|
|
110
|
+
name: props.name,
|
|
111
|
+
sourceMapMetadata: props.bundle?.sourceMapMetadata,
|
|
108
112
|
});
|
|
109
113
|
|
|
110
114
|
const errorHandler = useErrorHandler();
|
|
@@ -302,13 +306,13 @@ export function useWorker(
|
|
|
302
306
|
// TODO: Once we get service bindings working in the
|
|
303
307
|
// edge preview server, we can define remote dev service bindings
|
|
304
308
|
// and you can uncomment this code.
|
|
305
|
-
// https://github.com/cloudflare/
|
|
309
|
+
// https://github.com/cloudflare/workers-sdk/issues/1182
|
|
306
310
|
|
|
307
311
|
/*
|
|
308
312
|
if (name) {
|
|
309
313
|
await registerWorker(name, {
|
|
310
314
|
mode: "remote",
|
|
311
|
-
// upstream protocol is always https (https://github.com/cloudflare/
|
|
315
|
+
// upstream protocol is always https (https://github.com/cloudflare/workers-sdk/issues/583)
|
|
312
316
|
protocol: "https",
|
|
313
317
|
port: undefined,
|
|
314
318
|
host: workerPreviewToken.host,
|
|
@@ -493,6 +497,7 @@ export async function getRemotePreviewToken(props: RemoteProps) {
|
|
|
493
497
|
// code 10049 happens when the preview token expires
|
|
494
498
|
logger.log("Preview token expired, restart server to fetch a new one");
|
|
495
499
|
} else {
|
|
500
|
+
helpIfErrorIsSizeOrScriptStartup(err, props.bundle?.dependencies || {});
|
|
496
501
|
logger.error("Error on remote worker:", err);
|
|
497
502
|
}
|
|
498
503
|
}
|
|
@@ -571,6 +576,8 @@ async function createRemoteWorkerInit(props: {
|
|
|
571
576
|
usage_model: props.usageModel,
|
|
572
577
|
keepVars: true,
|
|
573
578
|
logpush: false,
|
|
579
|
+
placement: undefined, // no placement in dev
|
|
580
|
+
tail_consumers: undefined, // no tail consumers in dev - TODO revist?
|
|
574
581
|
};
|
|
575
582
|
|
|
576
583
|
return init;
|
|
@@ -601,3 +608,29 @@ function getWorkerAccountAndContext(props: {
|
|
|
601
608
|
|
|
602
609
|
return { workerAccount, workerContext };
|
|
603
610
|
}
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* A component that allows the user to select from a list of available accounts.
|
|
614
|
+
*/
|
|
615
|
+
function ChooseAccount(props: {
|
|
616
|
+
accounts: ChooseAccountItem[];
|
|
617
|
+
onSelect: (account: { name: string; id: string }) => void;
|
|
618
|
+
onError: (error: Error) => void;
|
|
619
|
+
}) {
|
|
620
|
+
return (
|
|
621
|
+
<>
|
|
622
|
+
<Text bold>Select an account from below:</Text>
|
|
623
|
+
<SelectInput
|
|
624
|
+
items={props.accounts.map((item) => ({
|
|
625
|
+
key: item.id,
|
|
626
|
+
label: item.name,
|
|
627
|
+
value: item,
|
|
628
|
+
}))}
|
|
629
|
+
onSelect={(item) => {
|
|
630
|
+
logger.log(`Using account: "${item.value.name} - ${item.value.id}"`);
|
|
631
|
+
props.onSelect({ id: item.value.id, name: item.value.name });
|
|
632
|
+
}}
|
|
633
|
+
/>
|
|
634
|
+
</>
|
|
635
|
+
);
|
|
636
|
+
}
|
package/src/dev/start-server.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { fork } from "node:child_process";
|
|
2
2
|
import { realpathSync } from "node:fs";
|
|
3
|
-
import { writeFile } from "node:fs/promises";
|
|
4
3
|
import * as path from "node:path";
|
|
5
4
|
import * as util from "node:util";
|
|
6
5
|
import onExit from "signal-exit";
|
|
7
6
|
import tmp from "tmp-promise";
|
|
8
|
-
import { bundleWorker } from "../bundle";
|
|
7
|
+
import { bundleWorker, dedupeModulesByName } from "../bundle";
|
|
9
8
|
import {
|
|
10
9
|
getBoundRegisteredWorkers,
|
|
11
10
|
registerWorker,
|
|
@@ -15,29 +14,34 @@ import {
|
|
|
15
14
|
import { runCustomBuild } from "../entry";
|
|
16
15
|
import { logger } from "../logger";
|
|
17
16
|
import { waitForPortToBeAvailable } from "../proxy";
|
|
17
|
+
import traverseModuleGraph from "../traverse-module-graph";
|
|
18
18
|
import {
|
|
19
19
|
setupBindings,
|
|
20
|
-
|
|
20
|
+
getMiniflare3,
|
|
21
|
+
buildMiniflare3Logger,
|
|
21
22
|
setupMiniflareOptions,
|
|
22
23
|
setupNodeOptions,
|
|
24
|
+
transformMf2OptionsToMf3Options,
|
|
23
25
|
} from "./local";
|
|
24
26
|
import { startRemoteServer } from "./remote";
|
|
25
27
|
import { validateDevProps } from "./validate-dev-props";
|
|
26
28
|
|
|
27
29
|
import type { Config } from "../config";
|
|
30
|
+
import type { DurableObjectBindings } from "../config/environment";
|
|
28
31
|
import type { WorkerRegistry } from "../dev-registry";
|
|
29
32
|
import type { Entry } from "../entry";
|
|
33
|
+
import type { CfModule } from "../worker";
|
|
30
34
|
import type { DevProps, DirectorySyncResult } from "./dev";
|
|
31
35
|
import type { LocalProps } from "./local";
|
|
32
36
|
import type { EsbuildBundle } from "./use-esbuild";
|
|
33
37
|
import type { Miniflare as Miniflare3Type } from "@miniflare/tre";
|
|
34
|
-
import type { MiniflareOptions } from "miniflare";
|
|
35
38
|
|
|
36
39
|
import type { ChildProcess } from "node:child_process";
|
|
37
40
|
|
|
38
41
|
export async function startDevServer(
|
|
39
42
|
props: DevProps & {
|
|
40
43
|
local: boolean;
|
|
44
|
+
disableDevRegistry: boolean;
|
|
41
45
|
}
|
|
42
46
|
) {
|
|
43
47
|
try {
|
|
@@ -61,25 +65,36 @@ export async function startDevServer(
|
|
|
61
65
|
}
|
|
62
66
|
|
|
63
67
|
//start the worker registry
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
logger.log("disableDevRegistry: ", props.disableDevRegistry);
|
|
69
|
+
if (!props.disableDevRegistry) {
|
|
70
|
+
try {
|
|
71
|
+
await startWorkerRegistry();
|
|
72
|
+
if (props.local) {
|
|
73
|
+
const boundRegisteredWorkers = await getBoundRegisteredWorkers({
|
|
74
|
+
services: props.bindings.services,
|
|
75
|
+
durableObjects: props.bindings.durable_objects,
|
|
76
|
+
});
|
|
72
77
|
|
|
73
|
-
|
|
74
|
-
|
|
78
|
+
if (
|
|
79
|
+
!util.isDeepStrictEqual(boundRegisteredWorkers, workerDefinitions)
|
|
80
|
+
) {
|
|
81
|
+
workerDefinitions = boundRegisteredWorkers || {};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
} catch (err) {
|
|
85
|
+
logger.error("failed to start worker registry", err);
|
|
75
86
|
}
|
|
76
87
|
}
|
|
77
88
|
|
|
89
|
+
const betaD1Shims = props.bindings.d1_databases?.map((db) => db.binding);
|
|
90
|
+
|
|
78
91
|
//implement a react-free version of useEsbuild
|
|
79
92
|
const bundle = await runEsbuild({
|
|
80
93
|
entry: props.entry,
|
|
81
94
|
destination: directory.name,
|
|
82
95
|
jsxFactory: props.jsxFactory,
|
|
96
|
+
processEntrypoint: props.processEntrypoint,
|
|
97
|
+
additionalModules: props.additionalModules,
|
|
83
98
|
rules: props.rules,
|
|
84
99
|
jsxFragment: props.jsxFragment,
|
|
85
100
|
serveAssetsFromWorker: Boolean(
|
|
@@ -87,15 +102,19 @@ export async function startDevServer(
|
|
|
87
102
|
),
|
|
88
103
|
tsconfig: props.tsconfig,
|
|
89
104
|
minify: props.minify,
|
|
90
|
-
|
|
105
|
+
legacyNodeCompat: props.legacyNodeCompat,
|
|
106
|
+
nodejsCompat: props.nodejsCompat,
|
|
91
107
|
define: props.define,
|
|
92
108
|
noBundle: props.noBundle,
|
|
93
109
|
assets: props.assetsConfig,
|
|
110
|
+
betaD1Shims,
|
|
94
111
|
workerDefinitions,
|
|
95
112
|
services: props.bindings.services,
|
|
96
113
|
firstPartyWorkerDevFacade: props.firstPartyWorker,
|
|
97
114
|
testScheduled: props.testScheduled,
|
|
98
|
-
|
|
115
|
+
local: props.local,
|
|
116
|
+
experimentalLocal: props.experimentalLocal,
|
|
117
|
+
doBindings: props.bindings.durable_objects?.bindings ?? [],
|
|
99
118
|
});
|
|
100
119
|
|
|
101
120
|
if (props.local) {
|
|
@@ -107,8 +126,8 @@ export async function startDevServer(
|
|
|
107
126
|
compatibilityFlags: props.compatibilityFlags,
|
|
108
127
|
bindings: props.bindings,
|
|
109
128
|
assetPaths: props.assetPaths,
|
|
110
|
-
|
|
111
|
-
|
|
129
|
+
initialPort: props.initialPort,
|
|
130
|
+
initialIp: props.initialIp,
|
|
112
131
|
rules: props.rules,
|
|
113
132
|
inspectorPort: props.inspectorPort,
|
|
114
133
|
localPersistencePath: props.localPersistencePath,
|
|
@@ -117,13 +136,15 @@ export async function startDevServer(
|
|
|
117
136
|
queueConsumers: props.queueConsumers,
|
|
118
137
|
localProtocol: props.localProtocol,
|
|
119
138
|
localUpstream: props.localUpstream,
|
|
120
|
-
logPrefix: props.logPrefix,
|
|
121
139
|
inspect: props.inspect,
|
|
122
140
|
onReady: props.onReady,
|
|
123
141
|
enablePagesAssetsServiceBinding: props.enablePagesAssetsServiceBinding,
|
|
124
142
|
usageModel: props.usageModel,
|
|
125
143
|
workerDefinitions,
|
|
126
144
|
experimentalLocal: props.experimentalLocal,
|
|
145
|
+
accountId: props.accountId,
|
|
146
|
+
experimentalLocalRemoteKv: props.experimentalLocalRemoteKv,
|
|
147
|
+
sourceMapPath: bundle?.sourceMapPath,
|
|
127
148
|
});
|
|
128
149
|
|
|
129
150
|
return {
|
|
@@ -142,8 +163,8 @@ export async function startDevServer(
|
|
|
142
163
|
bindings: props.bindings,
|
|
143
164
|
assetPaths: props.assetPaths,
|
|
144
165
|
isWorkersSite: props.isWorkersSite,
|
|
145
|
-
port: props.
|
|
146
|
-
ip: props.
|
|
166
|
+
port: props.initialPort,
|
|
167
|
+
ip: props.initialIp,
|
|
147
168
|
localProtocol: props.localProtocol,
|
|
148
169
|
inspectorPort: props.inspectorPort,
|
|
149
170
|
inspect: props.inspect,
|
|
@@ -188,87 +209,111 @@ async function runEsbuild({
|
|
|
188
209
|
destination,
|
|
189
210
|
jsxFactory,
|
|
190
211
|
jsxFragment,
|
|
212
|
+
processEntrypoint,
|
|
213
|
+
additionalModules,
|
|
191
214
|
rules,
|
|
192
215
|
assets,
|
|
216
|
+
betaD1Shims,
|
|
193
217
|
serveAssetsFromWorker,
|
|
194
218
|
tsconfig,
|
|
195
219
|
minify,
|
|
196
|
-
|
|
220
|
+
legacyNodeCompat,
|
|
221
|
+
nodejsCompat,
|
|
197
222
|
define,
|
|
198
223
|
noBundle,
|
|
199
224
|
workerDefinitions,
|
|
200
225
|
services,
|
|
201
226
|
firstPartyWorkerDevFacade,
|
|
202
227
|
testScheduled,
|
|
203
|
-
|
|
228
|
+
local,
|
|
229
|
+
experimentalLocal,
|
|
230
|
+
doBindings,
|
|
204
231
|
}: {
|
|
205
232
|
entry: Entry;
|
|
206
233
|
destination: string | undefined;
|
|
207
234
|
jsxFactory: string | undefined;
|
|
208
235
|
jsxFragment: string | undefined;
|
|
236
|
+
processEntrypoint: boolean;
|
|
237
|
+
additionalModules: CfModule[];
|
|
209
238
|
rules: Config["rules"];
|
|
210
239
|
assets: Config["assets"];
|
|
240
|
+
betaD1Shims?: string[];
|
|
211
241
|
define: Config["define"];
|
|
212
242
|
services: Config["services"];
|
|
213
243
|
serveAssetsFromWorker: boolean;
|
|
214
244
|
tsconfig: string | undefined;
|
|
215
245
|
minify: boolean | undefined;
|
|
216
|
-
|
|
246
|
+
legacyNodeCompat: boolean | undefined;
|
|
247
|
+
nodejsCompat: boolean | undefined;
|
|
217
248
|
noBundle: boolean;
|
|
218
249
|
workerDefinitions: WorkerRegistry;
|
|
219
250
|
firstPartyWorkerDevFacade: boolean | undefined;
|
|
220
251
|
testScheduled?: boolean;
|
|
221
|
-
|
|
252
|
+
local: boolean;
|
|
253
|
+
experimentalLocal: boolean | undefined;
|
|
254
|
+
doBindings: DurableObjectBindings;
|
|
222
255
|
}): Promise<EsbuildBundle | undefined> {
|
|
223
256
|
if (!destination) return;
|
|
224
257
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
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
|
+
}
|
|
263
300
|
|
|
264
301
|
return {
|
|
265
302
|
id: 0,
|
|
266
303
|
entry,
|
|
267
|
-
path: resolvedEntryPointPath,
|
|
268
|
-
type:
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
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,
|
|
272
317
|
};
|
|
273
318
|
}
|
|
274
319
|
|
|
@@ -282,21 +327,22 @@ export async function startLocalServer({
|
|
|
282
327
|
bindings,
|
|
283
328
|
workerDefinitions,
|
|
284
329
|
assetPaths,
|
|
285
|
-
|
|
330
|
+
initialPort,
|
|
286
331
|
inspectorPort,
|
|
287
332
|
rules,
|
|
288
333
|
localPersistencePath,
|
|
289
334
|
liveReload,
|
|
290
|
-
|
|
335
|
+
initialIp,
|
|
291
336
|
crons,
|
|
292
337
|
queueConsumers,
|
|
293
338
|
localProtocol,
|
|
294
339
|
localUpstream,
|
|
295
340
|
inspect,
|
|
296
341
|
onReady,
|
|
297
|
-
logPrefix,
|
|
298
342
|
enablePagesAssetsServiceBinding,
|
|
299
343
|
experimentalLocal,
|
|
344
|
+
accountId,
|
|
345
|
+
experimentalLocalRemoteKv,
|
|
300
346
|
}: LocalProps) {
|
|
301
347
|
let local: ChildProcess | undefined;
|
|
302
348
|
let experimentalLocalRef: Miniflare3Type | undefined;
|
|
@@ -311,14 +357,11 @@ export async function startLocalServer({
|
|
|
311
357
|
if (!bundle || !format) return;
|
|
312
358
|
|
|
313
359
|
// port for the worker
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
abortSignal: abortController.signal,
|
|
320
|
-
});
|
|
321
|
-
}
|
|
360
|
+
await waitForPortToBeAvailable(initialPort, {
|
|
361
|
+
retryPeriod: 200,
|
|
362
|
+
timeout: 2000,
|
|
363
|
+
abortSignal: abortController.signal,
|
|
364
|
+
});
|
|
322
365
|
|
|
323
366
|
if (bindings.services && bindings.services.length > 0) {
|
|
324
367
|
logger.warn(
|
|
@@ -326,15 +369,6 @@ export async function startLocalServer({
|
|
|
326
369
|
);
|
|
327
370
|
}
|
|
328
371
|
|
|
329
|
-
// In local mode, we want to copy all referenced modules into
|
|
330
|
-
// the output bundle directory before starting up
|
|
331
|
-
for (const module of bundle.modules) {
|
|
332
|
-
await writeFile(
|
|
333
|
-
path.join(path.dirname(bundle.path), module.name),
|
|
334
|
-
module.content
|
|
335
|
-
);
|
|
336
|
-
}
|
|
337
|
-
|
|
338
372
|
const scriptPath = realpathSync(bundle.path);
|
|
339
373
|
|
|
340
374
|
const upstream =
|
|
@@ -357,12 +391,12 @@ export async function startLocalServer({
|
|
|
357
391
|
bundle,
|
|
358
392
|
});
|
|
359
393
|
|
|
360
|
-
const { forkOptions, miniflareCLIPath } = setupMiniflareOptions({
|
|
394
|
+
const { forkOptions, miniflareCLIPath, options } = setupMiniflareOptions({
|
|
361
395
|
workerName,
|
|
362
|
-
port,
|
|
396
|
+
port: initialPort,
|
|
363
397
|
scriptPath,
|
|
364
398
|
localProtocol,
|
|
365
|
-
ip,
|
|
399
|
+
ip: initialIp,
|
|
366
400
|
format,
|
|
367
401
|
rules,
|
|
368
402
|
compatibilityDate,
|
|
@@ -384,27 +418,38 @@ export async function startLocalServer({
|
|
|
384
418
|
dataBlobBindings,
|
|
385
419
|
crons,
|
|
386
420
|
upstream,
|
|
387
|
-
logPrefix,
|
|
388
421
|
workerDefinitions,
|
|
389
422
|
enablePagesAssetsServiceBinding,
|
|
390
423
|
});
|
|
391
424
|
|
|
392
425
|
if (experimentalLocal) {
|
|
393
|
-
|
|
394
|
-
const
|
|
395
|
-
|
|
426
|
+
const log = await buildMiniflare3Logger();
|
|
427
|
+
const mf3Options = await transformMf2OptionsToMf3Options({
|
|
428
|
+
miniflare2Options: options,
|
|
429
|
+
format,
|
|
430
|
+
bundle,
|
|
431
|
+
log,
|
|
432
|
+
kvNamespaces: bindings?.kv_namespaces,
|
|
433
|
+
r2Buckets: bindings?.r2_buckets,
|
|
434
|
+
d1Databases: bindings?.d1_databases,
|
|
435
|
+
authenticatedAccountId: accountId,
|
|
436
|
+
kvRemote: experimentalLocalRemoteKv,
|
|
437
|
+
inspectorPort,
|
|
438
|
+
});
|
|
439
|
+
const { Miniflare } = await getMiniflare3();
|
|
440
|
+
const mf = new Miniflare(mf3Options);
|
|
396
441
|
const runtimeURL = await mf.ready;
|
|
397
442
|
experimentalLocalRef = mf;
|
|
398
443
|
removeSignalExitListener = onExit((_code, _signal) => {
|
|
399
444
|
logger.log("⎔ Shutting down experimental local server.");
|
|
400
|
-
mf.dispose();
|
|
445
|
+
void mf.dispose();
|
|
401
446
|
experimentalLocalRef = undefined;
|
|
402
447
|
});
|
|
403
448
|
onReady?.(runtimeURL.hostname, parseInt(runtimeURL.port ?? 8787));
|
|
404
449
|
return;
|
|
405
450
|
}
|
|
406
451
|
|
|
407
|
-
const nodeOptions = setupNodeOptions({ inspect,
|
|
452
|
+
const nodeOptions = setupNodeOptions({ inspect, inspectorPort });
|
|
408
453
|
logger.log("⎔ Starting a local server...");
|
|
409
454
|
|
|
410
455
|
const child = (local = fork(miniflareCLIPath, forkOptions, {
|
|
@@ -421,21 +466,21 @@ export async function startLocalServer({
|
|
|
421
466
|
await registerWorker(workerName, {
|
|
422
467
|
protocol: localProtocol,
|
|
423
468
|
mode: "local",
|
|
424
|
-
port: message.
|
|
425
|
-
host:
|
|
469
|
+
port: message.port,
|
|
470
|
+
host: initialIp,
|
|
426
471
|
durableObjects: internalDurableObjects.map((binding) => ({
|
|
427
472
|
name: binding.name,
|
|
428
473
|
className: binding.class_name,
|
|
429
474
|
})),
|
|
430
475
|
...(message.durableObjectsPort
|
|
431
476
|
? {
|
|
432
|
-
durableObjectsHost:
|
|
477
|
+
durableObjectsHost: initialIp,
|
|
433
478
|
durableObjectsPort: message.durableObjectsPort,
|
|
434
479
|
}
|
|
435
480
|
: {}),
|
|
436
481
|
});
|
|
437
482
|
}
|
|
438
|
-
onReady?.(
|
|
483
|
+
onReady?.(initialIp, message.port);
|
|
439
484
|
}
|
|
440
485
|
});
|
|
441
486
|
|