@farm.js/core 0.1.0-beta.33 → 0.1.0-beta.35
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/{chunk-EL644GWT.mjs → chunk-7JLDC7IO.mjs} +17 -4
- package/dist/chunk-7JLDC7IO.mjs.map +1 -0
- package/dist/{chunk-5PDVNNUQ.mjs → chunk-BNTDKO7T.mjs} +8 -4
- package/dist/chunk-BNTDKO7T.mjs.map +1 -0
- package/dist/{chunk-4TI6B4AY.mjs → chunk-HLN7NPNQ.mjs} +220 -154
- package/dist/chunk-HLN7NPNQ.mjs.map +1 -0
- package/dist/{chunk-NETDSCXV.mjs → chunk-IU42657J.mjs} +2 -2
- package/dist/{chunk-GKEYR7EK.mjs → chunk-IZFFEFOH.mjs} +2 -2
- package/dist/{chunk-GKEYR7EK.mjs.map → chunk-IZFFEFOH.mjs.map} +1 -1
- package/dist/{chunk-QGRLI3KV.mjs → chunk-O4IEAI32.mjs} +2 -2
- package/dist/{chunk-DV5ZT2JO.mjs → chunk-S7SW4LTM.mjs} +4 -4
- package/dist/client/lifecycle.mjs +2 -2
- package/dist/client-plugins.cjs +1 -1
- package/dist/client-plugins.cjs.map +1 -1
- package/dist/client-plugins.mjs +2 -2
- package/dist/client.cjs +1 -1
- package/dist/client.cjs.map +1 -1
- package/dist/client.mjs +2 -2
- package/dist/{devtools-BF6URGGF.mjs → devtools-G4S3JRIH.mjs} +3 -3
- package/dist/docs.cjs +13 -1
- package/dist/docs.cjs.map +1 -1
- package/dist/docs.mjs +3 -3
- package/dist/index.cjs +437 -352
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +7 -7
- package/dist/internal/build-runtime.cjs +414 -329
- package/dist/internal/build-runtime.cjs.map +1 -1
- package/dist/internal/build-runtime.mjs +6 -6
- package/dist/internal/client-runtime.cjs +1 -1
- package/dist/internal/client-runtime.cjs.map +1 -1
- package/dist/internal/client-runtime.mjs +2 -2
- package/dist/internal/config-runtime.cjs +17 -3
- package/dist/internal/config-runtime.cjs.map +1 -1
- package/dist/internal/config-runtime.mjs +2 -2
- package/dist/plugin.cjs +16 -3
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.mjs +3 -3
- package/dist/renderer.cjs +7 -3
- package/dist/renderer.cjs.map +1 -1
- package/dist/renderer.d.mts +9 -0
- package/dist/renderer.d.ts +9 -0
- package/dist/renderer.mjs +1 -1
- package/dist/server.cjs +23 -6
- package/dist/server.cjs.map +1 -1
- package/dist/server.mjs +4 -4
- package/dist/version.cjs +1 -1
- package/dist/version.cjs.map +1 -1
- package/dist/version.mjs +1 -1
- package/dist/vite.cjs +21 -5
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.mjs +3 -3
- package/package.json +3 -3
- package/dist/chunk-4TI6B4AY.mjs.map +0 -1
- package/dist/chunk-5PDVNNUQ.mjs.map +0 -1
- package/dist/chunk-EL644GWT.mjs.map +0 -1
- /package/dist/{chunk-NETDSCXV.mjs.map → chunk-IU42657J.mjs.map} +0 -0
- /package/dist/{chunk-QGRLI3KV.mjs.map → chunk-O4IEAI32.mjs.map} +0 -0
- /package/dist/{chunk-DV5ZT2JO.mjs.map → chunk-S7SW4LTM.mjs.map} +0 -0
- /package/dist/{devtools-BF6URGGF.mjs.map → devtools-G4S3JRIH.mjs.map} +0 -0
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
FARM_DOCS_LAST_MODIFIED_MANIFEST,
|
|
10
10
|
createFarmDocsLastModifiedManifest,
|
|
11
11
|
getFarmDocsRouteTypeEntries
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-IU42657J.mjs";
|
|
13
13
|
import {
|
|
14
14
|
generateFarmDocsSearchClientRuntime,
|
|
15
15
|
isFarmDocsSearchEnabled,
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
import {
|
|
19
19
|
hasCustomFarmRouteContext,
|
|
20
20
|
resolveDeployOutputPath
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-7JLDC7IO.mjs";
|
|
22
22
|
import {
|
|
23
23
|
resolveFarmInstrumentationFile
|
|
24
24
|
} from "./chunk-5NAM3OTS.mjs";
|
|
@@ -37,7 +37,7 @@ import {
|
|
|
37
37
|
mergeFarmFontCss,
|
|
38
38
|
mergeFarmViteConfig,
|
|
39
39
|
resolveRouteRenderingConfigFromFile
|
|
40
|
-
} from "./chunk-
|
|
40
|
+
} from "./chunk-S7SW4LTM.mjs";
|
|
41
41
|
import {
|
|
42
42
|
farmEnvironmentFunctionsPlugin
|
|
43
43
|
} from "./chunk-V6WE6JSZ.mjs";
|
|
@@ -53,7 +53,7 @@ import {
|
|
|
53
53
|
getFarmRendererComponentExtensions,
|
|
54
54
|
isReactRenderer,
|
|
55
55
|
loadFarmRendererVitePlugins
|
|
56
|
-
} from "./chunk-
|
|
56
|
+
} from "./chunk-BNTDKO7T.mjs";
|
|
57
57
|
import {
|
|
58
58
|
getFarmAppDirectories
|
|
59
59
|
} from "./chunk-74YTBPTY.mjs";
|
|
@@ -99,22 +99,72 @@ import {
|
|
|
99
99
|
} from "./chunk-CGILA3WO.mjs";
|
|
100
100
|
|
|
101
101
|
// src/build/index.ts
|
|
102
|
-
import
|
|
102
|
+
import path5 from "path";
|
|
103
103
|
import { existsSync as existsSync2 } from "fs";
|
|
104
104
|
|
|
105
|
+
// src/nitro/client-css-href.ts
|
|
106
|
+
import path from "path";
|
|
107
|
+
var FARM_CLIENT_CSS_HREF_PLACEHOLDER = "/__farm_client_css_href__";
|
|
108
|
+
var FARM_CLIENT_JS_SRC_PLACEHOLDER = "/__farm_client_js_src__";
|
|
109
|
+
async function hashAndCopy(sourcePath, destinationDir, hashedName) {
|
|
110
|
+
const fs = await import("fs/promises");
|
|
111
|
+
try {
|
|
112
|
+
const bytes = await fs.readFile(sourcePath);
|
|
113
|
+
if (bytes.length === 0) return null;
|
|
114
|
+
const { createHash } = await import("crypto");
|
|
115
|
+
const hash = createHash("sha256").update(bytes).digest("hex").slice(0, 8);
|
|
116
|
+
const name = hashedName(hash);
|
|
117
|
+
await fs.mkdir(destinationDir, { recursive: true });
|
|
118
|
+
await fs.writeFile(path.join(destinationDir, name), bytes);
|
|
119
|
+
return name;
|
|
120
|
+
} catch {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
__name(hashAndCopy, "hashAndCopy");
|
|
125
|
+
async function resolveHashedClientCssHref(clientOutputDir) {
|
|
126
|
+
const name = await hashAndCopy(
|
|
127
|
+
path.join(clientOutputDir, "farm-client.css"),
|
|
128
|
+
path.join(clientOutputDir, "assets"),
|
|
129
|
+
(hash) => `farm-client-h${hash}.css`
|
|
130
|
+
);
|
|
131
|
+
return name ? `/assets/${name}` : "/farm-client.css";
|
|
132
|
+
}
|
|
133
|
+
__name(resolveHashedClientCssHref, "resolveHashedClientCssHref");
|
|
134
|
+
async function findFingerprintedClientEntry(clientOutputDir) {
|
|
135
|
+
const fs = await import("fs/promises");
|
|
136
|
+
try {
|
|
137
|
+
const entries = await fs.readdir(clientOutputDir);
|
|
138
|
+
return entries.find((name) => /^farm-client-h[0-9a-f]+\.js$/.test(name)) ?? null;
|
|
139
|
+
} catch {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
__name(findFingerprintedClientEntry, "findFingerprintedClientEntry");
|
|
144
|
+
async function resolveHashedClientJsSrc(clientOutputDir) {
|
|
145
|
+
const entryName = await findFingerprintedClientEntry(clientOutputDir);
|
|
146
|
+
if (!entryName) return "/farm-client.js";
|
|
147
|
+
const fs = await import("fs/promises");
|
|
148
|
+
const shim = `export * from "./${entryName}";
|
|
149
|
+
`;
|
|
150
|
+
await fs.writeFile(path.join(clientOutputDir, "farm-client.js"), shim);
|
|
151
|
+
return `/${entryName}`;
|
|
152
|
+
}
|
|
153
|
+
__name(resolveHashedClientJsSrc, "resolveHashedClientJsSrc");
|
|
154
|
+
|
|
105
155
|
// src/nitro/universal-build.ts
|
|
106
156
|
import os from "os";
|
|
107
|
-
import
|
|
157
|
+
import path4 from "path";
|
|
108
158
|
import { constants as fsConstants, existsSync, readFileSync } from "fs";
|
|
109
159
|
import { fileURLToPath } from "url";
|
|
110
160
|
import { builtinModules, createRequire } from "module";
|
|
111
161
|
import { isDeepStrictEqual } from "util";
|
|
112
162
|
|
|
113
163
|
// src/route-runtime-manifest.ts
|
|
114
|
-
import
|
|
164
|
+
import path2 from "path";
|
|
115
165
|
var FARM_ROUTE_RUNTIME_MANIFEST = "route-runtime-manifest.json";
|
|
116
166
|
async function createFarmRouteRuntimeManifest(options) {
|
|
117
|
-
const root =
|
|
167
|
+
const root = path2.resolve(options.root || options.config.root || process.cwd());
|
|
118
168
|
const routes = [];
|
|
119
169
|
for (const [pattern, entry] of options.routeManager.getRoutes()) {
|
|
120
170
|
const routeModule = await options.routeManager.loadRouteModule(entry.modulePath);
|
|
@@ -162,7 +212,7 @@ async function createFarmRouteRuntimeManifest(options) {
|
|
|
162
212
|
__name(createFarmRouteRuntimeManifest, "createFarmRouteRuntimeManifest");
|
|
163
213
|
async function writeFarmRouteRuntimeManifest(directory, manifest) {
|
|
164
214
|
const fs = await import("fs/promises");
|
|
165
|
-
const manifestPath =
|
|
215
|
+
const manifestPath = path2.join(directory, FARM_ROUTE_RUNTIME_MANIFEST);
|
|
166
216
|
await fs.mkdir(directory, { recursive: true });
|
|
167
217
|
await fs.writeFile(manifestPath, `${JSON.stringify(manifest, null, 2)}
|
|
168
218
|
`);
|
|
@@ -202,13 +252,13 @@ function normalizeManifestSource(root, modulePath) {
|
|
|
202
252
|
const queryIndex = modulePath.indexOf("?");
|
|
203
253
|
const filePath = queryIndex === -1 ? modulePath : modulePath.slice(0, queryIndex);
|
|
204
254
|
const query = queryIndex === -1 ? "" : modulePath.slice(queryIndex);
|
|
205
|
-
const relativePath =
|
|
255
|
+
const relativePath = path2.isAbsolute(filePath) ? path2.relative(root, filePath) : filePath;
|
|
206
256
|
return `${relativePath.replace(/\\/g, "/")}${query}`;
|
|
207
257
|
}
|
|
208
258
|
__name(normalizeManifestSource, "normalizeManifestSource");
|
|
209
259
|
|
|
210
260
|
// src/nitro/vercel-route-runtime.ts
|
|
211
|
-
import
|
|
261
|
+
import path3 from "path";
|
|
212
262
|
async function createFarmVercelRouteRuntimeFunctions(outputDir, manifest, fs) {
|
|
213
263
|
const dynamicRoutes = manifest.routes.filter(
|
|
214
264
|
(route) => route.rendering === "dynamic" && route.runtime !== "edge"
|
|
@@ -228,8 +278,8 @@ async function createFarmVercelRouteRuntimeFunctions(outputDir, manifest, fs) {
|
|
|
228
278
|
group.routes.push(route);
|
|
229
279
|
groups.set(key, group);
|
|
230
280
|
}
|
|
231
|
-
const functionsDir =
|
|
232
|
-
const baseFunctionDir =
|
|
281
|
+
const functionsDir = path3.join(outputDir, "functions");
|
|
282
|
+
const baseFunctionDir = path3.join(functionsDir, "__nitro.func");
|
|
233
283
|
const destinations = /* @__PURE__ */ new Map();
|
|
234
284
|
let groupIndex = 0;
|
|
235
285
|
for (const [key, group] of groups) {
|
|
@@ -239,7 +289,7 @@ async function createFarmVercelRouteRuntimeFunctions(outputDir, manifest, fs) {
|
|
|
239
289
|
}
|
|
240
290
|
groupIndex += 1;
|
|
241
291
|
const functionName = `__farm_runtime_${groupIndex}`;
|
|
242
|
-
const functionDir =
|
|
292
|
+
const functionDir = path3.join(functionsDir, `${functionName}.func`);
|
|
243
293
|
await fs.cp(baseFunctionDir, functionDir, { recursive: true, force: true });
|
|
244
294
|
await configureVercelFunction(functionDir, group.config, fs);
|
|
245
295
|
destinations.set(key, `/${functionName}`);
|
|
@@ -289,7 +339,7 @@ function farmRoutePatternToVercelSource(pattern) {
|
|
|
289
339
|
}
|
|
290
340
|
__name(farmRoutePatternToVercelSource, "farmRoutePatternToVercelSource");
|
|
291
341
|
async function configureVercelFunction(functionDir, config, fs) {
|
|
292
|
-
const configPath =
|
|
342
|
+
const configPath = path3.join(functionDir, ".vc-config.json");
|
|
293
343
|
const current = JSON.parse(await fs.readFile(configPath, "utf8"));
|
|
294
344
|
const next = {
|
|
295
345
|
...current,
|
|
@@ -338,8 +388,9 @@ function createFarmVercelImmutableAssetRoute(basePath = "/") {
|
|
|
338
388
|
const normalizedBasePath = normalizeBasePath(basePath);
|
|
339
389
|
const escapedBasePath = escapeRegex(normalizedBasePath);
|
|
340
390
|
const prefix = escapedBasePath ? `/${escapedBasePath}` : "";
|
|
391
|
+
const fingerprint = "-h(?:[a-fA-F0-9]{8}|[a-fA-F0-9]{12}|[a-fA-F0-9]{16})";
|
|
341
392
|
return {
|
|
342
|
-
src: `^${prefix}/(?:assets|chunks)/(?:.+/)*[^/]
|
|
393
|
+
src: `^${prefix}/(?:(?:assets|chunks)/(?:.+/)*[^/]+|farm-client)${fingerprint}\\.(?!(?:[hH][tT][mM][lL]?)$)[^/]+$`,
|
|
343
394
|
headers: {
|
|
344
395
|
"Cache-Control": FARM_IMMUTABLE_ASSET_CACHE_CONTROL
|
|
345
396
|
},
|
|
@@ -566,7 +617,7 @@ function preloadFarmNitroRuntime() {
|
|
|
566
617
|
}
|
|
567
618
|
__name(preloadFarmNitroRuntime, "preloadFarmNitroRuntime");
|
|
568
619
|
var _filename = typeof import.meta.url !== "undefined" ? fileURLToPath(import.meta.url) : "";
|
|
569
|
-
var _dirname =
|
|
620
|
+
var _dirname = path4.dirname(_filename);
|
|
570
621
|
var NODE_BUILTIN_MODULES = /* @__PURE__ */ new Set([
|
|
571
622
|
...builtinModules,
|
|
572
623
|
...builtinModules.map((moduleName) => `node:${moduleName}`)
|
|
@@ -595,14 +646,14 @@ var FARM_SSR_PACKAGE_IMPORT = "#farm-ssr-entry";
|
|
|
595
646
|
var FARM_SSR_OUTPUT_DIR = "farm-ssr";
|
|
596
647
|
var FARM_CLIENT_BUILD_TARGET = ["es2020", "edge88", "firefox78", "chrome87", "safari14"];
|
|
597
648
|
function resolveNitroRuntimeDependency(root, specifier) {
|
|
598
|
-
const projectRequire = createRequire(
|
|
649
|
+
const projectRequire = createRequire(path4.join(root, "package.json"));
|
|
599
650
|
let runtimeRequire = projectRequire;
|
|
600
651
|
try {
|
|
601
652
|
runtimeRequire = createRequire(projectRequire.resolve("@farm.js/core"));
|
|
602
653
|
} catch {
|
|
603
654
|
}
|
|
604
655
|
const nitroEntry = runtimeRequire.resolve("nitro");
|
|
605
|
-
return createRequire(nitroEntry).resolve(specifier).split(
|
|
656
|
+
return createRequire(nitroEntry).resolve(specifier).split(path4.sep).join("/");
|
|
606
657
|
}
|
|
607
658
|
__name(resolveNitroRuntimeDependency, "resolveNitroRuntimeDependency");
|
|
608
659
|
function cloneConfigValue(value, seen = /* @__PURE__ */ new WeakMap()) {
|
|
@@ -696,7 +747,7 @@ function createMetadataImageWasmPlugin() {
|
|
|
696
747
|
return null;
|
|
697
748
|
}
|
|
698
749
|
const requestPath = source.slice(0, -"?module".length);
|
|
699
|
-
const resolvedPath =
|
|
750
|
+
const resolvedPath = path4.isAbsolute(requestPath) ? requestPath : path4.resolve(path4.dirname(importer.split("?", 1)[0]), requestPath);
|
|
700
751
|
return `${FARM_METADATA_IMAGE_WASM_PREFIX}${resolvedPath}`;
|
|
701
752
|
},
|
|
702
753
|
load(id) {
|
|
@@ -722,11 +773,11 @@ function collectSSRExternalPackages(ssrBundle) {
|
|
|
722
773
|
for (const importId of [...output.imports, ...output.dynamicImports]) {
|
|
723
774
|
const normalizedImportId = importId.replace(/\\/g, "/");
|
|
724
775
|
const normalizedId = normalizedImportId.replace(/^\.\//, "");
|
|
725
|
-
const resolvedRelativeId = normalizedImportId.startsWith("./") || normalizedImportId.startsWith("../") ?
|
|
776
|
+
const resolvedRelativeId = normalizedImportId.startsWith("./") || normalizedImportId.startsWith("../") ? path4.posix.normalize(path4.posix.join(path4.posix.dirname(fileName), normalizedImportId)) : null;
|
|
726
777
|
if (emittedFiles.has(normalizedId) || resolvedRelativeId !== null && emittedFiles.has(resolvedRelativeId) || NODE_BUILTIN_MODULES.has(importId) || importId.startsWith("node:")) {
|
|
727
778
|
continue;
|
|
728
779
|
}
|
|
729
|
-
if (
|
|
780
|
+
if (path4.isAbsolute(importId) || /^[A-Za-z]:[\\/]/.test(importId) || importId.startsWith("#") || importId.startsWith("\0")) {
|
|
730
781
|
externalPackages.add(importId);
|
|
731
782
|
continue;
|
|
732
783
|
}
|
|
@@ -739,15 +790,15 @@ function collectSSRExternalPackages(ssrBundle) {
|
|
|
739
790
|
}
|
|
740
791
|
__name(collectSSRExternalPackages, "collectSSRExternalPackages");
|
|
741
792
|
function createExternalSSRBundlePlugin(nitroEntryPath, ssrOutputDir, ssrEntryFile) {
|
|
742
|
-
const resolvedNitroEntry =
|
|
743
|
-
const resolvedSSREntry =
|
|
793
|
+
const resolvedNitroEntry = path4.resolve(nitroEntryPath);
|
|
794
|
+
const resolvedSSREntry = path4.resolve(ssrOutputDir, ssrEntryFile);
|
|
744
795
|
return {
|
|
745
796
|
name: "farm-externalize-prebuilt-ssr",
|
|
746
797
|
resolveId(source, importer) {
|
|
747
|
-
if (!importer ||
|
|
798
|
+
if (!importer || path4.resolve(importer) !== resolvedNitroEntry) {
|
|
748
799
|
return null;
|
|
749
800
|
}
|
|
750
|
-
const resolvedImport =
|
|
801
|
+
const resolvedImport = path4.resolve(path4.dirname(importer), source);
|
|
751
802
|
if (resolvedImport !== resolvedSSREntry) return null;
|
|
752
803
|
return { id: FARM_SSR_PACKAGE_IMPORT, external: true };
|
|
753
804
|
}
|
|
@@ -836,13 +887,13 @@ function resolveBuildDocsContentDir(config, root) {
|
|
|
836
887
|
if (!config.docs?.enabled) return null;
|
|
837
888
|
const configuredContentDir = config.docs.contentDir || config.docs.config.contentDir;
|
|
838
889
|
if (typeof configuredContentDir === "string" && configuredContentDir.trim()) {
|
|
839
|
-
const contentDir =
|
|
890
|
+
const contentDir = path4.isAbsolute(configuredContentDir) ? configuredContentDir : path4.join(root, configuredContentDir);
|
|
840
891
|
return existsSync(contentDir) ? contentDir : null;
|
|
841
892
|
}
|
|
842
893
|
const entryDir = config.docs.config.entry || trimSlashes(config.docs.entry) || "docs";
|
|
843
|
-
const appDocsDir =
|
|
894
|
+
const appDocsDir = path4.join(root, config.srcDir || "src", "app", entryDir);
|
|
844
895
|
if (existsSync(appDocsDir)) return appDocsDir;
|
|
845
|
-
const rootDocsDir =
|
|
896
|
+
const rootDocsDir = path4.join(root, entryDir);
|
|
846
897
|
return existsSync(rootDocsDir) ? rootDocsDir : null;
|
|
847
898
|
}
|
|
848
899
|
__name(resolveBuildDocsContentDir, "resolveBuildDocsContentDir");
|
|
@@ -860,7 +911,7 @@ function hasProjectPostcssConfig(root) {
|
|
|
860
911
|
".postcssrc.mjs",
|
|
861
912
|
".postcssrc.ts"
|
|
862
913
|
];
|
|
863
|
-
const projectRequire = createRequire(
|
|
914
|
+
const projectRequire = createRequire(path4.join(root, "package.json"));
|
|
864
915
|
return candidates.some((file) => {
|
|
865
916
|
try {
|
|
866
917
|
projectRequire.resolve(`./${file}`);
|
|
@@ -884,7 +935,7 @@ async function findFarmConfigPath(root) {
|
|
|
884
935
|
"config.mjs"
|
|
885
936
|
];
|
|
886
937
|
for (const candidate of candidates) {
|
|
887
|
-
const resolvedPath =
|
|
938
|
+
const resolvedPath = path4.join(root, candidate);
|
|
888
939
|
try {
|
|
889
940
|
await fs.access(resolvedPath);
|
|
890
941
|
return resolvedPath;
|
|
@@ -929,7 +980,7 @@ async function discoverMiddlewareRoutes(appDir) {
|
|
|
929
980
|
if (middlewareFile) {
|
|
930
981
|
discovered.push({
|
|
931
982
|
path: routePath,
|
|
932
|
-
filePath:
|
|
983
|
+
filePath: path4.join(dir, middlewareFile.name)
|
|
933
984
|
});
|
|
934
985
|
}
|
|
935
986
|
for (const entry of entries) {
|
|
@@ -937,7 +988,7 @@ async function discoverMiddlewareRoutes(appDir) {
|
|
|
937
988
|
continue;
|
|
938
989
|
}
|
|
939
990
|
const childRoutePath = routePath === "/" ? `/${entry.name}` : `${routePath}/${entry.name}`;
|
|
940
|
-
await walk(
|
|
991
|
+
await walk(path4.join(dir, entry.name), childRoutePath, discovered);
|
|
941
992
|
}
|
|
942
993
|
}
|
|
943
994
|
__name(walk, "walk");
|
|
@@ -1002,7 +1053,7 @@ async function buildUniversal(config, routeManager, apiRouteManager, serverRende
|
|
|
1002
1053
|
logger.info(`\u{1F4CB} Found ${pageRoutes.length} page routes`);
|
|
1003
1054
|
const fs = await import("fs/promises");
|
|
1004
1055
|
const layoutRoutes = [];
|
|
1005
|
-
const appDir =
|
|
1056
|
+
const appDir = path4.join(root, srcDir, "app");
|
|
1006
1057
|
async function findLayoutsForClient(dir, routePrefix = "/") {
|
|
1007
1058
|
try {
|
|
1008
1059
|
const entries = await fs.readdir(dir, { withFileTypes: true });
|
|
@@ -1010,11 +1061,11 @@ async function buildUniversal(config, routeManager, apiRouteManager, serverRende
|
|
|
1010
1061
|
if (entry.isFile() && entry.name.match(/^layout\.(tsx?|jsx?|vue|svelte)$/)) {
|
|
1011
1062
|
layoutRoutes.push({
|
|
1012
1063
|
pattern: routePrefix,
|
|
1013
|
-
modulePath:
|
|
1064
|
+
modulePath: path4.join(dir, entry.name)
|
|
1014
1065
|
});
|
|
1015
1066
|
} else if (entry.isDirectory() && !entry.name.startsWith(".") && !entry.name.startsWith("_")) {
|
|
1016
1067
|
const childPrefix = routePrefix === "/" ? `/${entry.name}` : `${routePrefix}/${entry.name}`;
|
|
1017
|
-
await findLayoutsForClient(
|
|
1068
|
+
await findLayoutsForClient(path4.join(dir, entry.name), childPrefix);
|
|
1018
1069
|
}
|
|
1019
1070
|
}
|
|
1020
1071
|
} catch {
|
|
@@ -1029,7 +1080,7 @@ async function buildUniversal(config, routeManager, apiRouteManager, serverRende
|
|
|
1029
1080
|
layoutRoutes.push({ pattern, modulePath: entry.modulePath });
|
|
1030
1081
|
}
|
|
1031
1082
|
logger.info(`\u{1F4CB} Found ${pageRoutes.length} page routes and ${layoutRoutes.length} layouts`);
|
|
1032
|
-
const clientOutputDir =
|
|
1083
|
+
const clientOutputDir = path4.join(root, distDir, "client");
|
|
1033
1084
|
const [productionViteResult] = await productionViteResultPromise;
|
|
1034
1085
|
if (productionViteResult.status === "rejected") {
|
|
1035
1086
|
await routeRuntimeManifestResultPromise;
|
|
@@ -1124,12 +1175,10 @@ async function buildUniversal(config, routeManager, apiRouteManager, serverRende
|
|
|
1124
1175
|
lifecyclePluginManager
|
|
1125
1176
|
);
|
|
1126
1177
|
const runtimeManifestPath = await writeFarmRouteRuntimeManifest(
|
|
1127
|
-
|
|
1178
|
+
path4.join(root, distDir),
|
|
1128
1179
|
routeRuntimeManifest
|
|
1129
1180
|
);
|
|
1130
|
-
logger.info(`\u{1F4CB} Route runtime manifest: ${
|
|
1131
|
-
logger.success("\u2705 Build completed successfully!");
|
|
1132
|
-
logger.info(`\u{1F4C1} Output directory: ${deployOutputDir}`);
|
|
1181
|
+
logger.info(`\u{1F4CB} Route runtime manifest: ${path4.relative(root, runtimeManifestPath)}`);
|
|
1133
1182
|
} catch (error) {
|
|
1134
1183
|
if (lifecyclePluginManager) {
|
|
1135
1184
|
await lifecyclePluginManager.runHookParallel("onError", {
|
|
@@ -1154,8 +1203,8 @@ async function writeSSRAssetsToClient(bundle, outputDir) {
|
|
|
1154
1203
|
await mergeBuiltFontCss(outputDir, output.source);
|
|
1155
1204
|
continue;
|
|
1156
1205
|
}
|
|
1157
|
-
const filePath =
|
|
1158
|
-
await fs.mkdir(
|
|
1206
|
+
const filePath = path4.join(outputDir, fileName);
|
|
1207
|
+
await fs.mkdir(path4.dirname(filePath), { recursive: true });
|
|
1159
1208
|
await fs.writeFile(filePath, output.source);
|
|
1160
1209
|
}
|
|
1161
1210
|
}
|
|
@@ -1164,8 +1213,8 @@ async function copyFarmDocsFontAssetsToClient(root, outputDir) {
|
|
|
1164
1213
|
const fs = await import("fs/promises");
|
|
1165
1214
|
await Promise.all(
|
|
1166
1215
|
resolveFarmDocsFontAssets(root).map(async ({ sourcePath, url }) => {
|
|
1167
|
-
const targetPath =
|
|
1168
|
-
await fs.mkdir(
|
|
1216
|
+
const targetPath = path4.join(outputDir, url.replace(/^\/+/, ""));
|
|
1217
|
+
await fs.mkdir(path4.dirname(targetPath), { recursive: true });
|
|
1169
1218
|
await fs.copyFile(sourcePath, targetPath);
|
|
1170
1219
|
})
|
|
1171
1220
|
);
|
|
@@ -1173,7 +1222,7 @@ async function copyFarmDocsFontAssetsToClient(root, outputDir) {
|
|
|
1173
1222
|
__name(copyFarmDocsFontAssetsToClient, "copyFarmDocsFontAssetsToClient");
|
|
1174
1223
|
async function mergeBuiltFontCss(outputDir, fontCssSource) {
|
|
1175
1224
|
const fs = await import("fs/promises");
|
|
1176
|
-
const fontCssPath =
|
|
1225
|
+
const fontCssPath = path4.join(outputDir, "farm-fonts.css");
|
|
1177
1226
|
let fontCss = fontCssSource;
|
|
1178
1227
|
if (fontCss === void 0) {
|
|
1179
1228
|
try {
|
|
@@ -1182,7 +1231,7 @@ async function mergeBuiltFontCss(outputDir, fontCssSource) {
|
|
|
1182
1231
|
return;
|
|
1183
1232
|
}
|
|
1184
1233
|
}
|
|
1185
|
-
const clientCssPath =
|
|
1234
|
+
const clientCssPath = path4.join(outputDir, "farm-client.css");
|
|
1186
1235
|
let clientCss = "";
|
|
1187
1236
|
try {
|
|
1188
1237
|
clientCss = await fs.readFile(clientCssPath, "utf8");
|
|
@@ -1203,7 +1252,8 @@ __name(_IncompleteClientBuildOutputError, "IncompleteClientBuildOutputError");
|
|
|
1203
1252
|
var IncompleteClientBuildOutputError = _IncompleteClientBuildOutputError;
|
|
1204
1253
|
async function validateClientBuildOutput(root, srcDir, outputDir) {
|
|
1205
1254
|
const fs = await import("fs/promises");
|
|
1206
|
-
const
|
|
1255
|
+
const fingerprinted = await findFingerprintedClientEntry(outputDir);
|
|
1256
|
+
const clientEntryPath = path4.join(outputDir, fingerprinted ?? "farm-client.js");
|
|
1207
1257
|
let clientEntrySize = 0;
|
|
1208
1258
|
try {
|
|
1209
1259
|
const clientEntry = await fs.stat(clientEntryPath);
|
|
@@ -1213,8 +1263,8 @@ async function validateClientBuildOutput(root, srcDir, outputDir) {
|
|
|
1213
1263
|
if (clientEntrySize === 0) {
|
|
1214
1264
|
throw new IncompleteClientBuildOutputError("farm-client.js is missing or empty");
|
|
1215
1265
|
}
|
|
1216
|
-
const clientCssPath =
|
|
1217
|
-
const globalsCssPath =
|
|
1266
|
+
const clientCssPath = path4.join(outputDir, "farm-client.css");
|
|
1267
|
+
const globalsCssPath = path4.join(root, srcDir, "app", "globals.css");
|
|
1218
1268
|
let expectsCss = false;
|
|
1219
1269
|
try {
|
|
1220
1270
|
const globalsCss = await fs.readFile(globalsCssPath, "utf8");
|
|
@@ -1345,10 +1395,10 @@ async function buildClient(productionVite, config, root, srcDir, outputDir, page
|
|
|
1345
1395
|
logger.info(
|
|
1346
1396
|
`\u{1F4F1} Total hydratable routes detected: ${clientPages.length} pages, ${clientLayouts.filter((layout) => layout.shouldHydrate).length} layouts, and ${clientRouteSlots.length} slots`
|
|
1347
1397
|
);
|
|
1348
|
-
const clientEntryRoot =
|
|
1398
|
+
const clientEntryRoot = path4.join(root, ".farm", "tmp");
|
|
1349
1399
|
await fs.mkdir(clientEntryRoot, { recursive: true });
|
|
1350
|
-
const clientEntryDir = await fs.mkdtemp(
|
|
1351
|
-
const clientEntryPath =
|
|
1400
|
+
const clientEntryDir = await fs.mkdtemp(path4.join(clientEntryRoot, "client-entry-"));
|
|
1401
|
+
const clientEntryPath = path4.join(clientEntryDir, "farm-client-entry.tsx");
|
|
1352
1402
|
const clientHydrationCode = generateClientHydrationEntry(
|
|
1353
1403
|
clientPages,
|
|
1354
1404
|
clientLayouts,
|
|
@@ -1374,7 +1424,7 @@ async function buildClient(productionVite, config, root, srcDir, outputDir, page
|
|
|
1374
1424
|
if (hasScopedPostcssConfig) {
|
|
1375
1425
|
logger.info("\u{1F4E6} Using project PostCSS/Tailwind configuration");
|
|
1376
1426
|
} else {
|
|
1377
|
-
const postcssConfigPath =
|
|
1427
|
+
const postcssConfigPath = path4.join(clientEntryDir, "postcss.config.cjs");
|
|
1378
1428
|
await fs.writeFile(postcssConfigPath, "module.exports = { plugins: [] };\n");
|
|
1379
1429
|
postcssSearchPath = clientEntryDir;
|
|
1380
1430
|
try {
|
|
@@ -1407,7 +1457,7 @@ async function buildClient(productionVite, config, root, srcDir, outputDir, page
|
|
|
1407
1457
|
"farm-client": clientEntryPath
|
|
1408
1458
|
},
|
|
1409
1459
|
output: {
|
|
1410
|
-
entryFileNames: "[name].js",
|
|
1460
|
+
entryFileNames: "[name]-h[hash].js",
|
|
1411
1461
|
chunkFileNames: "chunks/[name]-h[hash].js",
|
|
1412
1462
|
hashCharacters: "hex",
|
|
1413
1463
|
// Use predictable name for CSS so we can reference it in SSR HTML
|
|
@@ -1725,7 +1775,7 @@ function generateClientHydrationEntry(clientPages, layoutRoutes, clientRouteSlot
|
|
|
1725
1775
|
);
|
|
1726
1776
|
const rendererClientImports = isReactRenderer(renderer) ? `import React from "react";
|
|
1727
1777
|
import { createRoot, hydrateRoot } from "react-dom/client";` : `import React, { createRoot, hydrateRoot } from ${JSON.stringify(renderer.client)};`;
|
|
1728
|
-
const globalsCssPath =
|
|
1778
|
+
const globalsCssPath = path4.join(root, srcDir, "app", "globals.css");
|
|
1729
1779
|
const cssImportPath = toImportPath(globalsCssPath);
|
|
1730
1780
|
const cssImport = `import ${JSON.stringify(cssImportPath)};`;
|
|
1731
1781
|
const layoutImportStatements = [];
|
|
@@ -2994,9 +3044,9 @@ async function buildSSRInMemory(productionVite, config, root, routeManager, apiR
|
|
|
2994
3044
|
ssr: true
|
|
2995
3045
|
});
|
|
2996
3046
|
if (!hasScopedPostcssConfig) {
|
|
2997
|
-
postcssConfigDir = await fs.mkdtemp(
|
|
3047
|
+
postcssConfigDir = await fs.mkdtemp(path4.join(os.tmpdir(), "farm-postcss-"));
|
|
2998
3048
|
await fs.writeFile(
|
|
2999
|
-
|
|
3049
|
+
path4.join(postcssConfigDir, "postcss.config.cjs"),
|
|
3000
3050
|
"module.exports = { plugins: [] };\n"
|
|
3001
3051
|
);
|
|
3002
3052
|
try {
|
|
@@ -3074,7 +3124,7 @@ async function buildSSRInMemory(productionVite, config, root, routeManager, apiR
|
|
|
3074
3124
|
const notFoundExtensions = getFarmRendererComponentExtensions(config.renderer);
|
|
3075
3125
|
for (const sourceAppDir of appDirs) {
|
|
3076
3126
|
for (const ext of notFoundExtensions) {
|
|
3077
|
-
const checkPath =
|
|
3127
|
+
const checkPath = path4.join(sourceAppDir, `not-found${ext}`);
|
|
3078
3128
|
try {
|
|
3079
3129
|
await fs.access(checkPath);
|
|
3080
3130
|
notFoundPath = checkPath;
|
|
@@ -3506,7 +3556,7 @@ import { dirname as farmDocsDirname, join as farmDocsJoin } from "node:path";
|
|
|
3506
3556
|
import { fileURLToPath as farmDocsFileURLToPath } from "node:url";` : "";
|
|
3507
3557
|
const markdownHandlerImport = config.md?.enabled ? `import { applyMarkdownNegotiationHeaders, createMarkdownMirrorResponse } from "@farm.js/core/markdown";` : "";
|
|
3508
3558
|
const appMarkdownImport = hasMarkdownPages ? `import { createFarmMarkdownRouteModule, createFarmMarkdownSourceResponse } from "@farm.js/core/app-markdown";` : "const createFarmMarkdownSourceResponse = null;";
|
|
3509
|
-
const mdxComponentsPath = typeof config.mdx?.components === "string" ?
|
|
3559
|
+
const mdxComponentsPath = typeof config.mdx?.components === "string" ? path4.isAbsolute(config.mdx.components) ? config.mdx.components : path4.join(config.root, config.mdx.components) : null;
|
|
3510
3560
|
const mdxComponentsImport = mdxComponentsPath ? `import * as FarmMdxComponentsModule from "${mdxComponentsPath.replace(/\\/g, "/")}";` : "";
|
|
3511
3561
|
const layerConfigPaths = (config.layers || []).map((layer) => layer.configFile).filter((configFile) => Boolean(configFile)).filter((configFile) => configFile !== configModulePath);
|
|
3512
3562
|
const layerConfigImports = layerConfigPaths.map(
|
|
@@ -3781,8 +3831,8 @@ const farmDocsHandler = ${config.docs?.enabled ? adapterOwnsDocsRuntime ? `creat
|
|
|
3781
3831
|
contentDir: farmDocsResolvedConfig.contentDir || farmDocsResolvedConfig.config?.contentDir,
|
|
3782
3832
|
}, {
|
|
3783
3833
|
rootDir: farmDocsRuntimeRoot,
|
|
3784
|
-
clientEntry: "/
|
|
3785
|
-
stylesheets: ["/farm-fonts.css", "/
|
|
3834
|
+
clientEntry: "/__farm_client_js_src__",
|
|
3835
|
+
stylesheets: ["/farm-fonts.css", "/__farm_client_css_href__"],
|
|
3786
3836
|
resolveLayoutFonts: (pathname) =>
|
|
3787
3837
|
resolveFarmLayoutFonts(
|
|
3788
3838
|
getApplicableLayouts(getFarmRoutePathname(pathname)).map((layout) => layout.module),
|
|
@@ -3791,7 +3841,7 @@ const farmDocsHandler = ${config.docs?.enabled ? adapterOwnsDocsRuntime ? `creat
|
|
|
3791
3841
|
})` : `createFarmDocsHandler(farmDocsResolvedConfig, {
|
|
3792
3842
|
root: farmDocsRuntimeRoot,
|
|
3793
3843
|
srcDir: ${JSON.stringify(config.srcDir)},
|
|
3794
|
-
clientEntry: "/
|
|
3844
|
+
clientEntry: "/__farm_client_js_src__",
|
|
3795
3845
|
fontAssets: ${JSON.stringify(farmDocsFontAssets)},
|
|
3796
3846
|
resolveLayoutFonts: (pathname) =>
|
|
3797
3847
|
resolveFarmLayoutFonts(
|
|
@@ -4134,12 +4184,12 @@ function createFarmErrorDocument(html, title) {
|
|
|
4134
4184
|
' <meta name="viewport" content="width=device-width, initial-scale=1">\\n' +
|
|
4135
4185
|
' <link rel="icon" href="data:,">\\n' +
|
|
4136
4186
|
' <title>' + escapedTitle + '</title>\\n' +
|
|
4137
|
-
' <link rel="stylesheet" href="/
|
|
4187
|
+
' <link rel="stylesheet" href="/__farm_client_css_href__">\\n' +
|
|
4138
4188
|
renderFarmRendererHydrationScript() + '\\n' +
|
|
4139
4189
|
'</head>\\n<body>\\n' +
|
|
4140
4190
|
' <div id="root">' + html + '</div>\\n' +
|
|
4141
4191
|
' ' + renderFarmClientBootstrapScript() + '\\n' +
|
|
4142
|
-
' <script type="module" src="/
|
|
4192
|
+
' <script type="module" src="/__farm_client_js_src__"></script>\\n' +
|
|
4143
4193
|
'</body>\\n</html>';
|
|
4144
4194
|
}
|
|
4145
4195
|
|
|
@@ -4150,7 +4200,7 @@ function createFarmErrorDocument(html, title) {
|
|
|
4150
4200
|
.replace(/<\\/body>/i, '</div></body>');
|
|
4151
4201
|
}
|
|
4152
4202
|
fullHtml = fullHtml
|
|
4153
|
-
.replace(/<head([^>]*)>/i, '<head$1>\\n <link rel="stylesheet" href="/
|
|
4203
|
+
.replace(/<head([^>]*)>/i, '<head$1>\\n <link rel="stylesheet" href="/__farm_client_css_href__">')
|
|
4154
4204
|
.replace(/<\\/head>/i, renderFarmRendererHydrationScript() + '\\n</head>')
|
|
4155
4205
|
.replace(/<head([^>]*)>([\\s\\S]*?)<\\/head>/i, function(match, attrs, headContent) {
|
|
4156
4206
|
return headContent.includes("<title")
|
|
@@ -4160,7 +4210,7 @@ function createFarmErrorDocument(html, title) {
|
|
|
4160
4210
|
.replace(
|
|
4161
4211
|
/<\\/body>/i,
|
|
4162
4212
|
' ' + renderFarmClientBootstrapScript() + '\\n' +
|
|
4163
|
-
' <script type="module" src="/
|
|
4213
|
+
' <script type="module" src="/__farm_client_js_src__"></script>\\n</body>',
|
|
4164
4214
|
);
|
|
4165
4215
|
return fullHtml.trim().startsWith("<!DOCTYPE")
|
|
4166
4216
|
? fullHtml
|
|
@@ -4876,8 +4926,8 @@ ${config.docs?.enabled ? `async function wrapFarmDocsResponseWithLayouts(request
|
|
|
4876
4926
|
bodyMatch[0],
|
|
4877
4927
|
"<body" + bodyMatch[1] + ">" + rootMarkup + "</body>",
|
|
4878
4928
|
);
|
|
4879
|
-
if (!html.includes('href="/
|
|
4880
|
-
const clientStylesheet = ' <link rel="stylesheet" href="/
|
|
4929
|
+
if (!html.includes('href="/__farm_client_css_href__"')) {
|
|
4930
|
+
const clientStylesheet = ' <link rel="stylesheet" href="/__farm_client_css_href__">\\n';
|
|
4881
4931
|
const firstStyleIndex = html.search(/<style(?:\\s|>)/i);
|
|
4882
4932
|
html =
|
|
4883
4933
|
firstStyleIndex >= 0
|
|
@@ -4887,10 +4937,10 @@ ${config.docs?.enabled ? `async function wrapFarmDocsResponseWithLayouts(request
|
|
|
4887
4937
|
if (!html.includes('id="__farm_route_slots_data__"')) {
|
|
4888
4938
|
html = html.replace(/<[/]body>/i, renderFarmClientBootstrapScript() + "\\n</body>");
|
|
4889
4939
|
}
|
|
4890
|
-
if (!html.includes('src="/
|
|
4940
|
+
if (!html.includes('src="/__farm_client_js_src__"')) {
|
|
4891
4941
|
html = html.replace(
|
|
4892
4942
|
/<[/]body>/i,
|
|
4893
|
-
' <script type="module" src="/
|
|
4943
|
+
' <script type="module" src="/__farm_client_js_src__"></script>\\n</body>',
|
|
4894
4944
|
);
|
|
4895
4945
|
}
|
|
4896
4946
|
if (!html.includes('window._$HY')) {
|
|
@@ -5620,8 +5670,8 @@ async function handleFarmRequestInContext(
|
|
|
5620
5670
|
' <meta name="viewport" content="width=device-width, initial-scale=1">\\n' +
|
|
5621
5671
|
(hasFavicon ? '' : ' <link rel="icon" href="data:,">\\n') +
|
|
5622
5672
|
' <title>' + title + '</title>' + metaTags + '\\n' +
|
|
5623
|
-
' <link rel="stylesheet" href="/
|
|
5624
|
-
' <link rel="modulepreload" href="/
|
|
5673
|
+
' <link rel="stylesheet" href="/__farm_client_css_href__">\\n' +
|
|
5674
|
+
' <link rel="modulepreload" href="/__farm_client_js_src__">\\n' +
|
|
5625
5675
|
renderFarmRendererHydrationScript() + '\\n' +
|
|
5626
5676
|
'</head>\\n<body>\\n <div id="root">';
|
|
5627
5677
|
const streamSuffix = '</div>\\n' +
|
|
@@ -5630,7 +5680,7 @@ async function handleFarmRequestInContext(
|
|
|
5630
5680
|
routeSlotPayload,
|
|
5631
5681
|
clientPageProps
|
|
5632
5682
|
) + '\\n' +
|
|
5633
|
-
' <script type="module" src="/
|
|
5683
|
+
' <script type="module" src="/__farm_client_js_src__"></script>\\n' +
|
|
5634
5684
|
'</body>\\n</html>';
|
|
5635
5685
|
const themedStreamPrefix = streamPrefix.replace(
|
|
5636
5686
|
'<html lang="en">',
|
|
@@ -5675,7 +5725,7 @@ async function handleFarmRequestInContext(
|
|
|
5675
5725
|
// Layout provides full HTML structure - inject CSS and client script
|
|
5676
5726
|
fullHtml = html
|
|
5677
5727
|
// Inject CSS link after opening head tag or first meta tag
|
|
5678
|
-
.replace(/<head([^>]*)>/i, '<head$1>\\n <link rel="stylesheet" href="/
|
|
5728
|
+
.replace(/<head([^>]*)>/i, '<head$1>\\n <link rel="stylesheet" href="/__farm_client_css_href__">')
|
|
5679
5729
|
.replace(/<\\/head>/i, renderFarmRendererHydrationScript() + '\\n</head>')
|
|
5680
5730
|
// Inject title if not present and we have one
|
|
5681
5731
|
.replace(/<head([^>]*)>([\\s\\S]*?)<\\/head>/i, (match, attrs, headContent) => {
|
|
@@ -5696,7 +5746,7 @@ async function handleFarmRequestInContext(
|
|
|
5696
5746
|
routeSlotPayload,
|
|
5697
5747
|
clientPageProps
|
|
5698
5748
|
) + '\\n' +
|
|
5699
|
-
' <script type="module" src="/
|
|
5749
|
+
' <script type="module" src="/__farm_client_js_src__"></script>\\n</body>',
|
|
5700
5750
|
);
|
|
5701
5751
|
|
|
5702
5752
|
// Add DOCTYPE if not present
|
|
@@ -5712,13 +5762,13 @@ async function handleFarmRequestInContext(
|
|
|
5712
5762
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
5713
5763
|
\${hasFavicon ? "" : '<link rel="icon" href="data:,">'}
|
|
5714
5764
|
<title>\${title}</title>\${metaTags}
|
|
5715
|
-
<link rel="stylesheet" href="/
|
|
5765
|
+
<link rel="stylesheet" href="/__farm_client_css_href__">
|
|
5716
5766
|
\${renderFarmRendererHydrationScript()}
|
|
5717
5767
|
</head>
|
|
5718
5768
|
<body>
|
|
5719
5769
|
<div id="root">\${html}</div>
|
|
5720
5770
|
\${renderFarmClientBootstrapScript(pageProps.__farmCanonicalPath, routeSlotPayload, clientPageProps)}
|
|
5721
|
-
<script type="module" src="/
|
|
5771
|
+
<script type="module" src="/__farm_client_js_src__"></script>
|
|
5722
5772
|
</body>
|
|
5723
5773
|
</html>\`;
|
|
5724
5774
|
}
|
|
@@ -5977,12 +6027,12 @@ async function handleFarmRequestInContext(
|
|
|
5977
6027
|
let fullHtml;
|
|
5978
6028
|
if (hasFullDocument) {
|
|
5979
6029
|
fullHtml = html
|
|
5980
|
-
.replace(/<head([^>]*)>/i, '<head$1>\\n <link rel="stylesheet" href="/
|
|
6030
|
+
.replace(/<head([^>]*)>/i, '<head$1>\\n <link rel="stylesheet" href="/__farm_client_css_href__">')
|
|
5981
6031
|
.replace(/<\\/head>/i, renderFarmRendererHydrationScript() + '\\n</head>')
|
|
5982
6032
|
.replace(
|
|
5983
6033
|
/<\\/body>/i,
|
|
5984
6034
|
' ' + renderFarmClientBootstrapScript() + '\\n' +
|
|
5985
|
-
' <script type="module" src="/
|
|
6035
|
+
' <script type="module" src="/__farm_client_js_src__"></script>\\n</body>',
|
|
5986
6036
|
);
|
|
5987
6037
|
if (!fullHtml.trim().startsWith('<!DOCTYPE')) {
|
|
5988
6038
|
fullHtml = '<!DOCTYPE html>\\n' + fullHtml;
|
|
@@ -5994,14 +6044,14 @@ async function handleFarmRequestInContext(
|
|
|
5994
6044
|
<meta charset="UTF-8">
|
|
5995
6045
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
5996
6046
|
<link rel="icon" href="data:,">
|
|
5997
|
-
<link rel="stylesheet" href="/
|
|
6047
|
+
<link rel="stylesheet" href="/__farm_client_css_href__">
|
|
5998
6048
|
<title>404 - Page Not Found</title>
|
|
5999
6049
|
\${renderFarmRendererHydrationScript()}
|
|
6000
6050
|
</head>
|
|
6001
6051
|
<body>
|
|
6002
6052
|
<div id="root">\${html}</div>
|
|
6003
6053
|
\${renderFarmClientBootstrapScript()}
|
|
6004
|
-
<script type="module" src="/
|
|
6054
|
+
<script type="module" src="/__farm_client_js_src__"></script>
|
|
6005
6055
|
</body>
|
|
6006
6056
|
</html>\`;
|
|
6007
6057
|
}
|
|
@@ -6338,7 +6388,7 @@ async function buildNitroUniversal(config, routeManager, apiRouteManager, server
|
|
|
6338
6388
|
const isVercel = preset === "vercel" || preset === "vercel-edge";
|
|
6339
6389
|
const isCloudflareWorker = preset === "cloudflare-module";
|
|
6340
6390
|
const outputDir = resolveDeployOutputPath(root, config.deploy.outputDir);
|
|
6341
|
-
const ssrOutputDir =
|
|
6391
|
+
const ssrOutputDir = path4.join(root, distDir, "ssr");
|
|
6342
6392
|
const imageRuntime = resolveImageRuntime(config, preset);
|
|
6343
6393
|
const hasGeneratedMetadataImages = Array.from(routeManager.getMetadataImages().values()).some(
|
|
6344
6394
|
(image) => image.sourceType === "module"
|
|
@@ -6407,13 +6457,26 @@ async function buildNitroUniversal(config, routeManager, apiRouteManager, server
|
|
|
6407
6457
|
}
|
|
6408
6458
|
const scheduledTasks = mergeScheduledTasks(farmWorkflows.scheduledTasks, farmCron.scheduledTasks);
|
|
6409
6459
|
const cloudflareCronConfig = createFarmCronCloudflareConfig(farmCron.jobs);
|
|
6460
|
+
const [clientCssHref, clientJsSrc] = await Promise.all([
|
|
6461
|
+
resolveHashedClientCssHref(clientOutputDir),
|
|
6462
|
+
resolveHashedClientJsSrc(clientOutputDir)
|
|
6463
|
+
]);
|
|
6464
|
+
for (const output of Object.values(ssrBundle)) {
|
|
6465
|
+
if (output.type !== "chunk") continue;
|
|
6466
|
+
if (output.code.includes(FARM_CLIENT_CSS_HREF_PLACEHOLDER)) {
|
|
6467
|
+
output.code = output.code.split(FARM_CLIENT_CSS_HREF_PLACEHOLDER).join(clientCssHref);
|
|
6468
|
+
}
|
|
6469
|
+
if (output.code.includes(FARM_CLIENT_JS_SRC_PLACEHOLDER)) {
|
|
6470
|
+
output.code = output.code.split(FARM_CLIENT_JS_SRC_PLACEHOLDER).join(clientJsSrc);
|
|
6471
|
+
}
|
|
6472
|
+
}
|
|
6410
6473
|
await fs.mkdir(ssrOutputDir, { recursive: true });
|
|
6411
6474
|
for (const [fileName, output] of Object.entries(ssrBundle)) {
|
|
6412
|
-
const filePath =
|
|
6413
|
-
await fs.mkdir(
|
|
6475
|
+
const filePath = path4.join(ssrOutputDir, fileName);
|
|
6476
|
+
await fs.mkdir(path4.dirname(filePath), { recursive: true });
|
|
6414
6477
|
await fs.writeFile(filePath, output.type === "chunk" ? output.code : output.source);
|
|
6415
6478
|
}
|
|
6416
|
-
const nitroEntryPath =
|
|
6479
|
+
const nitroEntryPath = path4.join(ssrOutputDir, "nitro-entry.mjs");
|
|
6417
6480
|
const nitroEntryCode = `
|
|
6418
6481
|
// Farm.js Nitro Entry
|
|
6419
6482
|
// This file adapts Farm's Web fetch handler to Nitro's event handler contract.
|
|
@@ -6478,12 +6541,12 @@ export default async function farmNitroEventHandler(event) {
|
|
|
6478
6541
|
}
|
|
6479
6542
|
`.trim();
|
|
6480
6543
|
await fs.writeFile(nitroEntryPath, nitroEntryCode);
|
|
6481
|
-
const farmNodeServerEntryPath = preset === "node-server" ?
|
|
6544
|
+
const farmNodeServerEntryPath = preset === "node-server" ? path4.join(ssrOutputDir, "farm-node-server-entry.mjs") : null;
|
|
6482
6545
|
if (farmNodeServerEntryPath) {
|
|
6483
6546
|
await fs.writeFile(
|
|
6484
6547
|
farmNodeServerEntryPath,
|
|
6485
6548
|
createFarmNodeServerEntry({
|
|
6486
|
-
nitroEntryFile:
|
|
6549
|
+
nitroEntryFile: path4.basename(nitroEntryPath),
|
|
6487
6550
|
nodeHandlerModule: resolveNitroRuntimeDependency(root, "srvx/node"),
|
|
6488
6551
|
server: config.server,
|
|
6489
6552
|
websocketAdapterModule: resolveNitroRuntimeDependency(root, "crossws/adapters/node")
|
|
@@ -6517,12 +6580,12 @@ export default async function farmNitroEventHandler(event) {
|
|
|
6517
6580
|
...farmNodeServerEntryPath ? { entry: farmNodeServerEntryPath } : {},
|
|
6518
6581
|
rootDir: root,
|
|
6519
6582
|
srcDir: root,
|
|
6520
|
-
buildDir:
|
|
6583
|
+
buildDir: path4.join(root, distDir, ".nitro"),
|
|
6521
6584
|
compatibilityDate: "2024-12-01",
|
|
6522
6585
|
output: {
|
|
6523
6586
|
dir: outputDir,
|
|
6524
|
-
serverDir:
|
|
6525
|
-
publicDir:
|
|
6587
|
+
serverDir: path4.join(outputDir, "server"),
|
|
6588
|
+
publicDir: path4.join(outputDir, "public")
|
|
6526
6589
|
},
|
|
6527
6590
|
publicAssets: [
|
|
6528
6591
|
{
|
|
@@ -6607,7 +6670,7 @@ export default async function farmNitroEventHandler(event) {
|
|
|
6607
6670
|
if (pluginManager) {
|
|
6608
6671
|
nitroConfig = await pluginManager.runHookSerial("beforeNitroBuild", nitroConfig);
|
|
6609
6672
|
}
|
|
6610
|
-
const expectedServerDir =
|
|
6673
|
+
const expectedServerDir = path4.join(outputDir, "server");
|
|
6611
6674
|
const customRollupKeys = Object.keys(nitroConfig.rollupConfig || {}).filter(
|
|
6612
6675
|
(key) => key !== "external" && key !== "plugins"
|
|
6613
6676
|
);
|
|
@@ -6623,9 +6686,9 @@ export default async function farmNitroEventHandler(event) {
|
|
|
6623
6686
|
snapshotSSRRebundleOptions(nitroConfig)
|
|
6624
6687
|
);
|
|
6625
6688
|
const requestedBuilder = nitroConfig.builder ?? process.env.NITRO_BUILDER;
|
|
6626
|
-
const canReusePrebuiltSSR = isPrebuiltSSRCandidate && nitroConfig.preset === "node-server" && (requestedBuilder === void 0 || requestedBuilder === "rollup" || requestedBuilder === "rolldown") && nitroConfig.sourceMap === false && !hasUnsupportedEsbuildOverrides && !hasLateBuildMutationConfig && !hasUnsupportedSSRRebundleOverrides && nitroConfig.rollupConfig?.external === nitroRollupExternal && !hasRollupPlugins(nitroConfig.rollupConfig?.plugins) && customRollupKeys.length === 0 &&
|
|
6689
|
+
const canReusePrebuiltSSR = isPrebuiltSSRCandidate && nitroConfig.preset === "node-server" && (requestedBuilder === void 0 || requestedBuilder === "rollup" || requestedBuilder === "rolldown") && nitroConfig.sourceMap === false && !hasUnsupportedEsbuildOverrides && !hasLateBuildMutationConfig && !hasUnsupportedSSRRebundleOverrides && nitroConfig.rollupConfig?.external === nitroRollupExternal && !hasRollupPlugins(nitroConfig.rollupConfig?.plugins) && customRollupKeys.length === 0 && path4.resolve(nitroConfig.output?.serverDir || "") === path4.resolve(expectedServerDir) && Boolean(
|
|
6627
6690
|
nitroConfig.handlers?.some(
|
|
6628
|
-
(handler) =>
|
|
6691
|
+
(handler) => path4.resolve(handler?.handler || "") === nitroEntryPath
|
|
6629
6692
|
)
|
|
6630
6693
|
);
|
|
6631
6694
|
const selectRolldownBuilder = canReusePrebuiltSSR && requestedBuilder === void 0 && await canUseRolldownBuilder();
|
|
@@ -6637,8 +6700,9 @@ export default async function farmNitroEventHandler(event) {
|
|
|
6637
6700
|
...configuredEsbuildOptions,
|
|
6638
6701
|
// Function-name helpers are unsafe for provider scripts that serialize a
|
|
6639
6702
|
// function with toString(); the helper is outside the emitted script scope.
|
|
6640
|
-
keepNames:
|
|
6703
|
+
keepNames: config.docs?.enabled && config.docs.adapter?.server ? false : configuredEsbuildOptions.keepNames ?? true
|
|
6641
6704
|
};
|
|
6705
|
+
const prebuiltSSREsbuildOptions = config.docs?.enabled && config.docs.adapter?.server ? resolvedEsbuildOptions : configuredEsbuildOptions;
|
|
6642
6706
|
const effectiveMinify = configuredEsbuildOptions.minify ?? shouldMinify;
|
|
6643
6707
|
const useFarmEsbuildMinifier = effectiveMinify && nitroConfig.sourceMap === false && !hasUnsupportedEsbuildOverrides && !hasLateBuildMutationConfig;
|
|
6644
6708
|
const esbuildChunkMinifier = useFarmEsbuildMinifier ? createEsbuildChunkMinifyPlugin(resolvedEsbuildOptions) : null;
|
|
@@ -6680,10 +6744,10 @@ export default async function farmNitroEventHandler(event) {
|
|
|
6680
6744
|
});
|
|
6681
6745
|
}
|
|
6682
6746
|
prerenderer.hooks.hook("compiled", async () => {
|
|
6683
|
-
const prerenderServerDir =
|
|
6747
|
+
const prerenderServerDir = path4.join(outputDir, "server");
|
|
6684
6748
|
await copyPrebuiltSSRBundle(
|
|
6685
6749
|
ssrBundle,
|
|
6686
|
-
|
|
6750
|
+
path4.join(prerenderServerDir, FARM_SSR_OUTPUT_DIR),
|
|
6687
6751
|
{},
|
|
6688
6752
|
false,
|
|
6689
6753
|
fs
|
|
@@ -6717,20 +6781,20 @@ export default async function farmNitroEventHandler(event) {
|
|
|
6717
6781
|
const copyResults = await Promise.allSettled([
|
|
6718
6782
|
canReusePrebuiltSSR ? copyPrebuiltSSRBundle(
|
|
6719
6783
|
ssrBundle,
|
|
6720
|
-
|
|
6721
|
-
|
|
6784
|
+
path4.join(outputDir, "server", FARM_SSR_OUTPUT_DIR),
|
|
6785
|
+
prebuiltSSREsbuildOptions,
|
|
6722
6786
|
effectiveMinify,
|
|
6723
6787
|
fs
|
|
6724
6788
|
) : Promise.resolve(),
|
|
6725
|
-
imageRuntime === "node" ? copySharpRuntime(config, root,
|
|
6726
|
-
useExternalMetadataImageRuntime ? copyMetadataImageRuntime(root,
|
|
6789
|
+
imageRuntime === "node" ? copySharpRuntime(config, root, path4.join(outputDir, "server"), fs) : Promise.resolve(),
|
|
6790
|
+
useExternalMetadataImageRuntime ? copyMetadataImageRuntime(root, path4.join(outputDir, "server"), fs) : Promise.resolve()
|
|
6727
6791
|
]);
|
|
6728
6792
|
const failedCopy = copyResults.find(
|
|
6729
6793
|
(result) => result.status === "rejected"
|
|
6730
6794
|
);
|
|
6731
6795
|
if (failedCopy) throw failedCopy.reason;
|
|
6732
6796
|
if (canReusePrebuiltSSR) {
|
|
6733
|
-
await registerPrebuiltSSRPackageImport(
|
|
6797
|
+
await registerPrebuiltSSRPackageImport(path4.join(outputDir, "server"), ssrEntryFile, fs);
|
|
6734
6798
|
logger.info("\u26A1 Reused Farm's prebuilt SSR bundle for the Node output");
|
|
6735
6799
|
}
|
|
6736
6800
|
if (useRolldownBuilder) {
|
|
@@ -6770,8 +6834,8 @@ async function copyPrebuiltSSRBundle(ssrBundle, targetDir, configuredEsbuildOpti
|
|
|
6770
6834
|
await fs.rm(targetDir, { recursive: true, force: true });
|
|
6771
6835
|
await Promise.all(
|
|
6772
6836
|
Object.entries(ssrBundle).map(async ([fileName, output]) => {
|
|
6773
|
-
const targetPath =
|
|
6774
|
-
await fs.mkdir(
|
|
6837
|
+
const targetPath = path4.join(targetDir, fileName);
|
|
6838
|
+
await fs.mkdir(path4.dirname(targetPath), { recursive: true });
|
|
6775
6839
|
if (output.type === "asset") {
|
|
6776
6840
|
await fs.writeFile(targetPath, output.source);
|
|
6777
6841
|
return;
|
|
@@ -6790,7 +6854,7 @@ async function copyPrebuiltSSRBundle(ssrBundle, targetDir, configuredEsbuildOpti
|
|
|
6790
6854
|
}
|
|
6791
6855
|
__name(copyPrebuiltSSRBundle, "copyPrebuiltSSRBundle");
|
|
6792
6856
|
async function registerPrebuiltSSRPackageImport(serverDir, ssrEntryFile, fs) {
|
|
6793
|
-
const packagePath =
|
|
6857
|
+
const packagePath = path4.join(serverDir, "package.json");
|
|
6794
6858
|
const packageJSON = await fs.readFile(packagePath, "utf8").then((contents) => JSON.parse(contents)).catch((error) => {
|
|
6795
6859
|
if (error.code === "ENOENT") return { type: "module" };
|
|
6796
6860
|
throw error;
|
|
@@ -6807,16 +6871,16 @@ async function registerPrebuiltSSRPackageImport(serverDir, ssrEntryFile, fs) {
|
|
|
6807
6871
|
}
|
|
6808
6872
|
__name(registerPrebuiltSSRPackageImport, "registerPrebuiltSSRPackageImport");
|
|
6809
6873
|
async function postProcessVercelOutput(root, outputDir, fs, config, farmWorkflows, routeRuntimeManifest) {
|
|
6810
|
-
const serverDir =
|
|
6811
|
-
const functionsDir =
|
|
6812
|
-
const nitroFuncDir =
|
|
6813
|
-
const staticDir =
|
|
6814
|
-
const publicDir =
|
|
6874
|
+
const serverDir = path4.join(outputDir, "server");
|
|
6875
|
+
const functionsDir = path4.join(outputDir, "functions");
|
|
6876
|
+
const nitroFuncDir = path4.join(functionsDir, "__nitro.func");
|
|
6877
|
+
const staticDir = path4.join(outputDir, "static");
|
|
6878
|
+
const publicDir = path4.join(outputDir, "public");
|
|
6815
6879
|
await fs.mkdir(nitroFuncDir, { recursive: true });
|
|
6816
6880
|
const serverContents = await fs.readdir(serverDir);
|
|
6817
6881
|
for (const file of serverContents) {
|
|
6818
|
-
const src =
|
|
6819
|
-
const dest =
|
|
6882
|
+
const src = path4.join(serverDir, file);
|
|
6883
|
+
const dest = path4.join(nitroFuncDir, file);
|
|
6820
6884
|
await fs.rename(src, dest);
|
|
6821
6885
|
}
|
|
6822
6886
|
await fs.rmdir(serverDir);
|
|
@@ -6826,7 +6890,7 @@ async function postProcessVercelOutput(root, outputDir, fs, config, farmWorkflow
|
|
|
6826
6890
|
}
|
|
6827
6891
|
await copyFarmDocsContentForVercel(config, root, nitroFuncDir, fs);
|
|
6828
6892
|
await copyPrismaClientForVercel(root, nitroFuncDir, fs);
|
|
6829
|
-
const configPath =
|
|
6893
|
+
const configPath = path4.join(outputDir, "config.json");
|
|
6830
6894
|
const configContent = await fs.readFile(configPath, "utf-8");
|
|
6831
6895
|
const vercelConfig = JSON.parse(configContent);
|
|
6832
6896
|
const runtimeRoutes = await createFarmVercelRouteRuntimeFunctions(
|
|
@@ -6874,27 +6938,27 @@ __name(postProcessVercelOutput, "postProcessVercelOutput");
|
|
|
6874
6938
|
async function copyFarmDocsContentForVercel(config, root, nitroFuncDir, fs) {
|
|
6875
6939
|
const docsContentDir = resolveBuildDocsContentDir(config, root);
|
|
6876
6940
|
if (!docsContentDir) return;
|
|
6877
|
-
const bundledContentDir =
|
|
6941
|
+
const bundledContentDir = path4.join(nitroFuncDir, "chunks", "nitro", "farm-docs-content");
|
|
6878
6942
|
const lastModifiedManifest = createFarmDocsLastModifiedManifest(docsContentDir, {
|
|
6879
6943
|
fallback: "now"
|
|
6880
6944
|
});
|
|
6881
6945
|
await fs.rm(bundledContentDir, { recursive: true, force: true });
|
|
6882
|
-
await fs.mkdir(
|
|
6946
|
+
await fs.mkdir(path4.dirname(bundledContentDir), { recursive: true });
|
|
6883
6947
|
await fs.cp(docsContentDir, bundledContentDir, {
|
|
6884
6948
|
recursive: true,
|
|
6885
6949
|
force: true
|
|
6886
6950
|
});
|
|
6887
6951
|
await fs.writeFile(
|
|
6888
|
-
|
|
6952
|
+
path4.join(bundledContentDir, FARM_DOCS_LAST_MODIFIED_MANIFEST),
|
|
6889
6953
|
`${JSON.stringify(lastModifiedManifest, null, 2)}
|
|
6890
6954
|
`
|
|
6891
6955
|
);
|
|
6892
|
-
logger.info(`\u{1F4DA} Bundled docs content for Vercel: ${
|
|
6956
|
+
logger.info(`\u{1F4DA} Bundled docs content for Vercel: ${path4.relative(root, docsContentDir)}`);
|
|
6893
6957
|
}
|
|
6894
6958
|
__name(copyFarmDocsContentForVercel, "copyFarmDocsContentForVercel");
|
|
6895
6959
|
async function copySharpRuntime(config, root, nitroFuncDir, fs) {
|
|
6896
6960
|
if (config.images.provider === "none") return;
|
|
6897
|
-
const projectRequire = createRequire(
|
|
6961
|
+
const projectRequire = createRequire(path4.join(root, "package.json"));
|
|
6898
6962
|
let sharpRequire = projectRequire;
|
|
6899
6963
|
if (!resolvePackageJson(projectRequire, "sharp")) {
|
|
6900
6964
|
try {
|
|
@@ -6904,7 +6968,7 @@ async function copySharpRuntime(config, root, nitroFuncDir, fs) {
|
|
|
6904
6968
|
}
|
|
6905
6969
|
const copiedPackages = /* @__PURE__ */ new Map();
|
|
6906
6970
|
const packageCopies = /* @__PURE__ */ new Map();
|
|
6907
|
-
const targetNodeModules =
|
|
6971
|
+
const targetNodeModules = path4.join(nitroFuncDir, "node_modules");
|
|
6908
6972
|
function copyPackage(packageName, parentRequire) {
|
|
6909
6973
|
const activeCopy = packageCopies.get(packageName);
|
|
6910
6974
|
if (activeCopy) return activeCopy;
|
|
@@ -6917,10 +6981,10 @@ async function copySharpRuntime(config, root, nitroFuncDir, fs) {
|
|
|
6917
6981
|
const packageJsonPath = resolvePackageJson(parentRequire, packageName);
|
|
6918
6982
|
if (!packageJsonPath) return;
|
|
6919
6983
|
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, "utf8"));
|
|
6920
|
-
const packageDir =
|
|
6921
|
-
const targetDir =
|
|
6984
|
+
const packageDir = path4.dirname(packageJsonPath);
|
|
6985
|
+
const targetDir = path4.join(targetNodeModules, ...packageName.split("/"));
|
|
6922
6986
|
copiedPackages.set(packageName, String(packageJson.version || "*"));
|
|
6923
|
-
await fs.mkdir(
|
|
6987
|
+
await fs.mkdir(path4.dirname(targetDir), { recursive: true });
|
|
6924
6988
|
const packageRequire = createRequire(packageJsonPath);
|
|
6925
6989
|
const dependencies = {
|
|
6926
6990
|
...packageJson.dependencies,
|
|
@@ -6945,7 +7009,7 @@ async function copySharpRuntime(config, root, nitroFuncDir, fs) {
|
|
|
6945
7009
|
"Farm image optimization requires sharp. Reinstall dependencies without omitting optional packages."
|
|
6946
7010
|
);
|
|
6947
7011
|
}
|
|
6948
|
-
const functionPackagePath =
|
|
7012
|
+
const functionPackagePath = path4.join(nitroFuncDir, "package.json");
|
|
6949
7013
|
const functionPackage = JSON.parse(await fs.readFile(functionPackagePath, "utf8"));
|
|
6950
7014
|
functionPackage.dependencies = {
|
|
6951
7015
|
...functionPackage.dependencies,
|
|
@@ -6956,7 +7020,7 @@ async function copySharpRuntime(config, root, nitroFuncDir, fs) {
|
|
|
6956
7020
|
}
|
|
6957
7021
|
__name(copySharpRuntime, "copySharpRuntime");
|
|
6958
7022
|
async function copyMetadataImageRuntime(root, nitroFuncDir, fs) {
|
|
6959
|
-
const projectRequire = createRequire(
|
|
7023
|
+
const projectRequire = createRequire(path4.join(root, "package.json"));
|
|
6960
7024
|
let runtimeRequire = projectRequire;
|
|
6961
7025
|
let packageJsonPath = resolvePackageJson(runtimeRequire, "@vercel/og");
|
|
6962
7026
|
if (!packageJsonPath) {
|
|
@@ -6972,16 +7036,16 @@ async function copyMetadataImageRuntime(root, nitroFuncDir, fs) {
|
|
|
6972
7036
|
);
|
|
6973
7037
|
}
|
|
6974
7038
|
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, "utf8"));
|
|
6975
|
-
const packageDir =
|
|
6976
|
-
const targetDir =
|
|
6977
|
-
await fs.mkdir(
|
|
7039
|
+
const packageDir = path4.dirname(packageJsonPath);
|
|
7040
|
+
const targetDir = path4.join(nitroFuncDir, "node_modules", "@vercel", "og");
|
|
7041
|
+
await fs.mkdir(path4.dirname(targetDir), { recursive: true });
|
|
6978
7042
|
await fs.cp(packageDir, targetDir, {
|
|
6979
7043
|
recursive: true,
|
|
6980
7044
|
force: true,
|
|
6981
7045
|
dereference: true,
|
|
6982
7046
|
mode: fsConstants.COPYFILE_FICLONE
|
|
6983
7047
|
});
|
|
6984
|
-
const functionPackagePath =
|
|
7048
|
+
const functionPackagePath = path4.join(nitroFuncDir, "package.json");
|
|
6985
7049
|
const functionPackage = JSON.parse(await fs.readFile(functionPackagePath, "utf8"));
|
|
6986
7050
|
functionPackage.dependencies = {
|
|
6987
7051
|
...functionPackage.dependencies,
|
|
@@ -7002,23 +7066,23 @@ function resolvePackageJson(parentRequire, packageName) {
|
|
|
7002
7066
|
}
|
|
7003
7067
|
__name(resolvePackageJson, "resolvePackageJson");
|
|
7004
7068
|
async function copyPrismaClientForVercel(root, nitroFuncDir, fs) {
|
|
7005
|
-
const projectRequire = createRequire(
|
|
7069
|
+
const projectRequire = createRequire(path4.join(root, "package.json"));
|
|
7006
7070
|
let prismaClientDir;
|
|
7007
7071
|
try {
|
|
7008
|
-
prismaClientDir =
|
|
7072
|
+
prismaClientDir = path4.dirname(projectRequire.resolve("@prisma/client/default.js"));
|
|
7009
7073
|
} catch {
|
|
7010
7074
|
return;
|
|
7011
7075
|
}
|
|
7012
|
-
const generatedClientDir =
|
|
7076
|
+
const generatedClientDir = path4.join(prismaClientDir, "..", "..", ".prisma", "client");
|
|
7013
7077
|
try {
|
|
7014
7078
|
await fs.access(generatedClientDir);
|
|
7015
7079
|
} catch {
|
|
7016
7080
|
return;
|
|
7017
7081
|
}
|
|
7018
|
-
const targetNodeModules =
|
|
7019
|
-
const targetPrismaScopeDir =
|
|
7020
|
-
const targetGeneratedDir =
|
|
7021
|
-
const targetClientDir =
|
|
7082
|
+
const targetNodeModules = path4.join(nitroFuncDir, "node_modules");
|
|
7083
|
+
const targetPrismaScopeDir = path4.join(targetNodeModules, "@prisma");
|
|
7084
|
+
const targetGeneratedDir = path4.join(targetNodeModules, ".prisma", "client");
|
|
7085
|
+
const targetClientDir = path4.join(targetPrismaScopeDir, "client");
|
|
7022
7086
|
await fs.mkdir(targetPrismaScopeDir, { recursive: true });
|
|
7023
7087
|
await fs.cp(prismaClientDir, targetClientDir, {
|
|
7024
7088
|
recursive: true,
|
|
@@ -7028,8 +7092,8 @@ async function copyPrismaClientForVercel(root, nitroFuncDir, fs) {
|
|
|
7028
7092
|
recursive: true,
|
|
7029
7093
|
force: true
|
|
7030
7094
|
});
|
|
7031
|
-
const functionPackagePath =
|
|
7032
|
-
const clientPackagePath =
|
|
7095
|
+
const functionPackagePath = path4.join(nitroFuncDir, "package.json");
|
|
7096
|
+
const clientPackagePath = path4.join(prismaClientDir, "package.json");
|
|
7033
7097
|
const [functionPackageContent, clientPackageContent] = await Promise.all([
|
|
7034
7098
|
fs.readFile(functionPackagePath, "utf-8"),
|
|
7035
7099
|
fs.readFile(clientPackagePath, "utf-8")
|
|
@@ -7099,7 +7163,9 @@ async function buildWithProductionNodeEnv(config, options) {
|
|
|
7099
7163
|
suppressLintOnLink: config.suppressLintOnLink,
|
|
7100
7164
|
componentExtensions: config.renderer.componentExtensions,
|
|
7101
7165
|
i18nConfig: config.i18n
|
|
7102
|
-
}).catch(() => {
|
|
7166
|
+
}).catch((error) => {
|
|
7167
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
7168
|
+
logger.warn(`Route type generation failed (farm.d.ts may be stale): ${message}`);
|
|
7103
7169
|
});
|
|
7104
7170
|
const apiRouteManager = new APIRouteManager(
|
|
7105
7171
|
getFarmAppDirectories(config),
|
|
@@ -7125,9 +7191,9 @@ async function buildWithProductionNodeEnv(config, options) {
|
|
|
7125
7191
|
} else {
|
|
7126
7192
|
const { build: legacyViteBuild } = await import("vite");
|
|
7127
7193
|
logger.info("\u{1F4E6} Building client bundle...");
|
|
7128
|
-
await buildClient2(legacyViteBuild, config, root, srcDir,
|
|
7194
|
+
await buildClient2(legacyViteBuild, config, root, srcDir, path5.join(root, distDir, "client"));
|
|
7129
7195
|
logger.info("\u{1F4E6} Building SSR bundle...");
|
|
7130
|
-
await buildSSR(legacyViteBuild, config, root, srcDir,
|
|
7196
|
+
await buildSSR(legacyViteBuild, config, root, srcDir, path5.join(root, distDir, "server"));
|
|
7131
7197
|
logger.info(`\u{1F680} Building server with Nitro (preset: ${preset})...`);
|
|
7132
7198
|
await buildNitro(
|
|
7133
7199
|
config,
|
|
@@ -7149,7 +7215,7 @@ async function buildWithProductionNodeEnv(config, options) {
|
|
|
7149
7215
|
outputDir: deployOutputDir,
|
|
7150
7216
|
success: true
|
|
7151
7217
|
});
|
|
7152
|
-
logger.success(
|
|
7218
|
+
logger.success(`\u2705 Build completed successfully! (preset: ${preset})`);
|
|
7153
7219
|
logger.info(`\u{1F4C1} Output directory: ${deployOutputDir}`);
|
|
7154
7220
|
} catch (error) {
|
|
7155
7221
|
await pluginManager.runHookParallel("onError", {
|
|
@@ -7297,12 +7363,12 @@ async function buildSSR(viteBuild, config, root, srcDir, outputDir) {
|
|
|
7297
7363
|
}
|
|
7298
7364
|
__name(buildSSR, "buildSSR");
|
|
7299
7365
|
function resolveLegacyPageEntry(config, root, srcDir) {
|
|
7300
|
-
const appDir =
|
|
7366
|
+
const appDir = path5.join(root, srcDir, "app");
|
|
7301
7367
|
for (const extension of getFarmRendererComponentExtensions(config.renderer)) {
|
|
7302
|
-
const candidate =
|
|
7368
|
+
const candidate = path5.join(appDir, `page${extension}`);
|
|
7303
7369
|
if (existsSync2(candidate)) return candidate;
|
|
7304
7370
|
}
|
|
7305
|
-
return
|
|
7371
|
+
return path5.join(appDir, "page.tsx");
|
|
7306
7372
|
}
|
|
7307
7373
|
__name(resolveLegacyPageEntry, "resolveLegacyPageEntry");
|
|
7308
7374
|
async function buildNitro(config, routeManager, apiRouteManager, serverRenderer, preset, root, distDir, pluginManager) {
|
|
@@ -7321,18 +7387,18 @@ async function buildNitro(config, routeManager, apiRouteManager, serverRenderer,
|
|
|
7321
7387
|
nitroConfig = await pluginManager.runHookSerial("beforeNitroBuild", nitroConfig);
|
|
7322
7388
|
}
|
|
7323
7389
|
const outputDir = resolveDeployOutputPath(root, config.deploy.outputDir);
|
|
7324
|
-
const serverOutputDir =
|
|
7325
|
-
const publicOutputDir =
|
|
7390
|
+
const serverOutputDir = path5.join(outputDir, "server");
|
|
7391
|
+
const publicOutputDir = path5.join(outputDir, "public");
|
|
7326
7392
|
const { mkdir, cp } = await import("fs/promises");
|
|
7327
7393
|
await mkdir(serverOutputDir, { recursive: true });
|
|
7328
7394
|
await mkdir(publicOutputDir, { recursive: true });
|
|
7329
|
-
const clientDir =
|
|
7395
|
+
const clientDir = path5.join(root, distDir, "client");
|
|
7330
7396
|
try {
|
|
7331
7397
|
await mkdir(publicOutputDir, { recursive: true });
|
|
7332
7398
|
await cp(clientDir, publicOutputDir, { recursive: true });
|
|
7333
7399
|
logger.info("\u{1F4E6} Copied client assets to public directory");
|
|
7334
|
-
const manifestPath =
|
|
7335
|
-
const assetsDir =
|
|
7400
|
+
const manifestPath = path5.join(publicOutputDir, "farm-client-manifest.json");
|
|
7401
|
+
const assetsDir = path5.join(publicOutputDir, "assets");
|
|
7336
7402
|
const manifestExists = await import("fs/promises").then(
|
|
7337
7403
|
(fs) => fs.access(manifestPath).then(() => true).catch(() => false)
|
|
7338
7404
|
);
|
|
@@ -7348,8 +7414,8 @@ async function buildNitro(config, routeManager, apiRouteManager, serverRenderer,
|
|
|
7348
7414
|
logger.error(`\u274C Failed to copy client assets: ${error}`);
|
|
7349
7415
|
throw error;
|
|
7350
7416
|
}
|
|
7351
|
-
const serverDir =
|
|
7352
|
-
const nitroServerDir =
|
|
7417
|
+
const serverDir = path5.join(root, distDir, "server");
|
|
7418
|
+
const nitroServerDir = path5.join(root, distDir, ".nitro", "server", "farm");
|
|
7353
7419
|
try {
|
|
7354
7420
|
await mkdir(nitroServerDir, { recursive: true });
|
|
7355
7421
|
await cp(serverDir, nitroServerDir, { recursive: true });
|
|
@@ -7358,7 +7424,7 @@ async function buildNitro(config, routeManager, apiRouteManager, serverRenderer,
|
|
|
7358
7424
|
logger.warn(`Could not copy SSR bundles: ${error}`);
|
|
7359
7425
|
}
|
|
7360
7426
|
const nitro = await createNitro(nitroConfig);
|
|
7361
|
-
const registryPath =
|
|
7427
|
+
const registryPath = path5.join(root, distDir, ".nitro", "server", "farm-registry.ts");
|
|
7362
7428
|
try {
|
|
7363
7429
|
const { farmRegistry } = await import(
|
|
7364
7430
|
/* @vite-ignore */
|
|
@@ -7375,7 +7441,7 @@ async function buildNitro(config, routeManager, apiRouteManager, serverRenderer,
|
|
|
7375
7441
|
}
|
|
7376
7442
|
farmRegistry.routePaths = routePaths;
|
|
7377
7443
|
try {
|
|
7378
|
-
const clientManifestPath =
|
|
7444
|
+
const clientManifestPath = path5.join(root, distDir, "client", "farm-client-manifest.json");
|
|
7379
7445
|
const { readFile } = await import("fs/promises");
|
|
7380
7446
|
const manifestContent = await readFile(clientManifestPath, "utf-8");
|
|
7381
7447
|
farmRegistry.clientManifest = JSON.parse(manifestContent);
|
|
@@ -7400,4 +7466,4 @@ __name(buildNitro, "buildNitro");
|
|
|
7400
7466
|
export {
|
|
7401
7467
|
build
|
|
7402
7468
|
};
|
|
7403
|
-
//# sourceMappingURL=chunk-
|
|
7469
|
+
//# sourceMappingURL=chunk-HLN7NPNQ.mjs.map
|