@reckona/mreact-router 0.0.153 → 0.0.154
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/dist/build.d.ts.map +1 -1
- package/dist/build.js +66 -2
- package/dist/build.js.map +1 -1
- package/dist/module-runner.d.ts +6 -0
- package/dist/module-runner.d.ts.map +1 -1
- package/dist/module-runner.js +71 -0
- package/dist/module-runner.js.map +1 -1
- package/dist/render.d.ts +6 -0
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +40 -6
- package/dist/render.js.map +1 -1
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +1 -0
- package/dist/vite.js.map +1 -1
- package/package.json +11 -11
- package/src/build.ts +99 -1
- package/src/module-runner.ts +91 -0
- package/src/render.ts +71 -6
- package/src/vite.ts +1 -0
package/dist/build.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAsDA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAGL,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EAG1B,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAGnD,OAAO,EAAqC,KAAK,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAiCnG,OAAO,KAAK,EAAU,YAAY,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAa7D,MAAM,WAAW,eAAgB,SAAQ,uBAAuB;IAC9D,eAAe,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,qBAAqB,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IACvE,kBA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
|
|
8
8
|
import { transformCompilerModuleContext } from "@reckona/mreact-compiler/internal";
|
|
9
9
|
import { compilerModuleContextForSource, collectClientRouteReferences, createClientRouteInferenceCache, detectClientNavigationHint, formatClientRouteInferenceDiagnostic, inferClientRouteModule, navigationRuntimeLinkDisabledDiagnostic, resolveNavigationRuntime, } from "./client-route-inference.js";
|
|
10
10
|
import { buildClientRouteBatchOutput, buildNavigationRuntimeBundle, clientScriptForPath, routeIdForPath, } from "./navigation-runtime.js";
|
|
11
|
-
import { bundleAppRouterSourceModule, fileImportMetaUrlPlugin, importAppRouterSourceModule, } from "./module-runner.js";
|
|
11
|
+
import { COMPAT_VENDOR_PLACEHOLDER_PREFIX, bundleAppRouterSourceModule, fileImportMetaUrlPlugin, importAppRouterSourceModule, resolveCompatVendorEntryFiles, sourceReferencesCompatVendorSpecifier, } from "./module-runner.js";
|
|
12
12
|
import { scanAppRoutes } from "./routes.js";
|
|
13
13
|
import { appFileConventionForRootFilename } from "./file-conventions.js";
|
|
14
14
|
import { resolveAppRouterProjectOptions, resolveBuildTargets, } from "./config.js";
|
|
@@ -562,6 +562,60 @@ async function buildPublicAssetManifest(project, clientDir) {
|
|
|
562
562
|
]);
|
|
563
563
|
return [...new Set([...publicAssetPaths, ...appConventionPublicAssets])].sort();
|
|
564
564
|
}
|
|
565
|
+
const COMPAT_VENDOR_PLACEHOLDER_IMPORT_PATTERN = /(["'])mreact-compat-vendor:([\w-]+)\1/gu;
|
|
566
|
+
function rewriteCompatVendorPlaceholderImports(code) {
|
|
567
|
+
if (!code.includes(COMPAT_VENDOR_PLACEHOLDER_PREFIX)) {
|
|
568
|
+
return code;
|
|
569
|
+
}
|
|
570
|
+
// Module files live in server-modules/code/, vendor chunks in
|
|
571
|
+
// server-modules/chunks/, so the relative path is stable.
|
|
572
|
+
return code.replace(COMPAT_VENDOR_PLACEHOLDER_IMPORT_PATTERN, (_match, quote, entry) => `${quote}../chunks/compat.${entry}.mjs${quote}`);
|
|
573
|
+
}
|
|
574
|
+
function collectCompatVendorEntryUsage(artifacts) {
|
|
575
|
+
const usedEntries = new Set();
|
|
576
|
+
for (const [, artifact] of artifacts) {
|
|
577
|
+
for (const output of [artifact.string, artifact.stream]) {
|
|
578
|
+
const bundleCode = output?.bundleCode;
|
|
579
|
+
if (bundleCode === undefined || !bundleCode.includes(COMPAT_VENDOR_PLACEHOLDER_PREFIX)) {
|
|
580
|
+
continue;
|
|
581
|
+
}
|
|
582
|
+
for (const match of bundleCode.matchAll(COMPAT_VENDOR_PLACEHOLDER_IMPORT_PATTERN)) {
|
|
583
|
+
const entry = match[2];
|
|
584
|
+
if (entry !== undefined) {
|
|
585
|
+
usedEntries.add(entry);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
return usedEntries;
|
|
591
|
+
}
|
|
592
|
+
// Bundles the react-compat server runtime once per build into shared chunks
|
|
593
|
+
// under server-modules/chunks/ so per-route server modules can import it via
|
|
594
|
+
// relative paths instead of inlining their own copy.
|
|
595
|
+
async function writeCompatVendorChunks(serverDir, usedEntries) {
|
|
596
|
+
const entryFiles = resolveCompatVendorEntryFiles(serverDir);
|
|
597
|
+
const entries = await Promise.all([...entryFiles]
|
|
598
|
+
.filter(([name]) => usedEntries.has(name))
|
|
599
|
+
.map(async ([name, filename]) => ({
|
|
600
|
+
code: await readFile(filename, "utf8"),
|
|
601
|
+
filename,
|
|
602
|
+
name,
|
|
603
|
+
})));
|
|
604
|
+
const firstEntry = entries[0];
|
|
605
|
+
if (firstEntry === undefined) {
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
const output = await bundleRouterModules({
|
|
609
|
+
chunkFileNames: "compat-shared.[hash].mjs",
|
|
610
|
+
entries,
|
|
611
|
+
entryFileNames: "compat.[name].mjs",
|
|
612
|
+
platform: "node",
|
|
613
|
+
root: dirname(firstEntry.filename),
|
|
614
|
+
});
|
|
615
|
+
const chunksDir = join(serverDir, "server-modules", "chunks");
|
|
616
|
+
await mkdir(chunksDir, { recursive: true });
|
|
617
|
+
await Promise.all(output.chunks.map((chunk) => writeFile(join(chunksDir, chunk.fileName), chunk.code)));
|
|
618
|
+
}
|
|
565
619
|
async function writeServerModuleArtifactFiles(serverDir, serverModules, portableRuntimePackages = []) {
|
|
566
620
|
const files = {};
|
|
567
621
|
const renderFiles = {};
|
|
@@ -574,6 +628,10 @@ async function writeServerModuleArtifactFiles(serverDir, serverModules, portable
|
|
|
574
628
|
mkdir(join(modulesDir, "request"), { recursive: true }),
|
|
575
629
|
mkdir(join(modulesDir, "render"), { recursive: true }),
|
|
576
630
|
]);
|
|
631
|
+
const usedCompatVendorEntries = collectCompatVendorEntryUsage(artifactEntries);
|
|
632
|
+
if (usedCompatVendorEntries.size > 0) {
|
|
633
|
+
await writeCompatVendorChunks(serverDir, usedCompatVendorEntries);
|
|
634
|
+
}
|
|
577
635
|
const writtenArtifacts = await mapWithBuildConcurrency(artifactEntries, async ([file, artifact]) => {
|
|
578
636
|
const externalized = await externalizeServerModuleArtifactCode(serverDir, artifact, portableRuntimePackages);
|
|
579
637
|
const requestArtifact = requestServerModuleArtifact(externalized);
|
|
@@ -639,7 +697,7 @@ async function externalizeServerModuleOutputCode(serverDir, output, kind, portab
|
|
|
639
697
|
const sourceCode = kind === "bundle" ? output.bundleCode : output.code;
|
|
640
698
|
const moduleCode = sourceCode === undefined
|
|
641
699
|
? undefined
|
|
642
|
-
: rewritePortableRuntimePackageImports(sourceCode, portableRuntimePackages);
|
|
700
|
+
: rewriteCompatVendorPlaceholderImports(rewritePortableRuntimePackageImports(sourceCode, portableRuntimePackages));
|
|
643
701
|
if (moduleCode === undefined || moduleCode.length === 0) {
|
|
644
702
|
return output;
|
|
645
703
|
}
|
|
@@ -1188,6 +1246,10 @@ function routePathFromParams(route, params) {
|
|
|
1188
1246
|
}
|
|
1189
1247
|
async function buildServerModuleArtifacts(options) {
|
|
1190
1248
|
const routeByFile = new Map(options.routes.map((route) => [relative(options.projectRoot, route.file), route]));
|
|
1249
|
+
// One shared compat vendor chunk set replaces per-route inlining whenever
|
|
1250
|
+
// any app source references the react/compat specifier family.
|
|
1251
|
+
const externalizeCompatVendor = options.prebundleServerComponents &&
|
|
1252
|
+
Object.values(options.files).some(sourceReferencesCompatVendorSpecifier);
|
|
1191
1253
|
const loaderArtifactFiles = new Set();
|
|
1192
1254
|
const metadataArtifactFiles = new Set();
|
|
1193
1255
|
const requestArtifactFiles = new Set();
|
|
@@ -1401,6 +1463,7 @@ async function buildServerModuleArtifacts(options) {
|
|
|
1401
1463
|
bundleCode: await buildServerComponentBundleArtifactCode({
|
|
1402
1464
|
clientRouteInferenceCache: options.clientRouteInferenceCache,
|
|
1403
1465
|
code: output.code,
|
|
1466
|
+
externalizeCompatVendor,
|
|
1404
1467
|
filename: absoluteFile,
|
|
1405
1468
|
define: options.define,
|
|
1406
1469
|
root: options.projectRoot,
|
|
@@ -1433,6 +1496,7 @@ async function buildServerComponentBundleArtifactCode(options) {
|
|
|
1433
1496
|
return await bundleAppRouterSourceModule({
|
|
1434
1497
|
code: options.code,
|
|
1435
1498
|
define: options.define,
|
|
1499
|
+
externalizeCompatVendor: options.externalizeCompatVendor,
|
|
1436
1500
|
label: `server-component:${options.filename}`,
|
|
1437
1501
|
resolveDir: dirname(options.filename),
|
|
1438
1502
|
root: options.root,
|