@teyik0/furin 0.7.0-alpha.1 → 0.7.0-alpha.2
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/elysia-aot-worker.d.ts +22 -0
- package/dist/build/elysia-aot.d.ts +1 -1
- package/dist/build/index.js +226 -142
- package/dist/cli/index.js +227 -143
- package/dist/client/link.js +10 -4
- package/dist/client/router/types.d.ts +2 -0
- package/dist/furin.js +56 -18
- package/dist/server/router/patterns.d.ts +2 -0
- package/dist/server/router/types.d.ts +1 -1
- package/package.json +1 -1
- package/src/build/elysia-aot-worker.ts +51 -0
- package/src/build/elysia-aot.ts +83 -19
- package/src/build/hydrate.ts +4 -0
- package/src/client/router/boundary-tree.tsx +12 -10
- package/src/client/router/provider.tsx +2 -2
- package/src/client/router/types.ts +2 -0
- package/src/plugin/routes.ts +25 -13
- package/src/server/render/element.tsx +14 -9
- package/src/server/router/discovery.ts +25 -9
- package/src/server/router/patterns.ts +16 -0
- package/src/server/router/types.ts +1 -1
package/dist/build/index.js
CHANGED
|
@@ -71,6 +71,12 @@ function routeSegmentToPattern(segment) {
|
|
|
71
71
|
}
|
|
72
72
|
return dynamic.catchAll ? "*" : `:${dynamic.name}`;
|
|
73
73
|
}
|
|
74
|
+
function isRouteGroup(segment) {
|
|
75
|
+
return ROUTE_GROUP_RE.test(segment);
|
|
76
|
+
}
|
|
77
|
+
function routePatternKey(pattern) {
|
|
78
|
+
return pattern.replace(DYNAMIC_ROUTE_SEGMENT_RE, "$1:param");
|
|
79
|
+
}
|
|
74
80
|
function filePathToPattern(path) {
|
|
75
81
|
const parts = path.replaceAll("\\", "/").split("/");
|
|
76
82
|
const segments = [];
|
|
@@ -82,6 +88,9 @@ function filePathToPattern(path) {
|
|
|
82
88
|
}
|
|
83
89
|
const isFile = idx === lastIndex;
|
|
84
90
|
const name = isFile ? parse(part).name : part;
|
|
91
|
+
if (!isFile && isRouteGroup(name)) {
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
85
94
|
if (isFile && name === "index") {
|
|
86
95
|
continue;
|
|
87
96
|
}
|
|
@@ -176,9 +185,11 @@ function buildRouteMatcher(routes) {
|
|
|
176
185
|
return null;
|
|
177
186
|
};
|
|
178
187
|
}
|
|
179
|
-
var DYNAMIC_PARAMETER_NAME_RE, REGEX_META_CHARS_RE;
|
|
188
|
+
var DYNAMIC_PARAMETER_NAME_RE, ROUTE_GROUP_RE, DYNAMIC_ROUTE_SEGMENT_RE, REGEX_META_CHARS_RE;
|
|
180
189
|
var init_patterns = __esm(() => {
|
|
181
190
|
DYNAMIC_PARAMETER_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
191
|
+
ROUTE_GROUP_RE = /^\([^()]+\)$/;
|
|
192
|
+
DYNAMIC_ROUTE_SEGMENT_RE = /(^|\/):[^/]+/g;
|
|
182
193
|
REGEX_META_CHARS_RE = /[.*+?^${}()|[\]\\]/;
|
|
183
194
|
});
|
|
184
195
|
|
|
@@ -6719,11 +6730,11 @@ var init_plugin2 = () => {};
|
|
|
6719
6730
|
|
|
6720
6731
|
// src/build/index.ts
|
|
6721
6732
|
import { existsSync as existsSync16, writeFileSync as writeFileSync12 } from "fs";
|
|
6722
|
-
import { join as
|
|
6733
|
+
import { join as join18, relative as relative11, resolve as resolve12 } from "path";
|
|
6723
6734
|
|
|
6724
6735
|
// src/adapter/bun.ts
|
|
6725
6736
|
import { existsSync as existsSync11, readFileSync as readFileSync8, rmSync as rmSync2, writeFileSync as writeFileSync8 } from "fs";
|
|
6726
|
-
import { join as
|
|
6737
|
+
import { join as join13, resolve as resolve9 } from "path";
|
|
6727
6738
|
|
|
6728
6739
|
// src/build/bun-build.ts
|
|
6729
6740
|
function runBunBuild(config) {
|
|
@@ -6972,11 +6983,16 @@ function prepareCompileEntryApps(options) {
|
|
|
6972
6983
|
}
|
|
6973
6984
|
|
|
6974
6985
|
// src/build/elysia-aot.ts
|
|
6975
|
-
import { dirname as dirname2, resolve } from "path";
|
|
6976
|
-
import {
|
|
6986
|
+
import { dirname as dirname2, join as join4, resolve } from "path";
|
|
6987
|
+
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
6988
|
+
import { Worker } from "worker_threads";
|
|
6977
6989
|
var AOT_NAMESPACE = "furin-elysia-aot";
|
|
6978
6990
|
var ELYSIA_RESOLVE_DIR = dirname2(Bun.resolveSync("elysia", import.meta.dir));
|
|
6991
|
+
var AOT_WORKER_PATH = join4(dirname2(dirname2(fileURLToPath3(import.meta.resolve("@teyik0/furin")))), "src/build/elysia-aot-worker.ts");
|
|
6979
6992
|
var SOURCE_FILTER = /\.[cm]?[jt]sx?$/;
|
|
6993
|
+
var ELYSIA_IMPORT_FILTER = /^elysia(?:\/(?!compiled$|type$).*)?$/;
|
|
6994
|
+
var ELYSIA_VIRTUAL_IMPORT_FILTER = /^elysia\/(?:compiled|type)$/;
|
|
6995
|
+
var ANY_MODULE_FILTER = /.*/;
|
|
6980
6996
|
var WEBSOCKET_STUB_MARKER = "[elysia-aot] WebSocket route builder was stripped (strip mode) but a WS route was used.";
|
|
6981
6997
|
function loaderFor(path) {
|
|
6982
6998
|
const extension = path.slice(path.lastIndexOf("."));
|
|
@@ -7004,44 +7020,88 @@ export function handleWSResponse(){return e()}
|
|
|
7004
7020
|
}
|
|
7005
7021
|
function elysiaAot(entry) {
|
|
7006
7022
|
const entryPath = resolve(entry);
|
|
7007
|
-
const hooks = aotFactory({ entry, strip: false, target: "bun" });
|
|
7008
7023
|
return {
|
|
7009
7024
|
name: "elysia-aot",
|
|
7010
7025
|
async setup(build) {
|
|
7026
|
+
const worker = new Worker(AOT_WORKER_PATH, { workerData: { entry: entryPath } });
|
|
7027
|
+
const pending = new Map;
|
|
7028
|
+
let nextId = 0;
|
|
7029
|
+
let workerFailure;
|
|
7030
|
+
const fail = (error) => {
|
|
7031
|
+
workerFailure = error;
|
|
7032
|
+
for (const request of pending.values()) {
|
|
7033
|
+
request.reject(error);
|
|
7034
|
+
}
|
|
7035
|
+
pending.clear();
|
|
7036
|
+
};
|
|
7037
|
+
worker.on("message", (response) => {
|
|
7038
|
+
const request = pending.get(response.id);
|
|
7039
|
+
pending.delete(response.id);
|
|
7040
|
+
if (response.ok) {
|
|
7041
|
+
request?.resolve(response);
|
|
7042
|
+
} else {
|
|
7043
|
+
request?.reject(response.error);
|
|
7044
|
+
}
|
|
7045
|
+
});
|
|
7046
|
+
worker.on("error", fail);
|
|
7047
|
+
worker.on("exit", (code) => fail(new Error(`[furin] Elysia AOT worker exited (${code}).`)));
|
|
7048
|
+
const request = (payload) => new Promise((resolveResponse, reject) => {
|
|
7049
|
+
if (workerFailure) {
|
|
7050
|
+
reject(workerFailure);
|
|
7051
|
+
return;
|
|
7052
|
+
}
|
|
7053
|
+
const id = nextId;
|
|
7054
|
+
nextId += 1;
|
|
7055
|
+
pending.set(id, { reject, resolve: resolveResponse });
|
|
7056
|
+
worker.postMessage({ ...payload, id });
|
|
7057
|
+
});
|
|
7058
|
+
let compiled;
|
|
7059
|
+
let virtualType;
|
|
7011
7060
|
try {
|
|
7012
|
-
await
|
|
7061
|
+
({ code: compiled, virtualType } = await request({ method: "start" }));
|
|
7013
7062
|
} catch (error) {
|
|
7063
|
+
await worker.terminate();
|
|
7014
7064
|
if (error instanceof Error && error.message.startsWith("[elysia-aot]") && error.message.includes("mounts a sub-app")) {
|
|
7015
7065
|
console.warn("[furin] Elysia AOT skipped because the app uses .mount().");
|
|
7016
7066
|
return;
|
|
7017
7067
|
}
|
|
7018
7068
|
throw error;
|
|
7019
7069
|
}
|
|
7070
|
+
build.onEnd(async () => {
|
|
7071
|
+
try {
|
|
7072
|
+
await request({ method: "end" });
|
|
7073
|
+
} finally {
|
|
7074
|
+
await worker.terminate();
|
|
7075
|
+
}
|
|
7076
|
+
});
|
|
7020
7077
|
const entrySource = await Bun.file(entryPath).text();
|
|
7021
|
-
const transformedEntry = await
|
|
7078
|
+
const { code: transformedEntry } = await request({
|
|
7079
|
+
code: entrySource,
|
|
7080
|
+
method: "transform",
|
|
7081
|
+
path: entryPath
|
|
7082
|
+
});
|
|
7022
7083
|
if (transformedEntry !== undefined) {
|
|
7023
7084
|
await Bun.write(entryPath, transformedEntry);
|
|
7024
7085
|
}
|
|
7025
|
-
build.onResolve({ filter:
|
|
7086
|
+
build.onResolve({ filter: ELYSIA_IMPORT_FILTER }, ({ path }) => ({
|
|
7026
7087
|
path: Bun.resolveSync(path, ELYSIA_RESOLVE_DIR)
|
|
7027
7088
|
}));
|
|
7028
|
-
build.onResolve({ filter:
|
|
7029
|
-
|
|
7030
|
-
|
|
7089
|
+
build.onResolve({ filter: ELYSIA_VIRTUAL_IMPORT_FILTER }, ({ path }) => {
|
|
7090
|
+
if (path === "elysia/type" && virtualType === undefined) {
|
|
7091
|
+
return;
|
|
7092
|
+
}
|
|
7093
|
+
return { namespace: AOT_NAMESPACE, path };
|
|
7031
7094
|
});
|
|
7032
|
-
build.onLoad({ filter:
|
|
7033
|
-
const contents =
|
|
7095
|
+
build.onLoad({ filter: ANY_MODULE_FILTER, namespace: AOT_NAMESPACE }, ({ path }) => {
|
|
7096
|
+
const contents = path === "elysia/compiled" ? compiled : virtualType;
|
|
7034
7097
|
return contents === undefined ? undefined : { contents, loader: "js", resolveDir: ELYSIA_RESOLVE_DIR };
|
|
7035
7098
|
});
|
|
7036
7099
|
build.onLoad({ filter: SOURCE_FILTER }, async ({ path }) => {
|
|
7037
7100
|
if (resolve(path) === entryPath) {
|
|
7038
7101
|
return;
|
|
7039
7102
|
}
|
|
7040
|
-
if (hooks.transformInclude?.(path) === false) {
|
|
7041
|
-
return;
|
|
7042
|
-
}
|
|
7043
7103
|
const original = await Bun.file(path).text();
|
|
7044
|
-
const transformed = await
|
|
7104
|
+
const { code: transformed } = await request({ code: original, method: "transform", path });
|
|
7045
7105
|
if (transformed === undefined) {
|
|
7046
7106
|
return;
|
|
7047
7107
|
}
|
|
@@ -7050,23 +7110,20 @@ function elysiaAot(entry) {
|
|
|
7050
7110
|
loader: loaderFor(path)
|
|
7051
7111
|
};
|
|
7052
7112
|
});
|
|
7053
|
-
build.onEnd(() => {
|
|
7054
|
-
hooks.buildEnd?.();
|
|
7055
|
-
});
|
|
7056
7113
|
}
|
|
7057
7114
|
};
|
|
7058
7115
|
}
|
|
7059
7116
|
|
|
7060
7117
|
// src/build/private-server-sourcemaps.ts
|
|
7061
7118
|
import { existsSync as existsSync4, renameSync } from "fs";
|
|
7062
|
-
import { dirname as dirname3, isAbsolute, join as
|
|
7119
|
+
import { dirname as dirname3, isAbsolute, join as join5, relative as relative2 } from "path";
|
|
7063
7120
|
function movePrivateServerSourceMaps(outputDir, privateDir, filenames) {
|
|
7064
7121
|
for (const filename of filenames) {
|
|
7065
|
-
const source = isAbsolute(filename) ? filename :
|
|
7122
|
+
const source = isAbsolute(filename) ? filename : join5(outputDir, filename);
|
|
7066
7123
|
if (!existsSync4(source)) {
|
|
7067
7124
|
continue;
|
|
7068
7125
|
}
|
|
7069
|
-
const destination =
|
|
7126
|
+
const destination = join5(privateDir, relative2(outputDir, source));
|
|
7070
7127
|
ensureDir(dirname3(destination));
|
|
7071
7128
|
renameSync(source, destination);
|
|
7072
7129
|
}
|
|
@@ -7131,7 +7188,7 @@ function productionInstrumentationPlugin() {
|
|
|
7131
7188
|
|
|
7132
7189
|
// src/build/server-app-entry.ts
|
|
7133
7190
|
import { writeFileSync } from "fs";
|
|
7134
|
-
import { join as
|
|
7191
|
+
import { join as join7 } from "path";
|
|
7135
7192
|
|
|
7136
7193
|
// src/plugin/routes.ts
|
|
7137
7194
|
import {
|
|
@@ -7142,7 +7199,7 @@ import {
|
|
|
7142
7199
|
statSync as statSync2,
|
|
7143
7200
|
watch
|
|
7144
7201
|
} from "fs";
|
|
7145
|
-
import { dirname as dirname6, extname as extname2, isAbsolute as isAbsolute3, join as
|
|
7202
|
+
import { dirname as dirname6, extname as extname2, isAbsolute as isAbsolute3, join as join6, relative as relative4, resolve as resolve4, sep } from "path";
|
|
7146
7203
|
import { pathToFileURL } from "url";
|
|
7147
7204
|
import { Elysia } from "elysia";
|
|
7148
7205
|
|
|
@@ -7606,12 +7663,13 @@ function instanceNamespace(instance) {
|
|
|
7606
7663
|
return `${ROUTES_NAMESPACE_PREFIX}-${Bun.hash(instanceKey(instance)).toString(16)}`;
|
|
7607
7664
|
}
|
|
7608
7665
|
function scanRouteFiles(directory, directorySegments, files) {
|
|
7609
|
-
|
|
7666
|
+
const entries = readdirSync2(directory, { withFileTypes: true }).sort((left, right) => left.name.localeCompare(right.name));
|
|
7667
|
+
for (const entry of entries) {
|
|
7610
7668
|
if (entry.isDirectory()) {
|
|
7611
7669
|
if (entry.name.startsWith("_")) {
|
|
7612
7670
|
continue;
|
|
7613
7671
|
}
|
|
7614
|
-
scanRouteFiles(
|
|
7672
|
+
scanRouteFiles(join6(directory, entry.name), [...directorySegments, entry.name], files);
|
|
7615
7673
|
continue;
|
|
7616
7674
|
}
|
|
7617
7675
|
const extension = extname2(entry.name);
|
|
@@ -7619,7 +7677,7 @@ function scanRouteFiles(directory, directorySegments, files) {
|
|
|
7619
7677
|
continue;
|
|
7620
7678
|
}
|
|
7621
7679
|
const base = entry.name.slice(0, -extension.length);
|
|
7622
|
-
const sourcePath =
|
|
7680
|
+
const sourcePath = join6(directory, entry.name);
|
|
7623
7681
|
for (const segment of [...directorySegments, base]) {
|
|
7624
7682
|
parseDynamicRouteSegment(segment, sourcePath);
|
|
7625
7683
|
}
|
|
@@ -7639,9 +7697,6 @@ function scanRouteFiles(directory, directorySegments, files) {
|
|
|
7639
7697
|
function segmentPath(segment) {
|
|
7640
7698
|
return routeSegmentToPattern(segment);
|
|
7641
7699
|
}
|
|
7642
|
-
function routePath(segments) {
|
|
7643
|
-
return segments.length === 0 ? "/" : `/${segments.map(segmentPath).join("/")}`;
|
|
7644
|
-
}
|
|
7645
7700
|
function routeId(instanceId, path) {
|
|
7646
7701
|
const encodedPath = Array.from(new TextEncoder().encode(path), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
7647
7702
|
return `_route_${instanceId}_${encodedPath}`;
|
|
@@ -7670,14 +7725,22 @@ function buildRouteTree(pagesDir, instanceId) {
|
|
|
7670
7725
|
return node;
|
|
7671
7726
|
};
|
|
7672
7727
|
const root = ensureNode([]);
|
|
7728
|
+
const seenPatterns = new Map;
|
|
7673
7729
|
for (const file of scannedFiles) {
|
|
7674
7730
|
const node = ensureNode(file.directorySegments);
|
|
7675
7731
|
if (file.base === "_route") {
|
|
7676
|
-
const path =
|
|
7732
|
+
const path = `/${file.directorySegments.map(segmentPath).join("/")}#layout`;
|
|
7677
7733
|
node.layout = { id: routeId(instanceId, path), path: "", sourcePath: file.sourcePath };
|
|
7678
7734
|
continue;
|
|
7679
7735
|
}
|
|
7680
|
-
const path =
|
|
7736
|
+
const path = filePathToPattern(relative4(pagesDir, file.sourcePath));
|
|
7737
|
+
const patternKey = routePatternKey(path);
|
|
7738
|
+
const relativePath = relative4(pagesDir, file.sourcePath).replaceAll("\\", "/");
|
|
7739
|
+
const previousPath = seenPatterns.get(patternKey);
|
|
7740
|
+
if (previousPath !== undefined) {
|
|
7741
|
+
throw new Error(`[furin] Duplicate route pattern "${patternKey}" from "${previousPath}" and "${relativePath}".`);
|
|
7742
|
+
}
|
|
7743
|
+
seenPatterns.set(patternKey, relativePath);
|
|
7681
7744
|
const route = { id: routeId(instanceId, path), path, sourcePath: file.sourcePath };
|
|
7682
7745
|
if (file.base === "index") {
|
|
7683
7746
|
node.indexRoute = route;
|
|
@@ -7712,7 +7775,7 @@ function routeSourcePaths(instance) {
|
|
|
7712
7775
|
}
|
|
7713
7776
|
function emitRouteNode(node, indentation, includeRootCatchAll) {
|
|
7714
7777
|
const childIndentation = `${indentation} `;
|
|
7715
|
-
const prefix = node.name ? `/${segmentPath(node.name)}` : "";
|
|
7778
|
+
const prefix = node.name && !isRouteGroup(node.name) ? `/${segmentPath(node.name)}` : "";
|
|
7716
7779
|
const head = `new Elysia({ prefix: ${JSON.stringify(prefix)} })`;
|
|
7717
7780
|
const content = [];
|
|
7718
7781
|
if (node.indexRoute) {
|
|
@@ -7821,12 +7884,12 @@ function findPackageRoot(sourcePath) {
|
|
|
7821
7884
|
const fallback = dirname6(sourcePath);
|
|
7822
7885
|
let directory = fallback;
|
|
7823
7886
|
while (dirname6(directory) !== directory) {
|
|
7824
|
-
if (existsSync5(
|
|
7887
|
+
if (existsSync5(join6(directory, "package.json"))) {
|
|
7825
7888
|
return directory;
|
|
7826
7889
|
}
|
|
7827
7890
|
directory = dirname6(directory);
|
|
7828
7891
|
}
|
|
7829
|
-
return existsSync5(
|
|
7892
|
+
return existsSync5(join6(directory, "package.json")) ? directory : fallback;
|
|
7830
7893
|
}
|
|
7831
7894
|
function isWithinDirectory(path, directory) {
|
|
7832
7895
|
const relativePath = relative4(directory, path);
|
|
@@ -7946,8 +8009,8 @@ function serverProxySource(instance, includeRootCatchAll) {
|
|
|
7946
8009
|
function createRoutesPlugin(options) {
|
|
7947
8010
|
const routeFilesBySpecifier = new Map;
|
|
7948
8011
|
const routeFilesByResolvedPath = new Map;
|
|
7949
|
-
const registryVirtualPath =
|
|
7950
|
-
const composableRegistryVirtualPath =
|
|
8012
|
+
const registryVirtualPath = join6(resolve4(primaryInstance(options.instances).pagesDir), ".furin-routes-registry.ts?furin-virtual");
|
|
8013
|
+
const composableRegistryVirtualPath = join6(resolve4(primaryInstance(options.instances).pagesDir), ".furin-routes-registry-composable.ts?furin-virtual");
|
|
7951
8014
|
const instancesBySpecifier = new Map(options.instances.flatMap((instance) => [
|
|
7952
8015
|
[
|
|
7953
8016
|
routeModuleSpecifier(instance),
|
|
@@ -8028,11 +8091,11 @@ async function materializeServerAppEntry(options) {
|
|
|
8028
8091
|
if (!instance) {
|
|
8029
8092
|
throw new Error(`[furin] Missing route instance for server app ${index}.`);
|
|
8030
8093
|
}
|
|
8031
|
-
const routePath =
|
|
8094
|
+
const routePath = join7(options.outDir, `_furin-routes-${index}.ts`);
|
|
8032
8095
|
writeFileSync(routePath, await materializedRouteModuleSource(instance));
|
|
8033
8096
|
return { ...app, nativeRoutes: toPosixPath(routePath) };
|
|
8034
8097
|
}));
|
|
8035
|
-
const entryPath =
|
|
8098
|
+
const entryPath = join7(options.outDir, "_furin-app.ts");
|
|
8036
8099
|
writeFileSync(entryPath, buildEntrySource({
|
|
8037
8100
|
apps,
|
|
8038
8101
|
headerComment: options.headerComment,
|
|
@@ -8062,7 +8125,7 @@ if (typeof startServer === "function") {
|
|
|
8062
8125
|
init_transform_isomorphic();
|
|
8063
8126
|
|
|
8064
8127
|
// src/rsc/build/environment.ts
|
|
8065
|
-
import { fileURLToPath as
|
|
8128
|
+
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
8066
8129
|
var SERVER_ONLY_RE = /^(?:@teyik0\/)?furin\/server-only$/;
|
|
8067
8130
|
var CLIENT_ONLY_RE = /^(?:@teyik0\/)?furin\/client-only$/;
|
|
8068
8131
|
function environmentGuardPlugin(graph) {
|
|
@@ -8073,13 +8136,13 @@ function environmentGuardPlugin(graph) {
|
|
|
8073
8136
|
if (graph === "client") {
|
|
8074
8137
|
throw new Error(`[furin] ${args.importer} imports furin/server-only from the client graph.`);
|
|
8075
8138
|
}
|
|
8076
|
-
return { path:
|
|
8139
|
+
return { path: fileURLToPath4(import.meta.resolve("../../server-only.ts")) };
|
|
8077
8140
|
});
|
|
8078
8141
|
build.onResolve({ filter: CLIENT_ONLY_RE }, (args) => {
|
|
8079
8142
|
if (graph !== "client") {
|
|
8080
8143
|
throw new Error(`[furin] ${args.importer} imports furin/client-only from the ${graph} graph.`);
|
|
8081
8144
|
}
|
|
8082
|
-
return { path:
|
|
8145
|
+
return { path: fileURLToPath4(import.meta.resolve("../../client-only.ts")) };
|
|
8083
8146
|
});
|
|
8084
8147
|
}
|
|
8085
8148
|
};
|
|
@@ -8112,12 +8175,12 @@ function assertNoPrefixSlugCollisions(prefixes) {
|
|
|
8112
8175
|
|
|
8113
8176
|
// src/adapter/runtime-build.ts
|
|
8114
8177
|
import { existsSync as existsSync10, realpathSync as realpathSync4, writeFileSync as writeFileSync7 } from "fs";
|
|
8115
|
-
import { basename as basename5, dirname as dirname11, isAbsolute as isAbsolute5, join as
|
|
8116
|
-
import { fileURLToPath as
|
|
8178
|
+
import { basename as basename5, dirname as dirname11, isAbsolute as isAbsolute5, join as join12, relative as relative7, resolve as resolve8 } from "path";
|
|
8179
|
+
import { fileURLToPath as fileURLToPath6 } from "url";
|
|
8117
8180
|
|
|
8118
8181
|
// src/build/client.ts
|
|
8119
8182
|
import { existsSync as existsSync9, mkdirSync as mkdirSync3, writeFileSync as writeFileSync5 } from "fs";
|
|
8120
|
-
import { basename as basename3, dirname as dirname9, join as
|
|
8183
|
+
import { basename as basename3, dirname as dirname9, join as join10, resolve as resolve7 } from "path";
|
|
8121
8184
|
|
|
8122
8185
|
// src/plugin/transform-client.ts
|
|
8123
8186
|
init_dist();
|
|
@@ -8970,7 +9033,7 @@ init_lang_detect();
|
|
|
8970
9033
|
|
|
8971
9034
|
// src/build/hydrate.ts
|
|
8972
9035
|
import { existsSync as existsSync7, mkdirSync as mkdirSync2, readFileSync as readFileSync5, writeFileSync as writeFileSync3 } from "fs";
|
|
8973
|
-
import { join as
|
|
9036
|
+
import { join as join9 } from "path";
|
|
8974
9037
|
|
|
8975
9038
|
// src/server/render/shell.ts
|
|
8976
9039
|
function escapeHtml(str) {
|
|
@@ -9025,7 +9088,7 @@ init_patterns();
|
|
|
9025
9088
|
|
|
9026
9089
|
// src/build/route-types.ts
|
|
9027
9090
|
import { existsSync as existsSync6, readFileSync as readFileSync4, renameSync as renameSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
9028
|
-
import { extname as extname3, join as
|
|
9091
|
+
import { extname as extname3, join as join8, relative as relative5 } from "path";
|
|
9029
9092
|
|
|
9030
9093
|
// src/shared/route-map.ts
|
|
9031
9094
|
function routeTypeProperty(pattern) {
|
|
@@ -9098,7 +9161,7 @@ import "@teyik0/furin/routes";
|
|
|
9098
9161
|
|
|
9099
9162
|
${routeMapDeclaration(entries)}${tagBlock}
|
|
9100
9163
|
`;
|
|
9101
|
-
const typesPath =
|
|
9164
|
+
const typesPath = join8(projectRoot, "furin-env.d.ts");
|
|
9102
9165
|
const existing = existsSync6(typesPath) ? readFileSync4(typesPath, "utf8") : "";
|
|
9103
9166
|
if (content === existing) {
|
|
9104
9167
|
return false;
|
|
@@ -9111,6 +9174,7 @@ ${routeMapDeclaration(entries)}${tagBlock}
|
|
|
9111
9174
|
|
|
9112
9175
|
// src/build/hydrate.ts
|
|
9113
9176
|
function generateHydrateEntry(routes, rootLayout, basePath, clientLogging) {
|
|
9177
|
+
const rootDirectory = rootLayout.replaceAll("\\", "/").split("/").slice(0, -1).join("/");
|
|
9114
9178
|
const getBoundaryIdent = (idents, filePath) => {
|
|
9115
9179
|
if (!filePath) {
|
|
9116
9180
|
return;
|
|
@@ -9151,6 +9215,9 @@ function generateHydrateEntry(routes, rootLayout, basePath, clientLogging) {
|
|
|
9151
9215
|
if (notFoundIdent) {
|
|
9152
9216
|
parts.push(`notFound: ${notFoundIdent}.default`);
|
|
9153
9217
|
}
|
|
9218
|
+
if (seg.depth === 0 && seg.path.replaceAll("\\", "/") !== rootDirectory) {
|
|
9219
|
+
parts.push("isRoot: false");
|
|
9220
|
+
}
|
|
9154
9221
|
boundaryLiterals.push(`{ ${parts.join(", ")} }`);
|
|
9155
9222
|
}
|
|
9156
9223
|
const lazyImports = [
|
|
@@ -9490,7 +9557,7 @@ function writeDevFiles(routes, { outDir, rootLayout, basePath, clientLogging, sk
|
|
|
9490
9557
|
if (import.meta.hot) import.meta.hot.data.furinServerSourceVersion = ${JSON.stringify(serverSourceVersion)};
|
|
9491
9558
|
`;
|
|
9492
9559
|
const hydrateCode = generateHydrateEntry(routes, rootLayout, basePath, clientLogging) + serverVersion;
|
|
9493
|
-
const hydratePath =
|
|
9560
|
+
const hydratePath = join9(outDir, "_hydrate.tsx");
|
|
9494
9561
|
const existingHydrate = existsSync7(hydratePath) ? readFileSync5(hydratePath, "utf8") : "";
|
|
9495
9562
|
let changed = false;
|
|
9496
9563
|
if (hydrateCode !== existingHydrate) {
|
|
@@ -9498,7 +9565,7 @@ if (import.meta.hot) import.meta.hot.data.furinServerSourceVersion = ${JSON.stri
|
|
|
9498
9565
|
changed = true;
|
|
9499
9566
|
}
|
|
9500
9567
|
const indexHtml = generateIndexHtml();
|
|
9501
|
-
const indexPath =
|
|
9568
|
+
const indexPath = join9(outDir, "index.html");
|
|
9502
9569
|
const existingIndex = existsSync7(indexPath) ? readFileSync5(indexPath, "utf8") : "";
|
|
9503
9570
|
if (indexHtml !== existingIndex) {
|
|
9504
9571
|
writeFileSync3(indexPath, indexHtml);
|
|
@@ -9589,7 +9656,7 @@ async function buildClient(routes, {
|
|
|
9589
9656
|
pagesDir
|
|
9590
9657
|
}) {
|
|
9591
9658
|
const dirName = clientDirName ?? "client";
|
|
9592
|
-
const clientDir =
|
|
9659
|
+
const clientDir = join10(outDir, dirName);
|
|
9593
9660
|
if (!existsSync9(outDir)) {
|
|
9594
9661
|
mkdirSync3(outDir, { recursive: true });
|
|
9595
9662
|
}
|
|
@@ -9597,7 +9664,7 @@ async function buildClient(routes, {
|
|
|
9597
9664
|
mkdirSync3(clientDir, { recursive: true });
|
|
9598
9665
|
}
|
|
9599
9666
|
const hydrateCode = resolveClientModuleSpecifiers(generateHydrateEntry(routes, rootLayout, basePath, clientLogging));
|
|
9600
|
-
const hydratePath =
|
|
9667
|
+
const hydratePath = join10(outDir, dirName === "client" ? "_hydrate.tsx" : `_hydrate-${dirName}.tsx`);
|
|
9601
9668
|
const hydrateEntry = createVirtualBuildEntry(hydratePath, hydrateCode, "tsx");
|
|
9602
9669
|
console.log("[furin] Building production client bundle\u2026");
|
|
9603
9670
|
const transformPlugin = {
|
|
@@ -13704,17 +13771,23 @@ function buildElement(route, data, rootLayout) {
|
|
|
13704
13771
|
const byDepth = new Map;
|
|
13705
13772
|
const legacyRoute = route;
|
|
13706
13773
|
for (const segment of legacyRoute.segmentBoundaries ?? []) {
|
|
13707
|
-
byDepth.
|
|
13774
|
+
const boundaries = byDepth.get(segment.depth) ?? [];
|
|
13775
|
+
boundaries.unshift(segment);
|
|
13776
|
+
byDepth.set(segment.depth, boundaries);
|
|
13708
13777
|
}
|
|
13709
13778
|
for (let i = route.routeChain.length - 1;i >= 1; i -= 1) {
|
|
13710
|
-
|
|
13779
|
+
for (const segment of byDepth.get(i) ?? []) {
|
|
13780
|
+
element = wrapSegmentBoundaries(element, segment, undefined);
|
|
13781
|
+
}
|
|
13711
13782
|
const routeEntry = route.routeChain[i];
|
|
13712
13783
|
if (routeEntry?.layout) {
|
|
13713
13784
|
const Layout = routeEntry.layout;
|
|
13714
13785
|
element = createElement6(Layout, data, element);
|
|
13715
13786
|
}
|
|
13716
13787
|
}
|
|
13717
|
-
|
|
13788
|
+
for (const segment of byDepth.get(0) ?? []) {
|
|
13789
|
+
element = wrapSegmentBoundaries(element, segment, undefined);
|
|
13790
|
+
}
|
|
13718
13791
|
if (rootLayout.layout) {
|
|
13719
13792
|
const RootLayoutComponent = rootLayout.layout;
|
|
13720
13793
|
element = createElement6(RootLayoutComponent, data, element);
|
|
@@ -15266,8 +15339,8 @@ async function buildSSGCacheSnapshot(routes, root, origin, basePath) {
|
|
|
15266
15339
|
|
|
15267
15340
|
// src/rsc/build/index.ts
|
|
15268
15341
|
import { mkdirSync as mkdirSync4, writeFileSync as writeFileSync6 } from "fs";
|
|
15269
|
-
import { basename as basename4, join as
|
|
15270
|
-
import { fileURLToPath as
|
|
15342
|
+
import { basename as basename4, join as join11 } from "path";
|
|
15343
|
+
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
15271
15344
|
init_transform_isomorphic();
|
|
15272
15345
|
|
|
15273
15346
|
// src/rsc/version.ts
|
|
@@ -15316,9 +15389,9 @@ function assertInstalledRscVersions() {
|
|
|
15316
15389
|
// src/rsc/build/index.ts
|
|
15317
15390
|
async function buildRscGraph(apps, outDir, buildId, userPlugins) {
|
|
15318
15391
|
await assertInstalledRscVersions();
|
|
15319
|
-
const graphDir =
|
|
15392
|
+
const graphDir = join11(outDir, "rsc");
|
|
15320
15393
|
mkdirSync4(graphDir, { recursive: true });
|
|
15321
|
-
const rscEntry =
|
|
15394
|
+
const rscEntry = fileURLToPath5(import.meta.resolve("../../rsc-server.tsx"));
|
|
15322
15395
|
const entrypoints = [
|
|
15323
15396
|
...new Set(apps.flatMap(({ root, routes }) => [
|
|
15324
15397
|
root.path,
|
|
@@ -15358,7 +15431,7 @@ ${result.logs.map((log) => log.message).join(`
|
|
|
15358
15431
|
`)}`);
|
|
15359
15432
|
}
|
|
15360
15433
|
const codecResult = await runBunBuild({
|
|
15361
|
-
entrypoints: [
|
|
15434
|
+
entrypoints: [fileURLToPath5(import.meta.resolve("../server-codec.ts"))],
|
|
15362
15435
|
outdir: outDir,
|
|
15363
15436
|
target: "bun",
|
|
15364
15437
|
format: "esm",
|
|
@@ -15378,14 +15451,14 @@ ${codecResult.logs.map((log) => log.message).join(`
|
|
|
15378
15451
|
}
|
|
15379
15452
|
const css = result.outputs.filter((output) => output.path.endsWith(".css")).map((output) => ({ href: `/_rsc/${basename4(output.path)}` }));
|
|
15380
15453
|
const manifest = { buildId, clientReferences: [], css };
|
|
15381
|
-
writeFileSync6(
|
|
15454
|
+
writeFileSync6(join11(graphDir, "manifest.json"), JSON.stringify(manifest, null, 2));
|
|
15382
15455
|
return manifest;
|
|
15383
15456
|
}
|
|
15384
15457
|
|
|
15385
15458
|
// src/adapter/runtime-build.ts
|
|
15386
15459
|
init_patterns();
|
|
15387
|
-
var _pkgRoot2 = dirname11(dirname11(
|
|
15388
|
-
var _pkgSrcDir2 = existsSync10(
|
|
15460
|
+
var _pkgRoot2 = dirname11(dirname11(fileURLToPath6(import.meta.resolve("@teyik0/furin"))));
|
|
15461
|
+
var _pkgSrcDir2 = existsSync10(join12(_pkgRoot2, "src", "furin.ts")) ? join12(_pkgRoot2, "src") : join12(_pkgRoot2, "dist");
|
|
15389
15462
|
var _ext2 = ".ts";
|
|
15390
15463
|
var PPR_ROUTE_IMPORT_RE = /ppr-route(?:\.ts)?$/;
|
|
15391
15464
|
var MIXED_CACHE_IMPORT_RE = /mixed-cache(?:\.ts)?$/;
|
|
@@ -15536,8 +15609,8 @@ function buildCompileMetadata(root, routes) {
|
|
|
15536
15609
|
function pprRuntimePlugin(apps) {
|
|
15537
15610
|
const enabled = apps.some((app) => app.routes.some((route) => resolveDocumentMode(route) !== "ssr" && (app.root.route.requestLoader !== undefined || hasRequestLoader(route))));
|
|
15538
15611
|
const pprPath = resolve8(_pkgSrcDir2, "server/render/ppr-route.ts");
|
|
15539
|
-
const reactServerPath =
|
|
15540
|
-
const reactStaticPath =
|
|
15612
|
+
const reactServerPath = fileURLToPath6(import.meta.resolve(enabled ? "react-dom/server.edge" : "react-dom/server"));
|
|
15613
|
+
const reactStaticPath = fileURLToPath6(import.meta.resolve("react-dom/static.edge"));
|
|
15541
15614
|
return {
|
|
15542
15615
|
name: "furin-ppr-runtime",
|
|
15543
15616
|
setup(build) {
|
|
@@ -15603,7 +15676,7 @@ async function buildRuntimeApp(app, projectRoot, targetDir, serverEntry, options
|
|
|
15603
15676
|
basePath: prefix,
|
|
15604
15677
|
clientDirName,
|
|
15605
15678
|
clientLogging: options.clientLogging ?? false,
|
|
15606
|
-
metafilePath: options.analyze ?
|
|
15679
|
+
metafilePath: options.analyze ? join12(dirname11(targetDir), "analysis", `${targetName}-${clientDirName}.json`) : undefined,
|
|
15607
15680
|
optimizeImports: options.optimizeImports,
|
|
15608
15681
|
outDir: targetDir,
|
|
15609
15682
|
pagesDir: app.pagesDir,
|
|
@@ -15616,9 +15689,9 @@ async function buildRuntimeApp(app, projectRoot, targetDir, serverEntry, options
|
|
|
15616
15689
|
const buildFingerprint = await createBuildFingerprint(`${prefix}
|
|
15617
15690
|
${entryChunk}`, cssChunks, routes, root, serverEntry, modulePaths, projectRoot);
|
|
15618
15691
|
const buildId = Bun.hash(buildFingerprint).toString(16).slice(0, 12);
|
|
15619
|
-
const clientDir =
|
|
15692
|
+
const clientDir = join12(targetDir, clientDirName);
|
|
15620
15693
|
const indexHtml = generateProdIndexHtml(entryChunk, cssChunks, buildId, undefined, false);
|
|
15621
|
-
writeFileSync7(
|
|
15694
|
+
writeFileSync7(join12(clientDir, "index.html"), indexHtml);
|
|
15622
15695
|
setProductionTemplateContent(indexHtml);
|
|
15623
15696
|
setProductionPreloadManifest(preloadManifest);
|
|
15624
15697
|
ssgRouteCache().clear();
|
|
@@ -15680,7 +15753,7 @@ async function buildRuntimeAppsSequentially(apps, projectRoot, targetDir, server
|
|
|
15680
15753
|
// src/adapter/bun.ts
|
|
15681
15754
|
function generateBootEntry(appEntry, outDir, filename) {
|
|
15682
15755
|
ensureDir(outDir);
|
|
15683
|
-
const entryPath =
|
|
15756
|
+
const entryPath = join13(outDir, filename);
|
|
15684
15757
|
return createVirtualBuildEntry(entryPath, serverBootSource(appEntry), "ts");
|
|
15685
15758
|
}
|
|
15686
15759
|
function collectEmbeddedAssets(entryApps, publicDir, compile) {
|
|
@@ -15703,7 +15776,7 @@ function relocateServerMaps(build, enabled, targetDir, buildRoot) {
|
|
|
15703
15776
|
if (!enabled) {
|
|
15704
15777
|
return;
|
|
15705
15778
|
}
|
|
15706
|
-
movePrivateServerSourceMaps(targetDir,
|
|
15779
|
+
movePrivateServerSourceMaps(targetDir, join13(buildRoot, "private", "server-sourcemaps", "bun"), build.outputs.filter((output) => output.kind === "sourcemap").map((output) => output.path));
|
|
15707
15780
|
}
|
|
15708
15781
|
function writeServerMetafile(build, analyze, buildRoot) {
|
|
15709
15782
|
if (!analyze) {
|
|
@@ -15712,9 +15785,9 @@ function writeServerMetafile(build, analyze, buildRoot) {
|
|
|
15712
15785
|
if (build.metafile === undefined) {
|
|
15713
15786
|
throw new Error("[furin] Bun server build did not produce the requested metafile.");
|
|
15714
15787
|
}
|
|
15715
|
-
const analysisDir =
|
|
15788
|
+
const analysisDir = join13(buildRoot, "analysis");
|
|
15716
15789
|
ensureDir(analysisDir);
|
|
15717
|
-
const metafilePath =
|
|
15790
|
+
const metafilePath = join13(analysisDir, "bun-server.json");
|
|
15718
15791
|
writeFileSync8(metafilePath, `${JSON.stringify(build.metafile, null, 2)}
|
|
15719
15792
|
`);
|
|
15720
15793
|
console.log(`[furin] Server metafile: ${toPosixPath(metafilePath)}`);
|
|
@@ -15724,7 +15797,7 @@ function finalizeEmbeddedAssets(compile, apps, targetDir, manifest) {
|
|
|
15724
15797
|
return;
|
|
15725
15798
|
}
|
|
15726
15799
|
for (const app of apps) {
|
|
15727
|
-
rmSync2(
|
|
15800
|
+
rmSync2(join13(targetDir, clientDirNameForPrefix(app.prefix)), {
|
|
15728
15801
|
force: true,
|
|
15729
15802
|
recursive: true
|
|
15730
15803
|
});
|
|
@@ -15747,7 +15820,7 @@ async function createBunAppEntry(apps, entryApps, options, publicDir, serverEntr
|
|
|
15747
15820
|
...context.extraContext ?? [],
|
|
15748
15821
|
` clientDir: import.meta.dir + ${JSON.stringify(`/${clientDirNameForPrefix(context.prefix ?? "")}`)},`
|
|
15749
15822
|
],
|
|
15750
|
-
templateHtml: readFileSync8(
|
|
15823
|
+
templateHtml: readFileSync8(join13(targetDir, clientDirNameForPrefix(context.prefix ?? ""), "index.html"), "utf8")
|
|
15751
15824
|
}));
|
|
15752
15825
|
return await materializeServerAppEntry({
|
|
15753
15826
|
apps: contexts,
|
|
@@ -15768,25 +15841,25 @@ async function buildBunTarget(apps, rootDir, buildRoot, serverEntry, options) {
|
|
|
15768
15841
|
const targetManifest = buildTargetManifest(rootDir, buildRoot, target, serverEntry);
|
|
15769
15842
|
const targetDir = resolve9(rootDir, targetManifest.targetDir);
|
|
15770
15843
|
rmSync2(targetDir, { force: true, recursive: true });
|
|
15771
|
-
rmSync2(
|
|
15844
|
+
rmSync2(join13(buildRoot, "private", "server-sourcemaps", "bun"), {
|
|
15772
15845
|
force: true,
|
|
15773
15846
|
recursive: true
|
|
15774
15847
|
});
|
|
15775
15848
|
ensureDir(targetDir);
|
|
15776
|
-
const publicDir = existsSync11(
|
|
15849
|
+
const publicDir = existsSync11(join13(rootDir, "public")) ? join13(rootDir, "public") : undefined;
|
|
15777
15850
|
const { entryApps, headlineBuildId } = await buildRuntimeAppsSequentially(apps, rootDir, targetDir, serverEntry, options, "bun");
|
|
15778
15851
|
targetManifest.buildId = headlineBuildId;
|
|
15779
15852
|
if (serverEntry) {
|
|
15780
|
-
targetManifest.rscManifestPath = toPosixPath(
|
|
15853
|
+
targetManifest.rscManifestPath = toPosixPath(join13(targetManifest.targetDir, "rsc", "manifest.json"));
|
|
15781
15854
|
}
|
|
15782
|
-
const targetPublicDir = publicDir ?
|
|
15855
|
+
const targetPublicDir = publicDir ? join13(targetDir, "public") : undefined;
|
|
15783
15856
|
if (publicDir && targetPublicDir && options.compile !== "embed") {
|
|
15784
15857
|
copyDirRecursive(publicDir, targetPublicDir);
|
|
15785
15858
|
}
|
|
15786
15859
|
const appEntry = await createBunAppEntry(apps, entryApps, options, publicDir, serverEntry, targetDir);
|
|
15787
15860
|
if (options.compile && serverEntry && appEntry) {
|
|
15788
15861
|
const serverFilename = compiledServerFilename(process.platform);
|
|
15789
|
-
const outfile =
|
|
15862
|
+
const outfile = join13(targetDir, serverFilename);
|
|
15790
15863
|
const entry = generateBootEntry(appEntry, targetDir, "_compile-entry.ts");
|
|
15791
15864
|
const embeddedAssets = collectEmbeddedAssets(entryApps, publicDir, options.compile);
|
|
15792
15865
|
const serverBuild = await runBunBuild({
|
|
@@ -15816,7 +15889,7 @@ async function buildBunTarget(apps, rootDir, buildRoot, serverEntry, options) {
|
|
|
15816
15889
|
relocateServerMaps(serverBuild, options.serverSourceMaps, targetDir, buildRoot);
|
|
15817
15890
|
writeServerMetafile(serverBuild, options.analyze, buildRoot);
|
|
15818
15891
|
console.log(`[furin] Server binary: ${outfile}`);
|
|
15819
|
-
targetManifest.serverPath = toPosixPath(
|
|
15892
|
+
targetManifest.serverPath = toPosixPath(join13(targetManifest.targetDir, serverFilename));
|
|
15820
15893
|
finalizeEmbeddedAssets(options.compile, apps, targetDir, targetManifest);
|
|
15821
15894
|
} else if (serverEntry && appEntry) {
|
|
15822
15895
|
const entry = generateBootEntry(appEntry, targetDir, "server.ts");
|
|
@@ -15843,26 +15916,26 @@ async function buildBunTarget(apps, rootDir, buildRoot, serverEntry, options) {
|
|
|
15843
15916
|
});
|
|
15844
15917
|
relocateServerMaps(serverBuild, options.serverSourceMaps, targetDir, buildRoot);
|
|
15845
15918
|
writeServerMetafile(serverBuild, options.analyze, buildRoot);
|
|
15846
|
-
console.log(`[furin] Server bundle: ${toPosixPath(
|
|
15847
|
-
targetManifest.serverPath = toPosixPath(
|
|
15919
|
+
console.log(`[furin] Server bundle: ${toPosixPath(join13(targetManifest.targetDir, "server.js"))}`);
|
|
15920
|
+
targetManifest.serverPath = toPosixPath(join13(targetManifest.targetDir, "server.js"));
|
|
15848
15921
|
}
|
|
15849
15922
|
return targetManifest;
|
|
15850
15923
|
}
|
|
15851
15924
|
|
|
15852
15925
|
// src/adapter/package.ts
|
|
15853
15926
|
import { existsSync as existsSync12, rmSync as rmSync3, writeFileSync as writeFileSync9 } from "fs";
|
|
15854
|
-
import { join as
|
|
15927
|
+
import { join as join14, relative as relative8, resolve as resolve10 } from "path";
|
|
15855
15928
|
init_transform_isomorphic();
|
|
15856
15929
|
async function buildPackageTarget(app, rootDir, buildRoot, options) {
|
|
15857
15930
|
const { prefix, root, routes, pagesDir } = app;
|
|
15858
15931
|
const modulePaths = routeSourcePaths(app);
|
|
15859
|
-
const targetDir =
|
|
15932
|
+
const targetDir = join14(buildRoot, "package");
|
|
15860
15933
|
rmSync3(targetDir, { force: true, recursive: true });
|
|
15861
15934
|
ensureDir(targetDir);
|
|
15862
15935
|
const { entryChunk, cssChunks, preloadManifest } = await buildClient(routes, {
|
|
15863
15936
|
basePath: prefix,
|
|
15864
15937
|
clientLogging: options.clientLogging ?? false,
|
|
15865
|
-
metafilePath: options.analyze ?
|
|
15938
|
+
metafilePath: options.analyze ? join14(buildRoot, "analysis", "package-client.json") : undefined,
|
|
15866
15939
|
optimizeImports: options.optimizeImports,
|
|
15867
15940
|
outDir: targetDir,
|
|
15868
15941
|
pagesDir,
|
|
@@ -15875,13 +15948,13 @@ async function buildPackageTarget(app, rootDir, buildRoot, options) {
|
|
|
15875
15948
|
const buildFingerprint = await createBuildFingerprint(`${prefix}
|
|
15876
15949
|
${entryChunk}`, cssChunks, routes, root, null, modulePaths, rootDir);
|
|
15877
15950
|
const buildId = Bun.hash(buildFingerprint).toString(16).slice(0, 12);
|
|
15878
|
-
const clientDir =
|
|
15879
|
-
const publicDir =
|
|
15951
|
+
const clientDir = join14(targetDir, "client");
|
|
15952
|
+
const publicDir = join14(rootDir, "public");
|
|
15880
15953
|
if (existsSync12(publicDir)) {
|
|
15881
|
-
copyDirRecursive(publicDir,
|
|
15954
|
+
copyDirRecursive(publicDir, join14(targetDir, "public"));
|
|
15882
15955
|
}
|
|
15883
15956
|
const indexHtml = generateProdIndexHtml(entryChunk, cssChunks, buildId, undefined, false);
|
|
15884
|
-
writeFileSync9(
|
|
15957
|
+
writeFileSync9(join14(clientDir, "index.html"), indexHtml);
|
|
15885
15958
|
setProductionTemplateContent(indexHtml);
|
|
15886
15959
|
setProductionPreloadManifest(preloadManifest);
|
|
15887
15960
|
ssgRouteCache().clear();
|
|
@@ -15922,7 +15995,7 @@ ${entryChunk}`, cssChunks, routes, root, null, modulePaths, rootDir);
|
|
|
15922
15995
|
headerComment: "// Auto-generated by `furin build --target package` \u2014 do not edit",
|
|
15923
15996
|
mode: "register"
|
|
15924
15997
|
});
|
|
15925
|
-
const registerEntry =
|
|
15998
|
+
const registerEntry = join14(targetDir, "register.ts");
|
|
15926
15999
|
const register = createVirtualBuildEntry(registerEntry, registerSource, "ts");
|
|
15927
16000
|
const result = await runBunBuild({
|
|
15928
16001
|
entrypoints: [register.entrypoint],
|
|
@@ -15971,7 +16044,7 @@ export function createFurinApp(options = {}) {
|
|
|
15971
16044
|
|
|
15972
16045
|
export const prefix = ${JSON.stringify(prefix)};
|
|
15973
16046
|
`;
|
|
15974
|
-
writeFileSync9(
|
|
16047
|
+
writeFileSync9(join14(targetDir, "index.js"), factorySource);
|
|
15975
16048
|
const dtsSource = `import type { FurinOptions, furin } from "@teyik0/furin";
|
|
15976
16049
|
|
|
15977
16050
|
/** Extra furin() options \u2014 pagesDir/prefix/clientDir are baked into the package and cannot be overridden. */
|
|
@@ -15979,7 +16052,7 @@ export type CreateFurinAppOptions = Omit<FurinOptions, "pagesDir" | "prefix" | "
|
|
|
15979
16052
|
export declare function createFurinApp(options?: CreateFurinAppOptions): ReturnType<typeof furin>;
|
|
15980
16053
|
export declare const prefix: string;
|
|
15981
16054
|
`;
|
|
15982
|
-
writeFileSync9(
|
|
16055
|
+
writeFileSync9(join14(targetDir, "index.d.ts"), dtsSource);
|
|
15983
16056
|
console.log(`[furin] Package artifact: ${toPosixPath(relative8(rootDir, targetDir))}`);
|
|
15984
16057
|
return {
|
|
15985
16058
|
buildId,
|
|
@@ -15991,7 +16064,7 @@ export declare const prefix: string;
|
|
|
15991
16064
|
|
|
15992
16065
|
// src/adapter/static.ts
|
|
15993
16066
|
import { cpSync as cpSync2, existsSync as existsSync13, rmSync as rmSync4, writeFileSync as writeFileSync10 } from "fs";
|
|
15994
|
-
import { dirname as dirname12, isAbsolute as isAbsolute6, join as
|
|
16067
|
+
import { dirname as dirname12, isAbsolute as isAbsolute6, join as join15, parse as parse3, relative as relative9, resolve as resolve11, sep as sep2, win32 } from "path";
|
|
15995
16068
|
init_patterns();
|
|
15996
16069
|
var STATIC_CONCURRENCY = 4;
|
|
15997
16070
|
var DYNAMIC_SEGMENT_RE2 = /\/:[^/]+|\/\*/;
|
|
@@ -16000,7 +16073,7 @@ var STATIC_RENDER_ORIGIN = "http://localhost";
|
|
|
16000
16073
|
function pathToOutputFile(urlPath, outDir, fileName) {
|
|
16001
16074
|
const normalizedOutDir = resolve11(outDir);
|
|
16002
16075
|
if (urlPath === "/" || urlPath === "") {
|
|
16003
|
-
return
|
|
16076
|
+
return join15(normalizedOutDir, fileName);
|
|
16004
16077
|
}
|
|
16005
16078
|
const resolved = resolve11(normalizedOutDir, urlPath.slice(1), fileName);
|
|
16006
16079
|
if (!resolved.startsWith(`${normalizedOutDir}${sep2}`)) {
|
|
@@ -16221,13 +16294,13 @@ async function buildStaticTarget(routes, rootDir, buildRoot, root, options) {
|
|
|
16221
16294
|
const afterQueueCount = skippedRoutes.length;
|
|
16222
16295
|
rmSync4(outDir, { force: true, recursive: true });
|
|
16223
16296
|
ensureDir(outDir);
|
|
16224
|
-
const targetDir =
|
|
16297
|
+
const targetDir = join15(buildRoot, "static");
|
|
16225
16298
|
rmSync4(targetDir, { force: true, recursive: true });
|
|
16226
16299
|
ensureDir(targetDir);
|
|
16227
16300
|
const { entryChunk, cssChunks, preloadManifest } = await buildClient(ssgRoutes, {
|
|
16228
16301
|
basePath,
|
|
16229
16302
|
clientLogging: Boolean(options.clientLogging),
|
|
16230
|
-
metafilePath: options.analyze ?
|
|
16303
|
+
metafilePath: options.analyze ? join15(buildRoot, "analysis", "static-client.json") : undefined,
|
|
16231
16304
|
optimizeImports: options.optimizeImports,
|
|
16232
16305
|
outDir: targetDir,
|
|
16233
16306
|
pagesDir: dirname12(root.path),
|
|
@@ -16237,22 +16310,22 @@ async function buildStaticTarget(routes, rootDir, buildRoot, root, options) {
|
|
|
16237
16310
|
reactCompiler: options.reactCompiler,
|
|
16238
16311
|
rootLayout: root.path
|
|
16239
16312
|
});
|
|
16240
|
-
const publicFavicon =
|
|
16313
|
+
const publicFavicon = join15(rootDir, "public", "favicon.ico");
|
|
16241
16314
|
const faviconHref = existsSync13(publicFavicon) ? `${basePath}/favicon.ico` : undefined;
|
|
16242
16315
|
const shellHtml = generateProdIndexHtml(entryChunk, cssChunks, undefined, faviconHref, true);
|
|
16243
16316
|
setProductionTemplateContent(shellHtml);
|
|
16244
16317
|
setProductionPreloadManifest(preloadManifest);
|
|
16245
|
-
const publicSrcDir =
|
|
16318
|
+
const publicSrcDir = join15(rootDir, "public");
|
|
16246
16319
|
if (existsSync13(publicSrcDir)) {
|
|
16247
16320
|
cpSync2(publicSrcDir, outDir, { recursive: true });
|
|
16248
16321
|
}
|
|
16249
|
-
const clientSrcDir =
|
|
16322
|
+
const clientSrcDir = join15(targetDir, "client");
|
|
16250
16323
|
if (existsSync13(clientSrcDir)) {
|
|
16251
|
-
cpSync2(clientSrcDir,
|
|
16324
|
+
cpSync2(clientSrcDir, join15(outDir, "_client"), { recursive: true });
|
|
16252
16325
|
}
|
|
16253
16326
|
await runWithConcurrency(tasks, STATIC_CONCURRENCY);
|
|
16254
16327
|
assertNoPrerenderSkips(onSSR, skippedRoutes, afterQueueCount);
|
|
16255
|
-
writeFileSync10(
|
|
16328
|
+
writeFileSync10(join15(outDir, "404.html"), shellHtml);
|
|
16256
16329
|
console.log("[furin] static: wrote 404.html (SPA shell fallback)");
|
|
16257
16330
|
rmSync4(targetDir, { force: true, recursive: true });
|
|
16258
16331
|
console.log(`[furin] static: export complete \u2192 ${toPosixPath(outDir)}` + ` (${renderedRoutes.length} rendered, ${skippedRoutes.length} skipped)`);
|
|
@@ -16267,8 +16340,8 @@ async function buildStaticTarget(routes, rootDir, buildRoot, root, options) {
|
|
|
16267
16340
|
|
|
16268
16341
|
// src/adapter/vercel.ts
|
|
16269
16342
|
import { cpSync as cpSync3, existsSync as existsSync14, readFileSync as readFileSync9, rmSync as rmSync5, symlinkSync, writeFileSync as writeFileSync11 } from "fs";
|
|
16270
|
-
import { basename as basename6, dirname as dirname13, extname as extname4, join as
|
|
16271
|
-
import { fileURLToPath as
|
|
16343
|
+
import { basename as basename6, dirname as dirname13, extname as extname4, join as join16, relative as relative10 } from "path";
|
|
16344
|
+
import { fileURLToPath as fileURLToPath7, pathToFileURL as pathToFileURL2 } from "url";
|
|
16272
16345
|
init_transform_isomorphic();
|
|
16273
16346
|
init_patterns();
|
|
16274
16347
|
var ISR_PATH_PARAM = "__furin_path";
|
|
@@ -16277,7 +16350,7 @@ var ELYSIA_STATIC_IMPORT_RE = /^@elysia\/static$/;
|
|
|
16277
16350
|
var MATCH_ALL_RE = /.*/;
|
|
16278
16351
|
var REGEX_META_RE = /[.*+?^${}()|[\]\\]/;
|
|
16279
16352
|
var UNSAFE_FUNCTION_PATH_RE = /[^a-zA-Z0-9_.[\]/-]/g;
|
|
16280
|
-
var VERCEL_FUNCTIONS_PATH =
|
|
16353
|
+
var VERCEL_FUNCTIONS_PATH = fileURLToPath7(import.meta.resolve("@vercel/functions"));
|
|
16281
16354
|
var VERCEL_RUNTIME_STUB_NAMESPACE = "furin-vercel-runtime-stub";
|
|
16282
16355
|
var FURIN_RUNTIME_ROOT2 = dirname13(import.meta.dir);
|
|
16283
16356
|
function isFurinRuntimeImporter(importer) {
|
|
@@ -16310,8 +16383,8 @@ function vercelRuntimePlugin() {
|
|
|
16310
16383
|
};
|
|
16311
16384
|
}
|
|
16312
16385
|
function frameworkVersion() {
|
|
16313
|
-
const packageRoot = dirname13(dirname13(
|
|
16314
|
-
const packageJson = JSON.parse(readFileSync9(
|
|
16386
|
+
const packageRoot = dirname13(dirname13(fileURLToPath7(import.meta.resolve("@teyik0/furin"))));
|
|
16387
|
+
const packageJson = JSON.parse(readFileSync9(join16(packageRoot, "package.json"), "utf8"));
|
|
16315
16388
|
return packageJson.version;
|
|
16316
16389
|
}
|
|
16317
16390
|
function serverEntryLoader(serverEntry) {
|
|
@@ -16427,7 +16500,7 @@ async function addPrerenderFallback(spec, physicalRoutePath, prerender, function
|
|
|
16427
16500
|
body = result.html;
|
|
16428
16501
|
({ status } = result);
|
|
16429
16502
|
}
|
|
16430
|
-
const fallbackPath =
|
|
16503
|
+
const fallbackPath = join16(dirname13(join16(functionsDir, spec.functionName)), fallback);
|
|
16431
16504
|
ensureDir(dirname13(fallbackPath));
|
|
16432
16505
|
writeFileSync11(fallbackPath, body);
|
|
16433
16506
|
spec.config.fallback = fallback;
|
|
@@ -16440,7 +16513,7 @@ async function addPrerenderFallback(spec, physicalRoutePath, prerender, function
|
|
|
16440
16513
|
spec.config.initialStatus = status;
|
|
16441
16514
|
}
|
|
16442
16515
|
function createFunctionAlias(functionsDir, serverFunctionDir, functionName) {
|
|
16443
|
-
const aliasPath =
|
|
16516
|
+
const aliasPath = join16(functionsDir, `${functionName}.func`);
|
|
16444
16517
|
ensureDir(dirname13(aliasPath));
|
|
16445
16518
|
const target = relative10(dirname13(aliasPath), serverFunctionDir);
|
|
16446
16519
|
symlinkSync(target, aliasPath, process.platform === "win32" ? "junction" : "dir");
|
|
@@ -16665,10 +16738,10 @@ async function buildPprFallbacks(apps, builds, specs, functionsDir, rootDir, tar
|
|
|
16665
16738
|
if (jobs.length === 0) {
|
|
16666
16739
|
return;
|
|
16667
16740
|
}
|
|
16668
|
-
const resultPath =
|
|
16741
|
+
const resultPath = join16(targetDir, "ppr-results.json");
|
|
16669
16742
|
const requests = jobs.map(({ path, spec }) => `http://localhost/${spec.functionName}?${ISR_PATH_PARAM}=${encodeURIComponent(path)}`);
|
|
16670
16743
|
const script = `
|
|
16671
|
-
const handler = (await import(${JSON.stringify(pathToFileURL2(
|
|
16744
|
+
const handler = (await import(${JSON.stringify(pathToFileURL2(join16(functionsDir, "__server.func/index.js")).href)})).default;
|
|
16672
16745
|
const results = [];
|
|
16673
16746
|
for (const url of ${JSON.stringify(requests)}) {
|
|
16674
16747
|
const response = await handler.fetch(new Request(url));
|
|
@@ -16777,13 +16850,13 @@ export default { fetch: handle };
|
|
|
16777
16850
|
}
|
|
16778
16851
|
async function buildVercelTarget(apps, rootDir, buildRoot, serverEntry, options) {
|
|
16779
16852
|
assertDefaultServerExport(serverEntry);
|
|
16780
|
-
const targetDir =
|
|
16781
|
-
const outputDir =
|
|
16782
|
-
const staticDir =
|
|
16783
|
-
const functionsDir =
|
|
16784
|
-
const serverFunctionDir =
|
|
16853
|
+
const targetDir = join16(buildRoot, "vercel");
|
|
16854
|
+
const outputDir = join16(rootDir, ".vercel", "output");
|
|
16855
|
+
const staticDir = join16(outputDir, "static");
|
|
16856
|
+
const functionsDir = join16(outputDir, "functions");
|
|
16857
|
+
const serverFunctionDir = join16(functionsDir, "__server.func");
|
|
16785
16858
|
rmSync5(targetDir, { force: true, recursive: true });
|
|
16786
|
-
rmSync5(
|
|
16859
|
+
rmSync5(join16(buildRoot, "private", "server-sourcemaps", "vercel"), {
|
|
16787
16860
|
force: true,
|
|
16788
16861
|
recursive: true
|
|
16789
16862
|
});
|
|
@@ -16792,24 +16865,24 @@ async function buildVercelTarget(apps, rootDir, buildRoot, serverEntry, options)
|
|
|
16792
16865
|
ensureDir(staticDir);
|
|
16793
16866
|
ensureDir(serverFunctionDir);
|
|
16794
16867
|
const { builds, headlineBuildId } = await buildRuntimeAppsSequentially(apps, rootDir, targetDir, serverEntry, options, "vercel");
|
|
16795
|
-
cpSync3(
|
|
16796
|
-
const publicDir =
|
|
16868
|
+
cpSync3(join16(targetDir, "server-codec.js"), join16(serverFunctionDir, "server-codec.js"));
|
|
16869
|
+
const publicDir = join16(rootDir, "public");
|
|
16797
16870
|
if (existsSync14(publicDir)) {
|
|
16798
16871
|
cpSync3(publicDir, staticDir, { recursive: true });
|
|
16799
16872
|
for (const app of apps) {
|
|
16800
|
-
const appStaticDir =
|
|
16801
|
-
const appPublicDir =
|
|
16873
|
+
const appStaticDir = join16(staticDir, app.prefix.slice(1));
|
|
16874
|
+
const appPublicDir = join16(appStaticDir, "public");
|
|
16802
16875
|
cpSync3(publicDir, appPublicDir, { recursive: true });
|
|
16803
|
-
const favicon =
|
|
16876
|
+
const favicon = join16(publicDir, "favicon.ico");
|
|
16804
16877
|
if (app.prefix !== "" && existsSync14(favicon)) {
|
|
16805
|
-
cpSync3(favicon,
|
|
16878
|
+
cpSync3(favicon, join16(appStaticDir, "favicon.ico"));
|
|
16806
16879
|
}
|
|
16807
16880
|
}
|
|
16808
16881
|
}
|
|
16809
16882
|
for (let appIndex = 0;appIndex < apps.length; appIndex += 1) {
|
|
16810
16883
|
const app = apps[appIndex];
|
|
16811
16884
|
const build = builds[appIndex];
|
|
16812
|
-
const clientOutputDir =
|
|
16885
|
+
const clientOutputDir = join16(staticDir, app.prefix.slice(1), "_client");
|
|
16813
16886
|
cpSync3(build.clientDir, clientOutputDir, { recursive: true });
|
|
16814
16887
|
}
|
|
16815
16888
|
const pprResumeKey = crypto.randomUUID();
|
|
@@ -16828,7 +16901,7 @@ async function buildVercelTarget(apps, rootDir, buildRoot, serverEntry, options)
|
|
|
16828
16901
|
serverEntry
|
|
16829
16902
|
})
|
|
16830
16903
|
]);
|
|
16831
|
-
const entryPath =
|
|
16904
|
+
const entryPath = join16(serverFunctionDir, "_vercel-handler.ts");
|
|
16832
16905
|
const entry = createVirtualBuildEntry(entryPath, vercelEntrySource(apps, builds, prerenderSpecs, appEntry, pprResumeKey), "ts");
|
|
16833
16906
|
const serverBuild = await runBunBuild({
|
|
16834
16907
|
define: { "process.env.NODE_ENV": JSON.stringify("production") },
|
|
@@ -16856,22 +16929,22 @@ async function buildVercelTarget(apps, rootDir, buildRoot, serverEntry, options)
|
|
|
16856
16929
|
target: "bun"
|
|
16857
16930
|
});
|
|
16858
16931
|
if (options.serverSourceMaps) {
|
|
16859
|
-
movePrivateServerSourceMaps(serverFunctionDir,
|
|
16932
|
+
movePrivateServerSourceMaps(serverFunctionDir, join16(buildRoot, "private", "server-sourcemaps", "vercel"), serverBuild.outputs.filter((output) => output.kind === "sourcemap").map((output) => output.path));
|
|
16860
16933
|
}
|
|
16861
16934
|
if (options.analyze) {
|
|
16862
16935
|
if (serverBuild.metafile === undefined) {
|
|
16863
16936
|
throw new Error("[furin] Vercel server build did not produce the requested metafile.");
|
|
16864
16937
|
}
|
|
16865
|
-
const metafilePath =
|
|
16938
|
+
const metafilePath = join16(buildRoot, "analysis", "vercel-server.json");
|
|
16866
16939
|
ensureDir(dirname13(metafilePath));
|
|
16867
16940
|
writeFileSync11(metafilePath, `${JSON.stringify(serverBuild.metafile, null, 2)}
|
|
16868
16941
|
`);
|
|
16869
16942
|
console.log(`[furin] Server metafile: ${toPosixPath(metafilePath)}`);
|
|
16870
16943
|
}
|
|
16871
16944
|
const serverBundleBytes = serverBuild.outputs.filter((output) => output.path.endsWith(".js")).reduce((total, output) => total + output.size, 0);
|
|
16872
|
-
writeFileSync11(
|
|
16945
|
+
writeFileSync11(join16(serverFunctionDir, "index.js"), vercelBootstrapSource(serverBundleBytes));
|
|
16873
16946
|
await buildPprFallbacks(apps, builds, prerenderSpecs, functionsDir, rootDir, targetDir);
|
|
16874
|
-
writeFileSync11(
|
|
16947
|
+
writeFileSync11(join16(serverFunctionDir, ".vc-config.json"), `${JSON.stringify({
|
|
16875
16948
|
handler: "index.js",
|
|
16876
16949
|
launcherType: "Nodejs",
|
|
16877
16950
|
...options.vercelConfig?.regions === undefined ? {} : { regions: options.vercelConfig.regions },
|
|
@@ -16882,7 +16955,7 @@ async function buildVercelTarget(apps, rootDir, buildRoot, serverEntry, options)
|
|
|
16882
16955
|
`);
|
|
16883
16956
|
for (const spec of prerenderSpecs) {
|
|
16884
16957
|
createFunctionAlias(functionsDir, serverFunctionDir, spec.functionName);
|
|
16885
|
-
writeFileSync11(
|
|
16958
|
+
writeFileSync11(join16(functionsDir, `${spec.functionName}.prerender-config.json`), `${JSON.stringify(spec.config, null, 2)}
|
|
16886
16959
|
`);
|
|
16887
16960
|
}
|
|
16888
16961
|
const assetRoutes = apps.map((app) => ({
|
|
@@ -16912,7 +16985,7 @@ async function buildVercelTarget(apps, rootDir, buildRoot, serverEntry, options)
|
|
|
16912
16985
|
],
|
|
16913
16986
|
version: 3
|
|
16914
16987
|
};
|
|
16915
|
-
writeFileSync11(
|
|
16988
|
+
writeFileSync11(join16(outputDir, "config.json"), `${JSON.stringify(config, null, 2)}
|
|
16916
16989
|
`);
|
|
16917
16990
|
const ssgRoutes = builds.flatMap((build, index) => build.prerenders.filter((prerender) => resolveDocumentMode(prerender.route) === "ssg").map((prerender) => physicalPath(apps[index].prefix, prerender.path))).toSorted();
|
|
16918
16991
|
const isrRoutes = apps.flatMap((app) => app.routes.filter((route) => resolveDocumentMode(route) === "isr").map((route) => physicalPath(app.prefix, route.pattern))).toSorted();
|
|
@@ -16991,7 +17064,7 @@ init_instance();
|
|
|
16991
17064
|
// src/server/router/discovery.ts
|
|
16992
17065
|
import { existsSync as existsSync15 } from "fs";
|
|
16993
17066
|
import { readdir } from "fs/promises";
|
|
16994
|
-
import { join as
|
|
17067
|
+
import { join as join17, parse as parse4 } from "path";
|
|
16995
17068
|
|
|
16996
17069
|
// src/server/internal.ts
|
|
16997
17070
|
var _compileContexts = new Map;
|
|
@@ -17171,10 +17244,6 @@ async function scanRootLayout(pagesDir) {
|
|
|
17171
17244
|
}
|
|
17172
17245
|
var CONVENTION_FILE_NAMES = ["not-found", "error"];
|
|
17173
17246
|
var SOURCE_MODULE_EXTENSIONS = [".tsx", ".ts", ".jsx", ".js"];
|
|
17174
|
-
var DYNAMIC_ROUTE_SEGMENT_RE = /(^|\/):[^/]+/g;
|
|
17175
|
-
function routePatternKey(pattern) {
|
|
17176
|
-
return pattern.replace(DYNAMIC_ROUTE_SEGMENT_RE, "$1:param");
|
|
17177
|
-
}
|
|
17178
17247
|
function isConventionFileName(name) {
|
|
17179
17248
|
return CONVENTION_FILE_NAMES.includes(name);
|
|
17180
17249
|
}
|
|
@@ -17223,7 +17292,7 @@ async function scanPageFiles(pagesDir, root) {
|
|
|
17223
17292
|
const devRoute = await buildDevRoute(absolutePath, relativePath, pattern, root, pagesDir);
|
|
17224
17293
|
devRoute.notFound = notFound;
|
|
17225
17294
|
devRoute.error = errorComponent;
|
|
17226
|
-
devRoute.segmentBoundaries = segmentBoundaries;
|
|
17295
|
+
devRoute.segmentBoundaries = alignSegmentBoundaryDepths(segmentBoundaries, devRoute.routeChain);
|
|
17227
17296
|
routes.push(devRoute);
|
|
17228
17297
|
continue;
|
|
17229
17298
|
}
|
|
@@ -17243,7 +17312,7 @@ async function scanPageFiles(pagesDir, root) {
|
|
|
17243
17312
|
path: absolutePath,
|
|
17244
17313
|
pattern,
|
|
17245
17314
|
routeChain,
|
|
17246
|
-
segmentBoundaries,
|
|
17315
|
+
segmentBoundaries: alignSegmentBoundaryDepths(segmentBoundaries, routeChain),
|
|
17247
17316
|
tags: collectRouteTags(routeChain, page)
|
|
17248
17317
|
});
|
|
17249
17318
|
}
|
|
@@ -17281,6 +17350,21 @@ async function resolveDefinedLayoutParent(pagePath, pagesDir, rootRoute) {
|
|
|
17281
17350
|
}
|
|
17282
17351
|
return parent;
|
|
17283
17352
|
}
|
|
17353
|
+
function alignSegmentBoundaryDepths(boundaries, routeChain) {
|
|
17354
|
+
return boundaries.map((boundary) => {
|
|
17355
|
+
let depth = 0;
|
|
17356
|
+
for (const [index, entry] of routeChain.entries()) {
|
|
17357
|
+
if (!entry.sourcePath) {
|
|
17358
|
+
continue;
|
|
17359
|
+
}
|
|
17360
|
+
const directory = entry.sourcePath.slice(0, entry.sourcePath.lastIndexOf("/"));
|
|
17361
|
+
if (boundary.path === directory || boundary.path.startsWith(`${directory}/`)) {
|
|
17362
|
+
depth = index;
|
|
17363
|
+
}
|
|
17364
|
+
}
|
|
17365
|
+
return { ...boundary, depth };
|
|
17366
|
+
});
|
|
17367
|
+
}
|
|
17284
17368
|
async function collectSegmentBoundaries(pageAbsolutePath, pagesDir, notFoundCache, errorCache) {
|
|
17285
17369
|
const pageDir = pageAbsolutePath.slice(0, pageAbsolutePath.lastIndexOf("/"));
|
|
17286
17370
|
const dirs = [pagesDir];
|
|
@@ -17368,7 +17452,7 @@ async function collectPageFilePaths(dir) {
|
|
|
17368
17452
|
const files = [];
|
|
17369
17453
|
const entries = (await readdir(dir, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name));
|
|
17370
17454
|
const resolved = await mapWithConcurrency(entries, DIR_SCAN_CONCURRENCY, async (entry) => {
|
|
17371
|
-
const absolutePath = toPosixPath2(
|
|
17455
|
+
const absolutePath = toPosixPath2(join17(dir, entry.name));
|
|
17372
17456
|
if (entry.isDirectory()) {
|
|
17373
17457
|
return await collectPageFilePaths(absolutePath);
|
|
17374
17458
|
}
|
|
@@ -17494,7 +17578,7 @@ async function buildApp(options) {
|
|
|
17494
17578
|
}
|
|
17495
17579
|
async function buildAppInternal(options) {
|
|
17496
17580
|
const rootDir = resolve12(options.rootDir ?? process.cwd());
|
|
17497
|
-
const buildRoot =
|
|
17581
|
+
const buildRoot = join18(rootDir, BUILD_OUTPUT_DIR);
|
|
17498
17582
|
const serverEntry = (() => {
|
|
17499
17583
|
if (options.target === "static" || options.target === "package") {
|
|
17500
17584
|
return null;
|
|
@@ -17587,7 +17671,7 @@ async function buildAppInternal(options) {
|
|
|
17587
17671
|
throw new Error(`[furin] Unsupported build target "${target}"`);
|
|
17588
17672
|
}
|
|
17589
17673
|
}
|
|
17590
|
-
writeFileSync12(
|
|
17674
|
+
writeFileSync12(join18(buildRoot, "manifest.json"), `${JSON.stringify(manifest, null, 2)}
|
|
17591
17675
|
`);
|
|
17592
17676
|
return {
|
|
17593
17677
|
manifest,
|