vite-plugin-taro 0.6.3 → 0.6.6

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 (29) hide show
  1. package/README.en.md +3 -3
  2. package/README.md +3 -3
  3. package/dist/node/plugins/wx/dev/dev-host.d.ts +5 -4
  4. package/dist/node/plugins/wx/dev/dev-host.js +19 -43
  5. package/dist/node/plugins/wx/dev/plugins.d.ts +4 -3
  6. package/dist/node/plugins/wx/dev/plugins.js +4 -4
  7. package/dist/node/plugins/wx/dev/wx-dev-options.d.ts +2 -3
  8. package/dist/node/plugins/wx/dev/wx-dev-options.js +4 -4
  9. package/dist/node/plugins/wx/plugins.js +5 -11
  10. package/dist/node/plugins/wx/styles/plugins.d.ts +141 -3
  11. package/dist/node/plugins/wx/styles/plugins.js +401 -89
  12. package/dist/node/utils/vite.d.ts +4 -14
  13. package/dist/node/utils/vite.js +7 -40
  14. package/package.json +4 -3
  15. package/src/node/plugins/wx/dev/dev-host.ts +22 -44
  16. package/src/node/plugins/wx/dev/plugins.ts +5 -4
  17. package/src/node/plugins/wx/dev/wx-dev-options.ts +5 -7
  18. package/src/node/plugins/wx/plugins.ts +5 -11
  19. package/src/node/plugins/wx/styles/plugins.ts +518 -93
  20. package/src/node/utils/vite.ts +13 -58
  21. package/dist/node/plugins/wx/dev/create-style-capture.d.ts +0 -54
  22. package/dist/node/plugins/wx/dev/create-style-capture.js +0 -173
  23. package/dist/node/plugins/wx/styles/transform-wx-style.d.ts +0 -8
  24. package/dist/node/plugins/wx/styles/transform-wx-style.js +0 -9
  25. package/dist/node/plugins/wx/styles/utils.d.ts +0 -39
  26. package/dist/node/plugins/wx/styles/utils.js +0 -95
  27. package/src/node/plugins/wx/dev/create-style-capture.ts +0 -248
  28. package/src/node/plugins/wx/styles/transform-wx-style.ts +0 -11
  29. package/src/node/plugins/wx/styles/utils.ts +0 -119
@@ -1,4 +1,3 @@
1
- import { readFile } from 'node:fs/promises'
2
1
  import type { ServerResponse } from 'node:http'
3
2
  import path from 'node:path'
4
3
  import colors from 'picocolors'
@@ -6,10 +5,11 @@ import { type DevEngine, type DevOptions, dev } from 'rolldown/experimental'
6
5
  import { asyncScheduler } from 'rxjs'
7
6
  import type { Connect, ViteDevServer } from 'vite'
8
7
  import type { VptOptions } from '../../../../options.ts'
8
+ import type { WxStylePlugin } from '../styles/plugins.ts'
9
9
  import { createHmrResultsStream } from './create-hmr-results-stream.ts'
