@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/index.js
CHANGED
|
@@ -73,7 +73,7 @@ var init_globals = __esm({
|
|
|
73
73
|
});
|
|
74
74
|
|
|
75
75
|
// src/server.ts
|
|
76
|
-
import
|
|
76
|
+
import fs16 from "fs";
|
|
77
77
|
import path20 from "path";
|
|
78
78
|
|
|
79
79
|
// modules/server/utils/server-dir.ts
|
|
@@ -1148,6 +1148,7 @@ import { rspack as rspack2 } from "@rspack/core";
|
|
|
1148
1148
|
|
|
1149
1149
|
// modules/build/config/client.ts
|
|
1150
1150
|
import path12 from "path";
|
|
1151
|
+
import fs12 from "fs";
|
|
1151
1152
|
import { rspack } from "@rspack/core";
|
|
1152
1153
|
|
|
1153
1154
|
// modules/build/utils/index.ts
|
|
@@ -1291,15 +1292,21 @@ function createClientConfig(projectRoot, mode) {
|
|
|
1291
1292
|
const buildDir = path12.join(projectRoot, BUILD_FOLDER_NAME);
|
|
1292
1293
|
const clientEntry = path12.join(buildDir, "boostrap.ts");
|
|
1293
1294
|
const outDir = path12.join(buildDir, "client");
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1295
|
+
const envPath2 = path12.join(projectRoot, ".env");
|
|
1296
|
+
if (fs12.existsSync(envPath2)) {
|
|
1297
|
+
dotenv.config({
|
|
1298
|
+
path: envPath2
|
|
1299
|
+
});
|
|
1300
|
+
}
|
|
1297
1301
|
const publicEnv = {};
|
|
1298
1302
|
for (const [key, value] of Object.entries(process.env)) {
|
|
1299
1303
|
if (key.startsWith("PUBLIC_")) {
|
|
1300
1304
|
publicEnv[`process.env.${key}`] = JSON.stringify(value ?? "");
|
|
1301
1305
|
}
|
|
1302
1306
|
}
|
|
1307
|
+
if (!publicEnv["process.env.PUBLIC_WS_BASE_URL"]) {
|
|
1308
|
+
publicEnv["process.env.PUBLIC_WS_BASE_URL"] = JSON.stringify(void 0);
|
|
1309
|
+
}
|
|
1303
1310
|
const config = {
|
|
1304
1311
|
mode,
|
|
1305
1312
|
entry: {
|
|
@@ -1348,7 +1355,8 @@ function createClientConfig(projectRoot, mode) {
|
|
|
1348
1355
|
},
|
|
1349
1356
|
plugins: [
|
|
1350
1357
|
new rspack.DefinePlugin({
|
|
1351
|
-
|
|
1358
|
+
// Always define NODE_ENV, using mode as fallback if not set
|
|
1359
|
+
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || mode),
|
|
1352
1360
|
...publicEnv
|
|
1353
1361
|
}),
|
|
1354
1362
|
new rspack.CssExtractRspackPlugin({
|
|
@@ -1366,7 +1374,7 @@ function createClientConfig(projectRoot, mode) {
|
|
|
1366
1374
|
// modules/build/bundler/client.ts
|
|
1367
1375
|
init_globals();
|
|
1368
1376
|
import path13 from "path";
|
|
1369
|
-
import
|
|
1377
|
+
import fs13 from "fs";
|
|
1370
1378
|
function startClientBundler(projectRoot, mode = "development") {
|
|
1371
1379
|
const { config, outDir } = createClientConfig(projectRoot, mode);
|
|
1372
1380
|
copyStaticAssets(projectRoot, outDir);
|
|
@@ -1457,7 +1465,7 @@ function buildClientBundle(projectRoot) {
|
|
|
1457
1465
|
copyStaticAssets(projectRoot, outDir);
|
|
1458
1466
|
const assetManifest = generateAssetManifest(outDir);
|
|
1459
1467
|
const manifestPath = path13.join(projectRoot, BUILD_FOLDER_NAME, "asset-manifest.json");
|
|
1460
|
-
|
|
1468
|
+
fs13.writeFileSync(manifestPath, JSON.stringify(assetManifest, null, 2), "utf-8");
|
|
1461
1469
|
resolve3({ outDir });
|
|
1462
1470
|
});
|
|
1463
1471
|
});
|
|
@@ -3229,7 +3237,7 @@ init_globals();
|
|
|
3229
3237
|
// src/config.ts
|
|
3230
3238
|
init_globals();
|
|
3231
3239
|
import path16 from "path";
|
|
3232
|
-
import
|
|
3240
|
+
import fs14 from "fs";
|
|
3233
3241
|
var DEFAULT_CONFIG = {
|
|
3234
3242
|
directories: {
|
|
3235
3243
|
app: "app",
|
|
@@ -3291,10 +3299,10 @@ function loadConfig(projectRoot) {
|
|
|
3291
3299
|
];
|
|
3292
3300
|
let userConfig = {};
|
|
3293
3301
|
for (const configFile of configFiles) {
|
|
3294
|
-
if (
|
|
3302
|
+
if (fs14.existsSync(configFile)) {
|
|
3295
3303
|
try {
|
|
3296
3304
|
if (configFile.endsWith(".json")) {
|
|
3297
|
-
const content =
|
|
3305
|
+
const content = fs14.readFileSync(configFile, "utf-8");
|
|
3298
3306
|
userConfig = JSON.parse(content);
|
|
3299
3307
|
} else {
|
|
3300
3308
|
if (process.env.NODE_ENV === "development") {
|
|
@@ -3311,7 +3319,7 @@ function loadConfig(projectRoot) {
|
|
|
3311
3319
|
}
|
|
3312
3320
|
const config = deepMerge(DEFAULT_CONFIG, userConfig);
|
|
3313
3321
|
const appDir = path16.join(projectRoot, config.directories.app);
|
|
3314
|
-
if (!
|
|
3322
|
+
if (!fs14.existsSync(appDir) && process.env.NODE_ENV !== "test") {
|
|
3315
3323
|
console.warn(`[framework] App directory not found: ${appDir}`);
|
|
3316
3324
|
}
|
|
3317
3325
|
return config;
|
|
@@ -3703,7 +3711,6 @@ function requestLoggerMiddleware(options = {}) {
|
|
|
3703
3711
|
const startTime = Date.now();
|
|
3704
3712
|
res.on("finish", () => {
|
|
3705
3713
|
const duration = Date.now() - startTime;
|
|
3706
|
-
const shouldLogSuccess = logRequests === true;
|
|
3707
3714
|
if (res.statusCode >= 500) {
|
|
3708
3715
|
reqLogger.error(`${req.method} ${req.path} ${res.statusCode}`, {
|
|
3709
3716
|
statusCode: res.statusCode,
|
|
@@ -3714,11 +3721,6 @@ function requestLoggerMiddleware(options = {}) {
|
|
|
3714
3721
|
statusCode: res.statusCode,
|
|
3715
3722
|
duration: `${duration}ms`
|
|
3716
3723
|
});
|
|
3717
|
-
} else if (shouldLogSuccess) {
|
|
3718
|
-
reqLogger.debug(`${req.method} ${req.path} ${res.statusCode}`, {
|
|
3719
|
-
statusCode: res.statusCode,
|
|
3720
|
-
duration: `${duration}ms`
|
|
3721
|
-
});
|
|
3722
3724
|
}
|
|
3723
3725
|
});
|
|
3724
3726
|
}
|
|
@@ -4020,7 +4022,7 @@ function handleNotFound(res, urlPath) {
|
|
|
4020
4022
|
}
|
|
4021
4023
|
|
|
4022
4024
|
// modules/server/handlers/ssg.ts
|
|
4023
|
-
import
|
|
4025
|
+
import fs15 from "fs";
|
|
4024
4026
|
import path18 from "path";
|
|
4025
4027
|
var logger2 = createModuleLogger("ssg");
|
|
4026
4028
|
function getSsgDirForPath(baseDir, urlPath) {
|
|
@@ -4037,7 +4039,7 @@ function getSsgDataPath(baseDir, urlPath) {
|
|
|
4037
4039
|
}
|
|
4038
4040
|
function tryServeSsgHtml(res, ssgOutDir, urlPath) {
|
|
4039
4041
|
const ssgHtmlPath = getSsgHtmlPath(ssgOutDir, urlPath);
|
|
4040
|
-
if (!
|
|
4042
|
+
if (!fs15.existsSync(ssgHtmlPath)) {
|
|
4041
4043
|
return false;
|
|
4042
4044
|
}
|
|
4043
4045
|
logger2.info("Serving SSG HTML", { urlPath, ssgHtmlPath });
|
|
@@ -4047,17 +4049,17 @@ function tryServeSsgHtml(res, ssgOutDir, urlPath) {
|
|
|
4047
4049
|
);
|
|
4048
4050
|
res.statusCode = 200;
|
|
4049
4051
|
res.setHeader("Content-Type", "text/html; charset=utf-8");
|
|
4050
|
-
const stream =
|
|
4052
|
+
const stream = fs15.createReadStream(ssgHtmlPath, { encoding: "utf-8" });
|
|
4051
4053
|
stream.pipe(res);
|
|
4052
4054
|
return true;
|
|
4053
4055
|
}
|
|
4054
4056
|
function tryServeSsgData(res, ssgOutDir, urlPath) {
|
|
4055
4057
|
const ssgDataPath = getSsgDataPath(ssgOutDir, urlPath);
|
|
4056
|
-
if (!
|
|
4058
|
+
if (!fs15.existsSync(ssgDataPath)) {
|
|
4057
4059
|
return false;
|
|
4058
4060
|
}
|
|
4059
4061
|
try {
|
|
4060
|
-
const raw =
|
|
4062
|
+
const raw = fs15.readFileSync(ssgDataPath, "utf-8");
|
|
4061
4063
|
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
4062
4064
|
res.status(200).end(raw);
|
|
4063
4065
|
return true;
|
|
@@ -4765,7 +4767,12 @@ var setupApplication = async ({
|
|
|
4765
4767
|
|
|
4766
4768
|
// src/server.ts
|
|
4767
4769
|
import dotenv2 from "dotenv";
|
|
4768
|
-
|
|
4770
|
+
var envPath = path20.join(process.cwd(), ".env");
|
|
4771
|
+
if (fs16.existsSync(envPath)) {
|
|
4772
|
+
dotenv2.config({ path: envPath });
|
|
4773
|
+
} else {
|
|
4774
|
+
dotenv2.config();
|
|
4775
|
+
}
|
|
4769
4776
|
var logger3 = createModuleLogger("server");
|
|
4770
4777
|
async function startServer(options = {}) {
|
|
4771
4778
|
const isDev = options.isDev ?? process.env.NODE_ENV === "development";
|
|
@@ -4774,7 +4781,7 @@ async function startServer(options = {}) {
|
|
|
4774
4781
|
const port = options.port ?? (process.env.PORT ? parseInt(process.env.PORT, 10) : void 0) ?? config.server.port;
|
|
4775
4782
|
const host = process.env.HOST ?? (!isDev ? "0.0.0.0" : void 0) ?? config.server.host;
|
|
4776
4783
|
const appDir = options.appDir ?? (isDev ? getAppDir(projectRoot, config) : path20.join(getBuildDir(projectRoot, config), "server"));
|
|
4777
|
-
if (!isDev && !
|
|
4784
|
+
if (!isDev && !fs16.existsSync(appDir)) {
|
|
4778
4785
|
logger3.error("Compiled directory not found", void 0, {
|
|
4779
4786
|
buildDir: config.directories.build,
|
|
4780
4787
|
appDir,
|
|
@@ -4811,26 +4818,22 @@ async function startServer(options = {}) {
|
|
|
4811
4818
|
});
|
|
4812
4819
|
httpServer.listen(port, host, () => {
|
|
4813
4820
|
if (isDev) {
|
|
4814
|
-
|
|
4815
|
-
|
|
4816
|
-
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
|
|
4821
|
+
const reset = "\x1B[0m";
|
|
4822
|
+
const cyan = "\x1B[36m";
|
|
4823
|
+
const green = "\x1B[32m";
|
|
4824
|
+
const dim = "\x1B[2m";
|
|
4825
|
+
const bold = "\x1B[1m";
|
|
4826
|
+
const url = `http://${host === "0.0.0.0" ? "localhost" : host}:${port}`;
|
|
4827
|
+
console.log();
|
|
4828
|
+
console.log(`${bold}${green}\u2713${reset} ${bold}Dev server ready${reset}`);
|
|
4829
|
+
console.log(`${dim} Local:${reset} ${cyan}${url}${reset}`);
|
|
4830
|
+
if (routes.length > 0 || apiRoutes.length > 0 || wssRoutes.length > 0) {
|
|
4831
|
+
console.log(`${dim} Routes:${reset} ${routes.length} pages, ${apiRoutes.length} API, ${wssRoutes.length} WSS`);
|
|
4832
|
+
}
|
|
4833
|
+
console.log();
|
|
4820
4834
|
} else {
|
|
4821
|
-
const
|
|
4822
|
-
|
|
4823
|
-
url: `http://${host}:${port}`,
|
|
4824
|
-
appDir,
|
|
4825
|
-
buildDir
|
|
4826
|
-
});
|
|
4827
|
-
logger3.info("\u{1F9ED} Reading compiled routes from", { appDir });
|
|
4828
|
-
logger3.info("\u{1F4E6} Client served from", {
|
|
4829
|
-
path: `/static (${buildDir}/client)`
|
|
4830
|
-
});
|
|
4831
|
-
logger3.info("\u{1F4C4} SSG served from", {
|
|
4832
|
-
path: `${buildDir}/ssg (if exists)`
|
|
4833
|
-
});
|
|
4835
|
+
const url = `http://${host}:${port}`;
|
|
4836
|
+
console.log(`\u{1F680} Server running on ${url}`);
|
|
4834
4837
|
}
|
|
4835
4838
|
});
|
|
4836
4839
|
}
|
|
@@ -4884,7 +4887,7 @@ function pathToOutDir(baseDir, urlPath) {
|
|
|
4884
4887
|
}
|
|
4885
4888
|
|
|
4886
4889
|
// modules/build/ssg/renderer.ts
|
|
4887
|
-
import
|
|
4890
|
+
import fs17 from "fs";
|
|
4888
4891
|
import path22 from "path";
|
|
4889
4892
|
import { renderToString } from "react-dom/server";
|
|
4890
4893
|
init_globals();
|
|
@@ -4957,8 +4960,8 @@ async function renderStaticRoute(projectRoot, ssgOutDir, route, urlPath, params)
|
|
|
4957
4960
|
ensureDir(dir);
|
|
4958
4961
|
const htmlFile = path22.join(dir, "index.html");
|
|
4959
4962
|
const dataFile = path22.join(dir, "data.json");
|
|
4960
|
-
|
|
4961
|
-
|
|
4963
|
+
fs17.writeFileSync(htmlFile, html, "utf-8");
|
|
4964
|
+
fs17.writeFileSync(dataFile, JSON.stringify(initialData, null, 2), "utf-8");
|
|
4962
4965
|
}
|
|
4963
4966
|
|
|
4964
4967
|
// modules/build/ssg/builder.ts
|
|
@@ -5013,14 +5016,14 @@ async function buildStaticPages(projectRoot, routes) {
|
|
|
5013
5016
|
|
|
5014
5017
|
// modules/build/bundler/server.ts
|
|
5015
5018
|
import path24 from "path";
|
|
5016
|
-
import
|
|
5019
|
+
import fs18 from "fs";
|
|
5017
5020
|
import esbuild from "esbuild";
|
|
5018
5021
|
init_globals();
|
|
5019
5022
|
var SERVER_FILES = [INIT_FILE_NAME, CONFIG_FILE_NAME];
|
|
5020
5023
|
function collectAppSources(appDir) {
|
|
5021
5024
|
const entries = [];
|
|
5022
5025
|
function walk(dir) {
|
|
5023
|
-
const items =
|
|
5026
|
+
const items = fs18.readdirSync(dir, { withFileTypes: true });
|
|
5024
5027
|
for (const item of items) {
|
|
5025
5028
|
const full = path24.join(dir, item.name);
|
|
5026
5029
|
if (item.isDirectory()) {
|
|
@@ -5063,7 +5066,7 @@ async function buildServerApp(projectRoot, appDir) {
|
|
|
5063
5066
|
for (const fileName of SERVER_FILES) {
|
|
5064
5067
|
const initTS = path24.join(projectRoot, `${fileName}.ts`);
|
|
5065
5068
|
const initJS = path24.join(outDir, `${fileName}.js`);
|
|
5066
|
-
if (
|
|
5069
|
+
if (fs18.existsSync(initTS)) {
|
|
5067
5070
|
await esbuild.build({
|
|
5068
5071
|
entryPoints: [initTS],
|
|
5069
5072
|
outfile: initJS,
|
|
@@ -5806,7 +5809,7 @@ async function loadInitialRoute(initialUrl, initialData, routes, notFoundRoute,
|
|
|
5806
5809
|
};
|
|
5807
5810
|
}
|
|
5808
5811
|
function setupHotReload2() {
|
|
5809
|
-
const nodeEnv = typeof process !== "undefined" && process
|
|
5812
|
+
const nodeEnv = typeof process !== "undefined" && process.env?.NODE_ENV || "production";
|
|
5810
5813
|
const isDev = nodeEnv !== "production";
|
|
5811
5814
|
if (!isDev) {
|
|
5812
5815
|
return;
|