weapp-tailwindcss 4.11.0-alpha.4 → 4.11.0-alpha.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.
- package/dist/{chunk-GCZ7ZE7V.js → chunk-4BHL5BDO.js} +31 -31
- package/dist/{chunk-N3RT3VZH.js → chunk-DO6MQ3YF.js} +364 -74
- package/dist/{chunk-JKK5KZCN.js → chunk-KWG7VWW5.js} +3 -3
- package/dist/{chunk-TDHY27WS.mjs → chunk-LYANBRNN.mjs} +1 -1
- package/dist/{chunk-3V52XTPJ.mjs → chunk-OMARW5NC.mjs} +50 -0
- package/dist/{chunk-FI75TLOQ.js → chunk-QK6VNNNL.js} +51 -1
- package/dist/{chunk-NYZTRTBM.mjs → chunk-RQLIVYJZ.mjs} +331 -41
- package/dist/{chunk-ZPGT5C7G.mjs → chunk-TSRWDW6S.mjs} +1 -1
- package/dist/{chunk-JOT24YET.mjs → chunk-VMKFA54Q.mjs} +10 -4
- package/dist/{chunk-VHUV7ZDB.js → chunk-VO5STL3U.js} +6 -6
- package/dist/{chunk-VO2ZPNCW.js → chunk-WPH7LL5V.js} +23 -17
- package/dist/{chunk-6R2OVCLW.mjs → chunk-ZMQZ667Q.mjs} +3 -3
- package/dist/cli.js +2 -1
- package/dist/cli.mjs +2 -1
- package/dist/core.d.mts +1 -1
- package/dist/core.d.ts +1 -1
- package/dist/core.js +7 -7
- package/dist/core.mjs +2 -2
- package/dist/defaults.d.mts +1 -1
- package/dist/defaults.d.ts +1 -1
- package/dist/gulp.d.mts +1 -1
- package/dist/gulp.d.ts +1 -1
- package/dist/gulp.js +4 -4
- package/dist/gulp.mjs +3 -3
- package/dist/{index-BMwzhITq.d.mts → index-D8E0GGqB.d.mts} +28 -2
- package/dist/{index-BMwzhITq.d.ts → index-D8E0GGqB.d.ts} +28 -2
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +7 -7
- package/dist/index.mjs +6 -6
- package/dist/presets.d.mts +36 -1
- package/dist/presets.d.ts +36 -1
- package/dist/presets.js +14 -5
- package/dist/presets.mjs +12 -3
- package/dist/types.d.mts +2 -2
- package/dist/types.d.ts +2 -2
- package/dist/vite.d.mts +1 -1
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +4 -4
- package/dist/vite.mjs +3 -3
- package/dist/webpack.d.mts +1 -1
- package/dist/webpack.d.ts +1 -1
- package/dist/webpack.js +5 -5
- package/dist/webpack.mjs +4 -4
- package/dist/webpack4.d.mts +1 -1
- package/dist/webpack4.d.ts +1 -1
- package/dist/webpack4.js +26 -26
- package/dist/webpack4.mjs +3 -3
- package/package.json +2 -1
|
@@ -11,39 +11,223 @@ import {
|
|
|
11
11
|
processCachedTask
|
|
12
12
|
} from "./chunk-76S2EME4.mjs";
|
|
13
13
|
import {
|
|
14
|
+
JsTokenUpdater,
|
|
15
|
+
analyzeSource,
|
|
14
16
|
babelParse,
|
|
15
17
|
collectRuntimeClassSet,
|
|
16
18
|
createAttributeMatcher,
|
|
17
19
|
createDebug,
|
|
18
20
|
generateCode,
|
|
19
21
|
getCompilerContext,
|
|
22
|
+
isClassContextLiteralPath,
|
|
20
23
|
refreshTailwindRuntimeState,
|
|
21
24
|
replaceWxml,
|
|
22
25
|
setupPatchRecorder,
|
|
23
26
|
toCustomAttributesEntities,
|
|
24
27
|
traverse,
|
|
25
28
|
vitePluginName
|
|
26
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-VMKFA54Q.mjs";
|
|
27
30
|
import {
|
|
28
31
|
findNearestPackageRoot,
|
|
29
32
|
findTailwindConfig,
|
|
30
33
|
getRuntimeClassSetSignature,
|
|
31
|
-
|
|
32
|
-
|
|
34
|
+
isUniAppXEnabled,
|
|
35
|
+
resolveTailwindcssOptions,
|
|
36
|
+
resolveUniAppXOptions
|
|
37
|
+
} from "./chunk-OMARW5NC.mjs";
|
|
33
38
|
import {
|
|
34
39
|
resolveUniUtsPlatform
|
|
35
40
|
} from "./chunk-OOHJLO5M.mjs";
|
|
36
41
|
|
|
37
42
|
// src/bundlers/vite/index.ts
|
|
38
43
|
import { existsSync } from "fs";
|
|
39
|
-
import
|
|
44
|
+
import path5 from "path";
|
|
40
45
|
import process4 from "process";
|
|
41
46
|
import postcssHtmlTransform from "@weapp-tailwindcss/postcss/html-transform";
|
|
42
47
|
|
|
43
48
|
// src/uni-app-x/transform.ts
|
|
44
49
|
import { NodeTypes } from "@vue/compiler-dom";
|
|
45
50
|
import { parse } from "@vue/compiler-sfc";
|
|
51
|
+
import MagicString2 from "magic-string";
|
|
52
|
+
|
|
53
|
+
// src/uni-app-x/component-local-style.ts
|
|
54
|
+
import { splitCode } from "@weapp-tailwindcss/shared/extractors";
|
|
46
55
|
import MagicString from "magic-string";
|
|
56
|
+
var EXPRESSION_WRAPPER_PREFIX = "(\n";
|
|
57
|
+
var EXPRESSION_WRAPPER_SUFFIX = "\n)";
|
|
58
|
+
var COMPONENT_RE = /(?:^|[/\\])components(?:[/\\].+)?\.(?:uvue|nvue)$/;
|
|
59
|
+
function createStableHash(input) {
|
|
60
|
+
let hash = 2166136261;
|
|
61
|
+
for (let i = 0; i < input.length; i++) {
|
|
62
|
+
hash ^= input.charCodeAt(i);
|
|
63
|
+
hash = Math.imul(hash, 16777619);
|
|
64
|
+
}
|
|
65
|
+
return (hash >>> 0).toString(36);
|
|
66
|
+
}
|
|
67
|
+
function extractLiteralValue(path6) {
|
|
68
|
+
const allowDoubleQuotes = path6.isTemplateElement();
|
|
69
|
+
if (path6.isStringLiteral()) {
|
|
70
|
+
return {
|
|
71
|
+
allowDoubleQuotes,
|
|
72
|
+
literal: path6.node.value,
|
|
73
|
+
offset: 1
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
allowDoubleQuotes,
|
|
78
|
+
literal: path6.node.value.raw,
|
|
79
|
+
offset: 0
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function createAlias(fileId, utility, index) {
|
|
83
|
+
return `wtu-${createStableHash(`${fileId}:${utility}`)}-${index.toString(36)}`;
|
|
84
|
+
}
|
|
85
|
+
function isRuntimeCandidate(candidate, runtimeSet) {
|
|
86
|
+
if (!runtimeSet || runtimeSet.size === 0) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
return runtimeSet.has(candidate) || runtimeSet.has(replaceWxml(candidate));
|
|
90
|
+
}
|
|
91
|
+
function shouldEnableComponentLocalStyle(id) {
|
|
92
|
+
return COMPONENT_RE.test(id);
|
|
93
|
+
}
|
|
94
|
+
var UniAppXComponentLocalStyleCollector = class {
|
|
95
|
+
constructor(fileId, runtimeSet) {
|
|
96
|
+
this.fileId = fileId;
|
|
97
|
+
this.runtimeSet = runtimeSet;
|
|
98
|
+
this.aliasByUtility = /* @__PURE__ */ new Map();
|
|
99
|
+
this.aliasByLookup = /* @__PURE__ */ new Map();
|
|
100
|
+
}
|
|
101
|
+
ensureAlias(utility) {
|
|
102
|
+
const cached = this.aliasByUtility.get(utility);
|
|
103
|
+
if (cached) {
|
|
104
|
+
return cached;
|
|
105
|
+
}
|
|
106
|
+
const alias = createAlias(this.fileId, utility, this.aliasByUtility.size);
|
|
107
|
+
this.aliasByUtility.set(utility, alias);
|
|
108
|
+
this.aliasByLookup.set(utility, alias);
|
|
109
|
+
this.aliasByLookup.set(replaceWxml(utility), alias);
|
|
110
|
+
return alias;
|
|
111
|
+
}
|
|
112
|
+
rewriteLiteral(literal, shouldInclude) {
|
|
113
|
+
const candidates = splitCode(literal);
|
|
114
|
+
if (candidates.length === 0) {
|
|
115
|
+
return literal;
|
|
116
|
+
}
|
|
117
|
+
let rewritten = literal;
|
|
118
|
+
for (const candidate of candidates) {
|
|
119
|
+
if (!shouldInclude(candidate)) {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
rewritten = rewritten.replace(candidate, this.ensureAlias(candidate));
|
|
123
|
+
}
|
|
124
|
+
return rewritten;
|
|
125
|
+
}
|
|
126
|
+
collectAndRewriteStaticClass(literal) {
|
|
127
|
+
return this.rewriteLiteral(literal, (candidate) => isRuntimeCandidate(candidate, this.runtimeSet));
|
|
128
|
+
}
|
|
129
|
+
collectRuntimeClasses(rawSource, options = {}) {
|
|
130
|
+
const wrapped = options.wrapExpression ? `${EXPRESSION_WRAPPER_PREFIX}${rawSource}${EXPRESSION_WRAPPER_SUFFIX}` : rawSource;
|
|
131
|
+
try {
|
|
132
|
+
const ast = babelParse(wrapped, {
|
|
133
|
+
plugins: ["typescript"],
|
|
134
|
+
sourceType: options.wrapExpression ? "module" : "unambiguous"
|
|
135
|
+
});
|
|
136
|
+
const analysis = analyzeSource(ast, {}, void 0, false);
|
|
137
|
+
for (const path6 of analysis.targetPaths) {
|
|
138
|
+
const { literal, allowDoubleQuotes } = extractLiteralValue(path6);
|
|
139
|
+
const candidates = splitCode(literal, allowDoubleQuotes);
|
|
140
|
+
const classContext = options.wrapExpression || isClassContextLiteralPath(path6);
|
|
141
|
+
for (const candidate of candidates) {
|
|
142
|
+
if (!candidate || !classContext && !isRuntimeCandidate(candidate, this.runtimeSet)) {
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (isRuntimeCandidate(candidate, this.runtimeSet)) {
|
|
146
|
+
this.ensureAlias(candidate);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
} catch {
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
rewriteTransformedCode(rawSource, options = {}) {
|
|
154
|
+
if (this.aliasByLookup.size === 0) {
|
|
155
|
+
return rawSource;
|
|
156
|
+
}
|
|
157
|
+
const wrapped = options.wrapExpression ? `${EXPRESSION_WRAPPER_PREFIX}${rawSource}${EXPRESSION_WRAPPER_SUFFIX}` : rawSource;
|
|
158
|
+
try {
|
|
159
|
+
const ast = babelParse(wrapped, {
|
|
160
|
+
plugins: ["typescript"],
|
|
161
|
+
sourceType: options.wrapExpression ? "module" : "unambiguous"
|
|
162
|
+
});
|
|
163
|
+
const analysis = analyzeSource(ast, {}, void 0, false);
|
|
164
|
+
if (analysis.targetPaths.length === 0) {
|
|
165
|
+
return rawSource;
|
|
166
|
+
}
|
|
167
|
+
const updater = new JsTokenUpdater();
|
|
168
|
+
for (const path6 of analysis.targetPaths) {
|
|
169
|
+
const { literal, allowDoubleQuotes, offset } = extractLiteralValue(path6);
|
|
170
|
+
const candidates = splitCode(literal, allowDoubleQuotes);
|
|
171
|
+
if (candidates.length === 0) {
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
let rewritten = literal;
|
|
175
|
+
let mutated = false;
|
|
176
|
+
for (const candidate of candidates) {
|
|
177
|
+
const alias = this.aliasByLookup.get(candidate);
|
|
178
|
+
if (!alias) {
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
const replaced = rewritten.replace(candidate, alias);
|
|
182
|
+
if (replaced !== rewritten) {
|
|
183
|
+
rewritten = replaced;
|
|
184
|
+
mutated = true;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (!mutated || typeof path6.node.start !== "number" || typeof path6.node.end !== "number") {
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
updater.addToken({
|
|
191
|
+
start: path6.node.start + offset,
|
|
192
|
+
end: path6.node.end - offset,
|
|
193
|
+
value: rewritten,
|
|
194
|
+
path: path6
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
if (updater.length === 0) {
|
|
198
|
+
return rawSource;
|
|
199
|
+
}
|
|
200
|
+
const ms = new MagicString(wrapped);
|
|
201
|
+
updater.updateMagicString(ms);
|
|
202
|
+
if (options.wrapExpression) {
|
|
203
|
+
ms.remove(0, EXPRESSION_WRAPPER_PREFIX.length);
|
|
204
|
+
ms.remove(wrapped.length - EXPRESSION_WRAPPER_SUFFIX.length, wrapped.length);
|
|
205
|
+
}
|
|
206
|
+
return ms.toString();
|
|
207
|
+
} catch {
|
|
208
|
+
return rawSource;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
hasStyles() {
|
|
212
|
+
return this.aliasByUtility.size > 0;
|
|
213
|
+
}
|
|
214
|
+
toStyleBlock() {
|
|
215
|
+
if (!this.hasStyles()) {
|
|
216
|
+
return "";
|
|
217
|
+
}
|
|
218
|
+
const lines = ["<style scoped>"];
|
|
219
|
+
for (const [utility, alias] of this.aliasByUtility) {
|
|
220
|
+
lines.push(`.${alias} {`);
|
|
221
|
+
lines.push(` @apply ${utility};`);
|
|
222
|
+
lines.push("}");
|
|
223
|
+
}
|
|
224
|
+
lines.push("</style>");
|
|
225
|
+
return `${lines.join("\n")}
|
|
226
|
+
`;
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
// src/uni-app-x/transform.ts
|
|
47
231
|
function traverse2(node, visitor) {
|
|
48
232
|
visitor(node);
|
|
49
233
|
if (Array.isArray(node.children)) {
|
|
@@ -64,6 +248,16 @@ function updateStaticAttribute(ms, prop) {
|
|
|
64
248
|
ms.update(start, end, replaceWxml(prop.value.content));
|
|
65
249
|
}
|
|
66
250
|
}
|
|
251
|
+
function updateStaticAttributeWithLocalStyle(ms, prop, collector) {
|
|
252
|
+
if (!prop.value) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
const start = prop.value.loc.start.offset + 1;
|
|
256
|
+
const end = prop.value.loc.end.offset - 1;
|
|
257
|
+
if (start < end) {
|
|
258
|
+
ms.update(start, end, collector.collectAndRewriteStaticClass(prop.value.content));
|
|
259
|
+
}
|
|
260
|
+
}
|
|
67
261
|
function updateDirectiveExpression(ms, prop, jsHandler, runtimeSet) {
|
|
68
262
|
if (prop.exp?.type !== NodeTypes.SIMPLE_EXPRESSION) {
|
|
69
263
|
return;
|
|
@@ -80,6 +274,25 @@ function updateDirectiveExpression(ms, prop, jsHandler, runtimeSet) {
|
|
|
80
274
|
});
|
|
81
275
|
ms.update(start, end, generated);
|
|
82
276
|
}
|
|
277
|
+
function updateDirectiveExpressionWithLocalStyle(ms, prop, jsHandler, collector, runtimeSet) {
|
|
278
|
+
if (prop.exp?.type !== NodeTypes.SIMPLE_EXPRESSION) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
const start = prop.exp.loc.start.offset;
|
|
282
|
+
const end = prop.exp.loc.end.offset;
|
|
283
|
+
if (start >= end) {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
collector.collectRuntimeClasses(prop.exp.content, {
|
|
287
|
+
wrapExpression: true
|
|
288
|
+
});
|
|
289
|
+
const generated = generateCode(prop.exp.content, {
|
|
290
|
+
jsHandler,
|
|
291
|
+
runtimeSet,
|
|
292
|
+
wrapExpression: true
|
|
293
|
+
});
|
|
294
|
+
ms.update(start, end, collector.rewriteTransformedCode(generated, { wrapExpression: true }));
|
|
295
|
+
}
|
|
83
296
|
function shouldHandleAttribute(tag, attrName, disabledDefaultTemplateHandler, matchCustomAttribute) {
|
|
84
297
|
const lowerName = attrName.toLowerCase();
|
|
85
298
|
const shouldHandleDefault = !disabledDefaultTemplateHandler && lowerName === "class";
|
|
@@ -104,8 +317,9 @@ function transformUVue(code, id, jsHandler, runtimeSet, options = {}) {
|
|
|
104
317
|
}
|
|
105
318
|
const { customAttributesEntities, disabledDefaultTemplateHandler = false } = options;
|
|
106
319
|
const matchCustomAttribute = createAttributeMatcher(customAttributesEntities);
|
|
107
|
-
const ms = new
|
|
320
|
+
const ms = new MagicString2(code);
|
|
108
321
|
const { descriptor, errors } = parse(code);
|
|
322
|
+
const localStyleCollector = options.enableComponentLocalStyle && shouldEnableComponentLocalStyle(id) ? new UniAppXComponentLocalStyleCollector(id, runtimeSet) : void 0;
|
|
109
323
|
if (errors.length === 0) {
|
|
110
324
|
if (descriptor.template?.ast) {
|
|
111
325
|
traverse2(descriptor.template.ast, (node) => {
|
|
@@ -124,7 +338,11 @@ function transformUVue(code, id, jsHandler, runtimeSet, options = {}) {
|
|
|
124
338
|
if (!shouldHandle) {
|
|
125
339
|
continue;
|
|
126
340
|
}
|
|
127
|
-
|
|
341
|
+
if (shouldHandleDefault && localStyleCollector) {
|
|
342
|
+
updateStaticAttributeWithLocalStyle(ms, prop, localStyleCollector);
|
|
343
|
+
} else {
|
|
344
|
+
updateStaticAttribute(ms, prop);
|
|
345
|
+
}
|
|
128
346
|
if (shouldHandleDefault) {
|
|
129
347
|
continue;
|
|
130
348
|
}
|
|
@@ -139,18 +357,36 @@ function transformUVue(code, id, jsHandler, runtimeSet, options = {}) {
|
|
|
139
357
|
if (!shouldHandle) {
|
|
140
358
|
continue;
|
|
141
359
|
}
|
|
142
|
-
|
|
360
|
+
if (attrName.toLowerCase() === "class" && localStyleCollector) {
|
|
361
|
+
updateDirectiveExpressionWithLocalStyle(ms, prop, jsHandler, localStyleCollector, runtimeSet);
|
|
362
|
+
} else {
|
|
363
|
+
updateDirectiveExpression(ms, prop, jsHandler, runtimeSet);
|
|
364
|
+
}
|
|
143
365
|
}
|
|
144
366
|
}
|
|
145
367
|
});
|
|
146
368
|
}
|
|
147
369
|
if (descriptor.script) {
|
|
370
|
+
localStyleCollector?.collectRuntimeClasses(descriptor.script.content);
|
|
148
371
|
const { code: code2 } = jsHandler(descriptor.script.content, runtimeSet ?? /* @__PURE__ */ new Set(), defaultCreateJsHandlerOptions);
|
|
149
|
-
ms.update(
|
|
372
|
+
ms.update(
|
|
373
|
+
descriptor.script.loc.start.offset,
|
|
374
|
+
descriptor.script.loc.end.offset,
|
|
375
|
+
localStyleCollector ? localStyleCollector.rewriteTransformedCode(code2) : code2
|
|
376
|
+
);
|
|
150
377
|
}
|
|
151
378
|
if (descriptor.scriptSetup) {
|
|
379
|
+
localStyleCollector?.collectRuntimeClasses(descriptor.scriptSetup.content);
|
|
152
380
|
const { code: code2 } = jsHandler(descriptor.scriptSetup.content, runtimeSet ?? /* @__PURE__ */ new Set(), defaultCreateJsHandlerOptions);
|
|
153
|
-
ms.update(
|
|
381
|
+
ms.update(
|
|
382
|
+
descriptor.scriptSetup.loc.start.offset,
|
|
383
|
+
descriptor.scriptSetup.loc.end.offset,
|
|
384
|
+
localStyleCollector ? localStyleCollector.rewriteTransformedCode(code2) : code2
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
if (localStyleCollector?.hasStyles()) {
|
|
388
|
+
ms.append(`
|
|
389
|
+
${localStyleCollector.toStyleBlock()}`);
|
|
154
390
|
}
|
|
155
391
|
}
|
|
156
392
|
return {
|
|
@@ -228,6 +464,33 @@ async function formatPostcssSourceMap(rawMap, file) {
|
|
|
228
464
|
};
|
|
229
465
|
}
|
|
230
466
|
|
|
467
|
+
// src/uni-app-x/style-isolation.ts
|
|
468
|
+
import fs from "fs";
|
|
469
|
+
import path2 from "path";
|
|
470
|
+
import { parse as parse2 } from "comment-json";
|
|
471
|
+
var manifestCache = /* @__PURE__ */ new Map();
|
|
472
|
+
function resolveUniAppXStyleIsolationEnabled(root) {
|
|
473
|
+
if (!root) {
|
|
474
|
+
return false;
|
|
475
|
+
}
|
|
476
|
+
const normalizedRoot = path2.resolve(root);
|
|
477
|
+
const cached = manifestCache.get(normalizedRoot);
|
|
478
|
+
if (cached !== void 0) {
|
|
479
|
+
return cached;
|
|
480
|
+
}
|
|
481
|
+
const manifestPath = path2.join(normalizedRoot, "manifest.json");
|
|
482
|
+
let enabled = false;
|
|
483
|
+
try {
|
|
484
|
+
const raw = fs.readFileSync(manifestPath, "utf8");
|
|
485
|
+
const manifest = parse2(raw);
|
|
486
|
+
enabled = `${manifest["uni-app-x"]?.styleIsolationVersion ?? ""}` === "2";
|
|
487
|
+
} catch {
|
|
488
|
+
enabled = false;
|
|
489
|
+
}
|
|
490
|
+
manifestCache.set(normalizedRoot, enabled);
|
|
491
|
+
return enabled;
|
|
492
|
+
}
|
|
493
|
+
|
|
231
494
|
// src/uni-app-x/vite.ts
|
|
232
495
|
var preprocessorLangs = /* @__PURE__ */ new Set(["scss", "sass", "less", "styl", "stylus"]);
|
|
233
496
|
var INLINE_LANG_RE = /lang\.([a-z]+)/i;
|
|
@@ -256,10 +519,29 @@ function createUniAppXPlugins(options) {
|
|
|
256
519
|
styleHandler,
|
|
257
520
|
jsHandler,
|
|
258
521
|
ensureRuntimeClassSet,
|
|
259
|
-
getResolvedConfig
|
|
522
|
+
getResolvedConfig,
|
|
523
|
+
uniAppX
|
|
260
524
|
} = options;
|
|
525
|
+
const resolvedUniAppXOptions = resolveUniAppXOptions(uniAppX);
|
|
261
526
|
const isIosPlatform = providedIosPlatform ?? resolveUniUtsPlatform().isAppIos;
|
|
262
527
|
const cssHandlerOptionsCache = /* @__PURE__ */ new Map();
|
|
528
|
+
let componentLocalStyleEnabled;
|
|
529
|
+
function shouldEnableComponentLocalStyle2() {
|
|
530
|
+
if (!resolvedUniAppXOptions.componentLocalStyles.enabled) {
|
|
531
|
+
componentLocalStyleEnabled = false;
|
|
532
|
+
return false;
|
|
533
|
+
}
|
|
534
|
+
if (!resolvedUniAppXOptions.componentLocalStyles.onlyWhenStyleIsolationVersion2) {
|
|
535
|
+
componentLocalStyleEnabled = true;
|
|
536
|
+
return true;
|
|
537
|
+
}
|
|
538
|
+
if (componentLocalStyleEnabled !== void 0) {
|
|
539
|
+
return componentLocalStyleEnabled;
|
|
540
|
+
}
|
|
541
|
+
const root = getResolvedConfig()?.root;
|
|
542
|
+
componentLocalStyleEnabled = resolveUniAppXStyleIsolationEnabled(root);
|
|
543
|
+
return componentLocalStyleEnabled;
|
|
544
|
+
}
|
|
263
545
|
async function transformStyle(code, id, query) {
|
|
264
546
|
const parsed = query ?? parseVueRequest(id).query;
|
|
265
547
|
if (isCSSRequest(id) || parsed.vue && parsed.type === "style") {
|
|
@@ -334,11 +616,17 @@ function createUniAppXPlugins(options) {
|
|
|
334
616
|
const currentRuntimeSet = shouldForceRefresh ? await ensureRuntimeClassSet(true) : await ensureRuntimeClassSet();
|
|
335
617
|
const extraOptions = customAttributesEntities.length > 0 || disabledDefaultTemplateHandler ? {
|
|
336
618
|
customAttributesEntities,
|
|
337
|
-
disabledDefaultTemplateHandler
|
|
619
|
+
disabledDefaultTemplateHandler,
|
|
620
|
+
enableComponentLocalStyle: shouldEnableComponentLocalStyle2()
|
|
338
621
|
} : void 0;
|
|
339
622
|
if (extraOptions) {
|
|
340
623
|
return transformUVue(code, id, jsHandler, currentRuntimeSet, extraOptions);
|
|
341
624
|
}
|
|
625
|
+
if (shouldEnableComponentLocalStyle2()) {
|
|
626
|
+
return transformUVue(code, id, jsHandler, currentRuntimeSet, {
|
|
627
|
+
enableComponentLocalStyle: true
|
|
628
|
+
});
|
|
629
|
+
}
|
|
342
630
|
return transformUVue(code, id, jsHandler, currentRuntimeSet);
|
|
343
631
|
},
|
|
344
632
|
async handleHotUpdate(ctx) {
|
|
@@ -417,10 +705,10 @@ function createUniAppXAssetTask(file, originalSource, outDir, options) {
|
|
|
417
705
|
}
|
|
418
706
|
|
|
419
707
|
// src/bundlers/vite/generate-bundle.ts
|
|
420
|
-
import
|
|
708
|
+
import path3 from "path";
|
|
421
709
|
import process2 from "process";
|
|
422
710
|
import { logger } from "@weapp-tailwindcss/logger";
|
|
423
|
-
import { splitCode } from "@weapp-tailwindcss/shared/extractors";
|
|
711
|
+
import { splitCode as splitCode2 } from "@weapp-tailwindcss/shared/extractors";
|
|
424
712
|
|
|
425
713
|
// src/bundlers/vite/bundle-entries.ts
|
|
426
714
|
import { Buffer } from "buffer";
|
|
@@ -536,14 +824,14 @@ function createJsRuntimeAffectingSignature(source) {
|
|
|
536
824
|
const parts = [];
|
|
537
825
|
traverse(ast, {
|
|
538
826
|
noScope: true,
|
|
539
|
-
StringLiteral(
|
|
540
|
-
parts.push(`s:${
|
|
827
|
+
StringLiteral(path6) {
|
|
828
|
+
parts.push(`s:${path6.node.value}`);
|
|
541
829
|
},
|
|
542
|
-
TemplateElement(
|
|
543
|
-
parts.push(`t:${
|
|
830
|
+
TemplateElement(path6) {
|
|
831
|
+
parts.push(`t:${path6.node.value.raw}`);
|
|
544
832
|
},
|
|
545
|
-
JSXText(
|
|
546
|
-
const value =
|
|
833
|
+
JSXText(path6) {
|
|
834
|
+
const value = path6.node.value.trim();
|
|
547
835
|
if (value.length > 0) {
|
|
548
836
|
parts.push(`x:${value}`);
|
|
549
837
|
}
|
|
@@ -866,7 +1154,7 @@ function collectUnescapedDynamicCandidates(source) {
|
|
|
866
1154
|
let quoted = QUOTED_LITERAL_RE.exec(expression);
|
|
867
1155
|
while (quoted !== null) {
|
|
868
1156
|
const literal = quoted[1] ?? quoted[2] ?? quoted[3] ?? "";
|
|
869
|
-
for (const candidate of
|
|
1157
|
+
for (const candidate of splitCode2(literal, true)) {
|
|
870
1158
|
const normalized = candidate.trim();
|
|
871
1159
|
if (!normalized || !isArbitraryValueCandidate(normalized)) {
|
|
872
1160
|
continue;
|
|
@@ -933,8 +1221,8 @@ function createGenerateBundleHook(context) {
|
|
|
933
1221
|
const bundleFiles = Object.keys(bundle);
|
|
934
1222
|
const buildCommand = resolvedConfig?.command === "build";
|
|
935
1223
|
const useIncrementalMode = !buildCommand || hasOmittedKnownBundleFiles(bundleFiles, state.sourceHashByFile.keys());
|
|
936
|
-
const rootDir = resolvedConfig?.root ?
|
|
937
|
-
const outDir = resolvedConfig?.build?.outDir ?
|
|
1224
|
+
const rootDir = resolvedConfig?.root ? path3.resolve(resolvedConfig.root) : process2.cwd();
|
|
1225
|
+
const outDir = resolvedConfig?.build?.outDir ? path3.resolve(rootDir, resolvedConfig.build.outDir) : rootDir;
|
|
938
1226
|
const snapshot = buildBundleSnapshot(bundle, opts, outDir, state, disableDirtyOptimization || !useIncrementalMode);
|
|
939
1227
|
const useBundleRuntimeClassSet = useIncrementalMode || runtimeState.twPatcher.majorVersion === 4;
|
|
940
1228
|
const forceRuntimeRefreshBySource = useIncrementalMode && hasRuntimeAffectingSourceChanges(snapshot.runtimeAffectingChangedByType);
|
|
@@ -1144,7 +1432,7 @@ function createGenerateBundleHook(context) {
|
|
|
1144
1432
|
debug3("js skip transform (clean), replay cache: %s", file);
|
|
1145
1433
|
}
|
|
1146
1434
|
if (originalSource.type === "chunk") {
|
|
1147
|
-
const absoluteFile =
|
|
1435
|
+
const absoluteFile = path3.resolve(outDir, file);
|
|
1148
1436
|
const initialRawSource = originalEntrySource;
|
|
1149
1437
|
const linkedSet = useIncrementalMode ? /* @__PURE__ */ new Set() : void 0;
|
|
1150
1438
|
if (linkedByEntry && linkedSet) {
|
|
@@ -1255,7 +1543,7 @@ function createGenerateBundleHook(context) {
|
|
|
1255
1543
|
return;
|
|
1256
1544
|
}
|
|
1257
1545
|
const currentSource = originalEntrySource;
|
|
1258
|
-
const absoluteFile =
|
|
1546
|
+
const absoluteFile = path3.resolve(outDir, file);
|
|
1259
1547
|
const precheckOptions = createHandlerOptions(absoluteFile, {
|
|
1260
1548
|
uniAppX: uniAppX ?? true,
|
|
1261
1549
|
babelParserOptions: {
|
|
@@ -1313,7 +1601,7 @@ function createGenerateBundleHook(context) {
|
|
|
1313
1601
|
// src/bundlers/vite/incremental-runtime-class-set.ts
|
|
1314
1602
|
import { mkdir, readFile, rm, writeFile } from "fs/promises";
|
|
1315
1603
|
import { createRequire } from "module";
|
|
1316
|
-
import
|
|
1604
|
+
import path4 from "path";
|
|
1317
1605
|
import process3 from "process";
|
|
1318
1606
|
import { extractRawCandidatesWithPositions, extractValidCandidates } from "tailwindcss-patch";
|
|
1319
1607
|
var debug = createDebug("[vite:runtime-set] ");
|
|
@@ -1361,7 +1649,7 @@ async function importTailwindNodeModule() {
|
|
|
1361
1649
|
} catch {
|
|
1362
1650
|
const tailwindcssPatchEntry = require2.resolve("tailwindcss-patch");
|
|
1363
1651
|
const resolved = require2.resolve("@tailwindcss/node", {
|
|
1364
|
-
paths: [
|
|
1652
|
+
paths: [path4.dirname(tailwindcssPatchEntry)]
|
|
1365
1653
|
});
|
|
1366
1654
|
return await import(resolved);
|
|
1367
1655
|
}
|
|
@@ -1373,13 +1661,13 @@ function resolveMaybeAbsolute(base, value) {
|
|
|
1373
1661
|
if (!value) {
|
|
1374
1662
|
return void 0;
|
|
1375
1663
|
}
|
|
1376
|
-
return
|
|
1664
|
+
return path4.isAbsolute(value) ? value : path4.resolve(base, value);
|
|
1377
1665
|
}
|
|
1378
1666
|
async function resolveTailwindCssSource(patcher) {
|
|
1379
1667
|
const projectRoot = getProjectRoot(patcher);
|
|
1380
1668
|
const tailwindOptions = resolveTailwindcssOptions(patcher.options);
|
|
1381
1669
|
const configuredBase = resolveMaybeAbsolute(projectRoot, tailwindOptions?.v4?.base);
|
|
1382
|
-
const configDir = tailwindOptions?.config ?
|
|
1670
|
+
const configDir = tailwindOptions?.config ? path4.dirname(tailwindOptions.config) : void 0;
|
|
1383
1671
|
const sharedFallbacks = [
|
|
1384
1672
|
configuredBase,
|
|
1385
1673
|
projectRoot,
|
|
@@ -1402,7 +1690,7 @@ async function resolveTailwindCssSource(patcher) {
|
|
|
1402
1690
|
for (const entry of resolvedEntries) {
|
|
1403
1691
|
try {
|
|
1404
1692
|
cssChunks.push(await readFile(entry, "utf8"));
|
|
1405
|
-
entryDirs.push(
|
|
1693
|
+
entryDirs.push(path4.dirname(entry));
|
|
1406
1694
|
} catch {
|
|
1407
1695
|
}
|
|
1408
1696
|
}
|
|
@@ -1450,13 +1738,13 @@ function collectChangedRuntimeFiles(snapshot) {
|
|
|
1450
1738
|
]);
|
|
1451
1739
|
}
|
|
1452
1740
|
async function writeTempEntryFile(tempRoot, file, source) {
|
|
1453
|
-
const absoluteFile =
|
|
1454
|
-
await mkdir(
|
|
1741
|
+
const absoluteFile = path4.join(tempRoot, file);
|
|
1742
|
+
await mkdir(path4.dirname(absoluteFile), { recursive: true });
|
|
1455
1743
|
await writeFile(absoluteFile, source, "utf8");
|
|
1456
1744
|
return file;
|
|
1457
1745
|
}
|
|
1458
1746
|
function resolveEntryExtension(entry) {
|
|
1459
|
-
const ext =
|
|
1747
|
+
const ext = path4.extname(entry.file).replace(EXTENSION_DOT_PREFIX_RE, "");
|
|
1460
1748
|
if (ext.length > 0) {
|
|
1461
1749
|
return ext;
|
|
1462
1750
|
}
|
|
@@ -1594,7 +1882,7 @@ function createBundleRuntimeClassSetManager(options = {}) {
|
|
|
1594
1882
|
}
|
|
1595
1883
|
runtimeSignature = nextSignature;
|
|
1596
1884
|
const projectRoot = getProjectRoot(patcher);
|
|
1597
|
-
resolvedTempRoot = options.tempRoot ??
|
|
1885
|
+
resolvedTempRoot = options.tempRoot ?? path4.join(
|
|
1598
1886
|
projectRoot,
|
|
1599
1887
|
"node_modules",
|
|
1600
1888
|
".cache",
|
|
@@ -1734,7 +2022,7 @@ var weappTailwindcssPackageDir = resolvePackageDir("weapp-tailwindcss");
|
|
|
1734
2022
|
var weappTailwindcssDirPosix = slash(weappTailwindcssPackageDir);
|
|
1735
2023
|
var PACKAGE_JSON_FILE = "package.json";
|
|
1736
2024
|
function resolveImplicitTailwindcssBasedirFromViteRoot(root) {
|
|
1737
|
-
const resolvedRoot =
|
|
2025
|
+
const resolvedRoot = path5.resolve(root);
|
|
1738
2026
|
if (!existsSync(resolvedRoot)) {
|
|
1739
2027
|
return resolvedRoot;
|
|
1740
2028
|
}
|
|
@@ -1742,7 +2030,7 @@ function resolveImplicitTailwindcssBasedirFromViteRoot(root) {
|
|
|
1742
2030
|
let current = resolvedRoot;
|
|
1743
2031
|
while (true) {
|
|
1744
2032
|
searchRoots.push(current);
|
|
1745
|
-
const parent =
|
|
2033
|
+
const parent = path5.dirname(current);
|
|
1746
2034
|
if (parent === current) {
|
|
1747
2035
|
break;
|
|
1748
2036
|
}
|
|
@@ -1750,10 +2038,10 @@ function resolveImplicitTailwindcssBasedirFromViteRoot(root) {
|
|
|
1750
2038
|
}
|
|
1751
2039
|
const tailwindConfigPath = findTailwindConfig(searchRoots);
|
|
1752
2040
|
if (tailwindConfigPath) {
|
|
1753
|
-
return
|
|
2041
|
+
return path5.dirname(tailwindConfigPath);
|
|
1754
2042
|
}
|
|
1755
2043
|
const packageRoot = findNearestPackageRoot(resolvedRoot);
|
|
1756
|
-
if (packageRoot && existsSync(
|
|
2044
|
+
if (packageRoot && existsSync(path5.join(packageRoot, PACKAGE_JSON_FILE))) {
|
|
1757
2045
|
return packageRoot;
|
|
1758
2046
|
}
|
|
1759
2047
|
return resolvedRoot;
|
|
@@ -1775,6 +2063,7 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
|
1775
2063
|
uniAppX,
|
|
1776
2064
|
disabledDefaultTemplateHandler
|
|
1777
2065
|
} = opts;
|
|
2066
|
+
const uniAppXEnabled = isUniAppXEnabled(uniAppX);
|
|
1778
2067
|
const disabledOptions = resolveDisabledOptions(disabled);
|
|
1779
2068
|
const tailwindcssMajorVersion = initialTwPatcher.majorVersion ?? 0;
|
|
1780
2069
|
const shouldRewriteCssImports = opts.rewriteCssImports !== false && !disabledOptions.rewriteCssImports && (rewriteCssImportsSpecified || tailwindcssMajorVersion >= 4);
|
|
@@ -1808,7 +2097,7 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
|
1808
2097
|
const signature = getRuntimeClassSetSignature(runtimeState.twPatcher);
|
|
1809
2098
|
const optionsKey = JSON.stringify({
|
|
1810
2099
|
appType,
|
|
1811
|
-
uniAppX:
|
|
2100
|
+
uniAppX: uniAppXEnabled,
|
|
1812
2101
|
customAttributesEntities,
|
|
1813
2102
|
disabledDefaultTemplateHandler,
|
|
1814
2103
|
configPath,
|
|
@@ -1908,7 +2197,7 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
|
1908
2197
|
const getResolvedConfig = () => resolvedConfig;
|
|
1909
2198
|
const utsPlatform = resolveUniUtsPlatform();
|
|
1910
2199
|
const isIosPlatform = utsPlatform.isAppIos;
|
|
1911
|
-
const uniAppXPlugins =
|
|
2200
|
+
const uniAppXPlugins = uniAppXEnabled ? createUniAppXPlugins({
|
|
1912
2201
|
appType,
|
|
1913
2202
|
customAttributesEntities,
|
|
1914
2203
|
disabledDefaultTemplateHandler,
|
|
@@ -1918,7 +2207,8 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
|
1918
2207
|
styleHandler,
|
|
1919
2208
|
jsHandler,
|
|
1920
2209
|
ensureRuntimeClassSet,
|
|
1921
|
-
getResolvedConfig
|
|
2210
|
+
getResolvedConfig,
|
|
2211
|
+
uniAppX
|
|
1922
2212
|
}) : void 0;
|
|
1923
2213
|
const plugins = [
|
|
1924
2214
|
...rewritePlugins,
|
|
@@ -1927,7 +2217,7 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
|
1927
2217
|
enforce: "post",
|
|
1928
2218
|
async configResolved(config) {
|
|
1929
2219
|
resolvedConfig = config;
|
|
1930
|
-
const resolvedRoot = config.root ?
|
|
2220
|
+
const resolvedRoot = config.root ? path5.resolve(config.root) : void 0;
|
|
1931
2221
|
if (!hasExplicitTailwindcssBasedir && resolvedRoot) {
|
|
1932
2222
|
const nextTailwindcssBasedir = resolveImplicitTailwindcssBasedirFromViteRoot(resolvedRoot);
|
|
1933
2223
|
if (opts.tailwindcssBasedir !== nextTailwindcssBasedir) {
|