@evjs/cli 0.0.15 → 0.0.16

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.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import fs from "node:fs";
3
3
  import path from "node:path";
4
4
  import { fileURLToPath } from "node:url";
5
- import { configure, getConsoleSink } from "@logtape/logtape";
5
+ import { configure, getConsoleSink, getLogger } from "@logtape/logtape";
6
6
  import { Command } from "commander";
7
7
  import { build, dev } from "./index.js";
8
8
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
@@ -19,6 +19,7 @@ program
19
19
  .name("ev")
20
20
  .description("CLI for the evjs framework")
21
21
  .version(pkg.version);
22
+ const logger = getLogger(["evjs", "cli"]);
22
23
  program
23
24
  .command("dev")
24
25
  .description("Start development server")
@@ -30,7 +31,7 @@ program
30
31
  await dev(config ?? undefined, { cwd });
31
32
  }
32
33
  catch (err) {
33
- console.error(err);
34
+ logger.error `Failed to start dev server: ${err}`;
34
35
  process.exit(1);
35
36
  }
36
37
  });
@@ -45,7 +46,7 @@ program
45
46
  await build(config ?? undefined, { cwd });
46
47
  }
47
48
  catch (err) {
48
- console.error(err);
49
+ logger.error `Build failed: ${err}`;
49
50
  process.exit(1);
50
51
  }
51
52
  });
package/dist/index.js CHANGED
@@ -27,18 +27,28 @@ export async function dev(userConfig, options) {
27
27
  const cwd = options?.cwd ?? process.cwd();
28
28
  process.env.NODE_ENV ??= "development";
29
29
  const bundler = await getBundlerAdapter(config);
30
- // Background: start Node API when server bundle is ready
31
- let apiStarted = false;
30
+ // Track the running API server process for lifecycle management.
31
+ // Using a reference instead of a boolean allows proper restart on crash.
32
+ let apiProcess = null;
32
33
  const handleServerBundleReady = () => {
33
- if (apiStarted)
34
+ if (!config.serverEnabled)
34
35
  return;
35
36
  const manifestPath = path.resolve(cwd, "dist/server/manifest.json");
36
37
  if (!fs.existsSync(manifestPath))
37
38
  return;
38
39
  const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf-8"));
40
+ if (manifest.version !== 1) {
41
+ logger.warn `Unexpected server manifest version: ${manifest.version}. Expected 1.`;
42
+ return;
43
+ }
39
44
  if (!manifest.entry)
40
45
  return;
41
- apiStarted = true;
46
+ // Kill previous process before restarting (handles both first start and restarts)
47
+ if (apiProcess) {
48
+ logger.info `Restarting API server...`;
49
+ apiProcess.kill();
50
+ apiProcess = null;
51
+ }
42
52
  const serverPort = config?.server?.dev?.port ?? CONFIG_DEFAULTS.serverPort;
43
53
  const runtimeConfig = config?.server?.runtime ?? "node";
44
54
  const [runtime, ...runtimeExtraArgs] = runtimeConfig.split(/\s+/);
@@ -65,16 +75,21 @@ export async function dev(userConfig, options) {
65
75
  ]
66
76
  : [...runtimeExtraArgs, bootstrapPath];
67
77
  // Don't await execa here since it's a long-running watch process
68
- execa(runtime, runtimeArgs, {
78
+ const child = execa(runtime, runtimeArgs, {
69
79
  stdio: "inherit",
70
80
  env: { ...process.env, NODE_ENV: "development" },
71
- }).catch(() => {
72
- apiStarted = false;
81
+ });
82
+ apiProcess = child;
83
+ child.catch(() => {
84
+ // Clear reference so the next compilation can restart
85
+ if (apiProcess === child) {
86
+ apiProcess = null;
87
+ }
73
88
  });
74
89
  }
75
90
  catch (err) {
76
91
  logger.error `Server runtime failed: ${err}`;
77
- apiStarted = false;
92
+ apiProcess = null;
78
93
  }
79
94
  };
80
95
  await bundler.dev(config, cwd, {
@@ -1,4 +1,4 @@
1
- import type { EvConfig, EvConfigCtx } from "./config.js";
1
+ import type { EvConfig, EvConfigCtx } from "@evjs/shared";
2
2
  /**
3
3
  * Load evjs config from the project root.
4
4
  *
@@ -1,11 +1,6 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  const CONFIG_FILES = ["ev.config.ts", "ev.config.js", "ev.config.mjs"];
4
- /**
5
- * Historically used @swc-node/register, but it causes ERR_REQUIRE_CYCLE_MODULE inside Node 22.
6
- * Modern evjs relies on Node's native typescript handling or built-in --loader arguments.
7
- */
8
- async function ensureTsLoader() { }
9
4
  /**
10
5
  * Load evjs config from the project root.
11
6
  *
@@ -19,10 +14,6 @@ export async function loadConfig(cwd, ctx) {
19
14
  for (const filename of CONFIG_FILES) {
20
15
  const configPath = path.resolve(cwd, filename);
21
16
  if (fs.existsSync(configPath)) {
22
- // Register TS loader for .ts config files
23
- if (filename.endsWith(".ts")) {
24
- await ensureTsLoader();
25
- }
26
17
  const mod = await import(configPath);
27
18
  let config = mod.default ?? mod;
28
19
  // Execute plugin config hooks
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evjs/cli",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "description": "CLI and configuration layer for the evjs framework",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/dist/config.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import { CONFIG_DEFAULTS, defineConfig, type EvBundlerCtx, type EvConfig, type EvConfigCtx, type EvPlugin, type ResolvedEvConfig, resolveConfig } from "@evjs/shared";
2
- export { type EvConfig, type EvConfigCtx, type EvBundlerCtx, type ResolvedEvConfig, type EvPlugin, CONFIG_DEFAULTS, defineConfig, resolveConfig, };
package/dist/config.js DELETED
@@ -1,2 +0,0 @@
1
- import { CONFIG_DEFAULTS, defineConfig, resolveConfig, } from "@evjs/shared";
2
- export { CONFIG_DEFAULTS, defineConfig, resolveConfig, };