vinext 1.1.0 → 1.2.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 +21 -9
- package/dist/build/client-build-config.d.ts +10 -0
- package/dist/build/client-build-config.js +18 -2
- package/dist/build/pages-client-assets-module.d.ts +8 -0
- package/dist/build/pages-client-assets-module.js +21 -1
- package/dist/build/prerender-paths.js +5 -3
- package/dist/build/run-prerender.js +1 -1
- package/dist/build/ssr-manifest.d.ts +2 -0
- package/dist/build/ssr-manifest.js +6 -2
- package/dist/check.js +7 -6
- package/dist/cli.js +2 -1
- package/dist/client/client-redirect-matcher.d.ts +14 -0
- package/dist/client/client-redirect-matcher.js +37 -0
- package/dist/client/client-redirects.d.ts +27 -0
- package/dist/client/client-redirects.js +28 -0
- package/dist/client/client-rewrites.d.ts +2 -1
- package/dist/client/client-rewrites.js +1 -1
- package/dist/config/config-matchers.d.ts +26 -11
- package/dist/config/config-matchers.js +78 -81
- package/dist/config/destination-params.d.ts +47 -0
- package/dist/config/destination-params.js +116 -0
- package/dist/config/next-config.d.ts +7 -0
- package/dist/config/next-config.js +3 -0
- package/dist/entries/app-rsc-entry.d.ts +4 -0
- package/dist/entries/app-rsc-entry.js +20 -6
- package/dist/entries/pages-client-entry.js +3 -1
- package/dist/entries/pages-server-entry.js +13 -37
- package/dist/index.d.ts +3 -1
- package/dist/index.js +134 -43
- package/dist/init-cloudflare.d.ts +9 -0
- package/dist/init-cloudflare.js +107 -31
- package/dist/init-platform.d.ts +4 -0
- package/dist/init-platform.js +27 -2
- package/dist/init.d.ts +1 -0
- package/dist/init.js +67 -3
- package/dist/plugins/ast-scope.d.ts +7 -0
- package/dist/plugins/ast-scope.js +59 -3
- package/dist/plugins/cache-flight-codec.d.ts +1 -1
- package/dist/plugins/dynamic-preload-metadata.d.ts +1 -1
- package/dist/plugins/dynamic-preload-metadata.js +9 -8
- package/dist/plugins/ignore-dynamic-requests.d.ts +1 -1
- package/dist/plugins/ignore-dynamic-requests.js +3 -4
- package/dist/plugins/middleware-server-only.d.ts +5 -4
- package/dist/plugins/middleware-server-only.js +8 -5
- package/dist/plugins/pages-node-externals.js +1 -1
- package/dist/plugins/rsc-scan-glob-imports.d.ts +19 -0
- package/dist/plugins/rsc-scan-glob-imports.js +50 -0
- package/dist/plugins/strip-server-exports.js +262 -98
- package/dist/plugins/transform-result.d.ts +9 -5
- package/dist/plugins/transitive-externals.js +1 -1
- package/dist/plugins/typeof-window.d.ts +2 -2
- package/dist/plugins/use-cache-callable.js +8 -2
- package/dist/plugins/worker-server-only-imports.d.ts +20 -0
- package/dist/plugins/worker-server-only-imports.js +31 -0
- package/dist/plugins/worker-use-server.d.ts +25 -0
- package/dist/plugins/worker-use-server.js +129 -0
- package/dist/server/api-handler.d.ts +1 -0
- package/dist/server/api-handler.js +2 -1
- package/dist/server/app-browser-action-result.d.ts +1 -1
- package/dist/server/app-browser-action-result.js +9 -2
- package/dist/server/app-browser-navigation-controller.js +1 -1
- package/dist/server/app-browser-server-action-client.js +1 -1
- package/dist/server/app-middleware.d.ts +11 -0
- package/dist/server/app-middleware.js +17 -2
- package/dist/server/app-page-cache.d.ts +1 -1
- package/dist/server/app-page-cache.js +1 -1
- package/dist/server/app-page-dispatch.d.ts +3 -1
- package/dist/server/app-page-dispatch.js +4 -3
- package/dist/server/app-page-ppr-runtime.js +1 -1
- package/dist/server/app-page-render-observation.js +1 -1
- package/dist/server/app-page-request.js +53 -15
- package/dist/server/app-page-route-wiring.js +2 -2
- package/dist/server/app-pages-bridge.d.ts +1 -1
- package/dist/server/app-pages-bridge.js +2 -3
- package/dist/server/app-prerender-endpoints.js +9 -6
- package/dist/server/app-request-stage-dispatch.js +6 -2
- package/dist/server/app-request-stage-independent-entry.js +25 -5
- package/dist/server/app-response-stage-entry.js +10 -2
- package/dist/server/app-route-handler-cache.d.ts +1 -0
- package/dist/server/app-route-handler-cache.js +1 -0
- package/dist/server/app-route-handler-dispatch.d.ts +1 -0
- package/dist/server/app-route-handler-dispatch.js +5 -2
- package/dist/server/app-route-handler-execution.d.ts +1 -0
- package/dist/server/app-route-handler-execution.js +1 -0
- package/dist/server/app-route-handler-runtime.d.ts +4 -1
- package/dist/server/app-route-handler-runtime.js +45 -24
- package/dist/server/app-router-entry.js +24 -5
- package/dist/server/app-rsc-cache-busting.js +1 -1
- package/dist/server/app-rsc-errors.js +20 -16
- package/dist/server/app-rsc-handler.d.ts +7 -0
- package/dist/server/app-rsc-handler.js +85 -35
- package/dist/server/app-rsc-response-stage.js +4 -2
- package/dist/server/app-segment-config.d.ts +2 -1
- package/dist/server/app-server-action-execution.d.ts +2 -1
- package/dist/server/app-server-action-execution.js +61 -22
- package/dist/server/app-ssr-entry.js +2 -1
- package/dist/server/app-worker-stages.d.ts +5 -0
- package/dist/server/app-worker-stages.js +1 -1
- package/dist/server/cacheability-request.js +2 -2
- package/dist/server/client-build-files.d.ts +16 -0
- package/dist/server/client-build-files.js +36 -0
- package/dist/server/client-reuse-manifest.js +1 -1
- package/dist/server/dev-server.js +38 -27
- package/dist/server/dev-stack-sourcemap.js +18 -23
- package/dist/server/document-initial-head.d.ts +0 -11
- package/dist/server/document-initial-head.js +1 -1
- package/dist/server/forwarded-middleware-context.d.ts +5 -0
- package/dist/server/forwarded-middleware-context.js +22 -0
- package/dist/server/headers.d.ts +4 -1
- package/dist/server/headers.js +4 -1
- package/dist/server/http-conditional.d.ts +11 -0
- package/dist/server/http-conditional.js +10 -1
- package/dist/server/http-error-responses.d.ts +1 -1
- package/dist/server/image-optimization.d.ts +38 -0
- package/dist/server/image-optimization.js +93 -4
- package/dist/server/isr-cache.d.ts +10 -0
- package/dist/server/isr-cache.js +41 -6
- package/dist/server/metadata-route-response.js +9 -8
- package/dist/server/middleware-matcher.d.ts +2 -0
- package/dist/server/middleware-matcher.js +23 -2
- package/dist/server/middleware-runtime.d.ts +13 -0
- package/dist/server/middleware-runtime.js +33 -20
- package/dist/server/middleware.d.ts +1 -1
- package/dist/server/middleware.js +3 -1
- package/dist/server/multi-stage.d.ts +11 -0
- package/dist/server/normalize-path.d.ts +0 -13
- package/dist/server/normalize-path.js +1 -34
- package/dist/server/pages-api-route.d.ts +3 -2
- package/dist/server/pages-api-route.js +4 -3
- package/dist/server/pages-cache-tag.d.ts +12 -0
- package/dist/server/pages-cache-tag.js +19 -0
- package/dist/server/pages-client-assets.d.ts +2 -0
- package/dist/server/pages-data-route.d.ts +10 -0
- package/dist/server/pages-data-route.js +19 -2
- package/dist/server/pages-document-asset-props.d.ts +5 -1
- package/dist/server/pages-document-asset-props.js +13 -5
- package/dist/server/pages-document-splice.d.ts +19 -0
- package/dist/server/pages-document-splice.js +55 -0
- package/dist/server/pages-i18n.d.ts +12 -1
- package/dist/server/pages-i18n.js +18 -4
- package/dist/server/pages-node-compat.d.ts +16 -5
- package/dist/server/pages-node-compat.js +20 -12
- package/dist/server/pages-page-data.d.ts +32 -24
- package/dist/server/pages-page-data.js +50 -120
- package/dist/server/pages-page-handler.d.ts +0 -6
- package/dist/server/pages-page-handler.js +188 -126
- package/dist/server/pages-page-response.d.ts +12 -6
- package/dist/server/pages-page-response.js +41 -34
- package/dist/server/pages-request-pipeline.d.ts +10 -2
- package/dist/server/pages-request-pipeline.js +37 -18
- package/dist/server/pages-request-stage-entry.d.ts +6 -0
- package/dist/server/pages-request-stage-entry.js +71 -12
- package/dist/server/pages-response-stage-entry.js +4 -0
- package/dist/server/pages-revalidate.js +1 -1
- package/dist/server/pages-router-entry.js +4 -3
- package/dist/server/prerender-manifest.d.ts +3 -3
- package/dist/server/prerender-manifest.js +4 -3
- package/dist/server/prerender-work-unit-setup.js +4 -0
- package/dist/server/prod-server.d.ts +12 -0
- package/dist/server/prod-server.js +199 -69
- package/dist/server/proper-error.d.ts +4 -0
- package/dist/server/proper-error.js +31 -0
- package/dist/server/request-pipeline.d.ts +4 -1
- package/dist/server/request-pipeline.js +3 -2
- package/dist/server/revalidation-request.d.ts +1 -0
- package/dist/server/revalidation-request.js +1 -1
- package/dist/server/rsc-stream-hints.js +31 -2
- package/dist/server/seed-cache.d.ts +1 -0
- package/dist/server/seed-cache.js +5 -4
- package/dist/server/server-reference-loader.d.ts +4 -0
- package/dist/server/server-reference-loader.js +29 -0
- package/dist/server/socket-error-backstop.d.ts +9 -1
- package/dist/server/socket-error-backstop.js +46 -17
- package/dist/server/static-file-signal.d.ts +15 -4
- package/dist/server/static-file-signal.js +46 -12
- package/dist/server/worker-image-optimization.d.ts +34 -0
- package/dist/server/worker-image-optimization.js +86 -0
- package/dist/server/worker-stages.d.ts +1 -1
- package/dist/server/worker-stages.js +2 -2
- package/dist/server/worker-utils.d.ts +8 -3
- package/dist/server/worker-utils.js +12 -7
- package/dist/shims/app-router-scroll.js +4 -1
- package/dist/shims/app-router-tree-context.d.ts +5 -0
- package/dist/shims/app-router-tree-context.js +27 -0
- package/dist/shims/cache-callable-runtime.d.ts +4 -2
- package/dist/shims/cache-callable-runtime.js +21 -12
- package/dist/shims/cache-handler.js +1 -9
- package/dist/shims/cache-runtime.d.ts +6 -1
- package/dist/shims/cache-runtime.js +2 -1
- package/dist/shims/cache.d.ts +2 -2
- package/dist/shims/cache.js +40 -13
- package/dist/shims/cdn-cache.d.ts +8 -0
- package/dist/shims/cdn-cache.js +17 -1
- package/dist/shims/disable-smooth-scroll.d.ts +3 -0
- package/dist/shims/disable-smooth-scroll.js +36 -0
- package/dist/shims/document-placeholders.d.ts +19 -0
- package/dist/shims/document-placeholders.js +45 -0
- package/dist/shims/document.js +21 -5
- package/dist/shims/dynamic-preload-chunks.d.ts +1 -0
- package/dist/shims/dynamic-preload-chunks.js +13 -9
- package/dist/shims/dynamic.d.ts +1 -1
- package/dist/shims/dynamic.js +60 -8
- package/dist/shims/fetch-cache-state.d.ts +66 -0
- package/dist/shims/fetch-cache-state.js +92 -0
- package/dist/shims/fetch-cache.d.ts +3 -67
- package/dist/shims/fetch-cache.js +160 -125
- package/dist/shims/head.d.ts +10 -6
- package/dist/shims/head.js +15 -13
- package/dist/shims/image.js +2 -1
- package/dist/shims/internal/work-store-scope.d.ts +5 -0
- package/dist/shims/internal/work-store-scope.js +24 -0
- package/dist/shims/navigation.js +31 -5
- package/dist/shims/request-context.d.ts +2 -0
- package/dist/shims/request-state-types.d.ts +2 -1
- package/dist/shims/router.js +12 -20
- package/dist/shims/server.d.ts +16 -0
- package/dist/shims/server.js +24 -4
- package/dist/shims/unified-request-context.d.ts +1 -1
- package/dist/shims/url-utils.d.ts +2 -0
- package/dist/shims/url-utils.js +3 -1
- package/dist/utils/client-runtime-metadata.js +1 -1
- package/dist/utils/hash.d.ts +7 -0
- package/dist/utils/hash.js +11 -1
- package/dist/utils/package-name.d.ts +6 -0
- package/dist/utils/package-name.js +12 -1
- package/dist/utils/plugin-rsc-version.d.ts +4 -0
- package/dist/utils/plugin-rsc-version.js +15 -0
- package/dist/utils/prerender-output-paths.js +15 -4
- package/dist/utils/public-file-path.d.ts +10 -2
- package/dist/utils/public-file-path.js +13 -9
- package/dist/utils/public-routes.js +2 -2
- package/dist/utils/react-version.d.ts +3 -0
- package/dist/utils/react-version.js +1 -1
- package/package.json +7 -3
|
@@ -3,7 +3,8 @@ import { collectBindingNames, forEachAstChild, stringLiteralValue, walkAst } fro
|
|
|
3
3
|
import { hasTrailingComma } from "../utils/has-trailing-comma.js";
|
|
4
4
|
import { magicStringTransformResult } from "./transform-result.js";
|
|
5
5
|
import { stripViteModuleQuery } from "../utils/path.js";
|
|
6
|
-
import {
|
|
6
|
+
import { isForeignNodeModule } from "../utils/package-name.js";
|
|
7
|
+
import { relativeToRoot, relativeWithinRoot, tryRealpathSync } from "../build/ssr-manifest.js";
|
|
7
8
|
import { parseAst } from "vite";
|
|
8
9
|
import MagicString from "magic-string";
|
|
9
10
|
//#region src/plugins/dynamic-preload-metadata.ts
|
|
@@ -204,7 +205,7 @@ function toManifestModuleId(root, resolvedId) {
|
|
|
204
205
|
const relative = relativeWithinRoot(rootCandidate, moduleCandidate);
|
|
205
206
|
if (relative) return relative;
|
|
206
207
|
}
|
|
207
|
-
return null;
|
|
208
|
+
return relativeToRoot(root, cleaned) || null;
|
|
208
209
|
}
|
|
209
210
|
async function resolveManifestModuleIds(specifiers, importer, root, resolveDynamicImport) {
|
|
210
211
|
const resolvedIds = [];
|
|
@@ -262,24 +263,24 @@ async function transformNextDynamicPreloadMetadata(code, id, root, resolveDynami
|
|
|
262
263
|
if (!changed) return null;
|
|
263
264
|
return magicStringTransformResult(output);
|
|
264
265
|
}
|
|
265
|
-
function createDynamicPreloadMetadataPlugin() {
|
|
266
|
+
function createDynamicPreloadMetadataPlugin(getTranspiledPackages) {
|
|
266
267
|
let root = toSlash(process.cwd());
|
|
268
|
+
let isBuild = false;
|
|
267
269
|
return {
|
|
268
270
|
name: "vinext:dynamic-preload-metadata",
|
|
269
271
|
configResolved(config) {
|
|
270
272
|
root = config.root;
|
|
273
|
+
isBuild = config.command === "build";
|
|
271
274
|
},
|
|
272
275
|
transform: {
|
|
273
276
|
filter: {
|
|
274
|
-
id:
|
|
275
|
-
include: /\.(tsx?|jsx?|mjs)$/,
|
|
276
|
-
exclude: /node_modules/
|
|
277
|
-
},
|
|
277
|
+
id: /\.(tsx?|jsx?|mjs)$/,
|
|
278
278
|
code: "next/dynamic"
|
|
279
279
|
},
|
|
280
280
|
async handler(code, id) {
|
|
281
|
-
if (id.
|
|
281
|
+
if (id.startsWith("\0")) return null;
|
|
282
282
|
if (!/\.(tsx?|jsx?|mjs)$/.test(id)) return null;
|
|
283
|
+
if (id.includes("node_modules") && (!isBuild || isForeignNodeModule(id, getTranspiledPackages()))) return null;
|
|
283
284
|
const result = await transformNextDynamicPreloadMetadata(code, id, root, async (specifier, importer) => {
|
|
284
285
|
return (await this.resolve(specifier, importer, { skipSelf: true }))?.id ?? null;
|
|
285
286
|
});
|
|
@@ -11,7 +11,7 @@ import { Plugin } from "vite";
|
|
|
11
11
|
* identifiers, falls through to the AST pass.
|
|
12
12
|
*/
|
|
13
13
|
declare function mayContainVeryDynamicRequest(code: string): boolean;
|
|
14
|
-
declare function transformVeryDynamicRequests(code: string, id: string): MagicStringTransformResult | null;
|
|
14
|
+
declare function transformVeryDynamicRequests(code: string, id: string): MagicStringTransformResult<import("magic-string").SourceMap> | null;
|
|
15
15
|
export declare function createIgnoreDynamicRequestsPlugin(getTranspiledPackages?: () => readonly string[]): Plugin;
|
|
16
16
|
export declare const _transformVeryDynamicRequests: typeof transformVeryDynamicRequests;
|
|
17
17
|
export declare const _mayContainVeryDynamicRequest: typeof mayContainVeryDynamicRequest;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import path
|
|
1
|
+
import path from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
|
|
2
2
|
import { DYNAMIC_IMPORT_PRESCAN, SCRIPT_MODULE_ID_RE, collectBindingNames, forEachAstChild, isIdentifierNamed, mayContainDynamicImport, scriptParserLanguage, stringLiteralValue, unwrapExpression } from "./ast-utils.js";
|
|
3
3
|
import { magicStringTransformResult, omitUnusedBuildSourcemap } from "./transform-result.js";
|
|
4
4
|
import { stripViteModuleQuery } from "../utils/path.js";
|
|
5
|
+
import { isForeignNodeModule } from "../utils/package-name.js";
|
|
5
6
|
import { collectDirectScopeBindings, collectLoopScopeBindings, collectSwitchScopeBindings, collectVarScopeBindings, hasAstBinding, isFunctionNode } from "./ast-scope.js";
|
|
6
7
|
import { createTransformCache } from "./transform-cache.js";
|
|
7
8
|
import { fileURLToPath } from "node:url";
|
|
@@ -543,9 +544,7 @@ function createIgnoreDynamicRequestsPlugin(getTranspiledPackages = () => []) {
|
|
|
543
544
|
}
|
|
544
545
|
function shouldTransformVeryDynamicRequests(environment, id, transpiledPackages) {
|
|
545
546
|
if (environment.config.consumer === "server") return true;
|
|
546
|
-
|
|
547
|
-
if (!normalizedId.includes("/node_modules/")) return false;
|
|
548
|
-
return !transpiledPackages.some((packageName) => normalizedId.includes(`/node_modules/${packageName}/`));
|
|
547
|
+
return isForeignNodeModule(id, transpiledPackages);
|
|
549
548
|
}
|
|
550
549
|
const _transformVeryDynamicRequests = transformVeryDynamicRequests;
|
|
551
550
|
const _mayContainVeryDynamicRequest = mayContainVeryDynamicRequest;
|
|
@@ -29,10 +29,11 @@ import { Plugin } from "vite";
|
|
|
29
29
|
* to the tainted set. This propagates the taint along the import graph
|
|
30
30
|
* synchronously, before plugin-rsc's `order: "pre"` validate-imports
|
|
31
31
|
* handler sees the next `server-only` request.
|
|
32
|
-
* 3. When a tainted module imports `server-only` in a non-RSC
|
|
33
|
-
* short-circuit to the no-op shim path so plugin-rsc's
|
|
34
|
-
* matches the bare `^server-only$` specifier) never fires
|
|
35
|
-
* import.
|
|
32
|
+
* 3. When a tainted module imports `server-only` in a non-RSC server
|
|
33
|
+
* environment, short-circuit to the no-op shim path so plugin-rsc's
|
|
34
|
+
* filter (which matches the bare `^server-only$` specifier) never fires
|
|
35
|
+
* for that import. Browser environments are skipped entirely, so the
|
|
36
|
+
* client `server-only` validators still see every import there.
|
|
36
37
|
*
|
|
37
38
|
* The taint set is scoped to the middleware chain only — `server-only`
|
|
38
39
|
* imports from anywhere else (including client component code traversing
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { toSlash } from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
|
|
2
2
|
import { stripViteModuleQuery } from "../utils/path.js";
|
|
3
|
+
import { isServerEnvironment } from "./environment.js";
|
|
3
4
|
//#region src/plugins/middleware-server-only.ts
|
|
4
5
|
/**
|
|
5
6
|
* Allow `import 'server-only'` from neutral server targets (and any module
|
|
@@ -30,10 +31,11 @@ import { stripViteModuleQuery } from "../utils/path.js";
|
|
|
30
31
|
* to the tainted set. This propagates the taint along the import graph
|
|
31
32
|
* synchronously, before plugin-rsc's `order: "pre"` validate-imports
|
|
32
33
|
* handler sees the next `server-only` request.
|
|
33
|
-
* 3. When a tainted module imports `server-only` in a non-RSC
|
|
34
|
-
* short-circuit to the no-op shim path so plugin-rsc's
|
|
35
|
-
* matches the bare `^server-only$` specifier) never fires
|
|
36
|
-
* import.
|
|
34
|
+
* 3. When a tainted module imports `server-only` in a non-RSC server
|
|
35
|
+
* environment, short-circuit to the no-op shim path so plugin-rsc's
|
|
36
|
+
* filter (which matches the bare `^server-only$` specifier) never fires
|
|
37
|
+
* for that import. Browser environments are skipped entirely, so the
|
|
38
|
+
* client `server-only` validators still see every import there.
|
|
37
39
|
*
|
|
38
40
|
* The taint set is scoped to the middleware chain only — `server-only`
|
|
39
41
|
* imports from anywhere else (including client component code traversing
|
|
@@ -71,7 +73,8 @@ function createMiddlewareServerOnlyPlugin(options) {
|
|
|
71
73
|
resolveId: {
|
|
72
74
|
order: "pre",
|
|
73
75
|
async handler(id, importer, opts) {
|
|
74
|
-
|
|
76
|
+
const environment = this.environment;
|
|
77
|
+
if (!environment || !isServerEnvironment(environment) || environment.name === "rsc") return;
|
|
75
78
|
if (!importer) return;
|
|
76
79
|
if (!isTainted(importer) && !options.isNeutralServerModule?.(canonicalizeId(importer))) return;
|
|
77
80
|
if (id === "server-only") return {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import path from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
|
|
2
2
|
import { SCRIPT_MODULE_ID_RE, mayContainDynamicImport, scriptParserLanguage, staticStringValue, walkAst } from "./ast-utils.js";
|
|
3
3
|
import { canonicalizeFilePath, isPathInsideOrEqual, stripViteModuleQuery } from "../utils/path.js";
|
|
4
|
-
import { packageNameFromSpecifier } from "../utils/package-name.js";
|
|
5
4
|
import { isServerEnvironment } from "./environment.js";
|
|
5
|
+
import { packageNameFromSpecifier } from "../utils/package-name.js";
|
|
6
6
|
import fs from "node:fs";
|
|
7
7
|
import { parseAst } from "vite";
|
|
8
8
|
//#region src/plugins/pages-node-externals.ts
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Plugin, ResolvedConfig } from "vite";
|
|
2
|
+
import { RscPluginManager } from "@vitejs/plugin-rsc";
|
|
3
|
+
//#region src/plugins/rsc-scan-glob-imports.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* @vitejs/plugin-rsc 0.5.36 and 0.5.37 reduce scan-build modules to their
|
|
6
|
+
* import specifiers with es-module-lexer v3, which reports template-literal
|
|
7
|
+
* dynamic imports as glob patterns (``import(`file://${p}`)`` becomes
|
|
8
|
+
* `"file://*"`). The scan then emits them as plain imports, which fail to
|
|
9
|
+
* resolve (e.g. in @module-federation/vite). Other versions skip these
|
|
10
|
+
* specifiers (0.5.38 via vitejs/vite-plugin-react#1506), so for the affected
|
|
11
|
+
* ones keep the specifiers that don't resolve external during the scan. A real
|
|
12
|
+
* module whose specifier contains `*` still resolves and stays in the scan
|
|
13
|
+
* graph. The scan's output is discarded, so nothing else changes.
|
|
14
|
+
*/
|
|
15
|
+
export declare function isRscScanGlobImportsAffected(version: string): boolean;
|
|
16
|
+
export declare function createRscScanGlobImportsPlugin(options: {
|
|
17
|
+
getManager: (config: ResolvedConfig) => Promise<RscPluginManager | undefined>;
|
|
18
|
+
}): Plugin;
|
|
19
|
+
//#endregion
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { isVersionBelow } from "../utils/react-version.js";
|
|
2
|
+
//#region src/plugins/rsc-scan-glob-imports.ts
|
|
3
|
+
/**
|
|
4
|
+
* @vitejs/plugin-rsc 0.5.36 and 0.5.37 reduce scan-build modules to their
|
|
5
|
+
* import specifiers with es-module-lexer v3, which reports template-literal
|
|
6
|
+
* dynamic imports as glob patterns (``import(`file://${p}`)`` becomes
|
|
7
|
+
* `"file://*"`). The scan then emits them as plain imports, which fail to
|
|
8
|
+
* resolve (e.g. in @module-federation/vite). Other versions skip these
|
|
9
|
+
* specifiers (0.5.38 via vitejs/vite-plugin-react#1506), so for the affected
|
|
10
|
+
* ones keep the specifiers that don't resolve external during the scan. A real
|
|
11
|
+
* module whose specifier contains `*` still resolves and stays in the scan
|
|
12
|
+
* graph. The scan's output is discarded, so nothing else changes.
|
|
13
|
+
*/
|
|
14
|
+
function isRscScanGlobImportsAffected(version) {
|
|
15
|
+
return !isVersionBelow(version, [
|
|
16
|
+
0,
|
|
17
|
+
5,
|
|
18
|
+
36
|
|
19
|
+
]) && isVersionBelow(version, [
|
|
20
|
+
0,
|
|
21
|
+
5,
|
|
22
|
+
38
|
|
23
|
+
]);
|
|
24
|
+
}
|
|
25
|
+
function createRscScanGlobImportsPlugin(options) {
|
|
26
|
+
return {
|
|
27
|
+
name: "vinext:rsc-scan-glob-imports",
|
|
28
|
+
apply: "build",
|
|
29
|
+
enforce: "pre",
|
|
30
|
+
resolveId: {
|
|
31
|
+
filter: { id: /\*/ },
|
|
32
|
+
async handler(source, importer, resolveOptions) {
|
|
33
|
+
if (!(await options.getManager(this.environment.config))?.isScanBuild) return;
|
|
34
|
+
try {
|
|
35
|
+
const resolved = await this.resolve(source, importer, {
|
|
36
|
+
...resolveOptions,
|
|
37
|
+
skipSelf: true
|
|
38
|
+
});
|
|
39
|
+
if (resolved) return resolved;
|
|
40
|
+
} catch {}
|
|
41
|
+
return {
|
|
42
|
+
id: source,
|
|
43
|
+
external: true
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
export { createRscScanGlobImportsPlugin, isRscScanGlobImportsAffected };
|