@teyik0/furin 0.9.0-alpha.1 → 0.9.0-alpha.3
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/adapter/runtime-build.d.ts +7 -3
- package/dist/adapter/vercel.js +31 -6
- package/dist/build/client.d.ts +1 -1
- package/dist/build/entry-template.d.ts +3 -12
- package/dist/build/entry-template.ts +3 -15
- package/dist/build/hydrate.d.ts +6 -1
- package/dist/build/index.d.ts +1 -1
- package/dist/build/index.js +597 -445
- package/dist/build/route-metadata.d.ts +2 -2
- package/dist/build/route-types.d.ts +1 -1
- package/dist/build/types.d.ts +10 -4
- package/dist/cli/index.js +626 -466
- package/dist/client/chunks/{client-xy6g38kx.js → client-a7spxfnn.js} +24 -5
- package/dist/client/chunks/{client-rjhxgt64.js → client-d9v49jwz.js} +1 -1
- package/dist/client/chunks/{client-k29262a4.js → client-rdxyrw11.js} +1 -1
- package/dist/client/define-route.d.ts +14 -0
- package/dist/client/dev-error-overlay.ts +18 -0
- package/dist/client/internal/runtime-types.d.ts +8 -0
- package/dist/client/link.js +3 -3
- package/dist/client/router/link-utils.d.ts +3 -2
- package/dist/client/router/search/index.js +2 -2
- package/dist/client/router/types.d.ts +9 -3
- package/dist/client.js +22 -6
- package/dist/config.d.ts +4 -0
- package/dist/config.js +4 -1
- package/dist/define-route.d.ts +53 -12
- package/dist/furin.d.ts +13 -3
- package/dist/furin.js +771 -616
- package/dist/plugin/client-plugin.d.ts +1 -1
- package/dist/plugin/index.js +5 -4
- package/dist/plugin/route-config.d.ts +3 -3
- package/dist/plugin/route-manifest.d.ts +46 -0
- package/dist/plugin/route-tree.d.ts +13 -29
- package/dist/routes.d.ts +2 -2
- package/dist/server/dev/runtime.d.ts +2 -1
- package/dist/server/internal.d.ts +6 -0
- package/dist/server/internal.js +57 -76
- package/dist/server/registrations.d.ts +4 -2
- package/dist/server/router/defined-route.d.ts +4 -0
- package/dist/server/router/discovery.d.ts +14 -4
- package/dist/server/router/hmr.d.ts +12 -12
- package/dist/server/router/patterns.d.ts +4 -12
- package/dist/server/router/types.d.ts +16 -1
- package/dist/server/static-export.js +88 -120
- package/dist/server/sync/drizzle/index.d.ts +8 -10
- package/dist/shared/route-specificity.d.ts +10 -1
- package/package.json +4 -7
- package/src/adapter/package.ts +11 -37
- package/src/adapter/runtime-build.ts +5 -4
- package/src/adapter/static.ts +1 -1
- package/src/adapter/vercel.ts +2 -1
- package/src/build/client.ts +3 -3
- package/src/build/discover-pages-process.ts +1 -1
- package/src/build/elysia-aot.ts +2 -2
- package/src/build/entry-template.ts +3 -15
- package/src/build/hydrate.ts +14 -6
- package/src/build/index.ts +19 -9
- package/src/build/route-metadata.ts +15 -8
- package/src/build/route-types.ts +18 -43
- package/src/build/types.ts +12 -5
- package/src/cli/config.ts +6 -0
- package/src/cli/index.ts +30 -14
- package/src/client/define-route.ts +29 -4
- package/src/client/dev-error-overlay.ts +18 -0
- package/src/client/internal/runtime-types.ts +8 -0
- package/src/client/router/link-utils.ts +16 -8
- package/src/client/router/types.ts +40 -14
- package/src/config.ts +5 -0
- package/src/define-route.ts +85 -16
- package/src/furin.ts +31 -7
- package/src/plugin/client-plugin.ts +13 -8
- package/src/plugin/dev-routes.ts +8 -17
- package/src/plugin/route-config.ts +77 -62
- package/src/plugin/route-manifest.ts +437 -0
- package/src/plugin/route-modules.ts +6 -1
- package/src/plugin/route-registry.ts +11 -42
- package/src/plugin/route-tree.ts +71 -181
- package/src/routes.ts +2 -2
- package/src/server/dev/runtime.ts +16 -22
- package/src/server/dev-page-plugin.ts +5 -2
- package/src/server/internal.ts +4 -1
- package/src/server/registrations.ts +5 -2
- package/src/server/render/static-params.ts +2 -10
- package/src/server/router/defined-route.ts +8 -0
- package/src/server/router/discovery.ts +237 -196
- package/src/server/router/hmr.ts +45 -63
- package/src/server/router/patterns.ts +41 -117
- package/src/server/router/types.ts +17 -1
- package/src/server/sync/drizzle/index.ts +18 -19
- package/src/shared/route-specificity.ts +34 -2
- package/src/shared/utils/index.ts +1 -1
package/dist/build/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// src/build/index.ts
|
|
3
3
|
import { existsSync as existsSync18, writeFileSync as writeFileSync13 } from "fs";
|
|
4
|
-
import { join as
|
|
4
|
+
import { join as join21, relative as relative15, resolve as resolve13 } from "path";
|
|
5
5
|
|
|
6
6
|
// src/adapter/build.ts
|
|
7
7
|
import { existsSync as existsSync12, readFileSync as readFileSync7, rmSync as rmSync3, writeFileSync as writeFileSync7 } from "fs";
|
|
8
|
-
import { basename as basename5, extname as extname3, join as
|
|
8
|
+
import { basename as basename5, extname as extname3, join as join14, relative as relative9 } from "path";
|
|
9
9
|
|
|
10
10
|
// src/build/bun-build.ts
|
|
11
11
|
var PRODUCTION_DEFINE = { "process.env.NODE_ENV": JSON.stringify("production") };
|
|
@@ -184,7 +184,7 @@ function segmentSpecificity(segment) {
|
|
|
184
184
|
}
|
|
185
185
|
return segment.startsWith(":") ? 2 : 3;
|
|
186
186
|
}
|
|
187
|
-
function
|
|
187
|
+
function compareConcreteSpecificity(a, b) {
|
|
188
188
|
const aSegments = a.split("/").filter(Boolean);
|
|
189
189
|
const bSegments = b.split("/").filter(Boolean);
|
|
190
190
|
const length = Math.max(aSegments.length, bSegments.length);
|
|
@@ -204,6 +204,24 @@ function compareRouteSpecificity(a, b) {
|
|
|
204
204
|
}
|
|
205
205
|
return 0;
|
|
206
206
|
}
|
|
207
|
+
function expandOptionalSegments(pattern) {
|
|
208
|
+
let variants = [[]];
|
|
209
|
+
for (const segment of pattern.split("/").filter(Boolean)) {
|
|
210
|
+
if (segment.startsWith(":") && segment.endsWith("?")) {
|
|
211
|
+
const required = segment.slice(0, -1);
|
|
212
|
+
variants = variants.flatMap((variant) => [variant, [...variant, required]]);
|
|
213
|
+
} else {
|
|
214
|
+
variants = variants.map((variant) => [...variant, segment]);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return variants.map((variant) => `/${variant.join("/")}`);
|
|
218
|
+
}
|
|
219
|
+
function mostSpecificVariant(pattern) {
|
|
220
|
+
return expandOptionalSegments(pattern).reduce((best, variant) => compareConcreteSpecificity(variant, best) > 0 ? variant : best);
|
|
221
|
+
}
|
|
222
|
+
function compareRouteSpecificity(a, b) {
|
|
223
|
+
return compareConcreteSpecificity(mostSpecificVariant(a), mostSpecificVariant(b));
|
|
224
|
+
}
|
|
207
225
|
|
|
208
226
|
// src/shared/search-params.ts
|
|
209
227
|
function isObject(value) {
|
|
@@ -352,7 +370,6 @@ function normalizePrefix(prefix) {
|
|
|
352
370
|
}
|
|
353
371
|
|
|
354
372
|
// src/server/router/patterns.ts
|
|
355
|
-
import { parse } from "path";
|
|
356
373
|
function resolveRouteRevalidate(page) {
|
|
357
374
|
return page.revalidate ?? page._route.revalidate;
|
|
358
375
|
}
|
|
@@ -372,60 +389,7 @@ function resolveDocumentRevalidate(route) {
|
|
|
372
389
|
}
|
|
373
390
|
return Math.min(...intervals);
|
|
374
391
|
}
|
|
375
|
-
var
|
|
376
|
-
function parseDynamicRouteSegment(segment, sourcePath) {
|
|
377
|
-
if (!(segment.startsWith("[") && segment.endsWith("]"))) {
|
|
378
|
-
return;
|
|
379
|
-
}
|
|
380
|
-
const inner = segment.slice(1, -1);
|
|
381
|
-
const catchAll = inner.startsWith("...");
|
|
382
|
-
const name = catchAll ? inner.slice(3) : inner;
|
|
383
|
-
if (!DYNAMIC_PARAMETER_NAME_RE.test(name)) {
|
|
384
|
-
throw new Error(`[furin] Invalid dynamic parameter ${JSON.stringify(name)} in ${JSON.stringify(sourcePath ?? segment)}. Parameter names must match ${DYNAMIC_PARAMETER_NAME_RE}.`);
|
|
385
|
-
}
|
|
386
|
-
return { catchAll, name };
|
|
387
|
-
}
|
|
388
|
-
function routeSegmentToPattern(segment) {
|
|
389
|
-
const dynamic = parseDynamicRouteSegment(segment, undefined);
|
|
390
|
-
if (!dynamic) {
|
|
391
|
-
return segment;
|
|
392
|
-
}
|
|
393
|
-
return dynamic.catchAll ? "*" : `:${dynamic.name}`;
|
|
394
|
-
}
|
|
395
|
-
var ROUTE_GROUP_RE = /^\([^()]+\)$/;
|
|
396
|
-
function isRouteGroup(segment) {
|
|
397
|
-
return ROUTE_GROUP_RE.test(segment);
|
|
398
|
-
}
|
|
399
|
-
var DYNAMIC_ROUTE_SEGMENT_RE = /(^|\/):[^/]+/g;
|
|
400
|
-
function routePatternKey(pattern) {
|
|
401
|
-
return pattern.replace(DYNAMIC_ROUTE_SEGMENT_RE, "$1:param");
|
|
402
|
-
}
|
|
403
|
-
function filePathToPattern(path) {
|
|
404
|
-
const parts = path.replaceAll("\\", "/").split("/");
|
|
405
|
-
const segments = [];
|
|
406
|
-
const lastIndex = parts.length - 1;
|
|
407
|
-
for (let idx = 0;idx < parts.length; idx += 1) {
|
|
408
|
-
const part = parts[idx];
|
|
409
|
-
if (part === undefined || part.length === 0) {
|
|
410
|
-
continue;
|
|
411
|
-
}
|
|
412
|
-
const isFile = idx === lastIndex;
|
|
413
|
-
const name = isFile ? parse(part).name : part;
|
|
414
|
-
if (!isFile && isRouteGroup(name)) {
|
|
415
|
-
continue;
|
|
416
|
-
}
|
|
417
|
-
if (isFile && name === "index") {
|
|
418
|
-
continue;
|
|
419
|
-
}
|
|
420
|
-
const dynamic = parseDynamicRouteSegment(name, path);
|
|
421
|
-
if (dynamic) {
|
|
422
|
-
segments.push(dynamic.catchAll ? "*" : `:${dynamic.name}`);
|
|
423
|
-
} else {
|
|
424
|
-
segments.push(name);
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
return `/${segments.join("/")}`;
|
|
428
|
-
}
|
|
392
|
+
var SPLAT_PARAM = "_splat";
|
|
429
393
|
var REGEX_META_CHARS_RE = /[.*+?^${}()|[\]\\]/g;
|
|
430
394
|
function escapeRegExp(value) {
|
|
431
395
|
return value.replace(REGEX_META_CHARS_RE, "\\$&");
|
|
@@ -441,11 +405,17 @@ function routePatternRegexSource(pattern, sources) {
|
|
|
441
405
|
while (i < pattern.length && pattern[i] !== "/") {
|
|
442
406
|
i += 1;
|
|
443
407
|
}
|
|
444
|
-
|
|
445
|
-
|
|
408
|
+
const name = pattern.slice(start, i);
|
|
409
|
+
if (name.endsWith("?") && source.endsWith("/")) {
|
|
410
|
+
paramNames.push(name.slice(0, -1));
|
|
411
|
+
source = `${source.slice(0, -1)}(?:/${sources.param})?`;
|
|
412
|
+
} else {
|
|
413
|
+
paramNames.push(name);
|
|
414
|
+
source += sources.param;
|
|
415
|
+
}
|
|
446
416
|
} else if (pattern[i] === "*") {
|
|
447
|
-
paramNames.push(
|
|
448
|
-
source
|
|
417
|
+
paramNames.push(SPLAT_PARAM);
|
|
418
|
+
source = source.endsWith("/") ? `${source.slice(0, -1)}(?:/${sources.catchAll})?` : source + sources.catchAll;
|
|
449
419
|
i += 1;
|
|
450
420
|
} else {
|
|
451
421
|
const ch = pattern[i];
|
|
@@ -1768,18 +1738,19 @@ function movePrivateServerSourceMaps(outputDir, privateDir, filenames) {
|
|
|
1768
1738
|
|
|
1769
1739
|
// src/build/server-app-entry.ts
|
|
1770
1740
|
import { writeFileSync as writeFileSync2 } from "fs";
|
|
1771
|
-
import { join as
|
|
1741
|
+
import { join as join6 } from "path";
|
|
1772
1742
|
|
|
1773
1743
|
// src/plugin/route-registry.ts
|
|
1774
|
-
import {
|
|
1744
|
+
import { join as join5, resolve as resolve2 } from "path";
|
|
1775
1745
|
|
|
1776
1746
|
// src/plugin/route-modules.ts
|
|
1777
1747
|
import { existsSync as existsSync5, readFileSync, realpathSync, statSync } from "fs";
|
|
1778
1748
|
import { dirname as dirname4, isAbsolute as isAbsolute2, join as join4, relative as relative3, sep } from "path";
|
|
1779
1749
|
import { pathToFileURL } from "url";
|
|
1780
1750
|
var ROUTE_MODULE_CACHE_SYMBOL = Symbol.for("@teyik0/furin/route-module-cache");
|
|
1751
|
+
var OPTIONAL_MARK = /\?$/;
|
|
1781
1752
|
function validateRouteParams(path, schemas) {
|
|
1782
|
-
const pathParams = path.split("/").filter((segment) => segment === "*" || segment.startsWith(":")).map((segment) => segment === "*" ?
|
|
1753
|
+
const pathParams = path.split("/").filter((segment) => segment === "*" || segment.startsWith(":")).map((segment) => segment === "*" ? SPLAT_PARAM : segment.slice(1).replace(OPTIONAL_MARK, ""));
|
|
1783
1754
|
if (pathParams.length === 0) {
|
|
1784
1755
|
return;
|
|
1785
1756
|
}
|
|
@@ -1895,118 +1866,342 @@ async function validateRouteModules(routeFiles) {
|
|
|
1895
1866
|
}
|
|
1896
1867
|
|
|
1897
1868
|
// src/plugin/route-tree.ts
|
|
1869
|
+
import { resolve } from "path";
|
|
1870
|
+
|
|
1871
|
+
// src/plugin/route-manifest.ts
|
|
1898
1872
|
import { existsSync as existsSync6, readdirSync } from "fs";
|
|
1899
|
-
import { extname
|
|
1873
|
+
import { extname } from "path";
|
|
1900
1874
|
var ROUTE_EXTENSION = /\.(?:jsx?|tsx?)$/;
|
|
1901
|
-
var
|
|
1902
|
-
|
|
1903
|
-
|
|
1875
|
+
var PARAM_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
1876
|
+
var BRACKET_ESCAPE = /\[([^\]]*)\]/g;
|
|
1877
|
+
var SOURCE_EXTENSIONS = [".tsx", ".ts", ".jsx", ".js"];
|
|
1878
|
+
var PARAM_SEGMENT = /(^|\/):[^/]+/g;
|
|
1879
|
+
var NEXT_CATCH_ALL = /^\[\[?\.\.\.([^\]]+)\]\]?$/;
|
|
1880
|
+
function child(directory, name) {
|
|
1881
|
+
return `${directory}/${name}`;
|
|
1882
|
+
}
|
|
1883
|
+
function sortedEntries(directory) {
|
|
1884
|
+
return readdirSync(directory, { withFileTypes: true }).sort((left, right) => left.name.localeCompare(right.name));
|
|
1885
|
+
}
|
|
1886
|
+
function moduleBase(name) {
|
|
1887
|
+
if (name.endsWith(".d.ts") || !ROUTE_EXTENSION.test(name)) {
|
|
1888
|
+
return;
|
|
1889
|
+
}
|
|
1890
|
+
return name.slice(0, -extname(name).length);
|
|
1904
1891
|
}
|
|
1905
|
-
function
|
|
1906
|
-
return
|
|
1892
|
+
function findModule(directory, base) {
|
|
1893
|
+
return SOURCE_EXTENSIONS.map((extension) => child(directory, `${base}${extension}`)).find((path) => existsSync6(path));
|
|
1907
1894
|
}
|
|
1908
|
-
function
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
if (
|
|
1920
|
-
|
|
1921
|
-
}
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
if (ROUTE_CONVENTIONS.has(base)) {
|
|
1895
|
+
function paramName(name, raw, sourcePath) {
|
|
1896
|
+
if (!PARAM_NAME.test(name)) {
|
|
1897
|
+
throw new Error(`[furin] Invalid dynamic parameter ${JSON.stringify(raw)} in ${JSON.stringify(sourcePath)}. Parameter names must match ${PARAM_NAME}.`);
|
|
1898
|
+
}
|
|
1899
|
+
return name;
|
|
1900
|
+
}
|
|
1901
|
+
function splitFlatName(base) {
|
|
1902
|
+
const tokens = [];
|
|
1903
|
+
let current = "";
|
|
1904
|
+
let escaped = false;
|
|
1905
|
+
for (const character of base) {
|
|
1906
|
+
if (character === "[") {
|
|
1907
|
+
escaped = true;
|
|
1908
|
+
} else if (character === "]") {
|
|
1909
|
+
escaped = false;
|
|
1910
|
+
}
|
|
1911
|
+
if (character === "." && !escaped) {
|
|
1912
|
+
tokens.push(current);
|
|
1913
|
+
current = "";
|
|
1928
1914
|
continue;
|
|
1929
1915
|
}
|
|
1930
|
-
|
|
1931
|
-
|
|
1916
|
+
current += character;
|
|
1917
|
+
}
|
|
1918
|
+
tokens.push(current);
|
|
1919
|
+
return tokens;
|
|
1920
|
+
}
|
|
1921
|
+
function tanstackSegment(raw, sourcePath) {
|
|
1922
|
+
if (raw.startsWith("(") && raw.endsWith(")")) {
|
|
1923
|
+
return { raw, type: "group" };
|
|
1924
|
+
}
|
|
1925
|
+
if (raw === "$") {
|
|
1926
|
+
return { raw, type: "splat" };
|
|
1927
|
+
}
|
|
1928
|
+
if (raw.startsWith("{-$") && raw.endsWith("}")) {
|
|
1929
|
+
return {
|
|
1930
|
+
name: paramName(raw.slice(3, -1), raw, sourcePath),
|
|
1931
|
+
optional: true,
|
|
1932
|
+
raw,
|
|
1933
|
+
type: "param"
|
|
1934
|
+
};
|
|
1935
|
+
}
|
|
1936
|
+
if (raw.startsWith("$")) {
|
|
1937
|
+
return { name: paramName(raw.slice(1), raw, sourcePath), optional: false, raw, type: "param" };
|
|
1938
|
+
}
|
|
1939
|
+
if (raw.startsWith("_")) {
|
|
1940
|
+
return { raw, type: "pathless" };
|
|
1941
|
+
}
|
|
1942
|
+
const value = (raw.endsWith("_") ? raw.slice(0, -1) : raw).replace(BRACKET_ESCAPE, "$1");
|
|
1943
|
+
return { raw, type: "static", value };
|
|
1944
|
+
}
|
|
1945
|
+
function tanstackCandidate(base, segments, sourcePath) {
|
|
1946
|
+
const tokens = splitFlatName(base);
|
|
1947
|
+
const last = tokens.at(-1);
|
|
1948
|
+
const index = last === "index";
|
|
1949
|
+
const routeFile = last === "route";
|
|
1950
|
+
const own = (index || routeFile ? tokens.slice(0, -1) : tokens).map((token) => tanstackSegment(token, sourcePath));
|
|
1951
|
+
const routeSegments = [...segments, ...own];
|
|
1952
|
+
if (routeFile && routeSegments.length === 0) {
|
|
1953
|
+
throw new Error(`[furin] ${sourcePath}: a top-level route.tsx has no path to wrap. The root layout lives in __root.tsx.`);
|
|
1954
|
+
}
|
|
1955
|
+
return {
|
|
1956
|
+
forcedLayout: routeFile || routeSegments.at(-1)?.type === "pathless",
|
|
1957
|
+
index,
|
|
1958
|
+
segments: routeSegments,
|
|
1959
|
+
sourcePath
|
|
1960
|
+
};
|
|
1961
|
+
}
|
|
1962
|
+
function scanTanstack(pagesDir) {
|
|
1963
|
+
const candidates = [];
|
|
1964
|
+
const walk = (directory, segments) => {
|
|
1965
|
+
for (const entry of sortedEntries(directory)) {
|
|
1966
|
+
if (entry.name.startsWith("-")) {
|
|
1967
|
+
continue;
|
|
1968
|
+
}
|
|
1969
|
+
const sourcePath = child(directory, entry.name);
|
|
1970
|
+
if (entry.isDirectory()) {
|
|
1971
|
+
walk(sourcePath, [...segments, tanstackSegment(entry.name, sourcePath)]);
|
|
1972
|
+
continue;
|
|
1973
|
+
}
|
|
1974
|
+
const base = moduleBase(entry.name);
|
|
1975
|
+
if (base !== undefined && !(segments.length === 0 && base === "__root")) {
|
|
1976
|
+
candidates.push(tanstackCandidate(base, segments, sourcePath));
|
|
1977
|
+
}
|
|
1932
1978
|
}
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1979
|
+
};
|
|
1980
|
+
walk(pagesDir, []);
|
|
1981
|
+
return {
|
|
1982
|
+
boundaries: [],
|
|
1983
|
+
candidates,
|
|
1984
|
+
rootPath: findModule(pagesDir, "__root") ?? child(pagesDir, "__root.tsx")
|
|
1985
|
+
};
|
|
1986
|
+
}
|
|
1987
|
+
function nextSegment(name, sourcePath) {
|
|
1988
|
+
if (name.startsWith("(") && name.endsWith(")")) {
|
|
1989
|
+
return { raw: name, type: "group" };
|
|
1990
|
+
}
|
|
1991
|
+
const catchAll = name.match(NEXT_CATCH_ALL);
|
|
1992
|
+
if (catchAll?.[1] !== undefined) {
|
|
1993
|
+
paramName(catchAll[1], name, sourcePath);
|
|
1994
|
+
return { raw: "$", type: "splat" };
|
|
1995
|
+
}
|
|
1996
|
+
if (name.startsWith("[") && name.endsWith("]")) {
|
|
1997
|
+
const name_ = paramName(name.slice(1, -1), name, sourcePath);
|
|
1998
|
+
return { name: name_, optional: false, raw: `$${name_}`, type: "param" };
|
|
1999
|
+
}
|
|
2000
|
+
return { raw: name, type: "static", value: name };
|
|
2001
|
+
}
|
|
2002
|
+
function addNextFile(state, base, segments, sourcePath) {
|
|
2003
|
+
if (base === "route") {
|
|
2004
|
+
throw new Error(`[furin] ${sourcePath}: route handlers are not supported. Declare API routes on your Elysia app instead.`);
|
|
2005
|
+
}
|
|
2006
|
+
if (base === "layout" && segments.at(-1)?.type === "splat") {
|
|
2007
|
+
throw new Error(`[furin] ${sourcePath}: a layout cannot share a catch-all folder with its page: move it to the parent folder.`);
|
|
2008
|
+
}
|
|
2009
|
+
if (base === "page" || base === "layout" && segments.length > 0) {
|
|
2010
|
+
state.candidates.push({
|
|
2011
|
+
forcedLayout: base === "layout",
|
|
2012
|
+
index: base === "page" && segments.at(-1)?.type !== "splat",
|
|
2013
|
+
segments,
|
|
1936
2014
|
sourcePath
|
|
1937
2015
|
});
|
|
2016
|
+
} else if (base === "layout") {
|
|
2017
|
+
state.rootPath ??= sourcePath;
|
|
2018
|
+
} else if (base === "error") {
|
|
2019
|
+
state.boundary.errorPath ??= sourcePath;
|
|
2020
|
+
} else if (base === "not-found") {
|
|
2021
|
+
state.boundary.notFoundPath ??= sourcePath;
|
|
1938
2022
|
}
|
|
1939
2023
|
}
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
const
|
|
1943
|
-
|
|
2024
|
+
function scanNext(pagesDir) {
|
|
2025
|
+
const candidates = [];
|
|
2026
|
+
const boundaries = [];
|
|
2027
|
+
let rootPath;
|
|
2028
|
+
const walk = (directory, segments) => {
|
|
2029
|
+
const boundary = { directory, errorPath: undefined, notFoundPath: undefined };
|
|
2030
|
+
const state = { boundary, candidates, rootPath };
|
|
2031
|
+
for (const entry of sortedEntries(directory)) {
|
|
2032
|
+
const sourcePath = child(directory, entry.name);
|
|
2033
|
+
if (!entry.isDirectory()) {
|
|
2034
|
+
addNextFile(state, moduleBase(entry.name), segments, sourcePath);
|
|
2035
|
+
} else if (!entry.name.startsWith("_")) {
|
|
2036
|
+
walk(sourcePath, [...segments, nextSegment(entry.name, sourcePath)]);
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
rootPath ??= state.rootPath;
|
|
2040
|
+
if (boundary.errorPath || boundary.notFoundPath) {
|
|
2041
|
+
boundaries.push(boundary);
|
|
2042
|
+
}
|
|
2043
|
+
};
|
|
2044
|
+
walk(pagesDir, []);
|
|
2045
|
+
boundaries.sort((left, right) => left.directory.length - right.directory.length);
|
|
2046
|
+
return { boundaries, candidates, rootPath: rootPath ?? child(pagesDir, "layout.tsx") };
|
|
2047
|
+
}
|
|
2048
|
+
function segmentKey(segments) {
|
|
2049
|
+
return segments.map((segment) => segment.raw).join("/");
|
|
1944
2050
|
}
|
|
1945
|
-
function
|
|
1946
|
-
|
|
2051
|
+
function segmentPattern(segment) {
|
|
2052
|
+
switch (segment.type) {
|
|
2053
|
+
case "group":
|
|
2054
|
+
case "pathless":
|
|
2055
|
+
return;
|
|
2056
|
+
case "param":
|
|
2057
|
+
return `:${segment.name}${segment.optional ? "?" : ""}`;
|
|
2058
|
+
case "splat":
|
|
2059
|
+
return "*";
|
|
2060
|
+
default:
|
|
2061
|
+
return segment.value;
|
|
2062
|
+
}
|
|
1947
2063
|
}
|
|
1948
|
-
function
|
|
1949
|
-
|
|
1950
|
-
return `_route_${instanceId}_${encodedPath}`;
|
|
2064
|
+
function urlPattern(segments) {
|
|
2065
|
+
return `/${segments.flatMap((segment) => segmentPattern(segment) ?? []).join("/")}`;
|
|
1951
2066
|
}
|
|
1952
|
-
function
|
|
1953
|
-
|
|
1954
|
-
|
|
2067
|
+
function routeParams(segments) {
|
|
2068
|
+
return segments.flatMap((segment) => {
|
|
2069
|
+
if (segment.type === "param") {
|
|
2070
|
+
return [{ name: segment.name, optional: segment.optional }];
|
|
2071
|
+
}
|
|
2072
|
+
return segment.type === "splat" ? [{ name: "_splat", optional: false }] : [];
|
|
2073
|
+
});
|
|
2074
|
+
}
|
|
2075
|
+
function assertSplatLast(candidate) {
|
|
2076
|
+
const splat = candidate.segments.findIndex((segment) => segment.type === "splat");
|
|
2077
|
+
if (splat !== -1 && splat < candidate.segments.length - 1) {
|
|
2078
|
+
throw new Error(`[furin] ${candidate.sourcePath}: a catch-all segment must be the last segment of its path.`);
|
|
2079
|
+
}
|
|
2080
|
+
}
|
|
2081
|
+
function patternKeys(pattern) {
|
|
2082
|
+
const keys = expandOptionalSegments(pattern).map((variant) => variant.replace(PARAM_SEGMENT, "$1:param"));
|
|
2083
|
+
return [...new Set(keys)];
|
|
2084
|
+
}
|
|
2085
|
+
function claimPatterns(seenPatterns, pattern, sourcePath, relativePath) {
|
|
2086
|
+
for (const patternKey of patternKeys(pattern)) {
|
|
2087
|
+
const previous = seenPatterns.get(patternKey);
|
|
2088
|
+
if (previous !== undefined) {
|
|
2089
|
+
throw new Error(`[furin] Duplicate route pattern "${patternKey}" from "${relativePath(previous)}" and "${relativePath(sourcePath)}".`);
|
|
2090
|
+
}
|
|
2091
|
+
seenPatterns.set(patternKey, sourcePath);
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
2094
|
+
function buildManifest(scan, pagesDir, prefix) {
|
|
2095
|
+
const relativePath = (path) => path.slice(pagesDir.length + 1);
|
|
2096
|
+
const { candidates } = scan;
|
|
2097
|
+
const keys = candidates.map((candidate) => segmentKey(candidate.segments));
|
|
2098
|
+
const hasDescendant = (key, self2) => candidates.some((other, index) => other !== self2 && (keys[index]?.startsWith(`${key}/`) === true || other.index && keys[index] === key));
|
|
2099
|
+
const layouts = new Map;
|
|
2100
|
+
const kinds = candidates.map((candidate, index) => {
|
|
2101
|
+
assertSplatLast(candidate);
|
|
2102
|
+
const key = keys[index] ?? "";
|
|
2103
|
+
const isLayout = !candidate.index && (candidate.forcedLayout || hasDescendant(key, candidate));
|
|
2104
|
+
if (!isLayout) {
|
|
2105
|
+
return "page";
|
|
2106
|
+
}
|
|
2107
|
+
const existing = layouts.get(key);
|
|
2108
|
+
if (existing !== undefined) {
|
|
2109
|
+
throw new Error(`[furin] Two layouts wrap "/${key}": "${relativePath(existing)}" and "${relativePath(candidate.sourcePath)}".`);
|
|
2110
|
+
}
|
|
2111
|
+
layouts.set(key, candidate.sourcePath);
|
|
2112
|
+
return "layout";
|
|
2113
|
+
});
|
|
2114
|
+
const seenIds = new Map;
|
|
1955
2115
|
const seenPatterns = new Map;
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
2116
|
+
const routes = candidates.map((candidate, index) => {
|
|
2117
|
+
const kind = kinds[index] ?? "page";
|
|
2118
|
+
const { segments, sourcePath } = candidate;
|
|
2119
|
+
const key = keys[index] ?? "";
|
|
2120
|
+
let parentPath = candidate.index ? layouts.get(key) : undefined;
|
|
2121
|
+
for (let depth = segments.length - 1;parentPath === undefined && depth > 0; depth -= 1) {
|
|
2122
|
+
parentPath = layouts.get(segmentKey(segments.slice(0, depth)));
|
|
2123
|
+
}
|
|
2124
|
+
const path = `/${key}${candidate.index && key !== "" ? "/" : ""}`;
|
|
2125
|
+
const id = prefix === "" ? path : `${prefix}${path}`;
|
|
2126
|
+
const previousId = seenIds.get(id);
|
|
2127
|
+
if (previousId !== undefined) {
|
|
2128
|
+
throw new Error(`[furin] Duplicate route id "${id}" from "${relativePath(previousId)}" and "${relativePath(sourcePath)}".`);
|
|
2129
|
+
}
|
|
2130
|
+
seenIds.set(id, sourcePath);
|
|
2131
|
+
const pattern = urlPattern(segments);
|
|
2132
|
+
if (kind === "page") {
|
|
2133
|
+
claimPatterns(seenPatterns, pattern, sourcePath, relativePath);
|
|
2134
|
+
}
|
|
2135
|
+
return { id, kind, params: routeParams(segments), parentPath, pattern, sourcePath };
|
|
1969
2136
|
});
|
|
2137
|
+
return { boundaries: scan.boundaries, rootPath: scan.rootPath, routes };
|
|
2138
|
+
}
|
|
2139
|
+
function scanRouteManifest({ pagesDir, prefix, style }) {
|
|
2140
|
+
const directory = pagesDir.replaceAll("\\", "/");
|
|
2141
|
+
return buildManifest(style === "nextjs" ? scanNext(directory) : scanTanstack(directory), directory, prefix);
|
|
2142
|
+
}
|
|
2143
|
+
|
|
2144
|
+
// src/plugin/route-tree.ts
|
|
2145
|
+
function instanceKey(instance) {
|
|
2146
|
+
return `${resolve(instance.pagesDir)}\x00${instance.prefix}`;
|
|
2147
|
+
}
|
|
2148
|
+
function routeModuleSpecifier(instance) {
|
|
2149
|
+
return `@teyik0/furin/routes?instance=${Bun.hash(instanceKey(instance)).toString(16)}`;
|
|
1970
2150
|
}
|
|
1971
|
-
function
|
|
1972
|
-
const
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
2151
|
+
function routeId(instanceId, id) {
|
|
2152
|
+
const encodedId = Array.from(new TextEncoder().encode(id), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
2153
|
+
return `_route_${instanceId}_${encodedId}`;
|
|
2154
|
+
}
|
|
2155
|
+
function relativePrefix(pattern, parentPattern) {
|
|
2156
|
+
const own = pattern === "/" ? "" : pattern;
|
|
2157
|
+
const parent = parentPattern === "/" ? "" : parentPattern;
|
|
2158
|
+
if (!own.startsWith(parent)) {
|
|
2159
|
+
throw new Error(`[furin] Route pattern "${pattern}" does not extend its layout's "${parentPattern}".`);
|
|
2160
|
+
}
|
|
2161
|
+
return own.slice(parent.length);
|
|
2162
|
+
}
|
|
2163
|
+
function buildRouteTree(instance, instanceId) {
|
|
2164
|
+
const { routes } = scanRouteManifest(instance);
|
|
2165
|
+
const byPath = new Map(routes.map((route) => [route.sourcePath, route]));
|
|
2166
|
+
const root = { children: [], layout: undefined, pages: [], prefix: "" };
|
|
2167
|
+
const nodes = new Map([[undefined, root]]);
|
|
2168
|
+
const parentPattern = (route) => route.parentPath === undefined ? "/" : byPath.get(route.parentPath)?.pattern ?? "/";
|
|
2169
|
+
const ensureNode = (sourcePath) => {
|
|
2170
|
+
const existing = nodes.get(sourcePath);
|
|
1976
2171
|
if (existing) {
|
|
1977
2172
|
return existing;
|
|
1978
2173
|
}
|
|
2174
|
+
const layout = sourcePath === undefined ? undefined : byPath.get(sourcePath);
|
|
2175
|
+
if (!layout) {
|
|
2176
|
+
return root;
|
|
2177
|
+
}
|
|
2178
|
+
const prefix = relativePrefix(layout.pattern, parentPattern(layout));
|
|
1979
2179
|
const node = {
|
|
1980
2180
|
children: [],
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
2181
|
+
layout: {
|
|
2182
|
+
id: routeId(instanceId, layout.id),
|
|
2183
|
+
path: "",
|
|
2184
|
+
prefix,
|
|
2185
|
+
sourcePath: resolve(layout.sourcePath)
|
|
2186
|
+
},
|
|
2187
|
+
pages: [],
|
|
2188
|
+
prefix
|
|
1985
2189
|
};
|
|
1986
|
-
nodes.set(
|
|
1987
|
-
|
|
1988
|
-
ensureNode(segments.slice(0, -1)).children.push(node);
|
|
1989
|
-
}
|
|
2190
|
+
nodes.set(sourcePath, node);
|
|
2191
|
+
ensureNode(layout.parentPath).children.push(node);
|
|
1990
2192
|
return node;
|
|
1991
2193
|
};
|
|
1992
|
-
const
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
if (file.pattern === undefined) {
|
|
1996
|
-
const path = `/${file.directorySegments.map(segmentPath).join("/")}#layout`;
|
|
1997
|
-
node.layout = { id: routeId(instanceId, path), path: "", sourcePath: file.sourcePath };
|
|
2194
|
+
for (const route of routes) {
|
|
2195
|
+
if (route.kind === "layout") {
|
|
2196
|
+
ensureNode(route.sourcePath);
|
|
1998
2197
|
continue;
|
|
1999
2198
|
}
|
|
2000
|
-
|
|
2001
|
-
id: routeId(instanceId,
|
|
2002
|
-
path:
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
node.indexRoute = route;
|
|
2007
|
-
} else {
|
|
2008
|
-
node.fileRoutes.push(route);
|
|
2009
|
-
}
|
|
2199
|
+
ensureNode(route.parentPath).pages.push({
|
|
2200
|
+
id: routeId(instanceId, route.id),
|
|
2201
|
+
path: route.pattern,
|
|
2202
|
+
prefix: relativePrefix(route.pattern, parentPattern(route)),
|
|
2203
|
+
sourcePath: resolve(route.sourcePath)
|
|
2204
|
+
});
|
|
2010
2205
|
}
|
|
2011
2206
|
return root;
|
|
2012
2207
|
}
|
|
@@ -2021,17 +2216,13 @@ function collectRouteFiles(root) {
|
|
|
2021
2216
|
if (node.layout) {
|
|
2022
2217
|
files.push(node.layout);
|
|
2023
2218
|
}
|
|
2024
|
-
|
|
2025
|
-
files.push(node.indexRoute);
|
|
2026
|
-
}
|
|
2027
|
-
files.push(...node.fileRoutes);
|
|
2219
|
+
files.push(...node.pages);
|
|
2028
2220
|
nodes.push(...node.children);
|
|
2029
2221
|
}
|
|
2030
2222
|
return files;
|
|
2031
2223
|
}
|
|
2032
2224
|
function routeSourcePaths(instance) {
|
|
2033
|
-
|
|
2034
|
-
return collectRouteFiles(buildRouteTree(instance.pagesDir, instanceId)).map(({ sourcePath }) => resolve(sourcePath)).toSorted((left, right) => left.localeCompare(right));
|
|
2225
|
+
return scanRouteManifest(instance).routes.map(({ sourcePath }) => resolve(sourcePath)).toSorted((left, right) => left.localeCompare(right));
|
|
2035
2226
|
}
|
|
2036
2227
|
|
|
2037
2228
|
// src/plugin/route-registry.ts
|
|
@@ -2040,7 +2231,6 @@ var ROUTES_REGISTRY_SPECIFIER = "furin/routes?registry";
|
|
|
2040
2231
|
var COMPOSABLE_ROUTES_REGISTRY_SPECIFIER = "furin/routes?registry=composable";
|
|
2041
2232
|
var ROUTES_REGISTRY_FILTER = /^furin\/routes\?registry(?:=composable)?$/;
|
|
2042
2233
|
var ROUTE_FILE_FILTER = /^furin-route-file:.+$/;
|
|
2043
|
-
var ROUTE_FILES_NAMESPACE = "furin-route-files";
|
|
2044
2234
|
var ROUTES_REGISTRY_FILE_FILTER = /[\\/]\.furin-routes-registry(?:-composable)?\.ts\?furin-virtual$/;
|
|
2045
2235
|
var CLIENT_ROUTES_NAMESPACE = "furin-routes-client";
|
|
2046
2236
|
var CLIENT_ROUTES_FILTER = /^(?:@teyik0\/furin|furin)\/routes$/;
|
|
@@ -2054,15 +2244,10 @@ function instanceNamespace(instance) {
|
|
|
2054
2244
|
}
|
|
2055
2245
|
function emitRouteNode(node, indentation, includeRootCatchAll) {
|
|
2056
2246
|
const childIndentation = `${indentation} `;
|
|
2057
|
-
const
|
|
2058
|
-
const head = `new Elysia({ prefix: ${JSON.stringify(prefix)} })`;
|
|
2247
|
+
const head = `new Elysia({ prefix: ${JSON.stringify(node.prefix)} })`;
|
|
2059
2248
|
const content = [];
|
|
2060
|
-
|
|
2061
|
-
content.push(`${childIndentation}.use(new Elysia({ prefix:
|
|
2062
|
-
}
|
|
2063
|
-
for (const route of node.fileRoutes.filter((file) => includeRootCatchAll || file.path !== "/*")) {
|
|
2064
|
-
const segment = route.path.slice(route.path.lastIndexOf("/") + 1);
|
|
2065
|
-
content.push(`${childIndentation}.use(new Elysia({ prefix: ${JSON.stringify(`/${segment}`)} }).use(${route.id}.elysia))`);
|
|
2249
|
+
for (const route of node.pages.filter((file) => includeRootCatchAll || file.path !== "/*")) {
|
|
2250
|
+
content.push(`${childIndentation}.use(new Elysia({ prefix: ${JSON.stringify(route.prefix)} }).use(${route.id}.elysia))`);
|
|
2066
2251
|
}
|
|
2067
2252
|
for (const child of node.children) {
|
|
2068
2253
|
content.push(`${childIndentation}.use(`);
|
|
@@ -2092,11 +2277,8 @@ async function retainComposableRoutes(node) {
|
|
|
2092
2277
|
if (node.layout && !await isComposable(node.layout)) {
|
|
2093
2278
|
node.layout = undefined;
|
|
2094
2279
|
}
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
}
|
|
2098
|
-
const composableRoutes = (await Promise.all(node.fileRoutes.map(async (route) => ({ keep: await isComposable(route), route })))).flatMap(({ keep, route }) => keep ? [route] : []);
|
|
2099
|
-
node.fileRoutes = composableRoutes;
|
|
2280
|
+
const composableRoutes = (await Promise.all(node.pages.map(async (route) => ({ keep: await isComposable(route), route })))).flatMap(({ keep, route }) => keep ? [route] : []);
|
|
2281
|
+
node.pages = composableRoutes;
|
|
2100
2282
|
await Promise.all(node.children.map((child) => retainComposableRoutes(child)));
|
|
2101
2283
|
}
|
|
2102
2284
|
async function generateServerInstance(instance, routeFilesBySpecifier, materialized, includeRootCatchAll) {
|
|
@@ -2107,7 +2289,7 @@ async function generateServerInstance(instance, routeFilesBySpecifier, materiali
|
|
|
2107
2289
|
return includeRootCatchAll ? instance.routeRegistry.complete : instance.routeRegistry.composable;
|
|
2108
2290
|
}
|
|
2109
2291
|
const instanceId = Bun.hash(instanceKey(instance)).toString(16);
|
|
2110
|
-
const tree = buildRouteTree(instance
|
|
2292
|
+
const tree = buildRouteTree(instance, instanceId);
|
|
2111
2293
|
await retainComposableRoutes(tree);
|
|
2112
2294
|
const imports = collectRouteFiles(tree).sort((left, right) => left.sourcePath.localeCompare(right.sourcePath)).map((route) => {
|
|
2113
2295
|
const specifier = materialized ? resolve2(route.sourcePath).replaceAll("\\", "/") : routeFileSpecifier(route);
|
|
@@ -2151,7 +2333,7 @@ async function clientRoutesSource(instance) {
|
|
|
2151
2333
|
if (instance.routeRegistry) {
|
|
2152
2334
|
return instance.routeRegistry.client;
|
|
2153
2335
|
}
|
|
2154
|
-
const tree = buildRouteTree(instance
|
|
2336
|
+
const tree = buildRouteTree(instance, Bun.hash(instanceKey(instance)).toString(16));
|
|
2155
2337
|
const routes = collectRouteFiles(tree).filter((route) => route.path !== "").sort((left, right) => left.path.localeCompare(right.path));
|
|
2156
2338
|
const metadata = await Promise.all(routes.map(async (routeFile) => {
|
|
2157
2339
|
const module = await loadRouteModule(routeFile.sourcePath);
|
|
@@ -2180,9 +2362,8 @@ function serverProxySource(instance, includeRootCatchAll) {
|
|
|
2180
2362
|
}
|
|
2181
2363
|
function createRoutesPlugin(options) {
|
|
2182
2364
|
const routeFilesBySpecifier = new Map;
|
|
2183
|
-
const
|
|
2184
|
-
const
|
|
2185
|
-
const composableRegistryVirtualPath = join6(resolve2(primaryInstance(options.instances).pagesDir), ".furin-routes-registry-composable.ts?furin-virtual");
|
|
2365
|
+
const registryVirtualPath = join5(resolve2(primaryInstance(options.instances).pagesDir), ".furin-routes-registry.ts?furin-virtual");
|
|
2366
|
+
const composableRegistryVirtualPath = join5(resolve2(primaryInstance(options.instances).pagesDir), ".furin-routes-registry-composable.ts?furin-virtual");
|
|
2186
2367
|
const instancesBySpecifier = new Map(options.instances.flatMap((instance) => [
|
|
2187
2368
|
[
|
|
2188
2369
|
routeModuleSpecifier(instance),
|
|
@@ -2232,20 +2413,7 @@ function createRoutesPlugin(options) {
|
|
|
2232
2413
|
if (!routeFile) {
|
|
2233
2414
|
throw new Error(`[furin] Unknown route module: ${path}`);
|
|
2234
2415
|
}
|
|
2235
|
-
|
|
2236
|
-
routeFilesByResolvedPath.set(resolvedPath, routeFile);
|
|
2237
|
-
return { namespace: ROUTE_FILES_NAMESPACE, path: resolvedPath };
|
|
2238
|
-
});
|
|
2239
|
-
build.onLoad({ filter: VIRTUAL_ROUTES_FILTER, namespace: ROUTE_FILES_NAMESPACE }, async ({ path }) => {
|
|
2240
|
-
const routeFile = routeFilesByResolvedPath.get(path);
|
|
2241
|
-
if (!routeFile) {
|
|
2242
|
-
throw new Error(`[furin] Unknown route module: ${path}`);
|
|
2243
|
-
}
|
|
2244
|
-
return {
|
|
2245
|
-
contents: await Bun.file(routeFile.sourcePath).text(),
|
|
2246
|
-
loader: detectLoaderFromPath(routeFile.sourcePath),
|
|
2247
|
-
resolveDir: dirname5(routeFile.sourcePath)
|
|
2248
|
-
};
|
|
2416
|
+
return { path: routeFile.sourcePath };
|
|
2249
2417
|
});
|
|
2250
2418
|
for (const { instance, namespace, includeRootCatchAll } of instancesBySpecifier.values()) {
|
|
2251
2419
|
build.onLoad({ filter: VIRTUAL_ROUTES_FILTER, namespace }, () => ({
|
|
@@ -2265,11 +2433,11 @@ async function materializeServerAppEntry(options) {
|
|
|
2265
2433
|
if (!instance) {
|
|
2266
2434
|
throw new Error(`[furin] Missing route instance for server app ${index}.`);
|
|
2267
2435
|
}
|
|
2268
|
-
const routePath =
|
|
2436
|
+
const routePath = join6(options.outDir, `_furin-routes-${index}.ts`);
|
|
2269
2437
|
writeFileSync2(routePath, await materializedRouteModuleSource(instance));
|
|
2270
2438
|
return { ...app, nativeRoutes: toPosixPath(routePath) };
|
|
2271
2439
|
}));
|
|
2272
|
-
const entryPath =
|
|
2440
|
+
const entryPath = join6(options.outDir, "_furin-app.ts");
|
|
2273
2441
|
writeFileSync2(entryPath, buildEntrySource({
|
|
2274
2442
|
apps,
|
|
2275
2443
|
headerComment: options.headerComment,
|
|
@@ -2282,7 +2450,7 @@ async function materializeServerAppEntry(options) {
|
|
|
2282
2450
|
|
|
2283
2451
|
// src/rsc/build/index.ts
|
|
2284
2452
|
import { mkdirSync as mkdirSync2, writeFileSync as writeFileSync3 } from "fs";
|
|
2285
|
-
import { basename as basename2, join as
|
|
2453
|
+
import { basename as basename2, join as join8 } from "path";
|
|
2286
2454
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
2287
2455
|
// ../../node_modules/.bun/yuku-ast@0.13.0/node_modules/yuku-ast/dist/aliases.js
|
|
2288
2456
|
var ALIAS_GROUPS = {
|
|
@@ -4806,9 +4974,9 @@ var MagicString = class MagicString {
|
|
|
4806
4974
|
};
|
|
4807
4975
|
|
|
4808
4976
|
// src/shared/parser.ts
|
|
4809
|
-
import { parse
|
|
4977
|
+
import { parse } from "yuku-parser";
|
|
4810
4978
|
function parseSource(code, lang) {
|
|
4811
|
-
return
|
|
4979
|
+
return parse(code, { lang, sourceType: "module" });
|
|
4812
4980
|
}
|
|
4813
4981
|
|
|
4814
4982
|
// src/plugin/module-transform.ts
|
|
@@ -5152,7 +5320,7 @@ function pruneOrphanedCode(module, forced, retained) {
|
|
|
5152
5320
|
|
|
5153
5321
|
// src/plugin/transform-client-module.ts
|
|
5154
5322
|
import { realpathSync as realpathSync2 } from "fs";
|
|
5155
|
-
import { dirname as
|
|
5323
|
+
import { dirname as dirname5 } from "path";
|
|
5156
5324
|
var FURIN_CLIENT_MODULES = new Set(["@teyik0/furin/client", "furin/client"]);
|
|
5157
5325
|
var SERVER_LOAD = '() => Promise.reject(new Error("[furin] clientModule() can only be loaded in the browser."))';
|
|
5158
5326
|
function clientModuleKey(modulePath) {
|
|
@@ -5207,7 +5375,7 @@ function rewriteClientModules(module, environment) {
|
|
|
5207
5375
|
}
|
|
5208
5376
|
let key;
|
|
5209
5377
|
try {
|
|
5210
|
-
key = JSON.stringify(clientModuleKey(Bun.resolveSync(specifier,
|
|
5378
|
+
key = JSON.stringify(clientModuleKey(Bun.resolveSync(specifier, dirname5(filename))));
|
|
5211
5379
|
} catch (error) {
|
|
5212
5380
|
throw new Error(`[furin] Cannot resolve clientModule import ${JSON.stringify(specifier)} in ${filename}`, { cause: error });
|
|
5213
5381
|
}
|
|
@@ -5674,13 +5842,13 @@ function assertInstalledRscVersions() {
|
|
|
5674
5842
|
}
|
|
5675
5843
|
|
|
5676
5844
|
// src/rsc/build/client-references.ts
|
|
5677
|
-
import { dirname as
|
|
5845
|
+
import { dirname as dirname7 } from "path";
|
|
5678
5846
|
|
|
5679
5847
|
// ../../node_modules/.bun/cjs-module-lexer@2.3.0/node_modules/cjs-module-lexer/dist/lexer.mjs
|
|
5680
5848
|
var A;
|
|
5681
5849
|
var B = new Uint8Array(new Uint16Array([1]).buffer)[0] === 1;
|
|
5682
5850
|
var Q = typeof Buffer != "undefined";
|
|
5683
|
-
function
|
|
5851
|
+
function parse2(g, C = "@") {
|
|
5684
5852
|
A || initSync();
|
|
5685
5853
|
const G = g.length + 1, D = (A.__heap_base.value || A.__heap_base) + 4 * G - A.memory.buffer.byteLength;
|
|
5686
5854
|
D > 0 && A.memory.grow(Math.ceil(D / 65536));
|
|
@@ -5859,11 +6027,11 @@ function initSync() {
|
|
|
5859
6027
|
import { readFileSync as readFileSync2 } from "fs";
|
|
5860
6028
|
|
|
5861
6029
|
// src/rsc/build/paths.ts
|
|
5862
|
-
import { dirname as
|
|
6030
|
+
import { dirname as dirname6, join as join7 } from "path";
|
|
5863
6031
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
5864
|
-
var SOURCE_DIR =
|
|
5865
|
-
var CLIENT_REFERENCE_RUNTIME_PATH =
|
|
5866
|
-
var BUNDLED_CLIENT_CODEC_PATH =
|
|
6032
|
+
var SOURCE_DIR = dirname6(fileURLToPath3(import.meta.resolve("@teyik0/furin/rsc")));
|
|
6033
|
+
var CLIENT_REFERENCE_RUNTIME_PATH = join7(SOURCE_DIR, "rsc/client-references.ts");
|
|
6034
|
+
var BUNDLED_CLIENT_CODEC_PATH = join7(SOURCE_DIR, "rsc/bundled-client-codec.ts");
|
|
5867
6035
|
|
|
5868
6036
|
// src/rsc/build/flight-loader.ts
|
|
5869
6037
|
var CLIENT_CODEC = /react-server-dom-webpack-client\.(?:edge|browser)\.(?:development|production)\.js$/;
|
|
@@ -5984,7 +6152,7 @@ function clientReferencesPlugin(references) {
|
|
|
5984
6152
|
contents: isCommonJsModule(source, sourcePath) ? source : `${source}
|
|
5985
6153
|
${clientRegistration(sourcePath, path, prefix, references)}`,
|
|
5986
6154
|
loader: detectLoaderFromPath(sourcePath),
|
|
5987
|
-
resolveDir:
|
|
6155
|
+
resolveDir: dirname7(sourcePath)
|
|
5988
6156
|
};
|
|
5989
6157
|
});
|
|
5990
6158
|
build.onLoad({ filter: SCRIPTS }, async ({ path }) => {
|
|
@@ -6001,7 +6169,7 @@ registerClientModule(${JSON.stringify(clientModuleId(path))}, implementation);`
|
|
|
6001
6169
|
export * from ${JSON.stringify(path + IMPLEMENTATION)};
|
|
6002
6170
|
${names.length > 0 ? `export { ${names.map((name) => JSON.stringify(name)).join(", ")} } from ${JSON.stringify(path + IMPLEMENTATION)};` : ""}`,
|
|
6003
6171
|
loader: "js",
|
|
6004
|
-
resolveDir:
|
|
6172
|
+
resolveDir: dirname7(path)
|
|
6005
6173
|
};
|
|
6006
6174
|
});
|
|
6007
6175
|
}
|
|
@@ -6015,7 +6183,7 @@ function commonJsExports(source, path) {
|
|
|
6015
6183
|
withoutImports.remove(statement.start, statement.end);
|
|
6016
6184
|
}
|
|
6017
6185
|
}
|
|
6018
|
-
return
|
|
6186
|
+
return parse2(withoutImports.toString());
|
|
6019
6187
|
}
|
|
6020
6188
|
async function exportedNames(source, path, visited) {
|
|
6021
6189
|
if (visited.has(path)) {
|
|
@@ -6040,7 +6208,7 @@ async function exportedNames(source, path, visited) {
|
|
|
6040
6208
|
}
|
|
6041
6209
|
}
|
|
6042
6210
|
for (const specifier of reexports) {
|
|
6043
|
-
const dependency = Bun.resolveSync(specifier,
|
|
6211
|
+
const dependency = Bun.resolveSync(specifier, dirname7(path));
|
|
6044
6212
|
const exported = await exportedNames(await Bun.file(dependency).text(), dependency, visited);
|
|
6045
6213
|
for (const name of exported) {
|
|
6046
6214
|
if (name !== "default") {
|
|
@@ -6144,7 +6312,7 @@ ${codecResult.logs.map((log) => log.message).join(`
|
|
|
6144
6312
|
}
|
|
6145
6313
|
async function buildRscGraph(apps, outDir, buildId, userPlugins, external) {
|
|
6146
6314
|
await assertInstalledRscVersions();
|
|
6147
|
-
const graphDir =
|
|
6315
|
+
const graphDir = join8(outDir, "rsc");
|
|
6148
6316
|
mkdirSync2(graphDir, { recursive: true });
|
|
6149
6317
|
const rscEntry = fileURLToPath5(import.meta.resolve("../../rsc-server.tsx"));
|
|
6150
6318
|
const entrypoints = [
|
|
@@ -6198,13 +6366,13 @@ ${result.logs.map((log) => log.message).join(`
|
|
|
6198
6366
|
clientReferences: referencedClientExports(clientReferences, result.metafile),
|
|
6199
6367
|
css
|
|
6200
6368
|
};
|
|
6201
|
-
writeFileSync3(
|
|
6369
|
+
writeFileSync3(join8(graphDir, "manifest.json"), JSON.stringify(manifest, null, 2));
|
|
6202
6370
|
return manifest;
|
|
6203
6371
|
}
|
|
6204
6372
|
|
|
6205
6373
|
// src/adapter/prerender.ts
|
|
6206
6374
|
import { readFileSync as readFileSync3, rmSync as rmSync2 } from "fs";
|
|
6207
|
-
import { join as
|
|
6375
|
+
import { join as join9 } from "path";
|
|
6208
6376
|
import { pathToFileURL as pathToFileURL2 } from "url";
|
|
6209
6377
|
function prerenderScript(module, render, resultPath) {
|
|
6210
6378
|
const href = JSON.stringify(pathToFileURL2(module.path).href);
|
|
@@ -6223,7 +6391,7 @@ process.exit(0);
|
|
|
6223
6391
|
`;
|
|
6224
6392
|
}
|
|
6225
6393
|
async function runBundleScript(script, cwd, failure) {
|
|
6226
|
-
const resultPath =
|
|
6394
|
+
const resultPath = join9(cwd, ".furin", "build", `prerender-${crypto.randomUUID()}.json`);
|
|
6227
6395
|
const child = Bun.spawn([process.execPath, "-e", script(resultPath)], {
|
|
6228
6396
|
cwd,
|
|
6229
6397
|
env: { ...process.env, NODE_ENV: "production" },
|
|
@@ -6256,20 +6424,20 @@ function exportStaticFromBundle(path, cwd, options) {
|
|
|
6256
6424
|
// src/adapter/runtime-build.ts
|
|
6257
6425
|
import { existsSync as existsSync10, realpathSync as realpathSync4, writeFileSync as writeFileSync6 } from "fs";
|
|
6258
6426
|
import { createRequire } from "module";
|
|
6259
|
-
import { dirname as
|
|
6427
|
+
import { dirname as dirname11, isAbsolute as isAbsolute5, join as join12, relative as relative5, resolve as resolve7 } from "path";
|
|
6260
6428
|
import { fileURLToPath as fileURLToPath7 } from "url";
|
|
6261
6429
|
|
|
6262
6430
|
// src/build/client.ts
|
|
6263
6431
|
import { existsSync as existsSync9, mkdirSync as mkdirSync3 } from "fs";
|
|
6264
|
-
import { basename as basename4, dirname as
|
|
6432
|
+
import { basename as basename4, dirname as dirname10, join as join11, sep as sep2 } from "path";
|
|
6265
6433
|
import { fileURLToPath as fileURLToPath6 } from "url";
|
|
6266
6434
|
|
|
6267
6435
|
// src/plugin/client-plugin.ts
|
|
6268
|
-
import { dirname as
|
|
6436
|
+
import { dirname as dirname9, isAbsolute as isAbsolute4, resolve as resolve4 } from "path";
|
|
6269
6437
|
|
|
6270
6438
|
// src/plugin/hmr-dependencies.ts
|
|
6271
6439
|
import { readFileSync as readFileSync4 } from "fs";
|
|
6272
|
-
import { dirname as
|
|
6440
|
+
import { dirname as dirname8, isAbsolute as isAbsolute3, resolve as resolve3 } from "path";
|
|
6273
6441
|
function hmrDependencySignature(imports, filename) {
|
|
6274
6442
|
const routePath = resolve3(filename);
|
|
6275
6443
|
const visited = new Set;
|
|
@@ -6278,7 +6446,7 @@ function hmrDependencySignature(imports, filename) {
|
|
|
6278
6446
|
if (specifier === "furin" || specifier.startsWith("furin/") || specifier === "@teyik0/furin" || specifier.startsWith("@teyik0/furin/")) {
|
|
6279
6447
|
return true;
|
|
6280
6448
|
}
|
|
6281
|
-
const path = Bun.resolveSync(specifier,
|
|
6449
|
+
const path = Bun.resolveSync(specifier, dirname8(importer));
|
|
6282
6450
|
if (path === routePath) {
|
|
6283
6451
|
return false;
|
|
6284
6452
|
}
|
|
@@ -7142,11 +7310,12 @@ function stripServerCode(path, source) {
|
|
|
7142
7310
|
var ELYSIA_FILTER = /^elysia$/;
|
|
7143
7311
|
var BUN_BUILTIN_FILTER = /^bun:/;
|
|
7144
7312
|
var ANY_FILTER = /.*/;
|
|
7145
|
-
var
|
|
7313
|
+
var elysiaStub = (typeModule) => `export * as t from ${JSON.stringify(typeModule)};
|
|
7146
7314
|
export class NotFoundError extends Error { constructor(m) { super(m); this.name = "NotFoundError"; } }
|
|
7147
7315
|
export class ValidationError extends Error { constructor(m) { super(m); this.name = "ValidationError"; } }
|
|
7148
7316
|
export default {};
|
|
7149
7317
|
`;
|
|
7318
|
+
var ELYSIA_STUB_PREFIX = "elysia-stub:";
|
|
7150
7319
|
function trackHydrationTopology(filePath, source, topologyPaths) {
|
|
7151
7320
|
const normalizedPath = filePath.replaceAll("\\", "/");
|
|
7152
7321
|
if (!(normalizedPath.includes("/.furin/") && normalizedPath.endsWith("/_hydrate.tsx"))) {
|
|
@@ -7155,7 +7324,7 @@ function trackHydrationTopology(filePath, source, topologyPaths) {
|
|
|
7155
7324
|
const transpiler = new Bun.Transpiler({ loader: "tsx" });
|
|
7156
7325
|
for (const imported of transpiler.scanImports(source)) {
|
|
7157
7326
|
if (isAbsolute4(imported.path) || imported.path.startsWith(".")) {
|
|
7158
|
-
topologyPaths.add(resolve4(
|
|
7327
|
+
topologyPaths.add(resolve4(dirname9(filePath), imported.path.split("?")[0]));
|
|
7159
7328
|
}
|
|
7160
7329
|
}
|
|
7161
7330
|
}
|
|
@@ -7184,16 +7353,16 @@ function createClientStripPlugin({ mode }) {
|
|
|
7184
7353
|
environmentGuardPlugin("client").setup(build);
|
|
7185
7354
|
const topologyPaths = new Set;
|
|
7186
7355
|
const loadedSources = new Map;
|
|
7187
|
-
build.onResolve({ filter: ELYSIA_FILTER }, () => ({
|
|
7356
|
+
build.onResolve({ filter: ELYSIA_FILTER }, (args) => ({
|
|
7188
7357
|
namespace: "furin-stubs",
|
|
7189
|
-
path: "elysia
|
|
7358
|
+
path: ELYSIA_STUB_PREFIX + Bun.resolveSync("elysia/type", args.resolveDir)
|
|
7190
7359
|
}));
|
|
7191
7360
|
build.onResolve({ filter: BUN_BUILTIN_FILTER }, () => ({
|
|
7192
7361
|
namespace: "furin-stubs",
|
|
7193
7362
|
path: "bun-builtin-stub"
|
|
7194
7363
|
}));
|
|
7195
7364
|
build.onLoad({ filter: ANY_FILTER, namespace: "furin-stubs" }, (args) => ({
|
|
7196
|
-
contents: args.path
|
|
7365
|
+
contents: args.path.startsWith(ELYSIA_STUB_PREFIX) ? elysiaStub(args.path.slice(ELYSIA_STUB_PREFIX.length)) : "",
|
|
7197
7366
|
loader: "js"
|
|
7198
7367
|
}));
|
|
7199
7368
|
build.onLoad({ filter: SCRIPT_FILE_FILTER }, async (args) => {
|
|
@@ -7423,7 +7592,7 @@ ${buildIdMeta}${modeMeta}${faviconLink}${cssLinks ? `${cssLinks}
|
|
|
7423
7592
|
|
|
7424
7593
|
// src/build/route-types.ts
|
|
7425
7594
|
import { existsSync as existsSync7, readFileSync as readFileSync5, renameSync as renameSync2, writeFileSync as writeFileSync4 } from "fs";
|
|
7426
|
-
import { extname as extname2, join as
|
|
7595
|
+
import { extname as extname2, join as join10, relative as relative4, resolve as resolve5 } from "path";
|
|
7427
7596
|
|
|
7428
7597
|
// src/shared/route-map.ts
|
|
7429
7598
|
function compareCodeUnits(left, right) {
|
|
@@ -7462,38 +7631,19 @@ function tagToStringLiteral(tag) {
|
|
|
7462
7631
|
function importSpecifier(path, projectRoot) {
|
|
7463
7632
|
const extension = extname2(path);
|
|
7464
7633
|
const sourcePath = extension ? path.slice(0, -extension.length) : path;
|
|
7465
|
-
const relativePath =
|
|
7634
|
+
const relativePath = relative4(projectRoot, sourcePath).replaceAll("\\", "/");
|
|
7466
7635
|
return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
7467
7636
|
}
|
|
7468
|
-
function fileRouteEntries(
|
|
7469
|
-
const
|
|
7470
|
-
const
|
|
7471
|
-
|
|
7472
|
-
const
|
|
7473
|
-
const
|
|
7474
|
-
return { base, path, relativePath, segments };
|
|
7475
|
-
});
|
|
7476
|
-
const layouts = new Map(files.filter(({ base }) => base === "_route").map((file) => [file.segments.join("/"), file.path]));
|
|
7477
|
-
return files.map(({ base, path, relativePath, segments }) => {
|
|
7478
|
-
const isLayout = base === "_route";
|
|
7479
|
-
let parent = join11(pages, "root.tsx");
|
|
7480
|
-
for (let depth = isLayout ? segments.length - 1 : segments.length;depth > 0; depth -= 1) {
|
|
7481
|
-
const layout = layouts.get(segments.slice(0, depth).join("/"));
|
|
7482
|
-
if (layout) {
|
|
7483
|
-
parent = layout;
|
|
7484
|
-
break;
|
|
7485
|
-
}
|
|
7486
|
-
}
|
|
7487
|
-
const pathParams = [...segments, base].flatMap((segment) => {
|
|
7488
|
-
const dynamic = parseDynamicRouteSegment(segment, path);
|
|
7489
|
-
return dynamic ? [dynamic.catchAll ? '"*": string' : `${dynamic.name}: string`] : [];
|
|
7490
|
-
});
|
|
7491
|
-
const id = fileRouteId({ pagesDir: pages, prefix }, path);
|
|
7492
|
-
const pattern = filePathToPattern(isLayout ? segments.concat("index").join("/") : relativePath);
|
|
7637
|
+
function fileRouteEntries(instance, projectRoot) {
|
|
7638
|
+
const { prefix } = instance;
|
|
7639
|
+
const manifest = scanRouteManifest({ ...instance, pagesDir: resolve5(instance.pagesDir) });
|
|
7640
|
+
return manifest.routes.map(({ id, kind, params, parentPath, pattern }) => {
|
|
7641
|
+
const parent = parentPath ?? manifest.rootPath;
|
|
7642
|
+
const pathParams = params.map(({ name, optional }) => `${name}${optional ? "?" : ""}: string`);
|
|
7493
7643
|
return {
|
|
7494
7644
|
id,
|
|
7495
7645
|
lines: ` ${JSON.stringify(id)}: {
|
|
7496
|
-
kind: "${
|
|
7646
|
+
kind: "${kind}";
|
|
7497
7647
|
pattern: ${JSON.stringify(`${prefix}${pattern === "/" ? "" : pattern}` || "/")};
|
|
7498
7648
|
parent: typeof import(${JSON.stringify(importSpecifier(parent, projectRoot))}).route;
|
|
7499
7649
|
pathParams: {${pathParams.length > 0 ? ` ${pathParams.join("; ")} ` : ""}};
|
|
@@ -7532,7 +7682,7 @@ import "@teyik0/furin/routes";
|
|
|
7532
7682
|
|
|
7533
7683
|
${apps === undefined ? "" : fileRoutesDeclaration(apps, projectRoot)}${routeMapDeclaration(entries)}${tagBlock}
|
|
7534
7684
|
`;
|
|
7535
|
-
const typesPath =
|
|
7685
|
+
const typesPath = join10(projectRoot, "furin-env.d.ts");
|
|
7536
7686
|
const existing = existsSync7(typesPath) ? readFileSync5(typesPath, "utf8") : "";
|
|
7537
7687
|
if (content === existing) {
|
|
7538
7688
|
return false;
|
|
@@ -7595,11 +7745,13 @@ function hydrateEntry(routes, rootLayout, basePath, clientLogging, modulePathKey
|
|
|
7595
7745
|
continue;
|
|
7596
7746
|
}
|
|
7597
7747
|
const parts = [`depth: ${seg.depth}`];
|
|
7748
|
+
const errorExport = seg.fromRoute ? "route.errorComponent" : "default";
|
|
7749
|
+
const notFoundExport = seg.fromRoute ? "route.notFoundComponent" : "default";
|
|
7598
7750
|
if (errorIdent) {
|
|
7599
|
-
parts.push(`error: ${errorIdent}
|
|
7751
|
+
parts.push(`error: ${errorIdent}.${errorExport}`);
|
|
7600
7752
|
}
|
|
7601
7753
|
if (notFoundIdent) {
|
|
7602
|
-
parts.push(`notFound: ${notFoundIdent}
|
|
7754
|
+
parts.push(`notFound: ${notFoundIdent}.${notFoundExport}`);
|
|
7603
7755
|
}
|
|
7604
7756
|
if (seg.depth === 0 && seg.path.replaceAll("\\", "/") !== rootDirectory) {
|
|
7605
7757
|
parts.push("isRoot: false");
|
|
@@ -7864,6 +8016,7 @@ if (__deferred && __deferred._chunks) {
|
|
|
7864
8016
|
// with the server (stale deploy) or the server returned something we
|
|
7865
8017
|
// don't know how to hydrate. Bail loudly; the page stays static.
|
|
7866
8018
|
log.error({ action: "hydrate_no_match", pathname });
|
|
8019
|
+
if (import.meta.hot) throw new Error(\`[furin] No client route matches \${pathname}; the page stays static.\`);
|
|
7867
8020
|
return;
|
|
7868
8021
|
}
|
|
7869
8022
|
app = createElement(DocumentProvider, { value: documentState }, app);
|
|
@@ -7930,6 +8083,7 @@ if (__deferred && __deferred._chunks) {
|
|
|
7930
8083
|
log.info({ action: "hydrate_complete", pathname });
|
|
7931
8084
|
})().catch((err: unknown) => {
|
|
7932
8085
|
log.error({ action: "hydrate_failed", pathname, error: String(err) });
|
|
8086
|
+
if (import.meta.hot) console.error("[furin] Hydration failed:", err);
|
|
7933
8087
|
window.dispatchEvent(
|
|
7934
8088
|
new CustomEvent("furin:client-error", { detail: { error: err, phase: "hydrate" } })
|
|
7935
8089
|
);
|
|
@@ -7994,7 +8148,7 @@ function writeClientPreloadManifest(metafile, outputPaths, entryChunkPath, route
|
|
|
7994
8148
|
}
|
|
7995
8149
|
|
|
7996
8150
|
// src/build/client.ts
|
|
7997
|
-
var CLIENT_DIST_DIR = `${
|
|
8151
|
+
var CLIENT_DIST_DIR = `${join11(dirname10(dirname10(fileURLToPath6(import.meta.resolve("@teyik0/furin")))), "dist")}${sep2}`;
|
|
7998
8152
|
async function buildClient(routes, {
|
|
7999
8153
|
outDir,
|
|
8000
8154
|
rootLayout,
|
|
@@ -8007,11 +8161,11 @@ async function buildClient(routes, {
|
|
|
8007
8161
|
metafilePath,
|
|
8008
8162
|
optimizeImports,
|
|
8009
8163
|
reactCompiler,
|
|
8010
|
-
|
|
8164
|
+
pages,
|
|
8011
8165
|
routeRegistry
|
|
8012
8166
|
}) {
|
|
8013
8167
|
const dirName = clientDirName ?? "client";
|
|
8014
|
-
const clientDir =
|
|
8168
|
+
const clientDir = join11(outDir, dirName);
|
|
8015
8169
|
if (!existsSync9(outDir)) {
|
|
8016
8170
|
mkdirSync3(outDir, { recursive: true });
|
|
8017
8171
|
}
|
|
@@ -8020,7 +8174,7 @@ async function buildClient(routes, {
|
|
|
8020
8174
|
}
|
|
8021
8175
|
const boundaries = await discoverClientBoundaries([...new Set([rootLayout, ...routes.flatMap((route) => [route.path, ...route.routeChain.flatMap((entry) => entry.sourcePath ? [entry.sourcePath] : [])])])], plugins);
|
|
8022
8176
|
const hydrateCode = generateClientReferenceEntry(boundaries) + generateProductionHydrateEntry(routes, rootLayout, basePath, clientLogging);
|
|
8023
|
-
const hydratePath =
|
|
8177
|
+
const hydratePath = join11(outDir, dirName === "client" ? "_hydrate.tsx" : `_hydrate-${dirName}.tsx`);
|
|
8024
8178
|
const hydrateEntry = createVirtualBuildEntry(hydratePath, hydrateCode, "tsx");
|
|
8025
8179
|
console.log("[furin] Building production client bundle\u2026");
|
|
8026
8180
|
const routerLoggerPlugin = {
|
|
@@ -8060,7 +8214,7 @@ async function buildClient(routes, {
|
|
|
8060
8214
|
hydrateEntry.plugin,
|
|
8061
8215
|
...plugins ?? [],
|
|
8062
8216
|
...!clientLogging ? [routerLoggerPlugin] : [],
|
|
8063
|
-
...
|
|
8217
|
+
...pages ? [createRoutesPlugin({ instances: [{ ...pages, prefix: basePath, routeRegistry }], target: "client" })] : [],
|
|
8064
8218
|
createClientStripPlugin({ mode: "build" })
|
|
8065
8219
|
],
|
|
8066
8220
|
define: {
|
|
@@ -8097,11 +8251,11 @@ async function buildClient(routes, {
|
|
|
8097
8251
|
}
|
|
8098
8252
|
|
|
8099
8253
|
// src/adapter/runtime-build.ts
|
|
8100
|
-
var _pkgRoot2 =
|
|
8101
|
-
var _pkgSrcDir2 = existsSync10(
|
|
8254
|
+
var _pkgRoot2 = dirname11(dirname11(fileURLToPath7(import.meta.resolve("@teyik0/furin"))));
|
|
8255
|
+
var _pkgSrcDir2 = existsSync10(join12(_pkgRoot2, "src", "furin.ts")) ? join12(_pkgRoot2, "src") : join12(_pkgRoot2, "dist");
|
|
8102
8256
|
var _ext2 = ".ts";
|
|
8103
8257
|
function frameworkSourceModule(path) {
|
|
8104
|
-
return
|
|
8258
|
+
return join12(_pkgRoot2, "src", path);
|
|
8105
8259
|
}
|
|
8106
8260
|
var PPR_ROUTE_IMPORT_RE = /ppr-route(?:\.ts)?$/;
|
|
8107
8261
|
var MIXED_CACHE_IMPORT_RE = /mixed-cache(?:\.ts)?$/;
|
|
@@ -8154,12 +8308,12 @@ function nearestFingerprintFile(directory, names, boundary) {
|
|
|
8154
8308
|
let current = directory;
|
|
8155
8309
|
while (current !== undefined) {
|
|
8156
8310
|
for (const name of names) {
|
|
8157
|
-
const path =
|
|
8311
|
+
const path = join12(current, name);
|
|
8158
8312
|
if (existsSync10(path)) {
|
|
8159
8313
|
return path;
|
|
8160
8314
|
}
|
|
8161
8315
|
}
|
|
8162
|
-
const parent =
|
|
8316
|
+
const parent = dirname11(current);
|
|
8163
8317
|
current = parent === current || current === boundary ? undefined : parent;
|
|
8164
8318
|
}
|
|
8165
8319
|
return;
|
|
@@ -8212,9 +8366,9 @@ async function createBuildFingerprint(entryChunk, cssChunks, routes, root, serve
|
|
|
8212
8366
|
if (!isScript) {
|
|
8213
8367
|
return;
|
|
8214
8368
|
}
|
|
8215
|
-
const relativePath = toPosixPath(
|
|
8369
|
+
const relativePath = toPosixPath(relative5(rootBoundary, path));
|
|
8216
8370
|
const manifestBoundary = relativePath === ".." || relativePath.startsWith("../") || isAbsolute5(relativePath) ? undefined : rootBoundary;
|
|
8217
|
-
const manifest = nearestFingerprintFile(
|
|
8371
|
+
const manifest = nearestFingerprintFile(dirname11(path), ["package.json"], manifestBoundary);
|
|
8218
8372
|
if (manifest) {
|
|
8219
8373
|
fingerprintPaths.add(manifest);
|
|
8220
8374
|
await visit(manifest);
|
|
@@ -8223,7 +8377,7 @@ async function createBuildFingerprint(entryChunk, cssChunks, routes, root, serve
|
|
|
8223
8377
|
await Promise.all(transpiler.scanImports(content).flatMap(({ path: specifier, kind }) => {
|
|
8224
8378
|
let dependency;
|
|
8225
8379
|
try {
|
|
8226
|
-
dependency = kind === "require-call" || kind === "require-resolve" ? createRequire(path).resolve(specifier) : Bun.resolveSync(specifier,
|
|
8380
|
+
dependency = kind === "require-call" || kind === "require-resolve" ? createRequire(path).resolve(specifier) : Bun.resolveSync(specifier, dirname11(path));
|
|
8227
8381
|
} catch {
|
|
8228
8382
|
return [];
|
|
8229
8383
|
}
|
|
@@ -8261,11 +8415,11 @@ function stableFingerprintPath(path, projectRoot) {
|
|
|
8261
8415
|
if (dependencyStart !== -1) {
|
|
8262
8416
|
return `dependency/${posixPath.slice(dependencyStart + "/node_modules/".length)}`;
|
|
8263
8417
|
}
|
|
8264
|
-
const projectPath =
|
|
8418
|
+
const projectPath = relative5(realpathSync4(projectRoot), absolutePath);
|
|
8265
8419
|
if (!isAbsolute5(projectPath) && projectPath !== ".." && !projectPath.startsWith("../") && !projectPath.startsWith("..\\")) {
|
|
8266
8420
|
return `app/${toPosixPath(projectPath)}`;
|
|
8267
8421
|
}
|
|
8268
|
-
const frameworkPath =
|
|
8422
|
+
const frameworkPath = relative5(_pkgRoot2, absolutePath);
|
|
8269
8423
|
if (!isAbsolute5(frameworkPath) && frameworkPath !== ".." && !frameworkPath.startsWith("../") && !frameworkPath.startsWith("..\\")) {
|
|
8270
8424
|
return `furin/${toPosixPath(frameworkPath)}`;
|
|
8271
8425
|
}
|
|
@@ -8279,11 +8433,13 @@ function buildCompileMetadata(root, routes) {
|
|
|
8279
8433
|
const routeMetadata = {};
|
|
8280
8434
|
for (const route of routes) {
|
|
8281
8435
|
routeMetadata[toPosixPath(route.path)] = {
|
|
8436
|
+
layouts: route.layouts.map((layout) => ({ ...layout, path: toPosixPath(layout.path) })),
|
|
8282
8437
|
requestKeys: route.requestKeys,
|
|
8283
8438
|
requestKeysByLoader: route.requestKeysByLoader,
|
|
8284
8439
|
segmentBoundaries: route.segmentBoundaries.map((boundary) => ({
|
|
8285
8440
|
depth: boundary.depth,
|
|
8286
8441
|
errorPath: boundary.errorPath ? toPosixPath(boundary.errorPath) : undefined,
|
|
8442
|
+
...boundary.fromRoute ? { fromRoute: boundary.fromRoute } : {},
|
|
8287
8443
|
notFoundPath: boundary.notFoundPath ? toPosixPath(boundary.notFoundPath) : undefined,
|
|
8288
8444
|
path: toPosixPath(boundary.path)
|
|
8289
8445
|
}))
|
|
@@ -8305,7 +8461,7 @@ function pprRuntimePlugin(apps) {
|
|
|
8305
8461
|
return;
|
|
8306
8462
|
}
|
|
8307
8463
|
build.onResolve({ filter: PPR_ROUTE_IMPORT_RE }, ({ path, importer }) => {
|
|
8308
|
-
const absolute = resolve7(
|
|
8464
|
+
const absolute = resolve7(dirname11(importer.split("?")[0]), path);
|
|
8309
8465
|
if (absolute !== pprPath && `${absolute}.ts` !== pprPath) {
|
|
8310
8466
|
return;
|
|
8311
8467
|
}
|
|
@@ -8331,7 +8487,7 @@ function mixedRuntimePlugin(apps) {
|
|
|
8331
8487
|
return;
|
|
8332
8488
|
}
|
|
8333
8489
|
build.onResolve({ filter: MIXED_CACHE_IMPORT_RE }, ({ path, importer }) => {
|
|
8334
|
-
const absolute = resolve7(
|
|
8490
|
+
const absolute = resolve7(dirname11(importer.split("?")[0]), path);
|
|
8335
8491
|
if (absolute !== mixedPath && `${absolute}.ts` !== mixedPath) {
|
|
8336
8492
|
return;
|
|
8337
8493
|
}
|
|
@@ -8349,7 +8505,7 @@ function isFrameworkRuntimeImporter(importer) {
|
|
|
8349
8505
|
if (importer === "") {
|
|
8350
8506
|
return false;
|
|
8351
8507
|
}
|
|
8352
|
-
const fromRuntimeRoot =
|
|
8508
|
+
const fromRuntimeRoot = relative5(_pkgSrcDir2, importer.split("?")[0]);
|
|
8353
8509
|
return fromRuntimeRoot !== ".." && !fromRuntimeRoot.startsWith("../") && !fromRuntimeRoot.startsWith("..\\");
|
|
8354
8510
|
}
|
|
8355
8511
|
async function buildRuntimeApp(app, projectRoot, targetDir, serverEntry, options, targetName) {
|
|
@@ -8361,10 +8517,10 @@ async function buildRuntimeApp(app, projectRoot, targetDir, serverEntry, options
|
|
|
8361
8517
|
basePath: prefix,
|
|
8362
8518
|
clientDirName,
|
|
8363
8519
|
clientLogging: options.clientLogging ?? false,
|
|
8364
|
-
metafilePath: options.analyze ?
|
|
8520
|
+
metafilePath: options.analyze ? join12(dirname11(targetDir), "analysis", `${targetName}-${clientDirName}.json`) : undefined,
|
|
8365
8521
|
optimizeImports: options.optimizeImports,
|
|
8366
8522
|
outDir: targetDir,
|
|
8367
|
-
pagesDir: app.pagesDir,
|
|
8523
|
+
pages: { pagesDir: app.pagesDir, style: app.style },
|
|
8368
8524
|
routeRegistry: app.routeRegistry,
|
|
8369
8525
|
plugins: options.plugins,
|
|
8370
8526
|
preloadRouteChunks: options.preload?.routeChunks,
|
|
@@ -8375,9 +8531,9 @@ async function buildRuntimeApp(app, projectRoot, targetDir, serverEntry, options
|
|
|
8375
8531
|
const buildFingerprint = await createBuildFingerprint(`${prefix}
|
|
8376
8532
|
${entryChunk}`, cssChunks, routes, root, serverEntry, modulePaths, projectRoot);
|
|
8377
8533
|
const buildId = Bun.hash(buildFingerprint).toString(16).slice(0, 12);
|
|
8378
|
-
const clientDir =
|
|
8534
|
+
const clientDir = join12(targetDir, clientDirName);
|
|
8379
8535
|
const indexHtml = generateProdIndexHtml(entryChunk, cssChunks, buildId, undefined, false);
|
|
8380
|
-
writeFileSync6(
|
|
8536
|
+
writeFileSync6(join12(clientDir, "index.html"), indexHtml);
|
|
8381
8537
|
const { rootConventions, routeMetadata } = buildCompileMetadata(root, routes);
|
|
8382
8538
|
console.log(`[furin] Built ${label} (buildId ${buildId})`);
|
|
8383
8539
|
return {
|
|
@@ -8404,16 +8560,16 @@ ${entryChunk}`, cssChunks, routes, root, serverEntry, modulePaths, projectRoot);
|
|
|
8404
8560
|
}
|
|
8405
8561
|
|
|
8406
8562
|
// src/adapter/server-bundle.ts
|
|
8407
|
-
import { dirname as
|
|
8563
|
+
import { dirname as dirname14, relative as relative8 } from "path";
|
|
8408
8564
|
|
|
8409
8565
|
// src/build/elysia-aot.ts
|
|
8410
8566
|
import { fork } from "child_process";
|
|
8411
8567
|
import { existsSync as existsSync11, realpathSync as realpathSync5 } from "fs";
|
|
8412
|
-
import { dirname as
|
|
8568
|
+
import { dirname as dirname12, join as join13, relative as relative6, resolve as resolve8 } from "path";
|
|
8413
8569
|
import { fileURLToPath as fileURLToPath8 } from "url";
|
|
8414
8570
|
var AOT_NAMESPACE = "furin-elysia-aot";
|
|
8415
|
-
var ELYSIA_RESOLVE_DIR =
|
|
8416
|
-
var AOT_PROCESS_PATH =
|
|
8571
|
+
var ELYSIA_RESOLVE_DIR = dirname12(Bun.resolveSync("elysia", import.meta.dir));
|
|
8572
|
+
var AOT_PROCESS_PATH = join13(dirname12(dirname12(fileURLToPath8(import.meta.resolve("@teyik0/furin")))), "src/build/elysia-aot-worker.ts");
|
|
8417
8573
|
var SOURCE_FILTER = /\.[cm]?[jt]sx?$/;
|
|
8418
8574
|
var ELYSIA_IMPORT_FILTER = /^elysia(?:\/(?!compiled$|type$).*)?$/;
|
|
8419
8575
|
var ELYSIA_VIRTUAL_IMPORT_FILTER = /^elysia\/(?:compiled|type)$/;
|
|
@@ -8443,10 +8599,10 @@ export function drainWaiters(){return e()}
|
|
|
8443
8599
|
export function handleWSResponse(){return e()}
|
|
8444
8600
|
`;
|
|
8445
8601
|
}
|
|
8446
|
-
function mountLabel(rootDir, { pagesDir, prefix }) {
|
|
8602
|
+
function mountLabel(rootDir, { pagesDir, prefix, style }) {
|
|
8447
8603
|
const absolute = resolve8(rootDir, pagesDir);
|
|
8448
8604
|
const path = existsSync11(absolute) ? realpathSync5(absolute) : absolute;
|
|
8449
|
-
return `prefix ${JSON.stringify(prefix || "/")} (pagesDir ${
|
|
8605
|
+
return `prefix ${JSON.stringify(prefix || "/")} (pagesDir ${relative6(rootDir, path) || "."}, style ${style})`;
|
|
8450
8606
|
}
|
|
8451
8607
|
function registrationMismatch(build, registrations, evaluated) {
|
|
8452
8608
|
const root = realpathSync5(build.rootDir);
|
|
@@ -8607,7 +8763,7 @@ function elysiaAot(entry, expected) {
|
|
|
8607
8763
|
}
|
|
8608
8764
|
|
|
8609
8765
|
// src/build/production-instrumentation.ts
|
|
8610
|
-
import { dirname as
|
|
8766
|
+
import { dirname as dirname13, relative as relative7, resolve as resolve9 } from "path";
|
|
8611
8767
|
var INSTRUMENTATION_IMPORT = /(?:^|[/\\])devtools[/\\]instrumentation(?:\.ts|\.js)?$/;
|
|
8612
8768
|
var DEV_PAGE_PLUGIN_IMPORT = /(?:^|[/\\])server[/\\]dev-page-plugin(?:\.ts|\.js)?$/;
|
|
8613
8769
|
var DEV_RUNTIME_IMPORT = /(?:^|[/\\])server[/\\]dev[/\\](?:browser-events|diagnostics|graph|plugin|runtime)(?:\.ts|\.js)?$/;
|
|
@@ -8617,7 +8773,7 @@ var PRODUCTION_BOUNDARY_IMPORT = /(?:browser-events|instrumentation|dev-page-plu
|
|
|
8617
8773
|
var PRODUCTION_STUB_NAMESPACE = "furin-production-runtime-stub";
|
|
8618
8774
|
var FURIN_RUNTIME_ROOT = resolve9(import.meta.dir, "..");
|
|
8619
8775
|
function isFurinRuntimePath(path) {
|
|
8620
|
-
const fromRuntimeRoot =
|
|
8776
|
+
const fromRuntimeRoot = relative7(FURIN_RUNTIME_ROOT, path);
|
|
8621
8777
|
return fromRuntimeRoot !== ".." && !fromRuntimeRoot.startsWith("../") && !fromRuntimeRoot.startsWith("..\\");
|
|
8622
8778
|
}
|
|
8623
8779
|
function devBuildExports(path) {
|
|
@@ -8634,7 +8790,7 @@ function productionInstrumentationPlugin() {
|
|
|
8634
8790
|
name: "furin-production-instrumentation",
|
|
8635
8791
|
setup(build) {
|
|
8636
8792
|
build.onResolve({ filter: PRODUCTION_BOUNDARY_IMPORT }, (args) => {
|
|
8637
|
-
const importPath = resolve9(
|
|
8793
|
+
const importPath = resolve9(dirname13(args.importer), args.path);
|
|
8638
8794
|
if (!isFurinRuntimePath(importPath)) {
|
|
8639
8795
|
return;
|
|
8640
8796
|
}
|
|
@@ -8670,12 +8826,12 @@ var PRERENDER_SNAPSHOT_RE = /^\.\/furin-prerender\.json$/;
|
|
|
8670
8826
|
var ELYSIA_STATIC_IMPORT_RE = /^@elysia\/static$/;
|
|
8671
8827
|
var MATCH_ALL_RE = /.*/;
|
|
8672
8828
|
var STATIC_STUB_NAMESPACE = "furin-platform-assets-stub";
|
|
8673
|
-
var FURIN_RUNTIME_ROOT2 =
|
|
8829
|
+
var FURIN_RUNTIME_ROOT2 = dirname14(import.meta.dir);
|
|
8674
8830
|
function isFurinRuntimeImporter(importer) {
|
|
8675
8831
|
if (importer === "") {
|
|
8676
8832
|
return false;
|
|
8677
8833
|
}
|
|
8678
|
-
const fromRuntimeRoot =
|
|
8834
|
+
const fromRuntimeRoot = relative8(FURIN_RUNTIME_ROOT2, importer.split("?")[0]);
|
|
8679
8835
|
return fromRuntimeRoot !== ".." && !fromRuntimeRoot.startsWith("../") && !fromRuntimeRoot.startsWith("..\\");
|
|
8680
8836
|
}
|
|
8681
8837
|
function appSpecifierPlugin(appEntry) {
|
|
@@ -8769,10 +8925,10 @@ function withAssetContexts(adapter, builds, targetDir) {
|
|
|
8769
8925
|
return prepareCompileEntryApps({
|
|
8770
8926
|
apps: contexts.map((context) => ({
|
|
8771
8927
|
...context,
|
|
8772
|
-
embed: { clientDir:
|
|
8928
|
+
embed: { clientDir: join14(targetDir, clientDirNameForPrefix(context.prefix ?? "")) }
|
|
8773
8929
|
})),
|
|
8774
8930
|
outDir: targetDir,
|
|
8775
|
-
publicDir:
|
|
8931
|
+
publicDir: join14(targetDir, "public")
|
|
8776
8932
|
});
|
|
8777
8933
|
}
|
|
8778
8934
|
function adapterRoute(app, route) {
|
|
@@ -8816,22 +8972,22 @@ async function bundleServer(adapter, apps, appEntry, clientReferences, rootDir,
|
|
|
8816
8972
|
if (build.metafile === undefined) {
|
|
8817
8973
|
throw new Error(`[furin] The ${adapter.name} server build did not produce its metafile.`);
|
|
8818
8974
|
}
|
|
8819
|
-
writeBuildMetafile(
|
|
8975
|
+
writeBuildMetafile(join14(buildRoot, "analysis", `${adapter.name}-server.json`), build.metafile, "Server");
|
|
8820
8976
|
}
|
|
8821
8977
|
return {
|
|
8822
8978
|
dir: targetDir,
|
|
8823
8979
|
entry: `${basename5(adapter.runtimeModule, extname3(adapter.runtimeModule))}.js`,
|
|
8824
|
-
files: build.outputs.filter((output) => output.path.endsWith(".js")).map((output) => toPosixPath(
|
|
8980
|
+
files: build.outputs.filter((output) => output.path.endsWith(".js")).map((output) => toPosixPath(relative9(targetDir, output.path)))
|
|
8825
8981
|
};
|
|
8826
8982
|
}
|
|
8827
8983
|
function writePrerenderSnapshot(targetDir, prerenders) {
|
|
8828
8984
|
const snapshot = Object.fromEntries(prerenders.map(({ prefix, ssg }) => [prefix, ssg]));
|
|
8829
|
-
writeFileSync7(
|
|
8985
|
+
writeFileSync7(join14(targetDir, PRERENDER_SNAPSHOT_FILE), `${JSON.stringify(snapshot)}
|
|
8830
8986
|
`);
|
|
8831
8987
|
}
|
|
8832
8988
|
async function buildAdapterTarget(adapter, apps, rootDir, buildRoot, serverEntry, options) {
|
|
8833
8989
|
assertServerEntry(serverEntry, adapter);
|
|
8834
|
-
const targetDir =
|
|
8990
|
+
const targetDir = join14(buildRoot, adapter.name);
|
|
8835
8991
|
rmSync3(targetDir, { force: true, recursive: true });
|
|
8836
8992
|
rmSync3(privateServerSourceMapDir(buildRoot, adapter.name), {
|
|
8837
8993
|
force: true,
|
|
@@ -8842,10 +8998,10 @@ async function buildAdapterTarget(adapter, apps, rootDir, buildRoot, serverEntry
|
|
|
8842
8998
|
const rootIndex = apps.findIndex((app) => app.prefix === "");
|
|
8843
8999
|
const { buildId } = builds[rootIndex === -1 ? 0 : rootIndex];
|
|
8844
9000
|
const rscManifest = await buildRscGraph(apps, targetDir, buildId, options.plugins, options.serverExternalPackages);
|
|
8845
|
-
const projectPublicDir =
|
|
9001
|
+
const projectPublicDir = join14(rootDir, "public");
|
|
8846
9002
|
const publicDir = existsSync12(projectPublicDir) ? projectPublicDir : undefined;
|
|
8847
9003
|
if (publicDir !== undefined && adapter.capabilities.assets !== "platform") {
|
|
8848
|
-
copyDirRecursive(publicDir,
|
|
9004
|
+
copyDirRecursive(publicDir, join14(targetDir, "public"));
|
|
8849
9005
|
}
|
|
8850
9006
|
const frameworkCache = adapter.capabilities.publicCache === "framework";
|
|
8851
9007
|
const appEntry = await materializeServerAppEntry({
|
|
@@ -8864,7 +9020,7 @@ async function buildAdapterTarget(adapter, apps, rootDir, buildRoot, serverEntry
|
|
|
8864
9020
|
const info = routeBuildInfo(route);
|
|
8865
9021
|
return info.documentMode !== "ssr" && (info.queryKeys?.length ?? 0) === 0;
|
|
8866
9022
|
}));
|
|
8867
|
-
const prerenders = needsPrerender ? await prerenderFromBundle({ kind: "app", path:
|
|
9023
|
+
const prerenders = needsPrerender ? await prerenderFromBundle({ kind: "app", path: join14(targetDir, APP_MODULE) }, rootDir, frameworkCache) : [];
|
|
8868
9024
|
if (frameworkCache) {
|
|
8869
9025
|
writePrerenderSnapshot(targetDir, prerenders);
|
|
8870
9026
|
}
|
|
@@ -8888,7 +9044,7 @@ async function buildAdapterTarget(adapter, apps, rootDir, buildRoot, serverEntry
|
|
|
8888
9044
|
|
|
8889
9045
|
// src/adapter/bun.ts
|
|
8890
9046
|
import { existsSync as existsSync13, rmSync as rmSync4 } from "fs";
|
|
8891
|
-
import { join as
|
|
9047
|
+
import { join as join15, relative as relative10 } from "path";
|
|
8892
9048
|
var RUNTIME_MODULE = frameworkSourceModule("adapter/bun/server.ts");
|
|
8893
9049
|
var APP_RUNTIME_MODULE = frameworkSourceModule("adapter/bun/app.ts");
|
|
8894
9050
|
function compiledServerFilename(platform) {
|
|
@@ -8897,12 +9053,12 @@ function compiledServerFilename(platform) {
|
|
|
8897
9053
|
async function compileExecutable(output, compile, manifest) {
|
|
8898
9054
|
const { apps, buildRoot, server } = output;
|
|
8899
9055
|
const filename = compiledServerFilename(process.platform);
|
|
8900
|
-
const publicDir =
|
|
9056
|
+
const publicDir = join15(server.dir, "public");
|
|
8901
9057
|
const embedded = compile === "embed" ? [...apps.map((app) => app.clientDir), ...existsSync13(publicDir) ? [publicDir] : []] : undefined;
|
|
8902
9058
|
const build = await runBunBuild({
|
|
8903
9059
|
bytecode: true,
|
|
8904
|
-
compile: { assets: embedded, outfile:
|
|
8905
|
-
entrypoints: [
|
|
9060
|
+
compile: { assets: embedded, outfile: join15(server.dir, filename) },
|
|
9061
|
+
entrypoints: [join15(server.dir, server.entry)],
|
|
8906
9062
|
format: "esm",
|
|
8907
9063
|
minify: true,
|
|
8908
9064
|
sourcemap: output.serverSourceMaps ? "external" : "none",
|
|
@@ -8913,13 +9069,13 @@ async function compileExecutable(output, compile, manifest) {
|
|
|
8913
9069
|
movePrivateServerSourceMaps(server.dir, privateServerSourceMapDir(buildRoot, "bun"), build.outputs.filter((entry) => entry.kind === "sourcemap").map((entry) => entry.path));
|
|
8914
9070
|
}
|
|
8915
9071
|
for (const file of [...server.files, PRERENDER_SNAPSHOT_FILE]) {
|
|
8916
|
-
rmSync4(
|
|
9072
|
+
rmSync4(join15(server.dir, file), { force: true });
|
|
8917
9073
|
}
|
|
8918
|
-
manifest.serverPath = toPosixPath(
|
|
8919
|
-
console.log(`[furin] Server binary: ${
|
|
9074
|
+
manifest.serverPath = toPosixPath(join15(manifest.targetDir, filename));
|
|
9075
|
+
console.log(`[furin] Server binary: ${join15(server.dir, filename)}`);
|
|
8920
9076
|
if (compile === "embed") {
|
|
8921
9077
|
for (const app of apps) {
|
|
8922
|
-
rmSync4(
|
|
9078
|
+
rmSync4(join15(server.dir, clientDirNameForPrefix(app.prefix)), {
|
|
8923
9079
|
force: true,
|
|
8924
9080
|
recursive: true
|
|
8925
9081
|
});
|
|
@@ -8942,15 +9098,15 @@ function bun(compile, bunOutput) {
|
|
|
8942
9098
|
},
|
|
8943
9099
|
name: "bun",
|
|
8944
9100
|
async onBuildComplete(output) {
|
|
8945
|
-
const targetDir = toPosixPath(
|
|
9101
|
+
const targetDir = toPosixPath(relative10(output.rootDir, output.server.dir));
|
|
8946
9102
|
const manifest = {
|
|
8947
9103
|
buildId: output.buildId,
|
|
8948
|
-
clientDir: toPosixPath(
|
|
9104
|
+
clientDir: toPosixPath(join15(targetDir, "client")),
|
|
8949
9105
|
generatedAt: new Date().toISOString(),
|
|
8950
|
-
rscManifestPath: toPosixPath(
|
|
8951
|
-
serverPath: toPosixPath(
|
|
9106
|
+
rscManifestPath: toPosixPath(join15(targetDir, "rsc", "manifest.json")),
|
|
9107
|
+
serverPath: toPosixPath(join15(targetDir, output.server.entry)),
|
|
8952
9108
|
targetDir,
|
|
8953
|
-
templatePath: toPosixPath(
|
|
9109
|
+
templatePath: toPosixPath(join15(targetDir, "client", "index.html"))
|
|
8954
9110
|
};
|
|
8955
9111
|
if (isApp) {
|
|
8956
9112
|
manifest.appPath = manifest.serverPath;
|
|
@@ -8971,20 +9127,20 @@ function bun(compile, bunOutput) {
|
|
|
8971
9127
|
|
|
8972
9128
|
// src/adapter/package.ts
|
|
8973
9129
|
import { existsSync as existsSync14, rmSync as rmSync5, writeFileSync as writeFileSync8 } from "fs";
|
|
8974
|
-
import { join as
|
|
9130
|
+
import { join as join16, relative as relative11, resolve as resolve10 } from "path";
|
|
8975
9131
|
async function buildPackageTarget(app, rootDir, buildRoot, options) {
|
|
8976
9132
|
const { prefix, root, routes, pagesDir } = app;
|
|
8977
9133
|
const modulePaths = routeSourcePaths(app);
|
|
8978
|
-
const targetDir =
|
|
9134
|
+
const targetDir = join16(buildRoot, "package");
|
|
8979
9135
|
rmSync5(targetDir, { force: true, recursive: true });
|
|
8980
9136
|
ensureDir(targetDir);
|
|
8981
9137
|
const { entryChunk, cssChunks, preloadManifest } = await buildClient(routes, {
|
|
8982
9138
|
basePath: prefix,
|
|
8983
9139
|
clientLogging: options.clientLogging ?? false,
|
|
8984
|
-
metafilePath: options.analyze ?
|
|
9140
|
+
metafilePath: options.analyze ? join16(buildRoot, "analysis", "package-client.json") : undefined,
|
|
8985
9141
|
optimizeImports: options.optimizeImports,
|
|
8986
9142
|
outDir: targetDir,
|
|
8987
|
-
pagesDir,
|
|
9143
|
+
pages: { pagesDir, style: app.style },
|
|
8988
9144
|
routeRegistry: app.routeRegistry,
|
|
8989
9145
|
plugins: options.plugins,
|
|
8990
9146
|
preloadRouteChunks: options.preload?.routeChunks,
|
|
@@ -8995,30 +9151,14 @@ async function buildPackageTarget(app, rootDir, buildRoot, options) {
|
|
|
8995
9151
|
const buildFingerprint = await createBuildFingerprint(`${prefix}
|
|
8996
9152
|
${entryChunk}`, cssChunks, routes, root, null, modulePaths, rootDir);
|
|
8997
9153
|
const buildId = Bun.hash(buildFingerprint).toString(16).slice(0, 12);
|
|
8998
|
-
const clientDir =
|
|
8999
|
-
const publicDir =
|
|
9154
|
+
const clientDir = join16(targetDir, "client");
|
|
9155
|
+
const publicDir = join16(rootDir, "public");
|
|
9000
9156
|
if (existsSync14(publicDir)) {
|
|
9001
|
-
copyDirRecursive(publicDir,
|
|
9157
|
+
copyDirRecursive(publicDir, join16(targetDir, "public"));
|
|
9002
9158
|
}
|
|
9003
9159
|
const indexHtml = generateProdIndexHtml(entryChunk, cssChunks, buildId, undefined, false);
|
|
9004
|
-
writeFileSync8(
|
|
9005
|
-
const rootConventions
|
|
9006
|
-
errorPath: root.errorPath ? toPosixPath(root.errorPath) : undefined,
|
|
9007
|
-
notFoundPath: root.notFoundPath ? toPosixPath(root.notFoundPath) : undefined
|
|
9008
|
-
} : undefined;
|
|
9009
|
-
const routeMetadata = {};
|
|
9010
|
-
for (const route of routes) {
|
|
9011
|
-
routeMetadata[toPosixPath(route.path)] = {
|
|
9012
|
-
requestKeys: route.requestKeys,
|
|
9013
|
-
requestKeysByLoader: route.requestKeysByLoader,
|
|
9014
|
-
segmentBoundaries: route.segmentBoundaries.map((b) => ({
|
|
9015
|
-
depth: b.depth,
|
|
9016
|
-
errorPath: b.errorPath ? toPosixPath(b.errorPath) : undefined,
|
|
9017
|
-
notFoundPath: b.notFoundPath ? toPosixPath(b.notFoundPath) : undefined,
|
|
9018
|
-
path: toPosixPath(b.path)
|
|
9019
|
-
}))
|
|
9020
|
-
};
|
|
9021
|
-
}
|
|
9160
|
+
writeFileSync8(join16(clientDir, "index.html"), indexHtml);
|
|
9161
|
+
const { rootConventions, routeMetadata } = buildCompileMetadata(root, routes);
|
|
9022
9162
|
const registerSource = buildEntrySource({
|
|
9023
9163
|
apps: [
|
|
9024
9164
|
{
|
|
@@ -9038,7 +9178,7 @@ ${entryChunk}`, cssChunks, routes, root, null, modulePaths, rootDir);
|
|
|
9038
9178
|
mode: "register",
|
|
9039
9179
|
prerenderSnapshot: true
|
|
9040
9180
|
});
|
|
9041
|
-
const registerEntry =
|
|
9181
|
+
const registerEntry = join16(targetDir, "register.ts");
|
|
9042
9182
|
const register = createVirtualBuildEntry(registerEntry, registerSource, "ts");
|
|
9043
9183
|
const result = await runBunBuild({
|
|
9044
9184
|
define: PRODUCTION_DEFINE,
|
|
@@ -9065,7 +9205,7 @@ ${entryChunk}`, cssChunks, routes, root, null, modulePaths, rootDir);
|
|
|
9065
9205
|
if (!result.success) {
|
|
9066
9206
|
throw new AggregateError(result.logs, "[furin] package register build failed");
|
|
9067
9207
|
}
|
|
9068
|
-
const relativePagesDir = toPosixPath(
|
|
9208
|
+
const relativePagesDir = toPosixPath(relative11(targetDir, resolve10(rootDir, pagesDir)));
|
|
9069
9209
|
const factorySource = `// Auto-generated by \`furin build --target package\` \u2014 do not edit
|
|
9070
9210
|
import { fileURLToPath } from "node:url";
|
|
9071
9211
|
import { furin } from "@teyik0/furin";
|
|
@@ -9078,7 +9218,7 @@ const CLIENT_DIR = fileURLToPath(new URL("./client", import.meta.url));
|
|
|
9078
9218
|
* Mounts this packaged furin app as an Elysia plugin.
|
|
9079
9219
|
*
|
|
9080
9220
|
* @param {object} [options] Extra furin() options (logger, sync, ...) \u2014
|
|
9081
|
-
* pagesDir/prefix/clientDir are baked into the package and cannot be overridden.
|
|
9221
|
+
* pagesDir/prefix/style/clientDir are baked into the package and cannot be overridden.
|
|
9082
9222
|
* @returns {ReturnType<typeof import("@teyik0/furin").furin>}
|
|
9083
9223
|
*/
|
|
9084
9224
|
export function createFurinApp(options = {}) {
|
|
@@ -9086,45 +9226,46 @@ export function createFurinApp(options = {}) {
|
|
|
9086
9226
|
...options,
|
|
9087
9227
|
pagesDir: PAGES_DIR,
|
|
9088
9228
|
prefix: ${JSON.stringify(prefix)},
|
|
9229
|
+
style: ${JSON.stringify(app.style)},
|
|
9089
9230
|
clientDir: CLIENT_DIR,
|
|
9090
9231
|
});
|
|
9091
9232
|
}
|
|
9092
9233
|
|
|
9093
9234
|
export const prefix = ${JSON.stringify(prefix)};
|
|
9094
9235
|
`;
|
|
9095
|
-
writeFileSync8(
|
|
9236
|
+
writeFileSync8(join16(targetDir, "index.js"), factorySource);
|
|
9096
9237
|
const dtsSource = `import type { FurinOptions, furin } from "@teyik0/furin";
|
|
9097
9238
|
|
|
9098
|
-
/** Extra furin() options \u2014 pagesDir/prefix/clientDir are baked into the package and cannot be overridden. */
|
|
9099
|
-
export type CreateFurinAppOptions = Omit<FurinOptions, "pagesDir" | "prefix" | "clientDir">;
|
|
9239
|
+
/** Extra furin() options \u2014 pagesDir/prefix/style/clientDir are baked into the package and cannot be overridden. */
|
|
9240
|
+
export type CreateFurinAppOptions = Omit<FurinOptions, "pagesDir" | "prefix" | "style" | "clientDir">;
|
|
9100
9241
|
export declare function createFurinApp(options?: CreateFurinAppOptions): ReturnType<typeof furin>;
|
|
9101
9242
|
export declare const prefix: string;
|
|
9102
9243
|
`;
|
|
9103
|
-
writeFileSync8(
|
|
9104
|
-
const snapshotPath =
|
|
9244
|
+
writeFileSync8(join16(targetDir, "index.d.ts"), dtsSource);
|
|
9245
|
+
const snapshotPath = join16(targetDir, PRERENDER_SNAPSHOT_FILE);
|
|
9105
9246
|
writeFileSync8(snapshotPath, `{}
|
|
9106
9247
|
`);
|
|
9107
|
-
const prerenders = await prerenderFromBundle({ kind: "package", path:
|
|
9248
|
+
const prerenders = await prerenderFromBundle({ kind: "package", path: join16(targetDir, "index.js") }, rootDir, true);
|
|
9108
9249
|
writeFileSync8(snapshotPath, `${JSON.stringify(Object.fromEntries(prerenders.map(({ prefix: key, ssg }) => [key, ssg])))}
|
|
9109
9250
|
`);
|
|
9110
|
-
console.log(`[furin] Package artifact: ${toPosixPath(
|
|
9251
|
+
console.log(`[furin] Package artifact: ${toPosixPath(relative11(rootDir, targetDir))}`);
|
|
9111
9252
|
return {
|
|
9112
9253
|
buildId,
|
|
9113
9254
|
generatedAt: new Date().toISOString(),
|
|
9114
9255
|
prefix,
|
|
9115
|
-
targetDir: toPosixPath(
|
|
9256
|
+
targetDir: toPosixPath(relative11(rootDir, targetDir))
|
|
9116
9257
|
};
|
|
9117
9258
|
}
|
|
9118
9259
|
|
|
9119
9260
|
// src/adapter/static.ts
|
|
9120
9261
|
import { cpSync as cpSync2, existsSync as existsSync15, rmSync as rmSync6, writeFileSync as writeFileSync9 } from "fs";
|
|
9121
|
-
import { dirname as
|
|
9262
|
+
import { dirname as dirname15, isAbsolute as isAbsolute6, join as join17, parse as parse3, relative as relative12, resolve as resolve11, sep as sep3, win32 } from "path";
|
|
9122
9263
|
var TRAILING_SLASHES_RE = /\/+$/;
|
|
9123
9264
|
var STATIC_RENDER_ORIGIN = "http://localhost";
|
|
9124
9265
|
function pathToOutputFile(urlPath, outDir, fileName) {
|
|
9125
9266
|
const normalizedOutDir = resolve11(outDir);
|
|
9126
9267
|
if (urlPath === "/" || urlPath === "") {
|
|
9127
|
-
return
|
|
9268
|
+
return join17(normalizedOutDir, fileName);
|
|
9128
9269
|
}
|
|
9129
9270
|
const resolved = resolve11(normalizedOutDir, urlPath.slice(1), fileName);
|
|
9130
9271
|
if (!resolved.startsWith(`${normalizedOutDir}${sep3}`)) {
|
|
@@ -9243,7 +9384,7 @@ async function collectStaticOutputs(exported, outDir, basePath, onSSR, skippedRo
|
|
|
9243
9384
|
return outputs;
|
|
9244
9385
|
}
|
|
9245
9386
|
function writeStaticOutput(output) {
|
|
9246
|
-
ensureDir(
|
|
9387
|
+
ensureDir(dirname15(output.htmlFile));
|
|
9247
9388
|
writeFileSync9(output.htmlFile, output.html);
|
|
9248
9389
|
if (output.data !== null) {
|
|
9249
9390
|
writeFileSync9(output.dataFile, output.data);
|
|
@@ -9258,12 +9399,12 @@ function replaceOutDir(outDir, publicSrcDir, clientSrcDir, outputs, shellHtml) {
|
|
|
9258
9399
|
cpSync2(publicSrcDir, outDir, { recursive: true, dereference: true });
|
|
9259
9400
|
}
|
|
9260
9401
|
if (existsSync15(clientSrcDir)) {
|
|
9261
|
-
cpSync2(clientSrcDir,
|
|
9402
|
+
cpSync2(clientSrcDir, join17(outDir, "_client"), { recursive: true, dereference: true });
|
|
9262
9403
|
}
|
|
9263
9404
|
for (const output of outputs) {
|
|
9264
9405
|
writeStaticOutput(output);
|
|
9265
9406
|
}
|
|
9266
|
-
writeFileSync9(
|
|
9407
|
+
writeFileSync9(join17(outDir, "404.html"), shellHtml);
|
|
9267
9408
|
console.log("[furin] static: wrote 404.html (SPA shell fallback)");
|
|
9268
9409
|
}
|
|
9269
9410
|
function logRenderFailure(failure, error) {
|
|
@@ -9292,7 +9433,7 @@ var STATIC_ENTRY = "_furin-static";
|
|
|
9292
9433
|
async function bundleStaticExport(app, shellHtml, preloadManifest, serverDir, rootDir, options) {
|
|
9293
9434
|
const { root, routes } = app;
|
|
9294
9435
|
const { rootConventions, routeMetadata } = buildCompileMetadata(root, routes);
|
|
9295
|
-
const entry = createVirtualBuildEntry(
|
|
9436
|
+
const entry = createVirtualBuildEntry(join17(serverDir, `${STATIC_ENTRY}.ts`), buildEntrySource({
|
|
9296
9437
|
apps: [
|
|
9297
9438
|
{
|
|
9298
9439
|
clientLogging: Boolean(options.clientLogging),
|
|
@@ -9339,7 +9480,7 @@ async function bundleStaticExport(app, shellHtml, preloadManifest, serverDir, ro
|
|
|
9339
9480
|
throw new AggregateError(result.logs, "[furin] static export bundle failed");
|
|
9340
9481
|
}
|
|
9341
9482
|
await buildFlightCodec(serverDir, options.plugins);
|
|
9342
|
-
return
|
|
9483
|
+
return join17(serverDir, `${STATIC_ENTRY}.js`);
|
|
9343
9484
|
}
|
|
9344
9485
|
function assertNoRequestLoaders(routes, root) {
|
|
9345
9486
|
const offenders = [];
|
|
@@ -9375,11 +9516,11 @@ async function buildStaticTarget(app, rootDir, buildRoot, options) {
|
|
|
9375
9516
|
const outDir = resolve11(rootDir, rawOutDir);
|
|
9376
9517
|
const normalizedRoot = resolve11(rootDir);
|
|
9377
9518
|
const normalizedBuildRoot = resolve11(buildRoot);
|
|
9378
|
-
if (outDir === normalizedRoot || outDir === normalizedBuildRoot || outDir ===
|
|
9519
|
+
if (outDir === normalizedRoot || outDir === normalizedBuildRoot || outDir === parse3(outDir).root || rawOutDir === win32.parse(rawOutDir).root) {
|
|
9379
9520
|
throw new Error(`[furin] static: outDir resolves to "${outDir}" which is unsafe to delete. ` + `Use a dedicated output directory such as "dist".`);
|
|
9380
9521
|
}
|
|
9381
9522
|
function isOutsideOutDir(target) {
|
|
9382
|
-
const rel =
|
|
9523
|
+
const rel = relative12(outDir, target);
|
|
9383
9524
|
return rel.startsWith("..") || isAbsolute6(rel);
|
|
9384
9525
|
}
|
|
9385
9526
|
if (!(isOutsideOutDir(normalizedRoot) && isOutsideOutDir(normalizedBuildRoot))) {
|
|
@@ -9390,17 +9531,17 @@ async function buildStaticTarget(app, rootDir, buildRoot, options) {
|
|
|
9390
9531
|
const renderedRoutes = [];
|
|
9391
9532
|
const skippedRoutes = [];
|
|
9392
9533
|
const ssgRoutes = collectSsgRoutes(routes, onSSR, skippedRoutes);
|
|
9393
|
-
const targetDir =
|
|
9534
|
+
const targetDir = join17(buildRoot, "static");
|
|
9394
9535
|
rmSync6(targetDir, { force: true, recursive: true });
|
|
9395
9536
|
ensureDir(targetDir);
|
|
9396
9537
|
try {
|
|
9397
9538
|
const { entryChunk, cssChunks, preloadManifest } = await buildClient(ssgRoutes, {
|
|
9398
9539
|
basePath,
|
|
9399
9540
|
clientLogging: Boolean(options.clientLogging),
|
|
9400
|
-
metafilePath: options.analyze ?
|
|
9541
|
+
metafilePath: options.analyze ? join17(buildRoot, "analysis", "static-client.json") : undefined,
|
|
9401
9542
|
optimizeImports: options.optimizeImports,
|
|
9402
9543
|
outDir: targetDir,
|
|
9403
|
-
pagesDir:
|
|
9544
|
+
pages: { pagesDir: app.pagesDir, style: app.style },
|
|
9404
9545
|
routeRegistry: app.routeRegistry,
|
|
9405
9546
|
plugins: options.plugins,
|
|
9406
9547
|
preloadRouteChunks: options.preload?.routeChunks,
|
|
@@ -9408,16 +9549,16 @@ async function buildStaticTarget(app, rootDir, buildRoot, options) {
|
|
|
9408
9549
|
reactCompiler: options.reactCompiler,
|
|
9409
9550
|
rootLayout: root.path
|
|
9410
9551
|
});
|
|
9411
|
-
const publicFavicon =
|
|
9552
|
+
const publicFavicon = join17(rootDir, "public", "favicon.ico");
|
|
9412
9553
|
const faviconHref = existsSync15(publicFavicon) ? `${basePath}/favicon.ico` : undefined;
|
|
9413
9554
|
const shellHtml = generateProdIndexHtml(entryChunk, cssChunks, undefined, faviconHref, true);
|
|
9414
|
-
const bundle = await bundleStaticExport(app, shellHtml, preloadManifest,
|
|
9555
|
+
const bundle = await bundleStaticExport(app, shellHtml, preloadManifest, join17(targetDir, "server"), rootDir, options);
|
|
9415
9556
|
const exported = await exportStaticFromBundle(bundle, rootDir, {
|
|
9416
9557
|
basePath,
|
|
9417
9558
|
patterns: ssgRoutes.map((route) => route.pattern)
|
|
9418
9559
|
});
|
|
9419
9560
|
const outputs = await collectStaticOutputs(exported, outDir, basePath, onSSR, skippedRoutes);
|
|
9420
|
-
replaceOutDir(outDir,
|
|
9561
|
+
replaceOutDir(outDir, join17(rootDir, "public"), join17(targetDir, "client"), outputs, shellHtml);
|
|
9421
9562
|
renderedRoutes.push(...outputs.map((output) => output.path));
|
|
9422
9563
|
} finally {
|
|
9423
9564
|
rmSync6(targetDir, { force: true, recursive: true });
|
|
@@ -9442,7 +9583,7 @@ import {
|
|
|
9442
9583
|
symlinkSync,
|
|
9443
9584
|
writeFileSync as writeFileSync10
|
|
9444
9585
|
} from "fs";
|
|
9445
|
-
import { basename as basename6, dirname as
|
|
9586
|
+
import { basename as basename6, dirname as dirname16, join as join18, relative as relative13 } from "path";
|
|
9446
9587
|
import { fileURLToPath as fileURLToPath9, pathToFileURL as pathToFileURL3 } from "url";
|
|
9447
9588
|
|
|
9448
9589
|
// src/adapter/vercel/data.ts
|
|
@@ -9487,8 +9628,8 @@ function assertRegions(regions) {
|
|
|
9487
9628
|
}
|
|
9488
9629
|
}
|
|
9489
9630
|
function frameworkVersion() {
|
|
9490
|
-
const packageRoot =
|
|
9491
|
-
const packageJson = JSON.parse(readFileSync8(
|
|
9631
|
+
const packageRoot = dirname16(dirname16(fileURLToPath9(import.meta.resolve("@teyik0/furin"))));
|
|
9632
|
+
const packageJson = JSON.parse(readFileSync8(join18(packageRoot, "package.json"), "utf8"));
|
|
9492
9633
|
return packageJson.version;
|
|
9493
9634
|
}
|
|
9494
9635
|
function encodeCacheTag(value) {
|
|
@@ -9513,7 +9654,7 @@ function functionNameForPath(path, mode, names) {
|
|
|
9513
9654
|
return "[...splat]";
|
|
9514
9655
|
}
|
|
9515
9656
|
if (segment.startsWith(":")) {
|
|
9516
|
-
return `[${segment.slice(1)}]`;
|
|
9657
|
+
return segment.endsWith("?") ? `[[${segment.slice(1, -1)}]]` : `[${segment.slice(1)}]`;
|
|
9517
9658
|
}
|
|
9518
9659
|
const sanitized = segment.replace(UNSAFE_FUNCTION_PATH_RE, "-");
|
|
9519
9660
|
if (sanitized === segment && segment !== "." && segment !== "..") {
|
|
@@ -9628,8 +9769,8 @@ async function addPrerenderFallback(job, response, functionsDir) {
|
|
|
9628
9769
|
const { spec } = job;
|
|
9629
9770
|
const fallback = `${basename6(spec.functionName)}.prerender-fallback.html`;
|
|
9630
9771
|
const location = response.headers.get("location") ?? undefined;
|
|
9631
|
-
const fallbackPath =
|
|
9632
|
-
ensureDir(
|
|
9772
|
+
const fallbackPath = join18(dirname16(join18(functionsDir, spec.functionName)), fallback);
|
|
9773
|
+
ensureDir(dirname16(fallbackPath));
|
|
9633
9774
|
writeFileSync10(fallbackPath, await response.text());
|
|
9634
9775
|
spec.config.fallback = fallback;
|
|
9635
9776
|
spec.config.initialHeaders = {
|
|
@@ -9644,10 +9785,10 @@ async function buildProductionFallbacks(jobs, functionsDir, rootDir, buildRoot)
|
|
|
9644
9785
|
if (jobs.length === 0) {
|
|
9645
9786
|
return;
|
|
9646
9787
|
}
|
|
9647
|
-
const resultPath =
|
|
9788
|
+
const resultPath = join18(buildRoot, `vercel-prerender-${crypto.randomUUID()}.json`);
|
|
9648
9789
|
const requests = jobs.map(({ path, spec }) => `http://localhost/${spec.functionName}?${ISR_PATH_PARAM}=${encodeURIComponent(path)}`);
|
|
9649
9790
|
const script = `
|
|
9650
|
-
const handler = (await import(${JSON.stringify(pathToFileURL3(
|
|
9791
|
+
const handler = (await import(${JSON.stringify(pathToFileURL3(join18(functionsDir, "__server.func/index.js")).href)})).default;
|
|
9651
9792
|
const results = [];
|
|
9652
9793
|
for (const [index, url] of ${JSON.stringify(requests)}.entries()) {
|
|
9653
9794
|
const response = await handler.fetch(new Request(url));
|
|
@@ -9702,9 +9843,9 @@ async function buildBootstrap(serverFunctionDir) {
|
|
|
9702
9843
|
});
|
|
9703
9844
|
}
|
|
9704
9845
|
function createFunctionAlias(functionsDir, serverFunctionDir, functionName) {
|
|
9705
|
-
const aliasPath =
|
|
9706
|
-
ensureDir(
|
|
9707
|
-
const target =
|
|
9846
|
+
const aliasPath = join18(functionsDir, `${functionName}.func`);
|
|
9847
|
+
ensureDir(dirname16(aliasPath));
|
|
9848
|
+
const target = relative13(dirname16(aliasPath), serverFunctionDir);
|
|
9708
9849
|
symlinkSync(target, aliasPath, process.platform === "win32" ? "junction" : "dir");
|
|
9709
9850
|
}
|
|
9710
9851
|
function copyStaticAssets(output, staticDir) {
|
|
@@ -9712,16 +9853,16 @@ function copyStaticAssets(output, staticDir) {
|
|
|
9712
9853
|
if (publicDir !== undefined) {
|
|
9713
9854
|
cpSync3(publicDir, staticDir, { recursive: true });
|
|
9714
9855
|
for (const app of apps) {
|
|
9715
|
-
const appStaticDir =
|
|
9716
|
-
cpSync3(publicDir,
|
|
9717
|
-
const favicon =
|
|
9856
|
+
const appStaticDir = join18(staticDir, app.prefix.slice(1));
|
|
9857
|
+
cpSync3(publicDir, join18(appStaticDir, "public"), { recursive: true });
|
|
9858
|
+
const favicon = join18(publicDir, "favicon.ico");
|
|
9718
9859
|
if (app.prefix !== "" && existsSync16(favicon)) {
|
|
9719
|
-
cpSync3(favicon,
|
|
9860
|
+
cpSync3(favicon, join18(appStaticDir, "favicon.ico"));
|
|
9720
9861
|
}
|
|
9721
9862
|
}
|
|
9722
9863
|
}
|
|
9723
9864
|
for (const app of apps) {
|
|
9724
|
-
cpSync3(app.clientDir,
|
|
9865
|
+
cpSync3(app.clientDir, join18(staticDir, app.prefix.slice(1), "_client"), { recursive: true });
|
|
9725
9866
|
}
|
|
9726
9867
|
}
|
|
9727
9868
|
function buildOutputConfig(apps, specs) {
|
|
@@ -9755,7 +9896,7 @@ function buildOutputConfig(apps, specs) {
|
|
|
9755
9896
|
};
|
|
9756
9897
|
}
|
|
9757
9898
|
function writeFunctionConfig(serverFunctionDir, regions) {
|
|
9758
|
-
writeFileSync10(
|
|
9899
|
+
writeFileSync10(join18(serverFunctionDir, ".vc-config.json"), `${JSON.stringify({
|
|
9759
9900
|
handler: "index.js",
|
|
9760
9901
|
launcherType: "Nodejs",
|
|
9761
9902
|
...regions === undefined ? {} : { regions },
|
|
@@ -9772,39 +9913,39 @@ function vercel(options) {
|
|
|
9772
9913
|
name: "vercel",
|
|
9773
9914
|
async onBuildComplete(output) {
|
|
9774
9915
|
const { apps, rootDir, server } = output;
|
|
9775
|
-
const outputDir =
|
|
9776
|
-
const staticDir =
|
|
9777
|
-
const functionsDir =
|
|
9778
|
-
const serverFunctionDir =
|
|
9916
|
+
const outputDir = join18(rootDir, ".vercel", "output");
|
|
9917
|
+
const staticDir = join18(outputDir, "static");
|
|
9918
|
+
const functionsDir = join18(outputDir, "functions");
|
|
9919
|
+
const serverFunctionDir = join18(functionsDir, "__server.func");
|
|
9779
9920
|
rmSync7(outputDir, { force: true, recursive: true });
|
|
9780
9921
|
ensureDir(staticDir);
|
|
9781
9922
|
ensureDir(serverFunctionDir);
|
|
9782
9923
|
for (const file of [...server.files, "server-codec.js"]) {
|
|
9783
|
-
cpSync3(
|
|
9924
|
+
cpSync3(join18(server.dir, file), join18(serverFunctionDir, file));
|
|
9784
9925
|
}
|
|
9785
9926
|
copyStaticAssets(output, staticDir);
|
|
9786
9927
|
const pprResumeKey = crypto.randomUUID();
|
|
9787
9928
|
const { jobs, specs } = createPrerenderSpecs(apps, pprResumeKey);
|
|
9788
|
-
const serverBundleBytes = server.files.reduce((total, file) => total + statSync2(
|
|
9789
|
-
writeFileSync10(
|
|
9929
|
+
const serverBundleBytes = server.files.reduce((total, file) => total + statSync2(join18(server.dir, file)).size, 0);
|
|
9930
|
+
writeFileSync10(join18(serverFunctionDir, VERCEL_DATA_FILE), `${JSON.stringify(runtimeData(apps, specs, pprResumeKey, serverBundleBytes))}
|
|
9790
9931
|
`);
|
|
9791
9932
|
await buildBootstrap(serverFunctionDir);
|
|
9792
9933
|
await buildProductionFallbacks(jobs, functionsDir, rootDir, output.buildRoot);
|
|
9793
9934
|
writeFunctionConfig(serverFunctionDir, options.regions);
|
|
9794
9935
|
for (const spec of specs) {
|
|
9795
9936
|
createFunctionAlias(functionsDir, serverFunctionDir, spec.functionName);
|
|
9796
|
-
writeFileSync10(
|
|
9937
|
+
writeFileSync10(join18(functionsDir, `${spec.functionName}.prerender-config.json`), `${JSON.stringify(spec.config, null, 2)}
|
|
9797
9938
|
`);
|
|
9798
9939
|
}
|
|
9799
|
-
writeFileSync10(
|
|
9940
|
+
writeFileSync10(join18(outputDir, "config.json"), `${JSON.stringify(buildOutputConfig(apps, specs), null, 2)}
|
|
9800
9941
|
`);
|
|
9801
|
-
console.log(`[furin] Vercel output: ${toPosixPath(
|
|
9942
|
+
console.log(`[furin] Vercel output: ${toPosixPath(relative13(rootDir, outputDir))}`);
|
|
9802
9943
|
return {
|
|
9803
9944
|
buildId: output.buildId,
|
|
9804
9945
|
generatedAt: new Date().toISOString(),
|
|
9805
9946
|
isrRoutes: apps.flatMap((app) => app.routes.filter((route) => route.mode === "isr").map((route) => physicalPath(app.prefix, route.pattern))).toSorted(),
|
|
9806
|
-
outputDir: toPosixPath(
|
|
9807
|
-
serverPath: toPosixPath(
|
|
9947
|
+
outputDir: toPosixPath(relative13(rootDir, outputDir)),
|
|
9948
|
+
serverPath: toPosixPath(relative13(rootDir, serverFunctionDir)),
|
|
9808
9949
|
ssgRoutes: jobs.filter((job) => job.route.mode === "ssg").map((job) => job.path).toSorted()
|
|
9809
9950
|
};
|
|
9810
9951
|
},
|
|
@@ -9816,10 +9957,12 @@ function vercel(options) {
|
|
|
9816
9957
|
import { t } from "elysia";
|
|
9817
9958
|
var BUILD_TARGETS = ["bun", "vercel", "static", "package"];
|
|
9818
9959
|
var compileTargetSchema = t.Union([t.Literal("server"), t.Literal("embed")]);
|
|
9960
|
+
var routeStyleSchema = t.Union([t.Literal("nextjs"), t.Literal("tanstack")]);
|
|
9819
9961
|
var configSchema = t.Object({
|
|
9820
9962
|
apps: t.Optional(t.Array(t.Object({
|
|
9821
9963
|
pagesDir: t.String(),
|
|
9822
|
-
prefix: t.Optional(t.String())
|
|
9964
|
+
prefix: t.Optional(t.String()),
|
|
9965
|
+
style: routeStyleSchema
|
|
9823
9966
|
}))),
|
|
9824
9967
|
bun: t.Optional(t.Object({
|
|
9825
9968
|
compile: t.Optional(compileTargetSchema),
|
|
@@ -9834,6 +9977,7 @@ var configSchema = t.Object({
|
|
|
9834
9977
|
rootDir: t.Optional(t.String()),
|
|
9835
9978
|
serverEntry: t.Optional(t.String()),
|
|
9836
9979
|
serverSourceMaps: t.Optional(t.Boolean()),
|
|
9980
|
+
style: t.Optional(routeStyleSchema),
|
|
9837
9981
|
static: t.Optional(t.Object({
|
|
9838
9982
|
basePath: t.Optional(t.String()),
|
|
9839
9983
|
onSSR: t.Optional(t.Union([t.Literal("error"), t.Literal("skip")])),
|
|
@@ -9843,13 +9987,8 @@ var configSchema = t.Object({
|
|
|
9843
9987
|
|
|
9844
9988
|
// src/plugin/route-config.ts
|
|
9845
9989
|
import { existsSync as existsSync17, readFileSync as readFileSync9, writeFileSync as writeFileSync11 } from "fs";
|
|
9846
|
-
import {
|
|
9847
|
-
var EXTENSION_RE = /\.(?:[cm]?[jt]sx?)$/;
|
|
9990
|
+
import { relative as relative14, resolve as resolve12 } from "path";
|
|
9848
9991
|
var IDENTIFIER_RE = /^[A-Za-z_$][\w$]*$/;
|
|
9849
|
-
var PATH_SEPARATOR_RE = /[\\/]/;
|
|
9850
|
-
function withoutExtension(path) {
|
|
9851
|
-
return path.replace(EXTENSION_RE, "");
|
|
9852
|
-
}
|
|
9853
9992
|
function propertyName(key) {
|
|
9854
9993
|
if (key?.type === "Identifier") {
|
|
9855
9994
|
return key.name;
|
|
@@ -9930,9 +10069,9 @@ function position2(source, offset) {
|
|
|
9930
10069
|
function issueAt(file, parsed, node, message) {
|
|
9931
10070
|
return { file, ...position2(parsed.source, node.start), message };
|
|
9932
10071
|
}
|
|
9933
|
-
function checkKey(file,
|
|
10072
|
+
function checkKey(file, route, parsed) {
|
|
9934
10073
|
const { config, head, id } = parsed.route;
|
|
9935
|
-
const expected =
|
|
10074
|
+
const expected = route.id;
|
|
9936
10075
|
if (!id) {
|
|
9937
10076
|
return issueAt(file, parsed, head, `defineRoute() must name this file. Its id is "${expected}":
|
|
9938
10077
|
defineRoute("${expected}")`);
|
|
@@ -9961,21 +10100,21 @@ function suggestedMode(route, isRoot) {
|
|
|
9961
10100
|
}
|
|
9962
10101
|
return route.methods.has("loader") || route.methods.has("requestLoader") ? "ssr" : "ssg";
|
|
9963
10102
|
}
|
|
9964
|
-
function checkFactory(file,
|
|
10103
|
+
function checkFactory(file, manifestRoute, parsed) {
|
|
9965
10104
|
const { route } = parsed;
|
|
9966
|
-
const isRoot =
|
|
10105
|
+
const isRoot = manifestRoute === undefined;
|
|
9967
10106
|
if (isRoot === route.isRootFactory) {
|
|
9968
10107
|
return;
|
|
9969
10108
|
}
|
|
9970
10109
|
const mode = suggestedMode(route, isRoot);
|
|
9971
10110
|
if (isRoot) {
|
|
9972
|
-
return issueAt(file, parsed, route.head, `root
|
|
10111
|
+
return issueAt(file, parsed, route.head, `The root layout must use defineRootRoute(), which has no parent layout:
|
|
9973
10112
|
import { defineRootRoute } from "@teyik0/furin";
|
|
9974
10113
|
export const route = defineRootRoute().config({ mode: "${mode}" })`);
|
|
9975
10114
|
}
|
|
9976
|
-
return issueAt(file, parsed, route.head, `defineRootRoute() is reserved for root.
|
|
10115
|
+
return issueAt(file, parsed, route.head, `defineRootRoute() is reserved for the root layout. Use defineRoute with this file's id:
|
|
9977
10116
|
import { defineRoute } from "@teyik0/furin";
|
|
9978
|
-
export const route = defineRoute("${
|
|
10117
|
+
export const route = defineRoute("${manifestRoute.id}").config({ mode: "${mode}" })`);
|
|
9979
10118
|
}
|
|
9980
10119
|
function checkConfig(file, parsed) {
|
|
9981
10120
|
const { route } = parsed;
|
|
@@ -10006,56 +10145,64 @@ function declaredParams(route) {
|
|
|
10006
10145
|
}
|
|
10007
10146
|
return new Set(keys.filter((key) => key !== undefined));
|
|
10008
10147
|
}
|
|
10009
|
-
function
|
|
10010
|
-
return
|
|
10011
|
-
const dynamic = parseDynamicRouteSegment(segment, file);
|
|
10012
|
-
return dynamic ? [{ key: dynamic.catchAll ? "*" : dynamic.name, segment }] : [];
|
|
10013
|
-
}).filter(({ key }) => declared !== true && !declared.has(key));
|
|
10148
|
+
function undeclaredParams(route, declared) {
|
|
10149
|
+
return route.params.filter(({ name }) => declared !== true && !declared.has(name));
|
|
10014
10150
|
}
|
|
10015
|
-
function paramsSchema(
|
|
10016
|
-
const fields =
|
|
10151
|
+
function paramsSchema(params) {
|
|
10152
|
+
const fields = params.map(({ name, optional }) => `${IDENTIFIER_RE.test(name) ? name : JSON.stringify(name)}: ${optional ? "t.Optional(t.String())" : "t.String()"}`);
|
|
10017
10153
|
return `params: t.Object({ ${fields.join(", ")} })`;
|
|
10018
10154
|
}
|
|
10019
|
-
function checkParams(file,
|
|
10020
|
-
const missing =
|
|
10155
|
+
function checkParams(file, route, parsed) {
|
|
10156
|
+
const missing = undeclaredParams(route, declaredParams(parsed.route));
|
|
10021
10157
|
if (missing.length === 0) {
|
|
10022
10158
|
return;
|
|
10023
10159
|
}
|
|
10024
10160
|
const plural = missing.length > 1;
|
|
10025
10161
|
const tImport = parsed.imports.get("t")?.specifier === "elysia" ? "" : `
|
|
10026
10162
|
import { t } from "elysia";`;
|
|
10027
|
-
return issueAt(file, parsed, parsed.route.config ?? parsed.route.head, `The
|
|
10163
|
+
return issueAt(file, parsed, parsed.route.config ?? parsed.route.head, `The path param${plural ? "s" : ""} ${missing.map(({ name }) => name).join(", ")} ${plural ? "are" : "is"} missing from this page's params schema. Each page declares every dynamic segment of its path, including those of its layouts. Add to config():${tImport}
|
|
10028
10164
|
${paramsSchema(missing)}`);
|
|
10029
10165
|
}
|
|
10030
|
-
function
|
|
10031
|
-
const
|
|
10166
|
+
function checkBoundaryMethods(file, instance, parsed) {
|
|
10167
|
+
const method = ["error", "notFound"].find((name) => parsed.route.methods.has(name));
|
|
10168
|
+
if (instance.style !== "nextjs" || method === undefined) {
|
|
10169
|
+
return;
|
|
10170
|
+
}
|
|
10171
|
+
const convention = method === "error" ? "an error.tsx" : "a not-found.tsx";
|
|
10172
|
+
return issueAt(file, parsed, parsed.route.head, `.${method}() is the TanStack style. In the nextjs style, default-export the component from ${convention} next to this route.`);
|
|
10173
|
+
}
|
|
10174
|
+
function checkRoute(file, instance, route, parsed) {
|
|
10175
|
+
const factory = checkFactory(file, route, parsed);
|
|
10032
10176
|
if (factory) {
|
|
10033
10177
|
return [factory];
|
|
10034
10178
|
}
|
|
10035
|
-
const isLayout = basename7(withoutExtension(file)) === "_route";
|
|
10036
10179
|
return [
|
|
10037
10180
|
checkConfig(file, parsed),
|
|
10038
|
-
|
|
10181
|
+
route === undefined ? undefined : checkKey(file, route, parsed),
|
|
10039
10182
|
checkMode(file, parsed),
|
|
10040
|
-
|
|
10183
|
+
route === undefined || route.kind === "layout" ? undefined : checkParams(file, route, parsed),
|
|
10184
|
+
checkBoundaryMethods(file, instance, parsed)
|
|
10041
10185
|
];
|
|
10042
10186
|
}
|
|
10043
|
-
function routeFiles(
|
|
10044
|
-
const
|
|
10045
|
-
|
|
10046
|
-
|
|
10047
|
-
|
|
10048
|
-
|
|
10187
|
+
function routeFiles(manifest) {
|
|
10188
|
+
const files = manifest.routes.map((route) => [
|
|
10189
|
+
resolve12(route.sourcePath),
|
|
10190
|
+
route
|
|
10191
|
+
]);
|
|
10192
|
+
if (existsSync17(manifest.rootPath)) {
|
|
10193
|
+
files.push([resolve12(manifest.rootPath), undefined]);
|
|
10194
|
+
}
|
|
10195
|
+
return files.toSorted(([left], [right]) => left.localeCompare(right));
|
|
10049
10196
|
}
|
|
10050
|
-
function validateRouteConfig(
|
|
10051
|
-
const instance = { pagesDir: resolve12(pagesDir)
|
|
10052
|
-
return routeFiles(instance
|
|
10197
|
+
function validateRouteConfig(spec) {
|
|
10198
|
+
const instance = { ...spec, pagesDir: resolve12(spec.pagesDir) };
|
|
10199
|
+
return routeFiles(scanRouteManifest(instance)).flatMap(([file, route]) => {
|
|
10053
10200
|
const parsed = parseRoute(file);
|
|
10054
|
-
return parsed ? checkRoute(file, instance, parsed).filter((issue) => issue !== undefined) : [];
|
|
10201
|
+
return parsed ? checkRoute(file, instance, route, parsed).filter((issue) => issue !== undefined) : [];
|
|
10055
10202
|
});
|
|
10056
10203
|
}
|
|
10057
10204
|
function displayPath(file) {
|
|
10058
|
-
const projected =
|
|
10205
|
+
const projected = relative14(process.cwd(), file).replaceAll("\\", "/");
|
|
10059
10206
|
return projected.startsWith("../") ? file : projected;
|
|
10060
10207
|
}
|
|
10061
10208
|
function formatRouteConfigIssue(issue) {
|
|
@@ -10072,10 +10219,10 @@ function assertValidRouteConfig(instance) {
|
|
|
10072
10219
|
|
|
10073
10220
|
// src/build/discover-mounts.ts
|
|
10074
10221
|
import { readFileSync as readFileSync10, rmSync as rmSync8 } from "fs";
|
|
10075
|
-
import { join as
|
|
10222
|
+
import { join as join19 } from "path";
|
|
10076
10223
|
var DISCOVERY_PROCESS = frameworkSourceModule("build/discover-mounts-process.ts");
|
|
10077
10224
|
async function discoverFurinMounts(serverEntry, rootDir) {
|
|
10078
|
-
const resultPath =
|
|
10225
|
+
const resultPath = join19(rootDir, ".furin", "build", `mounts-${crypto.randomUUID()}.json`);
|
|
10079
10226
|
const child = Bun.spawn([process.execPath, DISCOVERY_PROCESS, serverEntry, resultPath], {
|
|
10080
10227
|
cwd: rootDir,
|
|
10081
10228
|
env: { ...process.env, NODE_ENV: "production" },
|
|
@@ -10102,7 +10249,7 @@ ${stdout}
|
|
|
10102
10249
|
|
|
10103
10250
|
// src/build/discover-pages.ts
|
|
10104
10251
|
import { mkdtempSync, readFileSync as readFileSync11, renameSync as renameSync3, rmSync as rmSync9, writeFileSync as writeFileSync12 } from "fs";
|
|
10105
|
-
import { join as
|
|
10252
|
+
import { join as join20 } from "path";
|
|
10106
10253
|
import { serialize } from "v8";
|
|
10107
10254
|
|
|
10108
10255
|
// src/build/discovery-plugins.ts
|
|
@@ -10173,10 +10320,10 @@ async function discoveryPlugins(plugins) {
|
|
|
10173
10320
|
// src/build/discover-pages.ts
|
|
10174
10321
|
async function discoverPages(apps, rootDir, plugins) {
|
|
10175
10322
|
const runtime = await discoveryPlugins(plugins);
|
|
10176
|
-
const buildDir =
|
|
10323
|
+
const buildDir = join20(rootDir, ".furin/build");
|
|
10177
10324
|
ensureDir(buildDir);
|
|
10178
|
-
const directory = mkdtempSync(
|
|
10179
|
-
const resultPath =
|
|
10325
|
+
const directory = mkdtempSync(join20(buildDir, "discovery-"));
|
|
10326
|
+
const resultPath = join20(directory, "pages.json");
|
|
10180
10327
|
const child = Bun.spawn([
|
|
10181
10328
|
process.execPath,
|
|
10182
10329
|
frameworkSourceModule("build/discover-pages-process.ts"),
|
|
@@ -10246,22 +10393,21 @@ async function resolveAppSpecs(options, serverEntry, rootDir) {
|
|
|
10246
10393
|
if (options.apps && options.apps.length > 0) {
|
|
10247
10394
|
return options.apps.map((app) => ({
|
|
10248
10395
|
pagesDir: resolve13(rootDir, app.pagesDir),
|
|
10249
|
-
prefix: normalizePrefix(app.prefix)
|
|
10396
|
+
prefix: normalizePrefix(app.prefix),
|
|
10397
|
+
style: app.style
|
|
10250
10398
|
}));
|
|
10251
10399
|
}
|
|
10252
|
-
if (options.pagesDir) {
|
|
10253
|
-
return [{ pagesDir: resolve13(rootDir, options.pagesDir), prefix: "" }];
|
|
10254
|
-
}
|
|
10255
10400
|
if (serverEntry) {
|
|
10256
10401
|
const mounted = await discoverFurinMounts(serverEntry, rootDir);
|
|
10257
10402
|
if (mounted.length > 0) {
|
|
10258
10403
|
return mounted.map((app) => ({
|
|
10259
10404
|
pagesDir: resolve13(rootDir, app.pagesDir),
|
|
10260
|
-
prefix: app.prefix
|
|
10405
|
+
prefix: app.prefix,
|
|
10406
|
+
style: app.style
|
|
10261
10407
|
}));
|
|
10262
10408
|
}
|
|
10263
10409
|
}
|
|
10264
|
-
|
|
10410
|
+
throw new Error(`[furin] No app to build: ${serverEntry ? `${toPosixPath(relative15(rootDir, serverEntry))} mounts no furin() plugin` : "no server entry found"}. Mount furin({ style }) in the server entry, or list the apps in furin.config.ts: apps: [{ pagesDir: "src/routes", style: "tanstack" }].`);
|
|
10265
10411
|
}
|
|
10266
10412
|
async function scanApps(options, serverEntry, rootDir) {
|
|
10267
10413
|
const appSpecs = await resolveAppSpecs(options, serverEntry, rootDir);
|
|
@@ -10290,9 +10436,13 @@ function generateRouteTypes(options) {
|
|
|
10290
10436
|
async function buildApp(options) {
|
|
10291
10437
|
return withProductionBuild(() => buildAppInternal(options));
|
|
10292
10438
|
}
|
|
10439
|
+
function existingServerEntry(options, rootDir) {
|
|
10440
|
+
const entry = resolve13(rootDir, options.serverEntry ?? "src/server.ts");
|
|
10441
|
+
return existsSync18(entry) ? entry : null;
|
|
10442
|
+
}
|
|
10293
10443
|
async function buildAppInternal(options) {
|
|
10294
10444
|
const rootDir = resolve13(options.rootDir ?? process.cwd());
|
|
10295
|
-
const buildRoot =
|
|
10445
|
+
const buildRoot = join21(rootDir, BUILD_OUTPUT_DIR);
|
|
10296
10446
|
const targets = requestedTargets(options.target);
|
|
10297
10447
|
const serverEntry = (() => {
|
|
10298
10448
|
if (targets.every(isServerless)) {
|
|
@@ -10310,7 +10460,8 @@ async function buildAppInternal(options) {
|
|
|
10310
10460
|
}
|
|
10311
10461
|
return entry;
|
|
10312
10462
|
})();
|
|
10313
|
-
const
|
|
10463
|
+
const mountEntry = serverEntry ?? existingServerEntry(options, rootDir);
|
|
10464
|
+
const apps = await scanApps(options, mountEntry, rootDir);
|
|
10314
10465
|
writeAppRouteTypes(apps, rootDir);
|
|
10315
10466
|
const primaryApp = apps.find((app) => app.prefix === "") ?? apps[0];
|
|
10316
10467
|
ensureDir(buildRoot);
|
|
@@ -10318,13 +10469,14 @@ async function buildAppInternal(options) {
|
|
|
10318
10469
|
version: 1,
|
|
10319
10470
|
generatedAt: new Date().toISOString(),
|
|
10320
10471
|
rootDir: toPosixPath(rootDir),
|
|
10321
|
-
pagesDir: toPosixPath(
|
|
10322
|
-
rootPath: toPosixPath(
|
|
10323
|
-
serverEntry: serverEntry ? toPosixPath(
|
|
10472
|
+
pagesDir: toPosixPath(relative15(rootDir, primaryApp.pagesDir)),
|
|
10473
|
+
rootPath: toPosixPath(relative15(rootDir, primaryApp.root.path)),
|
|
10474
|
+
serverEntry: serverEntry ? toPosixPath(relative15(rootDir, serverEntry)) : null,
|
|
10324
10475
|
routes: primaryApp.routes.map((route) => toBuildRouteManifestEntry(route, rootDir)),
|
|
10325
10476
|
apps: apps.map((app) => ({
|
|
10326
|
-
pagesDir: toPosixPath(
|
|
10477
|
+
pagesDir: toPosixPath(relative15(rootDir, app.pagesDir)),
|
|
10327
10478
|
prefix: app.prefix,
|
|
10479
|
+
style: app.style,
|
|
10328
10480
|
routes: app.routes.map((route) => toBuildRouteManifestEntry(route, rootDir))
|
|
10329
10481
|
})),
|
|
10330
10482
|
targets: {}
|
|
@@ -10350,7 +10502,7 @@ async function buildAppInternal(options) {
|
|
|
10350
10502
|
const adapter = adapterFor(target, options);
|
|
10351
10503
|
manifest.targets[adapter.name] = await buildAdapterTarget(adapter, apps, rootDir, buildRoot, serverEntry, options);
|
|
10352
10504
|
}
|
|
10353
|
-
writeFileSync13(
|
|
10505
|
+
writeFileSync13(join21(buildRoot, "manifest.json"), `${JSON.stringify(manifest, null, 2)}
|
|
10354
10506
|
`);
|
|
10355
10507
|
return {
|
|
10356
10508
|
manifest,
|