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
@@ -1,4 +1,7 @@
1
1
  import type { Plugin } from 'vite';
2
- import type { VptTarget } from '../../../../options.ts';
2
+ import type { MiniContract } from '../mini-contract.ts';
3
3
  /** Preserves watched directories and forces full reloads for Mini Program watch output without changing serve HMR. */
4
- export declare function createMiniWatchPlugin(target: VptTarget): Plugin;
4
+ export declare function createMiniWatchPlugin(contract: {
5
+ output: Pick<MiniContract['output'], 'projectConfigFilename' | 'projectPrivateConfigFilename'>;
6
+ watch: MiniContract['watch'];
7
+ }): Plugin;
@@ -0,0 +1,3 @@
1
+ import type { createResolver } from '../plugins/mini/resolve/resolver.ts';
2
+ /** Supplies native entry metadata around test-owned capsule sources without loading production shells. */
3
+ export declare function createMiniStyleEntries(appId: string, pageIds: readonly string[]): ReturnType<typeof createResolver>['entries'];
@@ -0,0 +1,7 @@
1
+ import type { HmrInfo } from '../plugins/mini/dev/hmr-protocol.ts';
2
+ /** Executes generated native CommonJS, SystemJS transport and HMR code without a DevTools installation. */
3
+ export declare function createNativeDevRuntime(outDir: string, info: HmrInfo): {
4
+ run: (code: string) => unknown;
5
+ reports: unknown[];
6
+ applyPatches(source: string): void;
7
+ };
@@ -1,5 +1,5 @@
1
1
  export declare const packageRequire: NodeJS.Require;
2
- /** Resolves a file shipped by this package as a portable Vite module ID. */
3
- export declare function resolvePackageFile(...segments: string[]): string;
2
+ /** Resolves a public export of the bundled Taro runtime package. */
3
+ export declare function resolveTaroRuntime(subpath: string): string;
4
4
  /** Resolves an unbundled browser runtime module from source in the workspace and from dist after publication. */
5
- export declare function resolveRuntimeFile(modulePath: string): string;
5
+ export declare function resolveVptRuntime(modulePath: string): string;
@@ -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,7 +1,6 @@
1
- import type { DevRuntime as RolldownDevRuntime } from 'rolldown/experimental/runtime-types';
1
+ import type { ElementType } from 'react';
2
+ import { DevRuntime } from 'rolldown/experimental/runtime';
2
3
  import { type HmrInfo } from './hmr-protocol.ts';
3
- /** Lexical base class injected into the runtime chunk by Rolldown; typed via the contract. */
4
- declare const DevRuntime: new (clientId: string) => RolldownDevRuntime;
5
4
  /** Mode-independent patch metadata consumed by the shared sequence and graph reducer. */
