vite-plugin-taro 0.7.8 → 0.7.10-beta.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.
Files changed (33) hide show
  1. package/dist/index.js +604 -344
  2. package/dist/node/plugins/mini/dev/create-hmr-results-stream.d.ts +10 -8
  3. package/dist/node/plugins/mini/dev/hmr-files.d.ts +2 -2
  4. package/dist/node/plugins/mini/dev/hmr-mode.d.ts +2 -2
  5. package/dist/node/plugins/mini/dev/inject-dev-page-component.d.ts +11 -0
  6. package/dist/node/plugins/mini/dev/mini-dev-options.d.ts +9 -15
  7. package/dist/node/plugins/mini/dev/modes/devtools/devtools-hmr-mode.d.ts +1 -2
  8. package/dist/node/plugins/mini/dev/modes/interpreter/interpreter-hmr-mode.d.ts +1 -2
  9. package/dist/node/plugins/mini/dev/modes/rebuild/rebuild-hmr-mode.d.ts +1 -2
  10. package/dist/node/plugins/mini/dev/plugins.d.ts +1 -1
  11. package/dist/node/plugins/mini/dev/replace-vite-transform-plugin.d.ts +6 -0
  12. package/dist/node/plugins/mini/mini-contract.d.ts +7 -14
  13. package/dist/node/plugins/mini/module/module.d.ts +20 -11
  14. package/dist/node/plugins/mini/output/create-transport-output.d.ts +1 -3
  15. package/dist/node/plugins/mini/placer/placer.d.ts +3 -5
  16. package/dist/node/plugins/mini/render/native.d.ts +1 -4
  17. package/dist/node/plugins/mini/resolve/resolver.d.ts +15 -2
  18. package/dist/node/plugins/mini/styles/minify-mini-stylesheet.d.ts +1 -1
  19. package/dist/node/plugins/mini/styles/plugins.d.ts +58 -45
  20. package/dist/node/plugins/mini/styles/project-mini-styles.d.ts +52 -0
  21. package/dist/node/plugins/mini/watch/create-mini-watch-plugin.d.ts +5 -2
  22. package/dist/node/tests/create-mini-style-entries.d.ts +3 -0
  23. package/dist/node/tests/create-native-dev-runtime.d.ts +7 -0
  24. package/dist/node/utils/packages.d.ts +3 -3
  25. package/dist/runtime/mini/dev/hmr-protocol.d.ts +2 -2
  26. package/dist/runtime/mini/dev/hmr-protocol.js +1 -1
  27. package/dist/runtime/mini/dev/mini-hmr-runtime.d.ts +8 -6
  28. package/dist/runtime/mini/dev/mini-hmr-runtime.js +35 -10
  29. package/dist/runtime/mini/dev/modes/devtools/devtools-runtime.js +1 -1
  30. package/dist/runtime/mini/dev/modes/interpreter/interpreter-runtime.d.ts +1 -1
  31. package/dist/runtime/mini/dev/modes/interpreter/interpreter-runtime.js +1 -1
  32. package/dist/runtime/mini/systemjs/system-core.js +1 -1
  33. package/package.json +5 -5
@@ -3,13 +3,15 @@ import { type SchedulerLike, Subject } from 'rxjs';
3
3
  type HmrUpdatesResult = Parameters<NonNullable<DevOptions['onHmrUpdates']>>[0];
4
4
  type HmrUpdates = Exclude<HmrUpdatesResult, Error>;
5
5
  /**
6
- * Adapts Rolldown's non-awaited HMR callback into lossless quiet-window publications.
6
+ * Adapts Rolldown's non-awaited HMR callback into lossless fixed-duration batch publications.
7
7
  *
8
- * Debouncing the result stream itself would retain only the final callback and lose incremental patch factories that later
9
- * patches provably do not reproduce. Instead, the debounced view is only a closing notifier for `buffer`: every callback is
10
- * retained in arrival order, and one configured quiet period emits the complete window to the host's existing serialized
11
- * writer. This first stream migration deliberately does not own physical state; `publish` and `reportError` remain synchronous
12
- * admission callbacks so the dev host can enqueue both through its single writer.
8
+ * Applying auditTime to the result stream itself would retain only the final callback and lose incremental patch factories
9
+ * that later patches do not reproduce. Instead, it only closes `buffer`: the first meaningful callback starts one timed window,
10
+ * and later callbacks join without postponing its deadline. No timer runs while idle. `publish` and `reportError` remain
11
+ * synchronous admission callbacks so the dev host can enqueue both through its existing serialized writer.
12
+ *
13
+ * Empty and Noop-only callbacks are excluded from both the buffer and its closing notifier, so they cannot delay meaningful
14
+ * work or enqueue empty publications. Mixed callbacks remain intact; the host still owns per-update selection.
13
15
  *
14
16
  * DevEngine failures are values, not Observable errors. They represent transient editor generations and carry no executable
15
17
  * patch, so the stream reports the final error but otherwise removes them. Successful callbacks on either side remain ordered
@@ -17,7 +19,7 @@ type HmrUpdates = Exclude<HmrUpdatesResult, Error>;
17
19
  * Completing the returned Subject flushes its current buffer synchronously, allowing host shutdown to await the resulting
18
20
  * serialized task rather than silently dropping an admitted patch.
19
21
  *
20
- * Complexity is O(updates + changed files) per emitted window, with one retained reference per callback until the quiet edge.
22
+ * Complexity is O(updates + changed files) per emitted window, with one retained reference per callback until its closing edge.
21
23
  */
