@evjs/cli 0.3.0 → 0.3.2

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/README.md CHANGED
@@ -20,7 +20,7 @@ Page tree is materialized as an SPA or MPA:
20
20
  - Shared HTML template: `./index.html`
21
21
  - Client dev server: port 3000
22
22
  - API server (dev): port 3001
23
- - Server functions auto-discovered via `"use server"` directive
23
+ - Reachable server functions discovered via the `"use server"` directive
24
24
  - Server request-route anchors auto-discovered from `./src/apis/**/api.*`
25
25
 
26
26
  `routing.mode` selects SPA or MPA materialization for the same semantic
@@ -39,15 +39,17 @@ Page-and-Route tree. It does not select a different file convention.
39
39
 
40
40
  ### `ev dev`
41
41
 
42
- Uses the default bundler adapter directly (no temp config files):
43
- 1. **dev server** (port 3000) — client bundle with HMR.
44
- 2. **Node API Server** (port 3001) — auto-starts when server bundle is emitted, uses `node --watch`.
42
+ Uses the default bundler adapter directly:
43
+
44
+ 1. **browser dev server** (preferred port 3000) — client bundle with HMR;
45
+ 2. **framework server** (preferred port 3001) — starts when the active
46
+ BuildPlan emits a server runtime.
45
47
 
46
48
  ### `ev build`
47
49
 
48
50
  Runs the production build through `@evjs/ev` with `NODE_ENV=production`:
49
51
  - `dist/client/` — optimized client assets with content hashes.
50
- - `dist/server/main.[hash].js` — server bundle.
52
+ - `dist/server/` — server artifacts when the BuildPlan requires them.
51
53
  - `dist/deployment-metadata.json` — canonical deployment metadata for tooling
52
54
  and adapters.
53
55
 
