vite-plugin-taro 0.7.7 → 0.7.9

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.
@@ -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
  /**
@@ -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;
@@ -12,7 +12,7 @@ export declare function isMiniClientEnvironment(environment: Readonly<{
12
12
  * The shared style pipeline already owns the resolver's ordered App/Page cascade policy, so the host does not reconstruct it
13
13
  * from unrelated Rolldown shell and bootstrap entries.
14
14
  */
15
- export declare function createMiniDevelopmentPlugin(contract: Pick<MiniContract, 'options' | 'runtime' | 'styles'>, styles: MiniStylePlugin): PluginOption[];
15
+ export declare function createMiniDevelopmentPlugin(contract: MiniContract, styles: MiniStylePlugin): PluginOption[];
16
16
  /**
17
17
  * Transfers development ownership of the App stylesheet from complete output to the dev host.
18
18
  *
@@ -25,11 +25,11 @@ export declare function createMiniDevelopmentPlugin(contract: Pick<MiniContract,
25
25
  * rebuild-mode transaction has completed;
26
26
  * 3. let the host replace the wrapper again with the new marker, causing a second App reload.
27
27
  *
28
- * Deleting the in-memory bundle entry avoids both premature writes. Startup cleanup removes all physical files; live recovery
29
- * builds do not clean, so their prior App stylesheet remains available. The host publishes the stylesheet once afterward.
28
+ * Deleting the in-memory bundle entry avoids both premature writes. Startup cleanup retains DevTools project configuration
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;
@@ -45,9 +45,11 @@ export type MiniProjectSkeletonInput = Readonly<{
45
45
  nativeComponents: readonly MiniNativeComponentRegistration[];
46
46
  isProduction: boolean;
47
47
  }>;
48
- /** One target-owned native project-skeleton generator. */
48
+ /** Target-owned native project filenames and project-skeleton generator. */
49
49
  export type OutputContract = {
50
- generateProjectSkeleton(input: MiniProjectSkeletonInput): Rolldown.EmittedAsset[];
50
+ projectConfigFilename: string;
51
+ projectPrivateConfigFilename: string;
52
+ generateProjectSkeleton(input: MiniProjectSkeletonInput, contract: MiniContract): Rolldown.EmittedAsset[];
51
53
  };
52
54
  /** Complete input consumed by the shared Mini Program pipeline. */
