@korajs/cli 1.0.0-beta.6 → 1.0.0-beta.7

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/bin.cjs CHANGED
@@ -1981,11 +1981,11 @@ var spectator_manager_exports = {};
1981
1981
  __export(spectator_manager_exports, {
1982
1982
  SpectatorManager: () => SpectatorManager
1983
1983
  });
1984
- var import_node_fs6, import_node_os, import_node_path28, FORWARDED_EVENTS, MAX_EVENT_BUFFER, SpectatorManager;
1984
+ var import_node_fs7, import_node_os, import_node_path28, FORWARDED_EVENTS, MAX_EVENT_BUFFER, SpectatorManager;
1985
1985
  var init_spectator_manager = __esm({
1986
1986
  "src/commands/studio/spectator-manager.ts"() {
1987
1987
  "use strict";
1988
- import_node_fs6 = require("fs");
1988
+ import_node_fs7 = require("fs");
1989
1989
  import_node_os = require("os");
1990
1990
  import_node_path28 = require("path");
1991
1991
  FORWARDED_EVENTS = [
@@ -2001,7 +2001,7 @@ var init_spectator_manager = __esm({
2001
2001
  SpectatorManager = class {
2002
2002
  constructor(options) {
2003
2003
  this.options = options;
2004
- this.tmpDir = (0, import_node_fs6.mkdtempSync)((0, import_node_path28.join)((0, import_node_os.tmpdir)(), "kora-studio-spectator-"));
2004
+ this.tmpDir = (0, import_node_fs7.mkdtempSync)((0, import_node_path28.join)((0, import_node_os.tmpdir)(), "kora-studio-spectator-"));
2005
2005
  this.dbPath = (0, import_node_path28.join)(this.tmpDir, "spectator-replica.db");
2006
2006
  }
2007
2007
  options;
@@ -2099,7 +2099,7 @@ var init_spectator_manager = __esm({
2099
2099
  this.runtime = null;
2100
2100
  }
2101
2101
  if (this.tmpDir) {
2102
- (0, import_node_fs6.rmSync)(this.tmpDir, { recursive: true, force: true });
2102
+ (0, import_node_fs7.rmSync)(this.tmpDir, { recursive: true, force: true });
2103
2103
  this.tmpDir = null;
2104
2104
  }
2105
2105
  }
@@ -2182,11 +2182,11 @@ function summarizeEvent(type, payload) {
2182
2182
  return type.replace("lab:", "");
2183
2183
  }
2184
2184
  }
2185
- var import_node_fs7, import_node_os2, import_node_path29, import_core3, DEFAULT_CHAOS, FORWARDED_EVENTS2, MAX_EVENT_BUFFER2, LabManager;
2185
+ var import_node_fs8, import_node_os2, import_node_path29, import_core3, DEFAULT_CHAOS, FORWARDED_EVENTS2, MAX_EVENT_BUFFER2, LabManager;
2186
2186
  var init_lab_manager = __esm({
2187
2187
  "src/commands/studio/lab-manager.ts"() {
2188
2188
  "use strict";
2189
- import_node_fs7 = require("fs");
2189
+ import_node_fs8 = require("fs");
2190
2190
  import_node_os2 = require("os");
2191
2191
  import_node_path29 = require("path");
2192
2192
  import_core3 = require("@korajs/core");
@@ -2246,7 +2246,7 @@ var init_lab_manager = __esm({
2246
2246
  }
2247
2247
  async start(initialDevices = 2) {
2248
2248
  const harness = await this.loadHarness();
2249
- this.tmpDir = (0, import_node_fs7.mkdtempSync)((0, import_node_path29.join)((0, import_node_os2.tmpdir)(), "kora-studio-lab-"));
2249
+ this.tmpDir = (0, import_node_fs8.mkdtempSync)((0, import_node_path29.join)((0, import_node_os2.tmpdir)(), "kora-studio-lab-"));
2250
2250
  this.server = new harness.TestServer(this.schema);
2251
2251
  for (let i = 0; i < initialDevices; i++) {
2252
2252
  await this.addDevice();
@@ -2377,7 +2377,7 @@ var init_lab_manager = __esm({
2377
2377
  });
2378
2378
  this.server = null;
2379
2379
  if (this.tmpDir) {
2380
- (0, import_node_fs7.rmSync)(this.tmpDir, { recursive: true, force: true });
2380
+ (0, import_node_fs8.rmSync)(this.tmpDir, { recursive: true, force: true });
2381
2381
  this.tmpDir = null;
2382
2382
  }
2383
2383
  }
@@ -6508,6 +6508,7 @@ function hasContextSetter(adapter) {
6508
6508
  }
6509
6509
 
6510
6510
  // src/commands/dev/dev-command.ts
6511
+ var import_node_fs6 = require("fs");
6511
6512
  var import_promises15 = require("fs/promises");
6512
6513
  var import_node_path23 = require("path");
6513
6514
  var import_node_path24 = require("path");
@@ -6730,6 +6731,7 @@ var devCommand = (0, import_citty6.defineCommand)({
6730
6731
  if (!projectRoot) {
6731
6732
  throw new InvalidProjectError(process.cwd());
6732
6733
  }
6734
+ loadProjectEnv(projectRoot);
6733
6735
  const config = await loadKoraConfig(projectRoot);
6734
6736
  const vitePort = typeof args.port === "string" ? args.port : String(config?.dev?.port ?? 5173);
6735
6737
  const syncPortFromConfig = typeof config?.dev?.sync === "object" && typeof config.dev.sync.port === "number" ? config.dev.sync.port : 3001;
@@ -6908,6 +6910,43 @@ async function fileExists3(path) {
6908
6910
  return false;
6909
6911
  }
6910
6912
  }
6913
+ function loadProjectEnv(projectRoot, mode = "development") {
6914
+ const files = [".env", ".env.local", `.env.${mode}`, `.env.${mode}.local`];
6915
+ const existingKeys = new Set(Object.keys(process.env));
6916
+ for (const file of files) {
6917
+ const path = (0, import_node_path23.join)(projectRoot, file);
6918
+ if (!(0, import_node_fs6.existsSync)(path)) continue;
6919
+ const parsed = parseEnvFile((0, import_node_fs6.readFileSync)(path, "utf8"));
6920
+ for (const [key, value] of Object.entries(parsed)) {
6921
+ if (!existingKeys.has(key)) {
6922
+ process.env[key] = value;
6923
+ }
6924
+ }
6925
+ }
6926
+ }
6927
+ function parseEnvFile(contents) {
6928
+ const env = {};
6929
+ for (const rawLine of contents.split(/\r?\n/)) {
6930
+ const line = rawLine.trim();
6931
+ if (!line || line.startsWith("#")) continue;
6932
+ const normalized = line.startsWith("export ") ? line.slice("export ".length).trim() : line;
6933
+ const equalsIndex = normalized.indexOf("=");
6934
+ if (equalsIndex <= 0) continue;
6935
+ const key = normalized.slice(0, equalsIndex).trim();
6936
+ if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) continue;
6937
+ env[key] = parseEnvValue(normalized.slice(equalsIndex + 1).trim());
6938
+ }
6939
+ return env;
6940
+ }
6941
+ function parseEnvValue(value) {
6942
+ const quote = value[0];
6943
+ if ((quote === '"' || quote === "'") && value[value.length - 1] === quote) {
6944
+ const inner = value.slice(1, -1);
6945
+ return quote === '"' ? inner.replace(/\\n/g, "\n").replace(/\\r/g, "\r") : inner;
6946
+ }
6947
+ const commentIndex = value.search(/\s#/);
6948
+ return (commentIndex >= 0 ? value.slice(0, commentIndex) : value).trim();
6949
+ }
6911
6950
  function normalizeManagedSyncStore(config, projectRoot) {
6912
6951
  const sync = config?.dev?.sync;
6913
6952
  if (typeof sync !== "object" || sync === null) return null;
@@ -8765,7 +8804,7 @@ function printStatus(status, url, logger) {
8765
8804
  }
8766
8805
 
8767
8806
  // src/commands/studio/studio-command.ts
8768
- var import_node_fs8 = require("fs");
8807
+ var import_node_fs9 = require("fs");
8769
8808
  var import_node_path30 = require("path");
8770
8809
  var import_citty12 = require("citty");
8771
8810
  var studioCommand = (0, import_citty12.defineCommand)({
@@ -8870,7 +8909,7 @@ var studioCommand = (0, import_citty12.defineCommand)({
8870
8909
  );
8871
8910
  }
8872
8911
  const dbPath = (0, import_node_path30.resolve)(process.cwd(), args.db);
8873
- if (!(0, import_node_fs8.existsSync)(dbPath)) {
8912
+ if (!(0, import_node_fs9.existsSync)(dbPath)) {
8874
8913
  throw new Error(`Database file not found: ${dbPath}`);
8875
8914
  }
8876
8915
  const server = await startStudioServer2({ port, dbPath });