@@ -86,8 +88,8 @@ export default defineConfig({
86
88
 
87
89
  The `dev` and `server.dev` fields accept extra options that are merged with
88
90
  defaults. Change only `routing.mode` to `"mpa"` to materialize the same Page
89
- tree as Page-owned Documents. Dynamic-route output and React route facets in
90
- MPA remain staged; `ev inspect` and `ev build` report unsupported combinations.
91
+ tree as Page-owned Documents. MPA accepts static Page paths and rejects
92
+ dynamic/catch-all paths and router-only boundary facets.
91
93
 
92
94
  ## Project Structure
93
95
 
@@ -119,25 +121,17 @@ Only `page.*` creates a canonical client Page and Route. Other files below a
119
121
  Page directory, including `index.*`, are ordinary Page-private source and need
120
122
  no `_` prefix. The Page directory determines the URL in both SPA and MPA mode.
121
123
 
122
- ## Common Mistakes
124
+ ## Authoring Boundaries
123
125
 
124
- 1. **Do not create `src/main.tsx` or top-level `entry` for a canonical app** —
125
- add `src/pages/**/page.tsx` anchors and declare `routing.mode`.
126
- 2. **Do not use `index.tsx` as a new Page anchor** — it is ordinary private
127
- source in the canonical model.
128
- 3. **Do not create a custom bundler config file** — use `ev.config.ts` instead.
129
- 4. **Do not install bundler internals manually** — the default adapter is
130
- provided by `@evjs/cli`.
131
- 5. **Config file must be `ev.config.ts`** — not `evjs.config.ts`.
132
- 6. **Import `defineConfig` and `definePageConfig` from `@evjs/ev`** — not from
133
- `@evjs/server`.
126
+ 1. Canonical apps publish Pages through `src/pages/**/page.*` and declare
127
+ `routing.mode`; colocated `index.*` files remain ordinary source.
128
+ 2. Configure the framework in `ev.config.ts`; the CLI supplies the default
129
+ bundler adapter.
130
+ 3. Import `defineConfig` and `definePageConfig` from `@evjs/ev`.
134
131
 
135
132
  Explicit `application.routes` and `component`/`routes` config are SPA-only
136
- route-tree inputs in `@evjs/ev`; their converters normalize into the same Core
137
- graph, reject MPA materialization, and do not define additional canonical
138
- routing models. File-convention applications must use `page.tsx` for every
139
- published Page, keep Page configuration in `page.config.ts`, and select only
140
- `routing.mode: "spa" | "mpa"`.
133
+ route-tree inputs in `@evjs/ev`; they normalize into the same CoreGraph and
134
+ cannot be combined with canonical `routing` discovery.
141
135
 
142
136
  ## Bundled Dependencies
143
137
 
@@ -12,8 +12,9 @@ function coerceFlagValue(value) {
12
12
  }
13
13
  /** Stores a flag value, preserving repeated flags as an ordered array. */
14
14
  function setFlag(flags, name, value) {
15
- const current = flags[name];
16
- if (current === undefined) {
15
+ const hasCurrent = Object.hasOwn(flags, name);
16
+ const current = hasCurrent ? flags[name] : undefined;
17
+ if (!hasCurrent || current === undefined) {
17
18
  flags[name] = value;
18
19
  }
19
20
  else if (Array.isArray(current)) {
@@ -31,7 +32,7 @@ function setFlag(flags, name, value) {
31
32
  * and repeated flags as arrays.
32
33
  */
33
34
  export function parseCliFlags(args) {
34
- const flags = {};
35
+ const flags = Object.create(null);
35
36
  for (let index = 0; index < args.length; index++) {
36
37
  const arg = args[index];
37
38
  if (arg === "--")
@@ -44,11 +45,13 @@ export function parseCliFlags(args) {
44
45
  const equalsIndex = rawFlag.indexOf("=");
45
46
  if (equalsIndex >= 0) {
46
47
  const name = toFlagName(rawFlag.slice(0, equalsIndex));
48
+ if (!name)
49
+ continue;
47
50
  setFlag(flags, name, coerceFlagValue(rawFlag.slice(equalsIndex + 1)));
48
51
  continue;
49
52
  }
50
53
  const nextArg = args[index + 1];
51
- if (nextArg && !nextArg.startsWith("-")) {
54
+ if (nextArg && !nextArg.startsWith("--")) {
52
55
  setFlag(flags, toFlagName(rawFlag), coerceFlagValue(nextArg));
53
56
  index++;
54
57
  }
@@ -6,11 +6,19 @@ type FrameworkCommand = (config: Config<DefaultBundlerConfig> | undefined, optio
6
6
  cwd: string;
7
7
  flags: CliFlags;
8
8
  }) => Promise<void>;
9
+ type ConfigLoader = (cwd: string, context?: {
10
+ onDependency(file: string): void;
11
+ }) => Promise<Config<DefaultBundlerConfig> | undefined>;
12
+ type DevFrameworkCommand = (config: Config<DefaultBundlerConfig> | undefined, options: {
13
+ cwd: string;
14
+ flags: CliFlags;
15
+ loadConfig: ConfigLoader;
16
+ }) => Promise<void>;
9
17
  export interface CliProgramDependencies {
10
18
  version: string;
11
19
  cwd(): string;
12
- loadConfig(cwd: string): Promise<Config<DefaultBundlerConfig> | undefined>;
13
- dev: FrameworkCommand;
20
+ loadConfig: ConfigLoader;
21
+ dev: DevFrameworkCommand;
14
22
  build: FrameworkCommand;
15
23
  prepare: FrameworkCommand;
16
24
  inspect(options: InspectCommandOptions): Promise<InspectCommandResult>;
@@ -32,8 +32,11 @@ export async function runCliProgram(argv, dependencies) {
32
32
  await runCommand("Failed to start dev server", async () => {
33
33
  const cwd = dependencies.cwd();
34
34
  const flags = parseCliFlags(command.args);
35
- const config = await dependencies.loadConfig(cwd);
36
- await dependencies.dev(config, { cwd, flags });
35
+ await dependencies.dev(undefined, {
36
+ cwd,
37
+ flags,
38
+ loadConfig: dependencies.loadConfig,
39
+ });
37
40
  });
38
41
  });
39
42
  program
package/dist/cli.js CHANGED
@@ -50,7 +50,7 @@ export async function runCli(argv = process.argv) {
50
50
  return runCliProgram(argv, {
51
51
  version: pkg.version,
52
52
  cwd: () => process.cwd(),
53
- loadConfig: (cwd) => loadConfig(cwd),
53
+ loadConfig: (cwd, options) => loadConfig(cwd, options),
54
54
  dev,
55
55
  build,
56
56
  prepare,
package/dist/index.d.ts CHANGED
@@ -1,11 +1,24 @@
1
- import { utoopackAdapter } from "@evjs/bundler-utoopack";
2
1
  import { type BuildOptions, type BundlerAdapter, type DevOptions, type PrepareFrameworkBuildOptions } from "@evjs/ev/_internal/build";
3
2
  import type { Config } from "@evjs/ev/config";
3
+ import type { DefaultBundlerConfig } from "./load-config.js";
4
4
  export type { BuildOptions, BundlerAdapter, DevOptions, PrepareFrameworkBuildOptions, } from "@evjs/ev/_internal/build";
5
5
  export { CONFIG_DEFAULTS, type Config, defineConfig, type ResolvedConfig, resolveConfig, } from "@evjs/ev/config";
6
- export type { BuildResult, BundlerCtx, ContributionContext, EmitApi, FrameworkIRView, FrameworkSlot, FrameworkSlotInput, GeneratedModuleRef, Plugin, PluginContext, PluginHooks, } from "@evjs/ev/plugin";
7
- export { loadConfig } from "./load-config.js";
8
- export type DefaultBundlerConfig = typeof utoopackAdapter extends BundlerAdapter<infer TBundlerCfg> ? TBundlerCfg : never;
9
- export declare function dev<TBundlerCfg = DefaultBundlerConfig>(userConfig?: Config<TBundlerCfg>, options?: DevOptions<TBundlerCfg>): Promise<void>;
10
- export declare function build<TBundlerCfg = DefaultBundlerConfig>(userConfig?: Config<TBundlerCfg>, options?: BuildOptions<TBundlerCfg>): Promise<void>;
6
+ export { type DefaultBundlerConfig, loadConfig } from "./load-config.js";
7
+ type ConfigWithBundler<TBundlerCfg> = Config<TBundlerCfg> & {
8
+ readonly bundler: BundlerAdapter<TBundlerCfg>;
9
+ };
10
+ type DevOptionsWithBundler<TBundlerCfg> = DevOptions<TBundlerCfg> & ({
11
+ readonly bundler: BundlerAdapter<TBundlerCfg>;
12
+ } | {
13
+ readonly fallbackBundler: BundlerAdapter<TBundlerCfg>;
14
+ });
15
+ type BuildOptionsWithBundler<TBundlerCfg> = BuildOptions<TBundlerCfg> & {
16
+ readonly bundler: BundlerAdapter<TBundlerCfg>;
17
+ };
18
+ export declare function dev(userConfig?: Config<DefaultBundlerConfig>, options?: DevOptions<DefaultBundlerConfig>): Promise<void>;
19
+ export declare function dev<TBundlerCfg>(userConfig: ConfigWithBundler<TBundlerCfg>, options?: DevOptions<TBundlerCfg>): Promise<void>;
20
+ export declare function dev<TBundlerCfg>(userConfig: Config<TBundlerCfg> | undefined, options: DevOptionsWithBundler<TBundlerCfg>): Promise<void>;
21
+ export declare function build(userConfig?: Config<DefaultBundlerConfig>, options?: BuildOptions<DefaultBundlerConfig>): Promise<void>;
22
+ export declare function build<TBundlerCfg>(userConfig: ConfigWithBundler<TBundlerCfg>, options?: BuildOptions<TBundlerCfg>): Promise<void>;
23
+ export declare function build<TBundlerCfg>(userConfig: Config<TBundlerCfg> | undefined, options: BuildOptionsWithBundler<TBundlerCfg>): Promise<void>;
11
24
  export declare function prepare<TBundlerCfg = DefaultBundlerConfig>(userConfig?: Config<TBundlerCfg>, options?: PrepareFrameworkBuildOptions<TBundlerCfg>): Promise<void>;
package/dist/index.js CHANGED
@@ -6,22 +6,37 @@ const defaultBundler = utoopackAdapter;
6
6
  export async function dev(userConfig, options) {
7
7
  const { loadConfig } = await import("./load-config.js");
8
8
  const defaultLoadConfig = (loadConfig);
9
- const bundler = options?.bundler ??
10
- userConfig?.bundler ??
11
- defaultBundler;
9
+ const reloadInitialConfig = options?.reloadInitialConfig ?? userConfig === undefined;
10
+ const configLoader = options?.loadConfig ??
11
+ (reloadInitialConfig ? defaultLoadConfig : undefined);
12
+ const explicitBundler = options?.bundler ?? userConfig?.bundler ?? options?.fallbackBundler;
13
+ if (explicitBundler) {
14
+ await frameworkDev(userConfig, {
15
+ ...options,
16
+ loadConfig: configLoader,
17
+ reloadInitialConfig,
18
+ });
19
+ return;
20
+ }
12
21
  await frameworkDev(userConfig, {
13
22
  ...options,
14
- bundler,
15
- loadConfig: options?.loadConfig ?? defaultLoadConfig,
23
+ fallbackBundler: defaultBundler,
24
+ loadConfig: configLoader,
25
+ reloadInitialConfig,
16
26
  });
17
27
  }
18
28
  export async function build(userConfig, options) {
19
- const bundler = options?.bundler ??
20
- userConfig?.bundler ??
21
- defaultBundler;
29
+ const explicitBundler = options?.bundler ?? userConfig?.bundler;
30
+ if (explicitBundler) {
31
+ await frameworkBuild(userConfig, {
32
+ ...options,
33
+ bundler: explicitBundler,
34
+ });
35
+ return;
36
+ }
22
37
  await frameworkBuild(userConfig, {
23
38
  ...options,
24
- bundler,
39
+ bundler: defaultBundler,
25
40
  });
26
41
  }
27
42
  export async function prepare(userConfig, options) {
@@ -4,10 +4,7 @@ import { loadConfig } from "./load-config.js";
4
4
  export async function runInspectCommand(options = {}) {
5
5
  const cwd = options.cwd ?? process.cwd();
6
6
  const config = await loadConfig(cwd);
7
- const result = await inspectFrameworkBuild(config ?? undefined, {
8
- cwd,
9
- runLifecycleHooks: false,
10
- });
7
+ const result = await inspectFrameworkBuild(config ?? undefined, { cwd });
11
8
  return {
12
9
  exitCode: hasInspectErrors(result) ? 1 : 0,
13
10
  output: options.json
package/dist/inspect.js CHANGED
@@ -8,7 +8,7 @@ export function formatInspectText(result) {
8
8
  const lines = [];
9
9
  lines.push("ev inspect");
10
10
  lines.push(`Project: ${result.cwd}`);
11
- lines.push(`Mode: ${result.command} (${result.mode})`);
11
+ lines.push(`Mode: ${result.mode}`);
12
12
  lines.push("");
13
13
  lines.push("Routing");
14
14
  if (result.routing) {
@@ -34,9 +34,12 @@ export function formatInspectText(result) {
34
34
  const target = formatRouteFileTarget(file);
35
35
  return `${file.status}: ${file.file}${target}${diagnostics ?? ""}`;
36
36
  });
37
- appendList(lines, "Applications", Object.values(result.graph.applications), (application) => `${application.id}: ${application.routingMode}, pages=${application.pageIds.length}, routes=${application.routeIds.length}, documents=${application.documentIds.length}`);
37
+ appendList(lines, "Applications", Object.values(result.graph.applications), (application) => {
38
+ const plugins = Object.entries(application.plugins).map(([key, setting]) => `${key}:${setting.enabled ? "on" : "off"}`);
39
+ return `${application.id}: ${application.routingMode}, pages=${application.pageIds.length}, routes=${application.routeIds.length}, documents=${application.documentIds.length}${plugins.length > 0 ? `, plugins=${plugins.join(",")}` : ""}`;
40
+ });
38
41
  appendList(lines, "Pages", Object.values(result.graph.pages), (page) => {
39
- const extensions = Object.keys(page.extensions);
42
+ const plugins = Object.entries(page.plugins).map(([key, setting]) => `${key}:${setting.enabled ? "on" : "off"}`);
40
43
  const metadata = [
41
44
  `application=${page.applicationId}`,
42
45
  `render=${page.render}`,
@@ -49,7 +52,7 @@ export function formatInspectText(result) {
49
52
  (typeof page.prerender === "object" && page.prerender.partial === true)
50
53
  ? "ppr=true"
51
54
  : undefined,
52
- extensions.length > 0 ? `extensions=${extensions.join(",")}` : undefined,
55
+ plugins.length > 0 ? `plugins=${plugins.join(",")}` : undefined,
53
56
  ]
54
57
  .filter(Boolean)
55
58
  .join(", ");
@@ -57,17 +60,21 @@ export function formatInspectText(result) {
57
60
  });
58
61
  appendList(lines, "Routes", result.graph.routes, formatCoreRoute);
59
62
  appendList(lines, "Documents", Object.values(result.graph.documents), (document) => `${document.id}: application=${document.applicationId}, owner=${document.owner.kind}, output=${document.output}`);
60
- appendList(lines, "Extensions", Object.entries(result.graph.extensions.namespaces), ([namespace, registration]) => {
63
+ appendList(lines, "Plugins", Object.entries(result.graph.plugins.entries), ([id, registration]) => {
64
+ const contracts = [
65
+ registration.application ? "application" : undefined,
66
+ registration.page ? "page" : undefined,
67
+ ].filter(Boolean);
61
68
  const metadata = [
62
- `producer=${formatCoreIdentifier(registration.producer)}`,
63
- `owners=${registration.owners.join(",")}`,
64
- registration.schemaVersion
65
- ? `schema=${registration.schemaVersion}`
69
+ contracts.length > 0 ? `contracts=${contracts.join(",")}` : undefined,
70
+ registration.page
71
+ ? `pageDefaultable=${registration.page.defaultable}`
66
72
  : undefined,
67
73
  ]
68
74
  .filter(Boolean)
69
75
  .join(", ");
70
- return `${namespace}: ${metadata}`;
76
+ const formattedId = formatCoreIdentifier(id);
77
+ return metadata ? `${formattedId}: ${metadata}` : formattedId;
71
78
  });
72
79
  appendList(lines, "Server Functions", result.graph.serverFunctions, (fn) => {
73
80
  return `${fn.exportName} -> ${fn.id} (${fn.module})`;
@@ -1,4 +1,7 @@
1
- import type { Config, DefaultBundlerConfig } from "@evjs/ev/config";
1
+ import type { utoopackAdapter } from "@evjs/bundler-utoopack";
2
+ import { type BundlerAdapter, type LoadConfigFileOptions } from "@evjs/ev/_internal/build";
3
+ import type { Config } from "@evjs/ev/config";
4
+ export type DefaultBundlerConfig = typeof utoopackAdapter extends BundlerAdapter<infer TBundlerCfg> ? TBundlerCfg : never;
2
5
  export declare const CONFIG_FILES: string[];
3
6
  /**
4
7
  * Load evjs config from the project root.
@@ -6,5 +9,5 @@ export declare const CONFIG_FILES: string[];
6
9
  * Looks for `ev.config.ts`, `.js`, or `.mjs` in the given directory.
7
10
  * Returns undefined if no config file is found.
8
11
  */
9
- export declare function loadConfig<TBundlerCfg = DefaultBundlerConfig>(cwd: string): Promise<Config<TBundlerCfg> | undefined>;
12
+ export declare function loadConfig<TBundlerCfg = DefaultBundlerConfig>(cwd: string, options?: LoadConfigFileOptions): Promise<Config<TBundlerCfg> | undefined>;
10
13
  export declare function resolveConfigPath(cwd: string): string | undefined;
@@ -1,6 +1,6 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
- import { loadConfigFile } from "@evjs/ev/_internal/build";
3
+ import { loadConfigFile, } from "@evjs/ev/_internal/build";
4
4
  export const CONFIG_FILES = ["ev.config.ts", "ev.config.js", "ev.config.mjs"];
5
5
  /**
6
6
  * Load evjs config from the project root.
@@ -8,17 +8,24 @@ export const CONFIG_FILES = ["ev.config.ts", "ev.config.js", "ev.config.mjs"];
8
8
  * Looks for `ev.config.ts`, `.js`, or `.mjs` in the given directory.
9
9
  * Returns undefined if no config file is found.
10
10
  */
11
- export async function loadConfig(cwd) {
11
+ export async function loadConfig(cwd, options = {}) {
12
12
  const configPath = resolveConfigPath(cwd);
13
13
  if (!configPath)
14
14
  return undefined;
15
- return loadConfigFile(configPath);
15
+ return loadConfigFile(configPath, options);
16
16
  }
17
17
  export function resolveConfigPath(cwd) {
18
18
  for (const filename of CONFIG_FILES) {
19
19
  const configPath = path.resolve(cwd, filename);
20
- if (fs.existsSync(configPath))
20
+ try {
21
+ fs.lstatSync(configPath);
21
22
  return configPath;
23
+ }
24
+ catch (error) {
25
+ const code = error?.code;
26
+ if (code !== "ENOENT" && code !== "ENOTDIR")
27
+ throw error;
28
+ }
22
29
  }
23
30
  return undefined;
24
31
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evjs/cli",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "Command-line wrapper for the evjs framework",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -28,8 +28,8 @@
28
28
  "check-types": "tsc --noEmit"
29
29
  },
30
30
  "dependencies": {
31
- "@evjs/bundler-utoopack": "0.3.0",
32
- "@evjs/ev": "0.3.0",
31
+ "@evjs/bundler-utoopack": "0.3.2",
32
+ "@evjs/ev": "0.3.2",
33
33
  "@logtape/logtape": "^2.0.4",
34
34
  "commander": "^12.1.0"
35
35
  },