vinext 0.1.4 → 0.1.6
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 +2 -2
- package/dist/build/css-url-assets.d.ts +1 -1
- package/dist/build/css-url-assets.js +9 -7
- package/dist/build/google-fonts/find-font-files-in-css.d.ts +16 -0
- package/dist/build/google-fonts/find-font-files-in-css.js +28 -0
- package/dist/build/prerender.js +2 -1
- package/dist/build/report.d.ts +1 -2
- package/dist/build/report.js +2 -11
- package/dist/build/run-prerender.js +1 -1
- package/dist/cache/cache-adapters-virtual.js +1 -1
- package/dist/check.js +3 -3
- package/dist/client/pages-router-link-navigation.d.ts +10 -0
- package/dist/client/pages-router-link-navigation.js +3 -3
- package/dist/cloudflare/src/cache/kv-data-adapter.runtime.d.ts +1 -1
- package/dist/deploy.js +3 -3
- package/dist/entries/app-rsc-entry.js +25 -20
- package/dist/entries/app-rsc-manifest.js +76 -46
- package/dist/entries/pages-server-entry.js +3 -1
- package/dist/index.js +254 -198
- package/dist/init.d.ts +5 -4
- package/dist/init.js +27 -8
- package/dist/plugins/css-data-url.js +30 -26
- package/dist/plugins/extensionless-dynamic-import.js +27 -24
- package/dist/plugins/fonts.js +3 -1
- package/dist/plugins/import-meta-url.js +21 -15
- package/dist/plugins/instrumentation-client.js +1 -1
- package/dist/plugins/middleware-export-validation.d.ts +5 -0
- package/dist/plugins/middleware-export-validation.js +36 -0
- package/dist/plugins/middleware-server-only.js +7 -6
- package/dist/plugins/og-asset-ownership.d.ts +27 -0
- package/dist/plugins/og-asset-ownership.js +285 -0
- package/dist/plugins/og-assets.js +66 -46
- package/dist/plugins/optimize-imports.js +9 -3
- package/dist/plugins/remove-console.d.ts +7 -1
- package/dist/plugins/remove-console.js +4 -1
- package/dist/plugins/require-context.js +21 -20
- package/dist/plugins/strip-server-exports.d.ts +7 -1
- package/dist/plugins/strip-server-exports.js +4 -1
- package/dist/server/accept-encoding.d.ts +29 -0
- package/dist/server/accept-encoding.js +95 -0
- package/dist/server/app-bfcache-identity.d.ts +26 -0
- package/dist/server/app-bfcache-identity.js +127 -0
- package/dist/server/app-browser-entry.js +17 -11
- package/dist/server/app-browser-rsc-redirect.d.ts +2 -1
- package/dist/server/app-browser-rsc-redirect.js +8 -1
- package/dist/server/app-browser-state.d.ts +2 -21
- package/dist/server/app-browser-state.js +4 -128
- package/dist/server/app-browser-stream.js +1 -1
- package/dist/server/app-browser-visible-commit.js +3 -2
- package/dist/server/app-fallback-renderer.d.ts +1 -1
- package/dist/server/app-layout-param-observation.d.ts +1 -1
- package/dist/server/app-layout-param-observation.js +1 -1
- package/dist/server/app-middleware.d.ts +1 -0
- package/dist/server/app-middleware.js +3 -1
- package/dist/server/app-page-boundary-render.d.ts +1 -1
- package/dist/server/app-page-boundary.js +1 -1
- package/dist/server/app-page-cache-finalizer.d.ts +62 -0
- package/dist/server/app-page-cache-finalizer.js +122 -0
- package/dist/server/app-page-cache-render.d.ts +2 -2
- package/dist/server/app-page-cache-render.js +1 -1
- package/dist/server/app-page-cache.d.ts +2 -53
- package/dist/server/app-page-cache.js +5 -131
- package/dist/server/app-page-dispatch.d.ts +4 -4
- package/dist/server/app-page-dispatch.js +10 -8
- package/dist/server/app-page-head.js +2 -2
- package/dist/server/app-page-probe.js +3 -2
- package/dist/server/app-page-render-observation.js +2 -2
- package/dist/server/app-page-render.d.ts +3 -3
- package/dist/server/app-page-render.js +3 -2
- package/dist/server/app-page-request.d.ts +7 -0
- package/dist/server/app-page-request.js +19 -1
- package/dist/server/app-page-stream.d.ts +2 -9
- package/dist/server/app-page-stream.js +1 -35
- package/dist/server/app-prerender-endpoints.d.ts +3 -3
- package/dist/server/app-prerender-endpoints.js +3 -4
- package/dist/server/app-request-context.d.ts +1 -2
- package/dist/server/app-request-context.js +2 -1
- package/dist/server/app-route-handler-dispatch.js +3 -2
- package/dist/server/app-route-handler-execution.d.ts +1 -1
- package/dist/server/app-route-handler-execution.js +1 -1
- package/dist/server/app-route-handler-response.d.ts +1 -1
- package/dist/server/app-route-module-loader.d.ts +62 -14
- package/dist/server/app-route-module-loader.js +61 -10
- package/dist/server/app-router-entry.js +2 -1
- package/dist/server/app-rsc-handler.d.ts +7 -6
- package/dist/server/app-rsc-handler.js +51 -40
- package/dist/server/app-rsc-response-finalizer.js +1 -1
- package/dist/server/app-rsc-route-matching.d.ts +9 -0
- package/dist/server/app-rsc-route-matching.js +13 -0
- package/dist/server/app-server-action-execution.d.ts +1 -1
- package/dist/server/app-server-action-execution.js +5 -4
- package/dist/server/app-ssr-entry.d.ts +1 -1
- package/dist/server/app-ssr-entry.js +9 -7
- package/dist/server/app-ssr-router-instance.d.ts +6 -0
- package/dist/server/app-ssr-router-instance.js +24 -0
- package/dist/server/app-ssr-stream.js +1 -1
- package/dist/server/artifact-compatibility.js +1 -1
- package/dist/server/client-reuse-manifest.js +1 -1
- package/dist/server/defer-until-stream-consumed.d.ts +7 -0
- package/dist/server/defer-until-stream-consumed.js +34 -0
- package/dist/server/dev-server.js +1 -1
- package/dist/server/headers.d.ts +5 -1
- package/dist/server/headers.js +5 -1
- package/dist/server/instrumentation.js +1 -1
- package/dist/server/isr-cache.d.ts +1 -1
- package/dist/server/isr-cache.js +1 -1
- package/dist/server/isr-decision.d.ts +1 -1
- package/dist/server/metadata-route-response.d.ts +3 -3
- package/dist/server/middleware-matcher.js +8 -6
- package/dist/server/middleware-runtime.d.ts +2 -1
- package/dist/server/middleware-runtime.js +21 -10
- package/dist/server/middleware.d.ts +2 -2
- package/dist/server/middleware.js +26 -11
- package/dist/server/open-redirect.d.ts +12 -0
- package/dist/server/open-redirect.js +21 -0
- package/dist/server/pages-page-data.d.ts +1 -1
- package/dist/server/pages-page-response.d.ts +1 -1
- package/dist/server/pages-page-response.js +2 -2
- package/dist/server/pages-request-pipeline.d.ts +3 -1
- package/dist/server/pages-request-pipeline.js +4 -2
- package/dist/server/prod-server.d.ts +1 -1
- package/dist/server/prod-server.js +87 -73
- package/dist/server/request-pipeline.d.ts +1 -24
- package/dist/server/request-pipeline.js +1 -33
- package/dist/server/seed-cache.d.ts +1 -1
- package/dist/shims/cache-handler.d.ts +106 -0
- package/dist/shims/cache-handler.js +176 -0
- package/dist/shims/cache-request-state.d.ts +47 -0
- package/dist/shims/cache-request-state.js +126 -0
- package/dist/shims/cache-runtime.d.ts +2 -2
- package/dist/shims/cache-runtime.js +3 -14
- package/dist/shims/cache.d.ts +3 -231
- package/dist/shims/cache.js +17 -383
- package/dist/shims/cdn-cache.d.ts +1 -1
- package/dist/shims/cdn-cache.js +1 -1
- package/dist/shims/error-boundary-navigation.d.ts +7 -0
- package/dist/shims/error-boundary-navigation.js +44 -0
- package/dist/shims/error-boundary.js +10 -8
- package/dist/shims/error.js +2 -1
- package/dist/shims/fetch-cache.js +1 -1
- package/dist/shims/font-google-base.d.ts +1 -0
- package/dist/shims/font-google-base.js +6 -21
- package/dist/shims/form.js +1 -1
- package/dist/shims/image.js +67 -9
- package/dist/shims/internal/app-page-props-cache-key.d.ts +5 -0
- package/dist/shims/internal/app-page-props-cache-key.js +16 -0
- package/dist/shims/internal/interpolate-as.d.ts +25 -0
- package/dist/shims/internal/interpolate-as.js +196 -0
- package/dist/shims/internal/navigation-untracked.js +2 -1
- package/dist/shims/layout-segment-context.d.ts +1 -1
- package/dist/shims/layout-segment-context.js +2 -1
- package/dist/shims/link.js +26 -3
- package/dist/shims/navigation-context-state.d.ts +40 -0
- package/dist/shims/navigation-context-state.js +116 -0
- package/dist/shims/navigation-errors.d.ts +55 -0
- package/dist/shims/navigation-errors.js +110 -0
- package/dist/shims/navigation-server.d.ts +3 -0
- package/dist/shims/navigation-server.js +3 -0
- package/dist/shims/navigation-state.d.ts +1 -2
- package/dist/shims/navigation-state.js +2 -1
- package/dist/shims/navigation.d.ts +3 -291
- package/dist/shims/navigation.js +13 -444
- package/dist/shims/navigation.react-server.d.ts +2 -2
- package/dist/shims/navigation.react-server.js +4 -2
- package/dist/shims/request-state-types.d.ts +3 -3
- package/dist/shims/router.d.ts +1 -3
- package/dist/shims/router.js +62 -18
- package/dist/shims/script.js +1 -1
- package/dist/shims/slot.js +3 -1
- package/dist/shims/unified-request-context.d.ts +2 -2
- package/dist/typegen.js +2 -10
- package/dist/utils/project.d.ts +7 -1
- package/dist/utils/project.js +16 -2
- package/dist/utils/virtual-module.d.ts +5 -0
- package/dist/utils/virtual-module.js +0 -0
- package/package.json +7 -3
package/dist/index.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { detectPackageManager } from "./utils/project.js";
|
|
2
2
|
import { normalizePathSeparators, stripJsExtension, stripViteModuleQuery } from "./utils/path.js";
|
|
3
3
|
import { normalizePathnameForRouteMatchStrict } from "./routing/utils.js";
|
|
4
|
+
import { escapeRegExp } from "./utils/regex.js";
|
|
4
5
|
import { buildViteResolveExtensions, createValidFileMatcher, findFileWithExts, normalizeViteResolveExtensions } from "./routing/file-matcher.js";
|
|
5
6
|
import { apiRouter, invalidateRouteCache, matchRoute, pagesRouter } from "./routing/pages-router.js";
|
|
6
7
|
import { INTERNAL_HEADERS, NEXTJS_DEPLOYMENT_ID_HEADER, VINEXT_INTERNAL_HEADERS, VINEXT_MW_CTX_HEADER, VINEXT_TIMING_HEADER } from "./server/headers.js";
|
|
7
8
|
import { normalizePath as normalizePath$1 } from "./server/normalize-path.js";
|
|
8
9
|
import { matchesRewriteSource, proxyExternalRequest } from "./config/config-matchers.js";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
10
|
+
import { isOpenRedirectShaped } from "./server/open-redirect.js";
|
|
11
|
+
import { filterInternalHeaders, normalizeTrailingSlash } from "./server/request-pipeline.js";
|
|
12
|
+
import { findMiddlewareFile, isProxyFile, runMiddleware } from "./server/middleware.js";
|
|
11
13
|
import { generateServerEntry } from "./entries/pages-server-entry.js";
|
|
12
14
|
import { generateClientEntry } from "./entries/pages-client-entry.js";
|
|
13
15
|
import { appRouteGraph, appRouter, invalidateAppRouteCache, matchAppRoute } from "./routing/app-router.js";
|
|
@@ -41,6 +43,7 @@ import { collectInlineCssManifest, injectInlineCssManifestGlobal } from "./build
|
|
|
41
43
|
import { installDevStackSourcemapMiddleware } from "./server/dev-stack-sourcemap.js";
|
|
42
44
|
import { runPagesRequest } from "./server/pages-request-pipeline.js";
|
|
43
45
|
import { pagesRouteHasPriorityOverAppRoute, validateHybridRouteConflicts } from "./server/hybrid-route-priority.js";
|
|
46
|
+
import { VIRTUAL_MODULE_ID_RE } from "./utils/virtual-module.js";
|
|
44
47
|
import { renderVinextBuiltUrl } from "./utils/built-asset-url.js";
|
|
45
48
|
import { asyncHooksStubPlugin } from "./plugins/async-hooks-stub.js";
|
|
46
49
|
import { clientReferenceDedupPlugin } from "./plugins/client-reference-dedup.js";
|
|
@@ -49,6 +52,7 @@ import { createRscClientReferenceLoadersPlugin } from "./plugins/rsc-client-refe
|
|
|
49
52
|
import { createInstrumentationClientTransformPlugin } from "./plugins/instrumentation-client.js";
|
|
50
53
|
import { INSTRUMENTATION_CLIENT_EMPTY_MODULE, generateInstrumentationClientInjectModule } from "./client/instrumentation-client-inject.js";
|
|
51
54
|
import { createMiddlewareServerOnlyPlugin } from "./plugins/middleware-server-only.js";
|
|
55
|
+
import { validateMiddlewareModuleExports } from "./plugins/middleware-export-validation.js";
|
|
52
56
|
import { createOptimizeImportsPlugin } from "./plugins/optimize-imports.js";
|
|
53
57
|
import { augmentSsrManifestFromBundle, relativeWithinRoot, tryRealpathSync } from "./build/ssr-manifest.js";
|
|
54
58
|
import { createDynamicPreloadMetadataPlugin } from "./plugins/dynamic-preload-metadata.js";
|
|
@@ -63,7 +67,7 @@ import { resolvePostcssStringPlugins } from "./plugins/postcss.js";
|
|
|
63
67
|
import { buildSassPreprocessorOptions, createSassAwareFileSystemLoader, createSassTildeImporter } from "./plugins/sass.js";
|
|
64
68
|
import { createClientAssetFileNames, createClientCodeSplittingConfig, createClientFileNameConfig, createClientManualChunks, createClientOutputConfig, createRscFrameworkChunkOutputConfig, getBuildBundlerOptions, getClientTreeshakeConfigForVite, withBuildBundlerOptions } from "./build/client-build-config.js";
|
|
65
69
|
import { markCssUrlAssetReferences, restoreDedupedCssAssetReferences } from "./build/css-url-assets.js";
|
|
66
|
-
import { hasExportAllCandidate,
|
|
70
|
+
import { hasExportAllCandidate, stripServerExports, validatePageExports } from "./plugins/strip-server-exports.js";
|
|
67
71
|
import { removeConsoleCalls } from "./plugins/remove-console.js";
|
|
68
72
|
import { createImportMetaUrlPlugin } from "./plugins/import-meta-url.js";
|
|
69
73
|
import { createRequireContextPlugin } from "./plugins/require-context.js";
|
|
@@ -84,6 +88,10 @@ import MagicString from "magic-string";
|
|
|
84
88
|
import tsconfigPaths from "vite-tsconfig-paths";
|
|
85
89
|
//#region src/index.ts
|
|
86
90
|
installSocketErrorBackstop();
|
|
91
|
+
function getCacheDirPrefix(cacheDir) {
|
|
92
|
+
const normalizedCacheDir = normalizePathSeparators(cacheDir);
|
|
93
|
+
return normalizedCacheDir.endsWith("/") ? normalizedCacheDir : `${normalizedCacheDir}/`;
|
|
94
|
+
}
|
|
87
95
|
function isInsideDirectory(dir, filePath) {
|
|
88
96
|
const relativePath = path.relative(dir, filePath);
|
|
89
97
|
return relativePath !== "" && !relativePath.startsWith("..") && !path.isAbsolute(relativePath);
|
|
@@ -300,10 +308,13 @@ const RESOLVED_ROOT_PARAMS = "\0virtual:vinext-root-params";
|
|
|
300
308
|
const RESOLVED_CACHE_ADAPTERS = "\0" + VIRTUAL_CACHE_ADAPTERS;
|
|
301
309
|
/** Virtual module for composed instrumentation-client bootstrap. */
|
|
302
310
|
const VIRTUAL_INSTRUMENTATION_CLIENT = "private-next-instrumentation-client";
|
|
303
|
-
const RESOLVED_INSTRUMENTATION_CLIENT =
|
|
311
|
+
const RESOLVED_INSTRUMENTATION_CLIENT = `${VIRTUAL_INSTRUMENTATION_CLIENT}.mjs`;
|
|
304
312
|
/** Image file extensions handled by the vinext:image-imports plugin.
|
|
305
313
|
* Shared between the Rolldown hook filter and the transform handler regex. */
|
|
306
314
|
const IMAGE_EXTS = "png|jpe?g|gif|webp|avif|svg|ico|bmp|tiff?";
|
|
315
|
+
/** Matches a trailing image extension on an import path. Built once: `IMAGE_EXTS`
|
|
316
|
+
* is constant, so there is no need to recompile this per transform invocation. */
|
|
317
|
+
const IMAGE_EXT_RE = new RegExp(`\\.(${IMAGE_EXTS})$`);
|
|
307
318
|
function createStaticImageAsset(imagePath) {
|
|
308
319
|
const source = fs.readFileSync(imagePath);
|
|
309
320
|
const extension = path.extname(imagePath);
|
|
@@ -321,6 +332,8 @@ function createStaticImageAsset(imagePath) {
|
|
|
321
332
|
*/
|
|
322
333
|
const _shimsDir = normalizePathSeparators(path.resolve(__dirname, "shims")) + "/";
|
|
323
334
|
const _fontGoogleShimPath = resolveShimModulePath(_shimsDir, "font-google");
|
|
335
|
+
const _appRscHandlerPath = resolveShimModulePath(normalizePathSeparators(path.resolve(__dirname, "server")), "app-rsc-handler");
|
|
336
|
+
const _canExternalizeAppRscHandler = _appRscHandlerPath.endsWith(".js");
|
|
324
337
|
function isValidExportIdentifier(name) {
|
|
325
338
|
return /^[$A-Z_a-z][$\w]*$/.test(name);
|
|
326
339
|
}
|
|
@@ -435,9 +448,10 @@ function vinext(options = {}) {
|
|
|
435
448
|
let rscCompatibilityId;
|
|
436
449
|
const draftModeSecret = randomUUID();
|
|
437
450
|
const sassComposesLoader = createSassAwareFileSystemLoader();
|
|
451
|
+
const typeofWindowIdFilter = { exclude: /(?!)/ };
|
|
438
452
|
let rscClassificationManifest = null;
|
|
439
|
-
const shimsDir = path.resolve(__dirname, "shims");
|
|
440
|
-
const canonicalize = (p) => tryRealpathSync(p) ?? p;
|
|
453
|
+
const shimsDir = normalizePathSeparators(path.resolve(__dirname, "shims"));
|
|
454
|
+
const canonicalize = (p) => normalizePathSeparators(tryRealpathSync(p) ?? p);
|
|
441
455
|
const pageTransformCanonicalPaths = /* @__PURE__ */ new Map();
|
|
442
456
|
const canonicalizePageTransformPath = (modulePath) => {
|
|
443
457
|
const cached = pageTransformCanonicalPaths.get(modulePath);
|
|
@@ -561,22 +575,25 @@ function vinext(options = {}) {
|
|
|
561
575
|
...viteMajorVersion >= 8 ? [{
|
|
562
576
|
name: "vinext:jsx-in-js",
|
|
563
577
|
enforce: "pre",
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
if (
|
|
569
|
-
if (
|
|
578
|
+
transform: {
|
|
579
|
+
filter: { id: /\.m?js(?:\?.*)?$/ },
|
|
580
|
+
async handler(code, id) {
|
|
581
|
+
const cleanId = id.split("?")[0];
|
|
582
|
+
if (isInsideDirectory(__dirname, cleanId)) return;
|
|
583
|
+
if (cleanId.includes("/node_modules/")) {
|
|
584
|
+
if (!code.includes("use client") && !code.includes("use server")) return;
|
|
585
|
+
if (!hasReactDirective(code)) return;
|
|
586
|
+
}
|
|
587
|
+
const result = await transformWithOxc(code, id, {
|
|
588
|
+
lang: "jsx",
|
|
589
|
+
jsx: { runtime: "automatic" },
|
|
590
|
+
sourcemap: true
|
|
591
|
+
});
|
|
592
|
+
return {
|
|
593
|
+
code: result.code,
|
|
594
|
+
map: result.map
|
|
595
|
+
};
|
|
570
596
|
}
|
|
571
|
-
const result = await transformWithOxc(code, id, {
|
|
572
|
-
lang: "jsx",
|
|
573
|
-
jsx: { runtime: "automatic" },
|
|
574
|
-
sourcemap: true
|
|
575
|
-
});
|
|
576
|
-
return {
|
|
577
|
-
code: result.code,
|
|
578
|
-
map: result.map
|
|
579
|
-
};
|
|
580
597
|
}
|
|
581
598
|
}] : [],
|
|
582
599
|
createMiddlewareServerOnlyPlugin({
|
|
@@ -642,7 +659,8 @@ function vinext(options = {}) {
|
|
|
642
659
|
fileMatcher = createValidFileMatcher(nextConfig.pageExtensions);
|
|
643
660
|
instrumentationPath = findInstrumentationFile(root, fileMatcher);
|
|
644
661
|
instrumentationClientPath = findInstrumentationClientFile(root, fileMatcher);
|
|
645
|
-
|
|
662
|
+
const middlewareConventionDir = canonicalize(baseDir) === canonicalize(path.posix.join(root, "src")) ? path.posix.join(root, "src") : root;
|
|
663
|
+
middlewarePath = findMiddlewareFile(root, fileMatcher, middlewareConventionDir);
|
|
646
664
|
const instrumentationClientInjects = nextConfig.instrumentationClientInject.map((spec) => spec.startsWith("./") || spec.startsWith("../") ? path.resolve(root, spec) : spec);
|
|
647
665
|
clientInjectModule = instrumentationClientInjects.length ? generateInstrumentationClientInjectModule(instrumentationClientInjects, instrumentationClientPath, INSTRUMENTATION_CLIENT_EMPTY_MODULE) : null;
|
|
648
666
|
if (env?.command === "build") await writeRouteTypes();
|
|
@@ -705,55 +723,55 @@ function vinext(options = {}) {
|
|
|
705
723
|
}
|
|
706
724
|
for (const key of Object.keys(nextConfig.compilerDefineServer)) if (key in defines) throw new Error(`The \`compiler.defineServer\` option is configured to replace the \`${key}\` variable. This variable is either part of a built-in or is already configured.`);
|
|
707
725
|
nextShimMap = Object.fromEntries(Object.entries({
|
|
708
|
-
"next/link": path.join(shimsDir, "link"),
|
|
709
|
-
"next/head": path.join(shimsDir, "head"),
|
|
710
|
-
"next/router": path.join(shimsDir, "router"),
|
|
711
|
-
"next/compat/router": path.join(shimsDir, "compat-router"),
|
|
712
|
-
"next/image": path.join(shimsDir, "image"),
|
|
713
|
-
"next/legacy/image": path.join(shimsDir, "legacy-image"),
|
|
714
|
-
"next/dynamic": path.join(shimsDir, "dynamic"),
|
|
715
|
-
"next/app": path.join(shimsDir, "app"),
|
|
716
|
-
"next/document": path.join(shimsDir, "document"),
|
|
717
|
-
"next/config": path.join(shimsDir, "config"),
|
|
718
|
-
"next/script": path.join(shimsDir, "script"),
|
|
719
|
-
"next/server": path.join(shimsDir, "server"),
|
|
720
|
-
"next/headers": path.join(shimsDir, "headers"),
|
|
721
|
-
"next/font/google": path.join(shimsDir, "font-google"),
|
|
722
|
-
"next/font/local": path.join(shimsDir, "font-local"),
|
|
723
|
-
"next/cache": path.join(shimsDir, "cache"),
|
|
724
|
-
"next/form": path.join(shimsDir, "form"),
|
|
725
|
-
"next/og": path.join(shimsDir, "og"),
|
|
726
|
-
"next/web-vitals": path.join(shimsDir, "web-vitals"),
|
|
727
|
-
"next/amp": path.join(shimsDir, "amp"),
|
|
728
|
-
"next/offline": path.join(shimsDir, "offline"),
|
|
729
|
-
"next/constants": path.join(shimsDir, "constants"),
|
|
730
|
-
"next/dist/shared/lib/app-router-context.shared-runtime": path.join(shimsDir, "internal", "app-router-context"),
|
|
731
|
-
"next/dist/shared/lib/app-router-context": path.join(shimsDir, "internal", "app-router-context"),
|
|
732
|
-
"next/dist/shared/lib/router-context.shared-runtime": path.join(shimsDir, "internal", "router-context"),
|
|
733
|
-
"next/dist/shared/lib/utils": path.join(shimsDir, "internal", "utils"),
|
|
734
|
-
"next/dist/server/api-utils": path.join(shimsDir, "internal", "api-utils"),
|
|
735
|
-
"next/dist/server/web/spec-extension/cookies": path.join(shimsDir, "internal", "cookies"),
|
|
736
|
-
"next/dist/compiled/@edge-runtime/cookies": path.join(shimsDir, "internal", "cookies"),
|
|
737
|
-
"next/dist/server/app-render/work-unit-async-storage.external": path.join(shimsDir, "internal", "work-unit-async-storage"),
|
|
738
|
-
"next/dist/client/components/work-unit-async-storage.external": path.join(shimsDir, "internal", "work-unit-async-storage"),
|
|
739
|
-
"next/dist/client/components/request-async-storage.external": path.join(shimsDir, "internal", "work-unit-async-storage"),
|
|
740
|
-
"next/dist/client/components/request-async-storage": path.join(shimsDir, "internal", "work-unit-async-storage"),
|
|
741
|
-
"next/dist/server/request/root-params": path.join(shimsDir, "root-params"),
|
|
742
|
-
"next/dist/server/config-shared": path.join(shimsDir, "internal", "utils"),
|
|
743
|
-
"server-only": path.join(shimsDir, "server-only"),
|
|
744
|
-
"client-only": path.join(shimsDir, "client-only"),
|
|
745
|
-
"vinext/error-boundary": path.join(shimsDir, "error-boundary"),
|
|
746
|
-
"vinext/layout-segment-context": path.join(shimsDir, "layout-segment-context"),
|
|
747
|
-
"vinext/metadata": path.join(shimsDir, "metadata"),
|
|
748
|
-
"vinext/fetch-cache": path.join(shimsDir, "fetch-cache"),
|
|
749
|
-
"vinext/cache-runtime": path.join(shimsDir, "cache-runtime"),
|
|
750
|
-
"vinext/navigation-state": path.join(shimsDir, "navigation-state"),
|
|
751
|
-
"vinext/unified-request-context": path.join(shimsDir, "unified-request-context"),
|
|
752
|
-
"vinext/pages-router-runtime": path.join(shimsDir, "pages-router-runtime"),
|
|
753
|
-
"vinext/router-state": path.join(shimsDir, "router-state"),
|
|
754
|
-
"vinext/head-state": path.join(shimsDir, "head-state"),
|
|
755
|
-
"vinext/i18n-state": path.join(shimsDir, "i18n-state"),
|
|
756
|
-
"vinext/i18n-context": path.join(shimsDir, "i18n-context"),
|
|
726
|
+
"next/link": path.posix.join(shimsDir, "link"),
|
|
727
|
+
"next/head": path.posix.join(shimsDir, "head"),
|
|
728
|
+
"next/router": path.posix.join(shimsDir, "router"),
|
|
729
|
+
"next/compat/router": path.posix.join(shimsDir, "compat-router"),
|
|
730
|
+
"next/image": path.posix.join(shimsDir, "image"),
|
|
731
|
+
"next/legacy/image": path.posix.join(shimsDir, "legacy-image"),
|
|
732
|
+
"next/dynamic": path.posix.join(shimsDir, "dynamic"),
|
|
733
|
+
"next/app": path.posix.join(shimsDir, "app"),
|
|
734
|
+
"next/document": path.posix.join(shimsDir, "document"),
|
|
735
|
+
"next/config": path.posix.join(shimsDir, "config"),
|
|
736
|
+
"next/script": path.posix.join(shimsDir, "script"),
|
|
737
|
+
"next/server": path.posix.join(shimsDir, "server"),
|
|
738
|
+
"next/headers": path.posix.join(shimsDir, "headers"),
|
|
739
|
+
"next/font/google": path.posix.join(shimsDir, "font-google"),
|
|
740
|
+
"next/font/local": path.posix.join(shimsDir, "font-local"),
|
|
741
|
+
"next/cache": path.posix.join(shimsDir, "cache"),
|
|
742
|
+
"next/form": path.posix.join(shimsDir, "form"),
|
|
743
|
+
"next/og": path.posix.join(shimsDir, "og"),
|
|
744
|
+
"next/web-vitals": path.posix.join(shimsDir, "web-vitals"),
|
|
745
|
+
"next/amp": path.posix.join(shimsDir, "amp"),
|
|
746
|
+
"next/offline": path.posix.join(shimsDir, "offline"),
|
|
747
|
+
"next/constants": path.posix.join(shimsDir, "constants"),
|
|
748
|
+
"next/dist/shared/lib/app-router-context.shared-runtime": path.posix.join(shimsDir, "internal", "app-router-context"),
|
|
749
|
+
"next/dist/shared/lib/app-router-context": path.posix.join(shimsDir, "internal", "app-router-context"),
|
|
750
|
+
"next/dist/shared/lib/router-context.shared-runtime": path.posix.join(shimsDir, "internal", "router-context"),
|
|
751
|
+
"next/dist/shared/lib/utils": path.posix.join(shimsDir, "internal", "utils"),
|
|
752
|
+
"next/dist/server/api-utils": path.posix.join(shimsDir, "internal", "api-utils"),
|
|
753
|
+
"next/dist/server/web/spec-extension/cookies": path.posix.join(shimsDir, "internal", "cookies"),
|
|
754
|
+
"next/dist/compiled/@edge-runtime/cookies": path.posix.join(shimsDir, "internal", "cookies"),
|
|
755
|
+
"next/dist/server/app-render/work-unit-async-storage.external": path.posix.join(shimsDir, "internal", "work-unit-async-storage"),
|
|
756
|
+
"next/dist/client/components/work-unit-async-storage.external": path.posix.join(shimsDir, "internal", "work-unit-async-storage"),
|
|
757
|
+
"next/dist/client/components/request-async-storage.external": path.posix.join(shimsDir, "internal", "work-unit-async-storage"),
|
|
758
|
+
"next/dist/client/components/request-async-storage": path.posix.join(shimsDir, "internal", "work-unit-async-storage"),
|
|
759
|
+
"next/dist/server/request/root-params": path.posix.join(shimsDir, "root-params"),
|
|
760
|
+
"next/dist/server/config-shared": path.posix.join(shimsDir, "internal", "utils"),
|
|
761
|
+
"server-only": path.posix.join(shimsDir, "server-only"),
|
|
762
|
+
"client-only": path.posix.join(shimsDir, "client-only"),
|
|
763
|
+
"vinext/error-boundary": path.posix.join(shimsDir, "error-boundary"),
|
|
764
|
+
"vinext/layout-segment-context": path.posix.join(shimsDir, "layout-segment-context"),
|
|
765
|
+
"vinext/metadata": path.posix.join(shimsDir, "metadata"),
|
|
766
|
+
"vinext/fetch-cache": path.posix.join(shimsDir, "fetch-cache"),
|
|
767
|
+
"vinext/cache-runtime": path.posix.join(shimsDir, "cache-runtime"),
|
|
768
|
+
"vinext/navigation-state": path.posix.join(shimsDir, "navigation-state"),
|
|
769
|
+
"vinext/unified-request-context": path.posix.join(shimsDir, "unified-request-context"),
|
|
770
|
+
"vinext/pages-router-runtime": path.posix.join(shimsDir, "pages-router-runtime"),
|
|
771
|
+
"vinext/router-state": path.posix.join(shimsDir, "router-state"),
|
|
772
|
+
"vinext/head-state": path.posix.join(shimsDir, "head-state"),
|
|
773
|
+
"vinext/i18n-state": path.posix.join(shimsDir, "i18n-state"),
|
|
774
|
+
"vinext/i18n-context": path.posix.join(shimsDir, "i18n-context"),
|
|
757
775
|
"vinext/cache": path.resolve(__dirname, "cache"),
|
|
758
776
|
"vinext/instrumentation": path.resolve(__dirname, "server", "instrumentation"),
|
|
759
777
|
"vinext/instrumentation-client": path.resolve(__dirname, "client", "instrumentation-client"),
|
|
@@ -905,6 +923,7 @@ function vinext(options = {}) {
|
|
|
905
923
|
"satori",
|
|
906
924
|
"@resvg/resvg-js",
|
|
907
925
|
"yoga-wasm-web",
|
|
926
|
+
...env?.command === "serve" && _canExternalizeAppRscHandler ? ["vinext/server/app-rsc-handler"] : [],
|
|
908
927
|
...userSsrExternal
|
|
909
928
|
],
|
|
910
929
|
...userSsrExternal === true ? {} : { noExternal: true }
|
|
@@ -1031,6 +1050,8 @@ function vinext(options = {}) {
|
|
|
1031
1050
|
return null;
|
|
1032
1051
|
},
|
|
1033
1052
|
async configResolved(config) {
|
|
1053
|
+
const cacheDirPrefix = getCacheDirPrefix(config.cacheDir);
|
|
1054
|
+
typeofWindowIdFilter.exclude = new RegExp(`^${escapeRegExp(cacheDirPrefix)}`);
|
|
1034
1055
|
sassComposesLoader.setResolvedConfig(config);
|
|
1035
1056
|
if (config.command === "build" && hasAppDir && hasPagesDir) {
|
|
1036
1057
|
const [appRoutes, pageRoutes, apiRoutes] = await Promise.all([
|
|
@@ -1067,9 +1088,16 @@ function vinext(options = {}) {
|
|
|
1067
1088
|
}));
|
|
1068
1089
|
},
|
|
1069
1090
|
resolveId: {
|
|
1070
|
-
filter: { id: /(?:next\/|vinext\/shims\/|virtual:vinext-|@vercel\/og(?:\.js)?$)/ },
|
|
1091
|
+
filter: { id: /(?:next\/|vinext\/(?:shims\/|server\/app-rsc-handler)|virtual:vinext-|@vercel\/og(?:\.js)?$)/ },
|
|
1071
1092
|
handler(id, importer) {
|
|
1072
1093
|
const cleanId = id.startsWith("\0") ? id.slice(1) : id;
|
|
1094
|
+
if (cleanId === "vinext/server/app-rsc-handler") {
|
|
1095
|
+
if (_canExternalizeAppRscHandler && this.environment?.name === "rsc" && this.environment.config?.command === "serve") return {
|
|
1096
|
+
id: _appRscHandlerPath,
|
|
1097
|
+
external: true
|
|
1098
|
+
};
|
|
1099
|
+
return _appRscHandlerPath;
|
|
1100
|
+
}
|
|
1073
1101
|
if (isVercelOgImport(cleanId) && !isVinextOgShimImporter(importer)) return resolveShimModulePath(_shimsDir, "og");
|
|
1074
1102
|
if (cleanId.startsWith("vinext/shims/")) return resolveShimModulePath(_shimsDir, stripJsExtension(stripViteModuleQuery(cleanId.slice(13))));
|
|
1075
1103
|
if (cleanId === VIRTUAL_SERVER_ENTRY) return RESOLVED_SERVER_ENTRY;
|
|
@@ -1188,14 +1216,19 @@ function vinext(options = {}) {
|
|
|
1188
1216
|
name: "vinext:css-url-assets-mark",
|
|
1189
1217
|
enforce: "pre",
|
|
1190
1218
|
apply: "build",
|
|
1191
|
-
transform
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1219
|
+
transform: {
|
|
1220
|
+
filter: {
|
|
1221
|
+
id: /\.(?:css|scss|sass|less|styl|stylus)(?:\?|$)/i,
|
|
1222
|
+
code: "url("
|
|
1223
|
+
},
|
|
1224
|
+
handler(code, id) {
|
|
1225
|
+
const marked = markCssUrlAssetReferences(code, id);
|
|
1226
|
+
if (marked === null) return null;
|
|
1227
|
+
return {
|
|
1228
|
+
code: marked,
|
|
1229
|
+
map: null
|
|
1230
|
+
};
|
|
1231
|
+
}
|
|
1199
1232
|
}
|
|
1200
1233
|
},
|
|
1201
1234
|
{
|
|
@@ -1220,7 +1253,6 @@ function vinext(options = {}) {
|
|
|
1220
1253
|
enforce: "post",
|
|
1221
1254
|
apply: "build",
|
|
1222
1255
|
generateBundle(_options, bundle) {
|
|
1223
|
-
if (this.environment?.name !== "client") return;
|
|
1224
1256
|
restoreDedupedCssAssetReferences(bundle, (asset) => {
|
|
1225
1257
|
this.emitFile({
|
|
1226
1258
|
type: "asset",
|
|
@@ -1298,18 +1330,20 @@ function vinext(options = {}) {
|
|
|
1298
1330
|
`export const addTransitionType = _React.addTransitionType || function addTransitionType() {};`
|
|
1299
1331
|
].join("\n");
|
|
1300
1332
|
},
|
|
1301
|
-
transform
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1333
|
+
transform: {
|
|
1334
|
+
filter: {
|
|
1335
|
+
id: {
|
|
1336
|
+
include: /\.(tsx?|jsx?|mjs)$/,
|
|
1337
|
+
exclude: [/node_modules/, VIRTUAL_MODULE_ID_RE]
|
|
1338
|
+
},
|
|
1339
|
+
code: /import\s*\{[^}]*(ViewTransition|addTransitionType)[^}]*\}\s*from\s*['"]react['"]/
|
|
1340
|
+
},
|
|
1341
|
+
handler(code) {
|
|
1342
|
+
return {
|
|
1343
|
+
code: code.replace(/from\s*['"]react['"]/g, "from \"virtual:vinext-react-canary\""),
|
|
1344
|
+
map: null
|
|
1345
|
+
};
|
|
1346
|
+
}
|
|
1313
1347
|
}
|
|
1314
1348
|
},
|
|
1315
1349
|
{
|
|
@@ -1827,51 +1861,71 @@ function vinext(options = {}) {
|
|
|
1827
1861
|
}
|
|
1828
1862
|
},
|
|
1829
1863
|
{
|
|
1830
|
-
name: "vinext:validate-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
if (!
|
|
1864
|
+
name: "vinext:validate-middleware-exports",
|
|
1865
|
+
enforce: "pre",
|
|
1866
|
+
transform(code, id) {
|
|
1867
|
+
if (!middlewarePath) return null;
|
|
1834
1868
|
const modulePath = stripViteModuleQuery(id);
|
|
1835
|
-
if (
|
|
1836
|
-
|
|
1837
|
-
if (!isWithinPagesDirectory(canonicalId)) return null;
|
|
1838
|
-
if (!fileMatcher.isPageFile(canonicalId)) return null;
|
|
1839
|
-
if (isApiPage(canonicalId)) return null;
|
|
1840
|
-
validatePageExports(code);
|
|
1869
|
+
if (canonicalize(modulePath) !== canonicalize(middlewarePath)) return null;
|
|
1870
|
+
validateMiddlewareModuleExports(code, modulePath, middlewarePath, isProxyFile(middlewarePath));
|
|
1841
1871
|
return null;
|
|
1842
|
-
}
|
|
1872
|
+
}
|
|
1873
|
+
},
|
|
1874
|
+
{
|
|
1875
|
+
name: "vinext:validate-page-exports",
|
|
1876
|
+
transform: {
|
|
1877
|
+
filter: {
|
|
1878
|
+
id: { exclude: VIRTUAL_MODULE_ID_RE },
|
|
1879
|
+
code: /\bexport\b[\s\S]*\*/
|
|
1880
|
+
},
|
|
1881
|
+
handler(code, id) {
|
|
1882
|
+
if (this.environment?.name !== "client") return null;
|
|
1883
|
+
if (!hasPagesDir || !hasExportAllCandidate(code)) return null;
|
|
1884
|
+
const modulePath = stripViteModuleQuery(id);
|
|
1885
|
+
if (!isWithinPagesDirectory(modulePath)) return null;
|
|
1886
|
+
const canonicalId = canonicalizePageTransformPath(modulePath);
|
|
1887
|
+
if (!isWithinPagesDirectory(canonicalId)) return null;
|
|
1888
|
+
if (!fileMatcher.isPageFile(canonicalId)) return null;
|
|
1889
|
+
if (isApiPage(canonicalId)) return null;
|
|
1890
|
+
validatePageExports(code);
|
|
1891
|
+
return null;
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1843
1894
|
},
|
|
1844
1895
|
{
|
|
1845
1896
|
name: "vinext:strip-server-exports",
|
|
1846
|
-
transform: {
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1897
|
+
transform: {
|
|
1898
|
+
filter: {
|
|
1899
|
+
id: { exclude: VIRTUAL_MODULE_ID_RE },
|
|
1900
|
+
code: /getServerSideProps|getStaticProps|getStaticPaths|unstable_getServerProps|unstable_getServerSideProps|unstable_getStaticProps|unstable_getStaticPaths/
|
|
1901
|
+
},
|
|
1902
|
+
handler(code, id) {
|
|
1903
|
+
if (this.environment?.name !== "client") return null;
|
|
1904
|
+
if (!hasPagesDir) return null;
|
|
1905
|
+
const modulePath = stripViteModuleQuery(id);
|
|
1906
|
+
if (!isWithinPagesDirectory(modulePath)) return null;
|
|
1907
|
+
const canonicalId = canonicalizePageTransformPath(modulePath);
|
|
1908
|
+
if (!isWithinPagesDirectory(canonicalId)) return null;
|
|
1909
|
+
if (!fileMatcher.isPageFile(canonicalId)) return null;
|
|
1910
|
+
const relativePath = canonicalId.slice(canonicalPagesDir.length);
|
|
1911
|
+
if (isApiPage(canonicalId)) return null;
|
|
1912
|
+
if (/^\/(?:_app|_document|_error)(?:\.[^/]*)?$/.test(relativePath)) return null;
|
|
1913
|
+
return stripServerExports(code);
|
|
1914
|
+
}
|
|
1915
|
+
}
|
|
1864
1916
|
},
|
|
1865
1917
|
{
|
|
1866
1918
|
name: "vinext:validate-server-only-client-imports",
|
|
1867
1919
|
transform: {
|
|
1868
1920
|
filter: {
|
|
1869
|
-
id:
|
|
1921
|
+
id: {
|
|
1922
|
+
include: /\.(tsx?|jsx?|mjs)$/,
|
|
1923
|
+
exclude: VIRTUAL_MODULE_ID_RE
|
|
1924
|
+
},
|
|
1870
1925
|
code: "server-only"
|
|
1871
1926
|
},
|
|
1872
|
-
handler(code
|
|
1927
|
+
handler(code) {
|
|
1873
1928
|
if (this.environment?.name !== "client") return null;
|
|
1874
|
-
if (id.startsWith("\0")) return null;
|
|
1875
1929
|
if (getLeadingReactDirective(code) === "use server") return null;
|
|
1876
1930
|
if (!hasServerOnlyMarkerImport(code)) return null;
|
|
1877
1931
|
throw new Error(`You're importing a module that depends on "server-only". This API is only available in Server Components in the App Router, but this module is reachable from a client bundle.`);
|
|
@@ -1882,17 +1936,17 @@ function vinext(options = {}) {
|
|
|
1882
1936
|
name: "vinext:remove-console",
|
|
1883
1937
|
apply: "build",
|
|
1884
1938
|
transform: {
|
|
1885
|
-
filter: {
|
|
1886
|
-
|
|
1939
|
+
filter: {
|
|
1940
|
+
id: {
|
|
1941
|
+
include: /\.(tsx?|jsx?|mjs)$/,
|
|
1942
|
+
exclude: /\/node_modules\//
|
|
1943
|
+
},
|
|
1944
|
+
code: /\bconsole\b/
|
|
1945
|
+
},
|
|
1946
|
+
handler(code) {
|
|
1887
1947
|
if (this.environment?.name !== "client") return null;
|
|
1888
1948
|
if (!nextConfig.removeConsole) return null;
|
|
1889
|
-
|
|
1890
|
-
const result = removeConsoleCalls(code, nextConfig.removeConsole);
|
|
1891
|
-
if (!result) return null;
|
|
1892
|
-
return {
|
|
1893
|
-
code: result,
|
|
1894
|
-
map: null
|
|
1895
|
-
};
|
|
1949
|
+
return removeConsoleCalls(code, nextConfig.removeConsole);
|
|
1896
1950
|
}
|
|
1897
1951
|
}
|
|
1898
1952
|
},
|
|
@@ -1900,8 +1954,13 @@ function vinext(options = {}) {
|
|
|
1900
1954
|
name: "vinext:typeof-window",
|
|
1901
1955
|
enforce: "post",
|
|
1902
1956
|
transform: {
|
|
1903
|
-
filter: {
|
|
1904
|
-
|
|
1957
|
+
filter: {
|
|
1958
|
+
id: typeofWindowIdFilter,
|
|
1959
|
+
code: /typeof\s+window/
|
|
1960
|
+
},
|
|
1961
|
+
handler(code, id) {
|
|
1962
|
+
const cacheDirPrefix = getCacheDirPrefix(this.environment.config.cacheDir);
|
|
1963
|
+
if (normalizePathSeparators(id).startsWith(cacheDirPrefix)) return null;
|
|
1905
1964
|
return replaceTypeofWindow(code, getTypeofWindowReplacement(this.environment));
|
|
1906
1965
|
}
|
|
1907
1966
|
}
|
|
@@ -1926,9 +1985,10 @@ function vinext(options = {}) {
|
|
|
1926
1985
|
staticImageAssets.clear();
|
|
1927
1986
|
},
|
|
1928
1987
|
watchChange(id) {
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1988
|
+
const key = normalizePathSeparators(id);
|
|
1989
|
+
imageImportDimCache.delete(key);
|
|
1990
|
+
staticImageAssets.delete(key);
|
|
1991
|
+
staticImageImportsByModule.delete(key);
|
|
1932
1992
|
},
|
|
1933
1993
|
resolveId: {
|
|
1934
1994
|
filter: { id: /\?vinext-(?:image-url|meta)$/ },
|
|
@@ -1973,15 +2033,11 @@ function vinext(options = {}) {
|
|
|
1973
2033
|
filter: {
|
|
1974
2034
|
id: {
|
|
1975
2035
|
include: /\.(tsx?|jsx?|mjs)$/,
|
|
1976
|
-
exclude: /node_modules
|
|
2036
|
+
exclude: [/node_modules/, VIRTUAL_MODULE_ID_RE]
|
|
1977
2037
|
},
|
|
1978
2038
|
code: new RegExp(`import\\s+\\w+\\s+from\\s+['"][^'"]+\\.(${IMAGE_EXTS})['"]`)
|
|
1979
2039
|
},
|
|
1980
2040
|
async handler(code, id) {
|
|
1981
|
-
if (id.includes("node_modules")) return null;
|
|
1982
|
-
if (id.startsWith("\0")) return null;
|
|
1983
|
-
if (!id.match(/\.(tsx?|jsx?|mjs)$/)) return null;
|
|
1984
|
-
const imageExtRe = new RegExp(`\\.(${IMAGE_EXTS})$`);
|
|
1985
2041
|
const lang = id.endsWith(".ts") ? "ts" : "tsx";
|
|
1986
2042
|
let ast;
|
|
1987
2043
|
try {
|
|
@@ -1997,7 +2053,7 @@ function vinext(options = {}) {
|
|
|
1997
2053
|
const importNode = node;
|
|
1998
2054
|
const importPath = importNode.source?.value;
|
|
1999
2055
|
if (typeof importPath !== "string") continue;
|
|
2000
|
-
if (!
|
|
2056
|
+
if (!IMAGE_EXT_RE.test(importPath)) continue;
|
|
2001
2057
|
const specifiers = importNode.specifiers ?? [];
|
|
2002
2058
|
if (specifiers.length !== 1) continue;
|
|
2003
2059
|
const specifier = specifiers[0];
|
|
@@ -2005,7 +2061,9 @@ function vinext(options = {}) {
|
|
|
2005
2061
|
const varName = specifier.local?.name;
|
|
2006
2062
|
if (!varName) continue;
|
|
2007
2063
|
const dir = path.dirname(id);
|
|
2008
|
-
const
|
|
2064
|
+
const resolvedImage = importPath.startsWith(".") ? path.resolve(dir, importPath) : (await this.resolve(importPath, id, { skipSelf: true }))?.id;
|
|
2065
|
+
if (!resolvedImage) continue;
|
|
2066
|
+
const absImagePath = normalizePathSeparators(resolvedImage.split("?", 1)[0]);
|
|
2009
2067
|
if (!fs.existsSync(absImagePath)) continue;
|
|
2010
2068
|
imageImports.add(absImagePath);
|
|
2011
2069
|
const urlVar = `__vinext_img_url_${varName}`;
|
|
@@ -2058,15 +2116,11 @@ function vinext(options = {}) {
|
|
|
2058
2116
|
filter: {
|
|
2059
2117
|
id: {
|
|
2060
2118
|
include: /\.(tsx?|jsx?|mjs)$/,
|
|
2061
|
-
exclude: /node_modules
|
|
2119
|
+
exclude: [/node_modules/, VIRTUAL_MODULE_ID_RE]
|
|
2062
2120
|
},
|
|
2063
2121
|
code: "use cache"
|
|
2064
2122
|
},
|
|
2065
2123
|
async handler(code, id) {
|
|
2066
|
-
if (id.includes("node_modules")) return null;
|
|
2067
|
-
if (id.startsWith("\0")) return null;
|
|
2068
|
-
if (!id.match(/\.(tsx?|jsx?|mjs)$/)) return null;
|
|
2069
|
-
if (!code.includes("use cache")) return null;
|
|
2070
2124
|
const ast = parseAst(code);
|
|
2071
2125
|
const cacheDirective = ast.body.find((node) => node.type === "ExpressionStatement" && node.expression?.type === "Literal" && typeof node.expression.value === "string" && node.expression.value.startsWith("use cache"));
|
|
2072
2126
|
function nodeHasInlineCacheDirective(node) {
|
|
@@ -2463,54 +2517,56 @@ function vinext(options = {}) {
|
|
|
2463
2517
|
{
|
|
2464
2518
|
name: "vinext:og-font-patch",
|
|
2465
2519
|
enforce: "pre",
|
|
2466
|
-
transform
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2520
|
+
transform: {
|
|
2521
|
+
filter: { id: /@vercel\/og.*index\.edge\.js/ },
|
|
2522
|
+
handler(code, id) {
|
|
2523
|
+
let result = code;
|
|
2524
|
+
const yogaMatch = /H = "data:application\/octet-stream;base64,([A-Za-z0-9+/]+=*)";/.exec(result);
|
|
2525
|
+
if (yogaMatch) {
|
|
2526
|
+
const yogaBase64 = yogaMatch[1];
|
|
2527
|
+
const distDir = path.dirname(id);
|
|
2528
|
+
const yogaWasmPath = path.join(distDir, "yoga.wasm");
|
|
2529
|
+
if (!fs.existsSync(yogaWasmPath)) fs.writeFileSync(yogaWasmPath, Buffer.from(yogaBase64, "base64"));
|
|
2530
|
+
result = result.replace(yogaMatch[0], `H = "";`);
|
|
2531
|
+
const YOGA_CALL = `yoga_wasm_base64_esm_default()`;
|
|
2532
|
+
const YOGA_CALL_PATCHED = [
|
|
2533
|
+
`yoga_wasm_base64_esm_default({ instantiateWasm: function(imports, callback) {`,
|
|
2534
|
+
` __vi_yoga_mod.then(function(mod) {`,
|
|
2535
|
+
` if (mod) {`,
|
|
2536
|
+
` WebAssembly.instantiate(mod, imports).then(function(inst) { callback(inst); });`,
|
|
2537
|
+
` } else {`,
|
|
2538
|
+
` Promise.all([import("node:fs"), import("node:url")]).then(function(mods) {`,
|
|
2539
|
+
` var p = mods[1].fileURLToPath(new URL("./yoga.wasm", import.meta.url));`,
|
|
2540
|
+
` return mods[0].promises.readFile(p).then(function(bytes) {`,
|
|
2541
|
+
` return WebAssembly.instantiate(bytes, imports).then(function(r) { callback(r.instance); });`,
|
|
2542
|
+
` });`,
|
|
2543
|
+
` });`,
|
|
2544
|
+
` }`,
|
|
2545
|
+
` });`,
|
|
2546
|
+
` return {};`,
|
|
2547
|
+
`} })`
|
|
2548
|
+
].join("\n");
|
|
2549
|
+
result = result.replace(YOGA_CALL, YOGA_CALL_PATCHED);
|
|
2550
|
+
result = [`var __vi_yoga_mod = import("./yoga.wasm?module").then(function(m) { return m.default; }).catch(function() { return null; });`].join("\n") + "\n" + result;
|
|
2551
|
+
}
|
|
2552
|
+
const resvgMatch = /import\s+resvg_wasm\s+from\s+["']\.\/resvg\.wasm\?module["']\s*;?/.exec(result);
|
|
2553
|
+
if (resvgMatch) {
|
|
2554
|
+
const resvgLoader = [
|
|
2555
|
+
`var resvg_wasm = import("./resvg.wasm?module").then(function(m) { return m.default; }).catch(function() {`,
|
|
2556
|
+
` return Promise.all([import("node:fs"), import("node:url")]).then(function(mods) {`,
|
|
2557
|
+
` var p = mods[1].fileURLToPath(new URL("./resvg.wasm", import.meta.url));`,
|
|
2558
|
+
` return mods[0].promises.readFile(p).then(function(buf) { return WebAssembly.compile(buf); });`,
|
|
2559
|
+
` });`,
|
|
2560
|
+
`});`
|
|
2561
|
+
].join("\n");
|
|
2562
|
+
result = result.replace(resvgMatch[0], resvgLoader);
|
|
2563
|
+
}
|
|
2564
|
+
if (result === code) return null;
|
|
2565
|
+
return {
|
|
2566
|
+
code: result,
|
|
2567
|
+
map: null
|
|
2568
|
+
};
|
|
2508
2569
|
}
|
|
2509
|
-
if (result === code) return null;
|
|
2510
|
-
return {
|
|
2511
|
-
code: result,
|
|
2512
|
-
map: null
|
|
2513
|
-
};
|
|
2514
2570
|
}
|
|
2515
2571
|
}
|
|
2516
2572
|
];
|