@lolyjs/core 0.2.0-alpha.12 → 0.2.0-alpha.13
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 +47 -34
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +40 -27
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +45 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +38 -25
- package/dist/index.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/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
|
|
@@ -4369,7 +4377,7 @@ function handleNotFound(res, urlPath) {
|
|
|
4369
4377
|
}
|
|
4370
4378
|
|
|
4371
4379
|
// modules/server/handlers/ssg.ts
|
|
4372
|
-
import
|
|
4380
|
+
import fs17 from "fs";
|
|
4373
4381
|
import path22 from "path";
|
|
4374
4382
|
var logger2 = createModuleLogger("ssg");
|
|
4375
4383
|
function getSsgDirForPath(baseDir, urlPath) {
|
|
@@ -4386,7 +4394,7 @@ function getSsgDataPath(baseDir, urlPath) {
|
|
|
4386
4394
|
}
|
|
4387
4395
|
function tryServeSsgHtml(res, ssgOutDir, urlPath) {
|
|
4388
4396
|
const ssgHtmlPath = getSsgHtmlPath(ssgOutDir, urlPath);
|
|
4389
|
-
if (!
|
|
4397
|
+
if (!fs17.existsSync(ssgHtmlPath)) {
|
|
4390
4398
|
return false;
|
|
4391
4399
|
}
|
|
4392
4400
|
logger2.info("Serving SSG HTML", { urlPath, ssgHtmlPath });
|
|
@@ -4396,17 +4404,17 @@ function tryServeSsgHtml(res, ssgOutDir, urlPath) {
|
|
|
4396
4404
|
);
|
|
4397
4405
|
res.statusCode = 200;
|
|
4398
4406
|
res.setHeader("Content-Type", "text/html; charset=utf-8");
|
|
4399
|
-
const stream =
|
|
4407
|
+
const stream = fs17.createReadStream(ssgHtmlPath, { encoding: "utf-8" });
|
|
4400
4408
|
stream.pipe(res);
|
|
4401
4409
|
return true;
|
|
4402
4410
|
}
|
|
4403
4411
|
function tryServeSsgData(res, ssgOutDir, urlPath) {
|
|
4404
4412
|
const ssgDataPath = getSsgDataPath(ssgOutDir, urlPath);
|
|
4405
|
-
if (!
|
|
4413
|
+
if (!fs17.existsSync(ssgDataPath)) {
|
|
4406
4414
|
return false;
|
|
4407
4415
|
}
|
|
4408
4416
|
try {
|
|
4409
|
-
const raw =
|
|
4417
|
+
const raw = fs17.readFileSync(ssgDataPath, "utf-8");
|
|
4410
4418
|
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
4411
4419
|
res.status(200).end(raw);
|
|
4412
4420
|
return true;
|
|
@@ -5045,7 +5053,12 @@ var setupApplication = async ({
|
|
|
5045
5053
|
|
|
5046
5054
|
// src/server.ts
|
|
5047
5055
|
import dotenv2 from "dotenv";
|
|
5048
|
-
|
|
5056
|
+
var envPath = path24.join(process.cwd(), ".env");
|
|
5057
|
+
if (fs18.existsSync(envPath)) {
|
|
5058
|
+
dotenv2.config({ path: envPath });
|
|
5059
|
+
} else {
|
|
5060
|
+
dotenv2.config();
|
|
5061
|
+
}
|
|
5049
5062
|
var logger3 = createModuleLogger("server");
|
|
5050
5063
|
async function startServer(options = {}) {
|
|
5051
5064
|
const isDev = options.isDev ?? process.env.NODE_ENV === "development";
|
|
@@ -5054,7 +5067,7 @@ async function startServer(options = {}) {
|
|
|
5054
5067
|
const port = options.port ?? (process.env.PORT ? parseInt(process.env.PORT, 10) : void 0) ?? config.server.port;
|
|
5055
5068
|
const host = process.env.HOST ?? (!isDev ? "0.0.0.0" : void 0) ?? config.server.host;
|
|
5056
5069
|
const appDir = options.appDir ?? (isDev ? getAppDir(projectRoot, config) : path24.join(getBuildDir(projectRoot, config), "server"));
|
|
5057
|
-
if (!isDev && !
|
|
5070
|
+
if (!isDev && !fs18.existsSync(appDir)) {
|
|
5058
5071
|
logger3.error("Compiled directory not found", void 0, {
|
|
5059
5072
|
buildDir: config.directories.build,
|
|
5060
5073
|
appDir,
|