@nasti-toolchain/nasti 1.3.9 → 1.4.0

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.d.cts CHANGED
@@ -5,6 +5,8 @@ interface NastiConfig {
5
5
  base?: string;
6
6
  /** 运行模式 */
7
7
  mode?: 'development' | 'production';
8
+ /** 打包目标平台:web(默认)或 electron */
9
+ target?: 'web' | 'electron';
8
10
  /** 框架自动检测或手动指定 */
9
11
  framework?: 'react' | 'vue' | 'auto';
10
12
  /** 路径解析配置 */
@@ -15,11 +17,44 @@ interface NastiConfig {
15
17
  server?: ServerConfig;
16
18
  /** 构建配置 */
17
19
  build?: BuildConfig;
20
+ /** Electron 配置(当 target === 'electron' 时生效) */
21
+ electron?: ElectronConfig;
18
22
  /** 环境变量前缀 */
19
23
  envPrefix?: string | string[];
20
24
  /** 日志级别 */
21
25
  logLevel?: 'info' | 'warn' | 'error' | 'silent';
22
26
  }
27
+ /** Electron 目标专用配置,支持 Electron 41+ */
28
+ interface ElectronConfig {
29
+ /** 主进程入口文件,相对项目根目录 */
30
+ main?: string;
31
+ /** Preload 脚本入口,相对项目根目录。可传入多个 */
32
+ preload?: string | string[];
33
+ /** 渲染进程(Web)入口 HTML,默认沿用根目录 index.html */
34
+ renderer?: string;
35
+ /**
36
+ * 主进程与 preload 打包目标 Node 版本。
37
+ * Electron 41 捆绑 Node 22.x,默认为 'node22'
38
+ */
39
+ nodeTarget?: string;
40
+ /**
41
+ * 主进程输出格式:cjs(默认,兼容 Electron 加载器)或 esm
42
+ * (Electron 41+ 完整支持 ESM 主进程)
43
+ */
44
+ mainFormat?: 'cjs' | 'esm';
45
+ /** Preload 输出格式,默认 cjs(Electron contextIsolation 推荐) */
46
+ preloadFormat?: 'cjs' | 'esm';
47
+ /** Electron 可执行文件路径,默认从 node_modules/electron 查找 */
48
+ electronPath?: string;
49
+ /** 传递给 Electron 的命令行参数(dev 模式) */
50
+ electronArgs?: string[];
51
+ /** 开发时主/preload 文件变化后自动重启 Electron,默认 true */
52
+ autoRestart?: boolean;
53
+ /** 声明最低 Electron 版本,默认 41(低于此版本将警告) */
54
+ minVersion?: number;
55
+ /** 主进程/preload 的外部依赖(不参与打包,运行时 require) */
56
+ external?: string[];
57
+ }
23
58
  interface ResolveConfig {
24
59
  alias?: Record<string, string>;
25
60
  extensions?: string[];
@@ -136,12 +171,14 @@ interface ResolvedConfig {
136
171
  root: string;
137
172
  base: string;
138
173
  mode: 'development' | 'production';
174
+ target: 'web' | 'electron';
139
175
  framework: 'react' | 'vue' | 'auto';
140
176
  command: 'build' | 'serve';
141
177
  resolve: Required<ResolveConfig>;
142
178
  plugins: NastiPlugin[];
143
179
  server: Required<ServerConfig>;
144
180
  build: Required<BuildConfig>;
181
+ electron: Required<ElectronConfig>;
145
182
  envPrefix: string[];
146
183
  logLevel: 'info' | 'warn' | 'error' | 'silent';
147
184
  }
@@ -200,6 +237,15 @@ interface HmrUpdate {
200
237
  }
201
238
 
202
239
  declare function defineConfig(config: NastiConfig): NastiConfig;
240
+ /**
241
+ * Resolve the final configuration by loading file-based config, merging with inline config, and applying plugin hooks.
242
+ *
243
+ * Loads configuration from the project root (derived from `inlineConfig.root` or defaults), deep-merges file config with `inlineConfig` (inline takes precedence), runs each plugin's `config` hook and incorporates any returned partial config, constructs the complete `ResolvedConfig` (filling defaults for missing values and resolving tsconfig paths), filters plugins according to their `apply` field, and then invokes each included plugin's `configResolved` hook.
244
+ *
245
+ * @param inlineConfig - User-provided configuration that overrides file config and defaults
246
+ * @param command - The current command, either `"build"` or `"serve"`, which influences mode and plugin filtering
247
+ * @returns The fully resolved configuration with defaults applied, plugins filtered, and plugin hooks executed
248
+ */
203
249
  declare function resolveConfig(inlineConfig: NastiConfig | undefined, command: 'build' | 'serve'): Promise<ResolvedConfig>;
204
250
 
205
251
  interface BuildResult {
@@ -212,6 +258,41 @@ interface BuildResult {
212
258
  }
213
259
  declare function build(inlineConfig?: NastiConfig): Promise<BuildResult>;
214
260
 
261
+ interface ElectronBuildResult {
262
+ rendererOutDir: string;
263
+ mainFile: string;
264
+ preloadFiles: string[];
265
+ }
266
+ /**
267
+ * Performs a full Electron build pipeline producing renderer, main, and preload artifacts.
268
+ *
269
+ * Resolves an Electron-targeted config, validates the installed Electron version, prepares the output directory, builds the renderer (via the web build), bundles the main process, bundles configured preload scripts, and logs a summary.
270
+ *
271
+ * @param inlineConfig - Optional config overrides merged into the resolved build configuration
272
+ * @returns An object with `rendererOutDir` (renderer output directory), `mainFile` (bundled main process file path), and `preloadFiles` (array of bundled preload file paths)
273
+ * @throws Error if the configured Electron main entry file does not exist
274
+ */
275
+ declare function buildElectron(inlineConfig?: NastiConfig): Promise<ElectronBuildResult>;
276
+
215
277
  declare function createServer(inlineConfig?: NastiConfig): Promise<DevServer>;
216
278
 
217
- export { type DevServer, type HmrPayload, type ModuleNode, type NastiConfig, type NastiPlugin, type ResolvedConfig, type TransformResult, build, createServer, defineConfig, resolveConfig };
279
+ interface ElectronDevOptions extends NastiConfig {
280
+ /** 不启动 Electron 进程,只编译主/preload(CI 场景) */
281
+ noSpawn?: boolean;
282
+ }
283
+ /**
284
+ * Start an Electron-focused development workflow: run the renderer dev server, build the main and preload bundles into .nasti/, and optionally spawn Electron with automatic restarts.
285
+ *
286
+ * @param inlineConfig - Development options; when `inlineConfig.noSpawn` is `true`, only compiles main/preload into `.nasti/` and does not start the Electron process.
287
+ */
288
+ declare function startElectronDev(inlineConfig?: ElectronDevOptions): Promise<void>;
289
+
290
+ /**
291
+ * Create a Vite/Rollup plugin that externalizes Electron and Node built-in imports according to the resolved config.
292
+ *
293
+ * @param config - Resolved build config; any entries in `config.electron.external` are added to the externalized modules set.
294
+ * @returns A plugin that marks `electron` and `electron/*` imports and Node built-in modules (including `node:`-prefixed names) as external.
295
+ */
296
+ declare function electronPlugin(config: ResolvedConfig): NastiPlugin;
297
+
298
+ export { type DevServer, type ElectronConfig, type HmrPayload, type ModuleNode, type NastiConfig, type NastiPlugin, type ResolvedConfig, type TransformResult, build, buildElectron, createServer, defineConfig, electronPlugin, resolveConfig, startElectronDev };
package/dist/index.d.ts CHANGED
@@ -5,6 +5,8 @@ interface NastiConfig {
5
5
  base?: string;
6
6
  /** 运行模式 */
7
7
  mode?: 'development' | 'production';
8
+ /** 打包目标平台:web(默认)或 electron */
9
+ target?: 'web' | 'electron';
8
10
  /** 框架自动检测或手动指定 */
9
11
  framework?: 'react' | 'vue' | 'auto';
10
12
  /** 路径解析配置 */
@@ -15,11 +17,44 @@ interface NastiConfig {
15
17
  server?: ServerConfig;
16
18
  /** 构建配置 */
17
19
  build?: BuildConfig;
20
+ /** Electron 配置(当 target === 'electron' 时生效) */
21
+ electron?: ElectronConfig;
18
22
  /** 环境变量前缀 */
19
23
  envPrefix?: string | string[];
20
24
  /** 日志级别 */
21
25
  logLevel?: 'info' | 'warn' | 'error' | 'silent';
22
26
  }
27
+ /** Electron 目标专用配置,支持 Electron 41+ */
28
+ interface ElectronConfig {
29
+ /** 主进程入口文件,相对项目根目录 */
30
+ main?: string;
31
+ /** Preload 脚本入口,相对项目根目录。可传入多个 */
32
+ preload?: string | string[];
33
+ /** 渲染进程(Web)入口 HTML,默认沿用根目录 index.html */
34
+ renderer?: string;
35
+ /**
36
+ * 主进程与 preload 打包目标 Node 版本。
37
+ * Electron 41 捆绑 Node 22.x,默认为 'node22'
38
+ */
39
+ nodeTarget?: string;
40
+ /**
41
+ * 主进程输出格式:cjs(默认,兼容 Electron 加载器)或 esm
42
+ * (Electron 41+ 完整支持 ESM 主进程)
43
+ */
44
+ mainFormat?: 'cjs' | 'esm';
45
+ /** Preload 输出格式,默认 cjs(Electron contextIsolation 推荐) */
46
+ preloadFormat?: 'cjs' | 'esm';
47
+ /** Electron 可执行文件路径,默认从 node_modules/electron 查找 */
48
+ electronPath?: string;
49
+ /** 传递给 Electron 的命令行参数(dev 模式) */
50
+ electronArgs?: string[];
51
+ /** 开发时主/preload 文件变化后自动重启 Electron,默认 true */
52
+ autoRestart?: boolean;
53
+ /** 声明最低 Electron 版本,默认 41(低于此版本将警告) */
54
+ minVersion?: number;
55
+ /** 主进程/preload 的外部依赖(不参与打包,运行时 require) */
56
+ external?: string[];
57
+ }
23
58
  interface ResolveConfig {
24
59
  alias?: Record<string, string>;
25
60
  extensions?: string[];
@@ -136,12 +171,14 @@ interface ResolvedConfig {
136
171
  root: string;
137
172
  base: string;
138
173
  mode: 'development' | 'production';
174
+ target: 'web' | 'electron';
139
175
  framework: 'react' | 'vue' | 'auto';
140
176
  command: 'build' | 'serve';
141
177
  resolve: Required<ResolveConfig>;
142
178
  plugins: NastiPlugin[];
143
179
  server: Required<ServerConfig>;
144
180
  build: Required<BuildConfig>;
181
+ electron: Required<ElectronConfig>;
145
182
  envPrefix: string[];
146
183
  logLevel: 'info' | 'warn' | 'error' | 'silent';
147
184
  }
@@ -200,6 +237,15 @@ interface HmrUpdate {
200
237
  }
201
238
 
202
239
  declare function defineConfig(config: NastiConfig): NastiConfig;
240
+ /**
241
+ * Resolve the final configuration by loading file-based config, merging with inline config, and applying plugin hooks.
242
+ *
243
+ * Loads configuration from the project root (derived from `inlineConfig.root` or defaults), deep-merges file config with `inlineConfig` (inline takes precedence), runs each plugin's `config` hook and incorporates any returned partial config, constructs the complete `ResolvedConfig` (filling defaults for missing values and resolving tsconfig paths), filters plugins according to their `apply` field, and then invokes each included plugin's `configResolved` hook.
244
+ *
245
+ * @param inlineConfig - User-provided configuration that overrides file config and defaults
246
+ * @param command - The current command, either `"build"` or `"serve"`, which influences mode and plugin filtering
247
+ * @returns The fully resolved configuration with defaults applied, plugins filtered, and plugin hooks executed
248
+ */
203
249
  declare function resolveConfig(inlineConfig: NastiConfig | undefined, command: 'build' | 'serve'): Promise<ResolvedConfig>;
204
250
 
205
251
  interface BuildResult {
@@ -212,6 +258,41 @@ interface BuildResult {
212
258
  }
213
259
  declare function build(inlineConfig?: NastiConfig): Promise<BuildResult>;
214
260
 
261
+ interface ElectronBuildResult {
262
+ rendererOutDir: string;
263
+ mainFile: string;
264
+ preloadFiles: string[];
265
+ }
266
+ /**
267
+ * Performs a full Electron build pipeline producing renderer, main, and preload artifacts.
268
+ *
269
+ * Resolves an Electron-targeted config, validates the installed Electron version, prepares the output directory, builds the renderer (via the web build), bundles the main process, bundles configured preload scripts, and logs a summary.
270
+ *
271
+ * @param inlineConfig - Optional config overrides merged into the resolved build configuration
272
+ * @returns An object with `rendererOutDir` (renderer output directory), `mainFile` (bundled main process file path), and `preloadFiles` (array of bundled preload file paths)
273
+ * @throws Error if the configured Electron main entry file does not exist
274
+ */
275
+ declare function buildElectron(inlineConfig?: NastiConfig): Promise<ElectronBuildResult>;
276
+
215
277
  declare function createServer(inlineConfig?: NastiConfig): Promise<DevServer>;
216
278
 
217
- export { type DevServer, type HmrPayload, type ModuleNode, type NastiConfig, type NastiPlugin, type ResolvedConfig, type TransformResult, build, createServer, defineConfig, resolveConfig };
279
+ interface ElectronDevOptions extends NastiConfig {
280
+ /** 不启动 Electron 进程,只编译主/preload(CI 场景) */
281
+ noSpawn?: boolean;
282
+ }
283
+ /**
284
+ * Start an Electron-focused development workflow: run the renderer dev server, build the main and preload bundles into .nasti/, and optionally spawn Electron with automatic restarts.
285
+ *
286
+ * @param inlineConfig - Development options; when `inlineConfig.noSpawn` is `true`, only compiles main/preload into `.nasti/` and does not start the Electron process.
287
+ */
288
+ declare function startElectronDev(inlineConfig?: ElectronDevOptions): Promise<void>;
289
+
290
+ /**
291
+ * Create a Vite/Rollup plugin that externalizes Electron and Node built-in imports according to the resolved config.
292
+ *
293
+ * @param config - Resolved build config; any entries in `config.electron.external` are added to the externalized modules set.
294
+ * @returns A plugin that marks `electron` and `electron/*` imports and Node built-in modules (including `node:`-prefixed names) as external.
295
+ */
296
+ declare function electronPlugin(config: ResolvedConfig): NastiPlugin;
297
+
298
+ export { type DevServer, type ElectronConfig, type HmrPayload, type ModuleNode, type NastiConfig, type NastiPlugin, type ResolvedConfig, type TransformResult, build, buildElectron, createServer, defineConfig, electronPlugin, resolveConfig, startElectronDev };