@teyik0/furin 0.2.0-alpha.4 → 0.2.0-alpha.5
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/bun.d.ts +17 -1
- package/dist/adapter/package.d.ts +26 -0
- package/dist/build/client.d.ts +1 -1
- package/dist/build/compile-entry.d.ts +3 -3
- package/dist/build/compile-entry.ts +88 -83
- package/dist/build/entry-template.d.ts +35 -9
- package/dist/build/entry-template.ts +106 -56
- package/dist/build/hydrate.d.ts +1 -1
- package/dist/build/index.js +643 -247
- package/dist/build/scan-server.d.ts +10 -4
- package/dist/build/server-routes-entry.d.ts +3 -3
- package/dist/build/server-routes-entry.ts +5 -11
- package/dist/build/ssg-cache.d.ts +1 -1
- package/dist/build/types.d.ts +36 -1
- package/dist/cli/config.d.ts +6 -1
- package/dist/cli/index.js +662 -260
- package/dist/config.d.ts +11 -2
- package/dist/config.js +5 -1
- package/dist/furin.d.ts +36 -18
- package/dist/furin.js +630 -310
- package/dist/server/auto-invalidate/registry.d.ts +8 -1
- package/dist/server/cache/dev-loader.d.ts +3 -2
- package/dist/server/cache/invalidation.d.ts +19 -0
- package/dist/server/cache/isr.d.ts +6 -2
- package/dist/server/cache/registry.d.ts +3 -3
- package/dist/server/cache/ssg.d.ts +6 -2
- package/dist/server/cache/store-view.d.ts +11 -0
- package/dist/server/instance.d.ts +86 -0
- package/dist/server/internal.d.ts +16 -1
- package/dist/server/internal.js +72 -5
- package/dist/server/render/template.d.ts +3 -2
- package/dist/server/sync/config.d.ts +11 -0
- package/dist/server/sync/stream.d.ts +8 -1
- package/dist/shared/prefix.d.ts +15 -0
- package/package.json +6 -1
- package/src/adapter/bun.ts +113 -50
- package/src/adapter/package.ts +206 -0
- package/src/build/client.ts +9 -3
- package/src/build/compile-entry.ts +88 -83
- package/src/build/entry-template.ts +106 -56
- package/src/build/hydrate.ts +4 -2
- package/src/build/index.ts +99 -28
- package/src/build/scan-server.ts +23 -7
- package/src/build/server-routes-entry.ts +5 -11
- package/src/build/ssg-cache.ts +6 -2
- package/src/build/types.ts +37 -1
- package/src/cli/config.ts +9 -3
- package/src/cli/index.ts +21 -3
- package/src/config.ts +14 -1
- package/src/furin.ts +297 -143
- package/src/server/auto-invalidate/registry.ts +23 -1
- package/src/server/auto-invalidate/runtime.ts +29 -4
- package/src/server/cache/dev-loader.ts +77 -38
- package/src/server/cache/invalidation.ts +71 -30
- package/src/server/cache/isr.ts +20 -5
- package/src/server/cache/registry.ts +17 -20
- package/src/server/cache/ssg.ts +19 -4
- package/src/server/cache/store-view.ts +30 -0
- package/src/server/instance.ts +252 -0
- package/src/server/internal.ts +100 -5
- package/src/server/render/not-found.ts +9 -3
- package/src/server/render/ssr.ts +16 -4
- package/src/server/render/template.ts +57 -24
- package/src/server/sync/config.ts +32 -1
- package/src/server/sync/plugin.ts +4 -5
- package/src/server/sync/stream.ts +19 -9
- package/src/shared/prefix.ts +38 -0
package/dist/cli/index.js
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/cli/index.ts
|
|
5
|
-
import { existsSync as
|
|
6
|
-
import { resolve as
|
|
5
|
+
import { existsSync as existsSync11 } from "fs";
|
|
6
|
+
import { resolve as resolve6 } from "path";
|
|
7
7
|
import { parseArgs } from "util";
|
|
8
8
|
|
|
9
9
|
// src/build/index.ts
|
|
10
|
-
import { existsSync as
|
|
11
|
-
import { join as
|
|
10
|
+
import { existsSync as existsSync9, writeFileSync as writeFileSync7 } from "fs";
|
|
11
|
+
import { join as join10, relative as relative5, resolve as resolve4 } from "path";
|
|
12
12
|
|
|
13
13
|
// src/adapter/bun.ts
|
|
14
14
|
import { existsSync as existsSync6, rmSync as rmSync2, writeFileSync as writeFileSync4 } from "fs";
|
|
@@ -1663,10 +1663,127 @@ function validateRouteChain(chain, root, pagePath) {
|
|
|
1663
1663
|
}
|
|
1664
1664
|
}
|
|
1665
1665
|
|
|
1666
|
+
// src/server/instance.ts
|
|
1667
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
1668
|
+
var _requestScope = new AsyncLocalStorage;
|
|
1669
|
+
var WHITESPACE_RE = /\s/;
|
|
1670
|
+
var _instances = new Map;
|
|
1671
|
+
var _defaultInstance = null;
|
|
1672
|
+
function createInstance(prefix, pagesDir) {
|
|
1673
|
+
return {
|
|
1674
|
+
prefix,
|
|
1675
|
+
pagesDir,
|
|
1676
|
+
syncStreamPath: undefined,
|
|
1677
|
+
buildId: "",
|
|
1678
|
+
registrationEpoch: 0,
|
|
1679
|
+
state: new Map
|
|
1680
|
+
};
|
|
1681
|
+
}
|
|
1682
|
+
function defaultInstance() {
|
|
1683
|
+
if (!_defaultInstance) {
|
|
1684
|
+
_defaultInstance = createInstance("", "");
|
|
1685
|
+
}
|
|
1686
|
+
return _defaultInstance;
|
|
1687
|
+
}
|
|
1688
|
+
function defaultInstanceBucket() {
|
|
1689
|
+
return defaultInstance();
|
|
1690
|
+
}
|
|
1691
|
+
function normalizePrefix(prefix) {
|
|
1692
|
+
if (prefix === undefined || prefix === "" || prefix === "/") {
|
|
1693
|
+
return "";
|
|
1694
|
+
}
|
|
1695
|
+
if (!prefix.startsWith("/")) {
|
|
1696
|
+
throw new Error(`[furin] prefix must start with "/" (got "${prefix}").`);
|
|
1697
|
+
}
|
|
1698
|
+
if (prefix.includes("//") || WHITESPACE_RE.test(prefix)) {
|
|
1699
|
+
throw new Error(`[furin] invalid prefix "${prefix}".`);
|
|
1700
|
+
}
|
|
1701
|
+
return prefix.endsWith("/") ? prefix.slice(0, -1) : prefix;
|
|
1702
|
+
}
|
|
1703
|
+
function currentInstance() {
|
|
1704
|
+
const scope = _requestScope.getStore();
|
|
1705
|
+
if (scope) {
|
|
1706
|
+
return scope.instance;
|
|
1707
|
+
}
|
|
1708
|
+
if (_instances.size === 1) {
|
|
1709
|
+
const only = _instances.values().next().value;
|
|
1710
|
+
if (only) {
|
|
1711
|
+
return only;
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
return defaultInstance();
|
|
1715
|
+
}
|
|
1716
|
+
function instanceSlot(init) {
|
|
1717
|
+
const key = Symbol("furin-instance-slot");
|
|
1718
|
+
return (instance) => {
|
|
1719
|
+
const target = instance ?? currentInstance();
|
|
1720
|
+
if (target.state.has(key)) {
|
|
1721
|
+
return target.state.get(key);
|
|
1722
|
+
}
|
|
1723
|
+
const value = init(target);
|
|
1724
|
+
target.state.set(key, value);
|
|
1725
|
+
return value;
|
|
1726
|
+
};
|
|
1727
|
+
}
|
|
1728
|
+
|
|
1666
1729
|
// src/server/internal.ts
|
|
1667
|
-
var
|
|
1668
|
-
function
|
|
1669
|
-
return
|
|
1730
|
+
var _compileContexts = new Map;
|
|
1731
|
+
function normalizeContextKey(path) {
|
|
1732
|
+
return path.replaceAll("\\", "/");
|
|
1733
|
+
}
|
|
1734
|
+
function pagesDirOf(ctx) {
|
|
1735
|
+
const rootPath = normalizeContextKey(ctx.rootPath);
|
|
1736
|
+
const lastSlash = rootPath.lastIndexOf("/");
|
|
1737
|
+
return lastSlash === -1 ? rootPath : rootPath.slice(0, lastSlash);
|
|
1738
|
+
}
|
|
1739
|
+
function contextKey(pagesDir, prefix) {
|
|
1740
|
+
return `${pagesDir}\x00${prefix}`;
|
|
1741
|
+
}
|
|
1742
|
+
function getCompileContext(pagesDir, prefix) {
|
|
1743
|
+
if (pagesDir !== undefined) {
|
|
1744
|
+
const dir = normalizeContextKey(pagesDir);
|
|
1745
|
+
if (prefix !== undefined) {
|
|
1746
|
+
const exact = _compileContexts.get(contextKey(dir, prefix));
|
|
1747
|
+
if (exact) {
|
|
1748
|
+
return exact;
|
|
1749
|
+
}
|
|
1750
|
+
}
|
|
1751
|
+
const dirMatch = soleContextForPagesDir(dir);
|
|
1752
|
+
if (dirMatch) {
|
|
1753
|
+
return dirMatch;
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
if (prefix !== undefined) {
|
|
1757
|
+
const prefixMatch = contextForPrefix(prefix);
|
|
1758
|
+
if (prefixMatch) {
|
|
1759
|
+
return prefixMatch;
|
|
1760
|
+
}
|
|
1761
|
+
}
|
|
1762
|
+
if (_compileContexts.size === 1) {
|
|
1763
|
+
return _compileContexts.values().next().value ?? null;
|
|
1764
|
+
}
|
|
1765
|
+
return null;
|
|
1766
|
+
}
|
|
1767
|
+
function soleContextForPagesDir(dir) {
|
|
1768
|
+
let match = null;
|
|
1769
|
+
for (const ctx of _compileContexts.values()) {
|
|
1770
|
+
if (pagesDirOf(ctx) !== dir) {
|
|
1771
|
+
continue;
|
|
1772
|
+
}
|
|
1773
|
+
if (match) {
|
|
1774
|
+
return null;
|
|
1775
|
+
}
|
|
1776
|
+
match = ctx;
|
|
1777
|
+
}
|
|
1778
|
+
return match;
|
|
1779
|
+
}
|
|
1780
|
+
function contextForPrefix(prefix) {
|
|
1781
|
+
for (const ctx of _compileContexts.values()) {
|
|
1782
|
+
if ((ctx.prefix ?? "") === prefix) {
|
|
1783
|
+
return ctx;
|
|
1784
|
+
}
|
|
1785
|
+
}
|
|
1786
|
+
return null;
|
|
1670
1787
|
}
|
|
1671
1788
|
|
|
1672
1789
|
// src/server/runtime-env.ts
|
|
@@ -2462,8 +2579,9 @@ function buildTargetManifest(rootDir, buildRoot, target, serverEntry) {
|
|
|
2462
2579
|
|
|
2463
2580
|
// src/build/client.ts
|
|
2464
2581
|
var TS_FILE_FILTER = /\.(tsx|ts)$/;
|
|
2465
|
-
async function buildClient(routes, { outDir, rootLayout, plugins, publicPath, basePath, clientLogging }) {
|
|
2466
|
-
const
|
|
2582
|
+
async function buildClient(routes, { outDir, rootLayout, plugins, publicPath, basePath, clientLogging, clientDirName }) {
|
|
2583
|
+
const dirName = clientDirName ?? "client";
|
|
2584
|
+
const clientDir = join3(outDir, dirName);
|
|
2467
2585
|
if (!existsSync3(outDir)) {
|
|
2468
2586
|
mkdirSync2(outDir, { recursive: true });
|
|
2469
2587
|
}
|
|
@@ -2471,7 +2589,7 @@ async function buildClient(routes, { outDir, rootLayout, plugins, publicPath, ba
|
|
|
2471
2589
|
mkdirSync2(clientDir, { recursive: true });
|
|
2472
2590
|
}
|
|
2473
2591
|
const hydrateCode = generateHydrateEntry(routes, rootLayout, basePath, clientLogging);
|
|
2474
|
-
const hydratePath = join3(outDir, "_hydrate.tsx");
|
|
2592
|
+
const hydratePath = join3(outDir, dirName === "client" ? "_hydrate.tsx" : `_hydrate-${dirName}.tsx`);
|
|
2475
2593
|
writeFileSync(hydratePath, hydrateCode);
|
|
2476
2594
|
console.log("[furin] Building production client bundle\u2026");
|
|
2477
2595
|
const transformPlugin = {
|
|
@@ -2577,55 +2695,29 @@ function collectConventionPaths(rootConventions, routeMetadata) {
|
|
|
2577
2695
|
}
|
|
2578
2696
|
return [...new Set(paths)];
|
|
2579
2697
|
}
|
|
2580
|
-
function
|
|
2581
|
-
const {
|
|
2582
|
-
buildId,
|
|
2583
|
-
headerComment,
|
|
2584
|
-
rootPath,
|
|
2585
|
-
routes,
|
|
2586
|
-
serverEntry,
|
|
2587
|
-
rootConventions,
|
|
2588
|
-
routeMetadata,
|
|
2589
|
-
ssgCache
|
|
2590
|
-
} = options;
|
|
2591
|
-
let { extraImports, extraContext } = options;
|
|
2592
|
-
if (extraImports === undefined) {
|
|
2593
|
-
extraImports = [];
|
|
2594
|
-
}
|
|
2595
|
-
if (extraContext === undefined) {
|
|
2596
|
-
extraContext = [];
|
|
2597
|
-
}
|
|
2698
|
+
function buildAppContextBlock(app, varPrefix) {
|
|
2598
2699
|
const allModulePaths = [
|
|
2599
|
-
rootPath,
|
|
2600
|
-
...routes.map((r) => r.path),
|
|
2601
|
-
...collectConventionPaths(rootConventions, routeMetadata)
|
|
2700
|
+
app.rootPath,
|
|
2701
|
+
...app.routes.map((r) => r.path),
|
|
2702
|
+
...collectConventionPaths(app.rootConventions, app.routeMetadata)
|
|
2602
2703
|
];
|
|
2603
|
-
const
|
|
2704
|
+
const importLines = [];
|
|
2604
2705
|
const moduleEntries = [];
|
|
2605
2706
|
for (let i = 0;i < allModulePaths.length; i++) {
|
|
2606
2707
|
const absPath = allModulePaths[i].replace(/\\/g, "/");
|
|
2607
|
-
const varName =
|
|
2608
|
-
|
|
2708
|
+
const varName = `${varPrefix}mod${i}`;
|
|
2709
|
+
importLines.push(`import * as ${varName} from ${JSON.stringify(absPath)};`);
|
|
2609
2710
|
moduleEntries.push(` ${JSON.stringify(absPath)}: ${varName},`);
|
|
2610
2711
|
}
|
|
2611
|
-
const routeEntries = routes.map((r) => ` { pattern: ${JSON.stringify(r.pattern)}, path: ${JSON.stringify(r.path.replace(/\\/g, "/"))}, mode: ${JSON.stringify(r.mode)} },`);
|
|
2612
|
-
const rootConventionsLine = rootConventions ? ` rootConventions: ${JSON.stringify(rootConventions)},` : "";
|
|
2613
|
-
const routeMetadataLine = routeMetadata ? ` routeMetadata: ${JSON.stringify(routeMetadata)},` : "";
|
|
2614
|
-
const ssgCacheLine = ssgCache ? ` ssgCache: ${JSON.stringify(ssgCache)},` : "";
|
|
2615
|
-
const
|
|
2616
|
-
headerComment,
|
|
2617
|
-
`import { __setCompileContext } from ${JSON.stringify(INTERNAL_MODULE_PATH)};`,
|
|
2618
|
-
`import { __setDevMode } from ${JSON.stringify(RUNTIME_ENV_MODULE_PATH)};`,
|
|
2619
|
-
...moduleImports,
|
|
2620
|
-
...extraImports.length > 0 ? ["", ...extraImports] : [],
|
|
2621
|
-
"",
|
|
2622
|
-
"// Force production mode \u2014 Bun may inline process.env.NODE_ENV at bundle time.",
|
|
2623
|
-
"__setDevMode(false);",
|
|
2624
|
-
'process.env.NODE_ENV = "production";',
|
|
2625
|
-
"",
|
|
2712
|
+
const routeEntries = app.routes.map((r) => ` { pattern: ${JSON.stringify(r.pattern)}, path: ${JSON.stringify(r.path.replace(/\\/g, "/"))}, mode: ${JSON.stringify(r.mode)} },`);
|
|
2713
|
+
const rootConventionsLine = app.rootConventions ? ` rootConventions: ${JSON.stringify(app.rootConventions)},` : "";
|
|
2714
|
+
const routeMetadataLine = app.routeMetadata ? ` routeMetadata: ${JSON.stringify(app.routeMetadata)},` : "";
|
|
2715
|
+
const ssgCacheLine = app.ssgCache ? ` ssgCache: ${JSON.stringify(app.ssgCache)},` : "";
|
|
2716
|
+
const contextLines = [
|
|
2626
2717
|
"__setCompileContext({",
|
|
2627
|
-
` buildId: ${JSON.stringify(buildId ?? "")},`,
|
|
2628
|
-
`
|
|
2718
|
+
` buildId: ${JSON.stringify(app.buildId ?? "")},`,
|
|
2719
|
+
` prefix: ${JSON.stringify(app.prefix ?? "")},`,
|
|
2720
|
+
` rootPath: ${JSON.stringify(app.rootPath.replace(/\\/g, "/"))},`,
|
|
2629
2721
|
rootConventionsLine,
|
|
2630
2722
|
" modules: {",
|
|
2631
2723
|
...moduleEntries,
|
|
@@ -2635,87 +2727,113 @@ function buildEntrySource(options) {
|
|
|
2635
2727
|
" ],",
|
|
2636
2728
|
routeMetadataLine,
|
|
2637
2729
|
ssgCacheLine,
|
|
2638
|
-
...extraContext,
|
|
2639
|
-
"});"
|
|
2730
|
+
...app.extraContext ?? [],
|
|
2731
|
+
"});"
|
|
2732
|
+
];
|
|
2733
|
+
return { contextLines, importLines };
|
|
2734
|
+
}
|
|
2735
|
+
function buildEntrySource(options) {
|
|
2736
|
+
const { apps, headerComment, serverEntry } = options;
|
|
2737
|
+
const mode = options.mode ?? "boot";
|
|
2738
|
+
const internalSpecifier = mode === "register" ? "@teyik0/furin/internal" : INTERNAL_MODULE_PATH;
|
|
2739
|
+
const importLines = [];
|
|
2740
|
+
const contextBlocks = [];
|
|
2741
|
+
for (let appIndex = 0;appIndex < apps.length; appIndex++) {
|
|
2742
|
+
const app = apps[appIndex];
|
|
2743
|
+
const varPrefix = apps.length === 1 ? "_" : `_a${appIndex}_`;
|
|
2744
|
+
const block = buildAppContextBlock(app, varPrefix);
|
|
2745
|
+
importLines.push(...block.importLines);
|
|
2746
|
+
if (app.extraImports && app.extraImports.length > 0) {
|
|
2747
|
+
importLines.push("", ...app.extraImports);
|
|
2748
|
+
}
|
|
2749
|
+
contextBlocks.push("", ...block.contextLines);
|
|
2750
|
+
}
|
|
2751
|
+
const lines = [
|
|
2752
|
+
headerComment,
|
|
2753
|
+
`import { __setCompileContext } from ${JSON.stringify(internalSpecifier)};`,
|
|
2754
|
+
...mode === "boot" ? [`import { __setDevMode } from ${JSON.stringify(RUNTIME_ENV_MODULE_PATH)};`] : [],
|
|
2755
|
+
...importLines,
|
|
2756
|
+
...mode === "boot" ? [
|
|
2757
|
+
"",
|
|
2758
|
+
"// Force production mode \u2014 Bun may inline process.env.NODE_ENV at bundle time.",
|
|
2759
|
+
"__setDevMode(false);",
|
|
2760
|
+
'process.env.NODE_ENV = "production";'
|
|
2761
|
+
] : [],
|
|
2762
|
+
...contextBlocks,
|
|
2640
2763
|
"",
|
|
2641
|
-
`await import(${JSON.stringify(serverEntry.replace(/\\/g, "/"))});`,
|
|
2642
|
-
""
|
|
2764
|
+
...serverEntry ? [`await import(${JSON.stringify(serverEntry.replace(/\\/g, "/"))});`, ""] : []
|
|
2643
2765
|
];
|
|
2644
2766
|
return lines.join(`
|
|
2645
2767
|
`);
|
|
2646
2768
|
}
|
|
2647
2769
|
|
|
2648
2770
|
// src/build/compile-entry.ts
|
|
2649
|
-
function
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
routes,
|
|
2655
|
-
serverEntry,
|
|
2656
|
-
embed,
|
|
2657
|
-
publicDir,
|
|
2658
|
-
rootConventions,
|
|
2659
|
-
routeMetadata,
|
|
2660
|
-
ssgCache
|
|
2661
|
-
} = options;
|
|
2662
|
-
ensureDir(outDir);
|
|
2771
|
+
function buildEmbeddedAssets(outDir, clientDir, publicDir, varPrefix) {
|
|
2772
|
+
if (!existsSync5(clientDir)) {
|
|
2773
|
+
throw new Error(`[furin] Client directory not found: ${clientDir}. Run the client build first.`);
|
|
2774
|
+
}
|
|
2775
|
+
const clientFiles = collectFilesRecursive(clientDir).filter((file) => !file.endsWith(".map"));
|
|
2663
2776
|
const assetImports = [];
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
}
|
|
2669
|
-
const
|
|
2670
|
-
const
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
} else {
|
|
2682
|
-
assetEntries.push(` ${JSON.stringify(`/_client/${clientRelativePath}`)}: ${varName},`);
|
|
2683
|
-
}
|
|
2777
|
+
const assetEntries = [];
|
|
2778
|
+
let templateVarName = null;
|
|
2779
|
+
let assetIndex = 0;
|
|
2780
|
+
const importAsset = (file) => {
|
|
2781
|
+
const varName = `${varPrefix}asset${assetIndex++}`;
|
|
2782
|
+
const relPath = toPosixPath2(relative2(outDir, file));
|
|
2783
|
+
const importPath = relPath.startsWith(".") ? relPath : `./${relPath}`;
|
|
2784
|
+
assetImports.push(`import ${varName} from ${JSON.stringify(importPath)} with { type: "file" };`);
|
|
2785
|
+
return varName;
|
|
2786
|
+
};
|
|
2787
|
+
for (const file of clientFiles) {
|
|
2788
|
+
const varName = importAsset(file);
|
|
2789
|
+
const clientRelativePath = toPosixPath2(relative2(clientDir, file));
|
|
2790
|
+
if (clientRelativePath === "index.html") {
|
|
2791
|
+
templateVarName = varName;
|
|
2792
|
+
} else {
|
|
2793
|
+
assetEntries.push(` ${JSON.stringify(`/_client/${clientRelativePath}`)}: ${varName},`);
|
|
2684
2794
|
}
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
}
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
const publicRelativePath = toPosixPath2(relative2(publicDir, file));
|
|
2696
|
-
assetEntries.push(` ${JSON.stringify(`/public/${publicRelativePath}`)}: ${varName},`);
|
|
2697
|
-
}
|
|
2795
|
+
}
|
|
2796
|
+
if (templateVarName === null) {
|
|
2797
|
+
throw new Error(`[furin] Embed mode requires a client index.html at ${join5(clientDir, "index.html")}. Run the client build first.`);
|
|
2798
|
+
}
|
|
2799
|
+
if (publicDir && existsSync5(publicDir)) {
|
|
2800
|
+
const publicFiles = collectFilesRecursive(publicDir);
|
|
2801
|
+
for (const file of publicFiles) {
|
|
2802
|
+
const varName = importAsset(file);
|
|
2803
|
+
const publicRelativePath = toPosixPath2(relative2(publicDir, file));
|
|
2804
|
+
assetEntries.push(` ${JSON.stringify(`/public/${publicRelativePath}`)}: ${varName},`);
|
|
2698
2805
|
}
|
|
2699
|
-
embeddedBlock = [
|
|
2700
|
-
" embedded: {",
|
|
2701
|
-
` template: ${templateVarName},`,
|
|
2702
|
-
" assets: {",
|
|
2703
|
-
...assetEntries,
|
|
2704
|
-
" },",
|
|
2705
|
-
" },"
|
|
2706
|
-
];
|
|
2707
2806
|
}
|
|
2807
|
+
const extraContext = [
|
|
2808
|
+
" embedded: {",
|
|
2809
|
+
` template: ${templateVarName},`,
|
|
2810
|
+
" assets: {",
|
|
2811
|
+
...assetEntries,
|
|
2812
|
+
" },",
|
|
2813
|
+
" },"
|
|
2814
|
+
];
|
|
2815
|
+
return { extraContext, extraImports: assetImports };
|
|
2816
|
+
}
|
|
2817
|
+
function generateCompileEntry(options) {
|
|
2818
|
+
const { apps, outDir, serverEntry, publicDir } = options;
|
|
2819
|
+
ensureDir(outDir);
|
|
2820
|
+
const preparedApps = apps.map((app, appIndex) => {
|
|
2821
|
+
const { embed, ...context } = app;
|
|
2822
|
+
if (!embed) {
|
|
2823
|
+
return context;
|
|
2824
|
+
}
|
|
2825
|
+
const varPrefix = apps.length === 1 ? "_" : `_a${appIndex}_`;
|
|
2826
|
+
const embedded = buildEmbeddedAssets(outDir, embed.clientDir, publicDir, varPrefix);
|
|
2827
|
+
return {
|
|
2828
|
+
...context,
|
|
2829
|
+
extraContext: [...context.extraContext ?? [], ...embedded.extraContext],
|
|
2830
|
+
extraImports: [...context.extraImports ?? [], ...embedded.extraImports]
|
|
2831
|
+
};
|
|
2832
|
+
});
|
|
2708
2833
|
const source = buildEntrySource({
|
|
2709
|
-
|
|
2710
|
-
headerComment: "// Auto-generated by furin compile \u2014 do not edit",
|
|
2711
|
-
|
|
2712
|
-
routes,
|
|
2713
|
-
serverEntry,
|
|
2714
|
-
extraImports: assetImports,
|
|
2715
|
-
extraContext: embeddedBlock,
|
|
2716
|
-
rootConventions,
|
|
2717
|
-
routeMetadata,
|
|
2718
|
-
ssgCache
|
|
2834
|
+
apps: preparedApps,
|
|
2835
|
+
headerComment: options.headerComment ?? "// Auto-generated by furin compile \u2014 do not edit",
|
|
2836
|
+
serverEntry
|
|
2719
2837
|
});
|
|
2720
2838
|
const entryPath = join5(outDir, "_compile-entry.ts");
|
|
2721
2839
|
writeFileSync2(entryPath, source);
|
|
@@ -2726,17 +2844,12 @@ function generateCompileEntry(options) {
|
|
|
2726
2844
|
import { writeFileSync as writeFileSync3 } from "fs";
|
|
2727
2845
|
import { join as join6 } from "path";
|
|
2728
2846
|
function generateServerRoutesEntry(options) {
|
|
2729
|
-
const {
|
|
2847
|
+
const { apps, outDir, serverEntry } = options;
|
|
2730
2848
|
ensureDir(outDir);
|
|
2731
2849
|
const source = buildEntrySource({
|
|
2732
|
-
|
|
2850
|
+
apps: apps.map(({ embed: _embed, ...context }) => context),
|
|
2733
2851
|
headerComment: "// Auto-generated by furin build \u2014 do not edit",
|
|
2734
|
-
|
|
2735
|
-
routes,
|
|
2736
|
-
serverEntry,
|
|
2737
|
-
rootConventions,
|
|
2738
|
-
routeMetadata,
|
|
2739
|
-
ssgCache
|
|
2852
|
+
serverEntry
|
|
2740
2853
|
});
|
|
2741
2854
|
const entryPath = join6(outDir, "server.ts");
|
|
2742
2855
|
writeFileSync3(entryPath, source);
|
|
@@ -2794,7 +2907,13 @@ class AutoInvalidateRegistry {
|
|
|
2794
2907
|
this.tagToPaths.clear();
|
|
2795
2908
|
}
|
|
2796
2909
|
}
|
|
2797
|
-
var
|
|
2910
|
+
var instanceAutoInvalidateRegistry = instanceSlot(() => new AutoInvalidateRegistry);
|
|
2911
|
+
var autoInvalidateRegistry = {
|
|
2912
|
+
registerLoaderTags: (urlPath, tags) => instanceAutoInvalidateRegistry().registerLoaderTags(urlPath, tags),
|
|
2913
|
+
pathsForTags: (tags) => instanceAutoInvalidateRegistry().pathsForTags(tags),
|
|
2914
|
+
unregisterPath: (urlPath) => instanceAutoInvalidateRegistry().unregisterPath(urlPath),
|
|
2915
|
+
reset: () => instanceAutoInvalidateRegistry().reset()
|
|
2916
|
+
};
|
|
2798
2917
|
|
|
2799
2918
|
// src/server/cache/route-cache.ts
|
|
2800
2919
|
function defaultPathFromKey(key) {
|
|
@@ -2898,19 +3017,60 @@ function createHtmlRouteCache(mode) {
|
|
|
2898
3017
|
});
|
|
2899
3018
|
}
|
|
2900
3019
|
|
|
3020
|
+
// src/server/cache/registry.ts
|
|
3021
|
+
var instanceInvalidators = instanceSlot(() => new Map);
|
|
3022
|
+
function registerCacheInvalidator(invalidator, instance) {
|
|
3023
|
+
const invalidators = instanceInvalidators(instance);
|
|
3024
|
+
const existing = invalidators.get(invalidator.name);
|
|
3025
|
+
if (existing !== undefined && existing !== invalidator) {
|
|
3026
|
+
throw new Error(`Cache invalidator "${invalidator.name}" is already registered for this furin instance with a different invalidator object.`);
|
|
3027
|
+
}
|
|
3028
|
+
invalidators.set(invalidator.name, invalidator);
|
|
3029
|
+
return () => {
|
|
3030
|
+
if (invalidators.get(invalidator.name) === invalidator) {
|
|
3031
|
+
invalidators.delete(invalidator.name);
|
|
3032
|
+
}
|
|
3033
|
+
};
|
|
3034
|
+
}
|
|
3035
|
+
|
|
3036
|
+
// src/server/cache/store-view.ts
|
|
3037
|
+
function createStoreView(resolve) {
|
|
3038
|
+
return {
|
|
3039
|
+
clear: () => resolve().clear(),
|
|
3040
|
+
delete: (key) => resolve().delete(key),
|
|
3041
|
+
entries: () => resolve().entries(),
|
|
3042
|
+
get: (key) => resolve().get(key),
|
|
3043
|
+
has: (key) => resolve().has(key),
|
|
3044
|
+
keys: () => resolve().keys(),
|
|
3045
|
+
set: (key, entry) => {
|
|
3046
|
+
resolve().set(key, entry);
|
|
3047
|
+
},
|
|
3048
|
+
get size() {
|
|
3049
|
+
return resolve().size;
|
|
3050
|
+
}
|
|
3051
|
+
};
|
|
3052
|
+
}
|
|
3053
|
+
|
|
2901
3054
|
// src/server/cache/ssg.ts
|
|
2902
|
-
var
|
|
2903
|
-
|
|
3055
|
+
var instanceSsgCache = instanceSlot((instance) => {
|
|
3056
|
+
const cache = createHtmlRouteCache("ssg");
|
|
3057
|
+
registerCacheInvalidator(cache, instance);
|
|
3058
|
+
return cache;
|
|
3059
|
+
});
|
|
3060
|
+
function ssgRouteCache(instance) {
|
|
3061
|
+
return instanceSsgCache(instance);
|
|
3062
|
+
}
|
|
3063
|
+
var ssgCache = createStoreView(() => instanceSsgCache().store);
|
|
2904
3064
|
function getSSGCache(key) {
|
|
2905
|
-
return
|
|
3065
|
+
return instanceSsgCache().get(key);
|
|
2906
3066
|
}
|
|
2907
3067
|
function setSSGCache(key, entry) {
|
|
2908
|
-
|
|
3068
|
+
instanceSsgCache().set(key, entry);
|
|
2909
3069
|
autoInvalidateRegistry.registerLoaderTags(key, entry.tags);
|
|
2910
3070
|
}
|
|
2911
3071
|
|
|
2912
3072
|
// src/server/context-logger.ts
|
|
2913
|
-
import { AsyncLocalStorage as
|
|
3073
|
+
import { AsyncLocalStorage as AsyncLocalStorage3 } from "async_hooks";
|
|
2914
3074
|
// ../../node_modules/.bun/evlog@2.19.2+7724ce3de6b3bca4/node_modules/evlog/dist/utils.mjs
|
|
2915
3075
|
function formatDuration(ms) {
|
|
2916
3076
|
if (ms < 1000)
|
|
@@ -5099,9 +5259,9 @@ function defineFrameworkIntegration(spec) {
|
|
|
5099
5259
|
}
|
|
5100
5260
|
|
|
5101
5261
|
// ../../node_modules/.bun/evlog@2.19.2+7724ce3de6b3bca4/node_modules/evlog/dist/elysia/index.mjs
|
|
5102
|
-
import { AsyncLocalStorage } from "async_hooks";
|
|
5262
|
+
import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
|
|
5103
5263
|
import { Elysia } from "elysia";
|
|
5104
|
-
var storage = new
|
|
5264
|
+
var storage = new AsyncLocalStorage2;
|
|
5105
5265
|
var activeLoggers = /* @__PURE__ */ new WeakSet;
|
|
5106
5266
|
function useLogger2() {
|
|
5107
5267
|
const logger = storage.getStore();
|
|
@@ -5145,7 +5305,7 @@ var noopLogger2 = {
|
|
|
5145
5305
|
getContext: () => ({}),
|
|
5146
5306
|
fork: (_label, fn) => fn()
|
|
5147
5307
|
};
|
|
5148
|
-
var syntheticRenderStorage = new
|
|
5308
|
+
var syntheticRenderStorage = new AsyncLocalStorage3;
|
|
5149
5309
|
function useLogger3() {
|
|
5150
5310
|
try {
|
|
5151
5311
|
return useLogger2();
|
|
@@ -5167,10 +5327,14 @@ async function runInSyntheticRenderScope(fn, initialContext) {
|
|
|
5167
5327
|
}
|
|
5168
5328
|
|
|
5169
5329
|
// src/server/sync/config.ts
|
|
5170
|
-
import { AsyncLocalStorage as
|
|
5171
|
-
var requestSyncStreamPath = new
|
|
5330
|
+
import { AsyncLocalStorage as AsyncLocalStorage4 } from "async_hooks";
|
|
5331
|
+
var requestSyncStreamPath = new AsyncLocalStorage4;
|
|
5172
5332
|
function getSyncStreamPath() {
|
|
5173
|
-
|
|
5333
|
+
const override = requestSyncStreamPath.getStore();
|
|
5334
|
+
if (override !== undefined) {
|
|
5335
|
+
return override;
|
|
5336
|
+
}
|
|
5337
|
+
return currentInstance().syncStreamPath;
|
|
5174
5338
|
}
|
|
5175
5339
|
|
|
5176
5340
|
// src/server/render/assemble.ts
|
|
@@ -6311,6 +6475,12 @@ function normalizeHref(href) {
|
|
|
6311
6475
|
}
|
|
6312
6476
|
return pathname + url.search + url.hash;
|
|
6313
6477
|
}
|
|
6478
|
+
function toLogical(physicalPathname, basePath) {
|
|
6479
|
+
if (basePath && physicalPathname.startsWith(basePath) && (physicalPathname.length === basePath.length || physicalPathname[basePath.length] === "/")) {
|
|
6480
|
+
return physicalPathname.slice(basePath.length) || "/";
|
|
6481
|
+
}
|
|
6482
|
+
return physicalPathname;
|
|
6483
|
+
}
|
|
6314
6484
|
// src/client/router/search-store.ts
|
|
6315
6485
|
import { createContext as createContext2 } from "react";
|
|
6316
6486
|
function searchSnapshotChanged(a, b) {
|
|
@@ -7217,36 +7387,46 @@ async function runLoaders(route, ctx) {
|
|
|
7217
7387
|
|
|
7218
7388
|
// src/server/render/template.ts
|
|
7219
7389
|
import { readFileSync } from "fs";
|
|
7220
|
-
var
|
|
7221
|
-
var _prodTemplateContent = null;
|
|
7222
|
-
var _devTemplateCache = null;
|
|
7390
|
+
var instanceTemplateState = instanceSlot(() => ({ devCache: null, prodContent: null, prodPath: null }));
|
|
7223
7391
|
var DEV_TEMPLATE_TTL_MS = 1000;
|
|
7224
7392
|
async function getDevTemplate(origin) {
|
|
7225
|
-
|
|
7226
|
-
|
|
7393
|
+
const instance = currentInstance();
|
|
7394
|
+
const state = instanceTemplateState(instance);
|
|
7395
|
+
if (state.devCache && Date.now() - state.devCache.ts < DEV_TEMPLATE_TTL_MS) {
|
|
7396
|
+
return state.devCache.html;
|
|
7227
7397
|
}
|
|
7228
|
-
const
|
|
7398
|
+
const entryPath = `${instance.prefix}/_bun_hmr_entry`;
|
|
7399
|
+
const r = await fetch(`${origin}${entryPath}`);
|
|
7229
7400
|
if (!r.ok) {
|
|
7230
|
-
throw new Error(
|
|
7401
|
+
throw new Error(`${entryPath} returned ${r.status}`);
|
|
7231
7402
|
}
|
|
7232
7403
|
const html = await r.text();
|
|
7233
|
-
|
|
7404
|
+
state.devCache = { html, ts: Date.now() };
|
|
7234
7405
|
return html;
|
|
7235
7406
|
}
|
|
7236
|
-
function setProductionTemplateContent(content) {
|
|
7237
|
-
|
|
7238
|
-
|
|
7407
|
+
function setProductionTemplateContent(content, instance) {
|
|
7408
|
+
const state = instanceTemplateState(instance);
|
|
7409
|
+
state.prodPath = null;
|
|
7410
|
+
state.prodContent = content;
|
|
7239
7411
|
}
|
|
7240
7412
|
function getProductionTemplate() {
|
|
7241
|
-
|
|
7242
|
-
|
|
7413
|
+
const own = readTemplate(instanceTemplateState());
|
|
7414
|
+
if (own !== null) {
|
|
7415
|
+
return own;
|
|
7416
|
+
}
|
|
7417
|
+
const fallback = instanceTemplateState(defaultInstanceBucket());
|
|
7418
|
+
return readTemplate(fallback);
|
|
7419
|
+
}
|
|
7420
|
+
function readTemplate(state) {
|
|
7421
|
+
if (state.prodContent !== null) {
|
|
7422
|
+
return state.prodContent;
|
|
7243
7423
|
}
|
|
7244
|
-
if (!
|
|
7424
|
+
if (!state.prodPath) {
|
|
7245
7425
|
return null;
|
|
7246
7426
|
}
|
|
7247
7427
|
try {
|
|
7248
|
-
|
|
7249
|
-
return
|
|
7428
|
+
state.prodContent = readFileSync(state.prodPath, "utf8");
|
|
7429
|
+
return state.prodContent;
|
|
7250
7430
|
} catch {
|
|
7251
7431
|
return null;
|
|
7252
7432
|
}
|
|
@@ -7261,10 +7441,10 @@ function assertDeferredModeAllowed(route, deferredPromises) {
|
|
|
7261
7441
|
throw new Error(`[furin] page "${route.pattern}" returned defer() but the route is rendered in "${route.mode}" mode. ` + "defer() streams data progressively and is only supported in SSR. " + "Return the data directly (await it inside the loader) or switch the route to SSR mode.");
|
|
7262
7442
|
}
|
|
7263
7443
|
}
|
|
7264
|
-
function currentHrefFromContext(ctx) {
|
|
7444
|
+
function currentHrefFromContext(ctx, basePath) {
|
|
7265
7445
|
const pathUrl = new URL(ctx.path, "http://furin.local");
|
|
7266
7446
|
const requestUrl = new URL(ctx.request.url);
|
|
7267
|
-
return normalizeHref(pathUrl.pathname) + (pathUrl.search || requestUrl.search);
|
|
7447
|
+
return normalizeHref(toLogical(pathUrl.pathname, basePath)) + (pathUrl.search || requestUrl.search);
|
|
7268
7448
|
}
|
|
7269
7449
|
function buildSuccessRender(route, root, componentProps, throwOnFailure) {
|
|
7270
7450
|
try {
|
|
@@ -7326,9 +7506,10 @@ async function prepareRender(route, ctx, root, basePath, throwOnFailure, precomp
|
|
|
7326
7506
|
errorDigest = success.errorDigest;
|
|
7327
7507
|
status = success.status;
|
|
7328
7508
|
}
|
|
7509
|
+
const resolvedBasePath = basePath ?? currentInstance().prefix;
|
|
7329
7510
|
const ssrContext = {
|
|
7330
|
-
basePath:
|
|
7331
|
-
currentHref: currentHrefFromContext(ctx),
|
|
7511
|
+
basePath: resolvedBasePath,
|
|
7512
|
+
currentHref: currentHrefFromContext(ctx, resolvedBasePath),
|
|
7332
7513
|
search: ctx.query ?? {},
|
|
7333
7514
|
searchRoutes: searchRoutes ?? [],
|
|
7334
7515
|
navigate: (_href, _opts) => Promise.resolve(),
|
|
@@ -7432,7 +7613,7 @@ async function prerenderSSG(route, params, root, origin, basePath, searchRoutes)
|
|
|
7432
7613
|
return entry;
|
|
7433
7614
|
}
|
|
7434
7615
|
// src/build/ssg-cache.ts
|
|
7435
|
-
async function buildSSGCacheSnapshot(routes, root, origin) {
|
|
7616
|
+
async function buildSSGCacheSnapshot(routes, root, origin, basePath) {
|
|
7436
7617
|
const snapshot = {};
|
|
7437
7618
|
const searchRoutes = createSearchRouteMetadata(routes);
|
|
7438
7619
|
for (const route of routes) {
|
|
@@ -7441,7 +7622,7 @@ async function buildSSGCacheSnapshot(routes, root, origin) {
|
|
|
7441
7622
|
}
|
|
7442
7623
|
const paramSets = await route.page.staticParams();
|
|
7443
7624
|
for (const params of paramSets) {
|
|
7444
|
-
const entry = await prerenderSSG(route, params, root, origin,
|
|
7625
|
+
const entry = await prerenderSSG(route, params, root, origin, basePath, searchRoutes);
|
|
7445
7626
|
if (entry instanceof Response) {
|
|
7446
7627
|
continue;
|
|
7447
7628
|
}
|
|
@@ -7451,6 +7632,25 @@ async function buildSSGCacheSnapshot(routes, root, origin) {
|
|
|
7451
7632
|
return snapshot;
|
|
7452
7633
|
}
|
|
7453
7634
|
|
|
7635
|
+
// src/shared/prefix.ts
|
|
7636
|
+
function clientDirNameForPrefix(prefix) {
|
|
7637
|
+
return prefix === "" ? "client" : `client-${prefixSlug(prefix)}`;
|
|
7638
|
+
}
|
|
7639
|
+
function prefixSlug(prefix) {
|
|
7640
|
+
return prefix.slice(1).replaceAll("/", "-");
|
|
7641
|
+
}
|
|
7642
|
+
function assertNoPrefixSlugCollisions(prefixes) {
|
|
7643
|
+
const byDirName = new Map;
|
|
7644
|
+
for (const prefix of prefixes) {
|
|
7645
|
+
const dirName = clientDirNameForPrefix(prefix);
|
|
7646
|
+
const existing = byDirName.get(dirName);
|
|
7647
|
+
if (existing !== undefined && existing !== prefix) {
|
|
7648
|
+
throw new Error(`[furin] prefixes "${existing}" and "${prefix}" both map to the client directory ` + `"${dirName}" \u2014 rename one of them so their slugs (\`/\` \u2192 \`-\`) no longer collide.`);
|
|
7649
|
+
}
|
|
7650
|
+
byDirName.set(dirName, prefix);
|
|
7651
|
+
}
|
|
7652
|
+
}
|
|
7653
|
+
|
|
7454
7654
|
// src/adapter/bun.ts
|
|
7455
7655
|
var _pkgRoot2 = dirname2(dirname2(fileURLToPath3(import.meta.resolve("@teyik0/furin"))));
|
|
7456
7656
|
var _pkgSrcDir2 = existsSync6(join7(_pkgRoot2, "src", "furin.ts")) ? join7(_pkgRoot2, "src") : join7(_pkgRoot2, "dist");
|
|
@@ -7516,52 +7716,79 @@ function buildCompileMetadata(root, routes) {
|
|
|
7516
7716
|
}
|
|
7517
7717
|
return { rootConventions, routeMetadata };
|
|
7518
7718
|
}
|
|
7519
|
-
async function
|
|
7520
|
-
|
|
7521
|
-
|
|
7522
|
-
}
|
|
7523
|
-
const target = "bun";
|
|
7524
|
-
const targetManifest = buildTargetManifest(rootDir, buildRoot, target, serverEntry);
|
|
7525
|
-
const targetDir = resolve(rootDir, targetManifest.targetDir);
|
|
7526
|
-
rmSync2(targetDir, { force: true, recursive: true });
|
|
7527
|
-
ensureDir(targetDir);
|
|
7719
|
+
async function buildOneApp(app, targetDir, serverEntry, options) {
|
|
7720
|
+
const { prefix, root, routes } = app;
|
|
7721
|
+
const clientDirName = clientDirNameForPrefix(prefix);
|
|
7722
|
+
const label = prefix === "" ? "root app" : `app "${prefix}"`;
|
|
7528
7723
|
const { entryChunk, cssChunks } = await buildClient(routes, {
|
|
7529
7724
|
outDir: targetDir,
|
|
7530
7725
|
rootLayout: root.path,
|
|
7531
7726
|
plugins: options.plugins,
|
|
7532
|
-
publicPath:
|
|
7533
|
-
basePath:
|
|
7534
|
-
clientLogging: options.clientLogging ?? false
|
|
7727
|
+
publicPath: `${prefix}/_client/`,
|
|
7728
|
+
basePath: prefix,
|
|
7729
|
+
clientLogging: options.clientLogging ?? false,
|
|
7730
|
+
clientDirName
|
|
7535
7731
|
});
|
|
7536
|
-
const buildFingerprint = await createBuildFingerprint(
|
|
7732
|
+
const buildFingerprint = await createBuildFingerprint(`${prefix}
|
|
7733
|
+
${entryChunk}`, cssChunks, routes, root, serverEntry);
|
|
7537
7734
|
const buildId = Bun.hash(buildFingerprint).toString(16).slice(0, 12);
|
|
7538
|
-
|
|
7539
|
-
const clientDir = join7(targetDir, "client");
|
|
7735
|
+
const clientDir = join7(targetDir, clientDirName);
|
|
7540
7736
|
const indexHtml = generateProdIndexHtml(entryChunk, cssChunks, buildId, undefined, false);
|
|
7541
7737
|
writeFileSync4(join7(clientDir, "index.html"), indexHtml);
|
|
7542
7738
|
setProductionTemplateContent(indexHtml);
|
|
7543
|
-
|
|
7544
|
-
const ssgCache2 = serverEntry ? await buildSSGCacheSnapshot(routes, root, "http://localhost") : undefined;
|
|
7739
|
+
ssgRouteCache().clear();
|
|
7740
|
+
const ssgCache2 = serverEntry ? await buildSSGCacheSnapshot(routes, root, "http://localhost", prefix) : undefined;
|
|
7741
|
+
const { rootConventions, routeMetadata } = buildCompileMetadata(root, routes);
|
|
7742
|
+
console.log(`[furin] Built ${label} (buildId ${buildId})`);
|
|
7743
|
+
return {
|
|
7744
|
+
buildId,
|
|
7745
|
+
entryApp: {
|
|
7746
|
+
buildId,
|
|
7747
|
+
prefix,
|
|
7748
|
+
rootPath: root.path,
|
|
7749
|
+
routes: routes.map((r) => ({ pattern: r.pattern, path: r.path, mode: r.mode })),
|
|
7750
|
+
rootConventions,
|
|
7751
|
+
routeMetadata,
|
|
7752
|
+
ssgCache: ssgCache2,
|
|
7753
|
+
embed: options.compile === "embed" ? { clientDir } : undefined
|
|
7754
|
+
},
|
|
7755
|
+
hydrateIntermediate: clientDirName === "client" ? "_hydrate.tsx" : `_hydrate-${clientDirName}.tsx`
|
|
7756
|
+
};
|
|
7757
|
+
}
|
|
7758
|
+
async function buildBunTarget(apps, rootDir, buildRoot, serverEntry, options) {
|
|
7759
|
+
if (options.compile && !serverEntry) {
|
|
7760
|
+
throw new Error(`[furin] \`compile: "${options.compile}"\` requires a server entry point. ` + "Create src/server.ts or set `serverEntry` in your furin.config.ts.");
|
|
7761
|
+
}
|
|
7762
|
+
if (apps.length === 0) {
|
|
7763
|
+
throw new Error("[furin] buildBunTarget requires at least one app.");
|
|
7764
|
+
}
|
|
7765
|
+
const target = "bun";
|
|
7766
|
+
const targetManifest = buildTargetManifest(rootDir, buildRoot, target, serverEntry);
|
|
7767
|
+
const targetDir = resolve(rootDir, targetManifest.targetDir);
|
|
7768
|
+
rmSync2(targetDir, { force: true, recursive: true });
|
|
7769
|
+
ensureDir(targetDir);
|
|
7545
7770
|
const publicDir = existsSync6(join7(rootDir, "public")) ? join7(rootDir, "public") : undefined;
|
|
7771
|
+
const entryApps = [];
|
|
7772
|
+
const hydrateIntermediates = [];
|
|
7773
|
+
for (const app of apps) {
|
|
7774
|
+
const built = await buildOneApp(app, targetDir, serverEntry, options);
|
|
7775
|
+
entryApps.push(built.entryApp);
|
|
7776
|
+
hydrateIntermediates.push(built.hydrateIntermediate);
|
|
7777
|
+
if (app.prefix === "" || targetManifest.buildId === "") {
|
|
7778
|
+
targetManifest.buildId = built.buildId;
|
|
7779
|
+
}
|
|
7780
|
+
}
|
|
7546
7781
|
const targetPublicDir = publicDir ? join7(targetDir, "public") : undefined;
|
|
7547
7782
|
if (publicDir && targetPublicDir && options.compile !== "embed") {
|
|
7548
7783
|
copyDirRecursive(publicDir, targetPublicDir);
|
|
7549
7784
|
}
|
|
7550
|
-
const { rootConventions, routeMetadata } = buildCompileMetadata(root, routes);
|
|
7551
7785
|
if (options.compile && serverEntry) {
|
|
7552
|
-
const clientDir2 = join7(targetDir, "client");
|
|
7553
7786
|
const outfile = join7(targetDir, "server");
|
|
7554
7787
|
const entryPath = generateCompileEntry({
|
|
7555
|
-
|
|
7556
|
-
rootPath: root.path,
|
|
7557
|
-
routes: routeManifest,
|
|
7788
|
+
apps: entryApps,
|
|
7558
7789
|
serverEntry,
|
|
7559
7790
|
outDir: targetDir,
|
|
7560
|
-
|
|
7561
|
-
publicDir,
|
|
7562
|
-
rootConventions,
|
|
7563
|
-
routeMetadata,
|
|
7564
|
-
ssgCache: ssgCache2
|
|
7791
|
+
publicDir
|
|
7565
7792
|
});
|
|
7566
7793
|
await Bun.build({
|
|
7567
7794
|
entrypoints: [entryPath],
|
|
@@ -7574,20 +7801,20 @@ async function buildBunTarget(routes, rootDir, buildRoot, root, serverEntry, opt
|
|
|
7574
7801
|
console.log(`[furin] Server binary: ${outfile}`);
|
|
7575
7802
|
targetManifest.serverPath = toPosixPath2(join7(targetManifest.targetDir, "server"));
|
|
7576
7803
|
if (options.compile === "embed") {
|
|
7577
|
-
|
|
7804
|
+
for (const app of apps) {
|
|
7805
|
+
rmSync2(join7(targetDir, clientDirNameForPrefix(app.prefix)), {
|
|
7806
|
+
force: true,
|
|
7807
|
+
recursive: true
|
|
7808
|
+
});
|
|
7809
|
+
}
|
|
7578
7810
|
targetManifest.clientDir = null;
|
|
7579
7811
|
targetManifest.templatePath = null;
|
|
7580
7812
|
}
|
|
7581
7813
|
} else if (serverEntry) {
|
|
7582
7814
|
const entryPath = generateServerRoutesEntry({
|
|
7583
|
-
|
|
7584
|
-
rootPath: root.path,
|
|
7585
|
-
routes: routeManifest,
|
|
7815
|
+
apps: entryApps,
|
|
7586
7816
|
serverEntry,
|
|
7587
|
-
outDir: targetDir
|
|
7588
|
-
rootConventions,
|
|
7589
|
-
routeMetadata,
|
|
7590
|
-
ssgCache: ssgCache2
|
|
7817
|
+
outDir: targetDir
|
|
7591
7818
|
});
|
|
7592
7819
|
await Bun.build({
|
|
7593
7820
|
entrypoints: [entryPath],
|
|
@@ -7604,25 +7831,147 @@ async function buildBunTarget(routes, rootDir, buildRoot, root, serverEntry, opt
|
|
|
7604
7831
|
"_compile-entry.ts",
|
|
7605
7832
|
"_compile-entry.js.map",
|
|
7606
7833
|
"server.ts",
|
|
7607
|
-
|
|
7834
|
+
...hydrateIntermediates
|
|
7608
7835
|
]) {
|
|
7609
7836
|
rmSync2(join7(targetDir, file), { force: true });
|
|
7610
7837
|
}
|
|
7611
7838
|
return targetManifest;
|
|
7612
7839
|
}
|
|
7613
7840
|
|
|
7841
|
+
// src/adapter/package.ts
|
|
7842
|
+
import { existsSync as existsSync7, rmSync as rmSync3, writeFileSync as writeFileSync5 } from "fs";
|
|
7843
|
+
import { join as join8, relative as relative3, resolve as resolve2 } from "path";
|
|
7844
|
+
async function buildPackageTarget(app, rootDir, buildRoot, options) {
|
|
7845
|
+
const { prefix, root, routes, pagesDir } = app;
|
|
7846
|
+
const targetDir = join8(buildRoot, "package");
|
|
7847
|
+
rmSync3(targetDir, { force: true, recursive: true });
|
|
7848
|
+
ensureDir(targetDir);
|
|
7849
|
+
const { entryChunk, cssChunks } = await buildClient(routes, {
|
|
7850
|
+
outDir: targetDir,
|
|
7851
|
+
rootLayout: root.path,
|
|
7852
|
+
plugins: options.plugins,
|
|
7853
|
+
publicPath: `${prefix}/_client/`,
|
|
7854
|
+
basePath: prefix,
|
|
7855
|
+
clientLogging: options.clientLogging ?? false
|
|
7856
|
+
});
|
|
7857
|
+
const buildFingerprint = await createBuildFingerprint(`${prefix}
|
|
7858
|
+
${entryChunk}`, cssChunks, routes, root, null);
|
|
7859
|
+
const buildId = Bun.hash(buildFingerprint).toString(16).slice(0, 12);
|
|
7860
|
+
const clientDir = join8(targetDir, "client");
|
|
7861
|
+
const publicDir = join8(rootDir, "public");
|
|
7862
|
+
if (existsSync7(publicDir)) {
|
|
7863
|
+
copyDirRecursive(publicDir, join8(targetDir, "public"));
|
|
7864
|
+
}
|
|
7865
|
+
const indexHtml = generateProdIndexHtml(entryChunk, cssChunks, buildId, undefined, false);
|
|
7866
|
+
writeFileSync5(join8(clientDir, "index.html"), indexHtml);
|
|
7867
|
+
setProductionTemplateContent(indexHtml);
|
|
7868
|
+
ssgRouteCache().clear();
|
|
7869
|
+
const ssgCache2 = await buildSSGCacheSnapshot(routes, root, "http://localhost", prefix);
|
|
7870
|
+
const rootConventions = root.errorPath || root.notFoundPath ? {
|
|
7871
|
+
errorPath: root.errorPath ? toPosixPath2(root.errorPath) : undefined,
|
|
7872
|
+
notFoundPath: root.notFoundPath ? toPosixPath2(root.notFoundPath) : undefined
|
|
7873
|
+
} : undefined;
|
|
7874
|
+
const routeMetadata = {};
|
|
7875
|
+
for (const route of routes) {
|
|
7876
|
+
routeMetadata[toPosixPath2(route.path)] = {
|
|
7877
|
+
segmentBoundaries: route.segmentBoundaries.map((b) => ({
|
|
7878
|
+
depth: b.depth,
|
|
7879
|
+
path: toPosixPath2(b.path),
|
|
7880
|
+
errorPath: b.errorPath ? toPosixPath2(b.errorPath) : undefined,
|
|
7881
|
+
notFoundPath: b.notFoundPath ? toPosixPath2(b.notFoundPath) : undefined
|
|
7882
|
+
}))
|
|
7883
|
+
};
|
|
7884
|
+
}
|
|
7885
|
+
const registerSource = buildEntrySource({
|
|
7886
|
+
apps: [
|
|
7887
|
+
{
|
|
7888
|
+
buildId,
|
|
7889
|
+
prefix,
|
|
7890
|
+
rootPath: root.path,
|
|
7891
|
+
routes: routes.map((r) => ({ pattern: r.pattern, path: r.path, mode: r.mode })),
|
|
7892
|
+
rootConventions,
|
|
7893
|
+
routeMetadata,
|
|
7894
|
+
ssgCache: ssgCache2
|
|
7895
|
+
}
|
|
7896
|
+
],
|
|
7897
|
+
headerComment: "// Auto-generated by `furin build --target package` \u2014 do not edit",
|
|
7898
|
+
mode: "register"
|
|
7899
|
+
});
|
|
7900
|
+
const registerEntry = join8(targetDir, "register.ts");
|
|
7901
|
+
writeFileSync5(registerEntry, registerSource);
|
|
7902
|
+
const result = await Bun.build({
|
|
7903
|
+
entrypoints: [registerEntry],
|
|
7904
|
+
outdir: targetDir,
|
|
7905
|
+
target: "bun",
|
|
7906
|
+
packages: "external",
|
|
7907
|
+
naming: { entry: "[name].[ext]", chunk: "[name]-[hash].[ext]" },
|
|
7908
|
+
sourcemap: "none",
|
|
7909
|
+
minify: false,
|
|
7910
|
+
plugins: options.plugins
|
|
7911
|
+
});
|
|
7912
|
+
if (!result.success) {
|
|
7913
|
+
throw new AggregateError(result.logs, "[furin] package register build failed");
|
|
7914
|
+
}
|
|
7915
|
+
rmSync3(registerEntry, { force: true });
|
|
7916
|
+
rmSync3(join8(targetDir, "_hydrate.tsx"), { force: true });
|
|
7917
|
+
const relativePagesDir = toPosixPath2(relative3(targetDir, resolve2(rootDir, pagesDir)));
|
|
7918
|
+
const factorySource = `// Auto-generated by \`furin build --target package\` \u2014 do not edit
|
|
7919
|
+
import { fileURLToPath } from "node:url";
|
|
7920
|
+
import { furin } from "@teyik0/furin";
|
|
7921
|
+
import "./register.js";
|
|
7922
|
+
|
|
7923
|
+
const PAGES_DIR = fileURLToPath(new URL(${JSON.stringify(`./${relativePagesDir}`)}, import.meta.url));
|
|
7924
|
+
const CLIENT_DIR = fileURLToPath(new URL("./client", import.meta.url));
|
|
7925
|
+
|
|
7926
|
+
/**
|
|
7927
|
+
* Mounts this packaged furin app as an Elysia plugin.
|
|
7928
|
+
*
|
|
7929
|
+
* @param {object} [options] Extra furin() options (logger, sync, ...) \u2014
|
|
7930
|
+
* pagesDir/prefix/clientDir are baked into the package and cannot be overridden.
|
|
7931
|
+
* @returns {Promise<import("elysia").Elysia>}
|
|
7932
|
+
*/
|
|
7933
|
+
export function createFurinApp(options = {}) {
|
|
7934
|
+
return furin({
|
|
7935
|
+
...options,
|
|
7936
|
+
pagesDir: PAGES_DIR,
|
|
7937
|
+
prefix: ${JSON.stringify(prefix)},
|
|
7938
|
+
clientDir: CLIENT_DIR,
|
|
7939
|
+
});
|
|
7940
|
+
}
|
|
7941
|
+
|
|
7942
|
+
export const prefix = ${JSON.stringify(prefix)};
|
|
7943
|
+
`;
|
|
7944
|
+
writeFileSync5(join8(targetDir, "index.js"), factorySource);
|
|
7945
|
+
const dtsSource = `import type { Elysia } from "elysia";
|
|
7946
|
+
import type { FurinOptions } from "@teyik0/furin";
|
|
7947
|
+
|
|
7948
|
+
/** Extra furin() options \u2014 pagesDir/prefix/clientDir are baked into the package and cannot be overridden. */
|
|
7949
|
+
export type CreateFurinAppOptions = Omit<FurinOptions, "pagesDir" | "prefix" | "clientDir">;
|
|
7950
|
+
export declare function createFurinApp(options?: CreateFurinAppOptions): Promise<Elysia>;
|
|
7951
|
+
export declare const prefix: string;
|
|
7952
|
+
`;
|
|
7953
|
+
writeFileSync5(join8(targetDir, "index.d.ts"), dtsSource);
|
|
7954
|
+
console.log(`[furin] Package artifact: ${toPosixPath2(relative3(rootDir, targetDir))}`);
|
|
7955
|
+
return {
|
|
7956
|
+
buildId,
|
|
7957
|
+
generatedAt: new Date().toISOString(),
|
|
7958
|
+
prefix,
|
|
7959
|
+
targetDir: toPosixPath2(relative3(rootDir, targetDir))
|
|
7960
|
+
};
|
|
7961
|
+
}
|
|
7962
|
+
|
|
7614
7963
|
// src/adapter/static.ts
|
|
7615
|
-
import { cpSync as cpSync2, existsSync as
|
|
7616
|
-
import { dirname as dirname3, isAbsolute, join as
|
|
7964
|
+
import { cpSync as cpSync2, existsSync as existsSync8, rmSync as rmSync4, writeFileSync as writeFileSync6 } from "fs";
|
|
7965
|
+
import { dirname as dirname3, isAbsolute, join as join9, relative as relative4, resolve as resolve3, sep } from "path";
|
|
7617
7966
|
var STATIC_CONCURRENCY = 4;
|
|
7618
7967
|
var DYNAMIC_SEGMENT_RE = /\/:[^/]+|\/\*/;
|
|
7619
7968
|
var TRAILING_SLASHES_RE2 = /\/+$/;
|
|
7620
7969
|
function pathToOutputFile(urlPath, outDir, fileName) {
|
|
7621
|
-
const normalizedOutDir =
|
|
7970
|
+
const normalizedOutDir = resolve3(outDir);
|
|
7622
7971
|
if (urlPath === "/" || urlPath === "") {
|
|
7623
|
-
return
|
|
7972
|
+
return join9(normalizedOutDir, fileName);
|
|
7624
7973
|
}
|
|
7625
|
-
const resolved =
|
|
7974
|
+
const resolved = resolve3(normalizedOutDir, urlPath.slice(1), fileName);
|
|
7626
7975
|
if (!resolved.startsWith(`${normalizedOutDir}${sep}`)) {
|
|
7627
7976
|
throw new Error(`[furin] static: unsafe output path detected for URL "${urlPath}" \u2014 path traversal via ".." is not allowed.`);
|
|
7628
7977
|
}
|
|
@@ -7639,8 +7988,8 @@ async function prerenderAndWrite(route, params, root, outDir, renderedRoutes, sk
|
|
|
7639
7988
|
return;
|
|
7640
7989
|
}
|
|
7641
7990
|
ensureDir(dirname3(htmlOutputFile));
|
|
7642
|
-
|
|
7643
|
-
|
|
7991
|
+
writeFileSync6(htmlOutputFile, entry.html);
|
|
7992
|
+
writeFileSync6(dataOutputFile, entry.ndjson);
|
|
7644
7993
|
renderedRoutes.push(urlPath);
|
|
7645
7994
|
console.log(`[furin] static: ${urlPath} \u2192 ${toPosixPath2(htmlOutputFile)}`);
|
|
7646
7995
|
} catch (err) {
|
|
@@ -7728,14 +8077,14 @@ async function buildStaticTarget(routes, rootDir, buildRoot, root, options) {
|
|
|
7728
8077
|
if (basePath && !basePath.startsWith("/")) {
|
|
7729
8078
|
throw new Error(`[furin] static: basePath must start with "/" (received "${rawBasePath}"). ` + `Use "" for root deployments or "/sub-path" for sub-path deployments.`);
|
|
7730
8079
|
}
|
|
7731
|
-
const outDir =
|
|
7732
|
-
const normalizedRoot =
|
|
7733
|
-
const normalizedBuildRoot =
|
|
8080
|
+
const outDir = resolve3(rootDir, staticConfig.outDir ?? "dist");
|
|
8081
|
+
const normalizedRoot = resolve3(rootDir);
|
|
8082
|
+
const normalizedBuildRoot = resolve3(buildRoot);
|
|
7734
8083
|
if (outDir === normalizedRoot || outDir === normalizedBuildRoot || outDir === "/" || outDir === ".") {
|
|
7735
8084
|
throw new Error(`[furin] static: outDir resolves to "${outDir}" which is unsafe to delete. ` + `Use a dedicated output directory such as "dist".`);
|
|
7736
8085
|
}
|
|
7737
8086
|
function isOutsideOutDir(target) {
|
|
7738
|
-
const rel =
|
|
8087
|
+
const rel = relative4(outDir, target);
|
|
7739
8088
|
return rel.startsWith("..") || isAbsolute(rel);
|
|
7740
8089
|
}
|
|
7741
8090
|
if (!(isOutsideOutDir(normalizedRoot) && isOutsideOutDir(normalizedBuildRoot))) {
|
|
@@ -7747,10 +8096,10 @@ async function buildStaticTarget(routes, rootDir, buildRoot, root, options) {
|
|
|
7747
8096
|
const skippedRoutes = [];
|
|
7748
8097
|
const ssgRoutes = collectSsgRoutes(routes, onSSR, skippedRoutes);
|
|
7749
8098
|
const searchRoutes = createSearchRouteMetadata(ssgRoutes);
|
|
7750
|
-
|
|
8099
|
+
rmSync4(outDir, { force: true, recursive: true });
|
|
7751
8100
|
ensureDir(outDir);
|
|
7752
|
-
const targetDir =
|
|
7753
|
-
|
|
8101
|
+
const targetDir = join9(buildRoot, "static");
|
|
8102
|
+
rmSync4(targetDir, { force: true, recursive: true });
|
|
7754
8103
|
ensureDir(targetDir);
|
|
7755
8104
|
const { entryChunk, cssChunks } = await buildClient(ssgRoutes, {
|
|
7756
8105
|
outDir: targetDir,
|
|
@@ -7760,17 +8109,17 @@ async function buildStaticTarget(routes, rootDir, buildRoot, root, options) {
|
|
|
7760
8109
|
basePath,
|
|
7761
8110
|
clientLogging: Boolean(options.clientLogging)
|
|
7762
8111
|
});
|
|
7763
|
-
const publicFavicon =
|
|
7764
|
-
const faviconHref =
|
|
8112
|
+
const publicFavicon = join9(rootDir, "public", "favicon.ico");
|
|
8113
|
+
const faviconHref = existsSync8(publicFavicon) ? `${basePath}/favicon.ico` : undefined;
|
|
7765
8114
|
const shellHtml = generateProdIndexHtml(entryChunk, cssChunks, undefined, faviconHref, true);
|
|
7766
8115
|
setProductionTemplateContent(shellHtml);
|
|
7767
|
-
const publicSrcDir =
|
|
7768
|
-
if (
|
|
8116
|
+
const publicSrcDir = join9(rootDir, "public");
|
|
8117
|
+
if (existsSync8(publicSrcDir)) {
|
|
7769
8118
|
cpSync2(publicSrcDir, outDir, { recursive: true });
|
|
7770
8119
|
}
|
|
7771
|
-
const clientSrcDir =
|
|
7772
|
-
if (
|
|
7773
|
-
cpSync2(clientSrcDir,
|
|
8120
|
+
const clientSrcDir = join9(targetDir, "client");
|
|
8121
|
+
if (existsSync8(clientSrcDir)) {
|
|
8122
|
+
cpSync2(clientSrcDir, join9(outDir, "_client"), { recursive: true });
|
|
7774
8123
|
}
|
|
7775
8124
|
const tasks = await buildTaskQueue(ssgRoutes, root, outDir, renderedRoutes, skippedRoutes, basePath, searchRoutes);
|
|
7776
8125
|
const afterQueueCount = skippedRoutes.length;
|
|
@@ -7783,9 +8132,9 @@ async function buildStaticTarget(routes, rootDir, buildRoot, root, options) {
|
|
|
7783
8132
|
${list}
|
|
7784
8133
|
` + `Set \`onSSR: "skip"\` in your static config to suppress this error.`);
|
|
7785
8134
|
}
|
|
7786
|
-
|
|
8135
|
+
writeFileSync6(join9(outDir, "404.html"), shellHtml);
|
|
7787
8136
|
console.log("[furin] static: wrote 404.html (SPA shell fallback)");
|
|
7788
|
-
|
|
8137
|
+
rmSync4(targetDir, { force: true, recursive: true });
|
|
7789
8138
|
console.log(`[furin] static: export complete \u2192 ${toPosixPath2(outDir)}` + ` (${renderedRoutes.length} rendered, ${skippedRoutes.length} skipped)`);
|
|
7790
8139
|
return {
|
|
7791
8140
|
basePath,
|
|
@@ -7798,12 +8147,16 @@ ${list}
|
|
|
7798
8147
|
|
|
7799
8148
|
// src/config.ts
|
|
7800
8149
|
import { t as t2 } from "elysia";
|
|
7801
|
-
var BUILD_TARGETS = ["bun", "node", "vercel", "cloudflare", "static"];
|
|
8150
|
+
var BUILD_TARGETS = ["bun", "node", "vercel", "cloudflare", "static", "package"];
|
|
7802
8151
|
var buildTargetSchema = t2.Union(BUILD_TARGETS.map((v) => t2.Literal(v)));
|
|
7803
8152
|
var compileTargetSchema = t2.Union([t2.Literal("server"), t2.Literal("embed")]);
|
|
7804
8153
|
var configSchema = t2.Object({
|
|
7805
8154
|
rootDir: t2.Optional(t2.String()),
|
|
7806
8155
|
pagesDir: t2.Optional(t2.String()),
|
|
8156
|
+
apps: t2.Optional(t2.Array(t2.Object({
|
|
8157
|
+
pagesDir: t2.String(),
|
|
8158
|
+
prefix: t2.Optional(t2.String())
|
|
8159
|
+
}))),
|
|
7807
8160
|
serverEntry: t2.Optional(t2.String()),
|
|
7808
8161
|
clientLogging: t2.Optional(t2.Boolean()),
|
|
7809
8162
|
targets: t2.Optional(t2.Array(buildTargetSchema)),
|
|
@@ -7855,9 +8208,13 @@ function checkFurinCall(node, out) {
|
|
|
7855
8208
|
}
|
|
7856
8209
|
const pagesDir = extractStringProperty(firstArg, "pagesDir");
|
|
7857
8210
|
if (pagesDir !== null) {
|
|
7858
|
-
|
|
8211
|
+
const prefix = extractStringProperty(firstArg, "prefix");
|
|
8212
|
+
out.push({ pagesDir, prefix: normalizeScannedPrefix(prefix) });
|
|
7859
8213
|
}
|
|
7860
8214
|
}
|
|
8215
|
+
function normalizeScannedPrefix(prefix) {
|
|
8216
|
+
return normalizePrefix(prefix ?? undefined);
|
|
8217
|
+
}
|
|
7861
8218
|
function isObjectExpressionNode2(node) {
|
|
7862
8219
|
return node.type === "ObjectExpression";
|
|
7863
8220
|
}
|
|
@@ -7887,31 +8244,42 @@ function getStringPropertyValue(prop, propName) {
|
|
|
7887
8244
|
// src/build/index.ts
|
|
7888
8245
|
var IMPLEMENTED_TARGETS = ["bun", "static"];
|
|
7889
8246
|
var BUILD_OUTPUT_DIR = ".furin/build";
|
|
7890
|
-
function
|
|
7891
|
-
if (
|
|
7892
|
-
return
|
|
8247
|
+
function resolveAppSpecs(options, serverEntry, rootDir) {
|
|
8248
|
+
if (options.apps && options.apps.length > 0) {
|
|
8249
|
+
return options.apps.map((app) => ({
|
|
8250
|
+
pagesDir: resolve4(rootDir, app.pagesDir),
|
|
8251
|
+
prefix: normalizePrefix(app.prefix)
|
|
8252
|
+
}));
|
|
7893
8253
|
}
|
|
7894
|
-
|
|
7895
|
-
|
|
7896
|
-
return null;
|
|
8254
|
+
if (options.pagesDir) {
|
|
8255
|
+
return [{ pagesDir: resolve4(rootDir, options.pagesDir), prefix: "" }];
|
|
7897
8256
|
}
|
|
7898
|
-
|
|
8257
|
+
if (serverEntry) {
|
|
8258
|
+
const detected = scanFurinInstances(serverEntry);
|
|
8259
|
+
if (detected.length > 0) {
|
|
8260
|
+
return detected.map((app) => ({
|
|
8261
|
+
pagesDir: resolve4(rootDir, app.pagesDir),
|
|
8262
|
+
prefix: app.prefix
|
|
8263
|
+
}));
|
|
8264
|
+
}
|
|
8265
|
+
}
|
|
8266
|
+
return [{ pagesDir: resolve4(rootDir, "src/pages"), prefix: "" }];
|
|
7899
8267
|
}
|
|
7900
8268
|
async function buildApp(options) {
|
|
7901
|
-
const rootDir =
|
|
7902
|
-
const buildRoot =
|
|
8269
|
+
const rootDir = resolve4(options.rootDir ?? process.cwd());
|
|
8270
|
+
const buildRoot = join10(rootDir, BUILD_OUTPUT_DIR);
|
|
7903
8271
|
const serverEntry = (() => {
|
|
7904
|
-
if (options.target === "static") {
|
|
8272
|
+
if (options.target === "static" || options.target === "package") {
|
|
7905
8273
|
return null;
|
|
7906
8274
|
}
|
|
7907
8275
|
if (options.serverEntry) {
|
|
7908
|
-
const resolved =
|
|
7909
|
-
if (
|
|
8276
|
+
const resolved = resolve4(rootDir, options.serverEntry);
|
|
8277
|
+
if (existsSync9(resolved)) {
|
|
7910
8278
|
return resolved;
|
|
7911
8279
|
}
|
|
7912
8280
|
}
|
|
7913
|
-
const entry =
|
|
7914
|
-
if (!
|
|
8281
|
+
const entry = resolve4(rootDir, "src/server.ts");
|
|
8282
|
+
if (!existsSync9(entry)) {
|
|
7915
8283
|
throw new Error("[furin] Entrypoint server.ts not found");
|
|
7916
8284
|
}
|
|
7917
8285
|
return entry;
|
|
@@ -7927,33 +8295,59 @@ async function buildApp(options) {
|
|
|
7927
8295
|
console.debug("[furin] Skipped plugin at runtime:", err);
|
|
7928
8296
|
}
|
|
7929
8297
|
}
|
|
7930
|
-
const
|
|
7931
|
-
const
|
|
8298
|
+
const appSpecs = resolveAppSpecs(options, serverEntry, rootDir);
|
|
8299
|
+
const duplicatePrefix = appSpecs.find((spec, index) => appSpecs.findIndex((other) => other.prefix === spec.prefix) !== index);
|
|
8300
|
+
if (duplicatePrefix) {
|
|
8301
|
+
throw new Error(`[furin] Two apps are configured with the prefix "${duplicatePrefix.prefix || "/"}" \u2014 give each app a unique prefix.`);
|
|
8302
|
+
}
|
|
8303
|
+
assertNoPrefixSlugCollisions(appSpecs.map((spec) => spec.prefix));
|
|
7932
8304
|
const requestedTargets = options.target === "all" ? [...IMPLEMENTED_TARGETS] : [options.target].map((target) => {
|
|
7933
8305
|
if (!BUILD_TARGETS.includes(target)) {
|
|
7934
8306
|
throw new Error(`[furin] Unsupported build target "${target}"`);
|
|
7935
8307
|
}
|
|
7936
8308
|
return target;
|
|
7937
8309
|
});
|
|
7938
|
-
const
|
|
8310
|
+
const apps = [];
|
|
8311
|
+
for (const spec of appSpecs) {
|
|
8312
|
+
const { root, routes } = await scanPages(spec.pagesDir);
|
|
8313
|
+
apps.push({ pagesDir: spec.pagesDir, prefix: spec.prefix, root, routes });
|
|
8314
|
+
}
|
|
8315
|
+
const primaryApp = apps.find((app) => app.prefix === "") ?? apps[0];
|
|
7939
8316
|
ensureDir(buildRoot);
|
|
7940
8317
|
const manifest = {
|
|
7941
8318
|
version: 1,
|
|
7942
8319
|
generatedAt: new Date().toISOString(),
|
|
7943
8320
|
rootDir: toPosixPath2(rootDir),
|
|
7944
|
-
pagesDir: toPosixPath2(
|
|
7945
|
-
rootPath: toPosixPath2(
|
|
7946
|
-
serverEntry: serverEntry ? toPosixPath2(
|
|
7947
|
-
routes: routes.map((route) => toBuildRouteManifestEntry(route, rootDir)),
|
|
8321
|
+
pagesDir: toPosixPath2(relative5(rootDir, primaryApp.pagesDir)),
|
|
8322
|
+
rootPath: toPosixPath2(relative5(rootDir, primaryApp.root.path)),
|
|
8323
|
+
serverEntry: serverEntry ? toPosixPath2(relative5(rootDir, serverEntry)) : null,
|
|
8324
|
+
routes: primaryApp.routes.map((route) => toBuildRouteManifestEntry(route, rootDir)),
|
|
8325
|
+
apps: apps.map((app) => ({
|
|
8326
|
+
pagesDir: toPosixPath2(relative5(rootDir, app.pagesDir)),
|
|
8327
|
+
prefix: app.prefix,
|
|
8328
|
+
routes: app.routes.map((route) => toBuildRouteManifestEntry(route, rootDir))
|
|
8329
|
+
})),
|
|
7948
8330
|
targets: {}
|
|
7949
8331
|
};
|
|
7950
8332
|
for (const target of requestedTargets) {
|
|
7951
8333
|
switch (target) {
|
|
7952
8334
|
case "bun":
|
|
7953
|
-
manifest.targets.bun = await buildBunTarget(
|
|
8335
|
+
manifest.targets.bun = await buildBunTarget(apps, rootDir, buildRoot, serverEntry, options);
|
|
7954
8336
|
break;
|
|
7955
8337
|
case "static":
|
|
7956
|
-
|
|
8338
|
+
if (apps.length > 1) {
|
|
8339
|
+
console.warn("[furin] `--target static` exports the root-mounted app only \u2014 prefixed apps are skipped.");
|
|
8340
|
+
}
|
|
8341
|
+
if (primaryApp.prefix !== "") {
|
|
8342
|
+
console.warn(`[furin] \`--target static\` exports an app mounted at "${primaryApp.prefix}", but the ` + `static export ignores the mount prefix \u2014 set \`static.basePath\` to "${primaryApp.prefix}" ` + "(or the sub-path the site is served from) so asset URLs resolve correctly.");
|
|
8343
|
+
}
|
|
8344
|
+
manifest.targets.static = await buildStaticTarget(primaryApp.routes, rootDir, buildRoot, primaryApp.root, options);
|
|
8345
|
+
break;
|
|
8346
|
+
case "package":
|
|
8347
|
+
if (apps.length > 1) {
|
|
8348
|
+
throw new Error("[furin] `--target package` builds exactly one app \u2014 configure a single pagesDir/prefix.");
|
|
8349
|
+
}
|
|
8350
|
+
manifest.targets.package = await buildPackageTarget(primaryApp, rootDir, buildRoot, options);
|
|
7957
8351
|
break;
|
|
7958
8352
|
case "node":
|
|
7959
8353
|
case "vercel":
|
|
@@ -7963,7 +8357,7 @@ async function buildApp(options) {
|
|
|
7963
8357
|
throw new Error(`[furin] Unsupported build target "${target}"`);
|
|
7964
8358
|
}
|
|
7965
8359
|
}
|
|
7966
|
-
|
|
8360
|
+
writeFileSync7(join10(buildRoot, "manifest.json"), `${JSON.stringify(manifest, null, 2)}
|
|
7967
8361
|
`);
|
|
7968
8362
|
return {
|
|
7969
8363
|
manifest,
|
|
@@ -7972,8 +8366,8 @@ async function buildApp(options) {
|
|
|
7972
8366
|
}
|
|
7973
8367
|
|
|
7974
8368
|
// src/cli/config.ts
|
|
7975
|
-
import { existsSync as
|
|
7976
|
-
import { resolve as
|
|
8369
|
+
import { existsSync as existsSync10 } from "fs";
|
|
8370
|
+
import { resolve as resolve5 } from "path";
|
|
7977
8371
|
import { pathToFileURL } from "url";
|
|
7978
8372
|
import { TypeCompiler } from "elysia/type-system";
|
|
7979
8373
|
var compiledConfigSchema = TypeCompiler.Compile(configSchema);
|
|
@@ -7983,13 +8377,12 @@ var DEFAULT_CONFIG_FILENAMES = [
|
|
|
7983
8377
|
"furin.config.mjs"
|
|
7984
8378
|
];
|
|
7985
8379
|
async function loadCliConfig(cwd, explicitConfigPath) {
|
|
7986
|
-
const rootDir =
|
|
7987
|
-
const configPath = explicitConfigPath ?
|
|
8380
|
+
const rootDir = resolve5(cwd);
|
|
8381
|
+
const configPath = explicitConfigPath ? resolve5(rootDir, explicitConfigPath) : DEFAULT_CONFIG_FILENAMES.map((filename) => resolve5(rootDir, filename)).find((path) => existsSync10(path));
|
|
7988
8382
|
if (!configPath) {
|
|
7989
8383
|
return {
|
|
7990
8384
|
configPath: null,
|
|
7991
|
-
rootDir
|
|
7992
|
-
pagesDir: resolve4(rootDir, "src/pages")
|
|
8385
|
+
rootDir
|
|
7993
8386
|
};
|
|
7994
8387
|
}
|
|
7995
8388
|
const imported = await import(pathToFileURL(configPath).href);
|
|
@@ -8002,13 +8395,13 @@ async function loadCliConfig(cwd, explicitConfigPath) {
|
|
|
8002
8395
|
const [firstError] = compiledConfigSchema.Errors(configToValidate);
|
|
8003
8396
|
throw new Error(`[furin] Invalid config at ${configPath}: ${firstError?.message ?? "unknown error"} (path: ${firstError?.path ?? "/"})`);
|
|
8004
8397
|
}
|
|
8005
|
-
const resolvedRootDir =
|
|
8398
|
+
const resolvedRootDir = resolve5(rootDir, configToValidate.rootDir ?? ".");
|
|
8006
8399
|
return {
|
|
8007
8400
|
...configToValidate,
|
|
8008
8401
|
plugins,
|
|
8009
8402
|
configPath,
|
|
8010
8403
|
rootDir: resolvedRootDir,
|
|
8011
|
-
pagesDir:
|
|
8404
|
+
pagesDir: configToValidate.pagesDir ? resolve5(resolvedRootDir, configToValidate.pagesDir) : undefined
|
|
8012
8405
|
};
|
|
8013
8406
|
}
|
|
8014
8407
|
|
|
@@ -8040,6 +8433,7 @@ if (command === "build") {
|
|
|
8040
8433
|
options: {
|
|
8041
8434
|
target: { type: "string" },
|
|
8042
8435
|
pagesDir: { type: "string" },
|
|
8436
|
+
prefix: { type: "string" },
|
|
8043
8437
|
config: { type: "string" }
|
|
8044
8438
|
},
|
|
8045
8439
|
strict: false
|
|
@@ -8059,10 +8453,10 @@ if (command === "build") {
|
|
|
8059
8453
|
bail(`Unsupported build target "${target}". Valid: ${BUILD_TARGETS.join(", ")}, all`);
|
|
8060
8454
|
}
|
|
8061
8455
|
const config = await loadCliConfig(process.cwd(), values.config);
|
|
8062
|
-
const
|
|
8063
|
-
const resolvedServerEntry =
|
|
8064
|
-
const entry =
|
|
8065
|
-
if (!
|
|
8456
|
+
const isServerlessTarget = target === "static" || target === "package";
|
|
8457
|
+
const resolvedServerEntry = isServerlessTarget ? undefined : (() => {
|
|
8458
|
+
const entry = resolve6(config.rootDir, config.serverEntry ?? "src/server.ts");
|
|
8459
|
+
if (!existsSync11(entry)) {
|
|
8066
8460
|
const expected = config.serverEntry ?? "src/server.ts";
|
|
8067
8461
|
throw new Error(`[furin] Entrypoint ${expected} not found`);
|
|
8068
8462
|
}
|
|
@@ -8073,7 +8467,13 @@ if (command === "build") {
|
|
|
8073
8467
|
target,
|
|
8074
8468
|
compile: resolveCompileMode(compileFlag, config.bun?.compile),
|
|
8075
8469
|
rootDir: config.rootDir,
|
|
8076
|
-
|
|
8470
|
+
apps: values.pagesDir ?? config.pagesDir ? [
|
|
8471
|
+
{
|
|
8472
|
+
pagesDir: values.pagesDir ?? config.pagesDir,
|
|
8473
|
+
prefix: normalizePrefix(values.prefix)
|
|
8474
|
+
}
|
|
8475
|
+
] : config.apps,
|
|
8476
|
+
pagesDir: undefined,
|
|
8077
8477
|
serverEntry: resolvedServerEntry,
|
|
8078
8478
|
plugins: config.plugins,
|
|
8079
8479
|
staticConfig: config.static,
|
|
@@ -8088,7 +8488,9 @@ USAGE furin build [options]
|
|
|
8088
8488
|
|
|
8089
8489
|
OPTIONS
|
|
8090
8490
|
--target ${BUILD_TARGETS.join(" | ")} | all (default: bun)
|
|
8491
|
+
"package" builds a publishable Elysia-plugin artifact (register.js + factory + client assets)
|
|
8091
8492
|
--pagesDir Pages directory
|
|
8493
|
+
--prefix Mount prefix for the built app (e.g. /admin) \u2014 pairs with --pagesDir
|
|
8092
8494
|
--config Config file path
|
|
8093
8495
|
--compile server | embed Compile to binary: "server" keeps client on disk, "embed" is self-contained
|
|
8094
8496
|
`);
|