53
55
  export type MiniContract = {
@@ -4,7 +4,7 @@ import type { GeneratedSubpackage, PackageLocation } from '../placer/placement.t
4
4
  /** Creates every compiler-owned Mini Program file derived from the final Rolldown bundle. */
5
5
  export declare function createOutputFiles({ bundle, contract, subpackages, isProduction, getModuleInfo, getPackageLocation }: {
6
6
  bundle: Rolldown.OutputBundle;
7
- contract: Pick<MiniContract, 'output' | 'styles'>;
7
+ contract: MiniContract;
8
8
  subpackages: readonly GeneratedSubpackage[];
9
9
  isProduction: boolean;
10
10
  getModuleInfo: (moduleId: string) => {
@@ -1,14 +1,8 @@
1
1
  import type { Rolldown } from 'vite';
2
- import type { VptOptions } from '../../../options.ts';
3
- import type { MiniProjectSkeletonInput } from '../mini/mini-contract.ts';
4
- type TtSkeletonInput = MiniProjectSkeletonInput & Readonly<{
5
- options: VptOptions;
6
- componentsModulePath: string;
7
- }>;
2
+ import type { MiniContract, MiniProjectSkeletonInput } from '../mini/mini-contract.ts';
8
3
  /**
9
4
  * TT supports recursive named templates. Like Alipay, its App host carries the independent Page root as p through each
10
5
  * template scope and CustomWrapper boundary. The TT runtime declares p as a native property on both generated components.
11
6
  * This preserves the App → Page React tree without copying Page nodes into the shared App projection or adding layout nodes.
12
7
  */
13
- export declare function createTtSkeleton({ bundle, subpackages, nativeComponents, isProduction, options, componentsModulePath }: TtSkeletonInput): Rolldown.EmittedAsset[];
14
- export {};
8
+ export declare function createTtSkeleton({ bundle, subpackages, nativeComponents, isProduction }: MiniProjectSkeletonInput, contract: MiniContract): Rolldown.EmittedAsset[];
@@ -1,10 +1,5 @@
1
1
  import type { Rolldown } from 'vite';
2
- import type { VptOptions } from '../../../options.ts';
3
- import type { MiniProjectSkeletonInput } from '../mini/mini-contract.ts';
4
- type WxSkeletonInput = MiniProjectSkeletonInput & Readonly<{
5
- options: VptOptions;
6
- componentsModulePath: string;
7
- }>;
2
+ import type { MiniContract, MiniProjectSkeletonInput } from '../mini/mini-contract.ts';
8
3
  /**
9
4
  * Generates the WX templates that project one React ownership tree through two native Page data roots.
10
5
  *
@@ -53,5 +48,4 @@ type WxSkeletonInput = MiniProjectSkeletonInput & Readonly<{
53
48
  * Page root mutates the in-memory outlet but does not serialize that root into App data. A newly pushed native Page receives the
54
49
  * current complete App snapshot with its initial Page batch; retained and hidden Pages need no navigation synchronization.
55
50
  */
56
- export declare function createWxSkeleton({ bundle, subpackages, nativeComponents, isProduction, options, componentsModulePath }: WxSkeletonInput): Rolldown.EmittedAsset[];
57
- export {};
51
+ export declare function createWxSkeleton({ bundle, subpackages, nativeComponents, isProduction }: MiniProjectSkeletonInput, contract: MiniContract): Rolldown.EmittedAsset[];
@@ -1,10 +1,5 @@
1
1
  import type { Rolldown } from 'vite';
2
- import type { VptOptions } from '../../../options.ts';
3
- import type { MiniProjectSkeletonInput } from '../mini/mini-contract.ts';
4
- type ZfbSkeletonInput = MiniProjectSkeletonInput & Readonly<{
5
- options: VptOptions;
6
- componentsModulePath: string;
7
- }>;
2
+ import type { MiniContract, MiniProjectSkeletonInput } from '../mini/mini-contract.ts';
8
3
  /**
9
4
  * Generates the Alipay templates that project one React ownership tree through two independent native Page data roots.
10
5
  *
@@ -53,7 +48,6 @@ type ZfbSkeletonInput = MiniProjectSkeletonInput & Readonly<{
53
48
  * declaration, but accepts an empty array and still packages the files beneath that root. Keeping `pages: []` preserves the real
54
49
  * model: no synthetic Page, native lifecycle, route, or template exists merely to make code eligible for asynchronous loading.
55
50
  */
56
- export declare function createZfbSkeleton({ bundle, subpackages, nativeComponents, isProduction, options, componentsModulePath }: ZfbSkeletonInput): Rolldown.EmittedAsset[];
51
+ export declare function createZfbSkeleton({ bundle, subpackages, nativeComponents, isProduction }: MiniProjectSkeletonInput, contract: MiniContract): Rolldown.EmittedAsset[];
57
52
  /** Adds Alipay's transparent App collection and threads the independent Page root through every recursive data scope. */
58
53
  export declare function buildZfbBaseTemplate(source: string): string;
59
- export {};
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * WeChat DevTools can retain stale file contents when output directories are deleted and recreated.
3
- * Preserve every directory so its watcher stays attached, but unlink every file to invalidate cached contents.
3
+ * Preserve every directory so its watcher stays attached, retain caller-owned project files, and unlink the rest.
4
4
  */
5
- export declare function cleanOutputFiles(directory: string): void;
5
+ export declare function cleanOutputFiles(directory: string, preservedRelativePaths: readonly string[]): void;
@@ -1,8 +1,8 @@
1
- /** Host-to-App terminal control over the App heap's authenticated Vite socket. */
1
+ /** Host-to-App terminal control over the authenticated Vite socket owned by the running App. */
2
2
  export declare const runtimeControlEvent = "vpt:mini-hmr:control";
3
3
  /** App-to-host application frontier and rebuild reports over the same socket. */
4
4
  export declare const runtimeReportEvent = "vpt:mini-hmr:report";
5
- /** Build identity and authenticated socket endpoint fixed for one App heap. */
5
+ /** Build identity and authenticated socket endpoint fixed for the lifetime of one running App. */
6
6
  export type HmrInfo = Readonly<{
7
7
  buildId: string;
8
8
  endpoint: string;
@@ -1,4 +1,4 @@
1
- /** Host-to-App terminal control over the App heap's authenticated Vite socket. */
1
+ /** Host-to-App terminal control over the authenticated Vite socket owned by the running App. */
2
2
  export const runtimeControlEvent = 'vpt:mini-hmr:control';
3
3
  /** App-to-host application frontier and rebuild reports over the same socket. */
4
4
  export const runtimeReportEvent = 'vpt:mini-hmr:report';
@@ -1,3 +1,4 @@
1
+ import type { ElementType } from 'react';
1
2
  import type { DevRuntime as RolldownDevRuntime } from 'rolldown/experimental/runtime-types';
2
3
  import { type HmrInfo } from './hmr-protocol.ts';
3
4
  /** Lexical base class injected into the runtime chunk by Rolldown; typed via the contract. */
@@ -55,7 +56,7 @@ export type ConnectMiniSocket = (endpoint: string) => MiniSocketTask;
55
56
  /** Shared Mini Program host mechanics extending the Rolldown contract instead of reimplementing it. */
56
57
  export declare class MiniHmrRuntime extends DevRuntime {
57
58
  /**
58
- * One session for this App heap. Undefined only before the mode-selected entry initializes the runtime; its identity then
59
+ * One session for the running App. Undefined only before the mode-selected entry initializes the runtime; its identity then
59
60
  * stays fixed while appliedSeq records the committed frontier.
60
61
  */
61
62
  private session;
@@ -67,7 +68,7 @@ export declare class MiniHmrRuntime extends DevRuntime {
67
68
  * the new one. Passive contexts are never retained, so space is O(number of boundaries).
68
69
  */
69
70
  private readonly moduleHotContexts;
70
- /** Immutable platform socket constructor retained for the App heap's first initialization. */
71
+ /** Immutable platform socket constructor retained until the running App initializes. */
71
72
  private readonly connectSocket;
72
73
  constructor(connectSocket: ConnectMiniSocket);
73
74
  /**
@@ -76,6 +77,8 @@ export declare class MiniHmrRuntime extends DevRuntime {
76
77
  * calling accept registers the new context after the apply plan captured old callbacks.
77
78
  */
78
79
  createModuleHotContext(moduleId: string): MiniHotContext;
80
+ /** Resolves a cold Page against patches installed before its physical capsule first executed. */
81
+ resolvePageComponent(moduleId: string, baseline: ElementType): ElementType;
79
82
  /** Computes accepting boundaries and every executed module that must be re-armed. */
80
83
  private computeHmrUpdate;
81
84
  /** Walks executed importers until an accepting boundary is found. */
@@ -86,7 +89,7 @@ export declare class MiniHmrRuntime extends DevRuntime {
86
89
  */
87
90
  private applyHmrUpdate;
88
91
  /**
89
- * Initializes exactly once per App heap. Repeated entry evaluation must not replace the identity or reset `appliedSeq`, because
92
+ * Initializes exactly once each time DevTools loads the App. Repeated entry evaluation must not replace the identity or reset `appliedSeq`, because
90
93
  * either change could acknowledge factories against another host client or replay already committed application generations.
91
94
  */
92
95
  initialize(info: HmrInfo): void;
@@ -60,7 +60,7 @@ class MiniHotContext {
60
60
  /** Shared Mini Program host mechanics extending the Rolldown contract instead of reimplementing it. */
61
61
  export class MiniHmrRuntime extends DevRuntime {
62
62
  /**
63
- * One session for this App heap. Undefined only before the mode-selected entry initializes the runtime; its identity then
63
+ * One session for the running App. Undefined only before the mode-selected entry initializes the runtime; its identity then
64
64
  * stays fixed while appliedSeq records the committed frontier.
65
65
  */
66
66
  session;
@@ -73,7 +73,7 @@ export class MiniHmrRuntime extends DevRuntime {
73
73
  * the new one. Passive contexts are never retained, so space is O(number of boundaries).
74
74
  */
75
75
  moduleHotContexts = new Map();
76
- /** Immutable platform socket constructor retained for the App heap's first initialization. */
76
+ /** Immutable platform socket constructor retained until the running App initializes. */
77
77
  connectSocket;
78
78
  constructor(connectSocket) {
79
79
  // The base has no messenger: the engine tracks per-client shipped payloads instead
@@ -94,6 +94,19 @@ export class MiniHmrRuntime extends DevRuntime {
94
94
  this.moduleHotContexts.delete(moduleId);
95
95
  return new MiniHotContext(moduleId, this.moduleHotContexts);
96
96
  }
97
+ /** Resolves a cold Page against patches installed before its physical capsule first executed. */
98
+ resolvePageComponent(moduleId, baseline) {
99
+ if (!this.hasFactory(moduleId)) {
100
+ return baseline;
101
+ }
102
+ // An unopened native Page evaluates its original capsule after the patch has already been ACKed. That capsule
103
+ // registers baseline exports in Rolldown's cache, shadowing the installed patch factory. Only evict that exact
104
+ // baseline reference: an already-refreshed Page's current exports must not be re-executed on every render.
105
+ if (this.isExecuted(moduleId) && this.loadExports(moduleId).default === baseline) {
106
+ this.removeModuleCache(moduleId);
107
+ }
108
+ return this.initModule(moduleId).default;
109
+ }
97
110
  /** Computes accepting boundaries and every executed module that must be re-armed. */
98
111
  computeHmrUpdate(changedIds) {
99
112
  // Mutable traversal accumulators are confined to one synchronous update plan.
@@ -163,7 +176,7 @@ export class MiniHmrRuntime extends DevRuntime {
163
176
  }
164
177
  }
165
178
  /**
166
- * Initializes exactly once per App heap. Repeated entry evaluation must not replace the identity or reset `appliedSeq`, because
179
+ * Initializes exactly once each time DevTools loads the App. Repeated entry evaluation must not replace the identity or reset `appliedSeq`, because
167
180
  * either change could acknowledge factories against another host client or replay already committed application generations.
168
181
  */
169
182
  initialize(info) {
@@ -219,13 +232,13 @@ export class MiniHmrRuntime extends DevRuntime {
219
232
  return;
220
233
  }
221
234
  if (!this.socket) {
222
- // Before OPEN the new heap uses only the disk baseline. Startup requests a rebuild if patches were published;
235
+ // Before OPEN the newly loaded App uses only the disk baseline. Startup requests a rebuild if patches were published;
223
236
  // do not replay their factories early or queue them for later. Closed connections likewise cannot acknowledge updates.
224
237
  return;
225
238
  }
226
239
  if (session.appliedSeq === 0 && payload.patches.length > 0 && payload.patches[0].seq > 1) {
227
240
  // Compile starts from the original bundle, but the physical file can be an ACK-pruned suffix. Do not install it or
228
- // classify an expected new-heap synchronization as patch corruption. OPEN reports startup automatically; if already
241
+ // classify expected startup synchronization as patch corruption. OPEN reports startup automatically; if already
229
242
  // connected, ask the host to rebuild the baseline now.
230
243
  this.sendReport({ kind: 'startup' });
231
244
  return;
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * DevTools adapter injected into the App-global Rolldown runtime chunk. Every Page evaluates the inert `hmr/patches.js` payload
3
- * before its route capsule, while this singleton survives Page JavaScript hot reload in the App heap. That lifetime difference is
3
+ * before its route capsule, while this singleton survives Page JavaScript hot reload as the App keeps running. That lifetime difference is
4
4
  * what allows module and React state to survive repeated native Page registration.
5
5
  */
6
6
  import { MiniHmrRuntime } from '../../mini-hmr-runtime.js';
@@ -2,7 +2,7 @@ import type { HmrInfo } from '../../hmr-protocol.ts';
2
2
  import { type ConnectMiniSocket, MiniHmrRuntime } from '../../mini-hmr-runtime.ts';
3
3
  /** Interprets cumulative patch source received by the shared App-level HMR socket. */
4
4
  declare class InterpreterHmrRuntime extends MiniHmrRuntime {
5
- /** One installer and Sval scope retain interpreted factory closures for this App heap. */
5
+ /** One installer and Sval scope retain interpreted factory closures for the lifetime of the running App. */
6
6
  private readonly installPatch;
7
7
  constructor(connectSocket: ConnectMiniSocket);
8
8
  protected onSocketEvent(info: HmrInfo, event: string, data: unknown): void;
@@ -7,7 +7,7 @@ import { MiniHmrRuntime } from '../../mini-hmr-runtime.js';
7
7
  import { interpreterServerEvent } from './interpreter-protocol.js';
8
8
  /** Interprets cumulative patch source received by the shared App-level HMR socket. */
9
9
  class InterpreterHmrRuntime extends MiniHmrRuntime {
10
- /** One installer and Sval scope retain interpreted factory closures for this App heap. */
10
+ /** One installer and Sval scope retain interpreted factory closures for the lifetime of the running App. */
11
11
  installPatch;
12
12
  constructor(connectSocket) {
13
13
  super(connectSocket);
@@ -37,7 +37,7 @@ systemJSPrototype.import = function (id, parentId, meta) {
37
37
  *
38
38
  * Mini Program placement guarantees that every registration in a synchronous graph uses the main-package transport. Encountering
39
39
  * a thenable therefore indicates a fatal placement invariant violation. No rollback is attempted: rows already published
40
- * to the shared registry remain there and the current runtime heap must not be reused.
40
+ * to the shared registry remain there and the current runtime instance must not be reused.
41
41
  */
42
42
  systemJSPrototype.importSync = function (id) {
43
43
  var loader = this;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-taro",
3
- "version": "0.7.7",
3
+ "version": "0.7.9",
4
4
  "author": "sep2",
5
5
  "description": "Vite 8 plugin for building one React/Taro codebase for WeChat, Alipay, TikTok, and H5 targets.",
6
6
  "type": "module",
@@ -67,7 +67,7 @@
67
67
  "rolldown": "1.2.9",
68
68
  "sval": "0.6.12",
69
69
  "tailwindcss": "^4.3.3",
70
- "vite-plugin-taro-runtime": "0.7.7"
70
+ "vite-plugin-taro-runtime": "0.7.9"
71
71
  },
72
72
  "peerDependencies": {
73
73
  "react": "^19.3.0",
@@ -91,6 +91,7 @@
91
91
  "c8": "^12.0.0",
92
92
  "oxc-walker": "1.1.1",
93
93
  "picocolors": "^1.1.1",
94
+ "postcss-rule-unit-converter": "0.2.3",
94
95
  "rxjs": "^7.8.2",
95
96
  "typescript": "^7.0.2",
96
97
  "vite": "8.3.0"