@nasti-toolchain/nasti 2.2.0 → 2.3.1

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
@@ -1,4 +1,5 @@
1
1
  import { InputOptions, OutputOptions, RenderedChunk } from 'rolldown';
2
+ import { IncomingMessage, ServerResponse } from 'node:http';
2
3
 
3
4
  type LogType = 'error' | 'warn' | 'info';
4
5
  type LogLevel = LogType | 'silent';
@@ -95,10 +96,20 @@ interface EnvironmentOptions {
95
96
  */
96
97
  consumer?: 'client' | 'server';
97
98
  /**
98
- * 该环境的构建入口(相对 root)。client 环境忽略此项(入口从 index.html
99
- * 提取);非 client 环境**只有声明了 entry 才会被 `nasti build` 构建**。
99
+ * 该环境的构建入口(相对 root)。client 默认从 HTML 提取;显式配置后可覆盖。
100
+ * client 环境只有声明 entry 或 driver 才会被 `nasti build` 构建。
100
101
  */
101
102
  entry?: string | string[];
103
+ /**
104
+ * HTML 入口(相对 root),仅 client consumer 使用。默认 `index.html`。
105
+ * Electron renderer 会把 `electron.renderer` 映射到这里。
106
+ */
107
+ html?: string;
108
+ /**
109
+ * 外部环境编译驱动标识。声明后由插件的 `createEnvironmentDriver` 提供实际实现,
110
+ * 可用于接入 Rspeedy 等不基于 Rolldown 的构建系统。
111
+ */
112
+ driver?: string;
102
113
  /** per-env 路径解析(client 默认含 'browser' condition;server 走 node conditions) */
103
114
  resolve?: ResolveConfig;
104
115
  /** per-env 构建覆盖(未设置的字段回退 top-level build) */
@@ -107,8 +118,12 @@ interface EnvironmentOptions {
107
118
  /** 解析后的环境配置 */
108
119
  interface ResolvedEnvironmentOptions {
109
120
  consumer: 'client' | 'server';
110
- /** client 环境的构建入口(绝对路径);client 恒为 [] */
121
+ /** 环境构建入口(绝对路径);client 未显式配置时为空并从 HTML 提取 */
111
122
  entry: string[];
123
+ /** HTML 入口绝对路径(仅 client consumer 有值) */
124
+ html?: string;
125
+ /** 外部环境编译驱动标识 */
126
+ driver?: string;
112
127
  resolve: Required<ResolveConfig>;
113
128
  build: Required<BuildConfig>;
114
129
  }
@@ -217,10 +232,16 @@ interface CssConfig {
217
232
  interface NastiPlugin {
218
233
  name: string;
219
234
  enforce?: 'pre' | 'post';
235
+ /** 必须在当前插件 setup 前完成 setup 的插件名 */
236
+ pre?: string[];
237
+ /** 必须在当前插件 setup 后完成 setup 的插件名 */
238
+ post?: string[];
220
239
  apply?: 'build' | 'serve' | ((config: ResolvedConfig, env: {
221
240
  mode: string;
222
241
  command: string;
223
242
  }) => boolean);
243
+ /** 插件初始化与跨插件 API 注册;每次 resolveConfig 只执行一次 */
244
+ setup?: (api: PluginApi) => void | Promise<void>;
224
245
  buildStart?: (this: PluginContext) => void | Promise<void>;
225
246
  buildEnd?: (this: PluginContext, error?: Error) => void | Promise<void>;
226
247
  /**
@@ -272,6 +293,16 @@ interface NastiPlugin {
272
293
  * 插件管线。未声明时插件应用于所有环境(与 Vite 默认一致)。
273
294
  */
274
295
  applyToEnvironment?: (environment: EnvironmentInstance) => boolean;
296
+ /**
297
+ * 为声明了 `environment.options.driver` 的环境提供外部编译驱动。
298
+ * 一个环境只能被一个插件接管;返回多个驱动会报错。
299
+ */
300
+ createEnvironmentDriver?: (environment: EnvironmentInstance, api: PluginApi) => EnvironmentDriver | null | undefined | Promise<EnvironmentDriver | null | undefined>;
301
+ /**
302
+ * 所有环境构建完成后的 app 级收尾钩子,用于跨环境聚合产物。
303
+ * Vue Lynx 原生后端可在这里组合 background/main-thread bundle。
304
+ */
305
+ afterBuildApp?: (results: Record<string, EnvironmentBuildResult>, api: PluginApi) => void | Promise<void>;
275
306
  configureServer?: (server: DevServer) => void | (() => void) | Promise<void | (() => void)>;
276
307
  transformIndexHtml?: (html: string) => string | HtmlTagDescriptor[] | {
277
308
  html: string;
@@ -292,6 +323,50 @@ interface PluginContext {
292
323
  */
293
324
  environment?: EnvironmentInstance;
294
325
  }
326
+ type PluginApiKey = string | symbol;
327
+ /** 插件 setup 与环境驱动共享的跨插件 API。 */
328
+ interface PluginApi {
329
+ readonly config: ResolvedConfig;
330
+ readonly logger: Logger;
331
+ expose: <T>(key: PluginApiKey, value: T) => void;
332
+ useExposed: <T>(key: PluginApiKey) => T | undefined;
333
+ }
334
+ interface EnvironmentBuildOutput {
335
+ fileName: string;
336
+ type: string;
337
+ code?: string;
338
+ source?: Uint8Array | string;
339
+ }
340
+ /** 外部环境驱动返回的标准构建结果。 */
341
+ interface EnvironmentBuildResult {
342
+ output: EnvironmentBuildOutput[];
343
+ entries?: Record<string, string>;
344
+ publicPath?: string;
345
+ manifest?: unknown;
346
+ stats?: unknown;
347
+ }
348
+ /** 外部环境驱动返回的开发服务信息。 */
349
+ interface EnvironmentServeResult {
350
+ localUrls?: string[];
351
+ networkUrls?: string[];
352
+ middleware?: (request: IncomingMessage, response: ServerResponse, next: (error?: unknown) => void) => void;
353
+ }
354
+ interface EnvironmentDriverContext {
355
+ environment: EnvironmentInstance;
356
+ config: ResolvedConfig;
357
+ api: PluginApi;
358
+ logger: Logger;
359
+ }
360
+ interface EnvironmentDriverServeContext extends EnvironmentDriverContext {
361
+ server: DevServer;
362
+ }
363
+ interface EnvironmentDriver {
364
+ name: string;
365
+ build?: (context: EnvironmentDriverContext) => EnvironmentBuildResult | Promise<EnvironmentBuildResult>;
366
+ serve?: (context: EnvironmentDriverServeContext) => EnvironmentServeResult | void | Promise<EnvironmentServeResult | void>;
367
+ watchChange?: (file: string, event: 'add' | 'change' | 'unlink', context: EnvironmentDriverContext) => void | Promise<void>;
368
+ close?: (context: EnvironmentDriverContext) => void | Promise<void>;
369
+ }
295
370
  /**
296
371
  * 环境实例的公共面(核心实现见 core/environment.ts 的 NastiEnvironment)。
297
372
  * 插件经 `this.environment` / `applyToEnvironment(env)` 感知环境。
@@ -303,6 +378,8 @@ interface EnvironmentInstance {
303
378
  config: ResolvedConfig;
304
379
  options: ResolvedEnvironmentOptions;
305
380
  hot: HotChannel;
381
+ /** 声明 driver 后,由插件提供的外部环境编译驱动 */
382
+ driver?: EnvironmentDriver;
306
383
  }
307
384
  /**
308
385
  * renderChunk / augmentChunkHash 的 `this`:Rolldown 真实插件上下文的最小可用面。
@@ -368,7 +445,8 @@ interface ResolvedConfig {
368
445
  base: string;
369
446
  mode: 'development' | 'production';
370
447
  target: 'web' | 'electron';
371
- framework: 'react' | 'vue' | 'auto';
448
+ /** `auto` 在配置解析阶段已收敛为具体框架 */
449
+ framework: 'react' | 'vue';
372
450
  command: 'build' | 'serve';
373
451
  resolve: Required<ResolveConfig>;
374
452
  plugins: NastiPlugin[];
@@ -400,6 +478,8 @@ interface DevServer {
400
478
  ws: WebSocketServer;
401
479
  /** Environment API:per-env 环境实例(Phase 1 仅 client 有完整运行时) */
402
480
  environments: Record<string, EnvironmentInstance>;
481
+ /** 外部环境驱动启动后返回的服务 URL / middleware 信息 */
482
+ environmentServices: Record<string, EnvironmentServeResult>;
403
483
  listen: (port?: number) => Promise<DevServer>;
404
484
  close: () => Promise<void>;
405
485
  transformRequest: (url: string) => Promise<TransformResult>;
@@ -482,6 +562,13 @@ interface HmrUpdate {
482
562
  }
483
563
 
484
564
  declare function defineConfig(config: NastiConfig): NastiConfig;
565
+ /**
566
+ * 将 framework:auto 收敛为具体框架。
567
+ *
568
+ * 优先使用源码中的 .vue 文件消除同时安装 React/Vue 时的歧义,其次读取
569
+ * package.json dependencies,最后回退 React 以保持 1.x 默认行为。
570
+ */
571
+ declare function detectFramework(root: string): 'react' | 'vue';
485
572
  /**
486
573
  * Resolve the final configuration by loading file-based config, merging with inline config, and applying plugin hooks.
487
574
  *
@@ -559,6 +646,8 @@ interface NastiEnvironmentInit {
559
646
  mode?: 'dev' | 'build';
560
647
  /** 环境的候选插件(init 时经 applyToEnvironment 过滤) */
561
648
  plugins?: NastiPlugin[];
649
+ /** 配置解析阶段创建的共享插件 API;通常自动从 ResolvedConfig 获取 */
650
+ pluginApi?: PluginApi;
562
651
  }
563
652
  declare class NastiEnvironment implements EnvironmentInstance {
564
653
  readonly name: string;
@@ -567,6 +656,7 @@ declare class NastiEnvironment implements EnvironmentInstance {
567
656
  readonly config: ResolvedConfig;
568
657
  readonly options: ResolvedEnvironmentOptions;
569
658
  readonly hot: HotChannel;
659
+ driver?: EnvironmentDriver;
570
660
  /** applyToEnvironment 过滤后的插件(init() 后可用) */
571
661
  plugins: NastiPlugin[];
572
662
  /** per-env 插件容器(init() 后可用;dev 管线使用) */
@@ -574,10 +664,12 @@ declare class NastiEnvironment implements EnvironmentInstance {
574
664
  /** per-env 模块图(dev 管线使用) */
575
665
  moduleGraph: ModuleGraph;
576
666
  private candidatePlugins;
667
+ private pluginApi;
577
668
  private initialized;
578
669
  constructor(name: string, config: ResolvedConfig, init?: NastiEnvironmentInit);
579
670
  /** 过滤插件并建 per-env PluginContainer */
580
671
  init(): Promise<void>;
672
+ getDriverContext(): EnvironmentDriverContext;
581
673
  close(): Promise<void>;
582
674
  }
583
675
  /** 按 applyToEnvironment 过滤环境插件(未声明 = 应用于所有环境) */
@@ -585,14 +677,11 @@ declare function resolveEnvironmentPlugins(environment: EnvironmentInstance, plu
585
677
 
586
678
  interface BuildResult {
587
679
  /** client 环境的产物(back-compat:1.x 的 BuildResult 形态) */
588
- output: Array<{
589
- fileName: string;
590
- type: string;
591
- code?: string;
592
- source?: Uint8Array | string;
593
- }>;
680
+ output: EnvironmentBuildOutput[];
594
681
  /** 全部已构建环境的产物(2.0 多环境 builder) */
595
682
  environments?: Record<string, BuildResult['output']>;
683
+ /** 环境驱动返回的完整结果(entries / manifest / stats 等) */
684
+ environmentResults?: Record<string, EnvironmentBuildResult>;
596
685
  }
597
686
  declare function build(inlineConfig?: NastiConfig): Promise<BuildResult>;
598
687
 
@@ -611,6 +700,13 @@ interface ElectronBuildResult {
611
700
  * @throws Error if the configured Electron main entry file does not exist
612
701
  */
613
702
  declare function buildElectron(inlineConfig?: NastiConfig): Promise<ElectronBuildResult>;
703
+ /**
704
+ * 从 Electron 配置派生 renderer 的普通 Web 构建配置。
705
+ *
706
+ * renderer 使用指定 HTML 入口;本地文件加载场景默认把 `/` base 收敛为
707
+ * `./`,避免产物中的 `/assets/*` 被解析到文件系统根目录。
708
+ */
709
+ declare function createElectronRendererConfig(config: ResolvedConfig, inlineConfig?: NastiConfig, overrides?: Pick<NastiConfig, 'build'>): NastiConfig;
614
710
 
615
711
  declare function createServer(inlineConfig?: NastiConfig): Promise<DevServer>;
616
712
 
@@ -624,6 +720,8 @@ interface ElectronDevOptions extends NastiConfig {
624
720
  * @param inlineConfig - Development options; when `inlineConfig.noSpawn` is `true`, only compiles main/preload into `.nasti/` and does not start the Electron process.
625
721
  */
626
722
  declare function startElectronDev(inlineConfig?: ElectronDevOptions): Promise<void>;
723
+ /** 将 renderer HTML 路径转换为 Electron 开发服务器 URL path。 */
724
+ declare function electronRendererDevPath(renderer: string): string;
627
725
 
628
726
  /**
629
727
  * Create a Vite/Rollup plugin that externalizes Electron and Node built-in imports according to the resolved config.
@@ -690,4 +788,4 @@ declare function buildEnvDefine(env: EnvRecord, mode: string, overrides?: Record
690
788
  /** 按环境 consumer 派生 import.meta.env.SSR 的 define 覆盖 */
691
789
  declare function ssrDefineOverrides(consumer: 'client' | 'server'): Record<string, string>;
692
790
 
693
- export { type BuildConfig, type DevServer, type ElectronConfig, type EnvironmentInstance, type EnvironmentOptions, type HmrPayload, type HotChannel, type HotChannelClient, type HotChannelInvokeHandlers, type LogLevel, LogLevels, type LogOptions, type Logger, type ModuleNode, type MonacoCustomWorker, type MonacoEditorLanguageWorker, type MonacoEditorPluginOptions, type NastiConfig, NastiEnvironment, type NastiPlugin, type NastiRolldownOptions, type PluginContext, type RenderChunkContext, type ResolvedConfig, type ResolvedEnvironmentOptions, type TransformResult, build, buildElectron, buildEnvDefine, createDebugger, createLogger, createNoopHotChannel, createServer, createWsHotChannel, defineConfig, electronPlugin, loadEnv, monacoEditorPlugin, printServerUrls, resolveConfig, resolveEnvironmentPlugins, ssrDefineOverrides, startElectronDev };
791
+ export { type BuildConfig, type DevServer, type ElectronConfig, type EnvironmentBuildOutput, type EnvironmentBuildResult, type EnvironmentDriver, type EnvironmentDriverContext, type EnvironmentDriverServeContext, type EnvironmentInstance, type EnvironmentOptions, type EnvironmentServeResult, type HmrPayload, type HotChannel, type HotChannelClient, type HotChannelInvokeHandlers, type LogLevel, LogLevels, type LogOptions, type Logger, type ModuleNode, type MonacoCustomWorker, type MonacoEditorLanguageWorker, type MonacoEditorPluginOptions, type NastiConfig, NastiEnvironment, type NastiPlugin, type NastiRolldownOptions, type PluginApi, type PluginApiKey, type PluginContext, type RenderChunkContext, type ResolvedConfig, type ResolvedEnvironmentOptions, type TransformResult, build, buildElectron, buildEnvDefine, createDebugger, createElectronRendererConfig, createLogger, createNoopHotChannel, createServer, createWsHotChannel, defineConfig, detectFramework, electronPlugin, electronRendererDevPath, loadEnv, monacoEditorPlugin, printServerUrls, resolveConfig, resolveEnvironmentPlugins, ssrDefineOverrides, startElectronDev };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { InputOptions, OutputOptions, RenderedChunk } from 'rolldown';
2
+ import { IncomingMessage, ServerResponse } from 'node:http';
2
3
 
3
4
  type LogType = 'error' | 'warn' | 'info';
4
5
  type LogLevel = LogType | 'silent';
@@ -95,10 +96,20 @@ interface EnvironmentOptions {
95
96
  */
96
97
  consumer?: 'client' | 'server';
97
98
  /**
98
- * 该环境的构建入口(相对 root)。client 环境忽略此项(入口从 index.html
99
- * 提取);非 client 环境**只有声明了 entry 才会被 `nasti build` 构建**。
99
+ * 该环境的构建入口(相对 root)。client 默认从 HTML 提取;显式配置后可覆盖。
100
+ * client 环境只有声明 entry 或 driver 才会被 `nasti build` 构建。
100
101
  */
101
102
  entry?: string | string[];
103
+ /**
104
+ * HTML 入口(相对 root),仅 client consumer 使用。默认 `index.html`。
105
+ * Electron renderer 会把 `electron.renderer` 映射到这里。
106
+ */
107
+ html?: string;
108
+ /**
109
+ * 外部环境编译驱动标识。声明后由插件的 `createEnvironmentDriver` 提供实际实现,
110
+ * 可用于接入 Rspeedy 等不基于 Rolldown 的构建系统。
111
+ */
112
+ driver?: string;
102
113
  /** per-env 路径解析(client 默认含 'browser' condition;server 走 node conditions) */
103
114
  resolve?: ResolveConfig;
104
115
  /** per-env 构建覆盖(未设置的字段回退 top-level build) */
@@ -107,8 +118,12 @@ interface EnvironmentOptions {
107
118
  /** 解析后的环境配置 */
108
119
  interface ResolvedEnvironmentOptions {
109
120
  consumer: 'client' | 'server';
110
- /** client 环境的构建入口(绝对路径);client 恒为 [] */
121
+ /** 环境构建入口(绝对路径);client 未显式配置时为空并从 HTML 提取 */
111
122
  entry: string[];
123
+ /** HTML 入口绝对路径(仅 client consumer 有值) */
124
+ html?: string;
125
+ /** 外部环境编译驱动标识 */
126
+ driver?: string;
112
127
  resolve: Required<ResolveConfig>;
113
128
  build: Required<BuildConfig>;
114
129
  }
@@ -217,10 +232,16 @@ interface CssConfig {
217
232
  interface NastiPlugin {
218
233
  name: string;
219
234
  enforce?: 'pre' | 'post';
235
+ /** 必须在当前插件 setup 前完成 setup 的插件名 */
236
+ pre?: string[];
237
+ /** 必须在当前插件 setup 后完成 setup 的插件名 */
238
+ post?: string[];
220
239
  apply?: 'build' | 'serve' | ((config: ResolvedConfig, env: {
221
240
  mode: string;
222
241
  command: string;
223
242
  }) => boolean);
243
+ /** 插件初始化与跨插件 API 注册;每次 resolveConfig 只执行一次 */
244
+ setup?: (api: PluginApi) => void | Promise<void>;
224
245
  buildStart?: (this: PluginContext) => void | Promise<void>;
225
246
  buildEnd?: (this: PluginContext, error?: Error) => void | Promise<void>;
226
247
  /**
@@ -272,6 +293,16 @@ interface NastiPlugin {
272
293
  * 插件管线。未声明时插件应用于所有环境(与 Vite 默认一致)。
273
294
  */
274
295
  applyToEnvironment?: (environment: EnvironmentInstance) => boolean;
296
+ /**
297
+ * 为声明了 `environment.options.driver` 的环境提供外部编译驱动。
298
+ * 一个环境只能被一个插件接管;返回多个驱动会报错。
299
+ */
300
+ createEnvironmentDriver?: (environment: EnvironmentInstance, api: PluginApi) => EnvironmentDriver | null | undefined | Promise<EnvironmentDriver | null | undefined>;
301
+ /**
302
+ * 所有环境构建完成后的 app 级收尾钩子,用于跨环境聚合产物。
303
+ * Vue Lynx 原生后端可在这里组合 background/main-thread bundle。
304
+ */
305
+ afterBuildApp?: (results: Record<string, EnvironmentBuildResult>, api: PluginApi) => void | Promise<void>;
275
306
  configureServer?: (server: DevServer) => void | (() => void) | Promise<void | (() => void)>;
276
307
  transformIndexHtml?: (html: string) => string | HtmlTagDescriptor[] | {
277
308
  html: string;
@@ -292,6 +323,50 @@ interface PluginContext {
292
323
  */
293
324
  environment?: EnvironmentInstance;
294
325
  }
326
+ type PluginApiKey = string | symbol;
327
+ /** 插件 setup 与环境驱动共享的跨插件 API。 */
328
+ interface PluginApi {
329
+ readonly config: ResolvedConfig;
330
+ readonly logger: Logger;
331
+ expose: <T>(key: PluginApiKey, value: T) => void;
332
+ useExposed: <T>(key: PluginApiKey) => T | undefined;
333
+ }
334
+ interface EnvironmentBuildOutput {
335
+ fileName: string;
336
+ type: string;
337
+ code?: string;
338
+ source?: Uint8Array | string;
339
+ }
340
+ /** 外部环境驱动返回的标准构建结果。 */
341
+ interface EnvironmentBuildResult {
342
+ output: EnvironmentBuildOutput[];
343
+ entries?: Record<string, string>;
344
+ publicPath?: string;
345
+ manifest?: unknown;
346
+ stats?: unknown;
347
+ }
348
+ /** 外部环境驱动返回的开发服务信息。 */
349
+ interface EnvironmentServeResult {
350
+ localUrls?: string[];
351
+ networkUrls?: string[];
352
+ middleware?: (request: IncomingMessage, response: ServerResponse, next: (error?: unknown) => void) => void;
353
+ }
354
+ interface EnvironmentDriverContext {
355
+ environment: EnvironmentInstance;
356
+ config: ResolvedConfig;
357
+ api: PluginApi;
358
+ logger: Logger;
359
+ }
360
+ interface EnvironmentDriverServeContext extends EnvironmentDriverContext {
361
+ server: DevServer;
362
+ }
363
+ interface EnvironmentDriver {
364
+ name: string;
365
+ build?: (context: EnvironmentDriverContext) => EnvironmentBuildResult | Promise<EnvironmentBuildResult>;
366
+ serve?: (context: EnvironmentDriverServeContext) => EnvironmentServeResult | void | Promise<EnvironmentServeResult | void>;
367
+ watchChange?: (file: string, event: 'add' | 'change' | 'unlink', context: EnvironmentDriverContext) => void | Promise<void>;
368
+ close?: (context: EnvironmentDriverContext) => void | Promise<void>;
369
+ }
295
370
  /**
296
371
  * 环境实例的公共面(核心实现见 core/environment.ts 的 NastiEnvironment)。
297
372
  * 插件经 `this.environment` / `applyToEnvironment(env)` 感知环境。
@@ -303,6 +378,8 @@ interface EnvironmentInstance {
303
378
  config: ResolvedConfig;
304
379
  options: ResolvedEnvironmentOptions;
305
380
  hot: HotChannel;
381
+ /** 声明 driver 后,由插件提供的外部环境编译驱动 */
382
+ driver?: EnvironmentDriver;
306
383
  }
307
384
  /**
308
385
  * renderChunk / augmentChunkHash 的 `this`:Rolldown 真实插件上下文的最小可用面。
@@ -368,7 +445,8 @@ interface ResolvedConfig {
368
445
  base: string;
369
446
  mode: 'development' | 'production';
370
447
  target: 'web' | 'electron';
371
- framework: 'react' | 'vue' | 'auto';
448
+ /** `auto` 在配置解析阶段已收敛为具体框架 */
449
+ framework: 'react' | 'vue';
372
450
  command: 'build' | 'serve';
373
451
  resolve: Required<ResolveConfig>;
374
452
  plugins: NastiPlugin[];
@@ -400,6 +478,8 @@ interface DevServer {
400
478
  ws: WebSocketServer;
401
479
  /** Environment API:per-env 环境实例(Phase 1 仅 client 有完整运行时) */
402
480
  environments: Record<string, EnvironmentInstance>;
481
+ /** 外部环境驱动启动后返回的服务 URL / middleware 信息 */
482
+ environmentServices: Record<string, EnvironmentServeResult>;
403
483
  listen: (port?: number) => Promise<DevServer>;
404
484
  close: () => Promise<void>;
405
485
  transformRequest: (url: string) => Promise<TransformResult>;
@@ -482,6 +562,13 @@ interface HmrUpdate {
482
562
  }
483
563
 
484
564
  declare function defineConfig(config: NastiConfig): NastiConfig;
565
+ /**
566
+ * 将 framework:auto 收敛为具体框架。
567
+ *
568
+ * 优先使用源码中的 .vue 文件消除同时安装 React/Vue 时的歧义,其次读取
569
+ * package.json dependencies,最后回退 React 以保持 1.x 默认行为。
570
+ */
571
+ declare function detectFramework(root: string): 'react' | 'vue';
485
572
  /**
486
573
  * Resolve the final configuration by loading file-based config, merging with inline config, and applying plugin hooks.
487
574
  *
@@ -559,6 +646,8 @@ interface NastiEnvironmentInit {
559
646
  mode?: 'dev' | 'build';
560
647
  /** 环境的候选插件(init 时经 applyToEnvironment 过滤) */
561
648
  plugins?: NastiPlugin[];
649
+ /** 配置解析阶段创建的共享插件 API;通常自动从 ResolvedConfig 获取 */
650
+ pluginApi?: PluginApi;
562
651
  }
563
652
  declare class NastiEnvironment implements EnvironmentInstance {
564
653
  readonly name: string;
@@ -567,6 +656,7 @@ declare class NastiEnvironment implements EnvironmentInstance {
567
656
  readonly config: ResolvedConfig;
568
657
  readonly options: ResolvedEnvironmentOptions;
569
658
  readonly hot: HotChannel;
659
+ driver?: EnvironmentDriver;
570
660
  /** applyToEnvironment 过滤后的插件(init() 后可用) */
571
661
  plugins: NastiPlugin[];
572
662
  /** per-env 插件容器(init() 后可用;dev 管线使用) */
@@ -574,10 +664,12 @@ declare class NastiEnvironment implements EnvironmentInstance {
574
664
  /** per-env 模块图(dev 管线使用) */
575
665
  moduleGraph: ModuleGraph;
576
666
  private candidatePlugins;
667
+ private pluginApi;
577
668
  private initialized;
578
669
  constructor(name: string, config: ResolvedConfig, init?: NastiEnvironmentInit);
579
670
  /** 过滤插件并建 per-env PluginContainer */
580
671
  init(): Promise<void>;
672
+ getDriverContext(): EnvironmentDriverContext;
581
673
  close(): Promise<void>;
582
674
  }
583
675
  /** 按 applyToEnvironment 过滤环境插件(未声明 = 应用于所有环境) */
@@ -585,14 +677,11 @@ declare function resolveEnvironmentPlugins(environment: EnvironmentInstance, plu
585
677
 
586
678
  interface BuildResult {
587
679
  /** client 环境的产物(back-compat:1.x 的 BuildResult 形态) */
588
- output: Array<{
589
- fileName: string;
590
- type: string;
591
- code?: string;
592
- source?: Uint8Array | string;
593
- }>;
680
+ output: EnvironmentBuildOutput[];
594
681
  /** 全部已构建环境的产物(2.0 多环境 builder) */
595
682
  environments?: Record<string, BuildResult['output']>;
683
+ /** 环境驱动返回的完整结果(entries / manifest / stats 等) */
684
+ environmentResults?: Record<string, EnvironmentBuildResult>;
596
685
  }
597
686
  declare function build(inlineConfig?: NastiConfig): Promise<BuildResult>;
598
687
 
@@ -611,6 +700,13 @@ interface ElectronBuildResult {
611
700
  * @throws Error if the configured Electron main entry file does not exist
612
701
  */
613
702
  declare function buildElectron(inlineConfig?: NastiConfig): Promise<ElectronBuildResult>;
703
+ /**
704
+ * 从 Electron 配置派生 renderer 的普通 Web 构建配置。
705
+ *
706
+ * renderer 使用指定 HTML 入口;本地文件加载场景默认把 `/` base 收敛为
707
+ * `./`,避免产物中的 `/assets/*` 被解析到文件系统根目录。
708
+ */
709
+ declare function createElectronRendererConfig(config: ResolvedConfig, inlineConfig?: NastiConfig, overrides?: Pick<NastiConfig, 'build'>): NastiConfig;
614
710
 
615
711
  declare function createServer(inlineConfig?: NastiConfig): Promise<DevServer>;
616
712
 
@@ -624,6 +720,8 @@ interface ElectronDevOptions extends NastiConfig {
624
720
  * @param inlineConfig - Development options; when `inlineConfig.noSpawn` is `true`, only compiles main/preload into `.nasti/` and does not start the Electron process.
625
721
  */
626
722
  declare function startElectronDev(inlineConfig?: ElectronDevOptions): Promise<void>;
723
+ /** 将 renderer HTML 路径转换为 Electron 开发服务器 URL path。 */
724
+ declare function electronRendererDevPath(renderer: string): string;
627
725
 
628
726
  /**
629
727
  * Create a Vite/Rollup plugin that externalizes Electron and Node built-in imports according to the resolved config.
@@ -690,4 +788,4 @@ declare function buildEnvDefine(env: EnvRecord, mode: string, overrides?: Record
690
788
  /** 按环境 consumer 派生 import.meta.env.SSR 的 define 覆盖 */
691
789
  declare function ssrDefineOverrides(consumer: 'client' | 'server'): Record<string, string>;
692
790
 
693
- export { type BuildConfig, type DevServer, type ElectronConfig, type EnvironmentInstance, type EnvironmentOptions, type HmrPayload, type HotChannel, type HotChannelClient, type HotChannelInvokeHandlers, type LogLevel, LogLevels, type LogOptions, type Logger, type ModuleNode, type MonacoCustomWorker, type MonacoEditorLanguageWorker, type MonacoEditorPluginOptions, type NastiConfig, NastiEnvironment, type NastiPlugin, type NastiRolldownOptions, type PluginContext, type RenderChunkContext, type ResolvedConfig, type ResolvedEnvironmentOptions, type TransformResult, build, buildElectron, buildEnvDefine, createDebugger, createLogger, createNoopHotChannel, createServer, createWsHotChannel, defineConfig, electronPlugin, loadEnv, monacoEditorPlugin, printServerUrls, resolveConfig, resolveEnvironmentPlugins, ssrDefineOverrides, startElectronDev };
791
+ export { type BuildConfig, type DevServer, type ElectronConfig, type EnvironmentBuildOutput, type EnvironmentBuildResult, type EnvironmentDriver, type EnvironmentDriverContext, type EnvironmentDriverServeContext, type EnvironmentInstance, type EnvironmentOptions, type EnvironmentServeResult, type HmrPayload, type HotChannel, type HotChannelClient, type HotChannelInvokeHandlers, type LogLevel, LogLevels, type LogOptions, type Logger, type ModuleNode, type MonacoCustomWorker, type MonacoEditorLanguageWorker, type MonacoEditorPluginOptions, type NastiConfig, NastiEnvironment, type NastiPlugin, type NastiRolldownOptions, type PluginApi, type PluginApiKey, type PluginContext, type RenderChunkContext, type ResolvedConfig, type ResolvedEnvironmentOptions, type TransformResult, build, buildElectron, buildEnvDefine, createDebugger, createElectronRendererConfig, createLogger, createNoopHotChannel, createServer, createWsHotChannel, defineConfig, detectFramework, electronPlugin, electronRendererDevPath, loadEnv, monacoEditorPlugin, printServerUrls, resolveConfig, resolveEnvironmentPlugins, ssrDefineOverrides, startElectronDev };