22
- export declare function createHmrResultsStream(settleMilliseconds: number, scheduler: SchedulerLike, publish: (result: HmrUpdates) => void, reportError: (error: Error) => void): Subject<HmrUpdatesResult>;
24
+ export declare function createHmrResultsStream(batchMilliseconds: number, scheduler: SchedulerLike, publish: (result: HmrUpdates) => void, reportError: (error: Error) => void): Subject<HmrUpdatesResult>;
23
25
  export {};
@@ -2,7 +2,7 @@ import type { HmrInfo } from './hmr-protocol.ts';
2
2
  export declare const hmrInfoFileName = "hmr/info.js";
3
3
  /**
4
4
  * Renders immutable CommonJS metadata because App startup must initialize the runtime synchronously before any entry capsule.
5
- * Freezing also prevents application code from accidentally changing the build identity or socket endpoint for the App heap.
5
+ * Freezing also prevents application code from accidentally changing the running App's build identity or socket endpoint.
6
6
  */
7
7
  export declare function renderHmrInfo(info: HmrInfo): string;
8
8
  /**
@@ -10,7 +10,7 @@ export declare function renderHmrInfo(info: HmrInfo): string;
10
10
  *
11
11
  * Imported global CSS can change while the entry remains byte-identical. DevTools may then reuse an older persistent compile
12
12
  * cache after it restarts. Tying this inert comment to the build identity invalidates that cache once per complete build,
13
- * while incremental style updates continue changing only the imported file and therefore preserve the App heap.
13
+ * while incremental style updates continue changing only the imported file and therefore keep the App running.
14
14
  */
15
15
  export declare function renderDevelopmentAppStyle(globalStyleFileName: string, buildId: string): string;
16
16
  /**
@@ -1,5 +1,5 @@
1
1
  import type { Plugin } from 'vite';
2
- import type { MiniHmrOptions, RuntimeModulesContract } from '../mini-contract.ts';
2
+ import type { MiniHmrOptions, RuntimeContract } from '../mini-contract.ts';
3
3
  import type { PatchPublication } from './hmr-protocol.ts';
4
4
  /** One mode-selected effect executed by the development host. */
5
5
  export type MiniHmrAction = Readonly<{
@@ -29,4 +29,4 @@ export type MiniHmrMode = Readonly<{
29
29
  }>) => string;
30
30
  }>;
31
31
  /** Resolves exactly one implementation before the Mini Program development host is created. */
32
- export declare function createMiniHmrMode(options: MiniHmrOptions, modules: RuntimeModulesContract): MiniHmrMode;
32
+ export declare function createMiniHmrMode(options: MiniHmrOptions, runtime: RuntimeContract): MiniHmrMode;
@@ -0,0 +1,11 @@
1
+ import type { AstTransformResult } from '../../../utils/transform.ts';
2
+ /**
3
+ * In serve, a native Page may load its original physical capsule after HMR has already installed a newer component factory.
4
+ * Taro captures the component at createPageConfig() time; without this lookup, that Page first mounts with stale source even
5
+ * though the patch was acknowledged. Replace only the component argument, leaving the production capsule untouched.
6
+ */
7
+ export declare function injectDevPageComponent({ capsuleCode, componentId, capsuleId }: {
8
+ capsuleCode: string;
9
+ componentId: string;
10
+ capsuleId: string;
11
+ }): AstTransformResult;
@@ -1,31 +1,25 @@
1
- import type { InputOptions, OutputOptions } from 'rolldown';
1
+ import type { OutputOptions, RolldownOptions } from 'rolldown';
2
2
  import { type DevEngine } from 'rolldown/experimental';
3
3
  import type { ViteDevServer } from 'vite';
4
4
  import type { MiniContract } from '../mini-contract.ts';
5
5
  import type { MiniHmrMode } from './hmr-mode.ts';
6
- type BundledDevRolldownOptions = InputOptions & {
7
- experimental?: {
8
- [key: string]: unknown;
9
- devMode?: boolean | Record<string, unknown>;
10
- };
11
- output?: OutputOptions | OutputOptions[];
12
- };
13
6
  export type BundledDev = {
14
7
  _devEngine?: DevEngine;
15
- getRolldownOptions(): Promise<BundledDevRolldownOptions>;
8
+ getRolldownOptions(): Promise<RolldownOptions>;
16
9
  listen(): Promise<void>;
17
10
  triggerBundleRegenerationIfStale(): Promise<boolean>;
18
11
  };
19
12
  /**
20
- * Installs physical Mini Program output and runtime conventions over Vite's browser-oriented bundled-development options.
13
+ * Applies physical Mini Program output and runtime conventions through Rolldown's public options hook.
21
14
  * Build completion deliberately remains outside this options adapter: DevEngine onOutput is the single lifecycle authority.
22
15
  */
23
- export declare function installMiniDevOptions({ bundledDev, server, contract, hmrMode }: {
24
- bundledDev: BundledDev;
16
+ export declare function createMiniDevOptionsPlugin({ server, contract, hmrMode }: {
25
17
  server: ViteDevServer;
26
18
  contract: Pick<MiniContract, 'options'>;
27
19
  hmrMode: MiniHmrMode;
28
- }): void;
20
+ }): {
21
+ name: string;
22
+ options(rolldownOptions: RolldownOptions): Promise<RolldownOptions>;
23
+ };
29
24
  /** Returns the configured output after rejecting states unsupported by the physical Mini Program engine. */
30
- export declare function requireSingleOutput(rolldownOptions: BundledDevRolldownOptions): OutputOptions;
31
- export {};
25
+ export declare function requireSingleOutput(rolldownOptions: RolldownOptions): OutputOptions;
@@ -1,4 +1,3 @@
1
- import type { RuntimeModulesContract } from '../../../mini-contract.ts';
2
1
  import type { MiniHmrMode } from '../../hmr-mode.ts';
