@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.cjs
CHANGED
|
@@ -115,7 +115,7 @@ __export(src_exports, {
|
|
|
115
115
|
module.exports = __toCommonJS(src_exports);
|
|
116
116
|
|
|
117
117
|
// src/server.ts
|
|
118
|
-
var
|
|
118
|
+
var import_fs18 = __toESM(require("fs"));
|
|
119
119
|
var import_path22 = __toESM(require("path"));
|
|
120
120
|
|
|
121
121
|
// modules/server/utils/server-dir.ts
|
|
@@ -1190,6 +1190,7 @@ var import_core2 = require("@rspack/core");
|
|
|
1190
1190
|
|
|
1191
1191
|
// modules/build/config/client.ts
|
|
1192
1192
|
var import_path14 = __toESM(require("path"));
|
|
1193
|
+
var import_fs12 = __toESM(require("fs"));
|
|
1193
1194
|
var import_core = require("@rspack/core");
|
|
1194
1195
|
|
|
1195
1196
|
// modules/build/utils/index.ts
|
|
@@ -1333,15 +1334,21 @@ function createClientConfig(projectRoot, mode) {
|
|
|
1333
1334
|
const buildDir = import_path14.default.join(projectRoot, BUILD_FOLDER_NAME);
|
|
1334
1335
|
const clientEntry = import_path14.default.join(buildDir, "boostrap.ts");
|
|
1335
1336
|
const outDir = import_path14.default.join(buildDir, "client");
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1337
|
+
const envPath2 = import_path14.default.join(projectRoot, ".env");
|
|
1338
|
+
if (import_fs12.default.existsSync(envPath2)) {
|
|
1339
|
+
import_dotenv.default.config({
|
|
1340
|
+
path: envPath2
|
|
1341
|
+
});
|
|
1342
|
+
}
|
|
1339
1343
|
const publicEnv = {};
|
|
1340
1344
|
for (const [key, value] of Object.entries(process.env)) {
|
|
1341
1345
|
if (key.startsWith("PUBLIC_")) {
|
|
1342
1346
|
publicEnv[`process.env.${key}`] = JSON.stringify(value ?? "");
|
|
1343
1347
|
}
|
|
1344
1348
|
}
|
|
1349
|
+
if (!publicEnv["process.env.PUBLIC_WS_BASE_URL"]) {
|
|
1350
|
+
publicEnv["process.env.PUBLIC_WS_BASE_URL"] = JSON.stringify(void 0);
|
|
1351
|
+
}
|
|
1345
1352
|
const config = {
|
|
1346
1353
|
mode,
|
|
1347
1354
|
entry: {
|
|
@@ -1390,7 +1397,8 @@ function createClientConfig(projectRoot, mode) {
|
|
|
1390
1397
|
},
|
|
1391
1398
|
plugins: [
|
|
1392
1399
|
new import_core.rspack.DefinePlugin({
|
|
1393
|
-
|
|
1400
|
+
// Always define NODE_ENV, using mode as fallback if not set
|
|
1401
|
+
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || mode),
|
|
1394
1402
|
...publicEnv
|
|
1395
1403
|
}),
|
|
1396
1404
|
new import_core.rspack.CssExtractRspackPlugin({
|
|
@@ -1407,7 +1415,7 @@ function createClientConfig(projectRoot, mode) {
|
|
|
1407
1415
|
|
|
1408
1416
|
// modules/build/bundler/client.ts
|
|
1409
1417
|
var import_path15 = __toESM(require("path"));
|
|
1410
|
-
var
|
|
1418
|
+
var import_fs13 = __toESM(require("fs"));
|
|
1411
1419
|
init_globals();
|
|
1412
1420
|
function startClientBundler(projectRoot, mode = "development") {
|
|
1413
1421
|
const { config, outDir } = createClientConfig(projectRoot, mode);
|
|
@@ -1499,14 +1507,14 @@ function buildClientBundle(projectRoot) {
|
|
|
1499
1507
|
copyStaticAssets(projectRoot, outDir);
|
|
1500
1508
|
const assetManifest = generateAssetManifest(outDir);
|
|
1501
1509
|
const manifestPath = import_path15.default.join(projectRoot, BUILD_FOLDER_NAME, "asset-manifest.json");
|
|
1502
|
-
|
|
1510
|
+
import_fs13.default.writeFileSync(manifestPath, JSON.stringify(assetManifest, null, 2), "utf-8");
|
|
1503
1511
|
resolve3({ outDir });
|
|
1504
1512
|
});
|
|
1505
1513
|
});
|
|
1506
1514
|
}
|
|
1507
1515
|
|
|
1508
1516
|
// ../../node_modules/.pnpm/chokidar@4.0.3/node_modules/chokidar/esm/index.js
|
|
1509
|
-
var
|
|
1517
|
+
var import_fs15 = require("fs");
|
|
1510
1518
|
var import_promises3 = require("fs/promises");
|
|
1511
1519
|
var import_events = require("events");
|
|
1512
1520
|
var sysPath2 = __toESM(require("path"), 1);
|
|
@@ -1731,7 +1739,7 @@ function readdirp(root, options = {}) {
|
|
|
1731
1739
|
}
|
|
1732
1740
|
|
|
1733
1741
|
// ../../node_modules/.pnpm/chokidar@4.0.3/node_modules/chokidar/esm/handler.js
|
|
1734
|
-
var
|
|
1742
|
+
var import_fs14 = require("fs");
|
|
1735
1743
|
var import_promises2 = require("fs/promises");
|
|
1736
1744
|
var sysPath = __toESM(require("path"), 1);
|
|
1737
1745
|
var import_os = require("os");
|
|
@@ -2069,7 +2077,7 @@ function createFsWatchInstance(path25, options, listener, errHandler, emitRaw) {
|
|
|
2069
2077
|
}
|
|
2070
2078
|
};
|
|
2071
2079
|
try {
|
|
2072
|
-
return (0,
|
|
2080
|
+
return (0, import_fs14.watch)(path25, {
|
|
2073
2081
|
persistent: options.persistent
|
|
2074
2082
|
}, handleEvent);
|
|
2075
2083
|
} catch (error) {
|
|
@@ -2152,7 +2160,7 @@ var setFsWatchFileListener = (path25, fullPath, options, handlers) => {
|
|
|
2152
2160
|
let cont = FsWatchFileInstances.get(fullPath);
|
|
2153
2161
|
const copts = cont && cont.options;
|
|
2154
2162
|
if (copts && (copts.persistent < options.persistent || copts.interval > options.interval)) {
|
|
2155
|
-
(0,
|
|
2163
|
+
(0, import_fs14.unwatchFile)(fullPath);
|
|
2156
2164
|
cont = void 0;
|
|
2157
2165
|
}
|
|
2158
2166
|
if (cont) {
|
|
@@ -2163,7 +2171,7 @@ var setFsWatchFileListener = (path25, fullPath, options, handlers) => {
|
|
|
2163
2171
|
listeners: listener,
|
|
2164
2172
|
rawEmitters: rawEmitter,
|
|
2165
2173
|
options,
|
|
2166
|
-
watcher: (0,
|
|
2174
|
+
watcher: (0, import_fs14.watchFile)(fullPath, options, (curr, prev) => {
|
|
2167
2175
|
foreach(cont.rawEmitters, (rawEmitter2) => {
|
|
2168
2176
|
rawEmitter2(EV.CHANGE, fullPath, { curr, prev });
|
|
2169
2177
|
});
|
|
@@ -2180,7 +2188,7 @@ var setFsWatchFileListener = (path25, fullPath, options, handlers) => {
|
|
|
2180
2188
|
delFromSet(cont, KEY_RAW, rawEmitter);
|
|
2181
2189
|
if (isEmptySet(cont.listeners)) {
|
|
2182
2190
|
FsWatchFileInstances.delete(fullPath);
|
|
2183
|
-
(0,
|
|
2191
|
+
(0, import_fs14.unwatchFile)(fullPath);
|
|
2184
2192
|
cont.options = cont.watcher = void 0;
|
|
2185
2193
|
Object.freeze(cont);
|
|
2186
2194
|
}
|
|
@@ -3023,7 +3031,7 @@ var FSWatcher = class extends import_events.EventEmitter {
|
|
|
3023
3031
|
const now = /* @__PURE__ */ new Date();
|
|
3024
3032
|
const writes = this._pendingWrites;
|
|
3025
3033
|
function awaitWriteFinishFn(prevStat) {
|
|
3026
|
-
(0,
|
|
3034
|
+
(0, import_fs15.stat)(fullPath, (err, curStat) => {
|
|
3027
3035
|
if (err || !writes.has(path25)) {
|
|
3028
3036
|
if (err && err.code !== "ENOENT")
|
|
3029
3037
|
awfEmit(err);
|
|
@@ -3270,7 +3278,7 @@ init_globals();
|
|
|
3270
3278
|
|
|
3271
3279
|
// src/config.ts
|
|
3272
3280
|
var import_path18 = __toESM(require("path"));
|
|
3273
|
-
var
|
|
3281
|
+
var import_fs16 = __toESM(require("fs"));
|
|
3274
3282
|
init_globals();
|
|
3275
3283
|
var DEFAULT_CONFIG = {
|
|
3276
3284
|
directories: {
|
|
@@ -3333,10 +3341,10 @@ function loadConfig(projectRoot) {
|
|
|
3333
3341
|
];
|
|
3334
3342
|
let userConfig = {};
|
|
3335
3343
|
for (const configFile of configFiles) {
|
|
3336
|
-
if (
|
|
3344
|
+
if (import_fs16.default.existsSync(configFile)) {
|
|
3337
3345
|
try {
|
|
3338
3346
|
if (configFile.endsWith(".json")) {
|
|
3339
|
-
const content =
|
|
3347
|
+
const content = import_fs16.default.readFileSync(configFile, "utf-8");
|
|
3340
3348
|
userConfig = JSON.parse(content);
|
|
3341
3349
|
} else {
|
|
3342
3350
|
if (process.env.NODE_ENV === "development") {
|
|
@@ -3353,7 +3361,7 @@ function loadConfig(projectRoot) {
|
|
|
3353
3361
|
}
|
|
3354
3362
|
const config = deepMerge(DEFAULT_CONFIG, userConfig);
|
|
3355
3363
|
const appDir = import_path18.default.join(projectRoot, config.directories.app);
|
|
3356
|
-
if (!
|
|
3364
|
+
if (!import_fs16.default.existsSync(appDir) && process.env.NODE_ENV !== "test") {
|
|
3357
3365
|
console.warn(`[framework] App directory not found: ${appDir}`);
|
|
3358
3366
|
}
|
|
3359
3367
|
return config;
|
|
@@ -3745,7 +3753,6 @@ function requestLoggerMiddleware(options = {}) {
|
|
|
3745
3753
|
const startTime = Date.now();
|
|
3746
3754
|
res.on("finish", () => {
|
|
3747
3755
|
const duration = Date.now() - startTime;
|
|
3748
|
-
const shouldLogSuccess = logRequests === true;
|
|
3749
3756
|
if (res.statusCode >= 500) {
|
|
3750
3757
|
reqLogger.error(`${req.method} ${req.path} ${res.statusCode}`, {
|
|
3751
3758
|
statusCode: res.statusCode,
|
|
@@ -3756,11 +3763,6 @@ function requestLoggerMiddleware(options = {}) {
|
|
|
3756
3763
|
statusCode: res.statusCode,
|
|
3757
3764
|
duration: `${duration}ms`
|
|
3758
3765
|
});
|
|
3759
|
-
} else if (shouldLogSuccess) {
|
|
3760
|
-
reqLogger.debug(`${req.method} ${req.path} ${res.statusCode}`, {
|
|
3761
|
-
statusCode: res.statusCode,
|
|
3762
|
-
duration: `${duration}ms`
|
|
3763
|
-
});
|
|
3764
3766
|
}
|
|
3765
3767
|
});
|
|
3766
3768
|
}
|
|
@@ -4062,7 +4064,7 @@ function handleNotFound(res, urlPath) {
|
|
|
4062
4064
|
}
|
|
4063
4065
|
|
|
4064
4066
|
// modules/server/handlers/ssg.ts
|
|
4065
|
-
var
|
|
4067
|
+
var import_fs17 = __toESM(require("fs"));
|
|
4066
4068
|
var import_path20 = __toESM(require("path"));
|
|
4067
4069
|
var logger2 = createModuleLogger("ssg");
|
|
4068
4070
|
function getSsgDirForPath(baseDir, urlPath) {
|
|
@@ -4079,7 +4081,7 @@ function getSsgDataPath(baseDir, urlPath) {
|
|
|
4079
4081
|
}
|
|
4080
4082
|
function tryServeSsgHtml(res, ssgOutDir, urlPath) {
|
|
4081
4083
|
const ssgHtmlPath = getSsgHtmlPath(ssgOutDir, urlPath);
|
|
4082
|
-
if (!
|
|
4084
|
+
if (!import_fs17.default.existsSync(ssgHtmlPath)) {
|
|
4083
4085
|
return false;
|
|
4084
4086
|
}
|
|
4085
4087
|
logger2.info("Serving SSG HTML", { urlPath, ssgHtmlPath });
|
|
@@ -4089,17 +4091,17 @@ function tryServeSsgHtml(res, ssgOutDir, urlPath) {
|
|
|
4089
4091
|
);
|
|
4090
4092
|
res.statusCode = 200;
|
|
4091
4093
|
res.setHeader("Content-Type", "text/html; charset=utf-8");
|
|
4092
|
-
const stream =
|
|
4094
|
+
const stream = import_fs17.default.createReadStream(ssgHtmlPath, { encoding: "utf-8" });
|
|
4093
4095
|
stream.pipe(res);
|
|
4094
4096
|
return true;
|
|
4095
4097
|
}
|
|
4096
4098
|
function tryServeSsgData(res, ssgOutDir, urlPath) {
|
|
4097
4099
|
const ssgDataPath = getSsgDataPath(ssgOutDir, urlPath);
|
|
4098
|
-
if (!
|
|
4100
|
+
if (!import_fs17.default.existsSync(ssgDataPath)) {
|
|
4099
4101
|
return false;
|
|
4100
4102
|
}
|
|
4101
4103
|
try {
|
|
4102
|
-
const raw =
|
|
4104
|
+
const raw = import_fs17.default.readFileSync(ssgDataPath, "utf-8");
|
|
4103
4105
|
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
4104
4106
|
res.status(200).end(raw);
|
|
4105
4107
|
return true;
|
|
@@ -4807,7 +4809,12 @@ var setupApplication = async ({
|
|
|
4807
4809
|
|
|
4808
4810
|
// src/server.ts
|
|
4809
4811
|
var import_dotenv2 = __toESM(require("dotenv"));
|
|
4810
|
-
|
|
4812
|
+
var envPath = import_path22.default.join(process.cwd(), ".env");
|
|
4813
|
+
if (import_fs18.default.existsSync(envPath)) {
|
|
4814
|
+
import_dotenv2.default.config({ path: envPath });
|
|
4815
|
+
} else {
|
|
4816
|
+
import_dotenv2.default.config();
|
|
4817
|
+
}
|
|
4811
4818
|
var logger3 = createModuleLogger("server");
|
|
4812
4819
|
async function startServer(options = {}) {
|
|
4813
4820
|
const isDev = options.isDev ?? process.env.NODE_ENV === "development";
|
|
@@ -4816,7 +4823,7 @@ async function startServer(options = {}) {
|
|
|
4816
4823
|
const port = options.port ?? (process.env.PORT ? parseInt(process.env.PORT, 10) : void 0) ?? config.server.port;
|
|
4817
4824
|
const host = process.env.HOST ?? (!isDev ? "0.0.0.0" : void 0) ?? config.server.host;
|
|
4818
4825
|
const appDir = options.appDir ?? (isDev ? getAppDir(projectRoot, config) : import_path22.default.join(getBuildDir(projectRoot, config), "server"));
|
|
4819
|
-
if (!isDev && !
|
|
4826
|
+
if (!isDev && !import_fs18.default.existsSync(appDir)) {
|
|
4820
4827
|
logger3.error("Compiled directory not found", void 0, {
|
|
4821
4828
|
buildDir: config.directories.build,
|
|
4822
4829
|
appDir,
|
|
@@ -4853,26 +4860,22 @@ async function startServer(options = {}) {
|
|
|
4853
4860
|
});
|
|
4854
4861
|
httpServer.listen(port, host, () => {
|
|
4855
4862
|
if (isDev) {
|
|
4856
|
-
|
|
4857
|
-
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
|
|
4863
|
+
const reset = "\x1B[0m";
|
|
4864
|
+
const cyan = "\x1B[36m";
|
|
4865
|
+
const green = "\x1B[32m";
|
|
4866
|
+
const dim = "\x1B[2m";
|
|
4867
|
+
const bold = "\x1B[1m";
|
|
4868
|
+
const url = `http://${host === "0.0.0.0" ? "localhost" : host}:${port}`;
|
|
4869
|
+
console.log();
|
|
4870
|
+
console.log(`${bold}${green}\u2713${reset} ${bold}Dev server ready${reset}`);
|
|
4871
|
+
console.log(`${dim} Local:${reset} ${cyan}${url}${reset}`);
|
|
4872
|
+
if (routes.length > 0 || apiRoutes.length > 0 || wssRoutes.length > 0) {
|
|
4873
|
+
console.log(`${dim} Routes:${reset} ${routes.length} pages, ${apiRoutes.length} API, ${wssRoutes.length} WSS`);
|
|
4874
|
+
}
|
|
4875
|
+
console.log();
|
|
4862
4876
|
} else {
|
|
4863
|
-
const
|
|
4864
|
-
|
|
4865
|
-
url: `http://${host}:${port}`,
|
|
4866
|
-
appDir,
|
|
4867
|
-
buildDir
|
|
4868
|
-
});
|
|
4869
|
-
logger3.info("\u{1F9ED} Reading compiled routes from", { appDir });
|
|
4870
|
-
logger3.info("\u{1F4E6} Client served from", {
|
|
4871
|
-
path: `/static (${buildDir}/client)`
|
|
4872
|
-
});
|
|
4873
|
-
logger3.info("\u{1F4C4} SSG served from", {
|
|
4874
|
-
path: `${buildDir}/ssg (if exists)`
|
|
4875
|
-
});
|
|
4877
|
+
const url = `http://${host}:${port}`;
|
|
4878
|
+
console.log(`\u{1F680} Server running on ${url}`);
|
|
4876
4879
|
}
|
|
4877
4880
|
});
|
|
4878
4881
|
}
|
|
@@ -4926,7 +4929,7 @@ function pathToOutDir(baseDir, urlPath) {
|
|
|
4926
4929
|
}
|
|
4927
4930
|
|
|
4928
4931
|
// modules/build/ssg/renderer.ts
|
|
4929
|
-
var
|
|
4932
|
+
var import_fs19 = __toESM(require("fs"));
|
|
4930
4933
|
var import_path24 = __toESM(require("path"));
|
|
4931
4934
|
var import_server3 = require("react-dom/server");
|
|
4932
4935
|
init_globals();
|
|
@@ -4999,8 +5002,8 @@ async function renderStaticRoute(projectRoot, ssgOutDir, route, urlPath, params)
|
|
|
4999
5002
|
ensureDir(dir);
|
|
5000
5003
|
const htmlFile = import_path24.default.join(dir, "index.html");
|
|
5001
5004
|
const dataFile = import_path24.default.join(dir, "data.json");
|
|
5002
|
-
|
|
5003
|
-
|
|
5005
|
+
import_fs19.default.writeFileSync(htmlFile, html, "utf-8");
|
|
5006
|
+
import_fs19.default.writeFileSync(dataFile, JSON.stringify(initialData, null, 2), "utf-8");
|
|
5004
5007
|
}
|
|
5005
5008
|
|
|
5006
5009
|
// modules/build/ssg/builder.ts
|
|
@@ -5055,14 +5058,14 @@ async function buildStaticPages(projectRoot, routes) {
|
|
|
5055
5058
|
|
|
5056
5059
|
// modules/build/bundler/server.ts
|
|
5057
5060
|
var import_path28 = __toESM(require("path"));
|
|
5058
|
-
var
|
|
5061
|
+
var import_fs20 = __toESM(require("fs"));
|
|
5059
5062
|
var import_esbuild = __toESM(require("esbuild"));
|
|
5060
5063
|
init_globals();
|
|
5061
5064
|
var SERVER_FILES = [INIT_FILE_NAME, CONFIG_FILE_NAME];
|
|
5062
5065
|
function collectAppSources(appDir) {
|
|
5063
5066
|
const entries = [];
|
|
5064
5067
|
function walk(dir) {
|
|
5065
|
-
const items =
|
|
5068
|
+
const items = import_fs20.default.readdirSync(dir, { withFileTypes: true });
|
|
5066
5069
|
for (const item of items) {
|
|
5067
5070
|
const full = import_path28.default.join(dir, item.name);
|
|
5068
5071
|
if (item.isDirectory()) {
|
|
@@ -5105,7 +5108,7 @@ async function buildServerApp(projectRoot, appDir) {
|
|
|
5105
5108
|
for (const fileName of SERVER_FILES) {
|
|
5106
5109
|
const initTS = import_path28.default.join(projectRoot, `${fileName}.ts`);
|
|
5107
5110
|
const initJS = import_path28.default.join(outDir, `${fileName}.js`);
|
|
5108
|
-
if (
|
|
5111
|
+
if (import_fs20.default.existsSync(initTS)) {
|
|
5109
5112
|
await import_esbuild.default.build({
|
|
5110
5113
|
entryPoints: [initTS],
|
|
5111
5114
|
outfile: initJS,
|
|
@@ -5848,7 +5851,7 @@ async function loadInitialRoute(initialUrl, initialData, routes, notFoundRoute,
|
|
|
5848
5851
|
};
|
|
5849
5852
|
}
|
|
5850
5853
|
function setupHotReload2() {
|
|
5851
|
-
const nodeEnv = typeof process !== "undefined" && process
|
|
5854
|
+
const nodeEnv = typeof process !== "undefined" && process.env?.NODE_ENV || "production";
|
|
5852
5855
|
const isDev = nodeEnv !== "production";
|
|
5853
5856
|
if (!isDev) {
|
|
5854
5857
|
return;
|