@nasti-toolchain/nasti 2.4.0 → 2.4.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/dist/index.d.cts CHANGED
@@ -1,5 +1,6 @@
1
- import { InputOptions, OutputOptions, RenderedChunk } from 'rolldown';
1
+ import { RenderedChunk, InputOptions, OutputOptions } from 'rolldown';
2
2
  import { IncomingMessage, ServerResponse } from 'node:http';
3
+ import { SFCParseOptions, SFCScriptCompileOptions, SFCTemplateCompileOptions, SFCAsyncStyleCompileOptions } from '@vue/compiler-sfc';
3
4
 
4
5
  type LogType = 'error' | 'warn' | 'info';
5
6
  type LogLevel = LogType | 'silent';
@@ -82,7 +83,7 @@ interface ExperimentalOptions {
82
83
  * dev 用 Rolldown `dev()` 引擎整体打包 client 环境后从内存服务
83
84
  * (完整打包模式 / Full Bundle Mode)。HMR 由引擎的 patch 机制驱动,
84
85
  * 动态 import 走懒编译端点。依赖 rolldown 实验 API(无 semver 保护,
85
- * 版本锁定 rc.13)。unbundled 管线保持默认。
86
+ * Nasti 会精确锁定经过验证的 Rolldown 版本)。unbundled 管线保持默认。
86
87
  * @experimental
87
88
  * @default false
88
89
  */
@@ -119,6 +120,39 @@ interface EnvironmentOptions {
119
120
  resolve?: ResolveConfig;
120
121
  /** per-env 构建覆盖(未设置的字段回退 top-level build) */
121
122
  build?: BuildConfig;
123
+ /**
124
+ * Vue SFC 编译扩展点。每个环境可独立设置 compiler-sfc 选项与源码变换,
125
+ * 同一个 SFC 的虚拟模块 id / scope id 不包含环境名,因而在多图之间保持稳定。
126
+ */
127
+ vue?: VueEnvironmentOptions;
128
+ }
129
+ interface VueSfcTransformContext {
130
+ filename: string;
131
+ environmentName: string;
132
+ type: 'sfc' | 'template' | 'style';
133
+ index?: number;
134
+ }
135
+ type VueSfcSourceTransform = (source: string, context: VueSfcTransformContext) => string
136
+ /**
137
+ * Object results may provide a source map from `code` back to `source`.
138
+ * Nasti composes it with compiler-sfc maps where that stage supports chaining.
139
+ */
140
+ | {
141
+ code: string;
142
+ map?: unknown;
143
+ } | Promise<string | {
144
+ code: string;
145
+ map?: unknown;
146
+ }>;
147
+ /** 直接透传给 `@vue/compiler-sfc` 对应阶段的 per-environment 选项。 */
148
+ interface VueEnvironmentOptions {
149
+ parse?: SFCParseOptions;
150
+ script?: Partial<SFCScriptCompileOptions>;
151
+ template?: Partial<SFCTemplateCompileOptions>;
152
+ style?: Partial<SFCAsyncStyleCompileOptions>;
153
+ transformSfc?: VueSfcSourceTransform;
154
+ transformTemplate?: VueSfcSourceTransform;
155
+ transformStyle?: VueSfcSourceTransform;
122
156
  }
123
157
  /** 解析后的环境配置 */