3
2
  import type { PatchUpdate } from '../../hmr-protocol.ts';
4
3
  export declare const devtoolsPatchesFileName = "hmr/patches.js";
@@ -9,7 +8,7 @@ export declare const devtoolsPatchesFileName = "hmr/patches.js";
9
8
  * DevTools observes a changed Page dependency, re-executes the Page shell, and that shell synchronously gives the cumulative
10
9
  * native factory payload to the persistent App runtime. Mixing any one of these pieces with another mode would break that chain.
11
10
  */
12
- export declare function createDevtoolsHmrMode(modules: RuntimeModulesContract): MiniHmrMode;
11
+ export declare function createDevtoolsHmrMode(runtimeFile: string): MiniHmrMode;
13
12
  /** Provides a valid, inert CommonJS dependency before the host has a patch range to publish. */
14
13
  export declare function renderInitialDevtoolsPatches(): string;
15
14
  /**
@@ -1,4 +1,3 @@
1
- import type { RuntimeModulesContract } from '../../../mini-contract.ts';
2
1
  import type { MiniHmrMode } from '../../hmr-mode.ts';
3
2
  /** Creates the pure interpreter adapter whose events are dispatched by the shared development host. */
4
- export declare function createInterpreterHmrMode(modules: RuntimeModulesContract): MiniHmrMode;
3
+ export declare function createInterpreterHmrMode(runtimeFile: string): MiniHmrMode;
@@ -1,4 +1,3 @@
1
- import type { RuntimeModulesContract } from '../../../mini-contract.ts';
2
1
  import type { MiniHmrMode } from '../../hmr-mode.ts';
3
2
  /** Selects complete-output replacement without installing a patch transport or native Page handoff. */
