@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 CHANGED
@@ -1113,6 +1113,7 @@ var import_core2 = require("@rspack/core");
1113
1113
 
1114
1114
  // modules/build/config/client.ts
1115
1115
  var import_path13 = __toESM(require("path"));
1116
+ var import_fs11 = __toESM(require("fs"));
1116
1117
  var import_core = require("@rspack/core");
1117
1118
 
1118
1119
  // modules/build/utils/index.ts
@@ -1256,15 +1257,21 @@ function createClientConfig(projectRoot, mode) {
1256
1257
  const buildDir = import_path13.default.join(projectRoot, BUILD_FOLDER_NAME);
1257
1258
  const clientEntry = import_path13.default.join(buildDir, "boostrap.ts");
1258
1259
  const outDir = import_path13.default.join(buildDir, "client");
1259
- import_dotenv.default.config({
1260
- path: projectRoot
1261
- });
1260
+ const envPath2 = import_path13.default.join(projectRoot, ".env");
1261
+ if (import_fs11.default.existsSync(envPath2)) {
1262
+ import_dotenv.default.config({
1263
+ path: envPath2
1264
+ });
1265
+ }
1262
1266
  const publicEnv = {};
1263
1267
  for (const [key, value] of Object.entries(process.env)) {
1264
1268
  if (key.startsWith("PUBLIC_")) {
1265
1269
  publicEnv[`process.env.${key}`] = JSON.stringify(value ?? "");
1266
1270
  }
1267
1271
  }
1272
+ if (!publicEnv["process.env.PUBLIC_WS_BASE_URL"]) {
1273
+ publicEnv["process.env.PUBLIC_WS_BASE_URL"] = JSON.stringify(void 0);
1274
+ }
1268
1275
  const config = {
1269
1276
  mode,
1270
1277
  entry: {
@@ -1313,7 +1320,8 @@ function createClientConfig(projectRoot, mode) {
1313
1320
  },
1314
1321
  plugins: [
1315
1322
  new import_core.rspack.DefinePlugin({
1316
- "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
1323
+ // Always define NODE_ENV, using mode as fallback if not set
1324
+ "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || mode),
1317
1325
  ...publicEnv
1318
1326
  }),
1319
1327
  new import_core.rspack.CssExtractRspackPlugin({
@@ -1330,7 +1338,7 @@ function createClientConfig(projectRoot, mode) {
1330
1338
 
1331
1339
  // modules/build/bundler/client.ts
1332
1340
  var import_path14 = __toESM(require("path"));
1333
- var import_fs11 = __toESM(require("fs"));
1341
+ var import_fs12 = __toESM(require("fs"));
1334
1342
  init_globals();
1335
1343
  function startClientBundler(projectRoot, mode = "development") {
1336
1344
  const { config, outDir } = createClientConfig(projectRoot, mode);
@@ -1422,7 +1430,7 @@ function buildClientBundle(projectRoot) {
1422
1430
  copyStaticAssets(projectRoot, outDir);
1423
1431
  const assetManifest = generateAssetManifest(outDir);
1424
1432
  const manifestPath = import_path14.default.join(projectRoot, BUILD_FOLDER_NAME, "asset-manifest.json");
1425
- import_fs11.default.writeFileSync(manifestPath, JSON.stringify(assetManifest, null, 2), "utf-8");
1433
+ import_fs12.default.writeFileSync(manifestPath, JSON.stringify(assetManifest, null, 2), "utf-8");
1426
1434
  resolve3({ outDir });
1427
1435
  });
1428
1436
  });
@@ -1465,7 +1473,7 @@ function pathToOutDir(baseDir, urlPath) {
1465
1473
  }
1466
1474
 
1467
1475
  // modules/build/ssg/renderer.ts
1468
- var import_fs12 = __toESM(require("fs"));
1476
+ var import_fs13 = __toESM(require("fs"));
1469
1477
  var import_path16 = __toESM(require("path"));
1470
1478
  var import_server = require("react-dom/server");
1471
1479
 
@@ -1688,8 +1696,8 @@ async function renderStaticRoute(projectRoot, ssgOutDir, route, urlPath, params)
1688
1696
  ensureDir(dir);
1689
1697
  const htmlFile = import_path16.default.join(dir, "index.html");
1690
1698
  const dataFile = import_path16.default.join(dir, "data.json");
1691
- import_fs12.default.writeFileSync(htmlFile, html, "utf-8");
1692
- import_fs12.default.writeFileSync(dataFile, JSON.stringify(initialData, null, 2), "utf-8");
1699
+ import_fs13.default.writeFileSync(htmlFile, html, "utf-8");
1700
+ import_fs13.default.writeFileSync(dataFile, JSON.stringify(initialData, null, 2), "utf-8");
1693
1701
  }
1694
1702
 
1695
1703
  // modules/build/ssg/builder.ts
@@ -1744,11 +1752,11 @@ async function buildStaticPages(projectRoot, routes) {
1744
1752
 
1745
1753
  // modules/build/bundler/server.ts
1746
1754
  var import_path21 = __toESM(require("path"));
1747
- var import_fs14 = __toESM(require("fs"));
1755
+ var import_fs15 = __toESM(require("fs"));
1748
1756
  var import_esbuild = __toESM(require("esbuild"));
1749
1757
 
1750
1758
  // modules/server/utils/server-dir.ts
1751
- var import_fs13 = __toESM(require("fs"));
1759
+ var import_fs14 = __toESM(require("fs"));
1752
1760
  var import_path20 = __toESM(require("path"));
1753
1761
  init_globals();
1754
1762
  var getServerFile = async (projectRoot, fileName) => {
@@ -1757,13 +1765,13 @@ var getServerFile = async (projectRoot, fileName) => {
1757
1765
  const isDev = process.env.NODE_ENV === "development";
1758
1766
  let mod = null;
1759
1767
  if (isDev) {
1760
- if (!import_fs13.default.existsSync(fileTS)) {
1768
+ if (!import_fs14.default.existsSync(fileTS)) {
1761
1769
  return null;
1762
1770
  }
1763
1771
  require("tsx/cjs");
1764
1772
  mod = require(fileTS);
1765
1773
  } else {
1766
- if (!import_fs13.default.existsSync(fileJS)) {
1774
+ if (!import_fs14.default.existsSync(fileJS)) {
1767
1775
  return null;
1768
1776
  }
1769
1777
  mod = require(fileJS);
@@ -1856,7 +1864,7 @@ var SERVER_FILES = [INIT_FILE_NAME, CONFIG_FILE_NAME];
1856
1864
  function collectAppSources(appDir) {
1857
1865
  const entries = [];
1858
1866
  function walk(dir) {
1859
- const items = import_fs14.default.readdirSync(dir, { withFileTypes: true });
1867
+ const items = import_fs15.default.readdirSync(dir, { withFileTypes: true });
1860
1868
  for (const item of items) {
1861
1869
  const full = import_path21.default.join(dir, item.name);
1862
1870
  if (item.isDirectory()) {
@@ -1899,7 +1907,7 @@ async function buildServerApp(projectRoot, appDir) {
1899
1907
  for (const fileName of SERVER_FILES) {
1900
1908
  const initTS = import_path21.default.join(projectRoot, `${fileName}.ts`);
1901
1909
  const initJS = import_path21.default.join(outDir, `${fileName}.js`);
1902
- if (import_fs14.default.existsSync(initTS)) {
1910
+ if (import_fs15.default.existsSync(initTS)) {
1903
1911
  await import_esbuild.default.build({
1904
1912
  entryPoints: [initTS],
1905
1913
  outfile: initJS,
@@ -1922,7 +1930,7 @@ init_globals();
1922
1930
 
1923
1931
  // src/config.ts
1924
1932
  var import_path22 = __toESM(require("path"));
1925
- var import_fs15 = __toESM(require("fs"));
1933
+ var import_fs16 = __toESM(require("fs"));
1926
1934
  init_globals();
1927
1935
  var DEFAULT_CONFIG2 = {
1928
1936
  directories: {
@@ -1985,10 +1993,10 @@ function loadConfig(projectRoot) {
1985
1993
  ];
1986
1994
  let userConfig = {};
1987
1995
  for (const configFile of configFiles) {
1988
- if (import_fs15.default.existsSync(configFile)) {
1996
+ if (import_fs16.default.existsSync(configFile)) {
1989
1997
  try {
1990
1998
  if (configFile.endsWith(".json")) {
1991
- const content = import_fs15.default.readFileSync(configFile, "utf-8");
1999
+ const content = import_fs16.default.readFileSync(configFile, "utf-8");
1992
2000
  userConfig = JSON.parse(content);
1993
2001
  } else {
1994
2002
  if (process.env.NODE_ENV === "development") {
@@ -2005,7 +2013,7 @@ function loadConfig(projectRoot) {
2005
2013
  }
2006
2014
  const config = deepMerge(DEFAULT_CONFIG2, userConfig);
2007
2015
  const appDir = import_path22.default.join(projectRoot, config.directories.app);
2008
- if (!import_fs15.default.existsSync(appDir) && process.env.NODE_ENV !== "test") {
2016
+ if (!import_fs16.default.existsSync(appDir) && process.env.NODE_ENV !== "test") {
2009
2017
  console.warn(`[framework] App directory not found: ${appDir}`);
2010
2018
  }
2011
2019
  return config;
@@ -2066,7 +2074,7 @@ async function buildApp(options = {}) {
2066
2074
  }
2067
2075
 
2068
2076
  // src/server.ts
2069
- var import_fs19 = __toESM(require("fs"));
2077
+ var import_fs20 = __toESM(require("fs"));
2070
2078
  var import_path28 = __toESM(require("path"));
2071
2079
 
2072
2080
  // modules/server/setup.ts
@@ -2074,7 +2082,7 @@ var import_express = __toESM(require("express"));
2074
2082
  var import_path25 = __toESM(require("path"));
2075
2083
 
2076
2084
  // ../../node_modules/.pnpm/chokidar@4.0.3/node_modules/chokidar/esm/index.js
2077
- var import_fs17 = require("fs");
2085
+ var import_fs18 = require("fs");
2078
2086
  var import_promises3 = require("fs/promises");
2079
2087
  var import_events = require("events");
2080
2088
  var sysPath2 = __toESM(require("path"), 1);
@@ -2299,7 +2307,7 @@ function readdirp(root, options = {}) {
2299
2307
  }
2300
2308
 
2301
2309
  // ../../node_modules/.pnpm/chokidar@4.0.3/node_modules/chokidar/esm/handler.js
2302
- var import_fs16 = require("fs");
2310
+ var import_fs17 = require("fs");
2303
2311
  var import_promises2 = require("fs/promises");
2304
2312
  var sysPath = __toESM(require("path"), 1);
2305
2313
  var import_os = require("os");
@@ -2637,7 +2645,7 @@ function createFsWatchInstance(path26, options, listener, errHandler, emitRaw) {
2637
2645
  }
2638
2646
  };
2639
2647
  try {
2640
- return (0, import_fs16.watch)(path26, {
2648
+ return (0, import_fs17.watch)(path26, {
2641
2649
  persistent: options.persistent
2642
2650
  }, handleEvent);
2643
2651
  } catch (error) {
@@ -2720,7 +2728,7 @@ var setFsWatchFileListener = (path26, fullPath, options, handlers) => {
2720
2728
  let cont = FsWatchFileInstances.get(fullPath);
2721
2729
  const copts = cont && cont.options;
2722
2730
  if (copts && (copts.persistent < options.persistent || copts.interval > options.interval)) {
2723
- (0, import_fs16.unwatchFile)(fullPath);
2731
+ (0, import_fs17.unwatchFile)(fullPath);
2724
2732
  cont = void 0;
2725
2733
  }
2726
2734
  if (cont) {
@@ -2731,7 +2739,7 @@ var setFsWatchFileListener = (path26, fullPath, options, handlers) => {
2731
2739
  listeners: listener,
2732
2740
  rawEmitters: rawEmitter,
2733
2741
  options,
2734
- watcher: (0, import_fs16.watchFile)(fullPath, options, (curr, prev) => {
2742
+ watcher: (0, import_fs17.watchFile)(fullPath, options, (curr, prev) => {
2735
2743
  foreach(cont.rawEmitters, (rawEmitter2) => {
2736
2744
  rawEmitter2(EV.CHANGE, fullPath, { curr, prev });
2737
2745
  });
@@ -2748,7 +2756,7 @@ var setFsWatchFileListener = (path26, fullPath, options, handlers) => {
2748
2756
  delFromSet(cont, KEY_RAW, rawEmitter);
2749
2757
  if (isEmptySet(cont.listeners)) {
2750
2758
  FsWatchFileInstances.delete(fullPath);
2751
- (0, import_fs16.unwatchFile)(fullPath);
2759
+ (0, import_fs17.unwatchFile)(fullPath);
2752
2760
  cont.options = cont.watcher = void 0;
2753
2761
  Object.freeze(cont);
2754
2762
  }
@@ -3591,7 +3599,7 @@ var FSWatcher = class extends import_events.EventEmitter {
3591
3599
  const now = /* @__PURE__ */ new Date();
3592
3600
  const writes = this._pendingWrites;
3593
3601
  function awaitWriteFinishFn(prevStat) {
3594
- (0, import_fs17.stat)(fullPath, (err, curStat) => {
3602
+ (0, import_fs18.stat)(fullPath, (err, curStat) => {
3595
3603
  if (err || !writes.has(path26)) {
3596
3604
  if (err && err.code !== "ENOENT")
3597
3605
  awfEmit(err);
@@ -4205,7 +4213,6 @@ function requestLoggerMiddleware(options = {}) {
4205
4213
  const startTime = Date.now();
4206
4214
  res.on("finish", () => {
4207
4215
  const duration = Date.now() - startTime;
4208
- const shouldLogSuccess = logRequests === true;
4209
4216
  if (res.statusCode >= 500) {
4210
4217
  reqLogger.error(`${req.method} ${req.path} ${res.statusCode}`, {
4211
4218
  statusCode: res.statusCode,
@@ -4216,11 +4223,6 @@ function requestLoggerMiddleware(options = {}) {
4216
4223
  statusCode: res.statusCode,
4217
4224
  duration: `${duration}ms`
4218
4225
  });
4219
- } else if (shouldLogSuccess) {
4220
- reqLogger.debug(`${req.method} ${req.path} ${res.statusCode}`, {
4221
- statusCode: res.statusCode,
4222
- duration: `${duration}ms`
4223
- });
4224
4226
  }
4225
4227
  });
4226
4228
  }
@@ -4374,7 +4376,7 @@ function handleNotFound(res, urlPath) {
4374
4376
  }
4375
4377
 
4376
4378
  // modules/server/handlers/ssg.ts
4377
- var import_fs18 = __toESM(require("fs"));
4379
+ var import_fs19 = __toESM(require("fs"));
4378
4380
  var import_path26 = __toESM(require("path"));
4379
4381
  var logger2 = createModuleLogger("ssg");
4380
4382
  function getSsgDirForPath(baseDir, urlPath) {
@@ -4391,7 +4393,7 @@ function getSsgDataPath(baseDir, urlPath) {
4391
4393
  }
4392
4394
  function tryServeSsgHtml(res, ssgOutDir, urlPath) {
4393
4395
  const ssgHtmlPath = getSsgHtmlPath(ssgOutDir, urlPath);
4394
- if (!import_fs18.default.existsSync(ssgHtmlPath)) {
4396
+ if (!import_fs19.default.existsSync(ssgHtmlPath)) {
4395
4397
  return false;
4396
4398
  }
4397
4399
  logger2.info("Serving SSG HTML", { urlPath, ssgHtmlPath });
@@ -4401,17 +4403,17 @@ function tryServeSsgHtml(res, ssgOutDir, urlPath) {
4401
4403
  );
4402
4404
  res.statusCode = 200;
4403
4405
  res.setHeader("Content-Type", "text/html; charset=utf-8");
4404
- const stream = import_fs18.default.createReadStream(ssgHtmlPath, { encoding: "utf-8" });
4406
+ const stream = import_fs19.default.createReadStream(ssgHtmlPath, { encoding: "utf-8" });
4405
4407
  stream.pipe(res);
4406
4408
  return true;
4407
4409
  }
4408
4410
  function tryServeSsgData(res, ssgOutDir, urlPath) {
4409
4411
  const ssgDataPath = getSsgDataPath(ssgOutDir, urlPath);
4410
- if (!import_fs18.default.existsSync(ssgDataPath)) {
4412
+ if (!import_fs19.default.existsSync(ssgDataPath)) {
4411
4413
  return false;
4412
4414
  }
4413
4415
  try {
4414
- const raw = import_fs18.default.readFileSync(ssgDataPath, "utf-8");
4416
+ const raw = import_fs19.default.readFileSync(ssgDataPath, "utf-8");
4415
4417
  res.setHeader("Content-Type", "application/json; charset=utf-8");
4416
4418
  res.status(200).end(raw);
4417
4419
  return true;
@@ -5050,7 +5052,12 @@ var setupApplication = async ({
5050
5052
 
5051
5053
  // src/server.ts
5052
5054
  var import_dotenv2 = __toESM(require("dotenv"));
5053
- import_dotenv2.default.config();
5055
+ var envPath = import_path28.default.join(process.cwd(), ".env");
5056
+ if (import_fs20.default.existsSync(envPath)) {
5057
+ import_dotenv2.default.config({ path: envPath });
5058
+ } else {
5059
+ import_dotenv2.default.config();
5060
+ }
5054
5061
  var logger3 = createModuleLogger("server");
5055
5062
  async function startServer(options = {}) {
5056
5063
  const isDev = options.isDev ?? process.env.NODE_ENV === "development";
@@ -5059,7 +5066,7 @@ async function startServer(options = {}) {
5059
5066
  const port = options.port ?? (process.env.PORT ? parseInt(process.env.PORT, 10) : void 0) ?? config.server.port;
5060
5067
  const host = process.env.HOST ?? (!isDev ? "0.0.0.0" : void 0) ?? config.server.host;
5061
5068
  const appDir = options.appDir ?? (isDev ? getAppDir(projectRoot, config) : import_path28.default.join(getBuildDir(projectRoot, config), "server"));
5062
- if (!isDev && !import_fs19.default.existsSync(appDir)) {
5069
+ if (!isDev && !import_fs20.default.existsSync(appDir)) {
5063
5070
  logger3.error("Compiled directory not found", void 0, {
5064
5071
  buildDir: config.directories.build,
5065
5072
  appDir,
@@ -5096,26 +5103,22 @@ async function startServer(options = {}) {
5096
5103
  });
5097
5104
  httpServer.listen(port, host, () => {
5098
5105
  if (isDev) {
5099
- logger3.info("\u{1F680} Dev server running", {
5100
- url: `http://${host}:${port}`,
5101
- appDir
5102
- });
5103
- logger3.info("\u{1F9ED} Reading routes from", { appDir });
5104
- logger3.info("\u{1F4E6} Client served from /static/client.js");
5106
+ const reset = "\x1B[0m";
5107
+ const cyan = "\x1B[36m";
5108
+ const green = "\x1B[32m";
5109
+ const dim = "\x1B[2m";
5110
+ const bold = "\x1B[1m";
5111
+ const url = `http://${host === "0.0.0.0" ? "localhost" : host}:${port}`;
5112
+ console.log();
5113
+ console.log(`${bold}${green}\u2713${reset} ${bold}Dev server ready${reset}`);
5114
+ console.log(`${dim} Local:${reset} ${cyan}${url}${reset}`);
5115
+ if (routes.length > 0 || apiRoutes.length > 0 || wssRoutes.length > 0) {
5116
+ console.log(`${dim} Routes:${reset} ${routes.length} pages, ${apiRoutes.length} API, ${wssRoutes.length} WSS`);
5117
+ }
5118
+ console.log();
5105
5119
  } else {
5106
- const buildDir = config.directories.build;
5107
- logger3.info("\u{1F680} Prod server running", {
5108
- url: `http://${host}:${port}`,
5109
- appDir,
5110
- buildDir
5111
- });
5112
- logger3.info("\u{1F9ED} Reading compiled routes from", { appDir });
5113
- logger3.info("\u{1F4E6} Client served from", {
5114
- path: `/static (${buildDir}/client)`
5115
- });
5116
- logger3.info("\u{1F4C4} SSG served from", {
5117
- path: `${buildDir}/ssg (if exists)`
5118
- });
5120
+ const url = `http://${host}:${port}`;
5121
+ console.log(`\u{1F680} Server running on ${url}`);
5119
5122
  }
5120
5123
  });
5121
5124
  }