124
158
  interface ResolvedEnvironmentOptions {
@@ -133,6 +167,7 @@ interface ResolvedEnvironmentOptions {
133
167
  driver?: string;
134
168
  resolve: Required<ResolveConfig>;
135
169
  build: Required<BuildConfig>;
170
+ vue: VueEnvironmentOptions;
136
171
  }
137
172
  /** Electron 目标专用配置,支持 Electron 41+ */
138
173
  interface ElectronConfig {
@@ -231,10 +266,21 @@ interface CssConfig {
231
266
  /** CSP nonce to add to inline <style> tags (dev only since 2.0 — build emits real .css files) */
232
267
  nonce?: string;
233
268
  /**
234
- * @deprecated 2.0 起 build 始终抽取真实 .css 文件(per-chunk hash + <link> 注入),
235
- * 该开关不再生效。控制拆分用 `build.cssCodeSplit`,控制压缩用 `build.cssMinify`。
269
+ * @deprecated 请改用 `css.emit` 控制是否写出 CSS 文件。控制拆分用
270
+ * `build.cssCodeSplit`,控制压缩用 `build.cssMinify`。
236
271
  */
237
272
  emitCssFile?: boolean;
273
+ /**
274
+ * 是否在浏览器运行时 / HTML 中注入 CSS。原生 client 环境可关闭注入,
275
+ * 同时继续保留 CSS 模块图与结构化元数据。
276
+ * @default true
277
+ */
278
+ inject?: boolean;
279
+ /**
280
+ * 是否写出 `.css` 文件。关闭后仍收集每个 chunk 的 CSS 所有权。
281
+ * @default true
282
+ */
283
+ emit?: boolean;
238
284
  }
239
285
  interface NastiPlugin {
240
286
  name: string;
@@ -319,6 +365,11 @@ interface NastiPlugin {
319
365
  tags: HtmlTagDescriptor[];
320
366
  }>;
321
367
  handleHotUpdate?: (ctx: HmrContext) => void | ModuleNode[] | Promise<void | ModuleNode[]>;
368
+ /**
369
+ * 一个文件在所有 dev client 环境完成失效、插件 HMR 钩子与重新转换后调用一次。
370
+ * 多运行时工具链可据此只重编码受影响的 native section。
371
+ */
372
+ handleHotUpdateApp?: (ctx: AppHmrContext) => void | Promise<void>;
322
373
  }
323
374
  interface PluginContext {
324
375
  resolve: (source: string, importer?: string) => Promise<ResolveIdResult>;
@@ -343,6 +394,44 @@ interface EnvironmentBuildOutput {
343
394
  type: string;
344
395
  code?: string;
345
396
  source?: Uint8Array | string;
397
+ map?: unknown;
398
+ name?: string;
399
+ names?: string[];
400
+ isEntry?: boolean;
401
+ isDynamicEntry?: boolean;
402
+ imports?: string[];
403
+ dynamicImports?: string[];
404
+ moduleIds?: string[];
405
+ }
406
+ interface EnvironmentCssModule {
407
+ id: string;
408
+ source: string;
409
+ code: string;
410
+ }
411
+ interface EnvironmentCssChunk {
412
+ fileName: string;
413
+ moduleIds: string[];
414
+ cssFileNames: string[];
415
+ }
416
+ interface EnvironmentCssMetadata {
417
+ modules: Record<string, EnvironmentCssModule>;
418
+ chunks: Record<string, EnvironmentCssChunk>;
419
+ }
420
+ interface EnvironmentChunkMetadata {
421
+ fileName: string;
422
+ name: string;
423
+ isEntry: boolean;
424
+ isDynamicEntry: boolean;
425
+ imports: string[];
426
+ dynamicImports: string[];
427
+ moduleIds: string[];
428
+ css: string[];
429
+ assets: string[];
430
+ }
431
+ interface EnvironmentAssetMetadata {
432
+ fileName: string;
433
+ names: string[];
434
+ publicPath: string;
346
435
  }
347
436
  /** 单个环境附加到标准构建结果上的结构化元数据。 */
348
437
  interface EnvironmentBuildMetadata {
@@ -350,6 +439,10 @@ interface EnvironmentBuildMetadata {
350
439
  publicPath?: string;
351
440
  manifest?: unknown;
352
441
  stats?: unknown;
442
+ chunks?: Record<string, EnvironmentChunkMetadata>;
443
+ assets?: Record<string, EnvironmentAssetMetadata>;
444
+ css?: EnvironmentCssMetadata;
445
+ sourceMaps?: Record<string, unknown>;
353
446
  }
354
447
  /** 外部环境驱动或原生 Rolldown 环境返回的标准构建结果。 */
355
448
  interface EnvironmentBuildResult extends EnvironmentBuildMetadata {
@@ -372,6 +465,10 @@ interface BuildAppContext {
372
465
  getArtifact: (environmentName: string, fileName: string) => EnvironmentBuildOutput | undefined;
373
466
  getEntry: (environmentName: string, entryName: string) => EnvironmentBuildOutput | undefined;
374
467
  getManifest: <T = unknown>(environmentName: string) => T | undefined;
468
+ getChunk: (environmentName: string, fileName: string) => EnvironmentChunkMetadata | undefined;
469
+ getCss: (environmentName: string) => EnvironmentCssMetadata | undefined;
470
+ getSourceMap: (environmentName: string, fileName: string) => unknown;
471
+ resolvePublicPath: (environmentName: string, fileName: string) => string | undefined;
375
472
  /** 将聚合产物安全地写入 top-level `build.outDir`,并纳入 BuildResult.appOutput。 */
376
473
  emitFile: (file: AppBuildOutput) => string;
377
474
  }
@@ -410,6 +507,22 @@ interface EnvironmentInstance {
410
507
  hot: HotChannel;
411
508
  /** 声明 driver 后,由插件提供的外部环境编译驱动 */
412
509
  driver?: EnvironmentDriver;
510
+ /** per-environment dev 模块图与插件列表。 */
511
+ moduleGraph: ModuleGraph$1;
512
+ plugins: NastiPlugin[];
513
+ /**
514
+ * 在该环境的独立 transform 管线中请求模块。仅 dev 环境在初始化后可用。
515
+ */
516
+ transformRequest: (url: string) => Promise<{
517
+ code: string;
518
+ map?: unknown;
519
+ } | null>;
520
+ /** 内置 CSS 管线登记模块;工具链通常读取 getCssModule(s)。 */
521
+ setCssModule: (module: EnvironmentCssModule) => void;
522
+ getCssModule: (id: string) => EnvironmentCssModule | undefined;
523
+ getCssModules: () => Readonly<Record<string, EnvironmentCssModule>>;
524
+ setAssetModule: (id: string, fileName: string) => void;
525
+ getAssetModules: () => Readonly<Record<string, string>>;
413
526
  /** 由生产插件登记 entries / manifest / stats,构建完成后合并进环境结果。 */
414
527
  setBuildMetadata: (metadata: EnvironmentBuildMetadata) => void;
415
528
  }
@@ -512,13 +625,14 @@ interface DevServer {
512
625
  moduleGraph: ModuleGraph$1;
513
626
  watcher: any;
514
627
  ws: WebSocketServer;
515
- /** Environment API:per-env 环境实例(Phase 1 client 有完整运行时) */
628
+ /** Environment API:每个 client-consumer 环境都有独立的 transform/HMR 管线。 */
516
629
  environments: Record<string, EnvironmentInstance>;
517
630
  /** 外部环境驱动启动后返回的服务 URL / middleware 信息 */
518
631
  environmentServices: Record<string, EnvironmentServeResult>;
519
632
  listen: (port?: number) => Promise<DevServer>;
520
633
  close: () => Promise<void>;
521
634
  transformRequest: (url: string) => Promise<TransformResult>;
635
+ transformEnvironmentRequest: (environmentName: string, url: string) => Promise<TransformResult>;
522
636
  /**
523
637
  * SSR:在 server consumer 环境(默认 `ssr`)中加载并执行模块,返回其导出。
524
638
  * Vite `server.ssrLoadModule` 的 back-compat shim(底层是 module runner +
@@ -576,8 +690,29 @@ interface HmrContext {
576
690
  modules: ModuleNode[];
577
691
  read: () => string | Promise<string>;
578
692
  server: DevServer;
693
+ environment: EnvironmentInstance;
579
694
  }
580
- type HmrPayload = {
695
+ interface EnvironmentTransformedModule {
696
+ module: ModuleNode;
697
+ result: {
698
+ code: string;
699
+ map?: unknown;
700
+ } | null;
701
+ }
702
+ interface EnvironmentHotUpdateResult {
703
+ environment: EnvironmentInstance;
704
+ modules: ModuleNode[];
705
+ updates: HmrUpdate[];
706
+ transformed: EnvironmentTransformedModule[];
707
+ fullReload: boolean;
708
+ }
709
+ interface AppHmrContext {
710
+ file: string;
711
+ timestamp: number;
712
+ environments: Readonly<Record<string, EnvironmentHotUpdateResult>>;
713
+ server: DevServer;
714
+ }
715
+ type HmrPayload = ({
581
716
  type: 'connected';
582
717
  } | {
583
718
  type: 'update';
@@ -594,6 +729,12 @@ type HmrPayload = {
594
729
  message: string;
595
730
  stack?: string;
596
731
  };
732
+ } | {
733
+ type: 'custom';
734
+ event: string;
735
+ data?: unknown;
736
+ }) & {
737
+ environment?: string;
597
738
  };
598
739
  interface HmrUpdate {
599
740
  type: 'js-update' | 'css-update';
@@ -651,9 +792,11 @@ declare class PluginContainer {
651
792
  }
652
793
 
653
794
  declare class ModuleGraph {
795
+ readonly environmentName: string;
654
796
  private urlToModuleMap;
655
797
  private idToModuleMap;
656
798
  private fileToModulesMap;
799
+ constructor(environmentName?: string);
657
800
  getModuleByUrl(url: string): ModuleNode | undefined;
658
801
  getModuleById(id: string): ModuleNode | undefined;
659
802
  getModulesByFile(file: string): Set<ModuleNode> | undefined;
@@ -717,11 +860,27 @@ declare class NastiEnvironment implements EnvironmentInstance {
717
860
  private candidatePlugins;
718
861
  private pluginApi;
719
862
  private buildMetadata;
863
+ private cssModules;
864
+ private assetModules;
865
+ private transformRequestHandler?;
720
866
  private initialized;
721
867
  constructor(name: string, config: ResolvedConfig, init?: NastiEnvironmentInit);
722
868
  /** 过滤插件并建 per-env PluginContainer */
723
869
  init(): Promise<void>;
724
870
  getDriverContext(): EnvironmentDriverContext;
871
+ configureDevPipeline(transformRequest: (url: string) => Promise<{
872
+ code: string;
873
+ map?: unknown;
874
+ } | null>): void;
875
+ transformRequest(url: string): Promise<{
876
+ code: string;
877
+ map?: unknown;
878
+ } | null>;
879
+ setCssModule(module: EnvironmentCssModule): void;
880
+ getCssModule(id: string): EnvironmentCssModule | undefined;
881
+ getCssModules(): Readonly<Record<string, EnvironmentCssModule>>;
882
+ setAssetModule(id: string, fileName: string): void;
883
+ getAssetModules(): Readonly<Record<string, string>>;
725
884
  setBuildMetadata(metadata: EnvironmentBuildMetadata): void;
726
885
  getBuildMetadata(): EnvironmentBuildMetadata;
727
886
  close(): Promise<void>;
@@ -808,13 +967,13 @@ interface MonacoEditorPluginOptions {
808
967
  }
809
968
  declare function monacoEditorPlugin(options?: MonacoEditorPluginOptions): NastiPlugin;
810
969
 
811
- /** 非 client 环境的占位通道(SSR/edge Phase 2 接上真实 transport) */
970
+ /** 非 client 环境的占位通道(SSR/edge 可由 runner/driver 接上真实 transport) */
812
971
  declare function createNoopHotChannel(): HotChannel;
813
972
  /**
814
- * client 环境的 ws 通道:包装 server/ws.ts 的 WebSocketServer。
815
- * 事件监听与 invoke 在现有 ws 协议上预留(custom event 协议 Phase 2 扩展)。
973
+ * client-consumer 环境的 ws 通道:包装 server/ws.ts 的 WebSocketServer。
974
+ * 事件监听与 invoke 在现有 ws 协议上预留,payload environment 字段分流。
816
975
  */
817
- declare function createWsHotChannel(ws: WebSocketServer): HotChannel;
976
+ declare function createWsHotChannel(ws: WebSocketServer, environmentName?: string): HotChannel;
818
977
 
819
978
  type NastiDebugScope = `nasti:${string}`;
820
979
  interface DebuggerOptions {
@@ -844,4 +1003,4 @@ declare function buildEnvDefine(env: EnvRecord, mode: string, overrides?: Record
844
1003
  /** 按环境 consumer 派生 import.meta.env.SSR 的 define 覆盖 */
845
1004
  declare function ssrDefineOverrides(consumer: 'client' | 'server'): Record<string, string>;
846
1005
 
847
- export { type AppBuildOutput, type BuildAppContext, type BuildConfig, type BuildResult, type DevServer, type ElectronConfig, type EnvironmentBuildMetadata, 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 };
1006
+ export { type AppBuildOutput, type AppHmrContext, type BuildAppContext, type BuildConfig, type BuildResult, type DevServer, type ElectronConfig, type EnvironmentAssetMetadata, type EnvironmentBuildMetadata, type EnvironmentBuildOutput, type EnvironmentBuildResult, type EnvironmentChunkMetadata, type EnvironmentCssChunk, type EnvironmentCssMetadata, type EnvironmentCssModule, type EnvironmentDriver, type EnvironmentDriverContext, type EnvironmentDriverServeContext, type EnvironmentHotUpdateResult, type EnvironmentInstance, type EnvironmentOptions, type EnvironmentServeResult, type EnvironmentTransformedModule, type HmrPayload, type HmrUpdate, 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, type VueEnvironmentOptions, type VueSfcSourceTransform, type VueSfcTransformContext, 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,5 +1,6 @@
1
- import { InputOptions, OutputOptions, RenderedChunk } from 'rolldown';
1
+ import { RenderedChunk, InputOptions, OutputOptions } from 'rolldown';
2
2
  import { IncomingMessage, ServerResponse } from 'node:http';
3
+ import { SFCParseOptions, SFCScriptCompileOptions, SFCTemplateCompileOptions, SFCAsyncStyleCompileOptions } from '@vue/compiler-sfc';
3
4
 
4
5
  type LogType = 'error' | 'warn' | 'info';
5
6
  type LogLevel = LogType | 'silent';
@@ -82,7 +83,7 @@ interface ExperimentalOptions {
82
83
  * dev 用 Rolldown `dev()` 引擎整体打包 client 环境后从内存服务
83
84
  * (完整打包模式 / Full Bundle Mode)。HMR 由引擎的 patch 机制驱动,
84
85
  * 动态 import 走懒编译端点。依赖 rolldown 实验 API(无 semver 保护,
85
- * 版本锁定 rc.13)。unbundled 管线保持默认。
86
+ * Nasti 会精确锁定经过验证的 Rolldown 版本)。unbundled 管线保持默认。
86
87
  * @experimental
87
88
  * @default false
88
89
  */
@@ -119,6 +120,39 @@ interface EnvironmentOptions {
119
120
  resolve?: ResolveConfig;
120
121
  /** per-env 构建覆盖(未设置的字段回退 top-level build) */
121
122
  build?: BuildConfig;
123
+ /**
124
+ * Vue SFC 编译扩展点。每个环境可独立设置 compiler-sfc 选项与源码变换,
125
+ * 同一个 SFC 的虚拟模块 id / scope id 不包含环境名,因而在多图之间保持稳定。
126
+ */
127
+ vue?: VueEnvironmentOptions;
128
+ }
129
+ interface VueSfcTransformContext {
130
+ filename: string;
131
+ environmentName: string;
132
+ type: 'sfc' | 'template' | 'style';
133
+ index?: number;
134
+ }
135
+ type VueSfcSourceTransform = (source: string, context: VueSfcTransformContext) => string
136
+ /**
137
+ * Object results may provide a source map from `code` back to `source`.
138
+ * Nasti composes it with compiler-sfc maps where that stage supports chaining.
139
+ */
140
+ | {
141
+ code: string;
142
+ map?: unknown;
143
+ } | Promise<string | {
144
+ code: string;
145
+ map?: unknown;
146
+ }>;
147
+ /** 直接透传给 `@vue/compiler-sfc` 对应阶段的 per-environment 选项。 */
148
+ interface VueEnvironmentOptions {
149
+ parse?: SFCParseOptions;
150
+ script?: Partial<SFCScriptCompileOptions>;
151
+ template?: Partial<SFCTemplateCompileOptions>;
152
+ style?: Partial<SFCAsyncStyleCompileOptions>;
153
+ transformSfc?: VueSfcSourceTransform;
154
+ transformTemplate?: VueSfcSourceTransform;
155
+ transformStyle?: VueSfcSourceTransform;
122
156
  }
123
157
  /** 解析后的环境配置 */
124
158
  interface ResolvedEnvironmentOptions {
@@ -133,6 +167,7 @@ interface ResolvedEnvironmentOptions {
133
167
  driver?: string;
134
168
  resolve: Required<ResolveConfig>;
135
169
  build: Required<BuildConfig>;
170
+ vue: VueEnvironmentOptions;
136
171
  }
137
172
  /** Electron 目标专用配置,支持 Electron 41+ */
138
173
  interface ElectronConfig {
@@ -231,10 +266,21 @@ interface CssConfig {
231
266
  /** CSP nonce to add to inline <style> tags (dev only since 2.0 — build emits real .css files) */
232
267
  nonce?: string;
233
268
  /**
234
- * @deprecated 2.0 起 build 始终抽取真实 .css 文件(per-chunk hash + <link> 注入),
235
- * 该开关不再生效。控制拆分用 `build.cssCodeSplit`,控制压缩用 `build.cssMinify`。
269
+ * @deprecated 请改用 `css.emit` 控制是否写出 CSS 文件。控制拆分用
270
+ * `build.cssCodeSplit`,控制压缩用 `build.cssMinify`。
236
271
  */
237
272
  emitCssFile?: boolean;
273
+ /**
274
+ * 是否在浏览器运行时 / HTML 中注入 CSS。原生 client 环境可关闭注入,
275
+ * 同时继续保留 CSS 模块图与结构化元数据。
276
+ * @default true
277
+ */
278
+ inject?: boolean;
279
+ /**
280
+ * 是否写出 `.css` 文件。关闭后仍收集每个 chunk 的 CSS 所有权。
281
+ * @default true
282
+ */
283
+ emit?: boolean;
238
284
  }
239
285
  interface NastiPlugin {
240
286
  name: string;
@@ -319,6 +365,11 @@ interface NastiPlugin {
319
365
  tags: HtmlTagDescriptor[];
320
366
  }>;
321
367
  handleHotUpdate?: (ctx: HmrContext) => void | ModuleNode[] | Promise<void | ModuleNode[]>;
368
+ /**
369
+ * 一个文件在所有 dev client 环境完成失效、插件 HMR 钩子与重新转换后调用一次。
370
+ * 多运行时工具链可据此只重编码受影响的 native section。
371
+ */
372
+ handleHotUpdateApp?: (ctx: AppHmrContext) => void | Promise<void>;
322
373
  }
323
374
  interface PluginContext {
324
375
  resolve: (source: string, importer?: string) => Promise<ResolveIdResult>;
@@ -343,6 +394,44 @@ interface EnvironmentBuildOutput {
343
394
  type: string;
344
395
  code?: string;
345
396
  source?: Uint8Array | string;
397
+ map?: unknown;
398
+ name?: string;
399
+ names?: string[];
400
+ isEntry?: boolean;
401
+ isDynamicEntry?: boolean;
402
+ imports?: string[];
403
+ dynamicImports?: string[];
404
+ moduleIds?: string[];
405
+ }
406
+ interface EnvironmentCssModule {
407
+ id: string;
408
+ source: string;
409
+ code: string;
410
+ }
411
+ interface EnvironmentCssChunk {
412
+ fileName: string;
413
+ moduleIds: string[];
414
+ cssFileNames: string[];
415
+ }
416
+ interface EnvironmentCssMetadata {
417
+ modules: Record<string, EnvironmentCssModule>;
418
+ chunks: Record<string, EnvironmentCssChunk>;
419
+ }
420
+ interface EnvironmentChunkMetadata {
421
+ fileName: string;
422
+ name: string;
423
+ isEntry: boolean;
424
+ isDynamicEntry: boolean;
425
+ imports: string[];
426
+ dynamicImports: string[];
427
+ moduleIds: string[];
428
+ css: string[];
429
+ assets: string[];
430
+ }
431
+ interface EnvironmentAssetMetadata {
432
+ fileName: string;
433
+ names: string[];
434
+ publicPath: string;
346
435
  }
347
436
  /** 单个环境附加到标准构建结果上的结构化元数据。 */
348
437
  interface EnvironmentBuildMetadata {
@@ -350,6 +439,10 @@ interface EnvironmentBuildMetadata {
350
439
  publicPath?: string;
351
440
  manifest?: unknown;
352
441
  stats?: unknown;
442
+ chunks?: Record<string, EnvironmentChunkMetadata>;
443
+ assets?: Record<string, EnvironmentAssetMetadata>;
444
+ css?: EnvironmentCssMetadata;
445
+ sourceMaps?: Record<string, unknown>;
353
446
  }
354
447
  /** 外部环境驱动或原生 Rolldown 环境返回的标准构建结果。 */
355
448
  interface EnvironmentBuildResult extends EnvironmentBuildMetadata {
@@ -372,6 +465,10 @@ interface BuildAppContext {
372
465
  getArtifact: (environmentName: string, fileName: string) => EnvironmentBuildOutput | undefined;
373
466
  getEntry: (environmentName: string, entryName: string) => EnvironmentBuildOutput | undefined;
374
467
  getManifest: <T = unknown>(environmentName: string) => T | undefined;
468
+ getChunk: (environmentName: string, fileName: string) => EnvironmentChunkMetadata | undefined;
469
+ getCss: (environmentName: string) => EnvironmentCssMetadata | undefined;
470
+ getSourceMap: (environmentName: string, fileName: string) => unknown;
471
+ resolvePublicPath: (environmentName: string, fileName: string) => string | undefined;
375
472
  /** 将聚合产物安全地写入 top-level `build.outDir`,并纳入 BuildResult.appOutput。 */
376
473
  emitFile: (file: AppBuildOutput) => string;
377
474
  }
@@ -410,6 +507,22 @@ interface EnvironmentInstance {
410
507
  hot: HotChannel;
411
508
  /** 声明 driver 后,由插件提供的外部环境编译驱动 */
412
509
  driver?: EnvironmentDriver;
510
+ /** per-environment dev 模块图与插件列表。 */
511
+ moduleGraph: ModuleGraph$1;
512
+ plugins: NastiPlugin[];
513
+ /**
514
+ * 在该环境的独立 transform 管线中请求模块。仅 dev 环境在初始化后可用。
515
+ */
516
+ transformRequest: (url: string) => Promise<{
517
+ code: string;
518
+ map?: unknown;
519
+ } | null>;
520
+ /** 内置 CSS 管线登记模块;工具链通常读取 getCssModule(s)。 */
521
+ setCssModule: (module: EnvironmentCssModule) => void;
522
+ getCssModule: (id: string) => EnvironmentCssModule | undefined;
523
+ getCssModules: () => Readonly<Record<string, EnvironmentCssModule>>;
524
+ setAssetModule: (id: string, fileName: string) => void;
525
+ getAssetModules: () => Readonly<Record<string, string>>;
413
526
  /** 由生产插件登记 entries / manifest / stats,构建完成后合并进环境结果。 */
414
527
  setBuildMetadata: (metadata: EnvironmentBuildMetadata) => void;
415
528
  }
@@ -512,13 +625,14 @@ interface DevServer {
512
625
  moduleGraph: ModuleGraph$1;
513
626
  watcher: any;
514
627
  ws: WebSocketServer;
515
- /** Environment API:per-env 环境实例(Phase 1 client 有完整运行时) */
628
+ /** Environment API:每个 client-consumer 环境都有独立的 transform/HMR 管线。 */
516
629
  environments: Record<string, EnvironmentInstance>;
517
630
  /** 外部环境驱动启动后返回的服务 URL / middleware 信息 */
518
631
  environmentServices: Record<string, EnvironmentServeResult>;
519
632
  listen: (port?: number) => Promise<DevServer>;
520
633
  close: () => Promise<void>;
521
634
  transformRequest: (url: string) => Promise<TransformResult>;
635
+ transformEnvironmentRequest: (environmentName: string, url: string) => Promise<TransformResult>;
522
636
  /**
523
637
  * SSR:在 server consumer 环境(默认 `ssr`)中加载并执行模块,返回其导出。
524
638
  * Vite `server.ssrLoadModule` 的 back-compat shim(底层是 module runner +
@@ -576,8 +690,29 @@ interface HmrContext {
576
690
  modules: ModuleNode[];
577
691
  read: () => string | Promise<string>;
578
692
  server: DevServer;
693
+ environment: EnvironmentInstance;
579
694
  }
580
- type HmrPayload = {
695
+ interface EnvironmentTransformedModule {
696
+ module: ModuleNode;
697
+ result: {
698
+ code: string;
699
+ map?: unknown;
700
+ } | null;
701
+ }
702
+ interface EnvironmentHotUpdateResult {
703
+ environment: EnvironmentInstance;
704
+ modules: ModuleNode[];
705
+ updates: HmrUpdate[];
706
+ transformed: EnvironmentTransformedModule[];
707
+ fullReload: boolean;
708
+ }
709
+ interface AppHmrContext {
710
+ file: string;
711
+ timestamp: number;
712
+ environments: Readonly<Record<string, EnvironmentHotUpdateResult>>;
713
+ server: DevServer;
714
+ }
715
+ type HmrPayload = ({
581
716
  type: 'connected';
582
717
  } | {
583
718
  type: 'update';
@@ -594,6 +729,12 @@ type HmrPayload = {
594
729
  message: string;
595
730
  stack?: string;
596
731
  };
732
+ } | {
733
+ type: 'custom';
734
+ event: string;
735
+ data?: unknown;
736
+ }) & {
737
+ environment?: string;
597
738
  };
598
739
  interface HmrUpdate {
599
740
  type: 'js-update' | 'css-update';
@@ -651,9 +792,11 @@ declare class PluginContainer {
651
792
  }
652
793
 
653
794
  declare class ModuleGraph {
795
+ readonly environmentName: string;
654
796
  private urlToModuleMap;
655
797
  private idToModuleMap;
656
798
  private fileToModulesMap;
799
+ constructor(environmentName?: string);
657
800
  getModuleByUrl(url: string): ModuleNode | undefined;
658
801
  getModuleById(id: string): ModuleNode | undefined;
659
802
  getModulesByFile(file: string): Set<ModuleNode> | undefined;
@@ -717,11 +860,27 @@ declare class NastiEnvironment implements EnvironmentInstance {
717
860
  private candidatePlugins;
718
861
  private pluginApi;
719
862
  private buildMetadata;
863
+ private cssModules;
864
+ private assetModules;
865
+ private transformRequestHandler?;
720
866
  private initialized;
721
867
  constructor(name: string, config: ResolvedConfig, init?: NastiEnvironmentInit);
722
868
  /** 过滤插件并建 per-env PluginContainer */
723
869
  init(): Promise<void>;
724
870
  getDriverContext(): EnvironmentDriverContext;
871
+ configureDevPipeline(transformRequest: (url: string) => Promise<{
872
+ code: string;
873
+ map?: unknown;
874
+ } | null>): void;
875
+ transformRequest(url: string): Promise<{
876
+ code: string;
877
+ map?: unknown;
878
+ } | null>;
879
+ setCssModule(module: EnvironmentCssModule): void;
880
+ getCssModule(id: string): EnvironmentCssModule | undefined;
881
+ getCssModules(): Readonly<Record<string, EnvironmentCssModule>>;
882
+ setAssetModule(id: string, fileName: string): void;
883
+ getAssetModules(): Readonly<Record<string, string>>;
725
884
  setBuildMetadata(metadata: EnvironmentBuildMetadata): void;
726
885
  getBuildMetadata(): EnvironmentBuildMetadata;
727
886
  close(): Promise<void>;
@@ -808,13 +967,13 @@ interface MonacoEditorPluginOptions {
808
967
  }
809
968
  declare function monacoEditorPlugin(options?: MonacoEditorPluginOptions): NastiPlugin;
810
969
 
811
- /** 非 client 环境的占位通道(SSR/edge Phase 2 接上真实 transport) */
970
+ /** 非 client 环境的占位通道(SSR/edge 可由 runner/driver 接上真实 transport) */
812
971
  declare function createNoopHotChannel(): HotChannel;
813
972
  /**
814
- * client 环境的 ws 通道:包装 server/ws.ts 的 WebSocketServer。
815
- * 事件监听与 invoke 在现有 ws 协议上预留(custom event 协议 Phase 2 扩展)。
973
+ * client-consumer 环境的 ws 通道:包装 server/ws.ts 的 WebSocketServer。
974
+ * 事件监听与 invoke 在现有 ws 协议上预留,payload environment 字段分流。
816
975
  */
817
- declare function createWsHotChannel(ws: WebSocketServer): HotChannel;
976
+ declare function createWsHotChannel(ws: WebSocketServer, environmentName?: string): HotChannel;
818
977
 
819
978
  type NastiDebugScope = `nasti:${string}`;
820
979
  interface DebuggerOptions {
@@ -844,4 +1003,4 @@ declare function buildEnvDefine(env: EnvRecord, mode: string, overrides?: Record
844
1003
  /** 按环境 consumer 派生 import.meta.env.SSR 的 define 覆盖 */
845
1004
  declare function ssrDefineOverrides(consumer: 'client' | 'server'): Record<string, string>;
846
1005
 
847
- export { type AppBuildOutput, type BuildAppContext, type BuildConfig, type BuildResult, type DevServer, type ElectronConfig, type EnvironmentBuildMetadata, 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 };
1006
+ export { type AppBuildOutput, type AppHmrContext, type BuildAppContext, type BuildConfig, type BuildResult, type DevServer, type ElectronConfig, type EnvironmentAssetMetadata, type EnvironmentBuildMetadata, type EnvironmentBuildOutput, type EnvironmentBuildResult, type EnvironmentChunkMetadata, type EnvironmentCssChunk, type EnvironmentCssMetadata, type EnvironmentCssModule, type EnvironmentDriver, type EnvironmentDriverContext, type EnvironmentDriverServeContext, type EnvironmentHotUpdateResult, type EnvironmentInstance, type EnvironmentOptions, type EnvironmentServeResult, type EnvironmentTransformedModule, type HmrPayload, type HmrUpdate, 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, type VueEnvironmentOptions, type VueSfcSourceTransform, type VueSfcTransformContext, build, buildElectron, buildEnvDefine, createDebugger, createElectronRendererConfig, createLogger, createNoopHotChannel, createServer, createWsHotChannel, defineConfig, detectFramework, electronPlugin, electronRendererDevPath, loadEnv, monacoEditorPlugin, printServerUrls, resolveConfig, resolveEnvironmentPlugins, ssrDefineOverrides, startElectronDev };