10
- import { createStyleCapture, type StyleCaptureAction } from './create-style-capture.ts'
11
10
  import {
12
11
  developmentAppWxssFileName,
12
+ globalWxssFileName,
13
13
  type HmrInfo,
14
14
  hmrControlPath,
15
15
  hmrInfoFileName,
@@ -36,7 +36,6 @@ type DevOutputResult = Parameters<NonNullable<DevOptions['onOutput']>>[0]
36
36
  type OutputAction = Readonly<{ kind: 'output'; result: DevOutputResult }>
37
37
 
38
38
  type HostAction =
39
- | StyleCaptureAction
40
39
  | Readonly<{ kind: 'publish'; result: HmrUpdates }>
41
40
  | Readonly<{ kind: 'error'; error: Error }>
42
41
  | Readonly<{ kind: 'reports'; reports: readonly RuntimeReport[] }>
@@ -52,17 +51,17 @@ const hmrSettleMilliseconds = 16
52
51
  * engine writes directly to the Mini Program output directory instead of serving browser
53
52
  * HMR over HTTP.
54
53
  *
55
- * `applicationEntryIds` is the resolver's immutable cascade policy, not a second graph: it selects the App capsule followed
56
- * by configured Page capsules from Rolldown's larger entry set. Rolldown remains the authority for every live import edge.
54
+ * The shared style plugin carries the resolver's immutable App/Page cascade policy while Rolldown remains authoritative for
55
+ * every live import edge.
57
56
  */
58
57
  export async function createWxDevHost({
59
58
  server,
60
59
  options,
61
- applicationEntryIds
60
+ styles
62
61
  }: {
63
62
  server: ViteDevServer
64
63
  options: VptOptions
65
- applicationEntryIds: readonly string[]
64
+ styles: WxStylePlugin
66
65
  }): Promise<WxDevHost> {
67
66
  const bundledDev = getBundledDev(server)
68
67
 
@@ -71,23 +70,12 @@ export async function createWxDevHost({
71
70
  logWxError(server.config.logger, `wx HMR ${action.kind} failed`, error)
72
71
  )
73
72
 
74
- const styleCapture = createStyleCapture({
75
- applicationEntryIds: applicationEntryIds,
76
- outDir: server.config.build.outDir,
77
- // Capture hooks run only after engine.run, when the host action subscription and all reducer dependencies are ready.
78
- emit: (action) => hostActions.next(action),
79
- transformTailwindRoot: async (rootId, requestId) => {
80
- // The capture contains generated CSS, while the sidecar must re-run from raw Tailwind directives. Vite exposes no
81
- // raw source in its live module graph, so this read is the authoritative source generation rather than a read-back.
82
- return server.environments.client.pluginContainer.transform(await readFile(rootId, 'utf8'), requestId)
83
- }
84
- })
85
73
  const publisher = new PatchPublisher((content) =>
86
74
  writeHmrFile(server.config.build.outDir, hmrPatchesFileName, content)
87
75
  )
88
76
 
89
77
  // Option installation now configures only Rolldown. Build lifecycle results enter through the engine's output action below.
90
- installWxDevOptions({ bundledDev, server, options, hostPlugins: [styleCapture.plugin] })
78
+ installWxDevOptions({ bundledDev, server, options })
91
79
  const engine: DevEngine = await createEngine()
92
80
 
93
81
  const hmrResults = createHmrResultsStream(
@@ -158,12 +146,17 @@ export async function createWxDevHost({
158
146
  hmrResults.complete()
159
147
  runtimeReports.complete()
160
148
  await hostActions.waitForIdle()
161
- // Keep the action edge open until the final generation has admitted all capture and output callbacks.
149
+ // Keep the action edge open until the final generation has admitted every output callback.
162
150
  await engine.ensureCurrentBuildFinish()
163
151
  await hostActions.complete()
164
152
  }
165
153
  }
166
154
 
155
+ /** Atomically materializes the style plugin's prepared global artifact. */
156
+ async function writeGlobalStyle(wxss: string): Promise<void> {
157
+ await writeHmrFile(server.config.build.outDir, globalWxssFileName, wxss)
158
+ }
159
+
167
160
  /** Rotates the build identity and materializes the App metadata for it. */
168
161
  async function rotateBuildSession(): Promise<void> {
169
162
  const port = boundPort(server)
@@ -207,14 +200,6 @@ export async function createWxDevHost({
207
200
  /** Reduces one merged source action through the existing authoritative host state. */
208
201
  function applyHostAction(action: HostAction): void | Promise<void> {
209
202
  switch (action.kind) {
210
- case 'capture-graph':
211
- // The buildStart reader is a live capability; replacing it only here makes the reducer own build rebinding.
212
- styleCapture.captureGraph(action.getModuleInfo)
213
- return
214
- case 'capture-style':
215
- // A failed upstream transform emits no action, intentionally retaining the last valid processed CSS generation.
216
- styleCapture.captureStyle(action.id, action.style)
217
- return
218
203
  case 'publish':
219
204
  return publishUpdates(action.result)
220
205
  case 'error':
@@ -228,21 +213,15 @@ export async function createWxDevHost({
228
213
  logWxError(server.config.logger, 'wx dev build failed', action.result)
229
214
  return
230
215
  }
231
- return reconcileCompleteOutput(action.result.output)
216
+ return publishCompleteStyles()
232
217
  case 'listening':
233
218
  return rotateBuildSession()
234
219
  }
235
220
  }
236
221
 
237
- /**
238
- * Reconciles graph-complete styles before rotating the App-visible build identity.
239
- *
240
- * DevEngine has already written its compiler asset when onOutput fires, but bundled development may have omitted CSS Modules
241
- * from that asset. Awaiting reconciliation inside the serialized reducer guarantees the subsequent app.wxss rotation—the
242
- * event that refreshes DevTools—can only expose a generation whose global WXSS already represents the complete App/Page graph.
243
- */
244
- async function reconcileCompleteOutput(output: Exclude<DevOutputResult, Error>['output']): Promise<void> {
245
- await styleCapture.reconcileComplete(output)
222
+ /** Publishes graph-complete styles before rotating the App-visible build identity. */
223
+ async function publishCompleteStyles(): Promise<void> {
224
+ await styles.finalizeUpdate([], writeGlobalStyle)
246
225
  await rotateBuildSession()
247
226
  }
248
227
 
@@ -329,18 +308,17 @@ export async function createWxDevHost({
329
308
  return
330
309
  }
331
310
 
332
- // `onHmrUpdates` is the transaction boundary after every affected transform has updated graph and candidate state.
333
- // Every non-CSS edit may alter imports or Tailwind classes; rendering broadly and comparing finalized bytes avoids
334
- // source scanning while preventing unrelated JavaScript edits from notifying DevTools through an identical rename.
335
- await styleCapture.publishChanged(patches.flatMap((patch) => patch.changedIds))
311
+ // `onHmrUpdates` runs after every affected transform has updated captured CSS and the live import graph. The style
312
+ // boundary finalizes every factory before atomically publishing their matching WXSS.
313
+ const finalizedPatches = await styles.finalizeUpdate(patches, writeGlobalStyle)
336
314
 
337
315
  // Publish global.wxss before the matching JavaScript patch so DevTools observes a coherent HMR transaction.
338
316
  // The physical file must exist before Rolldown advances: once committed, later patches may be generated relative to
339
317
  // this batch even if DevTools has not observed its file event yet. PatchPublisher keeps the unapplied range cumulative,
340
318
  // so any later file generation still carries every factory needed to bridge the runtime's older application frontier.
341
- await publisher.produce(patches)
319
+ await publisher.produce(finalizedPatches)
342
320
 
343
- await commitPublishedBatch(patches)
321
+ await commitPublishedBatch(finalizedPatches)
344
322
  }
345
323
 
346
324
  /**
@@ -4,6 +4,7 @@ import { esTarget } from '../../../utils/constant.ts'
4
4
  import { memoize } from '../../../utils/memoize.ts'
5
5
  import { normalizeModuleId } from '../../../utils/modules.ts'
6
6
  import { pageShellPath, rolldownRuntimeId } from '../module/module.ts'
7
+ import type { WxStylePlugin } from '../styles/plugins.ts'
7
8
  import { createWxDevHost, type WxDevHost } from './dev-host.ts'
8
9
  import { developmentAppWxssFileName } from './hmr-files.ts'
9
10
  import { createWxReactRefreshTransforms } from './react-refresh.ts'
@@ -17,10 +18,10 @@ export function isWxClientEnvironment(environment: Readonly<{ name: string }>):
17
18
  * Adds the serve-only bundled-development plugin set for the wx target: the dev adapter,
18
19
  * Page HMR activation, and React Refresh adaptation transforms.
19
20
  *
20
- * The ordered application entries cross this configuration boundary unchanged so the host can compose global CSS without
21
- * reconstructing the resolver's App/Page ownership policy from unrelated Rolldown shell and transport entries.
21
+ * The shared style pipeline already owns the resolver's ordered App/Page cascade policy, so the host does not reconstruct it
22
+ * from unrelated Rolldown shell and transport entries.
22
23
  */
23
- export function createWxDevelopmentPlugin(options: VptOptions, applicationEntryIds: readonly string[]): PluginOption[] {
24
+ export function createWxDevelopmentPlugin(options: VptOptions, styles: WxStylePlugin): PluginOption[] {
24
25
  /*
25
26
  * Vite creates this plugin descriptor before a server or DevEngine exists, then invokes configureServer and closeBundle on
26
27
  * different lifecycle stacks. This mutable handle transfers the one client-owned host between those hooks: configureServer
@@ -71,7 +72,7 @@ export function createWxDevelopmentPlugin(options: VptOptions, applicationEntryI
71
72
  host = await createWxDevHost({
72
73
  server: server,
73
74
  options: options,
74
- applicationEntryIds: applicationEntryIds
75
+ styles: styles
75
76
  })
76
77
  }
77
78
  },
@@ -1,5 +1,5 @@
1
1
  import path from 'node:path'
2
- import type { InputOptions, OutputOptions, Plugin } from 'rolldown'
2
+ import type { InputOptions, OutputOptions } from 'rolldown'
3
3
  import { build } from 'rolldown'
4
4
  import { type DevEngine, viteReporterPlugin } from 'rolldown/experimental'
5
5
  import type { ViteDevServer } from 'vite'
@@ -30,13 +30,11 @@ export type BundledDev = {
30
30
  export function installWxDevOptions({
31
31
  bundledDev,
32
32
  server,
33
- options,
34
- hostPlugins
33
+ options
35
34
  }: {
36
35
  bundledDev: BundledDev
37
36
  server: ViteDevServer
38
37
  options: VptOptions
39
- hostPlugins: Plugin[]
40
38
  }): void {
41
39
  /*
42
40
  * Vite owns this mutable adapter method and calls it later when constructing DevEngine. Replacing that one seam preserves
@@ -113,10 +111,10 @@ export function installWxDevOptions({
113
111
 
114
112
  /*
115
113
  * The plugin list is mutable configuration consumed once by this engine generation. Replace the top-level reference with
116
- * an ordered composite rather than pushing into Vite's potentially shared nested array: existing transforms run first,
117
- * host capture observes their final values, and the reporter observes final output without mutating either input list.
114
+ * an ordered composite rather than pushing into Vite's potentially shared nested array; the reporter observes final output
115
+ * without mutating Vite's retained input list.
118
116
  */
119
- rolldownOptions.plugins = [rolldownOptions.plugins, hostPlugins, createViteReporter(server)]
117
+ rolldownOptions.plugins = [rolldownOptions.plugins, createViteReporter(server)]
120
118
  disableViteOxcSourcemap(rolldownOptions.plugins)
121
119
 
122
120
  return rolldownOptions
@@ -12,7 +12,7 @@ import { renderCapsule } from './render/capsule.ts'
12
12
  import { renderNative } from './render/native.ts'
13
13
  import { materializeTransport } from './render/transport.ts'
14
14
  import { createResolver } from './resolve/resolver.ts'
15
- import { createWxStylePlugins } from './styles/plugins.ts'
15
+ import { createWxStylePlugin } from './styles/plugins.ts'
16
16
 
17
17
  type WxResolver = ReturnType<typeof createResolver>
18
18
 
@@ -23,13 +23,9 @@ export function createWxTargetPlugins(options: VptOptions): PluginOption[] {
23
23
  // Reuse the resolver instance's ordered application subset. Rolldown's complete input also contains bootstrap, transport,
24
24
  // shell, and component entries; entry membership alone cannot recover which roots define the App/Page CSS cascade.
25
25
  const placement = createWxPlacementPlugin()
26
+ const styles = createWxStylePlugin(resolver.applicationEntryIds)
26
27
 
27
- return [
28
- placement,
29
- createWxStylePlugins(),
30
- createWxPlugin(options, resolver, placement),
31
- createWxDevelopmentPlugin(options, resolver.applicationEntryIds)
32
- ]
28
+ return [placement, styles, createWxPlugin(options, resolver, placement), createWxDevelopmentPlugin(options, styles)]
33
29
  }
34
30
 
35
31
  /** Configures the complete wx target build pipeline. */
@@ -133,10 +129,8 @@ function createWxPlugin(options: VptOptions, resolver: WxResolver, placement: Wx
133
129
 
134
130
  generateBundle: {
135
131
  /*
136
- * This hook is registered after createWxStylePlugins() and shares hook-level `order: 'post'` with the adapted
137
- * upstream hooks and VPT style finalizer. Registration order therefore guarantees that the imported global
138
- * stylesheet is complete before native Page/component companions are emitted. Without this order, the finalizer
139
- * could consume incomplete Tailwind output or mistake native WXSS companions for additional compiler styles.
132
+ * Registration after the style pipeline makes the compiler stylesheet final before native Page and component
133
+ * companions are emitted. The style finalizer therefore cannot mistake native WXSS for application CSS.
140
134
  */
141
135
  order: 'post',
142
136
  async handler(_, bundle) {