@float.js/core 2.1.0 → 2.2.1
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/README.md +38 -0
- package/dist/cli/index.js +361 -120
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +389 -148
- package/dist/index.js.map +1 -1
- package/dist/router/index.d.ts +4 -0
- package/dist/router/index.js +32 -2
- package/dist/router/index.js.map +1 -1
- package/dist/server/index.js +331 -90
- package/dist/server/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
4
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
5
|
+
}) : x)(function(x) {
|
|
6
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
7
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
8
|
+
});
|
|
3
9
|
var __esm = (fn, res) => function __init() {
|
|
4
10
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
5
11
|
};
|
|
@@ -8,11 +14,11 @@ var __export = (target, all) => {
|
|
|
8
14
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
15
|
};
|
|
10
16
|
|
|
11
|
-
// ../../node_modules/.pnpm/tsup@8.5.
|
|
17
|
+
// ../../node_modules/.pnpm/tsup@8.5.1_typescript@5.9.3/node_modules/tsup/assets/esm_shims.js
|
|
12
18
|
import path from "path";
|
|
13
19
|
import { fileURLToPath } from "url";
|
|
14
20
|
var init_esm_shims = __esm({
|
|
15
|
-
"../../node_modules/.pnpm/tsup@8.5.
|
|
21
|
+
"../../node_modules/.pnpm/tsup@8.5.1_typescript@5.9.3/node_modules/tsup/assets/esm_shims.js"() {
|
|
16
22
|
"use strict";
|
|
17
23
|
}
|
|
18
24
|
});
|
|
@@ -729,7 +735,7 @@ function generateAPIResponse(state) {
|
|
|
729
735
|
function createDevDashboard(options = {}) {
|
|
730
736
|
const {
|
|
731
737
|
enabled = process.env.NODE_ENV !== "production",
|
|
732
|
-
path:
|
|
738
|
+
path: path10 = "/__float",
|
|
733
739
|
auth
|
|
734
740
|
} = options;
|
|
735
741
|
if (!enabled) {
|
|
@@ -737,7 +743,7 @@ function createDevDashboard(options = {}) {
|
|
|
737
743
|
}
|
|
738
744
|
return (req, res, next) => {
|
|
739
745
|
const url = req.url || "";
|
|
740
|
-
if (!url.startsWith(
|
|
746
|
+
if (!url.startsWith(path10)) {
|
|
741
747
|
return next();
|
|
742
748
|
}
|
|
743
749
|
if (auth) {
|
|
@@ -756,7 +762,7 @@ function createDevDashboard(options = {}) {
|
|
|
756
762
|
return;
|
|
757
763
|
}
|
|
758
764
|
}
|
|
759
|
-
const subPath = url.slice(
|
|
765
|
+
const subPath = url.slice(path10.length);
|
|
760
766
|
if (subPath === "" || subPath === "/") {
|
|
761
767
|
res.setHeader("Content-Type", "text/html");
|
|
762
768
|
res.end(generateDashboardHTML(dashboardState));
|
|
@@ -928,6 +934,26 @@ function findLayouts(routePath, allLayouts) {
|
|
|
928
934
|
}
|
|
929
935
|
return layouts;
|
|
930
936
|
}
|
|
937
|
+
function findLoading(routePath, allLoading) {
|
|
938
|
+
const segments = routePath.split("/").filter(Boolean);
|
|
939
|
+
for (let i = segments.length; i >= 0; i--) {
|
|
940
|
+
const currentPath = i === 0 ? "/" : "/" + segments.slice(0, i).join("/");
|
|
941
|
+
if (allLoading.has(currentPath)) {
|
|
942
|
+
return allLoading.get(currentPath);
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
return void 0;
|
|
946
|
+
}
|
|
947
|
+
function findError(routePath, allErrors) {
|
|
948
|
+
const segments = routePath.split("/").filter(Boolean);
|
|
949
|
+
for (let i = segments.length; i >= 0; i--) {
|
|
950
|
+
const currentPath = i === 0 ? "/" : "/" + segments.slice(0, i).join("/");
|
|
951
|
+
if (allErrors.has(currentPath)) {
|
|
952
|
+
return allErrors.get(currentPath);
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
return void 0;
|
|
956
|
+
}
|
|
931
957
|
async function scanRoutes(rootDir, options = {}) {
|
|
932
958
|
const opts = { ...DEFAULT_OPTIONS, ...options };
|
|
933
959
|
const appDir = path2.join(rootDir, opts.appDir);
|
|
@@ -939,12 +965,20 @@ async function scanRoutes(rootDir, options = {}) {
|
|
|
939
965
|
ignore: ["**/node_modules/**", "**/_*/**"]
|
|
940
966
|
});
|
|
941
967
|
const layoutMap = /* @__PURE__ */ new Map();
|
|
968
|
+
const loadingMap = /* @__PURE__ */ new Map();
|
|
969
|
+
const errorMap = /* @__PURE__ */ new Map();
|
|
942
970
|
for (const file of files) {
|
|
943
971
|
const type = getRouteType(file);
|
|
972
|
+
const { urlPath } = filePathToUrlPath(file, "");
|
|
944
973
|
if (type === "layout") {
|
|
945
|
-
const { urlPath } = filePathToUrlPath(file, "");
|
|
946
974
|
const layoutPath = urlPath === "/" ? "/" : urlPath.replace(/\/layout$/, "") || "/";
|
|
947
975
|
layoutMap.set(layoutPath, path2.join(appDir, file));
|
|
976
|
+
} else if (type === "loading") {
|
|
977
|
+
const loadingPath = urlPath === "/" ? "/" : urlPath.replace(/\/loading$/, "") || "/";
|
|
978
|
+
loadingMap.set(loadingPath, path2.join(appDir, file));
|
|
979
|
+
} else if (type === "error") {
|
|
980
|
+
const errorPath = urlPath === "/" ? "/" : urlPath.replace(/\/error$/, "") || "/";
|
|
981
|
+
errorMap.set(errorPath, path2.join(appDir, file));
|
|
948
982
|
}
|
|
949
983
|
}
|
|
950
984
|
const routes = [];
|
|
@@ -962,7 +996,9 @@ async function scanRoutes(rootDir, options = {}) {
|
|
|
962
996
|
params,
|
|
963
997
|
isCatchAll,
|
|
964
998
|
isOptionalCatchAll,
|
|
965
|
-
layouts: type === "page" ? findLayouts(urlPath, layoutMap) : []
|
|
999
|
+
layouts: type === "page" ? findLayouts(urlPath, layoutMap) : [],
|
|
1000
|
+
loading: type === "page" ? findLoading(urlPath, loadingMap) : void 0,
|
|
1001
|
+
error: type === "page" ? findError(urlPath, errorMap) : void 0
|
|
966
1002
|
};
|
|
967
1003
|
routes.push(route);
|
|
968
1004
|
}
|
|
@@ -1017,8 +1053,8 @@ init_esm_shims();
|
|
|
1017
1053
|
// src/server/dev-server.ts
|
|
1018
1054
|
init_esm_shims();
|
|
1019
1055
|
import http from "http";
|
|
1020
|
-
import
|
|
1021
|
-
import
|
|
1056
|
+
import fs5 from "fs";
|
|
1057
|
+
import path7 from "path";
|
|
1022
1058
|
import pc2 from "picocolors";
|
|
1023
1059
|
import chokidar from "chokidar";
|
|
1024
1060
|
import { WebSocketServer, WebSocket } from "ws";
|
|
@@ -1033,23 +1069,222 @@ import { Writable } from "stream";
|
|
|
1033
1069
|
// src/build/transform.ts
|
|
1034
1070
|
init_esm_shims();
|
|
1035
1071
|
import * as esbuild from "esbuild";
|
|
1072
|
+
import fs2 from "fs";
|
|
1073
|
+
import path4 from "path";
|
|
1074
|
+
import { pathToFileURL } from "url";
|
|
1075
|
+
|
|
1076
|
+
// src/build/persistent-cache.ts
|
|
1077
|
+
init_esm_shims();
|
|
1036
1078
|
import fs from "fs";
|
|
1037
1079
|
import path3 from "path";
|
|
1038
|
-
import
|
|
1080
|
+
import crypto from "crypto";
|
|
1081
|
+
var PersistentCache = class {
|
|
1082
|
+
cacheDir;
|
|
1083
|
+
manifestPath;
|
|
1084
|
+
manifest;
|
|
1085
|
+
constructor(rootDir = process.cwd()) {
|
|
1086
|
+
this.cacheDir = path3.join(rootDir, ".float", "cache");
|
|
1087
|
+
this.manifestPath = path3.join(this.cacheDir, "manifest.json");
|
|
1088
|
+
fs.mkdirSync(this.cacheDir, { recursive: true });
|
|
1089
|
+
this.manifest = this.loadManifest();
|
|
1090
|
+
}
|
|
1091
|
+
loadManifest() {
|
|
1092
|
+
if (fs.existsSync(this.manifestPath)) {
|
|
1093
|
+
try {
|
|
1094
|
+
const data = fs.readFileSync(this.manifestPath, "utf-8");
|
|
1095
|
+
return JSON.parse(data);
|
|
1096
|
+
} catch {
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
return {
|
|
1100
|
+
version: "1.0",
|
|
1101
|
+
entries: {}
|
|
1102
|
+
};
|
|
1103
|
+
}
|
|
1104
|
+
saveManifest() {
|
|
1105
|
+
fs.writeFileSync(
|
|
1106
|
+
this.manifestPath,
|
|
1107
|
+
JSON.stringify(this.manifest, null, 2)
|
|
1108
|
+
);
|
|
1109
|
+
}
|
|
1110
|
+
/**
|
|
1111
|
+
* Generate hash for content
|
|
1112
|
+
*/
|
|
1113
|
+
hash(content) {
|
|
1114
|
+
return crypto.createHash("sha256").update(content).digest("hex").slice(0, 16);
|
|
1115
|
+
}
|
|
1116
|
+
/**
|
|
1117
|
+
* Get cache key path
|
|
1118
|
+
*/
|
|
1119
|
+
getKeyPath(key) {
|
|
1120
|
+
const safeKey = key.replace(/[^a-z0-9_-]/gi, "_");
|
|
1121
|
+
return path3.join(this.cacheDir, `${safeKey}.cache`);
|
|
1122
|
+
}
|
|
1123
|
+
/**
|
|
1124
|
+
* Check if cache entry is valid
|
|
1125
|
+
*/
|
|
1126
|
+
has(key, contentHash) {
|
|
1127
|
+
const entry = this.manifest.entries[key];
|
|
1128
|
+
if (!entry) return false;
|
|
1129
|
+
const cachePath = this.getKeyPath(key);
|
|
1130
|
+
if (!fs.existsSync(cachePath)) {
|
|
1131
|
+
delete this.manifest.entries[key];
|
|
1132
|
+
this.saveManifest();
|
|
1133
|
+
return false;
|
|
1134
|
+
}
|
|
1135
|
+
if (contentHash && entry.hash !== contentHash) {
|
|
1136
|
+
return false;
|
|
1137
|
+
}
|
|
1138
|
+
return true;
|
|
1139
|
+
}
|
|
1140
|
+
/**
|
|
1141
|
+
* Get cached value
|
|
1142
|
+
*/
|
|
1143
|
+
get(key) {
|
|
1144
|
+
if (!this.has(key)) return null;
|
|
1145
|
+
try {
|
|
1146
|
+
const cachePath = this.getKeyPath(key);
|
|
1147
|
+
const data = fs.readFileSync(cachePath, "utf-8");
|
|
1148
|
+
const entry = JSON.parse(data);
|
|
1149
|
+
return entry.value;
|
|
1150
|
+
} catch {
|
|
1151
|
+
return null;
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
/**
|
|
1155
|
+
* Set cache value
|
|
1156
|
+
*/
|
|
1157
|
+
set(key, value, content) {
|
|
1158
|
+
const entry = {
|
|
1159
|
+
key,
|
|
1160
|
+
value,
|
|
1161
|
+
timestamp: Date.now(),
|
|
1162
|
+
hash: content ? this.hash(content) : this.hash(JSON.stringify(value))
|
|
1163
|
+
};
|
|
1164
|
+
const cachePath = this.getKeyPath(key);
|
|
1165
|
+
const data = JSON.stringify(entry);
|
|
1166
|
+
fs.writeFileSync(cachePath, data);
|
|
1167
|
+
this.manifest.entries[key] = {
|
|
1168
|
+
hash: entry.hash,
|
|
1169
|
+
timestamp: entry.timestamp,
|
|
1170
|
+
size: Buffer.byteLength(data)
|
|
1171
|
+
};
|
|
1172
|
+
this.saveManifest();
|
|
1173
|
+
}
|
|
1174
|
+
/**
|
|
1175
|
+
* Delete cache entry
|
|
1176
|
+
*/
|
|
1177
|
+
delete(key) {
|
|
1178
|
+
const cachePath = this.getKeyPath(key);
|
|
1179
|
+
if (fs.existsSync(cachePath)) {
|
|
1180
|
+
fs.unlinkSync(cachePath);
|
|
1181
|
+
}
|
|
1182
|
+
if (this.manifest.entries[key]) {
|
|
1183
|
+
delete this.manifest.entries[key];
|
|
1184
|
+
this.saveManifest();
|
|
1185
|
+
return true;
|
|
1186
|
+
}
|
|
1187
|
+
return false;
|
|
1188
|
+
}
|
|
1189
|
+
/**
|
|
1190
|
+
* Clear all cache
|
|
1191
|
+
*/
|
|
1192
|
+
clear() {
|
|
1193
|
+
if (fs.existsSync(this.cacheDir)) {
|
|
1194
|
+
fs.rmSync(this.cacheDir, { recursive: true });
|
|
1195
|
+
fs.mkdirSync(this.cacheDir, { recursive: true });
|
|
1196
|
+
}
|
|
1197
|
+
this.manifest = {
|
|
1198
|
+
version: "1.0",
|
|
1199
|
+
entries: {}
|
|
1200
|
+
};
|
|
1201
|
+
this.saveManifest();
|
|
1202
|
+
}
|
|
1203
|
+
/**
|
|
1204
|
+
* Get cache statistics
|
|
1205
|
+
*/
|
|
1206
|
+
stats() {
|
|
1207
|
+
const entries = Object.values(this.manifest.entries);
|
|
1208
|
+
const size = entries.reduce((acc, e) => acc + e.size, 0);
|
|
1209
|
+
const timestamps = entries.map((e) => e.timestamp);
|
|
1210
|
+
return {
|
|
1211
|
+
entries: entries.length,
|
|
1212
|
+
size,
|
|
1213
|
+
oldestEntry: timestamps.length > 0 ? Math.min(...timestamps) : null,
|
|
1214
|
+
newestEntry: timestamps.length > 0 ? Math.max(...timestamps) : null
|
|
1215
|
+
};
|
|
1216
|
+
}
|
|
1217
|
+
/**
|
|
1218
|
+
* Clean old entries (older than maxAge milliseconds)
|
|
1219
|
+
*/
|
|
1220
|
+
prune(maxAge = 7 * 24 * 60 * 60 * 1e3) {
|
|
1221
|
+
const now = Date.now();
|
|
1222
|
+
let cleaned = 0;
|
|
1223
|
+
for (const [key, entry] of Object.entries(this.manifest.entries)) {
|
|
1224
|
+
if (now - entry.timestamp > maxAge) {
|
|
1225
|
+
this.delete(key);
|
|
1226
|
+
cleaned++;
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
return cleaned;
|
|
1230
|
+
}
|
|
1231
|
+
};
|
|
1232
|
+
var globalCache = null;
|
|
1233
|
+
function getCache(rootDir) {
|
|
1234
|
+
if (!globalCache) {
|
|
1235
|
+
globalCache = new PersistentCache(rootDir);
|
|
1236
|
+
}
|
|
1237
|
+
return globalCache;
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
// src/build/transform.ts
|
|
1039
1241
|
var moduleCache = /* @__PURE__ */ new Map();
|
|
1040
|
-
async function transformFile(filePath) {
|
|
1041
|
-
const absolutePath =
|
|
1042
|
-
if (!
|
|
1242
|
+
async function transformFile(filePath, useCache = true) {
|
|
1243
|
+
const absolutePath = path4.isAbsolute(filePath) ? filePath : path4.resolve(filePath);
|
|
1244
|
+
if (!fs2.existsSync(absolutePath)) {
|
|
1043
1245
|
throw new Error(`File not found: ${absolutePath}`);
|
|
1044
1246
|
}
|
|
1045
|
-
const stats =
|
|
1247
|
+
const stats = fs2.statSync(absolutePath);
|
|
1046
1248
|
const mtime = stats.mtimeMs;
|
|
1047
1249
|
const cached = moduleCache.get(absolutePath);
|
|
1048
1250
|
if (cached && cached.mtime === mtime) {
|
|
1049
1251
|
return cached.module;
|
|
1050
1252
|
}
|
|
1051
|
-
|
|
1052
|
-
|
|
1253
|
+
if (useCache) {
|
|
1254
|
+
const cache2 = getCache();
|
|
1255
|
+
const source2 = fs2.readFileSync(absolutePath, "utf-8");
|
|
1256
|
+
const sourceHash = __require("crypto").createHash("sha256").update(source2).digest("hex").slice(0, 16);
|
|
1257
|
+
const cacheKey = `transform_${absolutePath}_${sourceHash}`;
|
|
1258
|
+
if (cache2.has(cacheKey)) {
|
|
1259
|
+
const cachedCode = cache2.get(cacheKey);
|
|
1260
|
+
if (cachedCode) {
|
|
1261
|
+
const tempDir2 = path4.join(process.cwd(), ".float", ".cache");
|
|
1262
|
+
fs2.mkdirSync(tempDir2, { recursive: true });
|
|
1263
|
+
const tempFile2 = path4.join(tempDir2, `${path4.basename(absolutePath, path4.extname(absolutePath))}_${Date.now()}.mjs`);
|
|
1264
|
+
fs2.writeFileSync(tempFile2, cachedCode);
|
|
1265
|
+
try {
|
|
1266
|
+
const module = await import(pathToFileURL(tempFile2).href);
|
|
1267
|
+
moduleCache.set(absolutePath, { module, mtime });
|
|
1268
|
+
setImmediate(() => {
|
|
1269
|
+
try {
|
|
1270
|
+
fs2.unlinkSync(tempFile2);
|
|
1271
|
+
} catch {
|
|
1272
|
+
}
|
|
1273
|
+
});
|
|
1274
|
+
return module;
|
|
1275
|
+
} catch (error2) {
|
|
1276
|
+
setImmediate(() => {
|
|
1277
|
+
try {
|
|
1278
|
+
fs2.unlinkSync(tempFile2);
|
|
1279
|
+
} catch {
|
|
1280
|
+
}
|
|
1281
|
+
});
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
const source = fs2.readFileSync(absolutePath, "utf-8");
|
|
1287
|
+
const ext = path4.extname(absolutePath);
|
|
1053
1288
|
const loader = getLoader(ext);
|
|
1054
1289
|
const result = await esbuild.transform(source, {
|
|
1055
1290
|
loader,
|
|
@@ -1059,25 +1294,31 @@ async function transformFile(filePath) {
|
|
|
1059
1294
|
sourcemap: "inline",
|
|
1060
1295
|
sourcefile: absolutePath
|
|
1061
1296
|
});
|
|
1062
|
-
const tempDir =
|
|
1063
|
-
|
|
1064
|
-
const tempFile =
|
|
1297
|
+
const tempDir = path4.join(process.cwd(), ".float", ".cache");
|
|
1298
|
+
fs2.mkdirSync(tempDir, { recursive: true });
|
|
1299
|
+
const tempFile = path4.join(tempDir, `${path4.basename(absolutePath, ext)}_${Date.now()}.mjs`);
|
|
1065
1300
|
let code = result.code;
|
|
1066
|
-
code = rewriteImports(code,
|
|
1067
|
-
|
|
1301
|
+
code = rewriteImports(code, path4.dirname(absolutePath));
|
|
1302
|
+
fs2.writeFileSync(tempFile, code);
|
|
1068
1303
|
try {
|
|
1069
1304
|
const module = await import(pathToFileURL(tempFile).href);
|
|
1070
1305
|
moduleCache.set(absolutePath, { module, mtime });
|
|
1306
|
+
if (useCache) {
|
|
1307
|
+
const cache2 = getCache();
|
|
1308
|
+
const sourceHash = __require("crypto").createHash("sha256").update(source).digest("hex").slice(0, 16);
|
|
1309
|
+
const cacheKey = `transform_${absolutePath}_${sourceHash}`;
|
|
1310
|
+
cache2.set(cacheKey, code, source);
|
|
1311
|
+
}
|
|
1071
1312
|
setImmediate(() => {
|
|
1072
1313
|
try {
|
|
1073
|
-
|
|
1314
|
+
fs2.unlinkSync(tempFile);
|
|
1074
1315
|
} catch {
|
|
1075
1316
|
}
|
|
1076
1317
|
});
|
|
1077
1318
|
return module;
|
|
1078
1319
|
} catch (error2) {
|
|
1079
1320
|
try {
|
|
1080
|
-
|
|
1321
|
+
fs2.unlinkSync(tempFile);
|
|
1081
1322
|
} catch {
|
|
1082
1323
|
}
|
|
1083
1324
|
throw error2;
|
|
@@ -1106,18 +1347,18 @@ function getLoader(ext) {
|
|
|
1106
1347
|
function rewriteImports(code, baseDir) {
|
|
1107
1348
|
const importRegex = /from\s+['"](\.[^'"]+)['"]/g;
|
|
1108
1349
|
return code.replace(importRegex, (match, importPath) => {
|
|
1109
|
-
let resolvedPath =
|
|
1350
|
+
let resolvedPath = path4.resolve(baseDir, importPath);
|
|
1110
1351
|
const extensions = [".tsx", ".ts", ".jsx", ".js", ".mjs", ""];
|
|
1111
1352
|
let found = false;
|
|
1112
1353
|
for (const ext of extensions) {
|
|
1113
1354
|
const tryPath = resolvedPath + ext;
|
|
1114
|
-
if (
|
|
1355
|
+
if (fs2.existsSync(tryPath)) {
|
|
1115
1356
|
resolvedPath = tryPath;
|
|
1116
1357
|
found = true;
|
|
1117
1358
|
break;
|
|
1118
1359
|
}
|
|
1119
|
-
const indexPath =
|
|
1120
|
-
if (
|
|
1360
|
+
const indexPath = path4.join(resolvedPath, `index${ext}`);
|
|
1361
|
+
if (fs2.existsSync(indexPath)) {
|
|
1121
1362
|
resolvedPath = indexPath;
|
|
1122
1363
|
found = true;
|
|
1123
1364
|
break;
|
|
@@ -1131,7 +1372,7 @@ function rewriteImports(code, baseDir) {
|
|
|
1131
1372
|
}
|
|
1132
1373
|
function clearModuleCache(filePath) {
|
|
1133
1374
|
if (filePath) {
|
|
1134
|
-
moduleCache.delete(
|
|
1375
|
+
moduleCache.delete(path4.resolve(filePath));
|
|
1135
1376
|
} else {
|
|
1136
1377
|
moduleCache.clear();
|
|
1137
1378
|
}
|
|
@@ -2522,13 +2763,13 @@ function generateExamplesPage() {
|
|
|
2522
2763
|
|
|
2523
2764
|
// src/build/css-processor.ts
|
|
2524
2765
|
init_esm_shims();
|
|
2525
|
-
import
|
|
2526
|
-
import
|
|
2766
|
+
import fs4 from "fs";
|
|
2767
|
+
import path6 from "path";
|
|
2527
2768
|
|
|
2528
2769
|
// src/build/tailwind-setup.ts
|
|
2529
2770
|
init_esm_shims();
|
|
2530
|
-
import
|
|
2531
|
-
import
|
|
2771
|
+
import fs3 from "fs";
|
|
2772
|
+
import path5 from "path";
|
|
2532
2773
|
import pc from "picocolors";
|
|
2533
2774
|
function checkTailwindSetup(rootDir) {
|
|
2534
2775
|
const possibleConfigs = [
|
|
@@ -2539,14 +2780,14 @@ function checkTailwindSetup(rootDir) {
|
|
|
2539
2780
|
];
|
|
2540
2781
|
let configPath = null;
|
|
2541
2782
|
for (const config of possibleConfigs) {
|
|
2542
|
-
const fullPath =
|
|
2543
|
-
if (
|
|
2783
|
+
const fullPath = path5.join(rootDir, config);
|
|
2784
|
+
if (fs3.existsSync(fullPath)) {
|
|
2544
2785
|
configPath = fullPath;
|
|
2545
2786
|
break;
|
|
2546
2787
|
}
|
|
2547
2788
|
}
|
|
2548
|
-
const globalsPath =
|
|
2549
|
-
const hasGlobals =
|
|
2789
|
+
const globalsPath = path5.join(rootDir, "app", "globals.css");
|
|
2790
|
+
const hasGlobals = fs3.existsSync(globalsPath);
|
|
2550
2791
|
return {
|
|
2551
2792
|
hasTailwind: !!configPath,
|
|
2552
2793
|
configPath,
|
|
@@ -2576,14 +2817,14 @@ export default {
|
|
|
2576
2817
|
plugins: [],
|
|
2577
2818
|
}
|
|
2578
2819
|
`;
|
|
2579
|
-
const configPath =
|
|
2580
|
-
|
|
2820
|
+
const configPath = path5.join(rootDir, "tailwind.config.js");
|
|
2821
|
+
fs3.writeFileSync(configPath, tailwindConfig);
|
|
2581
2822
|
if (!silent) {
|
|
2582
2823
|
console.log(pc.green(" \u2713 Created tailwind.config.js"));
|
|
2583
2824
|
}
|
|
2584
2825
|
}
|
|
2585
|
-
const postcssPath =
|
|
2586
|
-
if (!
|
|
2826
|
+
const postcssPath = path5.join(rootDir, "postcss.config.js");
|
|
2827
|
+
if (!fs3.existsSync(postcssPath) || force) {
|
|
2587
2828
|
const postcssConfig = `export default {
|
|
2588
2829
|
plugins: {
|
|
2589
2830
|
tailwindcss: {},
|
|
@@ -2591,28 +2832,28 @@ export default {
|
|
|
2591
2832
|
},
|
|
2592
2833
|
}
|
|
2593
2834
|
`;
|
|
2594
|
-
|
|
2835
|
+
fs3.writeFileSync(postcssPath, postcssConfig);
|
|
2595
2836
|
if (!silent) {
|
|
2596
2837
|
console.log(pc.green(" \u2713 Created postcss.config.js"));
|
|
2597
2838
|
}
|
|
2598
2839
|
}
|
|
2599
|
-
const appDir =
|
|
2600
|
-
if (!
|
|
2601
|
-
|
|
2840
|
+
const appDir = path5.join(rootDir, "app");
|
|
2841
|
+
if (!fs3.existsSync(appDir)) {
|
|
2842
|
+
fs3.mkdirSync(appDir, { recursive: true });
|
|
2602
2843
|
}
|
|
2603
|
-
const globalsPath =
|
|
2604
|
-
if (!
|
|
2844
|
+
const globalsPath = path5.join(appDir, "globals.css");
|
|
2845
|
+
if (!fs3.existsSync(globalsPath) || force) {
|
|
2605
2846
|
const globalsCss = `@tailwind base;
|
|
2606
2847
|
@tailwind components;
|
|
2607
2848
|
@tailwind utilities;
|
|
2608
2849
|
`;
|
|
2609
|
-
|
|
2850
|
+
fs3.writeFileSync(globalsPath, globalsCss);
|
|
2610
2851
|
if (!silent) {
|
|
2611
2852
|
console.log(pc.green(" \u2713 Created app/globals.css"));
|
|
2612
2853
|
}
|
|
2613
2854
|
}
|
|
2614
|
-
const layoutPath =
|
|
2615
|
-
if (!
|
|
2855
|
+
const layoutPath = path5.join(appDir, "layout.tsx");
|
|
2856
|
+
if (!fs3.existsSync(layoutPath)) {
|
|
2616
2857
|
const layoutContent = `import './globals.css'
|
|
2617
2858
|
|
|
2618
2859
|
export default function RootLayout({
|
|
@@ -2627,7 +2868,7 @@ export default function RootLayout({
|
|
|
2627
2868
|
)
|
|
2628
2869
|
}
|
|
2629
2870
|
`;
|
|
2630
|
-
|
|
2871
|
+
fs3.writeFileSync(layoutPath, layoutContent);
|
|
2631
2872
|
if (!silent) {
|
|
2632
2873
|
console.log(pc.green(" \u2713 Created app/layout.tsx"));
|
|
2633
2874
|
}
|
|
@@ -2637,8 +2878,8 @@ export default function RootLayout({
|
|
|
2637
2878
|
}
|
|
2638
2879
|
}
|
|
2639
2880
|
function checkTailwindDeps(rootDir) {
|
|
2640
|
-
const packageJsonPath =
|
|
2641
|
-
if (!
|
|
2881
|
+
const packageJsonPath = path5.join(rootDir, "package.json");
|
|
2882
|
+
if (!fs3.existsSync(packageJsonPath)) {
|
|
2642
2883
|
return {
|
|
2643
2884
|
hasPackageJson: false,
|
|
2644
2885
|
hasTailwind: false,
|
|
@@ -2646,7 +2887,7 @@ function checkTailwindDeps(rootDir) {
|
|
|
2646
2887
|
hasAutoprefixer: false
|
|
2647
2888
|
};
|
|
2648
2889
|
}
|
|
2649
|
-
const packageJson = JSON.parse(
|
|
2890
|
+
const packageJson = JSON.parse(fs3.readFileSync(packageJsonPath, "utf-8"));
|
|
2650
2891
|
const allDeps = {
|
|
2651
2892
|
...packageJson.dependencies,
|
|
2652
2893
|
...packageJson.devDependencies
|
|
@@ -2670,9 +2911,9 @@ function getTailwindInstallCommand(rootDir) {
|
|
|
2670
2911
|
if (missing.length === 0) {
|
|
2671
2912
|
return null;
|
|
2672
2913
|
}
|
|
2673
|
-
const hasYarnLock =
|
|
2674
|
-
const hasPnpmLock =
|
|
2675
|
-
const hasBunLock =
|
|
2914
|
+
const hasYarnLock = fs3.existsSync(path5.join(rootDir, "yarn.lock"));
|
|
2915
|
+
const hasPnpmLock = fs3.existsSync(path5.join(rootDir, "pnpm-lock.yaml"));
|
|
2916
|
+
const hasBunLock = fs3.existsSync(path5.join(rootDir, "bun.lockb"));
|
|
2676
2917
|
let pm = "npm install -D";
|
|
2677
2918
|
if (hasBunLock) pm = "bun add -d";
|
|
2678
2919
|
else if (hasPnpmLock) pm = "pnpm add -D";
|
|
@@ -2682,7 +2923,7 @@ function getTailwindInstallCommand(rootDir) {
|
|
|
2682
2923
|
|
|
2683
2924
|
// src/build/css-processor.ts
|
|
2684
2925
|
async function processCSS(filePath, rootDir = process.cwd()) {
|
|
2685
|
-
const content =
|
|
2926
|
+
const content = fs4.readFileSync(filePath, "utf-8");
|
|
2686
2927
|
const tailwindConfig = checkTailwindSetup(rootDir);
|
|
2687
2928
|
if (!tailwindConfig.hasTailwind) {
|
|
2688
2929
|
return { code: content };
|
|
@@ -2691,9 +2932,9 @@ async function processCSS(filePath, rootDir = process.cwd()) {
|
|
|
2691
2932
|
const postcss = await import("postcss").then((m) => m.default);
|
|
2692
2933
|
const tailwindcss = await import("tailwindcss").then((m) => m.default);
|
|
2693
2934
|
const autoprefixer = await import("autoprefixer").then((m) => m.default);
|
|
2694
|
-
const configPath = tailwindConfig.configPath ||
|
|
2935
|
+
const configPath = tailwindConfig.configPath || path6.join(rootDir, "tailwind.config.js");
|
|
2695
2936
|
let tailwindConfigModule = {};
|
|
2696
|
-
if (
|
|
2937
|
+
if (fs4.existsSync(configPath)) {
|
|
2697
2938
|
const configUrl = new URL(`file://${configPath}`);
|
|
2698
2939
|
tailwindConfigModule = await import(configUrl.href).then((m) => m.default || m);
|
|
2699
2940
|
}
|
|
@@ -2719,7 +2960,7 @@ function needsCSSProcessing(filePath, rootDir) {
|
|
|
2719
2960
|
if (!config.hasTailwind) {
|
|
2720
2961
|
return false;
|
|
2721
2962
|
}
|
|
2722
|
-
const content =
|
|
2963
|
+
const content = fs4.readFileSync(filePath, "utf-8");
|
|
2723
2964
|
return content.includes("@tailwind") || content.includes("@apply");
|
|
2724
2965
|
}
|
|
2725
2966
|
|
|
@@ -2727,7 +2968,7 @@ function needsCSSProcessing(filePath, rootDir) {
|
|
|
2727
2968
|
async function createDevServer(options) {
|
|
2728
2969
|
const { port, host, open } = options;
|
|
2729
2970
|
const rootDir = process.cwd();
|
|
2730
|
-
const publicDir =
|
|
2971
|
+
const publicDir = path7.join(rootDir, "public");
|
|
2731
2972
|
let routes = [];
|
|
2732
2973
|
let server = null;
|
|
2733
2974
|
let wss = null;
|
|
@@ -2811,17 +3052,17 @@ ${FLOAT_ERROR_OVERLAY}
|
|
|
2811
3052
|
const pathname = url.pathname;
|
|
2812
3053
|
console.log(pc2.dim(` ${req.method} ${pathname}`));
|
|
2813
3054
|
try {
|
|
2814
|
-
const publicFilePath =
|
|
2815
|
-
if (
|
|
2816
|
-
const content =
|
|
3055
|
+
const publicFilePath = path7.join(publicDir, pathname);
|
|
3056
|
+
if (fs5.existsSync(publicFilePath) && fs5.statSync(publicFilePath).isFile()) {
|
|
3057
|
+
const content = fs5.readFileSync(publicFilePath);
|
|
2817
3058
|
const contentType = mime.lookup(publicFilePath) || "application/octet-stream";
|
|
2818
3059
|
res.writeHead(200, { "Content-Type": contentType });
|
|
2819
3060
|
res.end(content);
|
|
2820
3061
|
return;
|
|
2821
3062
|
}
|
|
2822
3063
|
if (pathname.endsWith(".css")) {
|
|
2823
|
-
const cssPath =
|
|
2824
|
-
if (
|
|
3064
|
+
const cssPath = path7.join(rootDir, "app", pathname.replace(/^\//, ""));
|
|
3065
|
+
if (fs5.existsSync(cssPath)) {
|
|
2825
3066
|
try {
|
|
2826
3067
|
const needsProcessing = needsCSSProcessing(cssPath, rootDir);
|
|
2827
3068
|
if (needsProcessing) {
|
|
@@ -2832,7 +3073,7 @@ ${FLOAT_ERROR_OVERLAY}
|
|
|
2832
3073
|
});
|
|
2833
3074
|
res.end(result.code);
|
|
2834
3075
|
} else {
|
|
2835
|
-
const content =
|
|
3076
|
+
const content = fs5.readFileSync(cssPath, "utf-8");
|
|
2836
3077
|
res.writeHead(200, {
|
|
2837
3078
|
"Content-Type": "text/css",
|
|
2838
3079
|
"Cache-Control": "no-cache"
|
|
@@ -2842,7 +3083,7 @@ ${FLOAT_ERROR_OVERLAY}
|
|
|
2842
3083
|
return;
|
|
2843
3084
|
} catch (error2) {
|
|
2844
3085
|
console.error(pc2.red("CSS processing error:"), error2);
|
|
2845
|
-
const content =
|
|
3086
|
+
const content = fs5.readFileSync(cssPath, "utf-8");
|
|
2846
3087
|
res.writeHead(200, { "Content-Type": "text/css" });
|
|
2847
3088
|
res.end(content);
|
|
2848
3089
|
return;
|
|
@@ -2957,9 +3198,9 @@ ${FLOAT_ERROR_OVERLAY}
|
|
|
2957
3198
|
});
|
|
2958
3199
|
const watcher = chokidar.watch(
|
|
2959
3200
|
[
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
3201
|
+
path7.join(rootDir, "app/**/*.{ts,tsx,js,jsx}"),
|
|
3202
|
+
path7.join(rootDir, "components/**/*.{ts,tsx,js,jsx}"),
|
|
3203
|
+
path7.join(rootDir, "lib/**/*.{ts,tsx,js,jsx}")
|
|
2963
3204
|
],
|
|
2964
3205
|
{
|
|
2965
3206
|
ignored: /node_modules/,
|
|
@@ -2968,7 +3209,7 @@ ${FLOAT_ERROR_OVERLAY}
|
|
|
2968
3209
|
);
|
|
2969
3210
|
watcher.on("change", async (filePath) => {
|
|
2970
3211
|
console.log(pc2.yellow(`
|
|
2971
|
-
\u26A1 File changed: ${
|
|
3212
|
+
\u26A1 File changed: ${path7.relative(rootDir, filePath)}`));
|
|
2972
3213
|
if (filePath.includes("/app/")) {
|
|
2973
3214
|
await refreshRoutes();
|
|
2974
3215
|
}
|
|
@@ -2977,7 +3218,7 @@ ${FLOAT_ERROR_OVERLAY}
|
|
|
2977
3218
|
watcher.on("add", async (filePath) => {
|
|
2978
3219
|
if (filePath.includes("/app/")) {
|
|
2979
3220
|
console.log(pc2.green(`
|
|
2980
|
-
\u2795 File added: ${
|
|
3221
|
+
\u2795 File added: ${path7.relative(rootDir, filePath)}`));
|
|
2981
3222
|
await refreshRoutes();
|
|
2982
3223
|
notifyClients("reload");
|
|
2983
3224
|
}
|
|
@@ -2985,7 +3226,7 @@ ${FLOAT_ERROR_OVERLAY}
|
|
|
2985
3226
|
watcher.on("unlink", async (filePath) => {
|
|
2986
3227
|
if (filePath.includes("/app/")) {
|
|
2987
3228
|
console.log(pc2.red(`
|
|
2988
|
-
\u2796 File removed: ${
|
|
3229
|
+
\u2796 File removed: ${path7.relative(rootDir, filePath)}`));
|
|
2989
3230
|
await refreshRoutes();
|
|
2990
3231
|
notifyClients("reload");
|
|
2991
3232
|
}
|
|
@@ -3120,8 +3361,8 @@ function escapeHtml2(text) {
|
|
|
3120
3361
|
// src/server/prod-server.ts
|
|
3121
3362
|
init_esm_shims();
|
|
3122
3363
|
import http2 from "http";
|
|
3123
|
-
import
|
|
3124
|
-
import
|
|
3364
|
+
import fs6 from "fs";
|
|
3365
|
+
import path8 from "path";
|
|
3125
3366
|
import pc3 from "picocolors";
|
|
3126
3367
|
import mime2 from "mime-types";
|
|
3127
3368
|
var cachedRoutes = [];
|
|
@@ -3129,24 +3370,24 @@ var pageCache = /* @__PURE__ */ new Map();
|
|
|
3129
3370
|
async function startProductionServer(options) {
|
|
3130
3371
|
const { port, host } = options;
|
|
3131
3372
|
const rootDir = process.cwd();
|
|
3132
|
-
const distDir =
|
|
3133
|
-
const publicDir =
|
|
3134
|
-
const manifestPath =
|
|
3135
|
-
if (
|
|
3136
|
-
const manifest = JSON.parse(
|
|
3373
|
+
const distDir = path8.join(rootDir, ".float");
|
|
3374
|
+
const publicDir = path8.join(rootDir, "public");
|
|
3375
|
+
const manifestPath = path8.join(distDir, "routes-manifest.json");
|
|
3376
|
+
if (fs6.existsSync(manifestPath)) {
|
|
3377
|
+
const manifest = JSON.parse(fs6.readFileSync(manifestPath, "utf-8"));
|
|
3137
3378
|
cachedRoutes = manifest.routes;
|
|
3138
3379
|
console.log(pc3.dim(` \u{1F4E6} Loaded ${cachedRoutes.length} routes from manifest`));
|
|
3139
3380
|
} else {
|
|
3140
3381
|
console.error(pc3.red(" \u274C No build manifest found. Run `float build` first."));
|
|
3141
3382
|
process.exit(1);
|
|
3142
3383
|
}
|
|
3143
|
-
const pagesDir =
|
|
3144
|
-
if (
|
|
3145
|
-
const prerenderedFiles =
|
|
3384
|
+
const pagesDir = path8.join(distDir, "pages");
|
|
3385
|
+
if (fs6.existsSync(pagesDir)) {
|
|
3386
|
+
const prerenderedFiles = fs6.readdirSync(pagesDir, { recursive: true });
|
|
3146
3387
|
for (const file of prerenderedFiles) {
|
|
3147
3388
|
if (file.endsWith(".html")) {
|
|
3148
3389
|
const routePath = "/" + file.replace(/\.html$/, "").replace(/index$/, "");
|
|
3149
|
-
const content =
|
|
3390
|
+
const content = fs6.readFileSync(path8.join(pagesDir, file), "utf-8");
|
|
3150
3391
|
pageCache.set(routePath, content);
|
|
3151
3392
|
}
|
|
3152
3393
|
}
|
|
@@ -3156,9 +3397,9 @@ async function startProductionServer(options) {
|
|
|
3156
3397
|
const url = new URL(req.url || "/", `http://${host}:${port}`);
|
|
3157
3398
|
const pathname = url.pathname;
|
|
3158
3399
|
try {
|
|
3159
|
-
const staticPath =
|
|
3160
|
-
if (
|
|
3161
|
-
const content =
|
|
3400
|
+
const staticPath = path8.join(distDir, "static", pathname);
|
|
3401
|
+
if (fs6.existsSync(staticPath) && fs6.statSync(staticPath).isFile()) {
|
|
3402
|
+
const content = fs6.readFileSync(staticPath);
|
|
3162
3403
|
const contentType = mime2.lookup(staticPath) || "application/octet-stream";
|
|
3163
3404
|
res.writeHead(200, {
|
|
3164
3405
|
"Content-Type": contentType,
|
|
@@ -3167,9 +3408,9 @@ async function startProductionServer(options) {
|
|
|
3167
3408
|
res.end(content);
|
|
3168
3409
|
return;
|
|
3169
3410
|
}
|
|
3170
|
-
const publicFilePath =
|
|
3171
|
-
if (
|
|
3172
|
-
const content =
|
|
3411
|
+
const publicFilePath = path8.join(publicDir, pathname);
|
|
3412
|
+
if (fs6.existsSync(publicFilePath) && fs6.statSync(publicFilePath).isFile()) {
|
|
3413
|
+
const content = fs6.readFileSync(publicFilePath);
|
|
3173
3414
|
const contentType = mime2.lookup(publicFilePath) || "application/octet-stream";
|
|
3174
3415
|
res.writeHead(200, { "Content-Type": contentType });
|
|
3175
3416
|
res.end(content);
|
|
@@ -3216,8 +3457,8 @@ async function startProductionServer(options) {
|
|
|
3216
3457
|
// src/build/index.ts
|
|
3217
3458
|
init_esm_shims();
|
|
3218
3459
|
import * as esbuild2 from "esbuild";
|
|
3219
|
-
import
|
|
3220
|
-
import
|
|
3460
|
+
import fs7 from "fs";
|
|
3461
|
+
import path9 from "path";
|
|
3221
3462
|
import pc4 from "picocolors";
|
|
3222
3463
|
var DEFAULT_BUILD_OPTIONS = {
|
|
3223
3464
|
analyze: false,
|
|
@@ -3228,14 +3469,14 @@ async function build2(options = {}) {
|
|
|
3228
3469
|
const opts = { ...DEFAULT_BUILD_OPTIONS, ...options };
|
|
3229
3470
|
const startTime = Date.now();
|
|
3230
3471
|
const rootDir = process.cwd();
|
|
3231
|
-
const outputDir =
|
|
3232
|
-
if (
|
|
3233
|
-
|
|
3234
|
-
}
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3472
|
+
const outputDir = path9.join(rootDir, ".float");
|
|
3473
|
+
if (fs7.existsSync(outputDir)) {
|
|
3474
|
+
fs7.rmSync(outputDir, { recursive: true });
|
|
3475
|
+
}
|
|
3476
|
+
fs7.mkdirSync(outputDir, { recursive: true });
|
|
3477
|
+
fs7.mkdirSync(path9.join(outputDir, "pages"), { recursive: true });
|
|
3478
|
+
fs7.mkdirSync(path9.join(outputDir, "static"), { recursive: true });
|
|
3479
|
+
fs7.mkdirSync(path9.join(outputDir, "server"), { recursive: true });
|
|
3239
3480
|
console.log(pc4.dim(" Scanning routes..."));
|
|
3240
3481
|
const routes = await scanRoutes(rootDir);
|
|
3241
3482
|
const pageRoutes = routes.filter((r) => r.type === "page" && !r.params.length);
|
|
@@ -3248,7 +3489,7 @@ async function build2(options = {}) {
|
|
|
3248
3489
|
await esbuild2.build({
|
|
3249
3490
|
entryPoints: clientEntryPoints,
|
|
3250
3491
|
bundle: true,
|
|
3251
|
-
outdir:
|
|
3492
|
+
outdir: path9.join(outputDir, "static", "_float"),
|
|
3252
3493
|
format: "esm",
|
|
3253
3494
|
splitting: true,
|
|
3254
3495
|
minify: opts.minify,
|
|
@@ -3276,7 +3517,7 @@ async function build2(options = {}) {
|
|
|
3276
3517
|
await esbuild2.build({
|
|
3277
3518
|
entryPoints: serverEntryPoints,
|
|
3278
3519
|
bundle: true,
|
|
3279
|
-
outdir:
|
|
3520
|
+
outdir: path9.join(outputDir, "server"),
|
|
3280
3521
|
format: "esm",
|
|
3281
3522
|
platform: "node",
|
|
3282
3523
|
target: ["node18"],
|
|
@@ -3298,9 +3539,9 @@ async function build2(options = {}) {
|
|
|
3298
3539
|
for (const route of pageRoutes) {
|
|
3299
3540
|
try {
|
|
3300
3541
|
const html = await renderPage(route, {}, { isDev: false });
|
|
3301
|
-
const outputPath = route.path === "/" ?
|
|
3302
|
-
|
|
3303
|
-
|
|
3542
|
+
const outputPath = route.path === "/" ? path9.join(outputDir, "pages", "index.html") : path9.join(outputDir, "pages", route.path, "index.html");
|
|
3543
|
+
fs7.mkdirSync(path9.dirname(outputPath), { recursive: true });
|
|
3544
|
+
fs7.writeFileSync(outputPath, html);
|
|
3304
3545
|
prerenderedPages.push(route.path);
|
|
3305
3546
|
console.log(pc4.dim(` \u2713 ${route.path}`));
|
|
3306
3547
|
} catch (error2) {
|
|
@@ -3312,7 +3553,7 @@ async function build2(options = {}) {
|
|
|
3312
3553
|
await esbuild2.build({
|
|
3313
3554
|
entryPoints: [route.absolutePath],
|
|
3314
3555
|
bundle: true,
|
|
3315
|
-
outfile:
|
|
3556
|
+
outfile: path9.join(outputDir, "server", "api", `${route.path.replace(/\//g, "_")}.js`),
|
|
3316
3557
|
format: "esm",
|
|
3317
3558
|
platform: "neutral",
|
|
3318
3559
|
// Edge compatible
|
|
@@ -3320,10 +3561,10 @@ async function build2(options = {}) {
|
|
|
3320
3561
|
minify: true
|
|
3321
3562
|
});
|
|
3322
3563
|
}
|
|
3323
|
-
const publicDir =
|
|
3324
|
-
if (
|
|
3564
|
+
const publicDir = path9.join(rootDir, "public");
|
|
3565
|
+
if (fs7.existsSync(publicDir)) {
|
|
3325
3566
|
console.log(pc4.dim(" Copying public assets..."));
|
|
3326
|
-
copyDir(publicDir,
|
|
3567
|
+
copyDir(publicDir, path9.join(outputDir, "static"));
|
|
3327
3568
|
}
|
|
3328
3569
|
const manifest = {
|
|
3329
3570
|
version: 1,
|
|
@@ -3332,19 +3573,19 @@ async function build2(options = {}) {
|
|
|
3332
3573
|
path: r.path,
|
|
3333
3574
|
type: r.type,
|
|
3334
3575
|
filePath: r.filePath,
|
|
3335
|
-
absolutePath:
|
|
3576
|
+
absolutePath: path9.relative(rootDir, r.absolutePath),
|
|
3336
3577
|
params: r.params,
|
|
3337
3578
|
isCatchAll: r.isCatchAll,
|
|
3338
3579
|
isOptionalCatchAll: r.isOptionalCatchAll,
|
|
3339
|
-
layouts: r.layouts.map((l) =>
|
|
3580
|
+
layouts: r.layouts.map((l) => path9.relative(rootDir, l)),
|
|
3340
3581
|
prerendered: prerenderedPages.includes(r.path)
|
|
3341
3582
|
})),
|
|
3342
3583
|
staticPages: prerenderedPages,
|
|
3343
3584
|
dynamicRoutes: dynamicRoutes.map((r) => r.path),
|
|
3344
3585
|
apiRoutes: apiRoutes.map((r) => r.path)
|
|
3345
3586
|
};
|
|
3346
|
-
|
|
3347
|
-
|
|
3587
|
+
fs7.writeFileSync(
|
|
3588
|
+
path9.join(outputDir, "routes-manifest.json"),
|
|
3348
3589
|
JSON.stringify(manifest, null, 2)
|
|
3349
3590
|
);
|
|
3350
3591
|
const duration = Date.now() - startTime;
|
|
@@ -3354,8 +3595,8 @@ async function build2(options = {}) {
|
|
|
3354
3595
|
routes: routes.length,
|
|
3355
3596
|
pages: prerenderedPages.length
|
|
3356
3597
|
};
|
|
3357
|
-
|
|
3358
|
-
|
|
3598
|
+
fs7.writeFileSync(
|
|
3599
|
+
path9.join(outputDir, "build-info.json"),
|
|
3359
3600
|
JSON.stringify(buildInfo, null, 2)
|
|
3360
3601
|
);
|
|
3361
3602
|
console.log("");
|
|
@@ -3373,15 +3614,15 @@ async function build2(options = {}) {
|
|
|
3373
3614
|
};
|
|
3374
3615
|
}
|
|
3375
3616
|
function copyDir(src, dest) {
|
|
3376
|
-
|
|
3377
|
-
const entries =
|
|
3617
|
+
fs7.mkdirSync(dest, { recursive: true });
|
|
3618
|
+
const entries = fs7.readdirSync(src, { withFileTypes: true });
|
|
3378
3619
|
for (const entry of entries) {
|
|
3379
|
-
const srcPath =
|
|
3380
|
-
const destPath =
|
|
3620
|
+
const srcPath = path9.join(src, entry.name);
|
|
3621
|
+
const destPath = path9.join(dest, entry.name);
|
|
3381
3622
|
if (entry.isDirectory()) {
|
|
3382
3623
|
copyDir(srcPath, destPath);
|
|
3383
3624
|
} else {
|
|
3384
|
-
|
|
3625
|
+
fs7.copyFileSync(srcPath, destPath);
|
|
3385
3626
|
}
|
|
3386
3627
|
}
|
|
3387
3628
|
}
|
|
@@ -5834,10 +6075,10 @@ function matcherToRegex(pattern) {
|
|
|
5834
6075
|
let regex = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/:([a-zA-Z_][a-zA-Z0-9_]*)/g, "(?<$1>[^/]+)").replace(/\\\*/g, ".*").replace(/\\\(([^)]+)\\\)/g, "($1)?");
|
|
5835
6076
|
return new RegExp(`^${regex}$`);
|
|
5836
6077
|
}
|
|
5837
|
-
function matchesPath(
|
|
6078
|
+
function matchesPath(path10, matcher) {
|
|
5838
6079
|
if (!matcher) return true;
|
|
5839
6080
|
const patterns = Array.isArray(matcher) ? matcher : [matcher];
|
|
5840
|
-
return patterns.some((pattern) => matcherToRegex(pattern).test(
|
|
6081
|
+
return patterns.some((pattern) => matcherToRegex(pattern).test(path10));
|
|
5841
6082
|
}
|
|
5842
6083
|
function parseCookies(cookieHeader) {
|
|
5843
6084
|
const cookies = /* @__PURE__ */ new Map();
|
|
@@ -6083,14 +6324,14 @@ var middlewareHelpers = {
|
|
|
6083
6324
|
*/
|
|
6084
6325
|
trailingSlash(add = false) {
|
|
6085
6326
|
return (req) => {
|
|
6086
|
-
const
|
|
6087
|
-
if (
|
|
6088
|
-
const hasSlash =
|
|
6327
|
+
const path10 = req.nextUrl.pathname;
|
|
6328
|
+
if (path10 === "/") return NextResponse.next();
|
|
6329
|
+
const hasSlash = path10.endsWith("/");
|
|
6089
6330
|
if (add && !hasSlash) {
|
|
6090
|
-
return NextResponse.redirect(new URL(
|
|
6331
|
+
return NextResponse.redirect(new URL(path10 + "/", req.request.url));
|
|
6091
6332
|
}
|
|
6092
6333
|
if (!add && hasSlash) {
|
|
6093
|
-
return NextResponse.redirect(new URL(
|
|
6334
|
+
return NextResponse.redirect(new URL(path10.slice(0, -1), req.request.url));
|
|
6094
6335
|
}
|
|
6095
6336
|
return NextResponse.next();
|
|
6096
6337
|
};
|
|
@@ -6128,8 +6369,8 @@ var SSGEngine = class {
|
|
|
6128
6369
|
mkdirSync2(this.diskCachePath, { recursive: true });
|
|
6129
6370
|
}
|
|
6130
6371
|
}
|
|
6131
|
-
getCacheKey(
|
|
6132
|
-
const normalized =
|
|
6372
|
+
getCacheKey(path10, locale) {
|
|
6373
|
+
const normalized = path10.replace(/^\/+|\/+$/g, "") || "index";
|
|
6133
6374
|
const key = locale ? `${locale}/${normalized}` : normalized;
|
|
6134
6375
|
return key.replace(/\//g, "__");
|
|
6135
6376
|
}
|
|
@@ -6142,9 +6383,9 @@ var SSGEngine = class {
|
|
|
6142
6383
|
/**
|
|
6143
6384
|
* Generate static page and cache it
|
|
6144
6385
|
*/
|
|
6145
|
-
async generatePage(
|
|
6386
|
+
async generatePage(path10, getStaticProps, render, params = {}, locale) {
|
|
6146
6387
|
const startTime = Date.now();
|
|
6147
|
-
const cacheKey = this.getCacheKey(
|
|
6388
|
+
const cacheKey = this.getCacheKey(path10, locale);
|
|
6148
6389
|
try {
|
|
6149
6390
|
const propsResult = await getStaticProps({
|
|
6150
6391
|
params,
|
|
@@ -6153,7 +6394,7 @@ var SSGEngine = class {
|
|
|
6153
6394
|
});
|
|
6154
6395
|
if (propsResult.redirect) {
|
|
6155
6396
|
return {
|
|
6156
|
-
path:
|
|
6397
|
+
path: path10,
|
|
6157
6398
|
success: true,
|
|
6158
6399
|
duration: Date.now() - startTime,
|
|
6159
6400
|
size: 0
|
|
@@ -6161,7 +6402,7 @@ var SSGEngine = class {
|
|
|
6161
6402
|
}
|
|
6162
6403
|
if (propsResult.notFound) {
|
|
6163
6404
|
return {
|
|
6164
|
-
path:
|
|
6405
|
+
path: path10,
|
|
6165
6406
|
success: false,
|
|
6166
6407
|
duration: Date.now() - startTime,
|
|
6167
6408
|
size: 0,
|
|
@@ -6185,7 +6426,7 @@ var SSGEngine = class {
|
|
|
6185
6426
|
this.setMemoryCache(cacheKey, cachedPage);
|
|
6186
6427
|
this.writeToDisk(cacheKey, cachedPage);
|
|
6187
6428
|
return {
|
|
6188
|
-
path:
|
|
6429
|
+
path: path10,
|
|
6189
6430
|
success: true,
|
|
6190
6431
|
duration: Date.now() - startTime,
|
|
6191
6432
|
size: html.length,
|
|
@@ -6193,7 +6434,7 @@ var SSGEngine = class {
|
|
|
6193
6434
|
};
|
|
6194
6435
|
} catch (error2) {
|
|
6195
6436
|
return {
|
|
6196
|
-
path:
|
|
6437
|
+
path: path10,
|
|
6197
6438
|
success: false,
|
|
6198
6439
|
duration: Date.now() - startTime,
|
|
6199
6440
|
size: 0,
|
|
@@ -6204,8 +6445,8 @@ var SSGEngine = class {
|
|
|
6204
6445
|
/**
|
|
6205
6446
|
* Get cached page or generate on-demand
|
|
6206
6447
|
*/
|
|
6207
|
-
async getPage(
|
|
6208
|
-
const cacheKey = this.getCacheKey(
|
|
6448
|
+
async getPage(path10, getStaticProps, render, params = {}, locale, fallback = false) {
|
|
6449
|
+
const cacheKey = this.getCacheKey(path10, locale);
|
|
6209
6450
|
let cached = this.memoryCache.get(cacheKey);
|
|
6210
6451
|
if (!cached) {
|
|
6211
6452
|
cached = this.readFromDisk(cacheKey) || void 0;
|
|
@@ -6216,7 +6457,7 @@ var SSGEngine = class {
|
|
|
6216
6457
|
if (cached) {
|
|
6217
6458
|
const isStale = cached.revalidateAfter !== null && Date.now() > cached.revalidateAfter;
|
|
6218
6459
|
if (isStale && this.config.staleWhileRevalidate) {
|
|
6219
|
-
this.triggerRevalidation(
|
|
6460
|
+
this.triggerRevalidation(path10, getStaticProps, render, params, locale);
|
|
6220
6461
|
}
|
|
6221
6462
|
return { cached, stale: isStale };
|
|
6222
6463
|
}
|
|
@@ -6224,7 +6465,7 @@ var SSGEngine = class {
|
|
|
6224
6465
|
return null;
|
|
6225
6466
|
}
|
|
6226
6467
|
if (fallback === "blocking") {
|
|
6227
|
-
const result = await this.generatePage(
|
|
6468
|
+
const result = await this.generatePage(path10, getStaticProps, render, params, locale);
|
|
6228
6469
|
if (result.success) {
|
|
6229
6470
|
const newCached = this.memoryCache.get(cacheKey);
|
|
6230
6471
|
return newCached ? { cached: newCached, stale: false } : null;
|
|
@@ -6235,14 +6476,14 @@ var SSGEngine = class {
|
|
|
6235
6476
|
/**
|
|
6236
6477
|
* Trigger ISR revalidation in background
|
|
6237
6478
|
*/
|
|
6238
|
-
async triggerRevalidation(
|
|
6239
|
-
const cacheKey = this.getCacheKey(
|
|
6479
|
+
async triggerRevalidation(path10, getStaticProps, render, params = {}, locale) {
|
|
6480
|
+
const cacheKey = this.getCacheKey(path10, locale);
|
|
6240
6481
|
if (this.isrState.revalidating.has(cacheKey)) {
|
|
6241
6482
|
return;
|
|
6242
6483
|
}
|
|
6243
6484
|
this.isrState.revalidating.add(cacheKey);
|
|
6244
6485
|
try {
|
|
6245
|
-
await this.generatePage(
|
|
6486
|
+
await this.generatePage(path10, getStaticProps, render, params, locale);
|
|
6246
6487
|
this.isrState.lastRevalidation.set(cacheKey, Date.now());
|
|
6247
6488
|
} finally {
|
|
6248
6489
|
this.isrState.revalidating.delete(cacheKey);
|
|
@@ -6251,9 +6492,9 @@ var SSGEngine = class {
|
|
|
6251
6492
|
/**
|
|
6252
6493
|
* Force revalidation of a path (On-Demand ISR)
|
|
6253
6494
|
*/
|
|
6254
|
-
async revalidate(
|
|
6495
|
+
async revalidate(path10, getStaticProps, render, params = {}, locale) {
|
|
6255
6496
|
try {
|
|
6256
|
-
const result = await this.generatePage(
|
|
6497
|
+
const result = await this.generatePage(path10, getStaticProps, render, params, locale);
|
|
6257
6498
|
return { revalidated: result.success, error: result.error?.message };
|
|
6258
6499
|
} catch (error2) {
|
|
6259
6500
|
return {
|
|
@@ -6416,10 +6657,10 @@ function createSSGHandler(options) {
|
|
|
6416
6657
|
const engine = getSSGEngine();
|
|
6417
6658
|
return async (req) => {
|
|
6418
6659
|
const url = new URL(req.url);
|
|
6419
|
-
const
|
|
6660
|
+
const path10 = url.pathname;
|
|
6420
6661
|
const params = {};
|
|
6421
6662
|
const result = await engine.getPage(
|
|
6422
|
-
|
|
6663
|
+
path10,
|
|
6423
6664
|
options.getStaticProps,
|
|
6424
6665
|
options.render,
|
|
6425
6666
|
params,
|
|
@@ -6786,7 +7027,7 @@ var AnalyticsEngine = class {
|
|
|
6786
7027
|
for (const pv of recentPageviews) {
|
|
6787
7028
|
pathCounts[pv.pathname] = (pathCounts[pv.pathname] || 0) + 1;
|
|
6788
7029
|
}
|
|
6789
|
-
const topPages = Object.entries(pathCounts).map(([
|
|
7030
|
+
const topPages = Object.entries(pathCounts).map(([path10, count]) => ({ path: path10, count })).sort((a, b) => b.count - a.count).slice(0, 10);
|
|
6790
7031
|
return {
|
|
6791
7032
|
activeUsers: activeSessions.size,
|
|
6792
7033
|
pageviews: recentPageviews.length,
|