vinext 1.2.1 → 1.3.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/README.md +12 -9
- package/dist/build/client-build-config.d.ts +64 -3
- package/dist/build/client-build-config.js +131 -4
- package/dist/build/client-reference-groups.d.ts +163 -0
- package/dist/build/client-reference-groups.js +534 -0
- package/dist/build/module-dependency-cache.d.ts +31 -0
- package/dist/build/module-dependency-cache.js +51 -1
- package/dist/build/next-client-runtime-manifests.d.ts +10 -1
- package/dist/build/next-client-runtime-manifests.js +19 -4
- package/dist/build/nitro-public-files.d.ts +24 -0
- package/dist/build/nitro-public-files.js +60 -0
- package/dist/build/pages-client-assets-module.js +1 -1
- package/dist/build/prerender-paths.js +5 -2
- package/dist/build/server-actions-encryption-key.d.ts +23 -0
- package/dist/build/server-actions-encryption-key.js +101 -0
- package/dist/build/ssr-manifest.d.ts +3 -0
- package/dist/build/ssr-manifest.js +10 -1
- package/dist/client/client-rewrite-params.d.ts +9 -0
- package/dist/client/client-rewrite-params.js +20 -0
- package/dist/client/dev-error-overlay.js +2 -1
- package/dist/client/navigation-runtime.d.ts +25 -2
- package/dist/client/navigation-runtime.js +42 -11
- package/dist/client/vinext-next-data.d.ts +0 -1
- package/dist/config/config-matchers.d.ts +15 -40
- package/dist/config/config-matchers.js +183 -255
- package/dist/config/config-source.d.ts +34 -0
- package/dist/config/config-source.js +141 -0
- package/dist/config/header-params.d.ts +29 -0
- package/dist/config/header-params.js +106 -0
- package/dist/config/next-config.d.ts +7 -5
- package/dist/config/next-config.js +120 -7
- package/dist/entries/app-browser-entry.d.ts +14 -1
- package/dist/entries/app-browser-entry.js +26 -36
- package/dist/entries/app-rsc-entry.d.ts +2 -0
- package/dist/entries/app-rsc-entry.js +92 -57
- package/dist/entries/app-rsc-manifest.d.ts +10 -0
- package/dist/entries/app-rsc-manifest.js +20 -1
- package/dist/entries/app-ssr-entry.d.ts +4 -1
- package/dist/entries/app-ssr-entry.js +9 -2
- package/dist/entries/pages-client-entry.d.ts +1 -0
- package/dist/entries/pages-client-entry.js +6 -6
- package/dist/entries/pages-server-entry.js +17 -14
- package/dist/index.d.ts +11 -0
- package/dist/index.js +239 -83
- package/dist/init.js +17 -0
- package/dist/plugins/optimize-imports.d.ts +25 -2
- package/dist/plugins/optimize-imports.js +106 -20
- package/dist/plugins/rsc-client-reference-loaders.d.ts +45 -1
- package/dist/plugins/rsc-client-reference-loaders.js +336 -18
- package/dist/plugins/use-cache-callable.d.ts +5 -0
- package/dist/plugins/use-cache-callable.js +30 -8
- package/dist/plugins/worker-image-imports.d.ts +1 -0
- package/dist/plugins/worker-image-imports.js +1 -1
- package/dist/routing/app-route-graph.d.ts +1 -1
- package/dist/routing/browser-route-manifest.d.ts +43 -0
- package/dist/routing/browser-route-manifest.js +195 -0
- package/dist/routing/hashed-route-patterns.d.ts +4 -0
- package/dist/routing/hashed-route-patterns.js +22 -0
- package/dist/routing/optimistic-route-trie.d.ts +27 -0
- package/dist/routing/optimistic-route-trie.js +102 -0
- package/dist/routing/route-validation.d.ts +6 -1
- package/dist/routing/route-validation.js +26 -10
- package/dist/server/app-action-forwarding.d.ts +8 -0
- package/dist/server/app-action-forwarding.js +15 -1
- package/dist/server/app-browser-entry.js +147 -60
- package/dist/server/app-browser-error.d.ts +3 -1
- package/dist/server/app-browser-error.js +7 -2
- package/dist/server/app-browser-interception-context.d.ts +2 -2
- package/dist/server/app-browser-mpa-navigation.d.ts +1 -0
- package/dist/server/app-browser-mpa-navigation.js +6 -5
- package/dist/server/app-browser-navigation-controller.d.ts +17 -6
- package/dist/server/app-browser-navigation-controller.js +88 -26
- package/dist/server/app-browser-state.d.ts +2 -2
- package/dist/server/app-browser-visible-commit.d.ts +4 -4
- package/dist/server/app-client-reference-preloader.d.ts +23 -0
- package/dist/server/app-client-reference-preloader.js +30 -7
- package/dist/server/app-fallback-renderer.js +2 -1
- package/dist/server/app-middleware.d.ts +6 -0
- package/dist/server/app-middleware.js +8 -10
- package/dist/server/app-optimistic-routing.d.ts +8 -10
- package/dist/server/app-optimistic-routing.js +4 -95
- package/dist/server/app-page-boundary-render.js +8 -1
- package/dist/server/app-page-cache-render.js +1 -0
- package/dist/server/app-page-dispatch.js +2 -0
- package/dist/server/app-page-render.js +3 -1
- package/dist/server/app-page-rsc-render-status.d.ts +1 -0
- package/dist/server/app-page-rsc-render-status.js +1 -0
- package/dist/server/app-page-search-params-observation.d.ts +1 -4
- package/dist/server/app-page-search-params-observation.js +8 -10
- package/dist/server/app-page-stream.d.ts +7 -0
- package/dist/server/app-page-stream.js +1 -0
- package/dist/server/app-pages-bridge.d.ts +2 -1
- package/dist/server/app-pages-bridge.js +11 -7
- package/dist/server/app-prerender-static-params.js +3 -2
- package/dist/server/app-render-dependency.js +42 -2
- package/dist/server/app-request-stage-independent-entry.js +2 -2
- package/dist/server/app-response-stage-entry.js +3 -3
- package/dist/server/app-route-handler-dispatch.js +3 -1
- package/dist/server/app-route-handler-execution.d.ts +2 -0
- package/dist/server/app-route-handler-execution.js +9 -2
- package/dist/server/app-route-handler-middleware-context.d.ts +2 -1
- package/dist/server/app-route-handler-middleware-context.js +3 -3
- package/dist/server/app-route-handler-response.d.ts +2 -1
- package/dist/server/app-route-handler-response.js +2 -2
- package/dist/server/app-route-handler-runtime.d.ts +2 -0
- package/dist/server/app-route-handler-runtime.js +20 -3
- package/dist/server/app-route-module-loader.js +7 -6
- package/dist/server/app-route-tree.d.ts +20 -0
- package/dist/server/app-route-tree.js +18 -0
- package/dist/server/app-router-entry.js +2 -2
- package/dist/server/app-rsc-combined-handler.js +8 -1
- package/dist/server/app-rsc-errors.d.ts +7 -0
- package/dist/server/app-rsc-errors.js +9 -2
- package/dist/server/app-rsc-handler.d.ts +4 -1
- package/dist/server/app-rsc-handler.js +146 -130
- package/dist/server/app-rsc-response-finalizer.d.ts +5 -0
- package/dist/server/app-rsc-response-finalizer.js +4 -1
- package/dist/server/app-rsc-response-stage.js +3 -1
- package/dist/server/app-rsc-route-matching.d.ts +1 -0
- package/dist/server/app-rsc-route-matching.js +1 -1
- package/dist/server/app-server-action-execution.d.ts +23 -6
- package/dist/server/app-server-action-execution.js +50 -56
- package/dist/server/app-ssr-entry.d.ts +6 -0
- package/dist/server/app-ssr-entry.js +16 -7
- package/dist/server/app-ssr-stream.d.ts +7 -0
- package/dist/server/app-ssr-stream.js +13 -1
- package/dist/server/config-headers.js +12 -3
- package/dist/server/isolate-shared-promise.d.ts +10 -0
- package/dist/server/isolate-shared-promise.js +33 -0
- package/dist/server/isr-cache.js +3 -2
- package/dist/server/middleware-matcher-pattern.d.ts +0 -1
- package/dist/server/middleware-matcher-pattern.js +11 -140
- package/dist/server/middleware-matcher.js +5 -6
- package/dist/server/middleware-response-headers.d.ts +31 -0
- package/dist/server/middleware-response-headers.js +57 -1
- package/dist/server/middleware-runtime.js +26 -13
- package/dist/server/navigation-planner.d.ts +2 -2
- package/dist/server/nitro-public-files-plugin.d.ts +38 -0
- package/dist/server/nitro-public-files-plugin.js +106 -0
- package/dist/server/nitro-public-files.d.ts +21 -0
- package/dist/server/nitro-public-files.js +39 -0
- package/dist/server/pages-asset-tags.d.ts +5 -0
- package/dist/server/pages-asset-tags.js +9 -2
- package/dist/server/pages-client-assets.d.ts +4 -1
- package/dist/server/pages-i18n.d.ts +18 -0
- package/dist/server/pages-i18n.js +18 -2
- package/dist/server/pages-node-compat.d.ts +5 -3
- package/dist/server/pages-node-compat.js +35 -16
- package/dist/server/pages-request-pipeline.d.ts +6 -1
- package/dist/server/pages-request-pipeline.js +31 -35
- package/dist/server/pages-request-stage-entry.js +16 -6
- package/dist/server/pages-response-stage-entry.js +1 -1
- package/dist/server/pages-revalidate.js +1 -0
- package/dist/server/pages-router-entry.js +1 -1
- package/dist/server/prod-server.d.ts +2 -2
- package/dist/server/prod-server.js +71 -33
- package/dist/server/proxy-trust.d.ts +6 -0
- package/dist/server/proxy-trust.js +12 -6
- package/dist/server/request-pipeline.d.ts +5 -0
- package/dist/server/request-pipeline.js +12 -1
- package/dist/server/server-reference-loader.js +10 -1
- package/dist/server/static-file-cache.js +15 -3
- package/dist/server/worker-utils.js +1 -1
- package/dist/shims/cache-handler.js +3 -2
- package/dist/shims/cache-request-state.d.ts +40 -3
- package/dist/shims/cache-request-state.js +70 -5
- package/dist/shims/cache-runtime.js +47 -19
- package/dist/shims/cache.d.ts +2 -2
- package/dist/shims/cache.js +17 -8
- package/dist/shims/cdn-purge-routes.d.ts +24 -0
- package/dist/shims/cdn-purge-routes.js +77 -0
- package/dist/shims/dynamic.js +17 -4
- package/dist/shims/form.js +8 -3
- package/dist/shims/image-props.d.ts +93 -0
- package/dist/shims/image-props.js +323 -0
- package/dist/shims/image.d.ts +4 -18
- package/dist/shims/image.js +4 -319
- package/dist/shims/internal/headers-state.d.ts +7 -0
- package/dist/shims/internal/headers-state.js +14 -2
- package/dist/shims/internal/hybrid-client-route-owner-direct.d.ts +4 -1
- package/dist/shims/internal/hybrid-client-route-owner-direct.js +31 -14
- package/dist/shims/internal/hybrid-client-route-owner.js +8 -8
- package/dist/shims/link.js +5 -3
- package/dist/shims/navigation.d.ts +1 -1
- package/dist/shims/navigation.js +17 -5
- package/dist/shims/og.js +35 -10
- package/dist/shims/request-context.d.ts +13 -0
- package/dist/shims/router.js +19 -40
- package/dist/shims/server.d.ts +31 -4
- package/dist/shims/server.js +58 -10
- package/dist/shims/thenable-params.d.ts +6 -1
- package/dist/shims/thenable-params.js +11 -2
- package/dist/shims/unified-request-context.d.ts +5 -0
- package/dist/shims/unified-request-context.js +2 -0
- package/dist/utils/asset-prefix.d.ts +7 -0
- package/dist/utils/asset-prefix.js +10 -1
- package/dist/utils/client-build-manifest.js +12 -5
- package/dist/utils/client-runtime-metadata.d.ts +1 -0
- package/dist/utils/client-runtime-metadata.js +15 -2
- package/dist/utils/lazy-chunks.d.ts +4 -0
- package/dist/utils/manifest-paths.d.ts +14 -0
- package/dist/utils/manifest-paths.js +22 -1
- package/dist/utils/path-to-regexp.d.ts +21 -0
- package/dist/{server/middleware-path-to-regexp.js → utils/path-to-regexp.js} +14 -11
- package/dist/utils/plugin-react-version.d.ts +15 -0
- package/dist/utils/plugin-react-version.js +64 -0
- package/dist/utils/public-routes.d.ts +2 -0
- package/dist/utils/public-routes.js +18 -7
- package/package.json +1 -1
- package/dist/server/middleware-path-to-regexp.d.ts +0 -13
- package/dist/utils/regex-safety.d.ts +0 -17
- package/dist/utils/regex-safety.js +0 -789
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import path from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
|
|
2
2
|
import { isAbsoluteAssetPrefix, resolveAssetsDir } from "./asset-prefix.js";
|
|
3
|
-
import { manifestFileWithAssetPrefix, manifestFileWithBase } from "./manifest-paths.js";
|
|
3
|
+
import { isSharedClientChunkName, manifestFileWithAssetPrefix, manifestFileWithBase } from "./manifest-paths.js";
|
|
4
4
|
import { findClientEntryFileFromVinextManifest, findPagesClientEntryFileFromVinextManifest, readClientEntryManifest } from "./client-entry-manifest.js";
|
|
5
5
|
import { findClientEntryFile, findPagesClientEntryFile, readClientBuildManifest } from "./client-build-manifest.js";
|
|
6
6
|
import { computeDynamicImportPreloads, computeLazyChunks, dynamicImportPreloadsWithBase } from "./lazy-chunks.js";
|
|
7
7
|
//#region src/utils/client-runtime-metadata.ts
|
|
8
|
+
/**
|
|
9
|
+
* Shared Pages Router chunk files, keyed on Rolldown chunk names rather than
|
|
10
|
+
* emitted file names so user-configured `chunkFileNames` (e.g. hash-only
|
|
11
|
+
* patterns) keep their modulepreload/script tags.
|
|
12
|
+
*/
|
|
13
|
+
function collectSharedChunkFiles(buildManifest, applyBase) {
|
|
14
|
+
const files = /* @__PURE__ */ new Set();
|
|
15
|
+
for (const chunk of Object.values(buildManifest)) if (chunk.file.endsWith(".js") && isSharedClientChunkName(chunk.name)) files.add(applyBase(chunk.file));
|
|
16
|
+
return files.size > 0 ? [...files] : void 0;
|
|
17
|
+
}
|
|
8
18
|
function collectCssGraph(buildManifest, applyBase) {
|
|
9
19
|
const cssGraph = {};
|
|
10
20
|
for (const [key, chunk] of Object.entries(buildManifest)) {
|
|
@@ -74,7 +84,10 @@ function computeClientRuntimeMetadata(opts) {
|
|
|
74
84
|
if (entry) metadata.clientEntryFile = entry;
|
|
75
85
|
}
|
|
76
86
|
if (!buildManifest) return metadata;
|
|
77
|
-
if (opts.includeClientEntry)
|
|
87
|
+
if (opts.includeClientEntry) {
|
|
88
|
+
metadata.cssGraph = collectCssGraph(buildManifest, (file) => manifestFileWithBase(file, opts.assetBase));
|
|
89
|
+
metadata.sharedChunks = collectSharedChunkFiles(buildManifest, (file) => manifestFileWithBase(file, opts.assetBase));
|
|
90
|
+
}
|
|
78
91
|
metadata.appBootstrapPreinitModules = collectAppBootstrapPreinitModules(buildManifest, clientEntryManifest?.appBrowserEntry, (file) => {
|
|
79
92
|
const url = manifestFileWithAssetPrefix(file, opts.assetBase, opts.assetPrefix);
|
|
80
93
|
return isAbsoluteAssetPrefix(opts.assetPrefix) ? url : "/" + url;
|
|
@@ -4,6 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export type BuildManifestChunk = {
|
|
6
6
|
file: string;
|
|
7
|
+
/** Source module id (or virtual id) of an entry chunk. */
|
|
8
|
+
src?: string;
|
|
9
|
+
/** Rolldown chunk name, independent of the configured output file name. */
|
|
10
|
+
name?: string;
|
|
7
11
|
isEntry?: boolean;
|
|
8
12
|
isDynamicEntry?: boolean;
|
|
9
13
|
imports?: string[];
|
|
@@ -26,4 +26,18 @@ export declare function assetServingUrlFromBaseAnchored(value: string, basePath:
|
|
|
26
26
|
* `<base>/<base>/` prefix is collapsed; a single prefix is left untouched.
|
|
27
27
|
*/
|
|
28
28
|
export declare function collapseDuplicateBase(file: string, base: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* Whether a Rolldown chunk belongs to the shared Pages Router runtime, judged
|
|
31
|
+
* by its exact chunk name rather than its emitted file name so user-configured
|
|
32
|
+
* or hash-only `chunkFileNames` keep their modulepreload/script tags.
|
|
33
|
+
*/
|
|
34
|
+
export declare function isSharedClientChunkName(name: string | undefined): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Reserved `ssr-manifest.json` key listing the shared runtime chunk files.
|
|
37
|
+
* Consumers that pass the on-disk manifest straight to `renderPage()` (the
|
|
38
|
+
* legacy two-call Pages build) have no registered build metadata, and file
|
|
39
|
+
* names alone can't identify these chunks. The `\0` prefix keeps it from
|
|
40
|
+
* matching any module id.
|
|
41
|
+
*/
|
|
42
|
+
export declare const SSR_MANIFEST_SHARED_CHUNKS_KEY = "\0vinext:shared-chunks";
|
|
29
43
|
//#endregion
|
|
@@ -62,5 +62,26 @@ function collapseDuplicateBase(file, base) {
|
|
|
62
62
|
const doubledPrefix = `${normalizedBase}/${normalizedBase}/`;
|
|
63
63
|
return normalizedFile.startsWith(doubledPrefix) ? normalizedFile.slice(normalizedBase.length + 1) : normalizedFile;
|
|
64
64
|
}
|
|
65
|
+
const SHARED_CHUNK_NAMES = /* @__PURE__ */ new Set([
|
|
66
|
+
"framework",
|
|
67
|
+
"vinext",
|
|
68
|
+
"vinext-client-entry"
|
|
69
|
+
]);
|
|
70
|
+
/**
|
|
71
|
+
* Whether a Rolldown chunk belongs to the shared Pages Router runtime, judged
|
|
72
|
+
* by its exact chunk name rather than its emitted file name so user-configured
|
|
73
|
+
* or hash-only `chunkFileNames` keep their modulepreload/script tags.
|
|
74
|
+
*/
|
|
75
|
+
function isSharedClientChunkName(name) {
|
|
76
|
+
return name !== void 0 && SHARED_CHUNK_NAMES.has(name);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Reserved `ssr-manifest.json` key listing the shared runtime chunk files.
|
|
80
|
+
* Consumers that pass the on-disk manifest straight to `renderPage()` (the
|
|
81
|
+
* legacy two-call Pages build) have no registered build metadata, and file
|
|
82
|
+
* names alone can't identify these chunks. The `\0` prefix keeps it from
|
|
83
|
+
* matching any module id.
|
|
84
|
+
*/
|
|
85
|
+
const SSR_MANIFEST_SHARED_CHUNKS_KEY = "\0vinext:shared-chunks";
|
|
65
86
|
//#endregion
|
|
66
|
-
export { assetServingUrlFromBaseAnchored, collapseDuplicateBase, manifestFileWithAssetPrefix, manifestFileWithBase };
|
|
87
|
+
export { SSR_MANIFEST_SHARED_CHUNKS_KEY, assetServingUrlFromBaseAnchored, collapseDuplicateBase, isSharedClientChunkName, manifestFileWithAssetPrefix, manifestFileWithBase };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/utils/path-to-regexp.d.ts
|
|
2
|
+
export type PathToken = string | PathKey;
|
|
3
|
+
export type PathKey = {
|
|
4
|
+
name: string | number;
|
|
5
|
+
prefix: string;
|
|
6
|
+
suffix: string;
|
|
7
|
+
pattern: string;
|
|
8
|
+
modifier: string;
|
|
9
|
+
};
|
|
10
|
+
export type ParsePathPatternOptions = {
|
|
11
|
+
/** Characters a default param cannot contain. path-to-regexp defaults to `/#?`. */
|
|
12
|
+
delimiter?: string;
|
|
13
|
+
};
|
|
14
|
+
export declare function parsePathPattern(value: string, options?: ParsePathPatternOptions): PathToken[];
|
|
15
|
+
export declare function normalizePathTokens(tokens: PathToken[]): PathToken[];
|
|
16
|
+
/**
|
|
17
|
+
* path-to-regexp's `tokensToRegexp` with `strict: true`, without the closing
|
|
18
|
+
* `$`. Callers append the ending their Next.js matcher uses.
|
|
19
|
+
*/
|
|
20
|
+
export declare function pathTokensToRegExpSource(tokens: PathToken[]): string;
|
|
21
|
+
//#endregion
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region src/
|
|
1
|
+
//#region src/utils/path-to-regexp.ts
|
|
2
2
|
function lexer(value) {
|
|
3
3
|
const tokens = [];
|
|
4
4
|
let index = 0;
|
|
@@ -101,11 +101,12 @@ function lexer(value) {
|
|
|
101
101
|
});
|
|
102
102
|
return tokens;
|
|
103
103
|
}
|
|
104
|
-
function
|
|
104
|
+
function parsePathPattern(value, options = {}) {
|
|
105
105
|
const tokens = lexer(value);
|
|
106
106
|
const result = [];
|
|
107
107
|
const prefixes = "./";
|
|
108
|
-
const delimiter = "/#?";
|
|
108
|
+
const delimiter = options.delimiter ?? "/#?";
|
|
109
|
+
const delimiterClass = `[^${escapeRegex(delimiter)}]`;
|
|
109
110
|
let key = 0;
|
|
110
111
|
let index = 0;
|
|
111
112
|
let path = "";
|
|
@@ -135,8 +136,8 @@ function parseMiddlewarePath(value) {
|
|
|
135
136
|
const name = typeof previous === "string" ? previous : previous.name;
|
|
136
137
|
throw new TypeError(`Must have text between two parameters, missing text after "${name}"`);
|
|
137
138
|
}
|
|
138
|
-
if (!previousText || containsDelimiter(previousText)) return
|
|
139
|
-
return `(?:(?!${escapeRegex(previousText)})
|
|
139
|
+
if (!previousText || containsDelimiter(previousText)) return `${delimiterClass}+?`;
|
|
140
|
+
return `(?:(?!${escapeRegex(previousText)})${delimiterClass})+?`;
|
|
140
141
|
};
|
|
141
142
|
while (index < tokens.length) {
|
|
142
143
|
const character = tryConsume("CHAR");
|
|
@@ -192,7 +193,7 @@ function parseMiddlewarePath(value) {
|
|
|
192
193
|
function escapeRegex(value) {
|
|
193
194
|
return value.replace(/([.+*?=^!:${}()[\]|/\\])/g, "\\$1");
|
|
194
195
|
}
|
|
195
|
-
function
|
|
196
|
+
function normalizePathTokens(tokens) {
|
|
196
197
|
return tokens.map((token) => {
|
|
197
198
|
if (typeof token === "object" && (token.modifier === "*" || token.modifier === "+") && token.prefix === "" && token.suffix === "") return {
|
|
198
199
|
...token,
|
|
@@ -201,8 +202,11 @@ function normalizeMiddlewarePathTokens(tokens) {
|
|
|
201
202
|
return token;
|
|
202
203
|
});
|
|
203
204
|
}
|
|
204
|
-
|
|
205
|
-
|
|
205
|
+
/**
|
|
206
|
+
* path-to-regexp's `tokensToRegexp` with `strict: true`, without the closing
|
|
207
|
+
* `$`. Callers append the ending their Next.js matcher uses.
|
|
208
|
+
*/
|
|
209
|
+
function pathTokensToRegExpSource(tokens) {
|
|
206
210
|
let route = "^";
|
|
207
211
|
for (const token of tokens) {
|
|
208
212
|
if (typeof token === "string") {
|
|
@@ -223,8 +227,7 @@ function middlewarePathTokensToRegExp(tokens) {
|
|
|
223
227
|
}
|
|
224
228
|
} else route += `(?:${prefix}${suffix})${token.modifier}`;
|
|
225
229
|
}
|
|
226
|
-
route
|
|
227
|
-
return new RegExp(route);
|
|
230
|
+
return route;
|
|
228
231
|
}
|
|
229
232
|
//#endregion
|
|
230
|
-
export {
|
|
233
|
+
export { normalizePathTokens, parsePathPattern, pathTokensToRegExpSource };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/utils/plugin-react-version.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Resolve @vitejs/plugin-react from the project, falling back to vinext's own
|
|
4
|
+
* install when the project has none or reaches an unsupported version.
|
|
5
|
+
* Returns null when it is not installed, and throws when every copy found is
|
|
6
|
+
* unsupported.
|
|
7
|
+
*/
|
|
8
|
+
export declare function resolvePluginReactPath(projectRoot: string, fallbackFrom?: string): string | null;
|
|
9
|
+
/**
|
|
10
|
+
* The @vitejs/plugin-react upgrade vinext init must install before vinext.
|
|
11
|
+
* A declared copy below the floor conflicts with vinext's peer range: npm stops
|
|
12
|
+
* with ERESOLVE, and pnpm installs but vinext refuses to start.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getPluginReactUpgradeDeps(root: string): string[];
|
|
15
|
+
//#endregion
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import path from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
|
|
2
|
+
import { findPackageVersion, isVersionBelow } from "./react-version.js";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
//#region src/utils/plugin-react-version.ts
|
|
6
|
+
const MINIMUM_PLUGIN_REACT_VERSION = [
|
|
7
|
+
5,
|
|
8
|
+
1,
|
|
9
|
+
4
|
|
10
|
+
];
|
|
11
|
+
function resolveFrom(from) {
|
|
12
|
+
try {
|
|
13
|
+
const resolved = createRequire(from).resolve("@vitejs/plugin-react");
|
|
14
|
+
return {
|
|
15
|
+
path: resolved,
|
|
16
|
+
version: findPackageVersion(resolved, "@vitejs/plugin-react")
|
|
17
|
+
};
|
|
18
|
+
} catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function isSupported(plugin) {
|
|
23
|
+
return plugin.version !== null && !isVersionBelow(plugin.version, MINIMUM_PLUGIN_REACT_VERSION);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Resolve @vitejs/plugin-react from the project, falling back to vinext's own
|
|
27
|
+
* install when the project has none or reaches an unsupported version.
|
|
28
|
+
* Returns null when it is not installed, and throws when every copy found is
|
|
29
|
+
* unsupported.
|
|
30
|
+
*/
|
|
31
|
+
function resolvePluginReactPath(projectRoot, fallbackFrom = import.meta.url) {
|
|
32
|
+
const project = resolveFrom(path.join(projectRoot, "package.json"));
|
|
33
|
+
if (project && isSupported(project)) return project.path;
|
|
34
|
+
const fallback = resolveFrom(fallbackFrom);
|
|
35
|
+
if (fallback && isSupported(fallback)) {
|
|
36
|
+
if (project) console.warn(`[vinext] Ignoring @vitejs/plugin-react ${project.version ?? "(unknown version)"} at ${project.path}: vinext requires ${MINIMUM_PLUGIN_REACT_VERSION.join(".")} or newer. Using ${fallback.version} instead. Add @vitejs/plugin-react to your app's devDependencies to choose the version explicitly.`);
|
|
37
|
+
return fallback.path;
|
|
38
|
+
}
|
|
39
|
+
const found = project ?? fallback;
|
|
40
|
+
if (!found) return null;
|
|
41
|
+
throw new Error(`vinext: @vitejs/plugin-react ${MINIMUM_PLUGIN_REACT_VERSION.join(".")} or newer is required (found ${found.version ?? "an unknown version"} at ${found.path}). Add @vitejs/plugin-react@^6 to your app's devDependencies.`);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The @vitejs/plugin-react upgrade vinext init must install before vinext.
|
|
45
|
+
* A declared copy below the floor conflicts with vinext's peer range: npm stops
|
|
46
|
+
* with ERESOLVE, and pnpm installs but vinext refuses to start.
|
|
47
|
+
*/
|
|
48
|
+
function getPluginReactUpgradeDeps(root) {
|
|
49
|
+
const manifest = path.join(root, "package.json");
|
|
50
|
+
let declared;
|
|
51
|
+
try {
|
|
52
|
+
const pkg = JSON.parse(fs.readFileSync(manifest, "utf-8"));
|
|
53
|
+
declared = pkg.dependencies?.["@vitejs/plugin-react"] ?? pkg.devDependencies?.["@vitejs/plugin-react"];
|
|
54
|
+
} catch {
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
if (typeof declared !== "string") return [];
|
|
58
|
+
const major = /^[~^]?(\d+)(?:\.(?:\d+|[x*])){0,2}$/.exec(declared.trim())?.[1];
|
|
59
|
+
if (major !== void 0 && Number(major) < MINIMUM_PLUGIN_REACT_VERSION[0]) return ["@vitejs/plugin-react@latest"];
|
|
60
|
+
const installed = resolveFrom(manifest);
|
|
61
|
+
return installed && (!isSupported(installed) || installed.version?.includes("-")) ? ["@vitejs/plugin-react@latest"] : [];
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
export { getPluginReactUpgradeDeps, resolvePluginReactPath };
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
//#region src/utils/public-routes.d.ts
|
|
2
2
|
export declare function scanPublicFileRoutes(root: string, configuredPublicDir?: string | false): string[];
|
|
3
|
+
/** List the files in the public directory as `/`-prefixed relative paths. */
|
|
4
|
+
export declare function scanPublicFiles(root: string, configuredPublicDir?: string | false): string[];
|
|
3
5
|
//#endregion
|
|
@@ -3,10 +3,14 @@ import { publicFileRouteKey } from "./public-file-path.js";
|
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
//#region src/utils/public-routes.ts
|
|
5
5
|
function scanPublicFileRoutes(root, configuredPublicDir = "public") {
|
|
6
|
+
return [...new Set(scanPublicFiles(root, configuredPublicDir).map(publicFileRouteKey))].sort();
|
|
7
|
+
}
|
|
8
|
+
/** List the files in the public directory as `/`-prefixed relative paths. */
|
|
9
|
+
function scanPublicFiles(root, configuredPublicDir = "public") {
|
|
6
10
|
if (configuredPublicDir === false || configuredPublicDir === "") return [];
|
|
7
11
|
const publicDir = path.resolve(root, configuredPublicDir);
|
|
8
|
-
const
|
|
9
|
-
const
|
|
12
|
+
const files = [];
|
|
13
|
+
const ancestorDirs = /* @__PURE__ */ new Set();
|
|
10
14
|
function walk(dir) {
|
|
11
15
|
let realDir;
|
|
12
16
|
try {
|
|
@@ -14,8 +18,15 @@ function scanPublicFileRoutes(root, configuredPublicDir = "public") {
|
|
|
14
18
|
} catch {
|
|
15
19
|
return;
|
|
16
20
|
}
|
|
17
|
-
if (
|
|
18
|
-
|
|
21
|
+
if (ancestorDirs.has(realDir)) return;
|
|
22
|
+
ancestorDirs.add(realDir);
|
|
23
|
+
try {
|
|
24
|
+
walkEntries(dir);
|
|
25
|
+
} finally {
|
|
26
|
+
ancestorDirs.delete(realDir);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function walkEntries(dir) {
|
|
19
30
|
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
20
31
|
for (const entry of entries) {
|
|
21
32
|
const fullPath = path.join(dir, entry.name);
|
|
@@ -37,13 +48,13 @@ function scanPublicFileRoutes(root, configuredPublicDir = "public") {
|
|
|
37
48
|
if (!stat.isFile()) continue;
|
|
38
49
|
} else if (!entry.isFile()) continue;
|
|
39
50
|
const relativePath = path.relative(publicDir, fullPath);
|
|
40
|
-
|
|
51
|
+
files.push("/" + relativePath);
|
|
41
52
|
}
|
|
42
53
|
}
|
|
43
54
|
if (fs.existsSync(publicDir)) try {
|
|
44
55
|
walk(publicDir);
|
|
45
56
|
} catch {}
|
|
46
|
-
return
|
|
57
|
+
return files;
|
|
47
58
|
}
|
|
48
59
|
//#endregion
|
|
49
|
-
export { scanPublicFileRoutes };
|
|
60
|
+
export { scanPublicFileRoutes, scanPublicFiles };
|
package/package.json
CHANGED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
//#region src/server/middleware-path-to-regexp.d.ts
|
|
2
|
-
export type MiddlewarePathToken = string | MiddlewarePathKey;
|
|
3
|
-
export type MiddlewarePathKey = {
|
|
4
|
-
name: string | number;
|
|
5
|
-
prefix: string;
|
|
6
|
-
suffix: string;
|
|
7
|
-
pattern: string;
|
|
8
|
-
modifier: string;
|
|
9
|
-
};
|
|
10
|
-
export declare function parseMiddlewarePath(value: string): MiddlewarePathToken[];
|
|
11
|
-
export declare function normalizeMiddlewarePathTokens(tokens: MiddlewarePathToken[]): MiddlewarePathToken[];
|
|
12
|
-
export declare function middlewarePathTokensToRegExp(tokens: MiddlewarePathToken[]): RegExp;
|
|
13
|
-
//#endregion
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
//#region src/utils/regex-safety.d.ts
|
|
2
|
-
export type RegexSafetyIssue = "nested repetition" | "ambiguous alternatives under repetition" | "ambiguous sequence expansion" | "overlapping sequential repetition" | "analysis budget exceeded";
|
|
3
|
-
/**
|
|
4
|
-
* Whether a RegExp source declares a named group, which turns `\k<name>` into
|
|
5
|
-
* a backreference. Escaped characters and character classes cannot open one.
|
|
6
|
-
*/
|
|
7
|
-
export declare function mayHaveNamedGroups(pattern: string): boolean;
|
|
8
|
-
/**
|
|
9
|
-
* `namedGroups` must describe the whole compiled RegExp when `pattern` is only
|
|
10
|
-
* a fragment of it. It defaults to scanning `pattern` itself.
|
|
11
|
-
*/
|
|
12
|
-
export declare function analyzeRegexSafety(pattern: string, options?: {
|
|
13
|
-
ignoreCase?: boolean;
|
|
14
|
-
namedGroups?: boolean;
|
|
15
|
-
}): RegexSafetyIssue | null;
|
|
16
|
-
export declare function regexAtomsMayOverlap(left: string, right: string, ignoreCase?: boolean): boolean;
|
|
17
|
-
//#endregion
|