4
- export declare function createRebuildHmrMode(modules: RuntimeModulesContract): MiniHmrMode;
3
+ export declare function createRebuildHmrMode(runtimeFile: string): MiniHmrMode;
@@ -29,7 +29,7 @@ export declare function createMiniDevelopmentPlugin(contract: MiniContract, styl
29
29
  * but removes the prior physical App stylesheet; recovery builds do not clean. The host publishes the stylesheet once afterward.
30
30
  * Patch modes first reset delivery and publish matching `hmr/info.js`; rebuild mode has no patch state and writes a fresh marker
31
31
  * directly. Incremental HMR never enters this complete-output hook and changes only the imported global stylesheet; rewriting
32
- * the App root would reload the heap while a JavaScript patch is awaiting acknowledgement. The serve-only plugin leaves
32
+ * the App root would reload the runtime while a JavaScript patch is awaiting acknowledgement. The serve-only plugin leaves
33
33
  * production output unchanged.
34
34
  */
35
35
  export declare function removeDevelopmentAppStyle(bundle: Record<string, unknown>, appStyleFileName: string): void;
@@ -0,0 +1,6 @@
1
+ import type { RolldownPluginOption } from 'rolldown';
2
+ import type { DevEnvironment } from 'vite';
3
+ type TransformConfig = Pick<DevEnvironment['config'], 'root' | 'tsconfig' | 'consumer' | 'oxc'>;
4
+ /** Reconstructs Vite's native transform through its exported factory, without reading or mutating builtin internals. */
5
+ export declare function replaceViteTransformPlugin(pluginOption: RolldownPluginOption, config: TransformConfig): Promise<RolldownPluginOption>;
6
+ export {};
@@ -6,23 +6,11 @@ export type TaroContract = {
6
6
  componentsReactPath: string;
7
7
  targetRuntimePath: string;
8
8
  };
9
- /** Physical runtime modules selected by one Mini Program target. */
10
- export type RuntimeModulesContract = {
11
- bootstrap: string;
12
- appShell: string;
13
- appCapsule: string;
14
- componentShell: string;
15
- componentCapsule: string;
16
- customWrapperShell: string;
17
- pageShell: string;
18
- pageCapsule: string;
9
+ /** Target-specific development runtimes; shared Mini entry IDs live beside their source modules. */
10
+ export type RuntimeContract = {
19
11
  devtoolsHmrRuntime: string;
20
12
  interpreterHmrRuntime: string;
21
13
  };
22
- /** Physical runtime selection for one Mini Program target. */
23
- export type RuntimeContract = {
24
- modules: RuntimeModulesContract;
25
- };
26
14
  /** Style output names selected by one Mini Program target. */
27
15
  export type StyleContract = {
28
16
  appFileName: string;
@@ -51,6 +39,10 @@ export type OutputContract = {
51
39
  projectPrivateConfigFilename: string;
52
40
  generateProjectSkeleton(input: MiniProjectSkeletonInput, contract: MiniContract): Rolldown.EmittedAsset[];
53
41
  };
42
+ /** Native project config fields overridden only in physical build-watch output. */
43
+ export type WatchContract = {
44
+ override: Readonly<Record<string, VptJsonObject>>;
45
+ };
54
46
  /** Complete input consumed by the shared Mini Program pipeline. */
55
47
  export type MiniContract = {
56
48
  options: VptOptions;
@@ -58,6 +50,7 @@ export type MiniContract = {
58
50
  runtime: RuntimeContract;
59
51
  styles: StyleContract;
60
52
  output: OutputContract;
53
+ watch: WatchContract;
61
54
  };
62
55
  /** Application JSON represented by the current Mini Program contract. */
63
56
  export type MiniJsonObject = VptJsonObject;
@@ -1,6 +1,21 @@
1
1
  import { type Rolldown } from 'vite';
2
- import type { RuntimeModulesContract } from '../mini-contract.ts';
3
- export declare const miniRuntimeId: string;
2
+ /** Installs SystemJS, transport, and polyfills before native entries load capsules. */
3
+ export declare const miniBootstrapId: string;
4
+ /** Registers the native App using its generated configuration capsule. */
5
+ export declare const miniAppShellId: string;
6
+ /** Builds the App configuration and activates its React runtime. */
7
+ export declare const miniAppCapsuleId: string;
8
+ /** Registers the recursive native Component from its capsule configuration. */
9
+ export declare const miniComponentShellId: string;
10
+ /** Supplies the recursive Component and CustomWrapper configurations. */
11
+ export declare const miniComponentCapsuleId: string;
12
+ /** Registers the native CustomWrapper from the shared component capsule. */
13
+ export declare const miniCustomWrapperShellId: string;
14
+ /** Registers each route's native Page using its route-qualified capsule. */
15
+ export declare const miniPageShellId: string;
16
+ /** Specializes each route's Page configuration and component import. */
17
+ export declare const miniPageCapsuleId: string;
18
+ export declare const miniTaroRuntimeId: string;
4
19
  /** Identifies Rolldown's generated helper module independently of its unstable output filename. */
5
20
  export declare const rolldownRuntimeId = "\0rolldown/runtime.js";
6
21
  /** Identifies the virtual binding shared by native files, SystemJS capsules and HMR factories. */
@@ -9,7 +24,7 @@ export declare const vptGlobalBindingId = "\0vpt:global-binding";
9
24
  export declare const miniPolyfillsId = "\0vpt:mini-polyfills";
10
25
  /** External bootstrap dependency emitted only after the bundled graph is finalized. */
11
26
  export declare const miniTransportId = "\0vpt:mini-transport";
12
- export declare const miniTransportFileName = "common/vpt/transport.js";
27
+ export declare const miniTransportOutputPath = "common/vpt/transport.js";
13
28
  /** Resolves the shared Taro facade's target initialization side effect. */
14
29
  export declare const taroTargetRuntimeId = "\0vpt:taro-target-runtime";
15
30
  /** Redirects Vite's injected browser preload helper to the bootstrap identity loader. */
@@ -27,17 +42,11 @@ export declare const pageCapsuleId = "\0vpt:page-capsule";
27
42
  export type MiniChunk = Rolldown.PreRenderedChunk | Rolldown.RenderedChunk;
28
43
  /** Distinguishes native shells, lifecycle entry capsules, ordinary capsules, and shared native/SystemJS infrastructure. */
29
44
  export type MiniChunkKind = 'native' | 'entry-capsule' | 'normal-capsule' | 'amphibious';
30
- /** Classifies chunks by their compiler-owned modules; ordinary application chunks are normal capsules. */
31
- export type MiniModuleClassifier = (chunk: MiniChunk) => MiniChunkKind;
32
45
  /** Native hook filter for the physical core-js graph; the generated import-only entry needs no host rewriting. */
33
46
  export declare const miniPolyfillSourceFilter: RegExp;
34
47
  /** Keeps the global binding and core-js in the pre-bootstrap native chunk, outside the recursive framework group. */
35
48
  export declare function isMiniPolyfillModule(moduleId: string): boolean;
36
49
  /** Groups framework modules by resolved package roots; Rolldown includes their dependencies. */
37
50
  export declare function isMiniFrameworkVendorModule(moduleId: string): boolean;
38
- /**
39
- * The Mini graph separates lifecycle entries from bootstrap/polyfill/runtime infrastructure. A compiler-owned module
40
- * identifies its chunk's kind; chunks containing only application or framework modules are normal capsules.
41
- * One scan stops at the first known identity: O(M) worst-case time and O(1) extra space, without per-chunk collections.
42
- */
43
- export declare function createMiniModuleClassifier(modules: RuntimeModulesContract): MiniModuleClassifier;
51
+ /** Classifies each chunk by its compiler-owned modules; ordinary application chunks are normal capsules. O(M) time. */
52
+ export declare function classifyMiniModule(chunk: MiniChunk): MiniChunkKind;
@@ -1,5 +1,4 @@
1
1
  import type { Rolldown } from 'vite';
2
- import { type MiniModuleClassifier } from '../module/module.ts';
3
2
  import type { PackageLocation } from '../placer/placement.ts';
4
3
  /**
5
4
  * Emits the closed transport table in generateBundle, after placement and content-hash resolution. Each switch case has two
@@ -18,9 +17,8 @@ import type { PackageLocation } from '../placer/placement.ts';
18
17
  * paths. Fixed compact syntax and JSON-encoded IDs need no AST or quote-repair pass, while application chunks retain full
19
18
  * compression, mangling, and whitespace removal.
20
19
  */
21
- export declare function createTransportOutput({ bundle, classifyModule, getPackageLocation }: {
20
+ export declare function createTransportOutput({ bundle, getPackageLocation }: {
22
21
  bundle: Rolldown.OutputBundle;
23
- classifyModule: MiniModuleClassifier;
24
22
  getPackageLocation(chunk: Rolldown.OutputChunk): PackageLocation;
25
23
  }): {
26
24
  type: "asset";
@@ -1,11 +1,9 @@
1
1
  import type { Plugin, Rolldown } from 'vite';
2
- import type { RuntimeModulesContract } from '../mini-contract.ts';
3
- import { isMiniPolyfillModule, type MiniChunkKind, type MiniModuleClassifier } from '../module/module.ts';
2
+ import { isMiniPolyfillModule } from '../module/module.ts';
4
3
  import { type GeneratedSubpackage, type PackageLocation } from './placement.ts';
5
4
  export type { GeneratedSubpackage, Placement } from './placement.ts';
6
5
  /** Placement services consumed by the later Mini Program rendering and output hooks. */
7
6
  export type MiniPlacementPlugin = Plugin & Readonly<{
8
- classifyChunk(chunk: Rolldown.PreRenderedChunk | Rolldown.RenderedChunk): MiniChunkKind;
9
7
  getPackageLocation(chunk: Rolldown.RenderedChunk | Rolldown.OutputChunk): PackageLocation;
10
8
  getPhysicalChunkId(chunk: Rolldown.RenderedChunk | string): string;
11
9
  getSubpackages(): readonly GeneratedSubpackage[];
@@ -14,7 +12,7 @@ export type MiniPlacementPlugin = Plugin & Readonly<{
14
12
  * Rolldown options owned by Mini Program placement. Every field enforces a distinct output invariant. The plugin returns this object
15
13
  * from its config hook, while direct Rolldown integration tests reuse the same value to exercise the identical lifecycle.
16
14
  */
17
- export declare function createPlacementRolldownOptions(classifyChunk: MiniModuleClassifier): {
15
+ export declare function createPlacementRolldownOptions(): {
18
16
  /**
19
17
  * Rolldown owns shared chunk names and collision handling. LTHP adds physical package prefixes
20
18
  * to those names later without copying or replacing the chunks.
@@ -62,4 +60,4 @@ export declare function createPlacementRolldownOptions(classifyChunk: MiniModule
62
60
  * performs one whole-state transition, so stale graph state, duplicate planning, and partially reset generations are
63
61
  * unrepresentable.
64
62
  */
65
- export declare function createMiniPlacementPlugin(modules: RuntimeModulesContract): MiniPlacementPlugin;
63
+ export declare function createMiniPlacementPlugin(): MiniPlacementPlugin;
@@ -1,6 +1,5 @@
1
1
  import type { Rolldown } from 'vite';
2
2
  import type { AstTransformResult } from '../../../utils/transform.ts';
3
- import type { MiniModuleClassifier } from '../module/module.ts';
4
3
  /**
5
4
  * Materializes one final native/amphibious Rolldown chunk as executable Mini Program CommonJS.
6
5
  *
@@ -22,12 +21,10 @@ import type { MiniModuleClassifier } from '../module/module.ts';
22
21
  * source identifier. Source maps use the same range edits when requested; Mini Program development disables them and keeps this path
23
22
  * focused on startup latency.
24
23
  */
25
- export declare function renderNative({ code, chunk, chunks, bootstrapModuleId, getPhysicalChunkId, classifyModule, sourcemap }: {
24
+ export declare function renderNative({ code, chunk, chunks, getPhysicalChunkId, sourcemap }: {
26
25
  code: string;
27
26
  chunk: Rolldown.RenderedChunk;
28
27
  chunks: Readonly<Record<string, Rolldown.RenderedChunk>>;
29
- bootstrapModuleId: string;
30
28
  getPhysicalChunkId: (chunk: Rolldown.RenderedChunk | string) => string;
31
- classifyModule: MiniModuleClassifier;
32
29
  sourcemap: boolean;
33
30
  }): AstTransformResult;
@@ -1,9 +1,22 @@
1
1
  import { type Rolldown } from 'vite';
2
2
  import type { MiniContract } from '../mini-contract.ts';
3
3
  /** Creates the resolver and source specializer for one Mini Program module graph. */
4
- export declare function createResolver(contract: Pick<MiniContract, 'options' | 'runtime' | 'taro'>): {
4
+ export declare function createResolver(contract: Pick<MiniContract, 'options' | 'taro'>): {
5
5
  resolveId(id: string, importer: string | undefined, projectRoot: string): string | Rolldown.PartialResolvedId | undefined;
6
6
  specialize(code: string, id: string, sourcemap?: boolean): import("../../../utils/transform.ts").AstTransformResult | undefined;
7
- applicationEntryIds: string[];
7
+ entries: {
8
+ appEntries: {
9
+ capsuleId: string;
10
+ capsuleName: string;
11
+ shellId: string;
12
+ shellName: string;
13
+ };
14
+ pageEntries: {
15
+ capsuleId: string;
16
+ capsuleName: string;
17
+ shellId: string;
18
+ shellName: string;
19
+ }[];
20
+ };
8
21
  input: any;
9
22
  };
@@ -1,5 +1,5 @@
1
1
  import type { BuildOptions } from 'vite';
2
- /** Minifies only the completed global native stylesheet, without another browser compatibility or preprocessing pass. */
2
+ /** Minifies one completed native stylesheet, without another browser compatibility or preprocessing pass. */
3
3
  export declare function minifyMiniStylesheet(css: string, options: Readonly<{
4
4
  filename: string;
5
5
  minify: BuildOptions['cssMinify'];
@@ -1,25 +1,26 @@
1
1
  import { type Plugin } from 'vite';
2
2
  import type { MiniContract } from '../mini-contract.ts';
3
+ import type { createResolver } from '../resolve/resolver.ts';
3
4
  /** JavaScript code plus the physical filename required by the Mini Program class-name transformer. */
4
5
  type JavaScriptArtifact = Readonly<{
5
6
  code: string;
6
7
  filename: string;
7
8
  }>;
8
- /** Vite plugin with the host operation that finalizes one coherent native-style/JavaScript transaction. */
9
+ /** Vite plugin that finalizes native CSS and JavaScript without discarding HMR patches on CSS errors. */
9
10
  export type MiniStylePlugin = Plugin & Readonly<{
10
- /** Neutralizes browser CSS payloads and atomically publishes the matching global native stylesheet. */
11
- finalizeUpdate: <Artifact extends JavaScriptArtifact>(artifacts: readonly Artifact[], writeStylesheet: (stylesheet: string) => Promise<void>) => Promise<readonly Artifact[]>;
11
+ /** Publishes valid native CSS before JavaScript; CSS failures only log errors and retain the last valid styles. */
12
+ finalizeUpdate: <Artifact extends JavaScriptArtifact>(artifacts: readonly Artifact[], writeStylesheet: (fileName: string, source: string) => Promise<void>) => Promise<readonly Artifact[]>;
12
13
  }>;
13
14
  /**
14
- * Creates the single owner of global native-style compilation, graph projection, class rewriting, and publication.
15
+ * Creates the single owner of App/Page native-style compilation, graph projection, class rewriting, and publication.
15
16
  *
16
17
  * ## Architectural invariant
17
18
  *
18
- * One Mini Program transaction must expose JavaScript and native CSS produced from one class-identity snapshot. Tailwind utility
19
- * names can be escaped—for example, `py-5.5` becomes `py-5_d5`—so publishing either side independently can leave running code
20
- * referring to selectors that do not yet exist. This plugin therefore treats reachable CSS, Tailwind candidates, converted
21
- * native CSS, and converted JavaScript as one output. Complete builds and HMR updates both call `finalizeOutput()`; they differ only
22
- * in how the returned bytes are materialized.
19
+ * Successful Mini Program updates expose JavaScript and native CSS produced from one class-identity snapshot. Tailwind utility
20
+ * names can be escaped—for example, `py-5.5` becomes `py-5_d5`—so both sides share the current candidate union. Complete builds
21
+ * reject any conversion failure. HMR instead logs native CSS errors and retains the last valid stylesheet for each failed file.
22
+ * Failed CSS is never published. Valid JavaScript still arrives with its assigned patch sequence; dropping that sequence would
23
+ * force the running client to rebuild and lose state. Separate build/update finalizers share conversion and caching.
23
24
  *
24
25
  * ## Ownership boundaries
25
26
  *
@@ -33,12 +34,12 @@ export type MiniStylePlugin = Plugin & Readonly<{
33
34
  * `vite:css-post` hook only after the original hook succeeds; it never rereads source files or repeats CSS preprocessing.
34
35
  * 4. The fixed Mini transformer owns selector conversion and Oxc-based JavaScript class-string conversion. One retained
35
36
  * transformer and one projected candidate set drive both operations without loading a framework project context.
36
- * 5. VPT owns physical global native CSS and patch publication. Vite's browser CSS asset is only an intermediate carrier and is
37
- * removed before VPT emits the contract-selected global stylesheet.
37
+ * 5. VPT owns physical App/Page CSS and patch publication. Vite's browser CSS asset is only an intermediate carrier and is
38
+ * removed before VPT emits the App stylesheet and each native Page companion.
38
39
  *
39
- * Native Page and component styles are outside this global pipeline. The target skeleton is generated after this style plugin
40
- * and emits those opaque companions later. Mini output also enforces `cssCodeSplit: false`, so Vite contributes at
41
- * most one browser compiler stylesheet for this plugin to replace.
40
+ * Opaque native-component styles stay outside this pipeline and are emitted by later native output hooks. The requested
41
+ * `build.cssCodeSplit` controls native projection. Vite's intermediate browser carrier remains unsplit after that request
42
+ * is captured, preventing browser CSS-loading code from leaking into native output.
42
43
  *
43
44
  * ## Compilation phases
44
45
  *
@@ -61,72 +62,84 @@ export type MiniStylePlugin = Plugin & Readonly<{
61
62
  *
62
63
  * `configResolved` wraps the concrete `vite:css-post` transform while preserving its hook metadata, filter, ordering, and
63
64
  * plugin context. The original Vite hook executes first, which preserves CSS Module exports and Vite's internal extraction
64
- * state. Only a successful transform updates `styleByModuleId`; syntax errors therefore leave the last successful CSS available
65
- * to the currently running application. Query modes such as `?raw`, `?url`, and `?inline` are excluded because they represent
65
+ * state. Only a successful transform updates `styleByModuleId`; Vite processing errors leave the last successful CSS available.
66
+ * Native conversion may still reject CSS accepted by this hook. Query modes such as `?raw`, `?url`, and `?inline` represent
66
67
  * values rather than graph-owned stylesheets.
67
68
  *
68
69
  * ### 3. Live-graph projection
69
70
  *
70
- * Output finalization starts from resolved App/Page entry IDs and traverses Rolldown's current static and dynamic import edges
71
- * in dependency-first post-order. Transaction-local visited sets terminate cycles and deduplicate shared modules and physical
72
- * stylesheets. A retained stylesheet contributes only when its module is still reachable, so removing an import prunes its CSS
73
- * and Tailwind candidates without a separate prune protocol or persistent topology cache. Candidate sets are unioned only from
74
- * the Tailwind roots whose captured CSS survives that exact traversal, preserving the CSS/class identity invariant.
71
+ * The resolver supplies App/Page entry records; capsule resolution preserves those records and their native output paths.
72
+ * Each capsule traverses Rolldown's current static and dynamic import edges in dependency-first post-order. Root-local visited
73
+ * sets terminate cycles and deduplicate physical styles without suppressing another Page's independent cascade. App-reachable
74
+ * styles belong to the App and are excluded from every Page projection; styles shared only by Pages remain in each consumer.
75
+ * With splitting disabled, one traversal visits App then configured Pages and collects all reachable CSS into the App file,
76
+ * deduplicating shared styles and leaving Page companions empty. A retained stylesheet contributes only while reachable,
77
+ * so import removals prune CSS and candidates without a topology cache. Candidate sets contain only surviving Tailwind roots.
78
+ *
79
+ * App CSS is emitted at the contract's global filename; Page CSS is emitted beside each native Page shell. Only the App file
80
+ * receives HTML display defaults. JavaScript rewriting uses the union of all surviving App/Page Tailwind candidates.
75
81
  *
76
82
  * ### 4. Shared native-style finalization
77
83
  *
78
- * `finalizeOutput()` converts the concatenated reachable CSS to native CSS, optionally minifies that complete global file
79
- * (including HTML defaults), then transforms each JavaScript artifact with the same projected class set. Both builds and HMR
80
- * follow `build.cssMinify`, defaulting to `build.minify`, using Lightning CSS. Vite's intermediate CSS minification
84
+ * Both output finalizers convert and optionally minify each entry's CSS, then transform every JavaScript artifact using
85
+ * the shared candidate union. Builds and HMR follow `build.cssMinify`, defaulting to `build.minify`, using Lightning CSS.
86
+ * Vite's intermediate CSS minification
81
87
  * remains disabled so only final native bytes are optimized. The function returns data without bundle mutation or filesystem
82
- * publication. Any conversion or minification failure rejects before callers expose partial output. JavaScript conversion is
83
- * skipped when the projection contains no Tailwind candidates, preserving ordinary bundle bytes.
88
+ * publication. Complete builds reject conversion or minification failures. HMR logs CSS errors and reuses the affected file's
89
+ * last valid output, if any; neither invalid CSS nor partially processed CSS is published. JavaScript conversion stays strict
90
+ * and uses current candidates, even with stale CSS. It is skipped when the projection contains no Tailwind candidates,
91
+ * preserving ordinary bundle bytes.
84
92
  *
85
- * `createFinalizeOutput()` captures the resolved output policy once and retains only the latest successful CSS conversion and
86
- * candidate identity. Every transaction supplies a fresh live-graph projection, but byte-identical CSS skips both PostCSS and
87
- * Lightning CSS. Equal candidate contents reuse the same set and replacement table even when the projection allocated a new
88
- * set. Changed candidates never reuse stale replacements; conversion failures do not advance the snapshot.
93
+ * `createFinalizeOutput()` composes a strict build converter and an HMR-only recovery wrapper. Both retain the same latest
94
+ * successful conversion per file and candidate identity. Every transaction supplies a fresh live-graph projection, but byte-identical CSS skips PostCSS and
95
+ * Lightning CSS independently for each file. Equal candidate contents reuse the same set and replacement table even when
96
+ * the projection allocated a new set. Changed candidates never reuse stale replacements. Invalid CSS is never cached; rejected
97
+ * transactions do not advance the snapshot.
89
98
  *
90
99
  * ### 5a. Complete-build commit
91
100
  *
92
101
  * The post-order `generateBundle` hook gathers all JavaScript chunks, finalizes them as one operation, and only then mutates the
93
102
  * bundle. It assigns converted code, clears invalid source maps, removes Vite's intermediate browser stylesheet, and always
94
- * emits the contract-selected global file, including the HTML compatibility base even when the application has no styles.
95
- * Native output hooks run afterward and emit Page/component companion files independently.
103
+ * emits the App stylesheet with HTML defaults and every Page stylesheet, including empty Pages. Native output hooks run
104
+ * afterward without Page-style placeholders; opaque native-component styles remain independently owned.
96
105
  *
97
106
  * ### 5b. Development commit
98
107
  *
99
108
  * The development host calls `finalizeUpdate()` after Rolldown produces patch factories or a complete-output notification.
100
- * Finalization uses the `PluginContext` captured by `buildStart`, so it observes the same current graph as the compiler. After
101
- * all conversion succeeds, the host's atomic writer publishes changed native CSS before `finalizeUpdate()` returns converted
102
- * patch factories. Their captured Vite CSS literals are emptied first; factories, exports, changed IDs, and sequences remain
103
- * intact. The patch publisher therefore cannot expose newer JavaScript class identities before matching selectors exist.
104
- * `publishedStylesheet` advances only after a successful write and suppresses byte-identical native-tool reload events.
109
+ * Finalization uses the `PluginContext` captured by `buildStart`, so it observes the same current graph as the compiler. The host's
110
+ * atomic writer publishes valid native CSS before `finalizeUpdate()` returns converted patch factories. CSS conversion errors
111
+ * retain only the affected file's last valid styles; they do not block valid patches or healthy stylesheets. Captured Vite CSS
112
+ * literals are emptied first; factories, exports, changed IDs, and sequences remain intact.
113
+ * Each file's publication frontier advances only after its atomic write succeeds. A failed later write blocks JavaScript
114
+ * delivery; retry skips files already made durable. Empty Page CSS overwrites stale styles after import removal.
105
115
  *
106
116
  * ## Retained state and lifecycle
107
117
  *
108
118
  * Each plugin instance owns the following bounded state and transformation services:
109
119
  *
110
- * - `cssMinify`: requested global-style minification captured before disabling Vite's intermediate pass, then resolved once;
111
- * - `entryIds`: graph-exact App/Page entry identities resolved at the start of each build;
120
+ * - `cssCodeSplit`: requested native-style ownership policy captured before disabling Vite's browser-only splitting;
121
+ * - `cssMinify`: requested native-style minification captured before disabling Vite's intermediate pass, then resolved once;
122
+ * - `resolvedEntries`: App/Page metadata with graph-exact capsule identities resolved at the start of each build;
112
123
  * - `graphContext`: the active Rolldown graph reader needed by host calls made outside plugin hooks;
113
124
  * - `styleByModuleId`: the latest successful Vite CSS plus optional Tailwind state at one normalized module identity;
114
- * - `publishedStylesheet`: the last durably published development stylesheet used for unchanged-write suppression;
115
- * - `finalizeOutput`: resolved output options, the fixed Mini transformer, and the latest successful CSS/candidate snapshot.
125
+ * - `publishedStylesheets`: the last durably published bytes per development stylesheet for unchanged-write suppression;
126
+ * - `finalizeOutput`: resolved output options, the fixed transformer, and the latest successful per-file CSS/candidate snapshot.
116
127
  *
117
- * The state owners remain scoped to one plugin instance; `entryIds` is atomically replaced after each complete resolution.
128
+ * The state owners remain scoped to one plugin instance; `resolvedEntries` is atomically replaced after each complete resolution.
118
129
  * A development watcher retains them across updates; build and watcher shutdown clear the complete style store.
119
130
  *
120
131
  * ## Cost model
121
132
  *
122
- * Projection is `O(V + E + B + C)` for reachable modules, import edges, concatenated CSS bytes, and candidate insertions.
133
+ * Split projection is `O(sum(Vᵢ + Eᵢ + Bᵢ + Cᵢ))` across App/Page roots for reachable modules, import edges, projected CSS
134
+ * bytes, and candidate insertions. Combined projection is `O(V + E + B + C + P)` with one traversal and P Page companions.
135
+ * Candidate unioning needs no extra graph traversal.
123
136
  * Building one exact candidate precheck costs `O(C)` candidate bytes and testing a chunk costs `O(J)` source bytes. Matching
124
137
  * chunks then parse and walk in `O(J)`; replacing `Kᵢ` candidate tokens in literal `i` costs `O(LᵢKᵢ)` while preserving
125
138
  * untouched bytes through Rolldown's native editor. Comparing candidate sets costs `O(C)` without sorting. Retained memory
126
139
  * is `O(B + C + D + F)` for latest CSS, candidate sets, compiler dependencies, and watched file identities; no second application
127
140
  * graph is retained. The Tailwind generator stays alive across candidate edits to avoid repeating source normalization and
128
- * compiler initialization. Native CSS conversion/minification runs only when projected CSS changes;
141
+ * compiler initialization. Successful native CSS conversions are reused while projected CSS is unchanged; failures retry;
129
142
  * no extra source reads or graph traversals are needed.
130
143
  */
131
- export declare function createMiniStylePlugin(contract: Pick<MiniContract, 'styles'>, applicationEntryIds: readonly string[]): MiniStylePlugin;
144
+ export declare function createMiniStylePlugin(contract: Pick<MiniContract, 'styles'>, entries: ReturnType<typeof createResolver>['entries']): MiniStylePlugin;
132
145
  export {};
@@ -0,0 +1,52 @@
1
+ import type { createResolver } from '../resolve/resolver.ts';
2
+ type MiniEntries = ReturnType<typeof createResolver>['entries'];
3
+ /** Projection needs captured CSS and candidates, not the retained compiler or its invalidation state. */
4
+ type StyleSource = Readonly<{
5
+ css: string | undefined;
6
+ tailwind: Readonly<{
7
+ classSet: ReadonlySet<string>;
8
+ }> | undefined;
9
+ }>;
10
+ /** Read only current import edges while retaining the caller's graph context. */
11
+ type ModuleGraph = Readonly<{
12
+ getModuleInfo: (id: string) => Readonly<{
13
+ importedIds: readonly string[];
14
+ dynamicallyImportedIds: readonly string[];
15
+ }> | null;
16
+ }>;
17
+ /**
18
+ * Projects native CSS according to build.cssCodeSplit. Split output preserves each Page's dependency-first cascade;
19
+ * combined output traverses App then configured Pages once, deduplicating shared CSS in the global stylesheet.
20
+ * Page companions stay empty in combined output. Both policies share one union of surviving Tailwind candidates.
21
+ *
22
+ * Split work is O(sum(Vᵢ + Eᵢ + Bᵢ + Cᵢ)) across roots. Combined work is O(V + E + B + C + P), where P is the Page count.
23
+ * All visited/style collections are transaction-local, so cycles terminate and graph removals need no retained cache.
24
+ */
25
+ export declare function projectMiniStyles(entries: MiniEntries, styleByModuleId: ReadonlyMap<string, StyleSource>, context: ModuleGraph, cssCodeSplit: boolean): {
26
+ appEntries: {
27
+ capsuleId: string;
28
+ capsuleName: string;
29
+ shellId: string;
30
+ shellName: string;
31
+ styles: ReadonlyMap<string, Readonly<{
32
+ css: string;
33
+ classSet: ReadonlySet<string> | undefined;
34
+ }>>;
35
+ css: string;
36
+ classSet: Set<string>;
37
+ };
38
+ pageEntries: {
39
+ capsuleId: string;
40
+ capsuleName: string;
41
+ shellId: string;
42
+ shellName: string;
43
+ styles: ReadonlyMap<string, Readonly<{
44
+ css: string;
45
+ classSet: ReadonlySet<string> | undefined;
46
+ }>>;
47
+ css: string;
48
+ classSet: Set<string>;
49
+ }[];
50
+ classSet: Set<string>;
51
+ };
52
+ export {};