vite-plugin-taro 0.5.13 → 0.5.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/node/plugins/client/client-taro.d.ts +1 -1
- package/dist/node/plugins/client/client-taro.js +2 -1
- package/dist/node/plugins/h5/create-stencil-client-adapter.d.ts +1 -1
- package/dist/node/plugins/h5/create-stencil-client-adapter.js +2 -1
- package/dist/node/plugins/h5/resolver/module-resolver.js +2 -1
- package/dist/node/plugins/wx/dev/create-hmr-results-stream.d.ts +23 -0
- package/dist/node/plugins/wx/dev/create-hmr-results-stream.js +57 -0
- package/dist/node/plugins/wx/dev/create-style-capture.d.ts +42 -0
- package/dist/node/plugins/wx/dev/create-style-capture.js +125 -0
- package/dist/node/plugins/wx/dev/dev-host.d.ts +1 -1
- package/dist/node/plugins/wx/dev/dev-host.js +151 -93
- package/dist/node/plugins/wx/dev/hmr-files.d.ts +1 -0
- package/dist/node/plugins/wx/dev/hmr-files.js +1 -0
- package/dist/node/plugins/wx/dev/host-actions.d.ts +16 -0
- package/dist/node/plugins/wx/dev/host-actions.js +58 -0
- package/dist/node/plugins/wx/dev/patch-publisher.d.ts +2 -2
- package/dist/node/plugins/wx/dev/patch-publisher.js +17 -1
- package/dist/node/plugins/wx/dev/plugins.d.ts +4 -0
- package/dist/node/plugins/wx/dev/plugins.js +24 -8
- package/dist/node/plugins/wx/dev/react-refresh.js +6 -2
- package/dist/node/plugins/wx/dev/runtime-reports.d.ts +27 -0
- package/dist/node/plugins/wx/dev/runtime-reports.js +45 -0
- package/dist/node/plugins/wx/dev/wx-dev-options.d.ts +7 -3
- package/dist/node/plugins/wx/dev/wx-dev-options.js +46 -28
- package/dist/node/plugins/wx/module.d.ts +1 -1
- package/dist/node/plugins/wx/module.js +2 -1
- package/dist/node/plugins/wx/native/compile-native-component-interface.js +2 -1
- package/dist/node/plugins/wx/native/create-native-component-output.js +2 -0
- package/dist/node/plugins/wx/native/native-component-assets.d.ts +1 -1
- package/dist/node/plugins/wx/native/native-component-assets.js +3 -3
- package/dist/node/plugins/wx/native/native-component-interface.js +2 -1
- package/dist/node/plugins/wx/resolve/resolver.js +3 -2
- package/dist/node/plugins/wx/styles/plugins.js +20 -1
- package/dist/node/utils/modules.d.ts +1 -1
- package/dist/node/utils/modules.js +4 -3
- package/dist/node/utils/packages.js +2 -2
- package/package.json +4 -3
- package/src/node/plugins/client/client-taro.ts +2 -2
- package/src/node/plugins/h5/create-stencil-client-adapter.ts +2 -2
- package/src/node/plugins/h5/resolver/module-resolver.ts +2 -1
- package/src/node/plugins/wx/dev/create-hmr-results-stream.ts +71 -0
- package/src/node/plugins/wx/dev/create-style-capture.ts +179 -0
- package/src/node/plugins/wx/dev/dev-host.ts +177 -124
- package/src/node/plugins/wx/dev/hmr-files.ts +1 -0
- package/src/node/plugins/wx/dev/host-actions.ts +88 -0
- package/src/node/plugins/wx/dev/patch-publisher.ts +19 -2
- package/src/node/plugins/wx/dev/plugins.ts +25 -8
- package/src/node/plugins/wx/dev/react-refresh.ts +6 -2
- package/src/node/plugins/wx/dev/runtime-reports.ts +70 -0
- package/src/node/plugins/wx/dev/wx-dev-options.ts +50 -36
- package/src/node/plugins/wx/module.ts +2 -4
- package/src/node/plugins/wx/native/compile-native-component-interface.ts +2 -1
- package/src/node/plugins/wx/native/create-native-component-output.ts +2 -0
- package/src/node/plugins/wx/native/native-component-assets.ts +3 -4
- package/src/node/plugins/wx/native/native-component-interface.ts +2 -1
- package/src/node/plugins/wx/resolve/resolver.ts +3 -2
- package/src/node/plugins/wx/styles/plugins.ts +21 -1
- package/src/node/utils/modules.ts +4 -3
- package/src/node/utils/packages.ts +2 -2
- package/dist/node/plugins/wx/dev/create-wx-dev-mode.d.ts +0 -6
- package/dist/node/plugins/wx/dev/create-wx-dev-mode.js +0 -9
- package/dist/node/plugins/wx/dev/styles/create-style-capture-plugin.d.ts +0 -12
- package/dist/node/plugins/wx/dev/styles/create-style-capture-plugin.js +0 -21
- package/dist/node/plugins/wx/dev/styles/publish-style-hmr.d.ts +0 -27
- package/dist/node/plugins/wx/dev/styles/publish-style-hmr.js +0 -48
- package/dist/node/utils/serialized-task-queue.d.ts +0 -13
- package/dist/node/utils/serialized-task-queue.js +0 -25
- package/src/node/plugins/wx/dev/create-wx-dev-mode.ts +0 -14
- package/src/node/plugins/wx/dev/styles/create-style-capture-plugin.ts +0 -34
- package/src/node/plugins/wx/dev/styles/publish-style-hmr.ts +0 -71
- package/src/node/utils/serialized-task-queue.ts +0 -32
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { normalizePath } from 'vite';
|
|
1
2
|
import { normalizeModuleId } from '../../utils/modules.js';
|
|
2
3
|
import { resolvePackageFile } from '../../utils/packages.js';
|
|
3
4
|
import { clientTaroNativeId } from './constant.js';
|
|
@@ -17,7 +18,7 @@ import { injectTaroFrameworkApis } from './inject-taro-framework-apis.js';
|
|
|
17
18
|
/** Public facade used by transformed application API imports. */
|
|
18
19
|
export const clientTaroApiId = 'virtual:taro/api';
|
|
19
20
|
const clientTaroApiPath = resolvePackageFile('dist/runtime/client/taro/api.js');
|
|
20
|
-
const normalizedClientTaroApiPath =
|
|
21
|
+
const normalizedClientTaroApiPath = normalizePath(clientTaroApiPath);
|
|
21
22
|
const clientTaroComponentId = 'virtual:taro/components';
|
|
22
23
|
const clientTaroModules = new Map([
|
|
23
24
|
[clientTaroApiId, clientTaroApiPath],
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { normalizePath } from 'vite';
|
|
1
2
|
import { normalizeModuleId } from '../../utils/modules.js';
|
|
2
3
|
import { transformWithOxcWalker } from '../../utils/oxc-transform.js';
|
|
3
4
|
import { packageRequire } from '../../utils/packages.js';
|
|
4
5
|
const stencilClientPath = packageRequire.resolve('@stencil/core/internal/client', {
|
|
5
6
|
paths: [packageRequire.resolve('@tarojs/components/package.json')]
|
|
6
7
|
});
|
|
7
|
-
const normalizedStencilClientPath =
|
|
8
|
+
const normalizedStencilClientPath = normalizePath(stencilClientPath);
|
|
8
9
|
/**
|
|
9
10
|
* Creates the compiler-owned adaptation of Stencil's client style insertion.
|
|
10
11
|
*
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { normalizePath } from 'vite';
|
|
1
2
|
import { normalizeModuleId, resolveAppComponentPath } from '../../../utils/modules.js';
|
|
2
3
|
import { appComponentId } from '../../client/constant.js';
|
|
3
4
|
import { h5AppPath } from '../constant.js';
|
|
@@ -11,7 +12,7 @@ export function createModuleResolver(options) {
|
|
|
11
12
|
}
|
|
12
13
|
},
|
|
13
14
|
transform({ code, id, projectRoot, sourcemap = true }) {
|
|
14
|
-
if (normalizeModuleId(id) ===
|
|
15
|
+
if (normalizeModuleId(id) === normalizePath(h5AppPath)) {
|
|
15
16
|
return transformH5App({ code, id, options, projectRoot, sourcemap });
|
|
16
17
|
}
|
|
17
18
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { DevOptions } from 'rolldown/experimental';
|
|
2
|
+
import { type SchedulerLike, Subject } from 'rxjs';
|
|
3
|
+
type HmrUpdatesResult = Parameters<NonNullable<DevOptions['onHmrUpdates']>>[0];
|
|
4
|
+
type HmrUpdates = Exclude<HmrUpdatesResult, Error>;
|
|
5
|
+
/**
|
|
6
|
+
* Adapts Rolldown's non-awaited HMR callback into lossless quiet-window publications.
|
|
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.
|
|
13
|
+
*
|
|
14
|
+
* DevEngine failures are values, not Observable errors. They represent transient editor generations and carry no executable
|
|
15
|
+
* patch, so the stream reports the final error but otherwise removes them. Successful callbacks on either side remain ordered
|
|
16
|
+
* and lossless; Rolldown generated each against its unpublished client frontier, and the host delivers every retained payload.
|
|
17
|
+
* Completing the returned Subject flushes its current buffer synchronously, allowing host shutdown to await the resulting
|
|
18
|
+
* serialized task rather than silently dropping an admitted patch.
|
|
19
|
+
*
|
|
20
|
+
* Complexity is O(updates + changed files) per emitted window, with one retained reference per callback until the quiet edge.
|
|
21
|
+
*/
|
|
22
|
+
export declare function createHmrResultsStream(settleMilliseconds: number, scheduler: SchedulerLike, publish: (result: HmrUpdates) => void, reportError: (error: Error) => void): Subject<HmrUpdatesResult>;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { buffer, debounceTime, filter, Subject } from 'rxjs';
|
|
2
|
+
/**
|
|
3
|
+
* Adapts Rolldown's non-awaited HMR callback into lossless quiet-window publications.
|
|
4
|
+
*
|
|
5
|
+
* Debouncing the result stream itself would retain only the final callback and lose incremental patch factories that later
|
|
6
|
+
* patches provably do not reproduce. Instead, the debounced view is only a closing notifier for `buffer`: every callback is
|
|
7
|
+
* retained in arrival order, and one configured quiet period emits the complete window to the host's existing serialized
|
|
8
|
+
* writer. This first stream migration deliberately does not own physical state; `publish` and `reportError` remain synchronous
|
|
9
|
+
* admission callbacks so the dev host can enqueue both through its single writer.
|
|
10
|
+
*
|
|
11
|
+
* DevEngine failures are values, not Observable errors. They represent transient editor generations and carry no executable
|
|
12
|
+
* patch, so the stream reports the final error but otherwise removes them. Successful callbacks on either side remain ordered
|
|
13
|
+
* and lossless; Rolldown generated each against its unpublished client frontier, and the host delivers every retained payload.
|
|
14
|
+
* Completing the returned Subject flushes its current buffer synchronously, allowing host shutdown to await the resulting
|
|
15
|
+
* serialized task rather than silently dropping an admitted patch.
|
|
16
|
+
*
|
|
17
|
+
* Complexity is O(updates + changed files) per emitted window, with one retained reference per callback until the quiet edge.
|
|
18
|
+
*/
|
|
19
|
+
export function createHmrResultsStream(settleMilliseconds, scheduler, publish, reportError) {
|
|
20
|
+
/*
|
|
21
|
+
* This hot Subject is the sole mutable boundary between Rolldown's non-awaited callback and RxJS. Each next preserves one
|
|
22
|
+
* compiler generation by reference and in arrival order. buffer owns the temporary lossless window; debounceTime observes the
|
|
23
|
+
* same Subject only to decide when that window closes. Replacing this with a debounced scalar would discard patch factories,
|
|
24
|
+
* while letting callback Promises mutate host state directly would overlap publications. Completion flushes the final window
|
|
25
|
+
* before shutdown, after which the Subject is never reused.
|
|
26
|
+
*/
|
|
27
|
+
const results = new Subject();
|
|
28
|
+
results
|
|
29
|
+
.pipe(buffer(results.pipe(debounceTime(settleMilliseconds, scheduler))), filter((window) => window.length > 0))
|
|
30
|
+
.subscribe((window) => {
|
|
31
|
+
/*
|
|
32
|
+
* An Error is one source generation that produced no executable delta; it does not invalidate successful Rolldown
|
|
33
|
+
* callbacks already admitted on either side of it. Dropping the whole quiet window would therefore discard real
|
|
34
|
+
* patch factories, while starting a complete build would compile the same known-invalid editor contents. Keep the
|
|
35
|
+
* old runtime running, report only the latest diagnostic from a repeated parser burst, and continue below with the
|
|
36
|
+
* successful callback values exactly as if the temporary invalid save had never produced an HMR payload.
|
|
37
|
+
*/
|
|
38
|
+
const lastFailure = window.findLast((result) => result instanceof Error);
|
|
39
|
+
if (lastFailure) {
|
|
40
|
+
reportError(lastFailure);
|
|
41
|
+
}
|
|
42
|
+
const successfulWindow = window.filter((result) => !(result instanceof Error));
|
|
43
|
+
if (successfulWindow.length > 0) {
|
|
44
|
+
/*
|
|
45
|
+
* flatMap preserves callback arrival order and each callback's internal Rolldown order. Updates must not be
|
|
46
|
+
* deduplicated: later undelivered patches are deltas and do not reproduce factories from earlier sequences.
|
|
47
|
+
* changedFiles is opaque DevEngine metadata and has no identity semantics in the host, so preserving its raw
|
|
48
|
+
* concatenation is both cheaper and more faithful than maintaining a second Set-based interpretation here.
|
|
49
|
+
*/
|
|
50
|
+
publish({
|
|
51
|
+
updates: successfulWindow.flatMap((result) => result.updates),
|
|
52
|
+
changedFiles: successfulWindow.flatMap((result) => result.changedFiles)
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
return results;
|
|
57
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { GetModuleInfo, Plugin } from 'rolldown';
|
|
2
|
+
type ProcessedStyle = Readonly<{
|
|
3
|
+
css: string;
|
|
4
|
+
isTailwindRoot: boolean;
|
|
5
|
+
}>;
|
|
6
|
+
type CompleteOutputFile = Readonly<{
|
|
7
|
+
type: 'asset';
|
|
8
|
+
fileName: string;
|
|
9
|
+
source: string | Uint8Array;
|
|
10
|
+
}> | Readonly<{
|
|
11
|
+
type: 'chunk';
|
|
12
|
+
fileName: string;
|
|
13
|
+
}>;
|
|
14
|
+
export type StyleCaptureAction = Readonly<{
|
|
15
|
+
kind: 'capture-graph';
|
|
16
|
+
getModuleInfo: GetModuleInfo;
|
|
17
|
+
}> | Readonly<{
|
|
18
|
+
kind: 'capture-style';
|
|
19
|
+
id: string;
|
|
20
|
+
style: ProcessedStyle;
|
|
21
|
+
}>;
|
|
22
|
+
/**
|
|
23
|
+
* Owns capture hooks, the host's style projection, and its physical WXSS publication frontier.
|
|
24
|
+
*
|
|
25
|
+
* Rolldown remains authoritative for topology through its live graph reader. Plugin hooks emit typed actions so the host can
|
|
26
|
+
* serialize captures with every other effect; only the matching capture methods mutate this projection.
|
|
27
|
+
*/
|
|
28
|
+
export declare function createStyleCapture({ applicationEntryIds, outDir, emit, transformTailwindRoot }: {
|
|
29
|
+
applicationEntryIds: readonly string[];
|
|
30
|
+
outDir: string;
|
|
31
|
+
emit: (action: StyleCaptureAction) => void;
|
|
32
|
+
transformTailwindRoot: (rootId: string, requestId: string) => Promise<Readonly<{
|
|
33
|
+
code: string;
|
|
34
|
+
}> | null>;
|
|
35
|
+
}): Readonly<{
|
|
36
|
+
bindOutput: (output: readonly CompleteOutputFile[]) => void;
|
|
37
|
+
captureGraph: (reader: GetModuleInfo) => void;
|
|
38
|
+
captureStyle: (id: string, style: ProcessedStyle) => void;
|
|
39
|
+
plugin: Plugin;
|
|
40
|
+
publishChanged: (changedIds: readonly string[]) => Promise<void>;
|
|
41
|
+
}>;
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { isCSSRequest } from 'vite';
|
|
2
|
+
import { normalizeModuleId } from '../../../utils/modules.js';
|
|
3
|
+
import { transformWxStyle } from '../styles/transform-wx-style.js';
|
|
4
|
+
import { composeGraphStyleCss, createGraphStylePlan, createTailwindSidecarId, extractViteCss, isGlobalStyleRequest } from '../styles/utils.js';
|
|
5
|
+
import { globalWxssFileName, writeHmrFile } from './hmr-files.js';
|
|
6
|
+
/**
|
|
7
|
+
* Owns capture hooks, the host's style projection, and its physical WXSS publication frontier.
|
|
8
|
+
*
|
|
9
|
+
* Rolldown remains authoritative for topology through its live graph reader. Plugin hooks emit typed actions so the host can
|
|
10
|
+
* serialize captures with every other effect; only the matching capture methods mutate this projection.
|
|
11
|
+
*/
|
|
12
|
+
export function createStyleCapture({ applicationEntryIds, outDir, emit, transformTailwindRoot }) {
|
|
13
|
+
/*
|
|
14
|
+
* This mutable capability is rebound by buildStart for each complete generation. Rolldown keeps the captured function live
|
|
15
|
+
* across incremental graph edits, so HMR traverses authoritative current topology without maintaining a shadow graph. It is
|
|
16
|
+
* undefined only before the first buildStart; retaining an older reader across a later complete build would bind transactions
|
|
17
|
+
* to the wrong engine generation, while snapshotting module data would require O(V + E) mutation on every edit.
|
|
18
|
+
*/
|
|
19
|
+
let getModuleInfo;
|
|
20
|
+
/*
|
|
21
|
+
* This mutable Map is the CSS projection Rolldown does not retain: successful final transform hooks replace one module's
|
|
22
|
+
* processed bytes, failed transforms intentionally leave its last valid generation, and a successful multi-root Tailwind
|
|
23
|
+
* refresh commits all replacements only after every sibling resolves. Entries are not deleted when topology changes because
|
|
24
|
+
* reachability comes from the live graph plan; eager deletion would need a duplicate reverse graph and could remove CSS still
|
|
25
|
+
* shared by another App/Page root. Its size is bounded by style module identities seen during this server lifecycle.
|
|
26
|
+
*/
|
|
27
|
+
const processedStyles = new Map();
|
|
28
|
+
/*
|
|
29
|
+
* This mutable value mirrors the WXSS bytes currently durable on disk. It has one owner but two real transition sources:
|
|
30
|
+
*
|
|
31
|
+
* 1. DevEngine physically writes complete output before onOutput, so bindOutput only observes and adopts that external
|
|
32
|
+
* commit. An omitted asset means DevEngine preserved the existing file and this value must remain unchanged.
|
|
33
|
+
* 2. Incremental HMR is physically written by this host, so publishChanged advances the value only after its atomic write
|
|
34
|
+
* succeeds (or after byte equality proves no write was needed).
|
|
35
|
+
*
|
|
36
|
+
* Combining these operations behind one generic update event would still require branching between “observe an existing
|
|
37
|
+
* write” and “perform a new write”, while hiding their different durability boundaries. A genuine single path would require
|
|
38
|
+
* preventing DevEngine from writing complete WXSS and transferring that entire output responsibility to the host, adding
|
|
39
|
+
* asset interception and ordering machinery. The two explicit methods are therefore the smallest accurate state model.
|
|
40
|
+
*/
|
|
41
|
+
let publishedWxss;
|
|
42
|
+
const plugin = {
|
|
43
|
+
name: 'vpt:wx-dev-style-capture',
|
|
44
|
+
buildStart() {
|
|
45
|
+
emit({ kind: 'capture-graph', getModuleInfo: (moduleId) => this.getModuleInfo(moduleId) });
|
|
46
|
+
},
|
|
47
|
+
transform(code, id) {
|
|
48
|
+
if (!isGlobalStyleRequest(id)) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const css = extractViteCss(code, id);
|
|
52
|
+
emit({
|
|
53
|
+
kind: 'capture-style',
|
|
54
|
+
id: normalizeModuleId(id),
|
|
55
|
+
style: {
|
|
56
|
+
css: css,
|
|
57
|
+
isTailwindRoot: css.includes('weapp-tailwindcss vite-generated-css:')
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
return {
|
|
63
|
+
bindOutput(output) {
|
|
64
|
+
/*
|
|
65
|
+
* Complete output is one of the two real physical writers. Its emitted asset is therefore the authoritative frontier
|
|
66
|
+
* when present; omission means DevEngine preserved the existing file and this state must remain unchanged.
|
|
67
|
+
*/
|
|
68
|
+
const style = output.find((file) => file.type === 'asset' && file.fileName === globalWxssFileName);
|
|
69
|
+
if (style) {
|
|
70
|
+
publishedWxss = typeof style.source === 'string' ? style.source : new TextDecoder().decode(style.source);
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
captureGraph(reader) {
|
|
74
|
+
getModuleInfo = reader;
|
|
75
|
+
},
|
|
76
|
+
captureStyle(id, style) {
|
|
77
|
+
processedStyles.set(id, style);
|
|
78
|
+
},
|
|
79
|
+
plugin: plugin,
|
|
80
|
+
async publishChanged(changedIds) {
|
|
81
|
+
const styleChanged = changedIds.some(isGlobalStyleRequest);
|
|
82
|
+
const candidatesChanged = changedIds.some((id) => !isCSSRequest(id));
|
|
83
|
+
if (!styleChanged && !candidatesChanged) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (!getModuleInfo) {
|
|
87
|
+
throw new Error('WX style graph is unavailable before HMR publication');
|
|
88
|
+
}
|
|
89
|
+
// Traverse topology exactly once; root refresh and final rendering consume this immutable transaction plan.
|
|
90
|
+
const styleIds = createGraphStylePlan(applicationEntryIds, getModuleInfo, (styleId) => processedStyles.has(styleId));
|
|
91
|
+
if (candidatesChanged) {
|
|
92
|
+
await refreshTailwindStyles(styleIds, processedStyles, transformTailwindRoot);
|
|
93
|
+
}
|
|
94
|
+
const css = composeGraphStyleCss(styleIds, (styleId) => requireProcessedStyle(processedStyles, styleId).css);
|
|
95
|
+
const wxss = (await transformWxStyle(css)).css;
|
|
96
|
+
if (wxss !== publishedWxss) {
|
|
97
|
+
await writeHmrFile(outDir, globalWxssFileName, wxss);
|
|
98
|
+
}
|
|
99
|
+
// HMR is the second physical writer; advance the frontier only after its atomic write succeeds or was unnecessary.
|
|
100
|
+
publishedWxss = wxss;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/** Regenerates all reachable Tailwind roots and commits the cache only when every transform succeeds. */
|
|
105
|
+
async function refreshTailwindStyles(styleIds, processedStyles, transformRoot) {
|
|
106
|
+
const roots = styleIds.filter((styleId) => requireProcessedStyle(processedStyles, styleId).isTailwindRoot);
|
|
107
|
+
const refreshedStyles = await Promise.all(roots.map(async (rootId) => {
|
|
108
|
+
const requestId = createTailwindSidecarId(rootId);
|
|
109
|
+
const result = await transformRoot(rootId, requestId);
|
|
110
|
+
if (!result) {
|
|
111
|
+
throw new Error(`Tailwind sidecar transform produced no result: ${requestId}`);
|
|
112
|
+
}
|
|
113
|
+
return [rootId, { css: extractViteCss(result.code, requestId), isTailwindRoot: true }];
|
|
114
|
+
}));
|
|
115
|
+
refreshedStyles.forEach(([rootId, style]) => {
|
|
116
|
+
processedStyles.set(rootId, style);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
function requireProcessedStyle(processedStyles, styleId) {
|
|
120
|
+
const style = processedStyles.get(styleId);
|
|
121
|
+
if (!style) {
|
|
122
|
+
throw new Error(`WX style plan references uncaptured CSS: ${styleId}`);
|
|
123
|
+
}
|
|
124
|
+
return style;
|
|
125
|
+
}
|