@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/cli/index.js
CHANGED
|
@@ -8,11 +8,11 @@ import { parseArgs as parseArgs2 } from "util";
|
|
|
8
8
|
|
|
9
9
|
// src/build/index.ts
|
|
10
10
|
import { existsSync as existsSync18, writeFileSync as writeFileSync13 } from "fs";
|
|
11
|
-
import { join as
|
|
11
|
+
import { join as join21, relative as relative15, resolve as resolve13 } from "path";
|
|
12
12
|
|
|
13
13
|
// src/adapter/build.ts
|
|
14
14
|
import { existsSync as existsSync12, readFileSync as readFileSync7, rmSync as rmSync3, writeFileSync as writeFileSync7 } from "fs";
|
|
15
|
-
import { basename as basename5, extname as extname3, join as
|
|
15
|
+
import { basename as basename5, extname as extname3, join as join14, relative as relative9 } from "path";
|
|
16
16
|
|
|
17
17
|
// src/build/bun-build.ts
|
|
18
18
|
var PRODUCTION_DEFINE = { "process.env.NODE_ENV": JSON.stringify("production") };
|
|
@@ -191,7 +191,7 @@ function segmentSpecificity(segment) {
|
|
|
191
191
|
}
|
|
192
192
|
return segment.startsWith(":") ? 2 : 3;
|
|
193
193
|
}
|
|
194
|
-
function
|
|
194
|
+
function compareConcreteSpecificity(a, b) {
|
|
195
195
|
const aSegments = a.split("/").filter(Boolean);
|
|
196
196
|
const bSegments = b.split("/").filter(Boolean);
|
|
197
197
|
const length = Math.max(aSegments.length, bSegments.length);
|
|
@@ -211,6 +211,24 @@ function compareRouteSpecificity(a, b) {
|
|
|
211
211
|
}
|
|
212
212
|
return 0;
|
|
213
213
|
}
|
|
214
|
+
function expandOptionalSegments(pattern) {
|
|
215
|
+
let variants = [[]];
|
|
216
|
+
for (const segment of pattern.split("/").filter(Boolean)) {
|
|
217
|
+
if (segment.startsWith(":") && segment.endsWith("?")) {
|
|
218
|
+
const required = segment.slice(0, -1);
|
|
219
|
+
variants = variants.flatMap((variant) => [variant, [...variant, required]]);
|
|
220
|
+
} else {
|
|
221
|
+
variants = variants.map((variant) => [...variant, segment]);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return variants.map((variant) => `/${variant.join("/")}`);
|
|
225
|
+
}
|
|
226
|
+
function mostSpecificVariant(pattern) {
|
|
227
|
+
return expandOptionalSegments(pattern).reduce((best, variant) => compareConcreteSpecificity(variant, best) > 0 ? variant : best);
|
|
228
|
+
}
|
|
229
|
+
function compareRouteSpecificity(a, b) {
|
|
230
|
+
return compareConcreteSpecificity(mostSpecificVariant(a), mostSpecificVariant(b));
|
|
231
|
+
}
|
|
214
232
|
|
|
215
233
|
// src/shared/search-params.ts
|
|
216
234
|
function isObject(value) {
|
|
@@ -359,7 +377,6 @@ function normalizePrefix(prefix) {
|
|
|
359
377
|
}
|
|
360
378
|
|
|
361
379
|
// src/server/router/patterns.ts
|
|
362
|
-
import { parse } from "path";
|
|
363
380
|
function resolveRouteRevalidate(page) {
|
|
364
381
|
return page.revalidate ?? page._route.revalidate;
|
|
365
382
|
}
|
|
@@ -379,60 +396,7 @@ function resolveDocumentRevalidate(route) {
|
|
|
379
396
|
}
|
|
380
397
|
return Math.min(...intervals);
|
|
381
398
|
}
|
|
382
|
-
var
|
|
383
|
-
function parseDynamicRouteSegment(segment, sourcePath) {
|
|
384
|
-
if (!(segment.startsWith("[") && segment.endsWith("]"))) {
|
|
385
|
-
return;
|
|
386
|
-
}
|
|
387
|
-
const inner = segment.slice(1, -1);
|
|
388
|
-
const catchAll = inner.startsWith("...");
|
|
389
|
-
const name = catchAll ? inner.slice(3) : inner;
|
|
390
|
-
if (!DYNAMIC_PARAMETER_NAME_RE.test(name)) {
|
|
391
|
-
throw new Error(`[furin] Invalid dynamic parameter ${JSON.stringify(name)} in ${JSON.stringify(sourcePath ?? segment)}. Parameter names must match ${DYNAMIC_PARAMETER_NAME_RE}.`);
|
|
392
|
-
}
|
|
393
|
-
return { catchAll, name };
|
|
394
|
-
}
|
|
395
|
-
function routeSegmentToPattern(segment) {
|
|
396
|
-
const dynamic = parseDynamicRouteSegment(segment, undefined);
|
|
397
|
-
if (!dynamic) {
|
|
398
|
-
return segment;
|
|
399
|
-
}
|
|
400
|
-
return dynamic.catchAll ? "*" : `:${dynamic.name}`;
|
|
401
|
-
}
|
|
402
|
-
var ROUTE_GROUP_RE = /^\([^()]+\)$/;
|
|
403
|
-
function isRouteGroup(segment) {
|
|
404
|
-
return ROUTE_GROUP_RE.test(segment);
|
|
405
|
-
}
|
|
406
|
-
var DYNAMIC_ROUTE_SEGMENT_RE = /(^|\/):[^/]+/g;
|
|
407
|
-
function routePatternKey(pattern) {
|
|
408
|
-
return pattern.replace(DYNAMIC_ROUTE_SEGMENT_RE, "$1:param");
|
|
409
|
-
}
|
|
410
|
-
function filePathToPattern(path) {
|
|
411
|
-
const parts = path.replaceAll("\\", "/").split("/");
|
|
412
|
-
const segments = [];
|
|
413
|
-
const lastIndex = parts.length - 1;
|
|
414
|
-
for (let idx = 0;idx < parts.length; idx += 1) {
|
|
415
|
-
const part = parts[idx];
|
|
416
|
-
if (part === undefined || part.length === 0) {
|
|
417
|
-
continue;
|
|
418
|
-
}
|
|
419
|
-
const isFile = idx === lastIndex;
|
|
420
|
-
const name = isFile ? parse(part).name : part;
|
|
421
|
-
if (!isFile && isRouteGroup(name)) {
|
|
422
|
-
continue;
|
|
423
|
-
}
|
|
424
|
-
if (isFile && name === "index") {
|
|
425
|
-
continue;
|
|
426
|
-
}
|
|
427
|
-
const dynamic = parseDynamicRouteSegment(name, path);
|
|
428
|
-
if (dynamic) {
|
|
429
|
-
segments.push(dynamic.catchAll ? "*" : `:${dynamic.name}`);
|
|
430
|
-
} else {
|
|
431
|
-
segments.push(name);
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
return `/${segments.join("/")}`;
|
|
435
|
-
}
|
|
399
|
+
var SPLAT_PARAM = "_splat";
|
|
436
400
|
var REGEX_META_CHARS_RE = /[.*+?^${}()|[\]\\]/g;
|
|
437
401
|
function escapeRegExp(value) {
|
|
438
402
|
return value.replace(REGEX_META_CHARS_RE, "\\$&");
|
|
@@ -448,11 +412,17 @@ function routePatternRegexSource(pattern, sources) {
|
|
|
448
412
|
while (i < pattern.length && pattern[i] !== "/") {
|
|
449
413
|
i += 1;
|
|
450
414
|
}
|
|
451
|
-
|
|
452
|
-
|
|
415
|
+
const name = pattern.slice(start, i);
|
|
416
|
+
if (name.endsWith("?") && source.endsWith("/")) {
|
|
417
|
+
paramNames.push(name.slice(0, -1));
|
|
418
|
+
source = `${source.slice(0, -1)}(?:/${sources.param})?`;
|
|
419
|
+
} else {
|
|
420
|
+
paramNames.push(name);
|
|
421
|
+
source += sources.param;
|
|
422
|
+
}
|
|
453
423
|
} else if (pattern[i] === "*") {
|
|
454
|
-
paramNames.push(
|
|
455
|
-
source
|
|
424
|
+
paramNames.push(SPLAT_PARAM);
|
|
425
|
+
source = source.endsWith("/") ? `${source.slice(0, -1)}(?:/${sources.catchAll})?` : source + sources.catchAll;
|
|
456
426
|
i += 1;
|
|
457
427
|
} else {
|
|
458
428
|
const ch = pattern[i];
|
|
@@ -1775,18 +1745,19 @@ function movePrivateServerSourceMaps(outputDir, privateDir, filenames) {
|
|
|
1775
1745
|
|
|
1776
1746
|
// src/build/server-app-entry.ts
|
|
1777
1747
|
import { writeFileSync as writeFileSync2 } from "fs";
|
|
1778
|
-
import { join as
|
|
1748
|
+
import { join as join6 } from "path";
|
|
1779
1749
|
|
|
1780
1750
|
// src/plugin/route-registry.ts
|
|
1781
|
-
import {
|
|
1751
|
+
import { join as join5, resolve as resolve2 } from "path";
|
|
1782
1752
|
|
|
1783
1753
|
// src/plugin/route-modules.ts
|
|
1784
1754
|
import { existsSync as existsSync5, readFileSync, realpathSync, statSync } from "fs";
|
|
1785
1755
|
import { dirname as dirname4, isAbsolute as isAbsolute2, join as join4, relative as relative3, sep } from "path";
|
|
1786
1756
|
import { pathToFileURL } from "url";
|
|
1787
1757
|
var ROUTE_MODULE_CACHE_SYMBOL = Symbol.for("@teyik0/furin/route-module-cache");
|
|
1758
|
+
var OPTIONAL_MARK = /\?$/;
|
|
1788
1759
|
function validateRouteParams(path, schemas) {
|
|
1789
|
-
const pathParams = path.split("/").filter((segment) => segment === "*" || segment.startsWith(":")).map((segment) => segment === "*" ?
|
|
1760
|
+
const pathParams = path.split("/").filter((segment) => segment === "*" || segment.startsWith(":")).map((segment) => segment === "*" ? SPLAT_PARAM : segment.slice(1).replace(OPTIONAL_MARK, ""));
|
|
1790
1761
|
if (pathParams.length === 0) {
|
|
1791
1762
|
return;
|
|
1792
1763
|
}
|
|
@@ -1902,118 +1873,342 @@ async function validateRouteModules(routeFiles) {
|
|
|
1902
1873
|
}
|
|
1903
1874
|
|
|
1904
1875
|
// src/plugin/route-tree.ts
|
|
1876
|
+
import { resolve } from "path";
|
|
1877
|
+
|
|
1878
|
+
// src/plugin/route-manifest.ts
|
|
1905
1879
|
import { existsSync as existsSync6, readdirSync } from "fs";
|
|
1906
|
-
import { extname
|
|
1880
|
+
import { extname } from "path";
|
|
1907
1881
|
var ROUTE_EXTENSION = /\.(?:jsx?|tsx?)$/;
|
|
1908
|
-
var
|
|
1909
|
-
|
|
1910
|
-
|
|
1882
|
+
var PARAM_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
1883
|
+
var BRACKET_ESCAPE = /\[([^\]]*)\]/g;
|
|
1884
|
+
var SOURCE_EXTENSIONS = [".tsx", ".ts", ".jsx", ".js"];
|
|
1885
|
+
var PARAM_SEGMENT = /(^|\/):[^/]+/g;
|
|
1886
|
+
var NEXT_CATCH_ALL = /^\[\[?\.\.\.([^\]]+)\]\]?$/;
|
|
1887
|
+
function child(directory, name) {
|
|
1888
|
+
return `${directory}/${name}`;
|
|
1889
|
+
}
|
|
1890
|
+
function sortedEntries(directory) {
|
|
1891
|
+
return readdirSync(directory, { withFileTypes: true }).sort((left, right) => left.name.localeCompare(right.name));
|
|
1892
|
+
}
|
|
1893
|
+
function moduleBase(name) {
|
|
1894
|
+
if (name.endsWith(".d.ts") || !ROUTE_EXTENSION.test(name)) {
|
|
1895
|
+
return;
|
|
1896
|
+
}
|
|
1897
|
+
return name.slice(0, -extname(name).length);
|
|
1911
1898
|
}
|
|
1912
|
-
function
|
|
1913
|
-
return
|
|
1899
|
+
function findModule(directory, base) {
|
|
1900
|
+
return SOURCE_EXTENSIONS.map((extension) => child(directory, `${base}${extension}`)).find((path) => existsSync6(path));
|
|
1914
1901
|
}
|
|
1915
|
-
function
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
if (
|
|
1927
|
-
|
|
1928
|
-
}
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
if (ROUTE_CONVENTIONS.has(base)) {
|
|
1902
|
+
function paramName(name, raw, sourcePath) {
|
|
1903
|
+
if (!PARAM_NAME.test(name)) {
|
|
1904
|
+
throw new Error(`[furin] Invalid dynamic parameter ${JSON.stringify(raw)} in ${JSON.stringify(sourcePath)}. Parameter names must match ${PARAM_NAME}.`);
|
|
1905
|
+
}
|
|
1906
|
+
return name;
|
|
1907
|
+
}
|
|
1908
|
+
function splitFlatName(base) {
|
|
1909
|
+
const tokens = [];
|
|
1910
|
+
let current = "";
|
|
1911
|
+
let escaped = false;
|
|
1912
|
+
for (const character of base) {
|
|
1913
|
+
if (character === "[") {
|
|
1914
|
+
escaped = true;
|
|
1915
|
+
} else if (character === "]") {
|
|
1916
|
+
escaped = false;
|
|
1917
|
+
}
|
|
1918
|
+
if (character === "." && !escaped) {
|
|
1919
|
+
tokens.push(current);
|
|
1920
|
+
current = "";
|
|
1935
1921
|
continue;
|
|
1936
1922
|
}
|
|
1937
|
-
|
|
1938
|
-
|
|
1923
|
+
current += character;
|
|
1924
|
+
}
|
|
1925
|
+
tokens.push(current);
|
|
1926
|
+
return tokens;
|
|
1927
|
+
}
|
|
1928
|
+
function tanstackSegment(raw, sourcePath) {
|
|
1929
|
+
if (raw.startsWith("(") && raw.endsWith(")")) {
|
|
1930
|
+
return { raw, type: "group" };
|
|
1931
|
+
}
|
|
1932
|
+
if (raw === "$") {
|
|
1933
|
+
return { raw, type: "splat" };
|
|
1934
|
+
}
|
|
1935
|
+
if (raw.startsWith("{-$") && raw.endsWith("}")) {
|
|
1936
|
+
return {
|
|
1937
|
+
name: paramName(raw.slice(3, -1), raw, sourcePath),
|
|
1938
|
+
optional: true,
|
|
1939
|
+
raw,
|
|
1940
|
+
type: "param"
|
|
1941
|
+
};
|
|
1942
|
+
}
|
|
1943
|
+
if (raw.startsWith("$")) {
|
|
1944
|
+
return { name: paramName(raw.slice(1), raw, sourcePath), optional: false, raw, type: "param" };
|
|
1945
|
+
}
|
|
1946
|
+
if (raw.startsWith("_")) {
|
|
1947
|
+
return { raw, type: "pathless" };
|
|
1948
|
+
}
|
|
1949
|
+
const value = (raw.endsWith("_") ? raw.slice(0, -1) : raw).replace(BRACKET_ESCAPE, "$1");
|
|
1950
|
+
return { raw, type: "static", value };
|
|
1951
|
+
}
|
|
1952
|
+
function tanstackCandidate(base, segments, sourcePath) {
|
|
1953
|
+
const tokens = splitFlatName(base);
|
|
1954
|
+
const last = tokens.at(-1);
|
|
1955
|
+
const index = last === "index";
|
|
1956
|
+
const routeFile = last === "route";
|
|
1957
|
+
const own = (index || routeFile ? tokens.slice(0, -1) : tokens).map((token) => tanstackSegment(token, sourcePath));
|
|
1958
|
+
const routeSegments = [...segments, ...own];
|
|
1959
|
+
if (routeFile && routeSegments.length === 0) {
|
|
1960
|
+
throw new Error(`[furin] ${sourcePath}: a top-level route.tsx has no path to wrap. The root layout lives in __root.tsx.`);
|
|
1961
|
+
}
|
|
1962
|
+
return {
|
|
1963
|
+
forcedLayout: routeFile || routeSegments.at(-1)?.type === "pathless",
|
|
1964
|
+
index,
|
|
1965
|
+
segments: routeSegments,
|
|
1966
|
+
sourcePath
|
|
1967
|
+
};
|
|
1968
|
+
}
|
|
1969
|
+
function scanTanstack(pagesDir) {
|
|
1970
|
+
const candidates = [];
|
|
1971
|
+
const walk = (directory, segments) => {
|
|
1972
|
+
for (const entry of sortedEntries(directory)) {
|
|
1973
|
+
if (entry.name.startsWith("-")) {
|
|
1974
|
+
continue;
|
|
1975
|
+
}
|
|
1976
|
+
const sourcePath = child(directory, entry.name);
|
|
1977
|
+
if (entry.isDirectory()) {
|
|
1978
|
+
walk(sourcePath, [...segments, tanstackSegment(entry.name, sourcePath)]);
|
|
1979
|
+
continue;
|
|
1980
|
+
}
|
|
1981
|
+
const base = moduleBase(entry.name);
|
|
1982
|
+
if (base !== undefined && !(segments.length === 0 && base === "__root")) {
|
|
1983
|
+
candidates.push(tanstackCandidate(base, segments, sourcePath));
|
|
1984
|
+
}
|
|
1939
1985
|
}
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1986
|
+
};
|
|
1987
|
+
walk(pagesDir, []);
|
|
1988
|
+
return {
|
|
1989
|
+
boundaries: [],
|
|
1990
|
+
candidates,
|
|
1991
|
+
rootPath: findModule(pagesDir, "__root") ?? child(pagesDir, "__root.tsx")
|
|
1992
|
+
};
|
|
1993
|
+
}
|
|
1994
|
+
function nextSegment(name, sourcePath) {
|
|
1995
|
+
if (name.startsWith("(") && name.endsWith(")")) {
|
|
1996
|
+
return { raw: name, type: "group" };
|
|
1997
|
+
}
|
|
1998
|
+
const catchAll = name.match(NEXT_CATCH_ALL);
|
|
1999
|
+
if (catchAll?.[1] !== undefined) {
|
|
2000
|
+
paramName(catchAll[1], name, sourcePath);
|
|
2001
|
+
return { raw: "$", type: "splat" };
|
|
2002
|
+
}
|
|
2003
|
+
if (name.startsWith("[") && name.endsWith("]")) {
|
|
2004
|
+
const name_ = paramName(name.slice(1, -1), name, sourcePath);
|
|
2005
|
+
return { name: name_, optional: false, raw: `$${name_}`, type: "param" };
|
|
2006
|
+
}
|
|
2007
|
+
return { raw: name, type: "static", value: name };
|
|
2008
|
+
}
|
|
2009
|
+
function addNextFile(state, base, segments, sourcePath) {
|
|
2010
|
+
if (base === "route") {
|
|
2011
|
+
throw new Error(`[furin] ${sourcePath}: route handlers are not supported. Declare API routes on your Elysia app instead.`);
|
|
2012
|
+
}
|
|
2013
|
+
if (base === "layout" && segments.at(-1)?.type === "splat") {
|
|
2014
|
+
throw new Error(`[furin] ${sourcePath}: a layout cannot share a catch-all folder with its page: move it to the parent folder.`);
|
|
2015
|
+
}
|
|
2016
|
+
if (base === "page" || base === "layout" && segments.length > 0) {
|
|
2017
|
+
state.candidates.push({
|
|
2018
|
+
forcedLayout: base === "layout",
|
|
2019
|
+
index: base === "page" && segments.at(-1)?.type !== "splat",
|
|
2020
|
+
segments,
|
|
1943
2021
|
sourcePath
|
|
1944
2022
|
});
|
|
2023
|
+
} else if (base === "layout") {
|
|
2024
|
+
state.rootPath ??= sourcePath;
|
|
2025
|
+
} else if (base === "error") {
|
|
2026
|
+
state.boundary.errorPath ??= sourcePath;
|
|
2027
|
+
} else if (base === "not-found") {
|
|
2028
|
+
state.boundary.notFoundPath ??= sourcePath;
|
|
1945
2029
|
}
|
|
1946
2030
|
}
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
const
|
|
1950
|
-
|
|
2031
|
+
function scanNext(pagesDir) {
|
|
2032
|
+
const candidates = [];
|
|
2033
|
+
const boundaries = [];
|
|
2034
|
+
let rootPath;
|
|
2035
|
+
const walk = (directory, segments) => {
|
|
2036
|
+
const boundary = { directory, errorPath: undefined, notFoundPath: undefined };
|
|
2037
|
+
const state = { boundary, candidates, rootPath };
|
|
2038
|
+
for (const entry of sortedEntries(directory)) {
|
|
2039
|
+
const sourcePath = child(directory, entry.name);
|
|
2040
|
+
if (!entry.isDirectory()) {
|
|
2041
|
+
addNextFile(state, moduleBase(entry.name), segments, sourcePath);
|
|
2042
|
+
} else if (!entry.name.startsWith("_")) {
|
|
2043
|
+
walk(sourcePath, [...segments, nextSegment(entry.name, sourcePath)]);
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
rootPath ??= state.rootPath;
|
|
2047
|
+
if (boundary.errorPath || boundary.notFoundPath) {
|
|
2048
|
+
boundaries.push(boundary);
|
|
2049
|
+
}
|
|
2050
|
+
};
|
|
2051
|
+
walk(pagesDir, []);
|
|
2052
|
+
boundaries.sort((left, right) => left.directory.length - right.directory.length);
|
|
2053
|
+
return { boundaries, candidates, rootPath: rootPath ?? child(pagesDir, "layout.tsx") };
|
|
1951
2054
|
}
|
|
1952
|
-
function
|
|
1953
|
-
return
|
|
2055
|
+
function segmentKey(segments) {
|
|
2056
|
+
return segments.map((segment) => segment.raw).join("/");
|
|
1954
2057
|
}
|
|
1955
|
-
function
|
|
1956
|
-
|
|
1957
|
-
|
|
2058
|
+
function segmentPattern(segment) {
|
|
2059
|
+
switch (segment.type) {
|
|
2060
|
+
case "group":
|
|
2061
|
+
case "pathless":
|
|
2062
|
+
return;
|
|
2063
|
+
case "param":
|
|
2064
|
+
return `:${segment.name}${segment.optional ? "?" : ""}`;
|
|
2065
|
+
case "splat":
|
|
2066
|
+
return "*";
|
|
2067
|
+
default:
|
|
2068
|
+
return segment.value;
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
function urlPattern(segments) {
|
|
2072
|
+
return `/${segments.flatMap((segment) => segmentPattern(segment) ?? []).join("/")}`;
|
|
2073
|
+
}
|
|
2074
|
+
function routeParams(segments) {
|
|
2075
|
+
return segments.flatMap((segment) => {
|
|
2076
|
+
if (segment.type === "param") {
|
|
2077
|
+
return [{ name: segment.name, optional: segment.optional }];
|
|
2078
|
+
}
|
|
2079
|
+
return segment.type === "splat" ? [{ name: "_splat", optional: false }] : [];
|
|
2080
|
+
});
|
|
2081
|
+
}
|
|
2082
|
+
function assertSplatLast(candidate) {
|
|
2083
|
+
const splat = candidate.segments.findIndex((segment) => segment.type === "splat");
|
|
2084
|
+
if (splat !== -1 && splat < candidate.segments.length - 1) {
|
|
2085
|
+
throw new Error(`[furin] ${candidate.sourcePath}: a catch-all segment must be the last segment of its path.`);
|
|
2086
|
+
}
|
|
2087
|
+
}
|
|
2088
|
+
function patternKeys(pattern) {
|
|
2089
|
+
const keys = expandOptionalSegments(pattern).map((variant) => variant.replace(PARAM_SEGMENT, "$1:param"));
|
|
2090
|
+
return [...new Set(keys)];
|
|
1958
2091
|
}
|
|
1959
|
-
function
|
|
1960
|
-
const
|
|
1961
|
-
|
|
2092
|
+
function claimPatterns(seenPatterns, pattern, sourcePath, relativePath) {
|
|
2093
|
+
for (const patternKey of patternKeys(pattern)) {
|
|
2094
|
+
const previous = seenPatterns.get(patternKey);
|
|
2095
|
+
if (previous !== undefined) {
|
|
2096
|
+
throw new Error(`[furin] Duplicate route pattern "${patternKey}" from "${relativePath(previous)}" and "${relativePath(sourcePath)}".`);
|
|
2097
|
+
}
|
|
2098
|
+
seenPatterns.set(patternKey, sourcePath);
|
|
2099
|
+
}
|
|
2100
|
+
}
|
|
2101
|
+
function buildManifest(scan, pagesDir, prefix) {
|
|
2102
|
+
const relativePath = (path) => path.slice(pagesDir.length + 1);
|
|
2103
|
+
const { candidates } = scan;
|
|
2104
|
+
const keys = candidates.map((candidate) => segmentKey(candidate.segments));
|
|
2105
|
+
const hasDescendant = (key, self2) => candidates.some((other, index) => other !== self2 && (keys[index]?.startsWith(`${key}/`) === true || other.index && keys[index] === key));
|
|
2106
|
+
const layouts = new Map;
|
|
2107
|
+
const kinds = candidates.map((candidate, index) => {
|
|
2108
|
+
assertSplatLast(candidate);
|
|
2109
|
+
const key = keys[index] ?? "";
|
|
2110
|
+
const isLayout = !candidate.index && (candidate.forcedLayout || hasDescendant(key, candidate));
|
|
2111
|
+
if (!isLayout) {
|
|
2112
|
+
return "page";
|
|
2113
|
+
}
|
|
2114
|
+
const existing = layouts.get(key);
|
|
2115
|
+
if (existing !== undefined) {
|
|
2116
|
+
throw new Error(`[furin] Two layouts wrap "/${key}": "${relativePath(existing)}" and "${relativePath(candidate.sourcePath)}".`);
|
|
2117
|
+
}
|
|
2118
|
+
layouts.set(key, candidate.sourcePath);
|
|
2119
|
+
return "layout";
|
|
2120
|
+
});
|
|
2121
|
+
const seenIds = new Map;
|
|
1962
2122
|
const seenPatterns = new Map;
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
2123
|
+
const routes = candidates.map((candidate, index) => {
|
|
2124
|
+
const kind = kinds[index] ?? "page";
|
|
2125
|
+
const { segments, sourcePath } = candidate;
|
|
2126
|
+
const key = keys[index] ?? "";
|
|
2127
|
+
let parentPath = candidate.index ? layouts.get(key) : undefined;
|
|
2128
|
+
for (let depth = segments.length - 1;parentPath === undefined && depth > 0; depth -= 1) {
|
|
2129
|
+
parentPath = layouts.get(segmentKey(segments.slice(0, depth)));
|
|
2130
|
+
}
|
|
2131
|
+
const path = `/${key}${candidate.index && key !== "" ? "/" : ""}`;
|
|
2132
|
+
const id = prefix === "" ? path : `${prefix}${path}`;
|
|
2133
|
+
const previousId = seenIds.get(id);
|
|
2134
|
+
if (previousId !== undefined) {
|
|
2135
|
+
throw new Error(`[furin] Duplicate route id "${id}" from "${relativePath(previousId)}" and "${relativePath(sourcePath)}".`);
|
|
2136
|
+
}
|
|
2137
|
+
seenIds.set(id, sourcePath);
|
|
2138
|
+
const pattern = urlPattern(segments);
|
|
2139
|
+
if (kind === "page") {
|
|
2140
|
+
claimPatterns(seenPatterns, pattern, sourcePath, relativePath);
|
|
2141
|
+
}
|
|
2142
|
+
return { id, kind, params: routeParams(segments), parentPath, pattern, sourcePath };
|
|
1976
2143
|
});
|
|
2144
|
+
return { boundaries: scan.boundaries, rootPath: scan.rootPath, routes };
|
|
2145
|
+
}
|
|
2146
|
+
function scanRouteManifest({ pagesDir, prefix, style }) {
|
|
2147
|
+
const directory = pagesDir.replaceAll("\\", "/");
|
|
2148
|
+
return buildManifest(style === "nextjs" ? scanNext(directory) : scanTanstack(directory), directory, prefix);
|
|
2149
|
+
}
|
|
2150
|
+
|
|
2151
|
+
// src/plugin/route-tree.ts
|
|
2152
|
+
function instanceKey(instance) {
|
|
2153
|
+
return `${resolve(instance.pagesDir)}\x00${instance.prefix}`;
|
|
2154
|
+
}
|
|
2155
|
+
function routeModuleSpecifier(instance) {
|
|
2156
|
+
return `@teyik0/furin/routes?instance=${Bun.hash(instanceKey(instance)).toString(16)}`;
|
|
1977
2157
|
}
|
|
1978
|
-
function
|
|
1979
|
-
const
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
2158
|
+
function routeId(instanceId, id) {
|
|
2159
|
+
const encodedId = Array.from(new TextEncoder().encode(id), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
2160
|
+
return `_route_${instanceId}_${encodedId}`;
|
|
2161
|
+
}
|
|
2162
|
+
function relativePrefix(pattern, parentPattern) {
|
|
2163
|
+
const own = pattern === "/" ? "" : pattern;
|
|
2164
|
+
const parent = parentPattern === "/" ? "" : parentPattern;
|
|
2165
|
+
if (!own.startsWith(parent)) {
|
|
2166
|
+
throw new Error(`[furin] Route pattern "${pattern}" does not extend its layout's "${parentPattern}".`);
|
|
2167
|
+
}
|
|
2168
|
+
return own.slice(parent.length);
|
|
2169
|
+
}
|
|
2170
|
+
function buildRouteTree(instance, instanceId) {
|
|
2171
|
+
const { routes } = scanRouteManifest(instance);
|
|
2172
|
+
const byPath = new Map(routes.map((route) => [route.sourcePath, route]));
|
|
2173
|
+
const root = { children: [], layout: undefined, pages: [], prefix: "" };
|
|
2174
|
+
const nodes = new Map([[undefined, root]]);
|
|
2175
|
+
const parentPattern = (route) => route.parentPath === undefined ? "/" : byPath.get(route.parentPath)?.pattern ?? "/";
|
|
2176
|
+
const ensureNode = (sourcePath) => {
|
|
2177
|
+
const existing = nodes.get(sourcePath);
|
|
1983
2178
|
if (existing) {
|
|
1984
2179
|
return existing;
|
|
1985
2180
|
}
|
|
2181
|
+
const layout = sourcePath === undefined ? undefined : byPath.get(sourcePath);
|
|
2182
|
+
if (!layout) {
|
|
2183
|
+
return root;
|
|
2184
|
+
}
|
|
2185
|
+
const prefix = relativePrefix(layout.pattern, parentPattern(layout));
|
|
1986
2186
|
const node = {
|
|
1987
2187
|
children: [],
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
2188
|
+
layout: {
|
|
2189
|
+
id: routeId(instanceId, layout.id),
|
|
2190
|
+
path: "",
|
|
2191
|
+
prefix,
|
|
2192
|
+
sourcePath: resolve(layout.sourcePath)
|
|
2193
|
+
},
|
|
2194
|
+
pages: [],
|
|
2195
|
+
prefix
|
|
1992
2196
|
};
|
|
1993
|
-
nodes.set(
|
|
1994
|
-
|
|
1995
|
-
ensureNode(segments.slice(0, -1)).children.push(node);
|
|
1996
|
-
}
|
|
2197
|
+
nodes.set(sourcePath, node);
|
|
2198
|
+
ensureNode(layout.parentPath).children.push(node);
|
|
1997
2199
|
return node;
|
|
1998
2200
|
};
|
|
1999
|
-
const
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
if (file.pattern === undefined) {
|
|
2003
|
-
const path = `/${file.directorySegments.map(segmentPath).join("/")}#layout`;
|
|
2004
|
-
node.layout = { id: routeId(instanceId, path), path: "", sourcePath: file.sourcePath };
|
|
2201
|
+
for (const route of routes) {
|
|
2202
|
+
if (route.kind === "layout") {
|
|
2203
|
+
ensureNode(route.sourcePath);
|
|
2005
2204
|
continue;
|
|
2006
2205
|
}
|
|
2007
|
-
|
|
2008
|
-
id: routeId(instanceId,
|
|
2009
|
-
path:
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
node.indexRoute = route;
|
|
2014
|
-
} else {
|
|
2015
|
-
node.fileRoutes.push(route);
|
|
2016
|
-
}
|
|
2206
|
+
ensureNode(route.parentPath).pages.push({
|
|
2207
|
+
id: routeId(instanceId, route.id),
|
|
2208
|
+
path: route.pattern,
|
|
2209
|
+
prefix: relativePrefix(route.pattern, parentPattern(route)),
|
|
2210
|
+
sourcePath: resolve(route.sourcePath)
|
|
2211
|
+
});
|
|
2017
2212
|
}
|
|
2018
2213
|
return root;
|
|
2019
2214
|
}
|
|
@@ -2028,17 +2223,13 @@ function collectRouteFiles(root) {
|
|
|
2028
2223
|
if (node.layout) {
|
|
2029
2224
|
files.push(node.layout);
|
|
2030
2225
|
}
|
|
2031
|
-
|
|
2032
|
-
files.push(node.indexRoute);
|
|
2033
|
-
}
|
|
2034
|
-
files.push(...node.fileRoutes);
|
|
2226
|
+
files.push(...node.pages);
|
|
2035
2227
|
nodes.push(...node.children);
|
|
2036
2228
|
}
|
|
2037
2229
|
return files;
|
|
2038
2230
|
}
|
|
2039
2231
|
function routeSourcePaths(instance) {
|
|
2040
|
-
|
|
2041
|
-
return collectRouteFiles(buildRouteTree(instance.pagesDir, instanceId)).map(({ sourcePath }) => resolve(sourcePath)).toSorted((left, right) => left.localeCompare(right));
|
|
2232
|
+
return scanRouteManifest(instance).routes.map(({ sourcePath }) => resolve(sourcePath)).toSorted((left, right) => left.localeCompare(right));
|
|
2042
2233
|
}
|
|
2043
2234
|
|
|
2044
2235
|
// src/plugin/route-registry.ts
|
|
@@ -2047,7 +2238,6 @@ var ROUTES_REGISTRY_SPECIFIER = "furin/routes?registry";
|
|
|
2047
2238
|
var COMPOSABLE_ROUTES_REGISTRY_SPECIFIER = "furin/routes?registry=composable";
|
|
2048
2239
|
var ROUTES_REGISTRY_FILTER = /^furin\/routes\?registry(?:=composable)?$/;
|
|
2049
2240
|
var ROUTE_FILE_FILTER = /^furin-route-file:.+$/;
|
|
2050
|
-
var ROUTE_FILES_NAMESPACE = "furin-route-files";
|
|
2051
2241
|
var ROUTES_REGISTRY_FILE_FILTER = /[\\/]\.furin-routes-registry(?:-composable)?\.ts\?furin-virtual$/;
|
|
2052
2242
|
var CLIENT_ROUTES_NAMESPACE = "furin-routes-client";
|
|
2053
2243
|
var CLIENT_ROUTES_FILTER = /^(?:@teyik0\/furin|furin)\/routes$/;
|
|
@@ -2061,15 +2251,10 @@ function instanceNamespace(instance) {
|
|
|
2061
2251
|
}
|
|
2062
2252
|
function emitRouteNode(node, indentation, includeRootCatchAll) {
|
|
2063
2253
|
const childIndentation = `${indentation} `;
|
|
2064
|
-
const
|
|
2065
|
-
const head = `new Elysia({ prefix: ${JSON.stringify(prefix)} })`;
|
|
2254
|
+
const head = `new Elysia({ prefix: ${JSON.stringify(node.prefix)} })`;
|
|
2066
2255
|
const content = [];
|
|
2067
|
-
|
|
2068
|
-
content.push(`${childIndentation}.use(new Elysia({ prefix:
|
|
2069
|
-
}
|
|
2070
|
-
for (const route of node.fileRoutes.filter((file) => includeRootCatchAll || file.path !== "/*")) {
|
|
2071
|
-
const segment = route.path.slice(route.path.lastIndexOf("/") + 1);
|
|
2072
|
-
content.push(`${childIndentation}.use(new Elysia({ prefix: ${JSON.stringify(`/${segment}`)} }).use(${route.id}.elysia))`);
|
|
2256
|
+
for (const route of node.pages.filter((file) => includeRootCatchAll || file.path !== "/*")) {
|
|
2257
|
+
content.push(`${childIndentation}.use(new Elysia({ prefix: ${JSON.stringify(route.prefix)} }).use(${route.id}.elysia))`);
|
|
2073
2258
|
}
|
|
2074
2259
|
for (const child of node.children) {
|
|
2075
2260
|
content.push(`${childIndentation}.use(`);
|
|
@@ -2099,11 +2284,8 @@ async function retainComposableRoutes(node) {
|
|
|
2099
2284
|
if (node.layout && !await isComposable(node.layout)) {
|
|
2100
2285
|
node.layout = undefined;
|
|
2101
2286
|
}
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
}
|
|
2105
|
-
const composableRoutes = (await Promise.all(node.fileRoutes.map(async (route) => ({ keep: await isComposable(route), route })))).flatMap(({ keep, route }) => keep ? [route] : []);
|
|
2106
|
-
node.fileRoutes = composableRoutes;
|
|
2287
|
+
const composableRoutes = (await Promise.all(node.pages.map(async (route) => ({ keep: await isComposable(route), route })))).flatMap(({ keep, route }) => keep ? [route] : []);
|
|
2288
|
+
node.pages = composableRoutes;
|
|
2107
2289
|
await Promise.all(node.children.map((child) => retainComposableRoutes(child)));
|
|
2108
2290
|
}
|
|
2109
2291
|
async function generateServerInstance(instance, routeFilesBySpecifier, materialized, includeRootCatchAll) {
|
|
@@ -2114,7 +2296,7 @@ async function generateServerInstance(instance, routeFilesBySpecifier, materiali
|
|
|
2114
2296
|
return includeRootCatchAll ? instance.routeRegistry.complete : instance.routeRegistry.composable;
|
|
2115
2297
|
}
|
|
2116
2298
|
const instanceId = Bun.hash(instanceKey(instance)).toString(16);
|
|
2117
|
-
const tree = buildRouteTree(instance
|
|
2299
|
+
const tree = buildRouteTree(instance, instanceId);
|
|
2118
2300
|
await retainComposableRoutes(tree);
|
|
2119
2301
|
const imports = collectRouteFiles(tree).sort((left, right) => left.sourcePath.localeCompare(right.sourcePath)).map((route) => {
|
|
2120
2302
|
const specifier = materialized ? resolve2(route.sourcePath).replaceAll("\\", "/") : routeFileSpecifier(route);
|
|
@@ -2158,7 +2340,7 @@ async function clientRoutesSource(instance) {
|
|
|
2158
2340
|
if (instance.routeRegistry) {
|
|
2159
2341
|
return instance.routeRegistry.client;
|
|
2160
2342
|
}
|
|
2161
|
-
const tree = buildRouteTree(instance
|
|
2343
|
+
const tree = buildRouteTree(instance, Bun.hash(instanceKey(instance)).toString(16));
|
|
2162
2344
|
const routes = collectRouteFiles(tree).filter((route) => route.path !== "").sort((left, right) => left.path.localeCompare(right.path));
|
|
2163
2345
|
const metadata = await Promise.all(routes.map(async (routeFile) => {
|
|
2164
2346
|
const module = await loadRouteModule(routeFile.sourcePath);
|
|
@@ -2187,9 +2369,8 @@ function serverProxySource(instance, includeRootCatchAll) {
|
|
|
2187
2369
|
}
|
|
2188
2370
|
function createRoutesPlugin(options) {
|
|
2189
2371
|
const routeFilesBySpecifier = new Map;
|
|
2190
|
-
const
|
|
2191
|
-
const
|
|
2192
|
-
const composableRegistryVirtualPath = join6(resolve2(primaryInstance(options.instances).pagesDir), ".furin-routes-registry-composable.ts?furin-virtual");
|
|
2372
|
+
const registryVirtualPath = join5(resolve2(primaryInstance(options.instances).pagesDir), ".furin-routes-registry.ts?furin-virtual");
|
|
2373
|
+
const composableRegistryVirtualPath = join5(resolve2(primaryInstance(options.instances).pagesDir), ".furin-routes-registry-composable.ts?furin-virtual");
|
|
2193
2374
|
const instancesBySpecifier = new Map(options.instances.flatMap((instance) => [
|
|
2194
2375
|
[
|
|
2195
2376
|
routeModuleSpecifier(instance),
|
|
@@ -2239,20 +2420,7 @@ function createRoutesPlugin(options) {
|
|
|
2239
2420
|
if (!routeFile) {
|
|
2240
2421
|
throw new Error(`[furin] Unknown route module: ${path}`);
|
|
2241
2422
|
}
|
|
2242
|
-
|
|
2243
|
-
routeFilesByResolvedPath.set(resolvedPath, routeFile);
|
|
2244
|
-
return { namespace: ROUTE_FILES_NAMESPACE, path: resolvedPath };
|
|
2245
|
-
});
|
|
2246
|
-
build.onLoad({ filter: VIRTUAL_ROUTES_FILTER, namespace: ROUTE_FILES_NAMESPACE }, async ({ path }) => {
|
|
2247
|
-
const routeFile = routeFilesByResolvedPath.get(path);
|
|
2248
|
-
if (!routeFile) {
|
|
2249
|
-
throw new Error(`[furin] Unknown route module: ${path}`);
|
|
2250
|
-
}
|
|
2251
|
-
return {
|
|
2252
|
-
contents: await Bun.file(routeFile.sourcePath).text(),
|
|
2253
|
-
loader: detectLoaderFromPath(routeFile.sourcePath),
|
|
2254
|
-
resolveDir: dirname5(routeFile.sourcePath)
|
|
2255
|
-
};
|
|
2423
|
+
return { path: routeFile.sourcePath };
|
|
2256
2424
|
});
|
|
2257
2425
|
for (const { instance, namespace, includeRootCatchAll } of instancesBySpecifier.values()) {
|
|
2258
2426
|
build.onLoad({ filter: VIRTUAL_ROUTES_FILTER, namespace }, () => ({
|
|
@@ -2272,11 +2440,11 @@ async function materializeServerAppEntry(options) {
|
|
|
2272
2440
|
if (!instance) {
|
|
2273
2441
|
throw new Error(`[furin] Missing route instance for server app ${index}.`);
|
|
2274
2442
|
}
|
|
2275
|
-
const routePath =
|
|
2443
|
+
const routePath = join6(options.outDir, `_furin-routes-${index}.ts`);
|
|
2276
2444
|
writeFileSync2(routePath, await materializedRouteModuleSource(instance));
|
|
2277
2445
|
return { ...app, nativeRoutes: toPosixPath(routePath) };
|
|
2278
2446
|
}));
|
|
2279
|
-
const entryPath =
|
|
2447
|
+
const entryPath = join6(options.outDir, "_furin-app.ts");
|
|
2280
2448
|
writeFileSync2(entryPath, buildEntrySource({
|
|
2281
2449
|
apps,
|
|
2282
2450
|
headerComment: options.headerComment,
|
|
@@ -2289,7 +2457,7 @@ async function materializeServerAppEntry(options) {
|
|
|
2289
2457
|
|
|
2290
2458
|
// src/rsc/build/index.ts
|
|
2291
2459
|
import { mkdirSync as mkdirSync2, writeFileSync as writeFileSync3 } from "fs";
|
|
2292
|
-
import { basename as basename2, join as
|
|
2460
|
+
import { basename as basename2, join as join8 } from "path";
|
|
2293
2461
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
2294
2462
|
// ../../node_modules/.bun/yuku-ast@0.13.0/node_modules/yuku-ast/dist/aliases.js
|
|
2295
2463
|
var ALIAS_GROUPS = {
|
|
@@ -4813,9 +4981,9 @@ var MagicString = class MagicString {
|
|
|
4813
4981
|
};
|
|
4814
4982
|
|
|
4815
4983
|
// src/shared/parser.ts
|
|
4816
|
-
import { parse
|
|
4984
|
+
import { parse } from "yuku-parser";
|
|
4817
4985
|
function parseSource(code, lang) {
|
|
4818
|
-
return
|
|
4986
|
+
return parse(code, { lang, sourceType: "module" });
|
|
4819
4987
|
}
|
|
4820
4988
|
|
|
4821
4989
|
// src/plugin/module-transform.ts
|
|
@@ -5159,7 +5327,7 @@ function pruneOrphanedCode(module, forced, retained) {
|
|
|
5159
5327
|
|
|
5160
5328
|
// src/plugin/transform-client-module.ts
|
|
5161
5329
|
import { realpathSync as realpathSync2 } from "fs";
|
|
5162
|
-
import { dirname as
|
|
5330
|
+
import { dirname as dirname5 } from "path";
|
|
5163
5331
|
var FURIN_CLIENT_MODULES = new Set(["@teyik0/furin/client", "furin/client"]);
|
|
5164
5332
|
var SERVER_LOAD = '() => Promise.reject(new Error("[furin] clientModule() can only be loaded in the browser."))';
|
|
5165
5333
|
function clientModuleKey(modulePath) {
|
|
@@ -5214,7 +5382,7 @@ function rewriteClientModules(module, environment) {
|
|
|
5214
5382
|
}
|
|
5215
5383
|
let key;
|
|
5216
5384
|
try {
|
|
5217
|
-
key = JSON.stringify(clientModuleKey(Bun.resolveSync(specifier,
|
|
5385
|
+
key = JSON.stringify(clientModuleKey(Bun.resolveSync(specifier, dirname5(filename))));
|
|
5218
5386
|
} catch (error) {
|
|
5219
5387
|
throw new Error(`[furin] Cannot resolve clientModule import ${JSON.stringify(specifier)} in ${filename}`, { cause: error });
|
|
5220
5388
|
}
|
|
@@ -5681,13 +5849,13 @@ function assertInstalledRscVersions() {
|
|
|
5681
5849
|
}
|
|
5682
5850
|
|
|
5683
5851
|
// src/rsc/build/client-references.ts
|
|
5684
|
-
import { dirname as
|
|
5852
|
+
import { dirname as dirname7 } from "path";
|
|
5685
5853
|
|
|
5686
5854
|
// ../../node_modules/.bun/cjs-module-lexer@2.3.0/node_modules/cjs-module-lexer/dist/lexer.mjs
|
|
5687
5855
|
var A;
|
|
5688
5856
|
var B = new Uint8Array(new Uint16Array([1]).buffer)[0] === 1;
|
|
5689
5857
|
var Q = typeof Buffer != "undefined";
|
|
5690
|
-
function
|
|
5858
|
+
function parse2(g, C = "@") {
|
|
5691
5859
|
A || initSync();
|
|
5692
5860
|
const G = g.length + 1, D = (A.__heap_base.value || A.__heap_base) + 4 * G - A.memory.buffer.byteLength;
|
|
5693
5861
|
D > 0 && A.memory.grow(Math.ceil(D / 65536));
|
|
@@ -5866,11 +6034,11 @@ function initSync() {
|
|
|
5866
6034
|
import { readFileSync as readFileSync2 } from "fs";
|
|
5867
6035
|
|
|
5868
6036
|
// src/rsc/build/paths.ts
|
|
5869
|
-
import { dirname as
|
|
6037
|
+
import { dirname as dirname6, join as join7 } from "path";
|
|
5870
6038
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
5871
|
-
var SOURCE_DIR =
|
|
5872
|
-
var CLIENT_REFERENCE_RUNTIME_PATH =
|
|
5873
|
-
var BUNDLED_CLIENT_CODEC_PATH =
|
|
6039
|
+
var SOURCE_DIR = dirname6(fileURLToPath3(import.meta.resolve("@teyik0/furin/rsc")));
|
|
6040
|
+
var CLIENT_REFERENCE_RUNTIME_PATH = join7(SOURCE_DIR, "rsc/client-references.ts");
|
|
6041
|
+
var BUNDLED_CLIENT_CODEC_PATH = join7(SOURCE_DIR, "rsc/bundled-client-codec.ts");
|
|
5874
6042
|
|
|
5875
6043
|
// src/rsc/build/flight-loader.ts
|
|
5876
6044
|
var CLIENT_CODEC = /react-server-dom-webpack-client\.(?:edge|browser)\.(?:development|production)\.js$/;
|
|
@@ -5991,7 +6159,7 @@ function clientReferencesPlugin(references) {
|
|
|
5991
6159
|
contents: isCommonJsModule(source, sourcePath) ? source : `${source}
|
|
5992
6160
|
${clientRegistration(sourcePath, path, prefix, references)}`,
|
|
5993
6161
|
loader: detectLoaderFromPath(sourcePath),
|
|
5994
|
-
resolveDir:
|
|
6162
|
+
resolveDir: dirname7(sourcePath)
|
|
5995
6163
|
};
|
|
5996
6164
|
});
|
|
5997
6165
|
build.onLoad({ filter: SCRIPTS }, async ({ path }) => {
|
|
@@ -6008,7 +6176,7 @@ registerClientModule(${JSON.stringify(clientModuleId(path))}, implementation);`
|
|
|
6008
6176
|
export * from ${JSON.stringify(path + IMPLEMENTATION)};
|
|
6009
6177
|
${names.length > 0 ? `export { ${names.map((name) => JSON.stringify(name)).join(", ")} } from ${JSON.stringify(path + IMPLEMENTATION)};` : ""}`,
|
|
6010
6178
|
loader: "js",
|
|
6011
|
-
resolveDir:
|
|
6179
|
+
resolveDir: dirname7(path)
|
|
6012
6180
|
};
|
|
6013
6181
|
});
|
|
6014
6182
|
}
|
|
@@ -6022,7 +6190,7 @@ function commonJsExports(source, path) {
|
|
|
6022
6190
|
withoutImports.remove(statement.start, statement.end);
|
|
6023
6191
|
}
|
|
6024
6192
|
}
|
|
6025
|
-
return
|
|
6193
|
+
return parse2(withoutImports.toString());
|
|
6026
6194
|
}
|
|
6027
6195
|
async function exportedNames(source, path, visited) {
|
|
6028
6196
|
if (visited.has(path)) {
|
|
@@ -6047,7 +6215,7 @@ async function exportedNames(source, path, visited) {
|
|
|
6047
6215
|
}
|
|
6048
6216
|
}
|
|
6049
6217
|
for (const specifier of reexports) {
|
|
6050
|
-
const dependency = Bun.resolveSync(specifier,
|
|
6218
|
+
const dependency = Bun.resolveSync(specifier, dirname7(path));
|
|
6051
6219
|
const exported = await exportedNames(await Bun.file(dependency).text(), dependency, visited);
|
|
6052
6220
|
for (const name of exported) {
|
|
6053
6221
|
if (name !== "default") {
|
|
@@ -6151,7 +6319,7 @@ ${codecResult.logs.map((log) => log.message).join(`
|
|
|
6151
6319
|
}
|
|
6152
6320
|
async function buildRscGraph(apps, outDir, buildId, userPlugins, external) {
|
|
6153
6321
|
await assertInstalledRscVersions();
|
|
6154
|
-
const graphDir =
|
|
6322
|
+
const graphDir = join8(outDir, "rsc");
|
|
6155
6323
|
mkdirSync2(graphDir, { recursive: true });
|
|
6156
6324
|
const rscEntry = fileURLToPath5(import.meta.resolve("../../rsc-server.tsx"));
|
|
6157
6325
|
const entrypoints = [
|
|
@@ -6205,13 +6373,13 @@ ${result.logs.map((log) => log.message).join(`
|
|
|
6205
6373
|
clientReferences: referencedClientExports(clientReferences, result.metafile),
|
|
6206
6374
|
css
|
|
6207
6375
|
};
|
|
6208
|
-
writeFileSync3(
|
|
6376
|
+
writeFileSync3(join8(graphDir, "manifest.json"), JSON.stringify(manifest, null, 2));
|
|
6209
6377
|
return manifest;
|
|
6210
6378
|
}
|
|
6211
6379
|
|
|
6212
6380
|
// src/adapter/prerender.ts
|
|
6213
6381
|
import { readFileSync as readFileSync3, rmSync as rmSync2 } from "fs";
|
|
6214
|
-
import { join as
|
|
6382
|
+
import { join as join9 } from "path";
|
|
6215
6383
|
import { pathToFileURL as pathToFileURL2 } from "url";
|
|
6216
6384
|
function prerenderScript(module, render, resultPath) {
|
|
6217
6385
|
const href = JSON.stringify(pathToFileURL2(module.path).href);
|
|
@@ -6230,7 +6398,7 @@ process.exit(0);
|
|
|
6230
6398
|
`;
|
|
6231
6399
|
}
|
|
6232
6400
|
async function runBundleScript(script, cwd, failure) {
|
|
6233
|
-
const resultPath =
|
|
6401
|
+
const resultPath = join9(cwd, ".furin", "build", `prerender-${crypto.randomUUID()}.json`);
|
|
6234
6402
|
const child = Bun.spawn([process.execPath, "-e", script(resultPath)], {
|
|
6235
6403
|
cwd,
|
|
6236
6404
|
env: { ...process.env, NODE_ENV: "production" },
|
|
@@ -6263,20 +6431,20 @@ function exportStaticFromBundle(path, cwd, options) {
|
|
|
6263
6431
|
// src/adapter/runtime-build.ts
|
|
6264
6432
|
import { existsSync as existsSync10, realpathSync as realpathSync4, writeFileSync as writeFileSync6 } from "fs";
|
|
6265
6433
|
import { createRequire } from "module";
|
|
6266
|
-
import { dirname as
|
|
6434
|
+
import { dirname as dirname11, isAbsolute as isAbsolute5, join as join12, relative as relative5, resolve as resolve7 } from "path";
|
|
6267
6435
|
import { fileURLToPath as fileURLToPath7 } from "url";
|
|
6268
6436
|
|
|
6269
6437
|
// src/build/client.ts
|
|
6270
6438
|
import { existsSync as existsSync9, mkdirSync as mkdirSync3 } from "fs";
|
|
6271
|
-
import { basename as basename4, dirname as
|
|
6439
|
+
import { basename as basename4, dirname as dirname10, join as join11, sep as sep2 } from "path";
|
|
6272
6440
|
import { fileURLToPath as fileURLToPath6 } from "url";
|
|
6273
6441
|
|
|
6274
6442
|
// src/plugin/client-plugin.ts
|
|
6275
|
-
import { dirname as
|
|
6443
|
+
import { dirname as dirname9, isAbsolute as isAbsolute4, resolve as resolve4 } from "path";
|
|
6276
6444
|
|
|
6277
6445
|
// src/plugin/hmr-dependencies.ts
|
|
6278
6446
|
import { readFileSync as readFileSync4 } from "fs";
|
|
6279
|
-
import { dirname as
|
|
6447
|
+
import { dirname as dirname8, isAbsolute as isAbsolute3, resolve as resolve3 } from "path";
|
|
6280
6448
|
function hmrDependencySignature(imports, filename) {
|
|
6281
6449
|
const routePath = resolve3(filename);
|
|
6282
6450
|
const visited = new Set;
|
|
@@ -6285,7 +6453,7 @@ function hmrDependencySignature(imports, filename) {
|
|
|
6285
6453
|
if (specifier === "furin" || specifier.startsWith("furin/") || specifier === "@teyik0/furin" || specifier.startsWith("@teyik0/furin/")) {
|
|
6286
6454
|
return true;
|
|
6287
6455
|
}
|
|
6288
|
-
const path = Bun.resolveSync(specifier,
|
|
6456
|
+
const path = Bun.resolveSync(specifier, dirname8(importer));
|
|
6289
6457
|
if (path === routePath) {
|
|
6290
6458
|
return false;
|
|
6291
6459
|
}
|
|
@@ -7149,11 +7317,12 @@ function stripServerCode(path, source) {
|
|
|
7149
7317
|
var ELYSIA_FILTER = /^elysia$/;
|
|
7150
7318
|
var BUN_BUILTIN_FILTER = /^bun:/;
|
|
7151
7319
|
var ANY_FILTER = /.*/;
|
|
7152
|
-
var
|
|
7320
|
+
var elysiaStub = (typeModule) => `export * as t from ${JSON.stringify(typeModule)};
|
|
7153
7321
|
export class NotFoundError extends Error { constructor(m) { super(m); this.name = "NotFoundError"; } }
|
|
7154
7322
|
export class ValidationError extends Error { constructor(m) { super(m); this.name = "ValidationError"; } }
|
|
7155
7323
|
export default {};
|
|
7156
7324
|
`;
|
|
7325
|
+
var ELYSIA_STUB_PREFIX = "elysia-stub:";
|
|
7157
7326
|
function trackHydrationTopology(filePath, source, topologyPaths) {
|
|
7158
7327
|
const normalizedPath = filePath.replaceAll("\\", "/");
|
|
7159
7328
|
if (!(normalizedPath.includes("/.furin/") && normalizedPath.endsWith("/_hydrate.tsx"))) {
|
|
@@ -7162,7 +7331,7 @@ function trackHydrationTopology(filePath, source, topologyPaths) {
|
|
|
7162
7331
|
const transpiler = new Bun.Transpiler({ loader: "tsx" });
|
|
7163
7332
|
for (const imported of transpiler.scanImports(source)) {
|
|
7164
7333
|
if (isAbsolute4(imported.path) || imported.path.startsWith(".")) {
|
|
7165
|
-
topologyPaths.add(resolve4(
|
|
7334
|
+
topologyPaths.add(resolve4(dirname9(filePath), imported.path.split("?")[0]));
|
|
7166
7335
|
}
|
|
7167
7336
|
}
|
|
7168
7337
|
}
|
|
@@ -7191,16 +7360,16 @@ function createClientStripPlugin({ mode }) {
|
|
|
7191
7360
|
environmentGuardPlugin("client").setup(build);
|
|
7192
7361
|
const topologyPaths = new Set;
|
|
7193
7362
|
const loadedSources = new Map;
|
|
7194
|
-
build.onResolve({ filter: ELYSIA_FILTER }, () => ({
|
|
7363
|
+
build.onResolve({ filter: ELYSIA_FILTER }, (args) => ({
|
|
7195
7364
|
namespace: "furin-stubs",
|
|
7196
|
-
path: "elysia
|
|
7365
|
+
path: ELYSIA_STUB_PREFIX + Bun.resolveSync("elysia/type", args.resolveDir)
|
|
7197
7366
|
}));
|
|
7198
7367
|
build.onResolve({ filter: BUN_BUILTIN_FILTER }, () => ({
|
|
7199
7368
|
namespace: "furin-stubs",
|
|
7200
7369
|
path: "bun-builtin-stub"
|
|
7201
7370
|
}));
|
|
7202
7371
|
build.onLoad({ filter: ANY_FILTER, namespace: "furin-stubs" }, (args) => ({
|
|
7203
|
-
contents: args.path
|
|
7372
|
+
contents: args.path.startsWith(ELYSIA_STUB_PREFIX) ? elysiaStub(args.path.slice(ELYSIA_STUB_PREFIX.length)) : "",
|
|
7204
7373
|
loader: "js"
|
|
7205
7374
|
}));
|
|
7206
7375
|
build.onLoad({ filter: SCRIPT_FILE_FILTER }, async (args) => {
|
|
@@ -7430,7 +7599,7 @@ ${buildIdMeta}${modeMeta}${faviconLink}${cssLinks ? `${cssLinks}
|
|
|
7430
7599
|
|
|
7431
7600
|
// src/build/route-types.ts
|
|
7432
7601
|
import { existsSync as existsSync7, readFileSync as readFileSync5, renameSync as renameSync2, writeFileSync as writeFileSync4 } from "fs";
|
|
7433
|
-
import { extname as extname2, join as
|
|
7602
|
+
import { extname as extname2, join as join10, relative as relative4, resolve as resolve5 } from "path";
|
|
7434
7603
|
|
|
7435
7604
|
// src/shared/route-map.ts
|
|
7436
7605
|
function compareCodeUnits(left, right) {
|
|
@@ -7469,38 +7638,19 @@ function tagToStringLiteral(tag) {
|
|
|
7469
7638
|
function importSpecifier(path, projectRoot) {
|
|
7470
7639
|
const extension = extname2(path);
|
|
7471
7640
|
const sourcePath = extension ? path.slice(0, -extension.length) : path;
|
|
7472
|
-
const relativePath =
|
|
7641
|
+
const relativePath = relative4(projectRoot, sourcePath).replaceAll("\\", "/");
|
|
7473
7642
|
return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
7474
7643
|
}
|
|
7475
|
-
function fileRouteEntries(
|
|
7476
|
-
const
|
|
7477
|
-
const
|
|
7478
|
-
|
|
7479
|
-
const
|
|
7480
|
-
const
|
|
7481
|
-
return { base, path, relativePath, segments };
|
|
7482
|
-
});
|
|
7483
|
-
const layouts = new Map(files.filter(({ base }) => base === "_route").map((file) => [file.segments.join("/"), file.path]));
|
|
7484
|
-
return files.map(({ base, path, relativePath, segments }) => {
|
|
7485
|
-
const isLayout = base === "_route";
|
|
7486
|
-
let parent = join11(pages, "root.tsx");
|
|
7487
|
-
for (let depth = isLayout ? segments.length - 1 : segments.length;depth > 0; depth -= 1) {
|
|
7488
|
-
const layout = layouts.get(segments.slice(0, depth).join("/"));
|
|
7489
|
-
if (layout) {
|
|
7490
|
-
parent = layout;
|
|
7491
|
-
break;
|
|
7492
|
-
}
|
|
7493
|
-
}
|
|
7494
|
-
const pathParams = [...segments, base].flatMap((segment) => {
|
|
7495
|
-
const dynamic = parseDynamicRouteSegment(segment, path);
|
|
7496
|
-
return dynamic ? [dynamic.catchAll ? '"*": string' : `${dynamic.name}: string`] : [];
|
|
7497
|
-
});
|
|
7498
|
-
const id = fileRouteId({ pagesDir: pages, prefix }, path);
|
|
7499
|
-
const pattern = filePathToPattern(isLayout ? segments.concat("index").join("/") : relativePath);
|
|
7644
|
+
function fileRouteEntries(instance, projectRoot) {
|
|
7645
|
+
const { prefix } = instance;
|
|
7646
|
+
const manifest = scanRouteManifest({ ...instance, pagesDir: resolve5(instance.pagesDir) });
|
|
7647
|
+
return manifest.routes.map(({ id, kind, params, parentPath, pattern }) => {
|
|
7648
|
+
const parent = parentPath ?? manifest.rootPath;
|
|
7649
|
+
const pathParams = params.map(({ name, optional }) => `${name}${optional ? "?" : ""}: string`);
|
|
7500
7650
|
return {
|
|
7501
7651
|
id,
|
|
7502
7652
|
lines: ` ${JSON.stringify(id)}: {
|
|
7503
|
-
kind: "${
|
|
7653
|
+
kind: "${kind}";
|
|
7504
7654
|
pattern: ${JSON.stringify(`${prefix}${pattern === "/" ? "" : pattern}` || "/")};
|
|
7505
7655
|
parent: typeof import(${JSON.stringify(importSpecifier(parent, projectRoot))}).route;
|
|
7506
7656
|
pathParams: {${pathParams.length > 0 ? ` ${pathParams.join("; ")} ` : ""}};
|
|
@@ -7539,7 +7689,7 @@ import "@teyik0/furin/routes";
|
|
|
7539
7689
|
|
|
7540
7690
|
${apps === undefined ? "" : fileRoutesDeclaration(apps, projectRoot)}${routeMapDeclaration(entries)}${tagBlock}
|
|
7541
7691
|
`;
|
|
7542
|
-
const typesPath =
|
|
7692
|
+
const typesPath = join10(projectRoot, "furin-env.d.ts");
|
|
7543
7693
|
const existing = existsSync7(typesPath) ? readFileSync5(typesPath, "utf8") : "";
|
|
7544
7694
|
if (content === existing) {
|
|
7545
7695
|
return false;
|
|
@@ -7602,11 +7752,13 @@ function hydrateEntry(routes, rootLayout, basePath, clientLogging, modulePathKey
|
|
|
7602
7752
|
continue;
|
|
7603
7753
|
}
|
|
7604
7754
|
const parts = [`depth: ${seg.depth}`];
|
|
7755
|
+
const errorExport = seg.fromRoute ? "route.errorComponent" : "default";
|
|
7756
|
+
const notFoundExport = seg.fromRoute ? "route.notFoundComponent" : "default";
|
|
7605
7757
|
if (errorIdent) {
|
|
7606
|
-
parts.push(`error: ${errorIdent}
|
|
7758
|
+
parts.push(`error: ${errorIdent}.${errorExport}`);
|
|
7607
7759
|
}
|
|
7608
7760
|
if (notFoundIdent) {
|
|
7609
|
-
parts.push(`notFound: ${notFoundIdent}
|
|
7761
|
+
parts.push(`notFound: ${notFoundIdent}.${notFoundExport}`);
|
|
7610
7762
|
}
|
|
7611
7763
|
if (seg.depth === 0 && seg.path.replaceAll("\\", "/") !== rootDirectory) {
|
|
7612
7764
|
parts.push("isRoot: false");
|
|
@@ -7871,6 +8023,7 @@ if (__deferred && __deferred._chunks) {
|
|
|
7871
8023
|
// with the server (stale deploy) or the server returned something we
|
|
7872
8024
|
// don't know how to hydrate. Bail loudly; the page stays static.
|
|
7873
8025
|
log.error({ action: "hydrate_no_match", pathname });
|
|
8026
|
+
if (import.meta.hot) throw new Error(\`[furin] No client route matches \${pathname}; the page stays static.\`);
|
|
7874
8027
|
return;
|
|
7875
8028
|
}
|
|
7876
8029
|
app = createElement(DocumentProvider, { value: documentState }, app);
|
|
@@ -7937,6 +8090,7 @@ if (__deferred && __deferred._chunks) {
|
|
|
7937
8090
|
log.info({ action: "hydrate_complete", pathname });
|
|
7938
8091
|
})().catch((err: unknown) => {
|
|
7939
8092
|
log.error({ action: "hydrate_failed", pathname, error: String(err) });
|
|
8093
|
+
if (import.meta.hot) console.error("[furin] Hydration failed:", err);
|
|
7940
8094
|
window.dispatchEvent(
|
|
7941
8095
|
new CustomEvent("furin:client-error", { detail: { error: err, phase: "hydrate" } })
|
|
7942
8096
|
);
|
|
@@ -8001,7 +8155,7 @@ function writeClientPreloadManifest(metafile, outputPaths, entryChunkPath, route
|
|
|
8001
8155
|
}
|
|
8002
8156
|
|
|
8003
8157
|
// src/build/client.ts
|
|
8004
|
-
var CLIENT_DIST_DIR = `${
|
|
8158
|
+
var CLIENT_DIST_DIR = `${join11(dirname10(dirname10(fileURLToPath6(import.meta.resolve("@teyik0/furin")))), "dist")}${sep2}`;
|
|
8005
8159
|
async function buildClient(routes, {
|
|
8006
8160
|
outDir,
|
|
8007
8161
|
rootLayout,
|
|
@@ -8014,11 +8168,11 @@ async function buildClient(routes, {
|
|
|
8014
8168
|
metafilePath,
|
|
8015
8169
|
optimizeImports,
|
|
8016
8170
|
reactCompiler,
|
|
8017
|
-
|
|
8171
|
+
pages,
|
|
8018
8172
|
routeRegistry
|
|
8019
8173
|
}) {
|
|
8020
8174
|
const dirName = clientDirName ?? "client";
|
|
8021
|
-
const clientDir =
|
|
8175
|
+
const clientDir = join11(outDir, dirName);
|
|
8022
8176
|
if (!existsSync9(outDir)) {
|
|
8023
8177
|
mkdirSync3(outDir, { recursive: true });
|
|
8024
8178
|
}
|
|
@@ -8027,7 +8181,7 @@ async function buildClient(routes, {
|
|
|
8027
8181
|
}
|
|
8028
8182
|
const boundaries = await discoverClientBoundaries([...new Set([rootLayout, ...routes.flatMap((route) => [route.path, ...route.routeChain.flatMap((entry) => entry.sourcePath ? [entry.sourcePath] : [])])])], plugins);
|
|
8029
8183
|
const hydrateCode = generateClientReferenceEntry(boundaries) + generateProductionHydrateEntry(routes, rootLayout, basePath, clientLogging);
|
|
8030
|
-
const hydratePath =
|
|
8184
|
+
const hydratePath = join11(outDir, dirName === "client" ? "_hydrate.tsx" : `_hydrate-${dirName}.tsx`);
|
|
8031
8185
|
const hydrateEntry = createVirtualBuildEntry(hydratePath, hydrateCode, "tsx");
|
|
8032
8186
|
console.log("[furin] Building production client bundle\u2026");
|
|
8033
8187
|
const routerLoggerPlugin = {
|
|
@@ -8067,7 +8221,7 @@ async function buildClient(routes, {
|
|
|
8067
8221
|
hydrateEntry.plugin,
|
|
8068
8222
|
...plugins ?? [],
|
|
8069
8223
|
...!clientLogging ? [routerLoggerPlugin] : [],
|
|
8070
|
-
...
|
|
8224
|
+
...pages ? [createRoutesPlugin({ instances: [{ ...pages, prefix: basePath, routeRegistry }], target: "client" })] : [],
|
|
8071
8225
|
createClientStripPlugin({ mode: "build" })
|
|
8072
8226
|
],
|
|
8073
8227
|
define: {
|
|
@@ -8104,11 +8258,11 @@ async function buildClient(routes, {
|
|
|
8104
8258
|
}
|
|
8105
8259
|
|
|
8106
8260
|
// src/adapter/runtime-build.ts
|
|
8107
|
-
var _pkgRoot2 =
|
|
8108
|
-
var _pkgSrcDir2 = existsSync10(
|
|
8261
|
+
var _pkgRoot2 = dirname11(dirname11(fileURLToPath7(import.meta.resolve("@teyik0/furin"))));
|
|
8262
|
+
var _pkgSrcDir2 = existsSync10(join12(_pkgRoot2, "src", "furin.ts")) ? join12(_pkgRoot2, "src") : join12(_pkgRoot2, "dist");
|
|
8109
8263
|
var _ext2 = ".ts";
|
|
8110
8264
|
function frameworkSourceModule(path) {
|
|
8111
|
-
return
|
|
8265
|
+
return join12(_pkgRoot2, "src", path);
|
|
8112
8266
|
}
|
|
8113
8267
|
var PPR_ROUTE_IMPORT_RE = /ppr-route(?:\.ts)?$/;
|
|
8114
8268
|
var MIXED_CACHE_IMPORT_RE = /mixed-cache(?:\.ts)?$/;
|
|
@@ -8161,12 +8315,12 @@ function nearestFingerprintFile(directory, names, boundary) {
|
|
|
8161
8315
|
let current = directory;
|
|
8162
8316
|
while (current !== undefined) {
|
|
8163
8317
|
for (const name of names) {
|
|
8164
|
-
const path =
|
|
8318
|
+
const path = join12(current, name);
|
|
8165
8319
|
if (existsSync10(path)) {
|
|
8166
8320
|
return path;
|
|
8167
8321
|
}
|
|
8168
8322
|
}
|
|
8169
|
-
const parent =
|
|
8323
|
+
const parent = dirname11(current);
|
|
8170
8324
|
current = parent === current || current === boundary ? undefined : parent;
|
|
8171
8325
|
}
|
|
8172
8326
|
return;
|
|
@@ -8219,9 +8373,9 @@ async function createBuildFingerprint(entryChunk, cssChunks, routes, root, serve
|
|
|
8219
8373
|
if (!isScript) {
|
|
8220
8374
|
return;
|
|
8221
8375
|
}
|
|
8222
|
-
const relativePath = toPosixPath(
|
|
8376
|
+
const relativePath = toPosixPath(relative5(rootBoundary, path));
|
|
8223
8377
|
const manifestBoundary = relativePath === ".." || relativePath.startsWith("../") || isAbsolute5(relativePath) ? undefined : rootBoundary;
|
|
8224
|
-
const manifest = nearestFingerprintFile(
|
|
8378
|
+
const manifest = nearestFingerprintFile(dirname11(path), ["package.json"], manifestBoundary);
|
|
8225
8379
|
if (manifest) {
|
|
8226
8380
|
fingerprintPaths.add(manifest);
|
|
8227
8381
|
await visit(manifest);
|
|
@@ -8230,7 +8384,7 @@ async function createBuildFingerprint(entryChunk, cssChunks, routes, root, serve
|
|
|
8230
8384
|
await Promise.all(transpiler.scanImports(content).flatMap(({ path: specifier, kind }) => {
|
|
8231
8385
|
let dependency;
|
|
8232
8386
|
try {
|
|
8233
|
-
dependency = kind === "require-call" || kind === "require-resolve" ? createRequire(path).resolve(specifier) : Bun.resolveSync(specifier,
|
|
8387
|
+
dependency = kind === "require-call" || kind === "require-resolve" ? createRequire(path).resolve(specifier) : Bun.resolveSync(specifier, dirname11(path));
|
|
8234
8388
|
} catch {
|
|
8235
8389
|
return [];
|
|
8236
8390
|
}
|
|
@@ -8268,11 +8422,11 @@ function stableFingerprintPath(path, projectRoot) {
|
|
|
8268
8422
|
if (dependencyStart !== -1) {
|
|
8269
8423
|
return `dependency/${posixPath.slice(dependencyStart + "/node_modules/".length)}`;
|
|
8270
8424
|
}
|
|
8271
|
-
const projectPath =
|
|
8425
|
+
const projectPath = relative5(realpathSync4(projectRoot), absolutePath);
|
|
8272
8426
|
if (!isAbsolute5(projectPath) && projectPath !== ".." && !projectPath.startsWith("../") && !projectPath.startsWith("..\\")) {
|
|
8273
8427
|
return `app/${toPosixPath(projectPath)}`;
|
|
8274
8428
|
}
|
|
8275
|
-
const frameworkPath =
|
|
8429
|
+
const frameworkPath = relative5(_pkgRoot2, absolutePath);
|
|
8276
8430
|
if (!isAbsolute5(frameworkPath) && frameworkPath !== ".." && !frameworkPath.startsWith("../") && !frameworkPath.startsWith("..\\")) {
|
|
8277
8431
|
return `furin/${toPosixPath(frameworkPath)}`;
|
|
8278
8432
|
}
|
|
@@ -8286,11 +8440,13 @@ function buildCompileMetadata(root, routes) {
|
|
|
8286
8440
|
const routeMetadata = {};
|
|
8287
8441
|
for (const route of routes) {
|
|
8288
8442
|
routeMetadata[toPosixPath(route.path)] = {
|
|
8443
|
+
layouts: route.layouts.map((layout) => ({ ...layout, path: toPosixPath(layout.path) })),
|
|
8289
8444
|
requestKeys: route.requestKeys,
|
|
8290
8445
|
requestKeysByLoader: route.requestKeysByLoader,
|
|
8291
8446
|
segmentBoundaries: route.segmentBoundaries.map((boundary) => ({
|
|
8292
8447
|
depth: boundary.depth,
|
|
8293
8448
|
errorPath: boundary.errorPath ? toPosixPath(boundary.errorPath) : undefined,
|
|
8449
|
+
...boundary.fromRoute ? { fromRoute: boundary.fromRoute } : {},
|
|
8294
8450
|
notFoundPath: boundary.notFoundPath ? toPosixPath(boundary.notFoundPath) : undefined,
|
|
8295
8451
|
path: toPosixPath(boundary.path)
|
|
8296
8452
|
}))
|
|
@@ -8312,7 +8468,7 @@ function pprRuntimePlugin(apps) {
|
|
|
8312
8468
|
return;
|
|
8313
8469
|
}
|
|
8314
8470
|
build.onResolve({ filter: PPR_ROUTE_IMPORT_RE }, ({ path, importer }) => {
|
|
8315
|
-
const absolute = resolve7(
|
|
8471
|
+
const absolute = resolve7(dirname11(importer.split("?")[0]), path);
|
|
8316
8472
|
if (absolute !== pprPath && `${absolute}.ts` !== pprPath) {
|
|
8317
8473
|
return;
|
|
8318
8474
|
}
|
|
@@ -8338,7 +8494,7 @@ function mixedRuntimePlugin(apps) {
|
|
|
8338
8494
|
return;
|
|
8339
8495
|
}
|
|
8340
8496
|
build.onResolve({ filter: MIXED_CACHE_IMPORT_RE }, ({ path, importer }) => {
|
|
8341
|
-
const absolute = resolve7(
|
|
8497
|
+
const absolute = resolve7(dirname11(importer.split("?")[0]), path);
|
|
8342
8498
|
if (absolute !== mixedPath && `${absolute}.ts` !== mixedPath) {
|
|
8343
8499
|
return;
|
|
8344
8500
|
}
|
|
@@ -8356,7 +8512,7 @@ function isFrameworkRuntimeImporter(importer) {
|
|
|
8356
8512
|
if (importer === "") {
|
|
8357
8513
|
return false;
|
|
8358
8514
|
}
|
|
8359
|
-
const fromRuntimeRoot =
|
|
8515
|
+
const fromRuntimeRoot = relative5(_pkgSrcDir2, importer.split("?")[0]);
|
|
8360
8516
|
return fromRuntimeRoot !== ".." && !fromRuntimeRoot.startsWith("../") && !fromRuntimeRoot.startsWith("..\\");
|
|
8361
8517
|
}
|
|
8362
8518
|
async function buildRuntimeApp(app, projectRoot, targetDir, serverEntry, options, targetName) {
|
|
@@ -8368,10 +8524,10 @@ async function buildRuntimeApp(app, projectRoot, targetDir, serverEntry, options
|
|
|
8368
8524
|
basePath: prefix,
|
|
8369
8525
|
clientDirName,
|
|
8370
8526
|
clientLogging: options.clientLogging ?? false,
|
|
8371
|
-
metafilePath: options.analyze ?
|
|
8527
|
+
metafilePath: options.analyze ? join12(dirname11(targetDir), "analysis", `${targetName}-${clientDirName}.json`) : undefined,
|
|
8372
8528
|
optimizeImports: options.optimizeImports,
|
|
8373
8529
|
outDir: targetDir,
|
|
8374
|
-
pagesDir: app.pagesDir,
|
|
8530
|
+
pages: { pagesDir: app.pagesDir, style: app.style },
|
|
8375
8531
|
routeRegistry: app.routeRegistry,
|
|
8376
8532
|
plugins: options.plugins,
|
|
8377
8533
|
preloadRouteChunks: options.preload?.routeChunks,
|
|
@@ -8382,9 +8538,9 @@ async function buildRuntimeApp(app, projectRoot, targetDir, serverEntry, options
|
|
|
8382
8538
|
const buildFingerprint = await createBuildFingerprint(`${prefix}
|
|
8383
8539
|
${entryChunk}`, cssChunks, routes, root, serverEntry, modulePaths, projectRoot);
|
|
8384
8540
|
const buildId = Bun.hash(buildFingerprint).toString(16).slice(0, 12);
|
|
8385
|
-
const clientDir =
|
|
8541
|
+
const clientDir = join12(targetDir, clientDirName);
|
|
8386
8542
|
const indexHtml = generateProdIndexHtml(entryChunk, cssChunks, buildId, undefined, false);
|
|
8387
|
-
writeFileSync6(
|
|
8543
|
+
writeFileSync6(join12(clientDir, "index.html"), indexHtml);
|
|
8388
8544
|
const { rootConventions, routeMetadata } = buildCompileMetadata(root, routes);
|
|
8389
8545
|
console.log(`[furin] Built ${label} (buildId ${buildId})`);
|
|
8390
8546
|
return {
|
|
@@ -8411,16 +8567,16 @@ ${entryChunk}`, cssChunks, routes, root, serverEntry, modulePaths, projectRoot);
|
|
|
8411
8567
|
}
|
|
8412
8568
|
|
|
8413
8569
|
// src/adapter/server-bundle.ts
|
|
8414
|
-
import { dirname as
|
|
8570
|
+
import { dirname as dirname14, relative as relative8 } from "path";
|
|
8415
8571
|
|
|
8416
8572
|
// src/build/elysia-aot.ts
|
|
8417
8573
|
import { fork } from "child_process";
|
|
8418
8574
|
import { existsSync as existsSync11, realpathSync as realpathSync5 } from "fs";
|
|
8419
|
-
import { dirname as
|
|
8575
|
+
import { dirname as dirname12, join as join13, relative as relative6, resolve as resolve8 } from "path";
|
|
8420
8576
|
import { fileURLToPath as fileURLToPath8 } from "url";
|
|
8421
8577
|
var AOT_NAMESPACE = "furin-elysia-aot";
|
|
8422
|
-
var ELYSIA_RESOLVE_DIR =
|
|
8423
|
-
var AOT_PROCESS_PATH =
|
|
8578
|
+
var ELYSIA_RESOLVE_DIR = dirname12(Bun.resolveSync("elysia", import.meta.dir));
|
|
8579
|
+
var AOT_PROCESS_PATH = join13(dirname12(dirname12(fileURLToPath8(import.meta.resolve("@teyik0/furin")))), "src/build/elysia-aot-worker.ts");
|
|
8424
8580
|
var SOURCE_FILTER = /\.[cm]?[jt]sx?$/;
|
|
8425
8581
|
var ELYSIA_IMPORT_FILTER = /^elysia(?:\/(?!compiled$|type$).*)?$/;
|
|
8426
8582
|
var ELYSIA_VIRTUAL_IMPORT_FILTER = /^elysia\/(?:compiled|type)$/;
|
|
@@ -8450,10 +8606,10 @@ export function drainWaiters(){return e()}
|
|
|
8450
8606
|
export function handleWSResponse(){return e()}
|
|
8451
8607
|
`;
|
|
8452
8608
|
}
|
|
8453
|
-
function mountLabel(rootDir, { pagesDir, prefix }) {
|
|
8609
|
+
function mountLabel(rootDir, { pagesDir, prefix, style }) {
|
|
8454
8610
|
const absolute = resolve8(rootDir, pagesDir);
|
|
8455
8611
|
const path = existsSync11(absolute) ? realpathSync5(absolute) : absolute;
|
|
8456
|
-
return `prefix ${JSON.stringify(prefix || "/")} (pagesDir ${
|
|
8612
|
+
return `prefix ${JSON.stringify(prefix || "/")} (pagesDir ${relative6(rootDir, path) || "."}, style ${style})`;
|
|
8457
8613
|
}
|
|
8458
8614
|
function registrationMismatch(build, registrations, evaluated) {
|
|
8459
8615
|
const root = realpathSync5(build.rootDir);
|
|
@@ -8614,7 +8770,7 @@ function elysiaAot(entry, expected) {
|
|
|
8614
8770
|
}
|
|
8615
8771
|
|
|
8616
8772
|
// src/build/production-instrumentation.ts
|
|
8617
|
-
import { dirname as
|
|
8773
|
+
import { dirname as dirname13, relative as relative7, resolve as resolve9 } from "path";
|
|
8618
8774
|
var INSTRUMENTATION_IMPORT = /(?:^|[/\\])devtools[/\\]instrumentation(?:\.ts|\.js)?$/;
|
|
8619
8775
|
var DEV_PAGE_PLUGIN_IMPORT = /(?:^|[/\\])server[/\\]dev-page-plugin(?:\.ts|\.js)?$/;
|
|
8620
8776
|
var DEV_RUNTIME_IMPORT = /(?:^|[/\\])server[/\\]dev[/\\](?:browser-events|diagnostics|graph|plugin|runtime)(?:\.ts|\.js)?$/;
|
|
@@ -8624,7 +8780,7 @@ var PRODUCTION_BOUNDARY_IMPORT = /(?:browser-events|instrumentation|dev-page-plu
|
|
|
8624
8780
|
var PRODUCTION_STUB_NAMESPACE = "furin-production-runtime-stub";
|
|
8625
8781
|
var FURIN_RUNTIME_ROOT = resolve9(import.meta.dir, "..");
|
|
8626
8782
|
function isFurinRuntimePath(path) {
|
|
8627
|
-
const fromRuntimeRoot =
|
|
8783
|
+
const fromRuntimeRoot = relative7(FURIN_RUNTIME_ROOT, path);
|
|
8628
8784
|
return fromRuntimeRoot !== ".." && !fromRuntimeRoot.startsWith("../") && !fromRuntimeRoot.startsWith("..\\");
|
|
8629
8785
|
}
|
|
8630
8786
|
function devBuildExports(path) {
|
|
@@ -8641,7 +8797,7 @@ function productionInstrumentationPlugin() {
|
|
|
8641
8797
|
name: "furin-production-instrumentation",
|
|
8642
8798
|
setup(build) {
|
|
8643
8799
|
build.onResolve({ filter: PRODUCTION_BOUNDARY_IMPORT }, (args) => {
|
|
8644
|
-
const importPath = resolve9(
|
|
8800
|
+
const importPath = resolve9(dirname13(args.importer), args.path);
|
|
8645
8801
|
if (!isFurinRuntimePath(importPath)) {
|
|
8646
8802
|
return;
|
|
8647
8803
|
}
|
|
@@ -8677,12 +8833,12 @@ var PRERENDER_SNAPSHOT_RE = /^\.\/furin-prerender\.json$/;
|
|
|
8677
8833
|
var ELYSIA_STATIC_IMPORT_RE = /^@elysia\/static$/;
|
|
8678
8834
|
var MATCH_ALL_RE = /.*/;
|
|
8679
8835
|
var STATIC_STUB_NAMESPACE = "furin-platform-assets-stub";
|
|
8680
|
-
var FURIN_RUNTIME_ROOT2 =
|
|
8836
|
+
var FURIN_RUNTIME_ROOT2 = dirname14(import.meta.dir);
|
|
8681
8837
|
function isFurinRuntimeImporter(importer) {
|
|
8682
8838
|
if (importer === "") {
|
|
8683
8839
|
return false;
|
|
8684
8840
|
}
|
|
8685
|
-
const fromRuntimeRoot =
|
|
8841
|
+
const fromRuntimeRoot = relative8(FURIN_RUNTIME_ROOT2, importer.split("?")[0]);
|
|
8686
8842
|
return fromRuntimeRoot !== ".." && !fromRuntimeRoot.startsWith("../") && !fromRuntimeRoot.startsWith("..\\");
|
|
8687
8843
|
}
|
|
8688
8844
|
function appSpecifierPlugin(appEntry) {
|
|
@@ -8776,10 +8932,10 @@ function withAssetContexts(adapter, builds, targetDir) {
|
|
|
8776
8932
|
return prepareCompileEntryApps({
|
|
8777
8933
|
apps: contexts.map((context) => ({
|
|
8778
8934
|
...context,
|
|
8779
|
-
embed: { clientDir:
|
|
8935
|
+
embed: { clientDir: join14(targetDir, clientDirNameForPrefix(context.prefix ?? "")) }
|
|
8780
8936
|
})),
|
|
8781
8937
|
outDir: targetDir,
|
|
8782
|
-
publicDir:
|
|
8938
|
+
publicDir: join14(targetDir, "public")
|
|
8783
8939
|
});
|
|
8784
8940
|
}
|
|
8785
8941
|
function adapterRoute(app, route) {
|
|
@@ -8823,22 +8979,22 @@ async function bundleServer(adapter, apps, appEntry, clientReferences, rootDir,
|
|
|
8823
8979
|
if (build.metafile === undefined) {
|
|
8824
8980
|
throw new Error(`[furin] The ${adapter.name} server build did not produce its metafile.`);
|
|
8825
8981
|
}
|
|
8826
|
-
writeBuildMetafile(
|
|
8982
|
+
writeBuildMetafile(join14(buildRoot, "analysis", `${adapter.name}-server.json`), build.metafile, "Server");
|
|
8827
8983
|
}
|
|
8828
8984
|
return {
|
|
8829
8985
|
dir: targetDir,
|
|
8830
8986
|
entry: `${basename5(adapter.runtimeModule, extname3(adapter.runtimeModule))}.js`,
|
|
8831
|
-
files: build.outputs.filter((output) => output.path.endsWith(".js")).map((output) => toPosixPath(
|
|
8987
|
+
files: build.outputs.filter((output) => output.path.endsWith(".js")).map((output) => toPosixPath(relative9(targetDir, output.path)))
|
|
8832
8988
|
};
|
|
8833
8989
|
}
|
|
8834
8990
|
function writePrerenderSnapshot(targetDir, prerenders) {
|
|
8835
8991
|
const snapshot = Object.fromEntries(prerenders.map(({ prefix, ssg }) => [prefix, ssg]));
|
|
8836
|
-
writeFileSync7(
|
|
8992
|
+
writeFileSync7(join14(targetDir, PRERENDER_SNAPSHOT_FILE), `${JSON.stringify(snapshot)}
|
|
8837
8993
|
`);
|
|
8838
8994
|
}
|
|
8839
8995
|
async function buildAdapterTarget(adapter, apps, rootDir, buildRoot, serverEntry, options) {
|
|
8840
8996
|
assertServerEntry(serverEntry, adapter);
|
|
8841
|
-
const targetDir =
|
|
8997
|
+
const targetDir = join14(buildRoot, adapter.name);
|
|
8842
8998
|
rmSync3(targetDir, { force: true, recursive: true });
|
|
8843
8999
|
rmSync3(privateServerSourceMapDir(buildRoot, adapter.name), {
|
|
8844
9000
|
force: true,
|
|
@@ -8849,10 +9005,10 @@ async function buildAdapterTarget(adapter, apps, rootDir, buildRoot, serverEntry
|
|
|
8849
9005
|
const rootIndex = apps.findIndex((app) => app.prefix === "");
|
|
8850
9006
|
const { buildId } = builds[rootIndex === -1 ? 0 : rootIndex];
|
|
8851
9007
|
const rscManifest = await buildRscGraph(apps, targetDir, buildId, options.plugins, options.serverExternalPackages);
|
|
8852
|
-
const projectPublicDir =
|
|
9008
|
+
const projectPublicDir = join14(rootDir, "public");
|
|
8853
9009
|
const publicDir = existsSync12(projectPublicDir) ? projectPublicDir : undefined;
|
|
8854
9010
|
if (publicDir !== undefined && adapter.capabilities.assets !== "platform") {
|
|
8855
|
-
copyDirRecursive(publicDir,
|
|
9011
|
+
copyDirRecursive(publicDir, join14(targetDir, "public"));
|
|
8856
9012
|
}
|
|
8857
9013
|
const frameworkCache = adapter.capabilities.publicCache === "framework";
|
|
8858
9014
|
const appEntry = await materializeServerAppEntry({
|
|
@@ -8871,7 +9027,7 @@ async function buildAdapterTarget(adapter, apps, rootDir, buildRoot, serverEntry
|
|
|
8871
9027
|
const info = routeBuildInfo(route);
|
|
8872
9028
|
return info.documentMode !== "ssr" && (info.queryKeys?.length ?? 0) === 0;
|
|
8873
9029
|
}));
|
|
8874
|
-
const prerenders = needsPrerender ? await prerenderFromBundle({ kind: "app", path:
|
|
9030
|
+
const prerenders = needsPrerender ? await prerenderFromBundle({ kind: "app", path: join14(targetDir, APP_MODULE) }, rootDir, frameworkCache) : [];
|
|
8875
9031
|
if (frameworkCache) {
|
|
8876
9032
|
writePrerenderSnapshot(targetDir, prerenders);
|
|
8877
9033
|
}
|
|
@@ -8895,7 +9051,7 @@ async function buildAdapterTarget(adapter, apps, rootDir, buildRoot, serverEntry
|
|
|
8895
9051
|
|
|
8896
9052
|
// src/adapter/bun.ts
|
|
8897
9053
|
import { existsSync as existsSync13, rmSync as rmSync4 } from "fs";
|
|
8898
|
-
import { join as
|
|
9054
|
+
import { join as join15, relative as relative10 } from "path";
|
|
8899
9055
|
var RUNTIME_MODULE = frameworkSourceModule("adapter/bun/server.ts");
|
|
8900
9056
|
var APP_RUNTIME_MODULE = frameworkSourceModule("adapter/bun/app.ts");
|
|
8901
9057
|
function compiledServerFilename(platform) {
|
|
@@ -8904,12 +9060,12 @@ function compiledServerFilename(platform) {
|
|
|
8904
9060
|
async function compileExecutable(output, compile, manifest) {
|
|
8905
9061
|
const { apps, buildRoot, server } = output;
|
|
8906
9062
|
const filename = compiledServerFilename(process.platform);
|
|
8907
|
-
const publicDir =
|
|
9063
|
+
const publicDir = join15(server.dir, "public");
|
|
8908
9064
|
const embedded = compile === "embed" ? [...apps.map((app) => app.clientDir), ...existsSync13(publicDir) ? [publicDir] : []] : undefined;
|
|
8909
9065
|
const build = await runBunBuild({
|
|
8910
9066
|
bytecode: true,
|
|
8911
|
-
compile: { assets: embedded, outfile:
|
|
8912
|
-
entrypoints: [
|
|
9067
|
+
compile: { assets: embedded, outfile: join15(server.dir, filename) },
|
|
9068
|
+
entrypoints: [join15(server.dir, server.entry)],
|
|
8913
9069
|
format: "esm",
|
|
8914
9070
|
minify: true,
|
|
8915
9071
|
sourcemap: output.serverSourceMaps ? "external" : "none",
|
|
@@ -8920,13 +9076,13 @@ async function compileExecutable(output, compile, manifest) {
|
|
|
8920
9076
|
movePrivateServerSourceMaps(server.dir, privateServerSourceMapDir(buildRoot, "bun"), build.outputs.filter((entry) => entry.kind === "sourcemap").map((entry) => entry.path));
|
|
8921
9077
|
}
|
|
8922
9078
|
for (const file of [...server.files, PRERENDER_SNAPSHOT_FILE]) {
|
|
8923
|
-
rmSync4(
|
|
9079
|
+
rmSync4(join15(server.dir, file), { force: true });
|
|
8924
9080
|
}
|
|
8925
|
-
manifest.serverPath = toPosixPath(
|
|
8926
|
-
console.log(`[furin] Server binary: ${
|
|
9081
|
+
manifest.serverPath = toPosixPath(join15(manifest.targetDir, filename));
|
|
9082
|
+
console.log(`[furin] Server binary: ${join15(server.dir, filename)}`);
|
|
8927
9083
|
if (compile === "embed") {
|
|
8928
9084
|
for (const app of apps) {
|
|
8929
|
-
rmSync4(
|
|
9085
|
+
rmSync4(join15(server.dir, clientDirNameForPrefix(app.prefix)), {
|
|
8930
9086
|
force: true,
|
|
8931
9087
|
recursive: true
|
|
8932
9088
|
});
|
|
@@ -8949,15 +9105,15 @@ function bun(compile, bunOutput) {
|
|
|
8949
9105
|
},
|
|
8950
9106
|
name: "bun",
|
|
8951
9107
|
async onBuildComplete(output) {
|
|
8952
|
-
const targetDir = toPosixPath(
|
|
9108
|
+
const targetDir = toPosixPath(relative10(output.rootDir, output.server.dir));
|
|
8953
9109
|
const manifest = {
|
|
8954
9110
|
buildId: output.buildId,
|
|
8955
|
-
clientDir: toPosixPath(
|
|
9111
|
+
clientDir: toPosixPath(join15(targetDir, "client")),
|
|
8956
9112
|
generatedAt: new Date().toISOString(),
|
|
8957
|
-
rscManifestPath: toPosixPath(
|
|
8958
|
-
serverPath: toPosixPath(
|
|
9113
|
+
rscManifestPath: toPosixPath(join15(targetDir, "rsc", "manifest.json")),
|
|
9114
|
+
serverPath: toPosixPath(join15(targetDir, output.server.entry)),
|
|
8959
9115
|
targetDir,
|
|
8960
|
-
templatePath: toPosixPath(
|
|
9116
|
+
templatePath: toPosixPath(join15(targetDir, "client", "index.html"))
|
|
8961
9117
|
};
|
|
8962
9118
|
if (isApp) {
|
|
8963
9119
|
manifest.appPath = manifest.serverPath;
|
|
@@ -8978,20 +9134,20 @@ function bun(compile, bunOutput) {
|
|
|
8978
9134
|
|
|
8979
9135
|
// src/adapter/package.ts
|
|
8980
9136
|
import { existsSync as existsSync14, rmSync as rmSync5, writeFileSync as writeFileSync8 } from "fs";
|
|
8981
|
-
import { join as
|
|
9137
|
+
import { join as join16, relative as relative11, resolve as resolve10 } from "path";
|
|
8982
9138
|
async function buildPackageTarget(app, rootDir, buildRoot, options) {
|
|
8983
9139
|
const { prefix, root, routes, pagesDir } = app;
|
|
8984
9140
|
const modulePaths = routeSourcePaths(app);
|
|
8985
|
-
const targetDir =
|
|
9141
|
+
const targetDir = join16(buildRoot, "package");
|
|
8986
9142
|
rmSync5(targetDir, { force: true, recursive: true });
|
|
8987
9143
|
ensureDir(targetDir);
|
|
8988
9144
|
const { entryChunk, cssChunks, preloadManifest } = await buildClient(routes, {
|
|
8989
9145
|
basePath: prefix,
|
|
8990
9146
|
clientLogging: options.clientLogging ?? false,
|
|
8991
|
-
metafilePath: options.analyze ?
|
|
9147
|
+
metafilePath: options.analyze ? join16(buildRoot, "analysis", "package-client.json") : undefined,
|
|
8992
9148
|
optimizeImports: options.optimizeImports,
|
|
8993
9149
|
outDir: targetDir,
|
|
8994
|
-
pagesDir,
|
|
9150
|
+
pages: { pagesDir, style: app.style },
|
|
8995
9151
|
routeRegistry: app.routeRegistry,
|
|
8996
9152
|
plugins: options.plugins,
|
|
8997
9153
|
preloadRouteChunks: options.preload?.routeChunks,
|
|
@@ -9002,30 +9158,14 @@ async function buildPackageTarget(app, rootDir, buildRoot, options) {
|
|
|
9002
9158
|
const buildFingerprint = await createBuildFingerprint(`${prefix}
|
|
9003
9159
|
${entryChunk}`, cssChunks, routes, root, null, modulePaths, rootDir);
|
|
9004
9160
|
const buildId = Bun.hash(buildFingerprint).toString(16).slice(0, 12);
|
|
9005
|
-
const clientDir =
|
|
9006
|
-
const publicDir =
|
|
9161
|
+
const clientDir = join16(targetDir, "client");
|
|
9162
|
+
const publicDir = join16(rootDir, "public");
|
|
9007
9163
|
if (existsSync14(publicDir)) {
|
|
9008
|
-
copyDirRecursive(publicDir,
|
|
9164
|
+
copyDirRecursive(publicDir, join16(targetDir, "public"));
|
|
9009
9165
|
}
|
|
9010
9166
|
const indexHtml = generateProdIndexHtml(entryChunk, cssChunks, buildId, undefined, false);
|
|
9011
|
-
writeFileSync8(
|
|
9012
|
-
const rootConventions
|
|
9013
|
-
errorPath: root.errorPath ? toPosixPath(root.errorPath) : undefined,
|
|
9014
|
-
notFoundPath: root.notFoundPath ? toPosixPath(root.notFoundPath) : undefined
|
|
9015
|
-
} : undefined;
|
|
9016
|
-
const routeMetadata = {};
|
|
9017
|
-
for (const route of routes) {
|
|
9018
|
-
routeMetadata[toPosixPath(route.path)] = {
|
|
9019
|
-
requestKeys: route.requestKeys,
|
|
9020
|
-
requestKeysByLoader: route.requestKeysByLoader,
|
|
9021
|
-
segmentBoundaries: route.segmentBoundaries.map((b) => ({
|
|
9022
|
-
depth: b.depth,
|
|
9023
|
-
errorPath: b.errorPath ? toPosixPath(b.errorPath) : undefined,
|
|
9024
|
-
notFoundPath: b.notFoundPath ? toPosixPath(b.notFoundPath) : undefined,
|
|
9025
|
-
path: toPosixPath(b.path)
|
|
9026
|
-
}))
|
|
9027
|
-
};
|
|
9028
|
-
}
|
|
9167
|
+
writeFileSync8(join16(clientDir, "index.html"), indexHtml);
|
|
9168
|
+
const { rootConventions, routeMetadata } = buildCompileMetadata(root, routes);
|
|
9029
9169
|
const registerSource = buildEntrySource({
|
|
9030
9170
|
apps: [
|
|
9031
9171
|
{
|
|
@@ -9045,7 +9185,7 @@ ${entryChunk}`, cssChunks, routes, root, null, modulePaths, rootDir);
|
|
|
9045
9185
|
mode: "register",
|
|
9046
9186
|
prerenderSnapshot: true
|
|
9047
9187
|
});
|
|
9048
|
-
const registerEntry =
|
|
9188
|
+
const registerEntry = join16(targetDir, "register.ts");
|
|
9049
9189
|
const register = createVirtualBuildEntry(registerEntry, registerSource, "ts");
|
|
9050
9190
|
const result = await runBunBuild({
|
|
9051
9191
|
define: PRODUCTION_DEFINE,
|
|
@@ -9072,7 +9212,7 @@ ${entryChunk}`, cssChunks, routes, root, null, modulePaths, rootDir);
|
|
|
9072
9212
|
if (!result.success) {
|
|
9073
9213
|
throw new AggregateError(result.logs, "[furin] package register build failed");
|
|
9074
9214
|
}
|
|
9075
|
-
const relativePagesDir = toPosixPath(
|
|
9215
|
+
const relativePagesDir = toPosixPath(relative11(targetDir, resolve10(rootDir, pagesDir)));
|
|
9076
9216
|
const factorySource = `// Auto-generated by \`furin build --target package\` \u2014 do not edit
|
|
9077
9217
|
import { fileURLToPath } from "node:url";
|
|
9078
9218
|
import { furin } from "@teyik0/furin";
|
|
@@ -9085,7 +9225,7 @@ const CLIENT_DIR = fileURLToPath(new URL("./client", import.meta.url));
|
|
|
9085
9225
|
* Mounts this packaged furin app as an Elysia plugin.
|
|
9086
9226
|
*
|
|
9087
9227
|
* @param {object} [options] Extra furin() options (logger, sync, ...) \u2014
|
|
9088
|
-
* pagesDir/prefix/clientDir are baked into the package and cannot be overridden.
|
|
9228
|
+
* pagesDir/prefix/style/clientDir are baked into the package and cannot be overridden.
|
|
9089
9229
|
* @returns {ReturnType<typeof import("@teyik0/furin").furin>}
|
|
9090
9230
|
*/
|
|
9091
9231
|
export function createFurinApp(options = {}) {
|
|
@@ -9093,45 +9233,46 @@ export function createFurinApp(options = {}) {
|
|
|
9093
9233
|
...options,
|
|
9094
9234
|
pagesDir: PAGES_DIR,
|
|
9095
9235
|
prefix: ${JSON.stringify(prefix)},
|
|
9236
|
+
style: ${JSON.stringify(app.style)},
|
|
9096
9237
|
clientDir: CLIENT_DIR,
|
|
9097
9238
|
});
|
|
9098
9239
|
}
|
|
9099
9240
|
|
|
9100
9241
|
export const prefix = ${JSON.stringify(prefix)};
|
|
9101
9242
|
`;
|
|
9102
|
-
writeFileSync8(
|
|
9243
|
+
writeFileSync8(join16(targetDir, "index.js"), factorySource);
|
|
9103
9244
|
const dtsSource = `import type { FurinOptions, furin } from "@teyik0/furin";
|
|
9104
9245
|
|
|
9105
|
-
/** Extra furin() options \u2014 pagesDir/prefix/clientDir are baked into the package and cannot be overridden. */
|
|
9106
|
-
export type CreateFurinAppOptions = Omit<FurinOptions, "pagesDir" | "prefix" | "clientDir">;
|
|
9246
|
+
/** Extra furin() options \u2014 pagesDir/prefix/style/clientDir are baked into the package and cannot be overridden. */
|
|
9247
|
+
export type CreateFurinAppOptions = Omit<FurinOptions, "pagesDir" | "prefix" | "style" | "clientDir">;
|
|
9107
9248
|
export declare function createFurinApp(options?: CreateFurinAppOptions): ReturnType<typeof furin>;
|
|
9108
9249
|
export declare const prefix: string;
|
|
9109
9250
|
`;
|
|
9110
|
-
writeFileSync8(
|
|
9111
|
-
const snapshotPath =
|
|
9251
|
+
writeFileSync8(join16(targetDir, "index.d.ts"), dtsSource);
|
|
9252
|
+
const snapshotPath = join16(targetDir, PRERENDER_SNAPSHOT_FILE);
|
|
9112
9253
|
writeFileSync8(snapshotPath, `{}
|
|
9113
9254
|
`);
|
|
9114
|
-
const prerenders = await prerenderFromBundle({ kind: "package", path:
|
|
9255
|
+
const prerenders = await prerenderFromBundle({ kind: "package", path: join16(targetDir, "index.js") }, rootDir, true);
|
|
9115
9256
|
writeFileSync8(snapshotPath, `${JSON.stringify(Object.fromEntries(prerenders.map(({ prefix: key, ssg }) => [key, ssg])))}
|
|
9116
9257
|
`);
|
|
9117
|
-
console.log(`[furin] Package artifact: ${toPosixPath(
|
|
9258
|
+
console.log(`[furin] Package artifact: ${toPosixPath(relative11(rootDir, targetDir))}`);
|
|
9118
9259
|
return {
|
|
9119
9260
|
buildId,
|
|
9120
9261
|
generatedAt: new Date().toISOString(),
|
|
9121
9262
|
prefix,
|
|
9122
|
-
targetDir: toPosixPath(
|
|
9263
|
+
targetDir: toPosixPath(relative11(rootDir, targetDir))
|
|
9123
9264
|
};
|
|
9124
9265
|
}
|
|
9125
9266
|
|
|
9126
9267
|
// src/adapter/static.ts
|
|
9127
9268
|
import { cpSync as cpSync2, existsSync as existsSync15, rmSync as rmSync6, writeFileSync as writeFileSync9 } from "fs";
|
|
9128
|
-
import { dirname as
|
|
9269
|
+
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";
|
|
9129
9270
|
var TRAILING_SLASHES_RE = /\/+$/;
|
|
9130
9271
|
var STATIC_RENDER_ORIGIN = "http://localhost";
|
|
9131
9272
|
function pathToOutputFile(urlPath, outDir, fileName) {
|
|
9132
9273
|
const normalizedOutDir = resolve11(outDir);
|
|
9133
9274
|
if (urlPath === "/" || urlPath === "") {
|
|
9134
|
-
return
|
|
9275
|
+
return join17(normalizedOutDir, fileName);
|
|
9135
9276
|
}
|
|
9136
9277
|
const resolved = resolve11(normalizedOutDir, urlPath.slice(1), fileName);
|
|
9137
9278
|
if (!resolved.startsWith(`${normalizedOutDir}${sep3}`)) {
|
|
@@ -9250,7 +9391,7 @@ async function collectStaticOutputs(exported, outDir, basePath, onSSR, skippedRo
|
|
|
9250
9391
|
return outputs;
|
|
9251
9392
|
}
|
|
9252
9393
|
function writeStaticOutput(output) {
|
|
9253
|
-
ensureDir(
|
|
9394
|
+
ensureDir(dirname15(output.htmlFile));
|
|
9254
9395
|
writeFileSync9(output.htmlFile, output.html);
|
|
9255
9396
|
if (output.data !== null) {
|
|
9256
9397
|
writeFileSync9(output.dataFile, output.data);
|
|
@@ -9265,12 +9406,12 @@ function replaceOutDir(outDir, publicSrcDir, clientSrcDir, outputs, shellHtml) {
|
|
|
9265
9406
|
cpSync2(publicSrcDir, outDir, { recursive: true, dereference: true });
|
|
9266
9407
|
}
|
|
9267
9408
|
if (existsSync15(clientSrcDir)) {
|
|
9268
|
-
cpSync2(clientSrcDir,
|
|
9409
|
+
cpSync2(clientSrcDir, join17(outDir, "_client"), { recursive: true, dereference: true });
|
|
9269
9410
|
}
|
|
9270
9411
|
for (const output of outputs) {
|
|
9271
9412
|
writeStaticOutput(output);
|
|
9272
9413
|
}
|
|
9273
|
-
writeFileSync9(
|
|
9414
|
+
writeFileSync9(join17(outDir, "404.html"), shellHtml);
|
|
9274
9415
|
console.log("[furin] static: wrote 404.html (SPA shell fallback)");
|
|
9275
9416
|
}
|
|
9276
9417
|
function logRenderFailure(failure, error) {
|
|
@@ -9299,7 +9440,7 @@ var STATIC_ENTRY = "_furin-static";
|
|
|
9299
9440
|
async function bundleStaticExport(app, shellHtml, preloadManifest, serverDir, rootDir, options) {
|
|
9300
9441
|
const { root, routes } = app;
|
|
9301
9442
|
const { rootConventions, routeMetadata } = buildCompileMetadata(root, routes);
|
|
9302
|
-
const entry = createVirtualBuildEntry(
|
|
9443
|
+
const entry = createVirtualBuildEntry(join17(serverDir, `${STATIC_ENTRY}.ts`), buildEntrySource({
|
|
9303
9444
|
apps: [
|
|
9304
9445
|
{
|
|
9305
9446
|
clientLogging: Boolean(options.clientLogging),
|
|
@@ -9346,7 +9487,7 @@ async function bundleStaticExport(app, shellHtml, preloadManifest, serverDir, ro
|
|
|
9346
9487
|
throw new AggregateError(result.logs, "[furin] static export bundle failed");
|
|
9347
9488
|
}
|
|
9348
9489
|
await buildFlightCodec(serverDir, options.plugins);
|
|
9349
|
-
return
|
|
9490
|
+
return join17(serverDir, `${STATIC_ENTRY}.js`);
|
|
9350
9491
|
}
|
|
9351
9492
|
function assertNoRequestLoaders(routes, root) {
|
|
9352
9493
|
const offenders = [];
|
|
@@ -9382,11 +9523,11 @@ async function buildStaticTarget(app, rootDir, buildRoot, options) {
|
|
|
9382
9523
|
const outDir = resolve11(rootDir, rawOutDir);
|
|
9383
9524
|
const normalizedRoot = resolve11(rootDir);
|
|
9384
9525
|
const normalizedBuildRoot = resolve11(buildRoot);
|
|
9385
|
-
if (outDir === normalizedRoot || outDir === normalizedBuildRoot || outDir ===
|
|
9526
|
+
if (outDir === normalizedRoot || outDir === normalizedBuildRoot || outDir === parse3(outDir).root || rawOutDir === win32.parse(rawOutDir).root) {
|
|
9386
9527
|
throw new Error(`[furin] static: outDir resolves to "${outDir}" which is unsafe to delete. ` + `Use a dedicated output directory such as "dist".`);
|
|
9387
9528
|
}
|
|
9388
9529
|
function isOutsideOutDir(target) {
|
|
9389
|
-
const rel =
|
|
9530
|
+
const rel = relative12(outDir, target);
|
|
9390
9531
|
return rel.startsWith("..") || isAbsolute6(rel);
|
|
9391
9532
|
}
|
|
9392
9533
|
if (!(isOutsideOutDir(normalizedRoot) && isOutsideOutDir(normalizedBuildRoot))) {
|
|
@@ -9397,17 +9538,17 @@ async function buildStaticTarget(app, rootDir, buildRoot, options) {
|
|
|
9397
9538
|
const renderedRoutes = [];
|
|
9398
9539
|
const skippedRoutes = [];
|
|
9399
9540
|
const ssgRoutes = collectSsgRoutes(routes, onSSR, skippedRoutes);
|
|
9400
|
-
const targetDir =
|
|
9541
|
+
const targetDir = join17(buildRoot, "static");
|
|
9401
9542
|
rmSync6(targetDir, { force: true, recursive: true });
|
|
9402
9543
|
ensureDir(targetDir);
|
|
9403
9544
|
try {
|
|
9404
9545
|
const { entryChunk, cssChunks, preloadManifest } = await buildClient(ssgRoutes, {
|
|
9405
9546
|
basePath,
|
|
9406
9547
|
clientLogging: Boolean(options.clientLogging),
|
|
9407
|
-
metafilePath: options.analyze ?
|
|
9548
|
+
metafilePath: options.analyze ? join17(buildRoot, "analysis", "static-client.json") : undefined,
|
|
9408
9549
|
optimizeImports: options.optimizeImports,
|
|
9409
9550
|
outDir: targetDir,
|
|
9410
|
-
pagesDir:
|
|
9551
|
+
pages: { pagesDir: app.pagesDir, style: app.style },
|
|
9411
9552
|
routeRegistry: app.routeRegistry,
|
|
9412
9553
|
plugins: options.plugins,
|
|
9413
9554
|
preloadRouteChunks: options.preload?.routeChunks,
|
|
@@ -9415,16 +9556,16 @@ async function buildStaticTarget(app, rootDir, buildRoot, options) {
|
|
|
9415
9556
|
reactCompiler: options.reactCompiler,
|
|
9416
9557
|
rootLayout: root.path
|
|
9417
9558
|
});
|
|
9418
|
-
const publicFavicon =
|
|
9559
|
+
const publicFavicon = join17(rootDir, "public", "favicon.ico");
|
|
9419
9560
|
const faviconHref = existsSync15(publicFavicon) ? `${basePath}/favicon.ico` : undefined;
|
|
9420
9561
|
const shellHtml = generateProdIndexHtml(entryChunk, cssChunks, undefined, faviconHref, true);
|
|
9421
|
-
const bundle = await bundleStaticExport(app, shellHtml, preloadManifest,
|
|
9562
|
+
const bundle = await bundleStaticExport(app, shellHtml, preloadManifest, join17(targetDir, "server"), rootDir, options);
|
|
9422
9563
|
const exported = await exportStaticFromBundle(bundle, rootDir, {
|
|
9423
9564
|
basePath,
|
|
9424
9565
|
patterns: ssgRoutes.map((route) => route.pattern)
|
|
9425
9566
|
});
|
|
9426
9567
|
const outputs = await collectStaticOutputs(exported, outDir, basePath, onSSR, skippedRoutes);
|
|
9427
|
-
replaceOutDir(outDir,
|
|
9568
|
+
replaceOutDir(outDir, join17(rootDir, "public"), join17(targetDir, "client"), outputs, shellHtml);
|
|
9428
9569
|
renderedRoutes.push(...outputs.map((output) => output.path));
|
|
9429
9570
|
} finally {
|
|
9430
9571
|
rmSync6(targetDir, { force: true, recursive: true });
|
|
@@ -9449,7 +9590,7 @@ import {
|
|
|
9449
9590
|
symlinkSync,
|
|
9450
9591
|
writeFileSync as writeFileSync10
|
|
9451
9592
|
} from "fs";
|
|
9452
|
-
import { basename as basename6, dirname as
|
|
9593
|
+
import { basename as basename6, dirname as dirname16, join as join18, relative as relative13 } from "path";
|
|
9453
9594
|
import { fileURLToPath as fileURLToPath9, pathToFileURL as pathToFileURL3 } from "url";
|
|
9454
9595
|
|
|
9455
9596
|
// src/adapter/vercel/data.ts
|
|
@@ -9494,8 +9635,8 @@ function assertRegions(regions) {
|
|
|
9494
9635
|
}
|
|
9495
9636
|
}
|
|
9496
9637
|
function frameworkVersion() {
|
|
9497
|
-
const packageRoot =
|
|
9498
|
-
const packageJson = JSON.parse(readFileSync8(
|
|
9638
|
+
const packageRoot = dirname16(dirname16(fileURLToPath9(import.meta.resolve("@teyik0/furin"))));
|
|
9639
|
+
const packageJson = JSON.parse(readFileSync8(join18(packageRoot, "package.json"), "utf8"));
|
|
9499
9640
|
return packageJson.version;
|
|
9500
9641
|
}
|
|
9501
9642
|
function encodeCacheTag(value) {
|
|
@@ -9520,7 +9661,7 @@ function functionNameForPath(path, mode, names) {
|
|
|
9520
9661
|
return "[...splat]";
|
|
9521
9662
|
}
|
|
9522
9663
|
if (segment.startsWith(":")) {
|
|
9523
|
-
return `[${segment.slice(1)}]`;
|
|
9664
|
+
return segment.endsWith("?") ? `[[${segment.slice(1, -1)}]]` : `[${segment.slice(1)}]`;
|
|
9524
9665
|
}
|
|
9525
9666
|
const sanitized = segment.replace(UNSAFE_FUNCTION_PATH_RE, "-");
|
|
9526
9667
|
if (sanitized === segment && segment !== "." && segment !== "..") {
|
|
@@ -9635,8 +9776,8 @@ async function addPrerenderFallback(job, response, functionsDir) {
|
|
|
9635
9776
|
const { spec } = job;
|
|
9636
9777
|
const fallback = `${basename6(spec.functionName)}.prerender-fallback.html`;
|
|
9637
9778
|
const location = response.headers.get("location") ?? undefined;
|
|
9638
|
-
const fallbackPath =
|
|
9639
|
-
ensureDir(
|
|
9779
|
+
const fallbackPath = join18(dirname16(join18(functionsDir, spec.functionName)), fallback);
|
|
9780
|
+
ensureDir(dirname16(fallbackPath));
|
|
9640
9781
|
writeFileSync10(fallbackPath, await response.text());
|
|
9641
9782
|
spec.config.fallback = fallback;
|
|
9642
9783
|
spec.config.initialHeaders = {
|
|
@@ -9651,10 +9792,10 @@ async function buildProductionFallbacks(jobs, functionsDir, rootDir, buildRoot)
|
|
|
9651
9792
|
if (jobs.length === 0) {
|
|
9652
9793
|
return;
|
|
9653
9794
|
}
|
|
9654
|
-
const resultPath =
|
|
9795
|
+
const resultPath = join18(buildRoot, `vercel-prerender-${crypto.randomUUID()}.json`);
|
|
9655
9796
|
const requests = jobs.map(({ path, spec }) => `http://localhost/${spec.functionName}?${ISR_PATH_PARAM}=${encodeURIComponent(path)}`);
|
|
9656
9797
|
const script = `
|
|
9657
|
-
const handler = (await import(${JSON.stringify(pathToFileURL3(
|
|
9798
|
+
const handler = (await import(${JSON.stringify(pathToFileURL3(join18(functionsDir, "__server.func/index.js")).href)})).default;
|
|
9658
9799
|
const results = [];
|
|
9659
9800
|
for (const [index, url] of ${JSON.stringify(requests)}.entries()) {
|
|
9660
9801
|
const response = await handler.fetch(new Request(url));
|
|
@@ -9709,9 +9850,9 @@ async function buildBootstrap(serverFunctionDir) {
|
|
|
9709
9850
|
});
|
|
9710
9851
|
}
|
|
9711
9852
|
function createFunctionAlias(functionsDir, serverFunctionDir, functionName) {
|
|
9712
|
-
const aliasPath =
|
|
9713
|
-
ensureDir(
|
|
9714
|
-
const target =
|
|
9853
|
+
const aliasPath = join18(functionsDir, `${functionName}.func`);
|
|
9854
|
+
ensureDir(dirname16(aliasPath));
|
|
9855
|
+
const target = relative13(dirname16(aliasPath), serverFunctionDir);
|
|
9715
9856
|
symlinkSync(target, aliasPath, process.platform === "win32" ? "junction" : "dir");
|
|
9716
9857
|
}
|
|
9717
9858
|
function copyStaticAssets(output, staticDir) {
|
|
@@ -9719,16 +9860,16 @@ function copyStaticAssets(output, staticDir) {
|
|
|
9719
9860
|
if (publicDir !== undefined) {
|
|
9720
9861
|
cpSync3(publicDir, staticDir, { recursive: true });
|
|
9721
9862
|
for (const app of apps) {
|
|
9722
|
-
const appStaticDir =
|
|
9723
|
-
cpSync3(publicDir,
|
|
9724
|
-
const favicon =
|
|
9863
|
+
const appStaticDir = join18(staticDir, app.prefix.slice(1));
|
|
9864
|
+
cpSync3(publicDir, join18(appStaticDir, "public"), { recursive: true });
|
|
9865
|
+
const favicon = join18(publicDir, "favicon.ico");
|
|
9725
9866
|
if (app.prefix !== "" && existsSync16(favicon)) {
|
|
9726
|
-
cpSync3(favicon,
|
|
9867
|
+
cpSync3(favicon, join18(appStaticDir, "favicon.ico"));
|
|
9727
9868
|
}
|
|
9728
9869
|
}
|
|
9729
9870
|
}
|
|
9730
9871
|
for (const app of apps) {
|
|
9731
|
-
cpSync3(app.clientDir,
|
|
9872
|
+
cpSync3(app.clientDir, join18(staticDir, app.prefix.slice(1), "_client"), { recursive: true });
|
|
9732
9873
|
}
|
|
9733
9874
|
}
|
|
9734
9875
|
function buildOutputConfig(apps, specs) {
|
|
@@ -9762,7 +9903,7 @@ function buildOutputConfig(apps, specs) {
|
|
|
9762
9903
|
};
|
|
9763
9904
|
}
|
|
9764
9905
|
function writeFunctionConfig(serverFunctionDir, regions) {
|
|
9765
|
-
writeFileSync10(
|
|
9906
|
+
writeFileSync10(join18(serverFunctionDir, ".vc-config.json"), `${JSON.stringify({
|
|
9766
9907
|
handler: "index.js",
|
|
9767
9908
|
launcherType: "Nodejs",
|
|
9768
9909
|
...regions === undefined ? {} : { regions },
|
|
@@ -9779,39 +9920,39 @@ function vercel(options) {
|
|
|
9779
9920
|
name: "vercel",
|
|
9780
9921
|
async onBuildComplete(output) {
|
|
9781
9922
|
const { apps, rootDir, server } = output;
|
|
9782
|
-
const outputDir =
|
|
9783
|
-
const staticDir =
|
|
9784
|
-
const functionsDir =
|
|
9785
|
-
const serverFunctionDir =
|
|
9923
|
+
const outputDir = join18(rootDir, ".vercel", "output");
|
|
9924
|
+
const staticDir = join18(outputDir, "static");
|
|
9925
|
+
const functionsDir = join18(outputDir, "functions");
|
|
9926
|
+
const serverFunctionDir = join18(functionsDir, "__server.func");
|
|
9786
9927
|
rmSync7(outputDir, { force: true, recursive: true });
|
|
9787
9928
|
ensureDir(staticDir);
|
|
9788
9929
|
ensureDir(serverFunctionDir);
|
|
9789
9930
|
for (const file of [...server.files, "server-codec.js"]) {
|
|
9790
|
-
cpSync3(
|
|
9931
|
+
cpSync3(join18(server.dir, file), join18(serverFunctionDir, file));
|
|
9791
9932
|
}
|
|
9792
9933
|
copyStaticAssets(output, staticDir);
|
|
9793
9934
|
const pprResumeKey = crypto.randomUUID();
|
|
9794
9935
|
const { jobs, specs } = createPrerenderSpecs(apps, pprResumeKey);
|
|
9795
|
-
const serverBundleBytes = server.files.reduce((total, file) => total + statSync2(
|
|
9796
|
-
writeFileSync10(
|
|
9936
|
+
const serverBundleBytes = server.files.reduce((total, file) => total + statSync2(join18(server.dir, file)).size, 0);
|
|
9937
|
+
writeFileSync10(join18(serverFunctionDir, VERCEL_DATA_FILE), `${JSON.stringify(runtimeData(apps, specs, pprResumeKey, serverBundleBytes))}
|
|
9797
9938
|
`);
|
|
9798
9939
|
await buildBootstrap(serverFunctionDir);
|
|
9799
9940
|
await buildProductionFallbacks(jobs, functionsDir, rootDir, output.buildRoot);
|
|
9800
9941
|
writeFunctionConfig(serverFunctionDir, options.regions);
|
|
9801
9942
|
for (const spec of specs) {
|
|
9802
9943
|
createFunctionAlias(functionsDir, serverFunctionDir, spec.functionName);
|
|
9803
|
-
writeFileSync10(
|
|
9944
|
+
writeFileSync10(join18(functionsDir, `${spec.functionName}.prerender-config.json`), `${JSON.stringify(spec.config, null, 2)}
|
|
9804
9945
|
`);
|
|
9805
9946
|
}
|
|
9806
|
-
writeFileSync10(
|
|
9947
|
+
writeFileSync10(join18(outputDir, "config.json"), `${JSON.stringify(buildOutputConfig(apps, specs), null, 2)}
|
|
9807
9948
|
`);
|
|
9808
|
-
console.log(`[furin] Vercel output: ${toPosixPath(
|
|
9949
|
+
console.log(`[furin] Vercel output: ${toPosixPath(relative13(rootDir, outputDir))}`);
|
|
9809
9950
|
return {
|
|
9810
9951
|
buildId: output.buildId,
|
|
9811
9952
|
generatedAt: new Date().toISOString(),
|
|
9812
9953
|
isrRoutes: apps.flatMap((app) => app.routes.filter((route) => route.mode === "isr").map((route) => physicalPath(app.prefix, route.pattern))).toSorted(),
|
|
9813
|
-
outputDir: toPosixPath(
|
|
9814
|
-
serverPath: toPosixPath(
|
|
9954
|
+
outputDir: toPosixPath(relative13(rootDir, outputDir)),
|
|
9955
|
+
serverPath: toPosixPath(relative13(rootDir, serverFunctionDir)),
|
|
9815
9956
|
ssgRoutes: jobs.filter((job) => job.route.mode === "ssg").map((job) => job.path).toSorted()
|
|
9816
9957
|
};
|
|
9817
9958
|
},
|
|
@@ -9823,10 +9964,12 @@ function vercel(options) {
|
|
|
9823
9964
|
import { t } from "elysia";
|
|
9824
9965
|
var BUILD_TARGETS = ["bun", "vercel", "static", "package"];
|
|
9825
9966
|
var compileTargetSchema = t.Union([t.Literal("server"), t.Literal("embed")]);
|
|
9967
|
+
var routeStyleSchema = t.Union([t.Literal("nextjs"), t.Literal("tanstack")]);
|
|
9826
9968
|
var configSchema = t.Object({
|
|
9827
9969
|
apps: t.Optional(t.Array(t.Object({
|
|
9828
9970
|
pagesDir: t.String(),
|
|
9829
|
-
prefix: t.Optional(t.String())
|
|
9971
|
+
prefix: t.Optional(t.String()),
|
|
9972
|
+
style: routeStyleSchema
|
|
9830
9973
|
}))),
|
|
9831
9974
|
bun: t.Optional(t.Object({
|
|
9832
9975
|
compile: t.Optional(compileTargetSchema),
|
|
@@ -9841,6 +9984,7 @@ var configSchema = t.Object({
|
|
|
9841
9984
|
rootDir: t.Optional(t.String()),
|
|
9842
9985
|
serverEntry: t.Optional(t.String()),
|
|
9843
9986
|
serverSourceMaps: t.Optional(t.Boolean()),
|
|
9987
|
+
style: t.Optional(routeStyleSchema),
|
|
9844
9988
|
static: t.Optional(t.Object({
|
|
9845
9989
|
basePath: t.Optional(t.String()),
|
|
9846
9990
|
onSSR: t.Optional(t.Union([t.Literal("error"), t.Literal("skip")])),
|
|
@@ -9850,13 +9994,8 @@ var configSchema = t.Object({
|
|
|
9850
9994
|
|
|
9851
9995
|
// src/plugin/route-config.ts
|
|
9852
9996
|
import { existsSync as existsSync17, readFileSync as readFileSync9, writeFileSync as writeFileSync11 } from "fs";
|
|
9853
|
-
import {
|
|
9854
|
-
var EXTENSION_RE = /\.(?:[cm]?[jt]sx?)$/;
|
|
9997
|
+
import { relative as relative14, resolve as resolve12 } from "path";
|
|
9855
9998
|
var IDENTIFIER_RE = /^[A-Za-z_$][\w$]*$/;
|
|
9856
|
-
var PATH_SEPARATOR_RE = /[\\/]/;
|
|
9857
|
-
function withoutExtension(path) {
|
|
9858
|
-
return path.replace(EXTENSION_RE, "");
|
|
9859
|
-
}
|
|
9860
9999
|
function propertyName(key) {
|
|
9861
10000
|
if (key?.type === "Identifier") {
|
|
9862
10001
|
return key.name;
|
|
@@ -9937,9 +10076,9 @@ function position2(source, offset) {
|
|
|
9937
10076
|
function issueAt(file, parsed, node, message) {
|
|
9938
10077
|
return { file, ...position2(parsed.source, node.start), message };
|
|
9939
10078
|
}
|
|
9940
|
-
function checkKey(file,
|
|
10079
|
+
function checkKey(file, route, parsed) {
|
|
9941
10080
|
const { config, head, id } = parsed.route;
|
|
9942
|
-
const expected =
|
|
10081
|
+
const expected = route.id;
|
|
9943
10082
|
if (!id) {
|
|
9944
10083
|
return issueAt(file, parsed, head, `defineRoute() must name this file. Its id is "${expected}":
|
|
9945
10084
|
defineRoute("${expected}")`);
|
|
@@ -9968,21 +10107,21 @@ function suggestedMode(route, isRoot) {
|
|
|
9968
10107
|
}
|
|
9969
10108
|
return route.methods.has("loader") || route.methods.has("requestLoader") ? "ssr" : "ssg";
|
|
9970
10109
|
}
|
|
9971
|
-
function checkFactory(file,
|
|
10110
|
+
function checkFactory(file, manifestRoute, parsed) {
|
|
9972
10111
|
const { route } = parsed;
|
|
9973
|
-
const isRoot =
|
|
10112
|
+
const isRoot = manifestRoute === undefined;
|
|
9974
10113
|
if (isRoot === route.isRootFactory) {
|
|
9975
10114
|
return;
|
|
9976
10115
|
}
|
|
9977
10116
|
const mode = suggestedMode(route, isRoot);
|
|
9978
10117
|
if (isRoot) {
|
|
9979
|
-
return issueAt(file, parsed, route.head, `root
|
|
10118
|
+
return issueAt(file, parsed, route.head, `The root layout must use defineRootRoute(), which has no parent layout:
|
|
9980
10119
|
import { defineRootRoute } from "@teyik0/furin";
|
|
9981
10120
|
export const route = defineRootRoute().config({ mode: "${mode}" })`);
|
|
9982
10121
|
}
|
|
9983
|
-
return issueAt(file, parsed, route.head, `defineRootRoute() is reserved for root.
|
|
10122
|
+
return issueAt(file, parsed, route.head, `defineRootRoute() is reserved for the root layout. Use defineRoute with this file's id:
|
|
9984
10123
|
import { defineRoute } from "@teyik0/furin";
|
|
9985
|
-
export const route = defineRoute("${
|
|
10124
|
+
export const route = defineRoute("${manifestRoute.id}").config({ mode: "${mode}" })`);
|
|
9986
10125
|
}
|
|
9987
10126
|
function checkConfig(file, parsed) {
|
|
9988
10127
|
const { route } = parsed;
|
|
@@ -10013,56 +10152,64 @@ function declaredParams(route) {
|
|
|
10013
10152
|
}
|
|
10014
10153
|
return new Set(keys.filter((key) => key !== undefined));
|
|
10015
10154
|
}
|
|
10016
|
-
function
|
|
10017
|
-
return
|
|
10018
|
-
const dynamic = parseDynamicRouteSegment(segment, file);
|
|
10019
|
-
return dynamic ? [{ key: dynamic.catchAll ? "*" : dynamic.name, segment }] : [];
|
|
10020
|
-
}).filter(({ key }) => declared !== true && !declared.has(key));
|
|
10155
|
+
function undeclaredParams(route, declared) {
|
|
10156
|
+
return route.params.filter(({ name }) => declared !== true && !declared.has(name));
|
|
10021
10157
|
}
|
|
10022
|
-
function paramsSchema(
|
|
10023
|
-
const fields =
|
|
10158
|
+
function paramsSchema(params) {
|
|
10159
|
+
const fields = params.map(({ name, optional }) => `${IDENTIFIER_RE.test(name) ? name : JSON.stringify(name)}: ${optional ? "t.Optional(t.String())" : "t.String()"}`);
|
|
10024
10160
|
return `params: t.Object({ ${fields.join(", ")} })`;
|
|
10025
10161
|
}
|
|
10026
|
-
function checkParams(file,
|
|
10027
|
-
const missing =
|
|
10162
|
+
function checkParams(file, route, parsed) {
|
|
10163
|
+
const missing = undeclaredParams(route, declaredParams(parsed.route));
|
|
10028
10164
|
if (missing.length === 0) {
|
|
10029
10165
|
return;
|
|
10030
10166
|
}
|
|
10031
10167
|
const plural = missing.length > 1;
|
|
10032
10168
|
const tImport = parsed.imports.get("t")?.specifier === "elysia" ? "" : `
|
|
10033
10169
|
import { t } from "elysia";`;
|
|
10034
|
-
return issueAt(file, parsed, parsed.route.config ?? parsed.route.head, `The
|
|
10170
|
+
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}
|
|
10035
10171
|
${paramsSchema(missing)}`);
|
|
10036
10172
|
}
|
|
10037
|
-
function
|
|
10038
|
-
const
|
|
10173
|
+
function checkBoundaryMethods(file, instance, parsed) {
|
|
10174
|
+
const method = ["error", "notFound"].find((name) => parsed.route.methods.has(name));
|
|
10175
|
+
if (instance.style !== "nextjs" || method === undefined) {
|
|
10176
|
+
return;
|
|
10177
|
+
}
|
|
10178
|
+
const convention = method === "error" ? "an error.tsx" : "a not-found.tsx";
|
|
10179
|
+
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.`);
|
|
10180
|
+
}
|
|
10181
|
+
function checkRoute(file, instance, route, parsed) {
|
|
10182
|
+
const factory = checkFactory(file, route, parsed);
|
|
10039
10183
|
if (factory) {
|
|
10040
10184
|
return [factory];
|
|
10041
10185
|
}
|
|
10042
|
-
const isLayout = basename7(withoutExtension(file)) === "_route";
|
|
10043
10186
|
return [
|
|
10044
10187
|
checkConfig(file, parsed),
|
|
10045
|
-
|
|
10188
|
+
route === undefined ? undefined : checkKey(file, route, parsed),
|
|
10046
10189
|
checkMode(file, parsed),
|
|
10047
|
-
|
|
10190
|
+
route === undefined || route.kind === "layout" ? undefined : checkParams(file, route, parsed),
|
|
10191
|
+
checkBoundaryMethods(file, instance, parsed)
|
|
10048
10192
|
];
|
|
10049
10193
|
}
|
|
10050
|
-
function routeFiles(
|
|
10051
|
-
const
|
|
10052
|
-
|
|
10053
|
-
|
|
10054
|
-
|
|
10055
|
-
|
|
10194
|
+
function routeFiles(manifest) {
|
|
10195
|
+
const files = manifest.routes.map((route) => [
|
|
10196
|
+
resolve12(route.sourcePath),
|
|
10197
|
+
route
|
|
10198
|
+
]);
|
|
10199
|
+
if (existsSync17(manifest.rootPath)) {
|
|
10200
|
+
files.push([resolve12(manifest.rootPath), undefined]);
|
|
10201
|
+
}
|
|
10202
|
+
return files.toSorted(([left], [right]) => left.localeCompare(right));
|
|
10056
10203
|
}
|
|
10057
|
-
function validateRouteConfig(
|
|
10058
|
-
const instance = { pagesDir: resolve12(pagesDir)
|
|
10059
|
-
return routeFiles(instance
|
|
10204
|
+
function validateRouteConfig(spec) {
|
|
10205
|
+
const instance = { ...spec, pagesDir: resolve12(spec.pagesDir) };
|
|
10206
|
+
return routeFiles(scanRouteManifest(instance)).flatMap(([file, route]) => {
|
|
10060
10207
|
const parsed = parseRoute(file);
|
|
10061
|
-
return parsed ? checkRoute(file, instance, parsed).filter((issue) => issue !== undefined) : [];
|
|
10208
|
+
return parsed ? checkRoute(file, instance, route, parsed).filter((issue) => issue !== undefined) : [];
|
|
10062
10209
|
});
|
|
10063
10210
|
}
|
|
10064
10211
|
function displayPath(file) {
|
|
10065
|
-
const projected =
|
|
10212
|
+
const projected = relative14(process.cwd(), file).replaceAll("\\", "/");
|
|
10066
10213
|
return projected.startsWith("../") ? file : projected;
|
|
10067
10214
|
}
|
|
10068
10215
|
function formatRouteConfigIssue(issue) {
|
|
@@ -10079,10 +10226,10 @@ function assertValidRouteConfig(instance) {
|
|
|
10079
10226
|
|
|
10080
10227
|
// src/build/discover-mounts.ts
|
|
10081
10228
|
import { readFileSync as readFileSync10, rmSync as rmSync8 } from "fs";
|
|
10082
|
-
import { join as
|
|
10229
|
+
import { join as join19 } from "path";
|
|
10083
10230
|
var DISCOVERY_PROCESS = frameworkSourceModule("build/discover-mounts-process.ts");
|
|
10084
10231
|
async function discoverFurinMounts(serverEntry, rootDir) {
|
|
10085
|
-
const resultPath =
|
|
10232
|
+
const resultPath = join19(rootDir, ".furin", "build", `mounts-${crypto.randomUUID()}.json`);
|
|
10086
10233
|
const child = Bun.spawn([process.execPath, DISCOVERY_PROCESS, serverEntry, resultPath], {
|
|
10087
10234
|
cwd: rootDir,
|
|
10088
10235
|
env: { ...process.env, NODE_ENV: "production" },
|
|
@@ -10109,7 +10256,7 @@ ${stdout}
|
|
|
10109
10256
|
|
|
10110
10257
|
// src/build/discover-pages.ts
|
|
10111
10258
|
import { mkdtempSync, readFileSync as readFileSync11, renameSync as renameSync3, rmSync as rmSync9, writeFileSync as writeFileSync12 } from "fs";
|
|
10112
|
-
import { join as
|
|
10259
|
+
import { join as join20 } from "path";
|
|
10113
10260
|
import { serialize } from "v8";
|
|
10114
10261
|
|
|
10115
10262
|
// src/build/discovery-plugins.ts
|
|
@@ -10180,10 +10327,10 @@ async function discoveryPlugins(plugins) {
|
|
|
10180
10327
|
// src/build/discover-pages.ts
|
|
10181
10328
|
async function discoverPages(apps, rootDir, plugins) {
|
|
10182
10329
|
const runtime = await discoveryPlugins(plugins);
|
|
10183
|
-
const buildDir =
|
|
10330
|
+
const buildDir = join20(rootDir, ".furin/build");
|
|
10184
10331
|
ensureDir(buildDir);
|
|
10185
|
-
const directory = mkdtempSync(
|
|
10186
|
-
const resultPath =
|
|
10332
|
+
const directory = mkdtempSync(join20(buildDir, "discovery-"));
|
|
10333
|
+
const resultPath = join20(directory, "pages.json");
|
|
10187
10334
|
const child = Bun.spawn([
|
|
10188
10335
|
process.execPath,
|
|
10189
10336
|
frameworkSourceModule("build/discover-pages-process.ts"),
|
|
@@ -10253,22 +10400,21 @@ async function resolveAppSpecs(options, serverEntry, rootDir) {
|
|
|
10253
10400
|
if (options.apps && options.apps.length > 0) {
|
|
10254
10401
|
return options.apps.map((app) => ({
|
|
10255
10402
|
pagesDir: resolve13(rootDir, app.pagesDir),
|
|
10256
|
-
prefix: normalizePrefix(app.prefix)
|
|
10403
|
+
prefix: normalizePrefix(app.prefix),
|
|
10404
|
+
style: app.style
|
|
10257
10405
|
}));
|
|
10258
10406
|
}
|
|
10259
|
-
if (options.pagesDir) {
|
|
10260
|
-
return [{ pagesDir: resolve13(rootDir, options.pagesDir), prefix: "" }];
|
|
10261
|
-
}
|
|
10262
10407
|
if (serverEntry) {
|
|
10263
10408
|
const mounted = await discoverFurinMounts(serverEntry, rootDir);
|
|
10264
10409
|
if (mounted.length > 0) {
|
|
10265
10410
|
return mounted.map((app) => ({
|
|
10266
10411
|
pagesDir: resolve13(rootDir, app.pagesDir),
|
|
10267
|
-
prefix: app.prefix
|
|
10412
|
+
prefix: app.prefix,
|
|
10413
|
+
style: app.style
|
|
10268
10414
|
}));
|
|
10269
10415
|
}
|
|
10270
10416
|
}
|
|
10271
|
-
|
|
10417
|
+
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" }].`);
|
|
10272
10418
|
}
|
|
10273
10419
|
async function scanApps(options, serverEntry, rootDir) {
|
|
10274
10420
|
const appSpecs = await resolveAppSpecs(options, serverEntry, rootDir);
|
|
@@ -10297,9 +10443,13 @@ function generateRouteTypes(options) {
|
|
|
10297
10443
|
async function buildApp(options) {
|
|
10298
10444
|
return withProductionBuild(() => buildAppInternal(options));
|
|
10299
10445
|
}
|
|
10446
|
+
function existingServerEntry(options, rootDir) {
|
|
10447
|
+
const entry = resolve13(rootDir, options.serverEntry ?? "src/server.ts");
|
|
10448
|
+
return existsSync18(entry) ? entry : null;
|
|
10449
|
+
}
|
|
10300
10450
|
async function buildAppInternal(options) {
|
|
10301
10451
|
const rootDir = resolve13(options.rootDir ?? process.cwd());
|
|
10302
|
-
const buildRoot =
|
|
10452
|
+
const buildRoot = join21(rootDir, BUILD_OUTPUT_DIR);
|
|
10303
10453
|
const targets = requestedTargets(options.target);
|
|
10304
10454
|
const serverEntry = (() => {
|
|
10305
10455
|
if (targets.every(isServerless)) {
|
|
@@ -10317,7 +10467,8 @@ async function buildAppInternal(options) {
|
|
|
10317
10467
|
}
|
|
10318
10468
|
return entry;
|
|
10319
10469
|
})();
|
|
10320
|
-
const
|
|
10470
|
+
const mountEntry = serverEntry ?? existingServerEntry(options, rootDir);
|
|
10471
|
+
const apps = await scanApps(options, mountEntry, rootDir);
|
|
10321
10472
|
writeAppRouteTypes(apps, rootDir);
|
|
10322
10473
|
const primaryApp = apps.find((app) => app.prefix === "") ?? apps[0];
|
|
10323
10474
|
ensureDir(buildRoot);
|
|
@@ -10325,13 +10476,14 @@ async function buildAppInternal(options) {
|
|
|
10325
10476
|
version: 1,
|
|
10326
10477
|
generatedAt: new Date().toISOString(),
|
|
10327
10478
|
rootDir: toPosixPath(rootDir),
|
|
10328
|
-
pagesDir: toPosixPath(
|
|
10329
|
-
rootPath: toPosixPath(
|
|
10330
|
-
serverEntry: serverEntry ? toPosixPath(
|
|
10479
|
+
pagesDir: toPosixPath(relative15(rootDir, primaryApp.pagesDir)),
|
|
10480
|
+
rootPath: toPosixPath(relative15(rootDir, primaryApp.root.path)),
|
|
10481
|
+
serverEntry: serverEntry ? toPosixPath(relative15(rootDir, serverEntry)) : null,
|
|
10331
10482
|
routes: primaryApp.routes.map((route) => toBuildRouteManifestEntry(route, rootDir)),
|
|
10332
10483
|
apps: apps.map((app) => ({
|
|
10333
|
-
pagesDir: toPosixPath(
|
|
10484
|
+
pagesDir: toPosixPath(relative15(rootDir, app.pagesDir)),
|
|
10334
10485
|
prefix: app.prefix,
|
|
10486
|
+
style: app.style,
|
|
10335
10487
|
routes: app.routes.map((route) => toBuildRouteManifestEntry(route, rootDir))
|
|
10336
10488
|
})),
|
|
10337
10489
|
targets: {}
|
|
@@ -10357,7 +10509,7 @@ async function buildAppInternal(options) {
|
|
|
10357
10509
|
const adapter = adapterFor(target, options);
|
|
10358
10510
|
manifest.targets[adapter.name] = await buildAdapterTarget(adapter, apps, rootDir, buildRoot, serverEntry, options);
|
|
10359
10511
|
}
|
|
10360
|
-
writeFileSync13(
|
|
10512
|
+
writeFileSync13(join21(buildRoot, "manifest.json"), `${JSON.stringify(manifest, null, 2)}
|
|
10361
10513
|
`);
|
|
10362
10514
|
return {
|
|
10363
10515
|
manifest,
|
|
@@ -10481,6 +10633,9 @@ async function loadCliConfig(cwd, explicitConfigPath) {
|
|
|
10481
10633
|
const [firstError] = compiledConfigSchema.Errors(configToValidate);
|
|
10482
10634
|
throw new Error(`[furin] Invalid config at ${configPath}: ${firstError?.message ?? "unknown error"} (path: ${firstError?.instancePath ?? "/"})`);
|
|
10483
10635
|
}
|
|
10636
|
+
if (configToValidate.pagesDir !== undefined && configToValidate.style === undefined) {
|
|
10637
|
+
throw new Error(`[furin] Invalid config at ${configPath}: pagesDir needs its file-routing style: add style: "nextjs" or "tanstack".`);
|
|
10638
|
+
}
|
|
10484
10639
|
const resolvedRootDir = resolve14(rootDir, configToValidate.rootDir ?? ".");
|
|
10485
10640
|
return {
|
|
10486
10641
|
...configToValidate,
|
|
@@ -10493,7 +10648,7 @@ async function loadCliConfig(cwd, explicitConfigPath) {
|
|
|
10493
10648
|
}
|
|
10494
10649
|
|
|
10495
10650
|
// src/cli/dev.ts
|
|
10496
|
-
import { join as
|
|
10651
|
+
import { join as join22, resolve as resolve15 } from "path";
|
|
10497
10652
|
import { pathToFileURL as pathToFileURL5 } from "url";
|
|
10498
10653
|
import { parseArgs } from "util";
|
|
10499
10654
|
var PORT = /^\d+$/;
|
|
@@ -10544,7 +10699,7 @@ async function runDevelopment(cwd, args) {
|
|
|
10544
10699
|
const child = Bun.spawn([
|
|
10545
10700
|
process.execPath,
|
|
10546
10701
|
"--hot",
|
|
10547
|
-
|
|
10702
|
+
join22(import.meta.dir, "dev-worker.ts"),
|
|
10548
10703
|
resolve15(config.rootDir, config.serverEntry ?? "src/server.ts"),
|
|
10549
10704
|
port ?? "",
|
|
10550
10705
|
integration
|
|
@@ -10586,7 +10741,7 @@ async function runDevelopment(cwd, args) {
|
|
|
10586
10741
|
|
|
10587
10742
|
// src/cli/preview.ts
|
|
10588
10743
|
import { existsSync as existsSync20 } from "fs";
|
|
10589
|
-
import { isAbsolute as isAbsolute7, join as
|
|
10744
|
+
import { isAbsolute as isAbsolute7, join as join23, relative as relative16, resolve as resolve16 } from "path";
|
|
10590
10745
|
var LEADING_SLASHES_RE = /^\/+/;
|
|
10591
10746
|
var TRAILING_SLASHES_RE2 = /\/+$/;
|
|
10592
10747
|
function normalizeStaticPreviewBasePath(basePath) {
|
|
@@ -10605,14 +10760,14 @@ function startStaticPreview({
|
|
|
10605
10760
|
}) {
|
|
10606
10761
|
const basePath = normalizeStaticPreviewBasePath(rawBasePath);
|
|
10607
10762
|
const distDir = resolve16(rawDistDir);
|
|
10608
|
-
const indexPath =
|
|
10609
|
-
const notFoundPath =
|
|
10610
|
-
const faviconPath =
|
|
10763
|
+
const indexPath = join23(distDir, "index.html");
|
|
10764
|
+
const notFoundPath = join23(distDir, "404.html");
|
|
10765
|
+
const faviconPath = join23(distDir, "favicon.ico");
|
|
10611
10766
|
if (!(existsSync20(indexPath) && existsSync20(notFoundPath))) {
|
|
10612
10767
|
throw new Error(`[furin] preview: "${distDir}" is not a Furin static export. Run \`furin build --target static\` first.`);
|
|
10613
10768
|
}
|
|
10614
10769
|
const notFound = () => new Response(Bun.file(notFoundPath), { status: 404 });
|
|
10615
|
-
const clientDir =
|
|
10770
|
+
const clientDir = join23(distDir, "_client");
|
|
10616
10771
|
const fetchStaticFile = async (request) => {
|
|
10617
10772
|
const encodedPathname = new URL(request.url).pathname;
|
|
10618
10773
|
let pathname;
|
|
@@ -10626,7 +10781,7 @@ function startStaticPreview({
|
|
|
10626
10781
|
}
|
|
10627
10782
|
const logicalPath = pathname.slice(basePath.length).replace(LEADING_SLASHES_RE, "");
|
|
10628
10783
|
const exactPath = resolve16(distDir, logicalPath);
|
|
10629
|
-
const relativePath =
|
|
10784
|
+
const relativePath = relative16(distDir, exactPath);
|
|
10630
10785
|
if (relativePath.startsWith("..") || isAbsolute7(relativePath)) {
|
|
10631
10786
|
return notFound();
|
|
10632
10787
|
}
|
|
@@ -10634,7 +10789,7 @@ function startStaticPreview({
|
|
|
10634
10789
|
if (!pathname.endsWith("/") && await exactFile.exists()) {
|
|
10635
10790
|
return new Response(exactFile);
|
|
10636
10791
|
}
|
|
10637
|
-
const indexFile = Bun.file(
|
|
10792
|
+
const indexFile = Bun.file(join23(exactPath, "index.html"));
|
|
10638
10793
|
if (await indexFile.exists()) {
|
|
10639
10794
|
return new Response(indexFile);
|
|
10640
10795
|
}
|
|
@@ -10665,6 +10820,15 @@ function bail(msg) {
|
|
|
10665
10820
|
console.error(`\x1B[31m\u2717\x1B[0m ${msg}`);
|
|
10666
10821
|
process.exit(1);
|
|
10667
10822
|
}
|
|
10823
|
+
function singleApp(pagesDir, style, prefix) {
|
|
10824
|
+
if (!pagesDir) {
|
|
10825
|
+
return;
|
|
10826
|
+
}
|
|
10827
|
+
if (style !== "nextjs" && style !== "tanstack") {
|
|
10828
|
+
bail(`pagesDir ${pagesDir} needs its file-routing style: pass --style nextjs|tanstack or set \`style\` in furin.config.ts.`);
|
|
10829
|
+
}
|
|
10830
|
+
return [{ pagesDir, prefix: normalizePrefix(prefix), style }];
|
|
10831
|
+
}
|
|
10668
10832
|
function resolveCompileMode(flag, configCompile) {
|
|
10669
10833
|
if (flag === "embed") {
|
|
10670
10834
|
return "embed";
|
|
@@ -10752,6 +10916,7 @@ if (command === "dev") {
|
|
|
10752
10916
|
output: { type: "string" },
|
|
10753
10917
|
pagesDir: { type: "string" },
|
|
10754
10918
|
prefix: { type: "string" },
|
|
10919
|
+
style: { type: "string" },
|
|
10755
10920
|
target: { type: "string" }
|
|
10756
10921
|
},
|
|
10757
10922
|
strict: true
|
|
@@ -10787,16 +10952,10 @@ if (command === "dev") {
|
|
|
10787
10952
|
const result = await buildApp({
|
|
10788
10953
|
analyze: values.analyze,
|
|
10789
10954
|
bun: output === undefined ? undefined : { output },
|
|
10790
|
-
apps: values.pagesDir ?? config.pagesDir
|
|
10791
|
-
{
|
|
10792
|
-
pagesDir: values.pagesDir ?? config.pagesDir,
|
|
10793
|
-
prefix: normalizePrefix(values.prefix)
|
|
10794
|
-
}
|
|
10795
|
-
] : config.apps,
|
|
10955
|
+
apps: singleApp(values.pagesDir ?? config.pagesDir, values.style ?? config.style, values.prefix) ?? config.apps,
|
|
10796
10956
|
clientLogging: config.clientLogging ?? false,
|
|
10797
10957
|
compile: resolveCompileMode(compileFlag, config.bun?.compile),
|
|
10798
10958
|
optimizeImports: config.optimizeImports,
|
|
10799
|
-
pagesDir: undefined,
|
|
10800
10959
|
plugins: config.plugins,
|
|
10801
10960
|
serverExternalPackages: values.external,
|
|
10802
10961
|
preload: config.preload,
|
|
@@ -10816,7 +10975,8 @@ if (command === "dev") {
|
|
|
10816
10975
|
args: argv.slice(1),
|
|
10817
10976
|
options: {
|
|
10818
10977
|
config: { type: "string" },
|
|
10819
|
-
pagesDir: { type: "string" }
|
|
10978
|
+
pagesDir: { type: "string" },
|
|
10979
|
+
style: { type: "string" }
|
|
10820
10980
|
},
|
|
10821
10981
|
strict: true
|
|
10822
10982
|
}).values;
|
|
@@ -10825,10 +10985,8 @@ if (command === "dev") {
|
|
|
10825
10985
|
}
|
|
10826
10986
|
const values = rawValues;
|
|
10827
10987
|
const config = await loadCliConfig(process.cwd(), values.config);
|
|
10828
|
-
const pagesDir = values.pagesDir ?? config.pagesDir;
|
|
10829
10988
|
await generateRouteTypes({
|
|
10830
|
-
apps: pagesDir
|
|
10831
|
-
pagesDir: undefined,
|
|
10989
|
+
apps: singleApp(values.pagesDir ?? config.pagesDir, values.style ?? config.style, undefined) ?? config.apps,
|
|
10832
10990
|
plugins: config.plugins,
|
|
10833
10991
|
rootDir: config.rootDir,
|
|
10834
10992
|
serverEntry: config.serverEntry
|
|
@@ -10847,6 +11005,7 @@ BUILD OPTIONS
|
|
|
10847
11005
|
--target ${BUILD_TARGETS.join(" | ")} | all (default: bun)
|
|
10848
11006
|
"package" builds a publishable Elysia-plugin artifact (register.js + factory + client assets)
|
|
10849
11007
|
--pagesDir Pages directory
|
|
11008
|
+
--style File-routing style of --pagesDir: nextjs or tanstack
|
|
10850
11009
|
--prefix Mount prefix for the built app (e.g. /admin) \u2014 pairs with --pagesDir
|
|
10851
11010
|
--config Config file path
|
|
10852
11011
|
--compile server | embed Compile to binary: "server" keeps client on disk, "embed" is self-contained
|
|
@@ -10856,7 +11015,8 @@ BUILD OPTIONS
|
|
|
10856
11015
|
|
|
10857
11016
|
TYPEGEN OPTIONS
|
|
10858
11017
|
Writes furin-env.d.ts for every mounted app (run it before tsc in CI)
|
|
10859
|
-
--pagesDir Pages directory (default: config apps, server entry furin() mounts
|
|
11018
|
+
--pagesDir Pages directory (default: config pagesDir, config apps, then the server entry's furin() mounts)
|
|
11019
|
+
--style File-routing style of --pagesDir: nextjs or tanstack
|
|
10860
11020
|
--config Config file path
|
|
10861
11021
|
|
|
10862
11022
|
PREVIEW OPTIONS
|