@lolyjs/core 0.2.0-alpha.11 → 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/index.js CHANGED
@@ -73,7 +73,7 @@ var init_globals = __esm({
73
73
  });
74
74
 
75
75
  // src/server.ts
76
- import fs15 from "fs";
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
- dotenv.config({
1295
- path: projectRoot
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
- "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
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 fs12 from "fs";
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
- fs12.writeFileSync(manifestPath, JSON.stringify(assetManifest, null, 2), "utf-8");
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 fs13 from "fs";
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 (fs13.existsSync(configFile)) {
3302
+ if (fs14.existsSync(configFile)) {
3295
3303
  try {
3296
3304
  if (configFile.endsWith(".json")) {
3297
- const content = fs13.readFileSync(configFile, "utf-8");
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 (!fs13.existsSync(appDir) && process.env.NODE_ENV !== "test") {
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;
@@ -4020,7 +4028,7 @@ function handleNotFound(res, urlPath) {
4020
4028
  }
4021
4029
 
4022
4030
  // modules/server/handlers/ssg.ts
4023
- import fs14 from "fs";
4031
+ import fs15 from "fs";
4024
4032
  import path18 from "path";
4025
4033
  var logger2 = createModuleLogger("ssg");
4026
4034
  function getSsgDirForPath(baseDir, urlPath) {
@@ -4037,7 +4045,7 @@ function getSsgDataPath(baseDir, urlPath) {
4037
4045
  }
4038
4046
  function tryServeSsgHtml(res, ssgOutDir, urlPath) {
4039
4047
  const ssgHtmlPath = getSsgHtmlPath(ssgOutDir, urlPath);
4040
- if (!fs14.existsSync(ssgHtmlPath)) {
4048
+ if (!fs15.existsSync(ssgHtmlPath)) {
4041
4049
  return false;
4042
4050
  }
4043
4051
  logger2.info("Serving SSG HTML", { urlPath, ssgHtmlPath });
@@ -4047,17 +4055,17 @@ function tryServeSsgHtml(res, ssgOutDir, urlPath) {
4047
4055
  );
4048
4056
  res.statusCode = 200;
4049
4057
  res.setHeader("Content-Type", "text/html; charset=utf-8");
4050
- const stream = fs14.createReadStream(ssgHtmlPath, { encoding: "utf-8" });
4058
+ const stream = fs15.createReadStream(ssgHtmlPath, { encoding: "utf-8" });
4051
4059
  stream.pipe(res);
4052
4060
  return true;
4053
4061
  }
4054
4062
  function tryServeSsgData(res, ssgOutDir, urlPath) {
4055
4063
  const ssgDataPath = getSsgDataPath(ssgOutDir, urlPath);
4056
- if (!fs14.existsSync(ssgDataPath)) {
4064
+ if (!fs15.existsSync(ssgDataPath)) {
4057
4065
  return false;
4058
4066
  }
4059
4067
  try {
4060
- const raw = fs14.readFileSync(ssgDataPath, "utf-8");
4068
+ const raw = fs15.readFileSync(ssgDataPath, "utf-8");
4061
4069
  res.setHeader("Content-Type", "application/json; charset=utf-8");
4062
4070
  res.status(200).end(raw);
4063
4071
  return true;
@@ -4765,7 +4773,12 @@ var setupApplication = async ({
4765
4773
 
4766
4774
  // src/server.ts
4767
4775
  import dotenv2 from "dotenv";
4768
- dotenv2.config();
4776
+ var envPath = path20.join(process.cwd(), ".env");
4777
+ if (fs16.existsSync(envPath)) {
4778
+ dotenv2.config({ path: envPath });
4779
+ } else {
4780
+ dotenv2.config();
4781
+ }
4769
4782
  var logger3 = createModuleLogger("server");
4770
4783
  async function startServer(options = {}) {
4771
4784
  const isDev = options.isDev ?? process.env.NODE_ENV === "development";
@@ -4774,7 +4787,7 @@ async function startServer(options = {}) {
4774
4787
  const port = options.port ?? (process.env.PORT ? parseInt(process.env.PORT, 10) : void 0) ?? config.server.port;
4775
4788
  const host = process.env.HOST ?? (!isDev ? "0.0.0.0" : void 0) ?? config.server.host;
4776
4789
  const appDir = options.appDir ?? (isDev ? getAppDir(projectRoot, config) : path20.join(getBuildDir(projectRoot, config), "server"));
4777
- if (!isDev && !fs15.existsSync(appDir)) {
4790
+ if (!isDev && !fs16.existsSync(appDir)) {
4778
4791
  logger3.error("Compiled directory not found", void 0, {
4779
4792
  buildDir: config.directories.build,
4780
4793
  appDir,
@@ -4884,7 +4897,7 @@ function pathToOutDir(baseDir, urlPath) {
4884
4897
  }
4885
4898
 
4886
4899
  // modules/build/ssg/renderer.ts
4887
- import fs16 from "fs";
4900
+ import fs17 from "fs";
4888
4901
  import path22 from "path";
4889
4902
  import { renderToString } from "react-dom/server";
4890
4903
  init_globals();
@@ -4957,8 +4970,8 @@ async function renderStaticRoute(projectRoot, ssgOutDir, route, urlPath, params)
4957
4970
  ensureDir(dir);
4958
4971
  const htmlFile = path22.join(dir, "index.html");
4959
4972
  const dataFile = path22.join(dir, "data.json");
4960
- fs16.writeFileSync(htmlFile, html, "utf-8");
4961
- fs16.writeFileSync(dataFile, JSON.stringify(initialData, null, 2), "utf-8");
4973
+ fs17.writeFileSync(htmlFile, html, "utf-8");
4974
+ fs17.writeFileSync(dataFile, JSON.stringify(initialData, null, 2), "utf-8");
4962
4975
  }
4963
4976
 
4964
4977
  // modules/build/ssg/builder.ts
@@ -5013,14 +5026,14 @@ async function buildStaticPages(projectRoot, routes) {
5013
5026
 
5014
5027
  // modules/build/bundler/server.ts
5015
5028
  import path24 from "path";
5016
- import fs17 from "fs";
5029
+ import fs18 from "fs";
5017
5030
  import esbuild from "esbuild";
5018
5031
  init_globals();
5019
5032
  var SERVER_FILES = [INIT_FILE_NAME, CONFIG_FILE_NAME];
5020
5033
  function collectAppSources(appDir) {
5021
5034
  const entries = [];
5022
5035
  function walk(dir) {
5023
- const items = fs17.readdirSync(dir, { withFileTypes: true });
5036
+ const items = fs18.readdirSync(dir, { withFileTypes: true });
5024
5037
  for (const item of items) {
5025
5038
  const full = path24.join(dir, item.name);
5026
5039
  if (item.isDirectory()) {
@@ -5063,7 +5076,7 @@ async function buildServerApp(projectRoot, appDir) {
5063
5076
  for (const fileName of SERVER_FILES) {
5064
5077
  const initTS = path24.join(projectRoot, `${fileName}.ts`);
5065
5078
  const initJS = path24.join(outDir, `${fileName}.js`);
5066
- if (fs17.existsSync(initTS)) {
5079
+ if (fs18.existsSync(initTS)) {
5067
5080
  await esbuild.build({
5068
5081
  entryPoints: [initTS],
5069
5082
  outfile: initJS,
@@ -5806,7 +5819,7 @@ async function loadInitialRoute(initialUrl, initialData, routes, notFoundRoute,
5806
5819
  };
5807
5820
  }
5808
5821
  function setupHotReload2() {
5809
- const nodeEnv = typeof process !== "undefined" && process?.env?.NODE_ENV || "production";
5822
+ const nodeEnv = typeof process !== "undefined" && process.env?.NODE_ENV || "production";
5810
5823
  const isDev = nodeEnv !== "production";
5811
5824
  if (!isDev) {
5812
5825
  return;