@lolyjs/core 0.2.0-alpha.12 → 0.2.0-alpha.14
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/cli.cjs +62 -59
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +55 -52
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +60 -57
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +53 -50
- package/dist/index.js.map +1 -1
- package/dist/react/hooks.cjs +16 -6
- package/dist/react/hooks.cjs.map +1 -1
- package/dist/react/hooks.js +23 -13
- package/dist/react/hooks.js.map +1 -1
- package/dist/react/sockets.cjs +10 -4
- package/dist/react/sockets.cjs.map +1 -1
- package/dist/react/sockets.js +10 -4
- package/dist/react/sockets.js.map +1 -1
- package/dist/react/themes.cjs +61 -18
- package/dist/react/themes.cjs.map +1 -1
- package/dist/react/themes.js +63 -20
- package/dist/react/themes.js.map +1 -1
- package/dist/runtime.cjs +1 -1
- package/dist/runtime.cjs.map +1 -1
- package/dist/runtime.js +1 -1
- package/dist/runtime.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1108,6 +1108,7 @@ import { rspack as rspack2 } from "@rspack/core";
|
|
|
1108
1108
|
|
|
1109
1109
|
// modules/build/config/client.ts
|
|
1110
1110
|
import path11 from "path";
|
|
1111
|
+
import fs11 from "fs";
|
|
1111
1112
|
import { rspack } from "@rspack/core";
|
|
1112
1113
|
|
|
1113
1114
|
// modules/build/utils/index.ts
|
|
@@ -1251,15 +1252,21 @@ function createClientConfig(projectRoot, mode) {
|
|
|
1251
1252
|
const buildDir = path11.join(projectRoot, BUILD_FOLDER_NAME);
|
|
1252
1253
|
const clientEntry = path11.join(buildDir, "boostrap.ts");
|
|
1253
1254
|
const outDir = path11.join(buildDir, "client");
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1255
|
+
const envPath2 = path11.join(projectRoot, ".env");
|
|
1256
|
+
if (fs11.existsSync(envPath2)) {
|
|
1257
|
+
dotenv.config({
|
|
1258
|
+
path: envPath2
|
|
1259
|
+
});
|
|
1260
|
+
}
|
|
1257
1261
|
const publicEnv = {};
|
|
1258
1262
|
for (const [key, value] of Object.entries(process.env)) {
|
|
1259
1263
|
if (key.startsWith("PUBLIC_")) {
|
|
1260
1264
|
publicEnv[`process.env.${key}`] = JSON.stringify(value ?? "");
|
|
1261
1265
|
}
|
|
1262
1266
|
}
|
|
1267
|
+
if (!publicEnv["process.env.PUBLIC_WS_BASE_URL"]) {
|
|
1268
|
+
publicEnv["process.env.PUBLIC_WS_BASE_URL"] = JSON.stringify(void 0);
|
|
1269
|
+
}
|
|
1263
1270
|
const config = {
|
|
1264
1271
|
mode,
|
|
1265
1272
|
entry: {
|
|
@@ -1308,7 +1315,8 @@ function createClientConfig(projectRoot, mode) {
|
|
|
1308
1315
|
},
|
|
1309
1316
|
plugins: [
|
|
1310
1317
|
new rspack.DefinePlugin({
|
|
1311
|
-
|
|
1318
|
+
// Always define NODE_ENV, using mode as fallback if not set
|
|
1319
|
+
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || mode),
|
|
1312
1320
|
...publicEnv
|
|
1313
1321
|
}),
|
|
1314
1322
|
new rspack.CssExtractRspackPlugin({
|
|
@@ -1326,7 +1334,7 @@ function createClientConfig(projectRoot, mode) {
|
|
|
1326
1334
|
// modules/build/bundler/client.ts
|
|
1327
1335
|
init_globals();
|
|
1328
1336
|
import path12 from "path";
|
|
1329
|
-
import
|
|
1337
|
+
import fs12 from "fs";
|
|
1330
1338
|
function startClientBundler(projectRoot, mode = "development") {
|
|
1331
1339
|
const { config, outDir } = createClientConfig(projectRoot, mode);
|
|
1332
1340
|
copyStaticAssets(projectRoot, outDir);
|
|
@@ -1417,7 +1425,7 @@ function buildClientBundle(projectRoot) {
|
|
|
1417
1425
|
copyStaticAssets(projectRoot, outDir);
|
|
1418
1426
|
const assetManifest = generateAssetManifest(outDir);
|
|
1419
1427
|
const manifestPath = path12.join(projectRoot, BUILD_FOLDER_NAME, "asset-manifest.json");
|
|
1420
|
-
|
|
1428
|
+
fs12.writeFileSync(manifestPath, JSON.stringify(assetManifest, null, 2), "utf-8");
|
|
1421
1429
|
resolve3({ outDir });
|
|
1422
1430
|
});
|
|
1423
1431
|
});
|
|
@@ -1460,7 +1468,7 @@ function pathToOutDir(baseDir, urlPath) {
|
|
|
1460
1468
|
}
|
|
1461
1469
|
|
|
1462
1470
|
// modules/build/ssg/renderer.ts
|
|
1463
|
-
import
|
|
1471
|
+
import fs13 from "fs";
|
|
1464
1472
|
import path14 from "path";
|
|
1465
1473
|
import { renderToString } from "react-dom/server";
|
|
1466
1474
|
|
|
@@ -1683,8 +1691,8 @@ async function renderStaticRoute(projectRoot, ssgOutDir, route, urlPath, params)
|
|
|
1683
1691
|
ensureDir(dir);
|
|
1684
1692
|
const htmlFile = path14.join(dir, "index.html");
|
|
1685
1693
|
const dataFile = path14.join(dir, "data.json");
|
|
1686
|
-
|
|
1687
|
-
|
|
1694
|
+
fs13.writeFileSync(htmlFile, html, "utf-8");
|
|
1695
|
+
fs13.writeFileSync(dataFile, JSON.stringify(initialData, null, 2), "utf-8");
|
|
1688
1696
|
}
|
|
1689
1697
|
|
|
1690
1698
|
// modules/build/ssg/builder.ts
|
|
@@ -1739,12 +1747,12 @@ async function buildStaticPages(projectRoot, routes) {
|
|
|
1739
1747
|
|
|
1740
1748
|
// modules/build/bundler/server.ts
|
|
1741
1749
|
import path17 from "path";
|
|
1742
|
-
import
|
|
1750
|
+
import fs15 from "fs";
|
|
1743
1751
|
import esbuild from "esbuild";
|
|
1744
1752
|
|
|
1745
1753
|
// modules/server/utils/server-dir.ts
|
|
1746
1754
|
init_globals();
|
|
1747
|
-
import
|
|
1755
|
+
import fs14 from "fs";
|
|
1748
1756
|
import path16 from "path";
|
|
1749
1757
|
var getServerFile = async (projectRoot, fileName) => {
|
|
1750
1758
|
const fileTS = path16.join(projectRoot, `${fileName}.ts`);
|
|
@@ -1752,13 +1760,13 @@ var getServerFile = async (projectRoot, fileName) => {
|
|
|
1752
1760
|
const isDev = process.env.NODE_ENV === "development";
|
|
1753
1761
|
let mod = null;
|
|
1754
1762
|
if (isDev) {
|
|
1755
|
-
if (!
|
|
1763
|
+
if (!fs14.existsSync(fileTS)) {
|
|
1756
1764
|
return null;
|
|
1757
1765
|
}
|
|
1758
1766
|
__require("tsx/cjs");
|
|
1759
1767
|
mod = __require(fileTS);
|
|
1760
1768
|
} else {
|
|
1761
|
-
if (!
|
|
1769
|
+
if (!fs14.existsSync(fileJS)) {
|
|
1762
1770
|
return null;
|
|
1763
1771
|
}
|
|
1764
1772
|
mod = __require(fileJS);
|
|
@@ -1851,7 +1859,7 @@ var SERVER_FILES = [INIT_FILE_NAME, CONFIG_FILE_NAME];
|
|
|
1851
1859
|
function collectAppSources(appDir) {
|
|
1852
1860
|
const entries = [];
|
|
1853
1861
|
function walk(dir) {
|
|
1854
|
-
const items =
|
|
1862
|
+
const items = fs15.readdirSync(dir, { withFileTypes: true });
|
|
1855
1863
|
for (const item of items) {
|
|
1856
1864
|
const full = path17.join(dir, item.name);
|
|
1857
1865
|
if (item.isDirectory()) {
|
|
@@ -1894,7 +1902,7 @@ async function buildServerApp(projectRoot, appDir) {
|
|
|
1894
1902
|
for (const fileName of SERVER_FILES) {
|
|
1895
1903
|
const initTS = path17.join(projectRoot, `${fileName}.ts`);
|
|
1896
1904
|
const initJS = path17.join(outDir, `${fileName}.js`);
|
|
1897
|
-
if (
|
|
1905
|
+
if (fs15.existsSync(initTS)) {
|
|
1898
1906
|
await esbuild.build({
|
|
1899
1907
|
entryPoints: [initTS],
|
|
1900
1908
|
outfile: initJS,
|
|
@@ -1918,7 +1926,7 @@ init_globals();
|
|
|
1918
1926
|
// src/config.ts
|
|
1919
1927
|
init_globals();
|
|
1920
1928
|
import path18 from "path";
|
|
1921
|
-
import
|
|
1929
|
+
import fs16 from "fs";
|
|
1922
1930
|
var DEFAULT_CONFIG2 = {
|
|
1923
1931
|
directories: {
|
|
1924
1932
|
app: "app",
|
|
@@ -1980,10 +1988,10 @@ function loadConfig(projectRoot) {
|
|
|
1980
1988
|
];
|
|
1981
1989
|
let userConfig = {};
|
|
1982
1990
|
for (const configFile of configFiles) {
|
|
1983
|
-
if (
|
|
1991
|
+
if (fs16.existsSync(configFile)) {
|
|
1984
1992
|
try {
|
|
1985
1993
|
if (configFile.endsWith(".json")) {
|
|
1986
|
-
const content =
|
|
1994
|
+
const content = fs16.readFileSync(configFile, "utf-8");
|
|
1987
1995
|
userConfig = JSON.parse(content);
|
|
1988
1996
|
} else {
|
|
1989
1997
|
if (process.env.NODE_ENV === "development") {
|
|
@@ -2000,7 +2008,7 @@ function loadConfig(projectRoot) {
|
|
|
2000
2008
|
}
|
|
2001
2009
|
const config = deepMerge(DEFAULT_CONFIG2, userConfig);
|
|
2002
2010
|
const appDir = path18.join(projectRoot, config.directories.app);
|
|
2003
|
-
if (!
|
|
2011
|
+
if (!fs16.existsSync(appDir) && process.env.NODE_ENV !== "test") {
|
|
2004
2012
|
console.warn(`[framework] App directory not found: ${appDir}`);
|
|
2005
2013
|
}
|
|
2006
2014
|
return config;
|
|
@@ -2061,7 +2069,7 @@ async function buildApp(options = {}) {
|
|
|
2061
2069
|
}
|
|
2062
2070
|
|
|
2063
2071
|
// src/server.ts
|
|
2064
|
-
import
|
|
2072
|
+
import fs18 from "fs";
|
|
2065
2073
|
import path24 from "path";
|
|
2066
2074
|
|
|
2067
2075
|
// modules/server/setup.ts
|
|
@@ -4200,7 +4208,6 @@ function requestLoggerMiddleware(options = {}) {
|
|
|
4200
4208
|
const startTime = Date.now();
|
|
4201
4209
|
res.on("finish", () => {
|
|
4202
4210
|
const duration = Date.now() - startTime;
|
|
4203
|
-
const shouldLogSuccess = logRequests === true;
|
|
4204
4211
|
if (res.statusCode >= 500) {
|
|
4205
4212
|
reqLogger.error(`${req.method} ${req.path} ${res.statusCode}`, {
|
|
4206
4213
|
statusCode: res.statusCode,
|
|
@@ -4211,11 +4218,6 @@ function requestLoggerMiddleware(options = {}) {
|
|
|
4211
4218
|
statusCode: res.statusCode,
|
|
4212
4219
|
duration: `${duration}ms`
|
|
4213
4220
|
});
|
|
4214
|
-
} else if (shouldLogSuccess) {
|
|
4215
|
-
reqLogger.debug(`${req.method} ${req.path} ${res.statusCode}`, {
|
|
4216
|
-
statusCode: res.statusCode,
|
|
4217
|
-
duration: `${duration}ms`
|
|
4218
|
-
});
|
|
4219
4221
|
}
|
|
4220
4222
|
});
|
|
4221
4223
|
}
|
|
@@ -4369,7 +4371,7 @@ function handleNotFound(res, urlPath) {
|
|
|
4369
4371
|
}
|
|
4370
4372
|
|
|
4371
4373
|
// modules/server/handlers/ssg.ts
|
|
4372
|
-
import
|
|
4374
|
+
import fs17 from "fs";
|
|
4373
4375
|
import path22 from "path";
|
|
4374
4376
|
var logger2 = createModuleLogger("ssg");
|
|
4375
4377
|
function getSsgDirForPath(baseDir, urlPath) {
|
|
@@ -4386,7 +4388,7 @@ function getSsgDataPath(baseDir, urlPath) {
|
|
|
4386
4388
|
}
|
|
4387
4389
|
function tryServeSsgHtml(res, ssgOutDir, urlPath) {
|
|
4388
4390
|
const ssgHtmlPath = getSsgHtmlPath(ssgOutDir, urlPath);
|
|
4389
|
-
if (!
|
|
4391
|
+
if (!fs17.existsSync(ssgHtmlPath)) {
|
|
4390
4392
|
return false;
|
|
4391
4393
|
}
|
|
4392
4394
|
logger2.info("Serving SSG HTML", { urlPath, ssgHtmlPath });
|
|
@@ -4396,17 +4398,17 @@ function tryServeSsgHtml(res, ssgOutDir, urlPath) {
|
|
|
4396
4398
|
);
|
|
4397
4399
|
res.statusCode = 200;
|
|
4398
4400
|
res.setHeader("Content-Type", "text/html; charset=utf-8");
|
|
4399
|
-
const stream =
|
|
4401
|
+
const stream = fs17.createReadStream(ssgHtmlPath, { encoding: "utf-8" });
|
|
4400
4402
|
stream.pipe(res);
|
|
4401
4403
|
return true;
|
|
4402
4404
|
}
|
|
4403
4405
|
function tryServeSsgData(res, ssgOutDir, urlPath) {
|
|
4404
4406
|
const ssgDataPath = getSsgDataPath(ssgOutDir, urlPath);
|
|
4405
|
-
if (!
|
|
4407
|
+
if (!fs17.existsSync(ssgDataPath)) {
|
|
4406
4408
|
return false;
|
|
4407
4409
|
}
|
|
4408
4410
|
try {
|
|
4409
|
-
const raw =
|
|
4411
|
+
const raw = fs17.readFileSync(ssgDataPath, "utf-8");
|
|
4410
4412
|
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
4411
4413
|
res.status(200).end(raw);
|
|
4412
4414
|
return true;
|
|
@@ -5045,7 +5047,12 @@ var setupApplication = async ({
|
|
|
5045
5047
|
|
|
5046
5048
|
// src/server.ts
|
|
5047
5049
|
import dotenv2 from "dotenv";
|
|
5048
|
-
|
|
5050
|
+
var envPath = path24.join(process.cwd(), ".env");
|
|
5051
|
+
if (fs18.existsSync(envPath)) {
|
|
5052
|
+
dotenv2.config({ path: envPath });
|
|
5053
|
+
} else {
|
|
5054
|
+
dotenv2.config();
|
|
5055
|
+
}
|
|
5049
5056
|
var logger3 = createModuleLogger("server");
|
|
5050
5057
|
async function startServer(options = {}) {
|
|
5051
5058
|
const isDev = options.isDev ?? process.env.NODE_ENV === "development";
|
|
@@ -5054,7 +5061,7 @@ async function startServer(options = {}) {
|
|
|
5054
5061
|
const port = options.port ?? (process.env.PORT ? parseInt(process.env.PORT, 10) : void 0) ?? config.server.port;
|
|
5055
5062
|
const host = process.env.HOST ?? (!isDev ? "0.0.0.0" : void 0) ?? config.server.host;
|
|
5056
5063
|
const appDir = options.appDir ?? (isDev ? getAppDir(projectRoot, config) : path24.join(getBuildDir(projectRoot, config), "server"));
|
|
5057
|
-
if (!isDev && !
|
|
5064
|
+
if (!isDev && !fs18.existsSync(appDir)) {
|
|
5058
5065
|
logger3.error("Compiled directory not found", void 0, {
|
|
5059
5066
|
buildDir: config.directories.build,
|
|
5060
5067
|
appDir,
|
|
@@ -5091,26 +5098,22 @@ async function startServer(options = {}) {
|
|
|
5091
5098
|
});
|
|
5092
5099
|
httpServer.listen(port, host, () => {
|
|
5093
5100
|
if (isDev) {
|
|
5094
|
-
|
|
5095
|
-
|
|
5096
|
-
|
|
5097
|
-
|
|
5098
|
-
|
|
5099
|
-
|
|
5101
|
+
const reset = "\x1B[0m";
|
|
5102
|
+
const cyan = "\x1B[36m";
|
|
5103
|
+
const green = "\x1B[32m";
|
|
5104
|
+
const dim = "\x1B[2m";
|
|
5105
|
+
const bold = "\x1B[1m";
|
|
5106
|
+
const url = `http://${host === "0.0.0.0" ? "localhost" : host}:${port}`;
|
|
5107
|
+
console.log();
|
|
5108
|
+
console.log(`${bold}${green}\u2713${reset} ${bold}Dev server ready${reset}`);
|
|
5109
|
+
console.log(`${dim} Local:${reset} ${cyan}${url}${reset}`);
|
|
5110
|
+
if (routes.length > 0 || apiRoutes.length > 0 || wssRoutes.length > 0) {
|
|
5111
|
+
console.log(`${dim} Routes:${reset} ${routes.length} pages, ${apiRoutes.length} API, ${wssRoutes.length} WSS`);
|
|
5112
|
+
}
|
|
5113
|
+
console.log();
|
|
5100
5114
|
} else {
|
|
5101
|
-
const
|
|
5102
|
-
|
|
5103
|
-
url: `http://${host}:${port}`,
|
|
5104
|
-
appDir,
|
|
5105
|
-
buildDir
|
|
5106
|
-
});
|
|
5107
|
-
logger3.info("\u{1F9ED} Reading compiled routes from", { appDir });
|
|
5108
|
-
logger3.info("\u{1F4E6} Client served from", {
|
|
5109
|
-
path: `/static (${buildDir}/client)`
|
|
5110
|
-
});
|
|
5111
|
-
logger3.info("\u{1F4C4} SSG served from", {
|
|
5112
|
-
path: `${buildDir}/ssg (if exists)`
|
|
5113
|
-
});
|
|
5115
|
+
const url = `http://${host}:${port}`;
|
|
5116
|
+
console.log(`\u{1F680} Server running on ${url}`);
|
|
5114
5117
|
}
|
|
5115
5118
|
});
|
|
5116
5119
|
}
|