vinext 1.0.0-beta.12 → 1.0.0-beta.13
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 +39 -12
- package/dist/build/action-owner-manifest.js +23 -5
- package/dist/build/lifecycle.d.ts +42 -0
- package/dist/build/lifecycle.js +246 -0
- package/dist/build/nitro-route-rules.js +1 -1
- package/dist/build/pages-client-assets-module.d.ts +0 -3
- package/dist/build/pages-client-assets-module.js +1 -13
- package/dist/build/precompress.js +1 -1
- package/dist/build/prerender-paths.d.ts +1 -1
- package/dist/build/prerender-paths.js +6 -6
- package/dist/build/prerender-server-pool.js +1 -1
- package/dist/build/prerender.d.ts +1 -1
- package/dist/build/prerender.js +5 -5
- package/dist/build/preview-credentials.d.ts +1 -1
- package/dist/build/preview-credentials.js +2 -2
- package/dist/build/report.js +1 -1
- package/dist/build/run-prerender.d.ts +2 -2
- package/dist/build/run-prerender.js +5 -5
- package/dist/build/standalone.js +2 -2
- package/dist/cli-args.d.ts +5 -13
- package/dist/cli-args.js +2 -45
- package/dist/cli-dev-config.d.ts +6 -2
- package/dist/cli-dev-config.js +160 -3
- package/dist/cli.js +104 -439
- package/dist/config/config-matchers.js +1 -1
- package/dist/config/next-config.d.ts +2 -2
- package/dist/config/next-config.js +5 -5
- package/dist/config/prerender.d.ts +3 -0
- package/dist/config/prerender.js +8 -2
- package/dist/entries/app-browser-entry.js +1 -1
- package/dist/entries/app-rsc-entry.js +1 -1
- package/dist/entries/pages-client-entry.d.ts +1 -0
- package/dist/entries/pages-client-entry.js +17 -2
- package/dist/index.d.ts +6 -8
- package/dist/index.js +262 -101
- package/dist/init-cloudflare.d.ts +3 -2
- package/dist/init-cloudflare.js +117 -5
- package/dist/init-platform.d.ts +2 -0
- package/dist/init-platform.js +9 -3
- package/dist/init.d.ts +7 -5
- package/dist/init.js +41 -22
- package/dist/plugins/dynamic-preload-metadata.js +1 -1
- package/dist/plugins/extensionless-dynamic-import.js +2 -2
- package/dist/plugins/fonts.js +1 -1
- package/dist/plugins/ignore-dynamic-requests.js +1 -1
- package/dist/plugins/import-meta-url.js +1 -1
- package/dist/plugins/instrumentation-client.js +1 -1
- package/dist/plugins/og-assets.js +32 -13
- package/dist/plugins/og-harfbuzz.d.ts +24 -0
- package/dist/plugins/og-harfbuzz.js +260 -0
- package/dist/plugins/optimize-imports.js +1 -1
- package/dist/plugins/require-condition-resolution.js +2 -2
- package/dist/plugins/require-context.js +2 -2
- package/dist/plugins/typeof-window.js +1 -1
- package/dist/plugins/use-cache-callable.d.ts +0 -2
- package/dist/plugins/use-cache-callable.js +8 -16
- package/dist/plugins/worker-image-imports.js +1 -1
- package/dist/routing/app-route-graph.js +1 -1
- package/dist/routing/app-router.js +1 -1
- package/dist/routing/pages-router.js +1 -1
- package/dist/server/app-action-forwarding.js +1 -1
- package/dist/server/app-browser-error.js +1 -1
- package/dist/server/app-elements-wire.js +2 -2
- package/dist/server/app-middleware.js +1 -1
- package/dist/server/app-optimistic-routing.js +1 -1
- package/dist/server/app-page-dispatch.js +1 -1
- package/dist/server/app-page-element-builder.js +3 -2
- package/dist/server/app-page-probe.js +3 -3
- package/dist/server/app-request-stage-independent-entry.js +2 -2
- package/dist/server/app-route-handler-dispatch.js +1 -1
- package/dist/server/app-route-handler-runtime.js +1 -1
- package/dist/server/app-router-entry.js +2 -2
- package/dist/server/app-rsc-handler.d.ts +1 -1
- package/dist/server/app-rsc-handler.js +4 -4
- package/dist/server/app-rsc-response-stage.js +1 -1
- package/dist/server/app-rsc-route-matching.js +1 -1
- package/dist/server/app-server-action-execution.js +4 -4
- package/dist/server/artifact-compatibility.js +1 -1
- package/dist/server/client-reuse-manifest.js +1 -1
- package/dist/server/dev-lockfile.d.ts +1 -1
- package/dist/server/dev-lockfile.js +4 -1
- package/dist/server/dev-server.d.ts +1 -1
- package/dist/server/dev-server.js +28 -6
- package/dist/server/dev-stack-sourcemap.js +1 -1
- package/dist/server/isr-cache.js +1 -1
- package/dist/server/metadata-route-response.js +8 -0
- package/dist/server/middleware-runtime.js +3 -3
- package/dist/server/pages-data-route.js +1 -1
- package/dist/server/pages-dev-hydration.d.ts +6 -0
- package/dist/server/pages-dev-hydration.js +19 -7
- package/dist/server/pages-page-data.js +2 -2
- package/dist/server/pages-page-handler.js +1 -1
- package/dist/server/pages-page-response.js +1 -1
- package/dist/server/pages-request-pipeline.js +3 -3
- package/dist/server/pages-request-stage-entry.js +3 -3
- package/dist/server/pages-revalidate.js +1 -1
- package/dist/server/prerender-route-params.js +1 -1
- package/dist/server/prod-server.js +7 -7
- package/dist/server/request-pipeline.js +2 -2
- package/dist/server/socket-error-backstop.js +1 -1
- package/dist/shims/cache-callable-runtime.d.ts +38 -0
- package/dist/shims/cache-callable-runtime.js +162 -11
- package/dist/shims/cache-runtime.d.ts +6 -8
- package/dist/shims/cache-runtime.js +82 -22
- package/dist/shims/font-local.js +1 -1
- package/dist/shims/form.js +1 -1
- package/dist/shims/headers.js +2 -2
- package/dist/shims/internal/app-page-props-cache-key.d.ts +29 -0
- package/dist/shims/internal/app-page-props-cache-key.js +53 -1
- package/dist/shims/internal/format-url-object.d.ts +7 -0
- package/dist/shims/internal/format-url-object.js +53 -0
- package/dist/shims/internal/normalize-router-href.d.ts +15 -0
- package/dist/shims/internal/normalize-router-href.js +41 -0
- package/dist/shims/internal/pages-data-target.d.ts +4 -1
- package/dist/shims/internal/pages-data-target.js +28 -35
- package/dist/shims/internal/route-pattern-for-warning.d.ts +2 -2
- package/dist/shims/internal/route-pattern-for-warning.js +3 -3
- package/dist/shims/link.js +31 -92
- package/dist/shims/metadata.js +5 -4
- package/dist/shims/navigation.js +2 -2
- package/dist/shims/router-state.js +1 -1
- package/dist/shims/router.d.ts +8 -7
- package/dist/shims/router.js +312 -148
- package/dist/shims/server.js +3 -3
- package/dist/utils/built-asset-url.js +1 -1
- package/dist/utils/project.d.ts +1 -11
- package/dist/utils/project.js +19 -28
- package/dist/utils/react-version.d.ts +3 -1
- package/dist/utils/react-version.js +19 -1
- package/dist/utils/vite-cli-invocation.d.ts +21 -0
- package/dist/utils/vite-cli-invocation.js +144 -0
- package/package.json +10 -2
package/dist/build/report.js
CHANGED
|
@@ -4,7 +4,7 @@ import fs from "node:fs";
|
|
|
4
4
|
import { parseSync } from "vite";
|
|
5
5
|
//#region src/build/report.ts
|
|
6
6
|
/**
|
|
7
|
-
* Build report — prints a Next.js-style route table after `
|
|
7
|
+
* Build report — prints a Next.js-style route table after `vite build`.
|
|
8
8
|
*
|
|
9
9
|
* Classifies every discovered route as:
|
|
10
10
|
* ○ Static — confirmed static: force-static or revalidate=Infinity
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { VinextRouteRootConfig } from "../config/prerender.js";
|
|
1
2
|
import { ResolvedNextConfig } from "../config/next-config.js";
|
|
2
3
|
import { PrerenderResult, PrerenderRouteResult } from "./prerender.js";
|
|
3
|
-
import { VinextRouteRootConfig } from "../config/prerender.js";
|
|
4
4
|
//#region src/build/run-prerender.d.ts
|
|
5
5
|
type RunPrerenderOptions = {
|
|
6
6
|
/** Project root directory. */
|
|
@@ -45,7 +45,7 @@ type RunPrerenderOptions = {
|
|
|
45
45
|
* to a single `dist/server/vinext-prerender.json`.
|
|
46
46
|
*
|
|
47
47
|
* If a required production bundle does not exist, an error is thrown directing
|
|
48
|
-
* the user to run `
|
|
48
|
+
* the user to run `vite build` first.
|
|
49
49
|
*/
|
|
50
50
|
/**
|
|
51
51
|
* Throw if any route is a `fatal` error (a thrown generateStaticParams /
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import path from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
|
|
2
2
|
import { findDir } from "../utils/project.js";
|
|
3
|
-
import { apiRouter, pagesRouter } from "../routing/pages-router.js";
|
|
4
|
-
import { appRouter } from "../routing/app-router.js";
|
|
5
|
-
import { scanMetadataFiles } from "../server/metadata-routes.js";
|
|
6
3
|
import { PHASE_PRODUCTION_BUILD } from "../shims/constants.js";
|
|
7
4
|
import { loadNextConfig, resolveNextConfig } from "../config/next-config.js";
|
|
5
|
+
import { appRouter } from "../routing/app-router.js";
|
|
6
|
+
import { apiRouter, pagesRouter } from "../routing/pages-router.js";
|
|
7
|
+
import { scanMetadataFiles } from "../server/metadata-routes.js";
|
|
8
8
|
import { readPrerenderSecret } from "./server-manifest.js";
|
|
9
9
|
import { rememberCurrentServerEntryImportMtime, startProdServer } from "../server/prod-server.js";
|
|
10
10
|
import { enterPrerenderPhase } from "./prerender-phase.js";
|
|
@@ -14,7 +14,7 @@ import { resolveBuiltRscEntryPath } from "./server-entry.js";
|
|
|
14
14
|
import fs from "node:fs";
|
|
15
15
|
//#region src/build/run-prerender.ts
|
|
16
16
|
/**
|
|
17
|
-
* Shared prerender runner used by both `
|
|
17
|
+
* Shared prerender runner used by both `vite build` (cli.ts) and
|
|
18
18
|
* `vinext-cloudflare deploy --prerender-all` (deploy.ts).
|
|
19
19
|
*
|
|
20
20
|
* `runPrerender` handles route scanning, dynamic imports, progress reporting,
|
|
@@ -83,7 +83,7 @@ function readBuiltBuildId(serverDir) {
|
|
|
83
83
|
* to a single `dist/server/vinext-prerender.json`.
|
|
84
84
|
*
|
|
85
85
|
* If a required production bundle does not exist, an error is thrown directing
|
|
86
|
-
* the user to run `
|
|
86
|
+
* the user to run `vite build` first.
|
|
87
87
|
*/
|
|
88
88
|
/**
|
|
89
89
|
* Throw if any route is a `fatal` error (a thrown generateStaticParams /
|
package/dist/build/standalone.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { readJsonFile } from "../utils/safe-json-file.js";
|
|
2
1
|
import { resolveVinextPackageRoot } from "../utils/vinext-root.js";
|
|
2
|
+
import { readJsonFile } from "../utils/safe-json-file.js";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import fs from "node:fs";
|
|
5
5
|
import nodePath from "node:path";
|
|
@@ -148,7 +148,7 @@ function emitStandaloneOutput(options) {
|
|
|
148
148
|
const outDir = nodePath.resolve(options.outDir);
|
|
149
149
|
const clientDir = nodePath.join(outDir, "client");
|
|
150
150
|
const serverDir = nodePath.join(outDir, "server");
|
|
151
|
-
if (!fs.existsSync(clientDir) || !fs.existsSync(serverDir)) throw new Error(`No build output found in ${outDir}. Run
|
|
151
|
+
if (!fs.existsSync(clientDir) || !fs.existsSync(serverDir)) throw new Error(`No build output found in ${outDir}. Run vite build first.`);
|
|
152
152
|
const standaloneDir = nodePath.join(outDir, "standalone");
|
|
153
153
|
const standaloneDistDir = nodePath.join(standaloneDir, "dist");
|
|
154
154
|
const standaloneNodeModulesDir = nodePath.join(standaloneDir, "node_modules");
|
package/dist/cli-args.d.ts
CHANGED
|
@@ -2,21 +2,14 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* CLI argument parser for the vinext CLI.
|
|
4
4
|
*
|
|
5
|
-
* Parses
|
|
6
|
-
* Validates that value-taking flags
|
|
7
|
-
*
|
|
5
|
+
* Parses the shared flags used by vinext's non-Vite commands.
|
|
6
|
+
* Validates that value-taking flags have actual values rather than silently
|
|
7
|
+
* consuming the next flag or returning NaN/undefined.
|
|
8
8
|
*/
|
|
9
9
|
type ParsedArgs = {
|
|
10
10
|
port?: number;
|
|
11
11
|
hostname?: string;
|
|
12
|
-
mode?: string;
|
|
13
12
|
help?: boolean;
|
|
14
|
-
verbose?: boolean;
|
|
15
|
-
turbopack?: boolean;
|
|
16
|
-
experimental?: boolean;
|
|
17
|
-
prerenderAll?: boolean;
|
|
18
|
-
prerenderConcurrency?: number;
|
|
19
|
-
precompress?: boolean;
|
|
20
13
|
positionals?: string[];
|
|
21
14
|
};
|
|
22
15
|
/**
|
|
@@ -24,9 +17,8 @@ type ParsedArgs = {
|
|
|
24
17
|
*
|
|
25
18
|
* Handles both `--flag value` and `--flag=value` forms for value-taking flags.
|
|
26
19
|
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* own flag set including `--env`, `--skip-build`, etc.
|
|
20
|
+
* `vinext dev` and `vinext build` bypass this parser and delegate their
|
|
21
|
+
* arguments directly to Vite.
|
|
30
22
|
*/
|
|
31
23
|
export declare function parseArgs(args: string[]): ParsedArgs;
|
|
32
24
|
//#endregion
|
package/dist/cli-args.js
CHANGED
|
@@ -35,20 +35,13 @@ function parsePort(raw, flag) {
|
|
|
35
35
|
if (parsed < 0 || parsed > 65535) throw new Error(`${flag} expects a valid port (0-65535), but got "${raw}".`);
|
|
36
36
|
return parsed;
|
|
37
37
|
}
|
|
38
|
-
function parsePositiveIntegerArg(raw, flag) {
|
|
39
|
-
if (raw === "") throw new Error(`${flag} requires a value, but none was provided.`);
|
|
40
|
-
const parsed = Number(raw);
|
|
41
|
-
if (!Number.isInteger(parsed) || parsed <= 0) throw new Error(`${flag} expects a positive integer, but got "${raw}".`);
|
|
42
|
-
return parsed;
|
|
43
|
-
}
|
|
44
38
|
/**
|
|
45
39
|
* Parse CLI arguments into a structured object.
|
|
46
40
|
*
|
|
47
41
|
* Handles both `--flag value` and `--flag=value` forms for value-taking flags.
|
|
48
42
|
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* own flag set including `--env`, `--skip-build`, etc.
|
|
43
|
+
* `vinext dev` and `vinext build` bypass this parser and delegate their
|
|
44
|
+
* arguments directly to Vite.
|
|
52
45
|
*/
|
|
53
46
|
function parseArgs(args) {
|
|
54
47
|
const result = {};
|
|
@@ -63,27 +56,6 @@ function parseArgs(args) {
|
|
|
63
56
|
case "-h":
|
|
64
57
|
result.help = true;
|
|
65
58
|
break;
|
|
66
|
-
case "--verbose":
|
|
67
|
-
result.verbose = true;
|
|
68
|
-
break;
|
|
69
|
-
case "--turbopack":
|
|
70
|
-
result.turbopack = true;
|
|
71
|
-
break;
|
|
72
|
-
case "--experimental-https":
|
|
73
|
-
result.experimental = true;
|
|
74
|
-
break;
|
|
75
|
-
case "--prerender-all":
|
|
76
|
-
result.prerenderAll = true;
|
|
77
|
-
break;
|
|
78
|
-
case "--prerender-concurrency": {
|
|
79
|
-
const raw = takeValue(arg, args, i);
|
|
80
|
-
i++;
|
|
81
|
-
result.prerenderConcurrency = parsePositiveIntegerArg(raw, arg);
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
case "--precompress":
|
|
85
|
-
result.precompress = true;
|
|
86
|
-
break;
|
|
87
59
|
case "--port":
|
|
88
60
|
case "-p": {
|
|
89
61
|
const raw = takeValue(arg, args, i);
|
|
@@ -96,10 +68,6 @@ function parseArgs(args) {
|
|
|
96
68
|
result.hostname = takeValue(arg, args, i);
|
|
97
69
|
i++;
|
|
98
70
|
break;
|
|
99
|
-
case "--mode":
|
|
100
|
-
result.mode = takeValue(arg, args, i);
|
|
101
|
-
i++;
|
|
102
|
-
break;
|
|
103
71
|
default: {
|
|
104
72
|
const eqRaw = tryEqualsForm(arg, "port");
|
|
105
73
|
if (eqRaw !== null) {
|
|
@@ -112,17 +80,6 @@ function parseArgs(args) {
|
|
|
112
80
|
result.hostname = hostRaw;
|
|
113
81
|
break;
|
|
114
82
|
}
|
|
115
|
-
const modeRaw = tryEqualsForm(arg, "mode");
|
|
116
|
-
if (modeRaw !== null) {
|
|
117
|
-
if (modeRaw === "") throw new Error(`--mode requires a value, but none was provided.`);
|
|
118
|
-
result.mode = modeRaw;
|
|
119
|
-
break;
|
|
120
|
-
}
|
|
121
|
-
const prerenderConcurrencyRaw = tryEqualsForm(arg, "prerender-concurrency");
|
|
122
|
-
if (prerenderConcurrencyRaw !== null) {
|
|
123
|
-
result.prerenderConcurrency = parsePositiveIntegerArg(prerenderConcurrencyRaw, "--prerender-concurrency");
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
83
|
if (!FLAG_PATTERN.test(arg)) addPositional(arg);
|
|
127
84
|
break;
|
|
128
85
|
}
|
package/dist/cli-dev-config.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import { Plugin, ServerOptions } from "vite";
|
|
1
|
+
import { Plugin, ResolvedConfig, ServerOptions, UserConfig } from "vite";
|
|
2
2
|
//#region src/cli-dev-config.d.ts
|
|
3
|
+
export declare const VINEXT_DEV_RESTART_CONFIG = "__vinextDevRestart";
|
|
4
|
+
export declare const VINEXT_DEV_CLI_LIFECYCLE = "__vinextDevCliLifecycle";
|
|
5
|
+
export declare function reserveViteCliDevInvocation(): boolean;
|
|
6
|
+
export declare function claimViteCliDevInvocation(root: string, isRestart?: boolean, isReserved?: boolean): boolean;
|
|
3
7
|
export type DevServerCliOptions = {
|
|
4
8
|
port?: number;
|
|
5
9
|
hostname?: string;
|
|
6
10
|
};
|
|
7
11
|
export declare function applyDevServerDefaults(server: ServerOptions, options: DevServerCliOptions): void;
|
|
8
|
-
export declare function
|
|
12
|
+
export declare function createDevServerLifecyclePlugin(options: DevServerCliOptions, isEnabled: (config: UserConfig | ResolvedConfig) => boolean): Plugin;
|
|
9
13
|
export declare function normalizeDevServerHostname(host: string | boolean | undefined): string;
|
|
10
14
|
//#endregion
|
package/dist/cli-dev-config.js
CHANGED
|
@@ -1,17 +1,57 @@
|
|
|
1
|
+
import { toSlash } from "./deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
|
|
2
|
+
import { formatAlreadyRunningError, tryAcquireLockfile } from "./server/dev-lockfile.js";
|
|
3
|
+
import { isViteCliInvocation } from "./utils/vite-cli-invocation.js";
|
|
4
|
+
import fs from "node:fs";
|
|
1
5
|
//#region src/cli-dev-config.ts
|
|
6
|
+
const activeDevServerLocks = /* @__PURE__ */ new Map();
|
|
7
|
+
let devInvocationRoot;
|
|
8
|
+
let devInvocationReserved = false;
|
|
9
|
+
const VINEXT_DEV_RESTART_CONFIG = "__vinextDevRestart";
|
|
10
|
+
const VINEXT_DEV_CLI_LIFECYCLE = "__vinextDevCliLifecycle";
|
|
11
|
+
function normalizeDevLifecycleRoot(root) {
|
|
12
|
+
try {
|
|
13
|
+
return toSlash(fs.realpathSync.native(root));
|
|
14
|
+
} catch {
|
|
15
|
+
return root;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function reserveViteCliDevInvocation() {
|
|
19
|
+
if (!isViteCliInvocation("dev") || devInvocationReserved) return false;
|
|
20
|
+
devInvocationReserved = true;
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
function claimViteCliDevInvocation(root, isRestart = false, isReserved = false) {
|
|
24
|
+
root = normalizeDevLifecycleRoot(root);
|
|
25
|
+
if (!isViteCliInvocation("dev")) return false;
|
|
26
|
+
if (!isRestart && (!isReserved || devInvocationRoot !== void 0)) return false;
|
|
27
|
+
devInvocationRoot = root;
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
2
30
|
function applyDevServerDefaults(server, options) {
|
|
3
31
|
server.port = options.port ?? server.port ?? 3e3;
|
|
4
32
|
server.host = options.hostname ?? server.host ?? "localhost";
|
|
5
33
|
}
|
|
6
|
-
function
|
|
34
|
+
function createDevServerLifecyclePlugin(options, isEnabled) {
|
|
7
35
|
return {
|
|
8
|
-
name: "vinext:dev-server-
|
|
36
|
+
name: "vinext:dev-server-lifecycle",
|
|
9
37
|
enforce: "post",
|
|
10
38
|
config: {
|
|
11
39
|
order: "post",
|
|
12
40
|
handler(config) {
|
|
41
|
+
if (!isEnabled(config) || config.server?.middlewareMode) return;
|
|
13
42
|
applyDevServerDefaults(config.server ??= {}, options);
|
|
14
43
|
}
|
|
44
|
+
},
|
|
45
|
+
configureServer: {
|
|
46
|
+
order: "post",
|
|
47
|
+
handler(server) {
|
|
48
|
+
if (!isEnabled(server.config)) return;
|
|
49
|
+
if (!server.config.server.middlewareMode) {
|
|
50
|
+
if (options.port !== void 0) server.config.server.port = options.port;
|
|
51
|
+
if (options.hostname !== void 0) server.config.server.host = options.hostname;
|
|
52
|
+
}
|
|
53
|
+
configureDevServerLifecycle(server);
|
|
54
|
+
}
|
|
15
55
|
}
|
|
16
56
|
};
|
|
17
57
|
}
|
|
@@ -19,5 +59,122 @@ function normalizeDevServerHostname(host) {
|
|
|
19
59
|
if (typeof host === "string") return host;
|
|
20
60
|
return host === true ? "0.0.0.0" : "localhost";
|
|
21
61
|
}
|
|
62
|
+
function configureDevServerLifecycle(server) {
|
|
63
|
+
const root = normalizeDevLifecycleRoot(server.config.root);
|
|
64
|
+
let activeLock;
|
|
65
|
+
const releaseLock = () => {
|
|
66
|
+
if (!activeLock) return;
|
|
67
|
+
const lock = activeLock;
|
|
68
|
+
activeLock = void 0;
|
|
69
|
+
lock.servers--;
|
|
70
|
+
if (lock.servers > 0 || lock.restarting) return;
|
|
71
|
+
lock.lockfile.release();
|
|
72
|
+
if (activeDevServerLocks.get(root) === lock) activeDevServerLocks.delete(root);
|
|
73
|
+
};
|
|
74
|
+
const releaseLifecycle = () => {
|
|
75
|
+
releaseLock();
|
|
76
|
+
if (!activeDevServerLocks.get(root)?.restarting && devInvocationRoot === root) {
|
|
77
|
+
devInvocationRoot = void 0;
|
|
78
|
+
devInvocationReserved = false;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const closeServer = server.close.bind(server);
|
|
82
|
+
server.close = async () => {
|
|
83
|
+
try {
|
|
84
|
+
await closeServer();
|
|
85
|
+
} finally {
|
|
86
|
+
releaseLifecycle();
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const restartServer = server.restart.bind(server);
|
|
90
|
+
server.restart = async (forceOptimize) => {
|
|
91
|
+
const restartingLock = activeDevServerLocks.get(root);
|
|
92
|
+
if (restartingLock) restartingLock.restarting = true;
|
|
93
|
+
const inlineConfig = server.config.inlineConfig;
|
|
94
|
+
inlineConfig[VINEXT_DEV_RESTART_CONFIG] = true;
|
|
95
|
+
try {
|
|
96
|
+
await restartServer(forceOptimize);
|
|
97
|
+
} finally {
|
|
98
|
+
delete inlineConfig[VINEXT_DEV_RESTART_CONFIG];
|
|
99
|
+
delete server.config.inlineConfig[VINEXT_DEV_RESTART_CONFIG];
|
|
100
|
+
if (server.config["__vinextDevCliLifecycle"]) devInvocationRoot = normalizeDevLifecycleRoot(server.config.root);
|
|
101
|
+
else {
|
|
102
|
+
devInvocationRoot = void 0;
|
|
103
|
+
devInvocationReserved = false;
|
|
104
|
+
}
|
|
105
|
+
if (restartingLock) {
|
|
106
|
+
restartingLock.restarting = false;
|
|
107
|
+
if (restartingLock.servers === 0) {
|
|
108
|
+
restartingLock.lockfile.release();
|
|
109
|
+
if (activeDevServerLocks.get(root) === restartingLock) activeDevServerLocks.delete(root);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const listenServer = server.listen.bind(server);
|
|
115
|
+
server.listen = async (port, isRestart) => {
|
|
116
|
+
if (server.config.server.middlewareMode || process.env.VINEXT_NO_DEV_LOCK === "1") return listenServer(port, isRestart);
|
|
117
|
+
const configuredPort = port ?? server.config.server.port ?? 3e3;
|
|
118
|
+
const hostname = normalizeDevServerHostname(server.config.server.host);
|
|
119
|
+
const displayHostname = hostname === "0.0.0.0" ? "localhost" : hostname;
|
|
120
|
+
const restartingLock = activeDevServerLocks.get(root);
|
|
121
|
+
if (restartingLock?.restarting) activeLock = restartingLock;
|
|
122
|
+
else {
|
|
123
|
+
const startedAt = Date.now();
|
|
124
|
+
const acquired = tryAcquireLockfile({
|
|
125
|
+
root,
|
|
126
|
+
info: {
|
|
127
|
+
pid: process.pid,
|
|
128
|
+
port: configuredPort,
|
|
129
|
+
hostname,
|
|
130
|
+
appUrl: `http://${displayHostname}:${configuredPort}`,
|
|
131
|
+
startedAt,
|
|
132
|
+
cwd: root
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
if (!acquired.ok) throw new Error(formatAlreadyRunningError({
|
|
136
|
+
existing: acquired.existing,
|
|
137
|
+
cwd: root,
|
|
138
|
+
lockfilePath: acquired.lockfilePath
|
|
139
|
+
}));
|
|
140
|
+
activeLock = {
|
|
141
|
+
lockfile: acquired.lockfile,
|
|
142
|
+
restarting: false,
|
|
143
|
+
servers: 0,
|
|
144
|
+
startedAt
|
|
145
|
+
};
|
|
146
|
+
activeDevServerLocks.set(root, activeLock);
|
|
147
|
+
}
|
|
148
|
+
activeLock.servers++;
|
|
149
|
+
try {
|
|
150
|
+
return await listenServer(port, isRestart);
|
|
151
|
+
} catch (error) {
|
|
152
|
+
releaseLock();
|
|
153
|
+
throw error;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
server.httpServer?.on("listening", () => {
|
|
157
|
+
if (!activeLock) return;
|
|
158
|
+
const port = server.config.server.port ?? 3e3;
|
|
159
|
+
const hostname = normalizeDevServerHostname(server.config.server.host);
|
|
160
|
+
const displayHostname = hostname === "0.0.0.0" ? "localhost" : hostname;
|
|
161
|
+
const lock = activeLock;
|
|
162
|
+
setImmediate(() => {
|
|
163
|
+
if (activeLock !== lock) return;
|
|
164
|
+
const address = server.httpServer?.address();
|
|
165
|
+
const actualPort = typeof address === "object" && address ? address.port : port;
|
|
166
|
+
const appUrl = server.resolvedUrls?.local[0]?.replace(/\/$/, "") ?? `http://${displayHostname}:${actualPort}`;
|
|
167
|
+
lock.lockfile.update({
|
|
168
|
+
pid: process.pid,
|
|
169
|
+
port: actualPort,
|
|
170
|
+
hostname,
|
|
171
|
+
appUrl,
|
|
172
|
+
startedAt: lock.startedAt,
|
|
173
|
+
cwd: root
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
server.httpServer?.on("close", releaseLock);
|
|
178
|
+
}
|
|
22
179
|
//#endregion
|
|
23
|
-
export { applyDevServerDefaults,
|
|
180
|
+
export { VINEXT_DEV_CLI_LIFECYCLE, VINEXT_DEV_RESTART_CONFIG, applyDevServerDefaults, claimViteCliDevInvocation, createDevServerLifecyclePlugin, normalizeDevServerHostname, reserveViteCliDevInvocation };
|