@evjs/cli 0.3.30-alpha.1 → 0.3.31
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/api/framework-commands.d.ts +1 -0
- package/dist/api/framework-commands.js +6 -1
- package/dist/commands/analyze/command.d.ts +30 -0
- package/dist/commands/analyze/command.js +69 -0
- package/dist/commands/analyze/runtime.d.ts +2 -0
- package/dist/commands/analyze/runtime.js +38 -0
- package/dist/program/command-program.d.ts +2 -0
- package/dist/program/command-program.js +2 -0
- package/dist/program/run.js +4 -2
- package/package.json +3 -3
|
@@ -18,6 +18,7 @@ type BuildOptionsWithBundler<TBundlerCfg> = BuildOptions<TBundlerCfg> & {
|
|
|
18
18
|
export declare function dev(userConfig?: Config<DefaultBundlerConfig>, options?: DevOptions<DefaultBundlerConfig>): Promise<void>;
|
|
19
19
|
export declare function dev<TBundlerCfg>(userConfig: ConfigWithBundler<TBundlerCfg>, options?: DevOptions<TBundlerCfg>): Promise<void>;
|
|
20
20
|
export declare function dev<TBundlerCfg>(userConfig: Config<TBundlerCfg> | undefined, options: DevOptionsWithBundler<TBundlerCfg>): Promise<void>;
|
|
21
|
+
export declare function runDev<TBundlerCfg>(userConfig?: Config<TBundlerCfg>, options?: DevOptions<TBundlerCfg>, forceExitOnRepeatedInterrupt?: boolean): Promise<void>;
|
|
21
22
|
export declare function build(userConfig?: Config<DefaultBundlerConfig>, options?: BuildOptions<DefaultBundlerConfig>): Promise<void>;
|
|
22
23
|
export declare function build<TBundlerCfg>(userConfig: ConfigWithBundler<TBundlerCfg>, options?: BuildOptions<TBundlerCfg>): Promise<void>;
|
|
23
24
|
export declare function build<TBundlerCfg>(userConfig: Config<TBundlerCfg> | undefined, options: BuildOptionsWithBundler<TBundlerCfg>): Promise<void>;
|
|
@@ -3,7 +3,10 @@ import { build as frameworkBuild, dev as frameworkDev, prepareFrameworkBuild, }
|
|
|
3
3
|
export { CONFIG_DEFAULTS, defineConfig, resolveConfig, } from "@evjs/ev/config";
|
|
4
4
|
export { loadConfig } from "../config/load.js";
|
|
5
5
|
const defaultBundler = utoopackAdapter;
|
|
6
|
-
export
|
|
6
|
+
export function dev(userConfig, options) {
|
|
7
|
+
return runDev(userConfig, options);
|
|
8
|
+
}
|
|
9
|
+
export async function runDev(userConfig, options, forceExitOnRepeatedInterrupt = false) {
|
|
7
10
|
const { loadConfig } = await import("../config/load.js");
|
|
8
11
|
const defaultLoadConfig = loadConfig;
|
|
9
12
|
const reloadInitialConfig = options?.reloadInitialConfig ?? userConfig === undefined;
|
|
@@ -13,6 +16,7 @@ export async function dev(userConfig, options) {
|
|
|
13
16
|
if (explicitBundler) {
|
|
14
17
|
await frameworkDev(userConfig, {
|
|
15
18
|
...options,
|
|
19
|
+
forceExitOnRepeatedInterrupt,
|
|
16
20
|
loadConfig: configLoader,
|
|
17
21
|
reloadInitialConfig,
|
|
18
22
|
});
|
|
@@ -21,6 +25,7 @@ export async function dev(userConfig, options) {
|
|
|
21
25
|
await frameworkDev(userConfig, {
|
|
22
26
|
...options,
|
|
23
27
|
fallbackBundler: defaultBundler,
|
|
28
|
+
forceExitOnRepeatedInterrupt,
|
|
24
29
|
loadConfig: configLoader,
|
|
25
30
|
reloadInitialConfig,
|
|
26
31
|
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Config } from "@evjs/ev/config";
|
|
2
|
+
import type { CliFlags } from "@evjs/ev/plugin";
|
|
3
|
+
import { type Command } from "commander";
|
|
4
|
+
import type { DefaultBundlerConfig } from "../../config/load.js";
|
|
5
|
+
interface ExportFilters {
|
|
6
|
+
entry?: string;
|
|
7
|
+
environment?: "client" | "server";
|
|
8
|
+
}
|
|
9
|
+
export interface BundleAnalysisActions {
|
|
10
|
+
capture(config: Config<DefaultBundlerConfig> | undefined, options: {
|
|
11
|
+
cwd: string;
|
|
12
|
+
flags: CliFlags;
|
|
13
|
+
outputPath?: string;
|
|
14
|
+
}): Promise<{
|
|
15
|
+
outputPath: string;
|
|
16
|
+
}>;
|
|
17
|
+
serveReport(reportPath: string, port?: number): Promise<{
|
|
18
|
+
url: string;
|
|
19
|
+
}>;
|
|
20
|
+
exportReport(reportPath: string, filters: ExportFilters): AsyncIterable<object>;
|
|
21
|
+
writeJsonLine(line: string): void | Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
interface AnalyzeCommandDependencies {
|
|
24
|
+
analysis: BundleAnalysisActions;
|
|
25
|
+
cwd(): string;
|
|
26
|
+
loadConfig(cwd: string): Promise<Config<DefaultBundlerConfig> | undefined>;
|
|
27
|
+
writeStdout(output: string): void;
|
|
28
|
+
}
|
|
29
|
+
export declare function registerAnalyzeCommand(program: Command, dependencies: AnalyzeCommandDependencies, runCommand: (summary: string, command: () => Promise<void>) => Promise<void>): void;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { InvalidArgumentError, Option } from "commander";
|
|
3
|
+
import { parseCliFlags } from "../../program/options.js";
|
|
4
|
+
function parsePort(value) {
|
|
5
|
+
const port = Number(value);
|
|
6
|
+
if (!/^\d+$/.test(value) || !Number.isInteger(port) || port > 65535) {
|
|
7
|
+
throw new InvalidArgumentError("Analyzer port must be an integer between 0 and 65535.");
|
|
8
|
+
}
|
|
9
|
+
return port;
|
|
10
|
+
}
|
|
11
|
+
export function registerAnalyzeCommand(program, dependencies, runCommand) {
|
|
12
|
+
const analyze = program
|
|
13
|
+
.command("analyze")
|
|
14
|
+
.description("Analyze production bundles with Utoopack")
|
|
15
|
+
.enablePositionalOptions()
|
|
16
|
+
.allowUnknownOption(true)
|
|
17
|
+
.option("-o, --output", "Write the report without starting a server")
|
|
18
|
+
.option("--output-dir <directory>", "Report directory relative to the project (default: .utoo/analyze)")
|
|
19
|
+
.option("--port <port>", "Local report server port (default: 4000)", parsePort)
|
|
20
|
+
.action(async (options, command) => {
|
|
21
|
+
await runCommand("Analysis failed", async () => {
|
|
22
|
+
const cwd = dependencies.cwd();
|
|
23
|
+
const flags = parseCliFlags(command.args);
|
|
24
|
+
const config = await dependencies.loadConfig(cwd);
|
|
25
|
+
const report = await dependencies.analysis.capture(config, {
|
|
26
|
+
cwd,
|
|
27
|
+
flags,
|
|
28
|
+
outputPath: options.outputDir,
|
|
29
|
+
});
|
|
30
|
+
dependencies.writeStdout(`Analyzer report written to ${report.outputPath}\n`);
|
|
31
|
+
if (!options.output) {
|
|
32
|
+
const server = await dependencies.analysis.serveReport(report.outputPath, options.port);
|
|
33
|
+
dependencies.writeStdout(`Bundle Analyzer available at ${server.url}\n`);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
analyze
|
|
38
|
+
.command("export")
|
|
39
|
+
.description("Export a saved report as JSONL without compiling")
|
|
40
|
+
.allowExcessArguments(false)
|
|
41
|
+
.allowUnknownOption(false)
|
|
42
|
+
.option("--report <directory>", "Saved report directory, relative to the current directory", ".utoo/analyze")
|
|
43
|
+
.option("--entry <name>", "Filter by entry name or /entry-N ID")
|
|
44
|
+
.addOption(new Option("--environment <environment>", "Filter by entry environment").choices(["client", "server"]))
|
|
45
|
+
.action(async (options, command) => {
|
|
46
|
+
// Commander can parse options owned by the parent before dispatching
|
|
47
|
+
// the subcommand. Do not silently ignore capture options on export.
|
|
48
|
+
const capture = analyze.opts();
|
|
49
|
+
if (capture.output ||
|
|
50
|
+
capture.outputDir !== undefined ||
|
|
51
|
+
capture.port !== undefined) {
|
|
52
|
+
command.error("error: --output, --output-dir and --port are only supported by ev analyze (capture).");
|
|
53
|
+
}
|
|
54
|
+
await runCommand("Analysis export failed", async () => {
|
|
55
|
+
const reportPath = path.resolve(dependencies.cwd(), options.report);
|
|
56
|
+
try {
|
|
57
|
+
for await (const record of dependencies.analysis.exportReport(reportPath, { entry: options.entry, environment: options.environment })) {
|
|
58
|
+
await dependencies.analysis.writeJsonLine(`${JSON.stringify(record)}\n`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
// A pipe consumer such as `head` can stop reading early.
|
|
63
|
+
if (error?.code !== "EPIPE") {
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export const bundleAnalysisActions = {
|
|
2
|
+
async capture(config, options) {
|
|
3
|
+
const [{ analyzeFrameworkBuild }, { utoopackAdapter }] = await Promise.all([
|
|
4
|
+
import("@evjs/ev/_internal/build/analyze"),
|
|
5
|
+
import("@evjs/bundler-utoopack"),
|
|
6
|
+
]);
|
|
7
|
+
return analyzeFrameworkBuild(config, {
|
|
8
|
+
...options,
|
|
9
|
+
bundler: config?.bundler ?? utoopackAdapter,
|
|
10
|
+
});
|
|
11
|
+
},
|
|
12
|
+
async serveReport(reportPath, port) {
|
|
13
|
+
const { serveBundleAnalysisReport } = await import("@evjs/bundler-utoopack/_internal/analyze");
|
|
14
|
+
return serveBundleAnalysisReport(reportPath, port);
|
|
15
|
+
},
|
|
16
|
+
async *exportReport(reportPath, filters) {
|
|
17
|
+
const { exportBundleAnalysisReport } = await import("@evjs/bundler-utoopack/_internal/analyze");
|
|
18
|
+
yield* exportBundleAnalysisReport(reportPath, filters);
|
|
19
|
+
},
|
|
20
|
+
writeJsonLine(line) {
|
|
21
|
+
const { stdout } = process;
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
// Wait for the write callback so a large report does not accumulate in
|
|
24
|
+
// stdout's buffer. A failed write also emits an error on the stream.
|
|
25
|
+
const onError = (error) => reject(error);
|
|
26
|
+
stdout.once("error", onError);
|
|
27
|
+
stdout.write(line, (error) => {
|
|
28
|
+
if (error) {
|
|
29
|
+
reject(error);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
stdout.off("error", onError);
|
|
33
|
+
resolve();
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Config } from "@evjs/ev/config";
|
|
2
2
|
import type { CliFlags } from "@evjs/ev/plugin";
|
|
3
|
+
import { type BundleAnalysisActions } from "../commands/analyze/command.js";
|
|
3
4
|
import { type InspectCommandOptions, type InspectCommandResult } from "../commands/inspect/command.js";
|
|
4
5
|
import type { DefaultBundlerConfig } from "../config/load.js";
|
|
5
6
|
type FrameworkCommand = (config: Config<DefaultBundlerConfig> | undefined, options: {
|
|
@@ -25,6 +26,7 @@ export interface CliProgramDependencies {
|
|
|
25
26
|
loadConfig: ConfigLoader;
|
|
26
27
|
dev: DevFrameworkCommand;
|
|
27
28
|
build: FrameworkCommand;
|
|
29
|
+
analysis: BundleAnalysisActions;
|
|
28
30
|
prepare: FrameworkCommand;
|
|
29
31
|
inspect(options: InspectCommandOptions): Promise<InspectCommandResult>;
|
|
30
32
|
writeStdout(output: string): void;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Command, CommanderError } from "commander";
|
|
2
|
+
import { registerAnalyzeCommand, } from "../commands/analyze/command.js";
|
|
2
3
|
import { formatInspectCommandErrorJson, } from "../commands/inspect/command.js";
|
|
3
4
|
import { parseCliFlags } from "./options.js";
|
|
4
5
|
export async function runCliProgram(argv, dependencies) {
|
|
@@ -57,6 +58,7 @@ export async function runCliProgram(argv, dependencies) {
|
|
|
57
58
|
await dependencies.build(config, { cwd, flags });
|
|
58
59
|
});
|
|
59
60
|
});
|
|
61
|
+
registerAnalyzeCommand(program, dependencies, runCommand);
|
|
60
62
|
program
|
|
61
63
|
.command("prepare")
|
|
62
64
|
.description("Generate .ev framework IR without running a bundler")
|
package/dist/program/run.js
CHANGED
|
@@ -3,7 +3,8 @@ import fs from "node:fs";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import { configure, getConsoleSink, getLogger } from "@logtape/logtape";
|
|
6
|
-
import { build,
|
|
6
|
+
import { build, prepare, runDev } from "../api/framework-commands.js";
|
|
7
|
+
import { bundleAnalysisActions } from "../commands/analyze/runtime.js";
|
|
7
8
|
import { runInspectCommand } from "../commands/inspect/command.js";
|
|
8
9
|
import { loadConfig } from "../config/load.js";
|
|
9
10
|
import { runCliProgram } from "./command-program.js";
|
|
@@ -51,8 +52,9 @@ export async function runCli(argv = process.argv) {
|
|
|
51
52
|
version: pkg.version,
|
|
52
53
|
cwd: () => process.cwd(),
|
|
53
54
|
loadConfig: (cwd, options) => loadConfig(cwd, options),
|
|
54
|
-
dev,
|
|
55
|
+
dev: (config, options) => runDev(config, options, true),
|
|
55
56
|
build,
|
|
57
|
+
analysis: bundleAnalysisActions,
|
|
56
58
|
prepare,
|
|
57
59
|
inspect: runInspectCommand,
|
|
58
60
|
writeStdout: (output) => process.stdout.write(output),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evjs/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.31",
|
|
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.
|
|
32
|
-
"@evjs/ev": "0.3.
|
|
31
|
+
"@evjs/bundler-utoopack": "0.3.31",
|
|
32
|
+
"@evjs/ev": "0.3.31",
|
|
33
33
|
"@logtape/logtape": "^2.0.4",
|
|
34
34
|
"commander": "^12.1.0"
|
|
35
35
|
},
|