@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/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 import_fs17 = __toESM(require("fs"));
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
- import_dotenv.default.config({
1337
- path: projectRoot
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
- "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
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 import_fs12 = __toESM(require("fs"));
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
- import_fs12.default.writeFileSync(manifestPath, JSON.stringify(assetManifest, null, 2), "utf-8");
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 import_fs14 = require("fs");
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 import_fs13 = require("fs");
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, import_fs13.watch)(path25, {
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, import_fs13.unwatchFile)(fullPath);
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, import_fs13.watchFile)(fullPath, options, (curr, prev) => {
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, import_fs13.unwatchFile)(fullPath);
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, import_fs14.stat)(fullPath, (err, curStat) => {
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 import_fs15 = __toESM(require("fs"));
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 (import_fs15.default.existsSync(configFile)) {
3344
+ if (import_fs16.default.existsSync(configFile)) {
3337
3345
  try {
3338
3346
  if (configFile.endsWith(".json")) {
3339
- const content = import_fs15.default.readFileSync(configFile, "utf-8");
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 (!import_fs15.default.existsSync(appDir) && process.env.NODE_ENV !== "test") {
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;
@@ -4062,7 +4070,7 @@ function handleNotFound(res, urlPath) {
4062
4070
  }
4063
4071
 
4064
4072
  // modules/server/handlers/ssg.ts
4065
- var import_fs16 = __toESM(require("fs"));
4073
+ var import_fs17 = __toESM(require("fs"));
4066
4074
  var import_path20 = __toESM(require("path"));
4067
4075
  var logger2 = createModuleLogger("ssg");
4068
4076
  function getSsgDirForPath(baseDir, urlPath) {
@@ -4079,7 +4087,7 @@ function getSsgDataPath(baseDir, urlPath) {
4079
4087
  }
4080
4088
  function tryServeSsgHtml(res, ssgOutDir, urlPath) {
4081
4089
  const ssgHtmlPath = getSsgHtmlPath(ssgOutDir, urlPath);
4082
- if (!import_fs16.default.existsSync(ssgHtmlPath)) {
4090
+ if (!import_fs17.default.existsSync(ssgHtmlPath)) {
4083
4091
  return false;
4084
4092
  }
4085
4093
  logger2.info("Serving SSG HTML", { urlPath, ssgHtmlPath });
@@ -4089,17 +4097,17 @@ function tryServeSsgHtml(res, ssgOutDir, urlPath) {
4089
4097
  );
4090
4098
  res.statusCode = 200;
4091
4099
  res.setHeader("Content-Type", "text/html; charset=utf-8");
4092
- const stream = import_fs16.default.createReadStream(ssgHtmlPath, { encoding: "utf-8" });
4100
+ const stream = import_fs17.default.createReadStream(ssgHtmlPath, { encoding: "utf-8" });
4093
4101
  stream.pipe(res);
4094
4102
  return true;
4095
4103
  }
4096
4104
  function tryServeSsgData(res, ssgOutDir, urlPath) {
4097
4105
  const ssgDataPath = getSsgDataPath(ssgOutDir, urlPath);
4098
- if (!import_fs16.default.existsSync(ssgDataPath)) {
4106
+ if (!import_fs17.default.existsSync(ssgDataPath)) {
4099
4107
  return false;
4100
4108
  }
4101
4109
  try {
4102
- const raw = import_fs16.default.readFileSync(ssgDataPath, "utf-8");
4110
+ const raw = import_fs17.default.readFileSync(ssgDataPath, "utf-8");
4103
4111
  res.setHeader("Content-Type", "application/json; charset=utf-8");
4104
4112
  res.status(200).end(raw);
4105
4113
  return true;
@@ -4807,7 +4815,12 @@ var setupApplication = async ({
4807
4815
 
4808
4816
  // src/server.ts
4809
4817
  var import_dotenv2 = __toESM(require("dotenv"));
4810
- import_dotenv2.default.config();
4818
+ var envPath = import_path22.default.join(process.cwd(), ".env");
4819
+ if (import_fs18.default.existsSync(envPath)) {
4820
+ import_dotenv2.default.config({ path: envPath });
4821
+ } else {
4822
+ import_dotenv2.default.config();
4823
+ }
4811
4824
  var logger3 = createModuleLogger("server");
4812
4825
  async function startServer(options = {}) {
4813
4826
  const isDev = options.isDev ?? process.env.NODE_ENV === "development";
@@ -4816,7 +4829,7 @@ async function startServer(options = {}) {
4816
4829
  const port = options.port ?? (process.env.PORT ? parseInt(process.env.PORT, 10) : void 0) ?? config.server.port;
4817
4830
  const host = process.env.HOST ?? (!isDev ? "0.0.0.0" : void 0) ?? config.server.host;
4818
4831
  const appDir = options.appDir ?? (isDev ? getAppDir(projectRoot, config) : import_path22.default.join(getBuildDir(projectRoot, config), "server"));
4819
- if (!isDev && !import_fs17.default.existsSync(appDir)) {
4832
+ if (!isDev && !import_fs18.default.existsSync(appDir)) {
4820
4833
  logger3.error("Compiled directory not found", void 0, {
4821
4834
  buildDir: config.directories.build,
4822
4835
  appDir,
@@ -4926,7 +4939,7 @@ function pathToOutDir(baseDir, urlPath) {
4926
4939
  }
4927
4940
 
4928
4941
  // modules/build/ssg/renderer.ts
4929
- var import_fs18 = __toESM(require("fs"));
4942
+ var import_fs19 = __toESM(require("fs"));
4930
4943
  var import_path24 = __toESM(require("path"));
4931
4944
  var import_server3 = require("react-dom/server");
4932
4945
  init_globals();
@@ -4999,8 +5012,8 @@ async function renderStaticRoute(projectRoot, ssgOutDir, route, urlPath, params)
4999
5012
  ensureDir(dir);
5000
5013
  const htmlFile = import_path24.default.join(dir, "index.html");
5001
5014
  const dataFile = import_path24.default.join(dir, "data.json");
5002
- import_fs18.default.writeFileSync(htmlFile, html, "utf-8");
5003
- import_fs18.default.writeFileSync(dataFile, JSON.stringify(initialData, null, 2), "utf-8");
5015
+ import_fs19.default.writeFileSync(htmlFile, html, "utf-8");
5016
+ import_fs19.default.writeFileSync(dataFile, JSON.stringify(initialData, null, 2), "utf-8");
5004
5017
  }
5005
5018
 
5006
5019
  // modules/build/ssg/builder.ts
@@ -5055,14 +5068,14 @@ async function buildStaticPages(projectRoot, routes) {
5055
5068
 
5056
5069
  // modules/build/bundler/server.ts
5057
5070
  var import_path28 = __toESM(require("path"));
5058
- var import_fs19 = __toESM(require("fs"));
5071
+ var import_fs20 = __toESM(require("fs"));
5059
5072
  var import_esbuild = __toESM(require("esbuild"));
5060
5073
  init_globals();
5061
5074
  var SERVER_FILES = [INIT_FILE_NAME, CONFIG_FILE_NAME];
5062
5075
  function collectAppSources(appDir) {
5063
5076
  const entries = [];
5064
5077
  function walk(dir) {
5065
- const items = import_fs19.default.readdirSync(dir, { withFileTypes: true });
5078
+ const items = import_fs20.default.readdirSync(dir, { withFileTypes: true });
5066
5079
  for (const item of items) {
5067
5080
  const full = import_path28.default.join(dir, item.name);
5068
5081
  if (item.isDirectory()) {
@@ -5105,7 +5118,7 @@ async function buildServerApp(projectRoot, appDir) {
5105
5118
  for (const fileName of SERVER_FILES) {
5106
5119
  const initTS = import_path28.default.join(projectRoot, `${fileName}.ts`);
5107
5120
  const initJS = import_path28.default.join(outDir, `${fileName}.js`);
5108
- if (import_fs19.default.existsSync(initTS)) {
5121
+ if (import_fs20.default.existsSync(initTS)) {
5109
5122
  await import_esbuild.default.build({
5110
5123
  entryPoints: [initTS],
5111
5124
  outfile: initJS,
@@ -5848,7 +5861,7 @@ async function loadInitialRoute(initialUrl, initialData, routes, notFoundRoute,
5848
5861
  };
5849
5862
  }
5850
5863
  function setupHotReload2() {
5851
- const nodeEnv = typeof process !== "undefined" && process?.env?.NODE_ENV || "production";
5864
+ const nodeEnv = typeof process !== "undefined" && process.env?.NODE_ENV || "production";
5852
5865
  const isDev = nodeEnv !== "production";
5853
5866
  if (!isDev) {
5854
5867
  return;