6
5
  export type RuntimePatch = Readonly<{
7
6
  seq: number;
@@ -55,11 +54,12 @@ export type ConnectMiniSocket = (endpoint: string) => MiniSocketTask;
55
54
  /** Shared Mini Program host mechanics extending the Rolldown contract instead of reimplementing it. */
56
55
  export declare class MiniHmrRuntime extends DevRuntime {
57
56
  /**
58
- * One session for this App heap. Undefined only before the mode-selected entry initializes the runtime; its identity then
57
+ * One session for the running App. Undefined only before the mode-selected entry initializes the runtime; its identity then
59
58
  * stays fixed while appliedSeq records the committed frontier.
60
59
  */
61
60
  private session;
62
61
  private socket;
62
+ private disconnectWarningHandled;
63
63
  /**
64
64
  * Sparse current-generation accepting boundaries keyed by module id. Entries alone must
65
65
  * outlive Rolldown module-cache eviction so old callbacks can receive fresh exports.
@@ -67,7 +67,7 @@ export declare class MiniHmrRuntime extends DevRuntime {
67
67
  * the new one. Passive contexts are never retained, so space is O(number of boundaries).
68
68
  */
69
69
  private readonly moduleHotContexts;
70
- /** Immutable platform socket constructor retained for the App heap's first initialization. */
70
+ /** Immutable platform socket constructor retained until the running App initializes. */
71
71
  private readonly connectSocket;
72
72
  constructor(connectSocket: ConnectMiniSocket);
73
73
  /**
@@ -76,6 +76,8 @@ export declare class MiniHmrRuntime extends DevRuntime {
76
76
  * calling accept registers the new context after the apply plan captured old callbacks.
77
77
  */
78
78
  createModuleHotContext(moduleId: string): MiniHotContext;
79
+ /** Resolves a cold Page against patches installed before its physical capsule first executed. */
80
+ resolvePageComponent(moduleId: string, baseline: ElementType): ElementType;
79
81
  /** Computes accepting boundaries and every executed module that must be re-armed. */
80
82
  private computeHmrUpdate;
81
83
  /** Walks executed importers until an accepting boundary is found. */
@@ -86,7 +88,7 @@ export declare class MiniHmrRuntime extends DevRuntime {
86
88
  */
87
89
  private applyHmrUpdate;
88
90
  /**
89
- * Initializes exactly once per App heap. Repeated entry evaluation must not replace the identity or reset `appliedSeq`, because
91
+ * Initializes exactly once each time DevTools loads the App. Repeated entry evaluation must not replace the identity or reset `appliedSeq`, because
90
92
  * either change could acknowledge factories against another host client or replay already committed application generations.
91
93
  */
92
94
  initialize(info: HmrInfo): void;
@@ -1,11 +1,12 @@
1
1
  /*
2
2
  * Shared Mini Program HMR runtime, bundled into the mode-selected entry and injected into Rolldown's generated runtime chunk.
3
- * Rolldown provides the lexical `DevRuntime` base class; this file extends that registry instead of duplicating module loading.
3
+ * The exported Rolldown `DevRuntime` is bundled with this adapter instead of relying on an implicitly injected base class.
4
4
  *
5
5
  * Concrete modes decide how executable registrations arrive—native project JavaScript or interpreted source—and provide only a
6
6
  * synchronous installer. This class owns the invariant that installation, graph propagation, cache eviction, boundary execution,
7
7
  * and ACK form one application transaction; it has no file-delivery or interpreter policy of its own.
8
8
  */
9
+ import { DevRuntime } from 'rolldown/experimental/runtime';
9
10
  import { runtimeControlEvent, runtimeReportEvent } from './hmr-protocol.js';
10
11
  import { polyfillQueueMicrotask } from './polyfill/polyfill-queue-microtask.js';
11
12
  /** Shared no-op CSS contract because physical rebuilds replace styles wholesale. */
@@ -60,12 +61,14 @@ class MiniHotContext {
60
61
  /** Shared Mini Program host mechanics extending the Rolldown contract instead of reimplementing it. */
61
62
  export class MiniHmrRuntime extends DevRuntime {
62
63
  /**
63
- * One session for this App heap. Undefined only before the mode-selected entry initializes the runtime; its identity then
64
+ * One session for the running App. Undefined only before the mode-selected entry initializes the runtime; its identity then
64
65
  * stays fixed while appliedSeq records the committed frontier.
65
66
  */
66
67
  session;
67
68
  // Set only by native OPEN and cleared on close/error: this reference is the authority for whether reports can be sent.
68
69
  socket;
70
+ // One socket belongs to this App runtime. Its first failure or deliberate stop silences subsequent error/close warnings.
71
+ disconnectWarningHandled = false;
69
72
  /**
70
73
  * Sparse current-generation accepting boundaries keyed by module id. Entries alone must
71
74
  * outlive Rolldown module-cache eviction so old callbacks can receive fresh exports.
@@ -73,7 +76,7 @@ export class MiniHmrRuntime extends DevRuntime {
73
76
  * the new one. Passive contexts are never retained, so space is O(number of boundaries).
74
77
  */
75
78
  moduleHotContexts = new Map();
76
- /** Immutable platform socket constructor retained for the App heap's first initialization. */
79
+ /** Immutable platform socket constructor retained until the running App initializes. */
77
80
  connectSocket;
78
81
  constructor(connectSocket) {
79
82
  // The base has no messenger: the engine tracks per-client shipped payloads instead
@@ -94,6 +97,19 @@ export class MiniHmrRuntime extends DevRuntime {
94
97
  this.moduleHotContexts.delete(moduleId);
95
98
  return new MiniHotContext(moduleId, this.moduleHotContexts);
96
99
  }
100
+ /** Resolves a cold Page against patches installed before its physical capsule first executed. */
101
+ resolvePageComponent(moduleId, baseline) {
102
+ if (!this.hasFactory(moduleId)) {
103
+ return baseline;
104
+ }
105
+ // An unopened native Page evaluates its original capsule after the patch has already been ACKed. That capsule
106
+ // registers baseline exports in Rolldown's cache, shadowing the installed patch factory. Only evict that exact
107
+ // baseline reference: an already-refreshed Page's current exports must not be re-executed on every render.
108
+ if (this.isExecuted(moduleId) && this.loadExports(moduleId).default === baseline) {
109
+ this.removeModuleCache(moduleId);
110
+ }
111
+ return this.initModule(moduleId).default;
112
+ }
97
113
  /** Computes accepting boundaries and every executed module that must be re-armed. */
98
114
  computeHmrUpdate(changedIds) {
99
115
  // Mutable traversal accumulators are confined to one synchronous update plan.
@@ -120,7 +136,9 @@ export class MiniHmrRuntime extends DevRuntime {
120
136
  boundaries.push(moduleId);
121
137
  return undefined;
122
138
  }
123
- const importers = this.getImporters(moduleId).filter((importer) => this.isExecuted(importer));
139
+ // A Page wrapper can import itself in Rolldown's graph. That edge makes no progress toward an accepting boundary;
140
+ // excluding it preserves real multi-module cycle detection below without rejecting an otherwise valid Page update.
141
+ const importers = this.getImporters(moduleId).filter((importer) => importer !== moduleId && this.isExecuted(importer));
124
142
  if (importers.length === 0) {
125
143
  return `no HMR boundary found for module ${moduleId}`;
126
144
  }
@@ -163,7 +181,7 @@ export class MiniHmrRuntime extends DevRuntime {
163
181
  }
164
182
  }
165
183
  /**
166
- * Initializes exactly once per App heap. Repeated entry evaluation must not replace the identity or reset `appliedSeq`, because
184
+ * Initializes exactly once each time DevTools loads the App. Repeated entry evaluation must not replace the identity or reset `appliedSeq`, because
167
185
  * either change could acknowledge factories against another host client or replay already committed application generations.
168
186
  */
169
187
  initialize(info) {
@@ -172,11 +190,16 @@ export class MiniHmrRuntime extends DevRuntime {
172
190
  }
173
191
  this.session = { buildId: info.buildId, appliedSeq: 0 };
174
192
  const socket = this.connectSocket(info.endpoint);
175
- const clearSocket = () => {
193
+ const handleDisconnect = () => {
176
194
  this.socket = undefined;
195
+ if (this.disconnectWarningHandled) {
196
+ return;
197
+ }
198
+ this.disconnectWarningHandled = true;
199
+ console.warn('[vpt] HMR disconnected. Ensure the Vite dev server is running, then reload the Mini Program in DevTools.');
177
200
  };
178
- socket.onClose(clearSocket);
179
- socket.onError(clearSocket);
201
+ socket.onClose(handleDisconnect);
202
+ socket.onError(handleDisconnect);
180
203
  socket.onOpen(() => {
181
204
  this.socket = socket;
182
205
  this.sendReport({ kind: 'startup' });
@@ -203,6 +226,8 @@ export class MiniHmrRuntime extends DevRuntime {
203
226
  throw new Error('Mini Program HMR socket is not initialized');
204
227
  }
205
228
  const socket = this.socket;
229
+ // Mark intentional shutdown before invoking the native API, which may immediately emit close or error.
230
+ this.disconnectWarningHandled = true;
206
231
  this.socket = undefined;
207
232
  socket?.close({ code: 1000, reason: reason });
208
233
  }
@@ -219,13 +244,13 @@ export class MiniHmrRuntime extends DevRuntime {
219
244
  return;
220
245
  }
221
246
  if (!this.socket) {
222
- // Before OPEN the new heap uses only the disk baseline. Startup requests a rebuild if patches were published;
247
+ // Before OPEN the newly loaded App uses only the disk baseline. Startup requests a rebuild if patches were published;
223
248
  // do not replay their factories early or queue them for later. Closed connections likewise cannot acknowledge updates.
224
249
  return;
225
250
  }
226
251
  if (session.appliedSeq === 0 && payload.patches.length > 0 && payload.patches[0].seq > 1) {
227
252
  // 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
253
+ // classify expected startup synchronization as patch corruption. OPEN reports startup automatically; if already
229
254
  // connected, ask the host to rebuild the baseline now.
230
255
  this.sendReport({ kind: 'startup' });
231
256
  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.8",
3
+ "version": "0.7.10-beta.0",
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.8"
70
+ "vite-plugin-taro-runtime": "0.7.10-beta.0"
71
71
  },
72
72
  "peerDependencies": {
73
73
  "react": "^19.3.0",
@@ -80,18 +80,18 @@
80
80
  "@babel/plugin-transform-dynamic-import": "^8.0.1",
81
81
  "@babel/plugin-transform-modules-commonjs": "^8.0.1",
82
82
  "@babel/plugin-transform-modules-systemjs": "^8.0.1",
83
- "@oxc-project/types": "0.150.0",
83
+ "@oxc-project/types": "0.151.0",
84
84
  "@tailwindcss-mangle/engine": "0.2.0",
85
85
  "@types/node": "^26.6.2",
86
86
  "@types/react": "^19.3.0",
87
87
  "@types/react-dom": "^19.3.0",
88
88
  "@types/react-refresh": "^0.14.7",
89
89
  "@weapp-core/escape": "8.0.0",
90
- "@weapp-tailwindcss/postcss": "3.3.5",
90
+ "@weapp-tailwindcss/postcss": "3.3.7",
91
91
  "c8": "^12.0.0",
92
92
  "oxc-walker": "1.1.1",
93
93
  "picocolors": "^1.1.1",
94
- "postcss-pxtrans": "1.0.4",
94
+ "postcss-rule-unit-converter": "0.2.3",
95
95
  "rxjs": "^7.8.2",
96
96
  "typescript": "^7.0.2",
97
97
  "vite": "8.3.0"