weapp-tailwindcss 4.3.3 → 4.4.0-alpha.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.
- package/dist/chunk-2NRTWL47.js +43 -0
- package/dist/{chunk-GFQ2R7SX.mjs → chunk-3MSGCIVH.mjs} +127 -129
- package/dist/{chunk-3KMEJ2LM.js → chunk-AEJDBNAX.js} +540 -315
- package/dist/{chunk-M7PVNKCH.mjs → chunk-AXYGCCZW.mjs} +45 -57
- package/dist/chunk-E2LRXNZ3.js +122 -0
- package/dist/{chunk-L36QGA7Y.mjs → chunk-FBGUUXQV.mjs} +1 -1
- package/dist/{chunk-A75TB5TE.js → chunk-FOSGDQZ7.js} +34 -43
- package/dist/chunk-H4JTYYOI.mjs +43 -0
- package/dist/{chunk-5BTC4YQI.mjs → chunk-IHKVNALD.mjs} +29 -38
- package/dist/chunk-KAKRCCPX.mjs +122 -0
- package/dist/{chunk-L7VNJFIK.js → chunk-NZ7VALIM.js} +129 -131
- package/dist/{chunk-JDLLZFZX.js → chunk-PPTSD6TQ.js} +46 -58
- package/dist/{chunk-O3G5TVND.js → chunk-RBRSMHFS.js} +1 -1
- package/dist/chunk-UW3WHSZ5.js +39 -0
- package/dist/{chunk-3KXFKRIX.mjs → chunk-WCIVXE2D.mjs} +539 -314
- package/dist/chunk-ZNKIYZRQ.mjs +39 -0
- package/dist/cli.js +5 -8
- package/dist/cli.mjs +4 -7
- package/dist/core.js +5 -5
- package/dist/core.mjs +4 -4
- package/dist/css-macro/postcss.js +1 -1
- package/dist/css-macro/postcss.mjs +1 -1
- package/dist/css-macro.js +3 -3
- package/dist/css-macro.mjs +2 -2
- package/dist/defaults.js +4 -4
- package/dist/defaults.mjs +3 -3
- package/dist/escape.js +1 -1
- package/dist/escape.mjs +1 -1
- package/dist/gulp.js +7 -7
- package/dist/gulp.mjs +6 -6
- package/dist/index.js +9 -9
- package/dist/index.mjs +8 -8
- package/dist/postcss-html-transform.js +1 -1
- package/dist/postcss-html-transform.mjs +1 -1
- package/dist/presets.js +3 -3
- package/dist/presets.mjs +2 -2
- package/dist/types.d.mts +247 -246
- package/dist/types.d.ts +247 -246
- package/dist/types.js +1 -1
- package/dist/types.mjs +1 -1
- package/dist/vite.js +7 -7
- package/dist/vite.mjs +6 -6
- package/dist/webpack.js +7 -7
- package/dist/webpack.mjs +6 -6
- package/dist/webpack4.js +48 -63
- package/dist/webpack4.mjs +46 -61
- package/package.json +4 -5
- package/dist/chunk-3AUX4FGE.mjs +0 -13
- package/dist/chunk-GEUHO2UC.mjs +0 -141
- package/dist/chunk-LSSLYD6B.js +0 -13
- package/dist/chunk-QXQOYYCR.js +0 -26
- package/dist/chunk-TI4R65TB.js +0 -141
- package/dist/chunk-Y5AFAYKI.mjs +0 -26
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/debug/index.ts
|
|
2
|
+
var _debug2 = require('debug'); var _debug3 = _interopRequireDefault(_debug2);
|
|
3
|
+
var _debug = _debug3.default.call(void 0, "weapp-tw");
|
|
4
|
+
function createDebug(prefix) {
|
|
5
|
+
function debug(formatter, ...args) {
|
|
6
|
+
return _debug((_nullishCoalesce(prefix, () => ( ""))) + formatter, ...args);
|
|
7
|
+
}
|
|
8
|
+
return debug;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// src/bundlers/shared/cache.ts
|
|
12
|
+
async function processCachedTask({
|
|
13
|
+
cache,
|
|
14
|
+
cacheKey,
|
|
15
|
+
hashKey = cacheKey,
|
|
16
|
+
rawSource,
|
|
17
|
+
readCache,
|
|
18
|
+
applyResult,
|
|
19
|
+
transform,
|
|
20
|
+
onCacheHit
|
|
21
|
+
}) {
|
|
22
|
+
let cacheHit = false;
|
|
23
|
+
const result = await cache.process({
|
|
24
|
+
key: cacheKey,
|
|
25
|
+
hashKey,
|
|
26
|
+
rawSource,
|
|
27
|
+
resolveCache: readCache,
|
|
28
|
+
async onCacheHit(value) {
|
|
29
|
+
cacheHit = true;
|
|
30
|
+
await applyResult(value);
|
|
31
|
+
_optionalChain([onCacheHit, 'optionalCall', _ => _()]);
|
|
32
|
+
},
|
|
33
|
+
transform
|
|
34
|
+
});
|
|
35
|
+
if (!cacheHit) {
|
|
36
|
+
await applyResult(result);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
exports.createDebug = createDebug; exports.processCachedTask = processCachedTask;
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
|
-
createDebug
|
|
3
|
-
|
|
2
|
+
createDebug,
|
|
3
|
+
processCachedTask
|
|
4
|
+
} from "./chunk-H4JTYYOI.mjs";
|
|
4
5
|
import {
|
|
5
6
|
vitePluginName
|
|
6
7
|
} from "./chunk-CMUA5KCO.mjs";
|
|
7
8
|
import {
|
|
8
9
|
generateCode,
|
|
9
10
|
getCompilerContext
|
|
10
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-WCIVXE2D.mjs";
|
|
11
12
|
import {
|
|
12
13
|
replaceWxml
|
|
13
14
|
} from "./chunk-Q67IXIAH.mjs";
|
|
14
15
|
import {
|
|
15
16
|
getGroupedEntries
|
|
16
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-ZNKIYZRQ.mjs";
|
|
17
18
|
|
|
18
19
|
// src/bundlers/vite/index.ts
|
|
19
20
|
import postcssHtmlTransform from "@weapp-tailwindcss/postcss/html-transform";
|
|
@@ -24,10 +25,32 @@ import MagicString from "magic-string";
|
|
|
24
25
|
import { parse } from "vue/compiler-sfc";
|
|
25
26
|
function traverse(node, visitor) {
|
|
26
27
|
visitor(node);
|
|
27
|
-
if (node.children) {
|
|
28
|
-
node.children
|
|
28
|
+
if (Array.isArray(node.children)) {
|
|
29
|
+
for (const child of node.children) {
|
|
30
|
+
if (child && typeof child === "object" && "type" in child) {
|
|
31
|
+
traverse(child, visitor);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
29
34
|
}
|
|
30
35
|
}
|
|
36
|
+
function createClassAttributeUpdater(ms) {
|
|
37
|
+
return (prop) => {
|
|
38
|
+
if (prop.value) {
|
|
39
|
+
ms.update(prop.value.loc.start.offset + 1, prop.value.loc.end.offset - 1, replaceWxml(prop.value.content));
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function createClassDirectiveUpdater(ms, jsHandler, runtimeSet) {
|
|
44
|
+
return (prop) => {
|
|
45
|
+
if (prop.arg?.type === NodeTypes.SIMPLE_EXPRESSION && prop.arg.content === "class" && prop.exp?.type === NodeTypes.SIMPLE_EXPRESSION) {
|
|
46
|
+
const generated = generateCode(prop.exp.content, {
|
|
47
|
+
jsHandler,
|
|
48
|
+
runtimeSet
|
|
49
|
+
});
|
|
50
|
+
ms.update(prop.exp.loc.start.offset, prop.exp.loc.end.offset, generated);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
31
54
|
var defaultCreateJsHandlerOptions = {
|
|
32
55
|
babelParserOptions: {
|
|
33
56
|
plugins: [
|
|
@@ -42,27 +65,21 @@ function transformUVue(code, id, jsHandler, runtimeSet) {
|
|
|
42
65
|
const ms = new MagicString(code);
|
|
43
66
|
const { descriptor, errors } = parse(code);
|
|
44
67
|
if (errors.length === 0) {
|
|
45
|
-
if (descriptor.template) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
ms.update(prop.exp.loc.start.offset, prop.exp.loc.end.offset, code2);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
});
|
|
68
|
+
if (descriptor.template?.ast) {
|
|
69
|
+
const updateStaticClass = createClassAttributeUpdater(ms);
|
|
70
|
+
const updateDynamicClass = createClassDirectiveUpdater(ms, jsHandler, runtimeSet);
|
|
71
|
+
traverse(descriptor.template.ast, (node) => {
|
|
72
|
+
if (node.type !== NodeTypes.ELEMENT) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
for (const prop of node.props) {
|
|
76
|
+
if (prop.type === NodeTypes.ATTRIBUTE && prop.name === "class") {
|
|
77
|
+
updateStaticClass(prop);
|
|
78
|
+
} else if (prop.type === NodeTypes.DIRECTIVE && prop.name === "bind") {
|
|
79
|
+
updateDynamicClass(prop);
|
|
80
|
+
}
|
|
62
81
|
}
|
|
63
|
-
};
|
|
64
|
-
var extractClassNames = extractClassNames2;
|
|
65
|
-
traverse(descriptor.template.ast, extractClassNames2);
|
|
82
|
+
});
|
|
66
83
|
}
|
|
67
84
|
if (descriptor.script) {
|
|
68
85
|
const { code: code2 } = jsHandler(descriptor.script.content, runtimeSet ?? /* @__PURE__ */ new Set(), defaultCreateJsHandlerOptions);
|
|
@@ -195,131 +212,114 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
|
195
212
|
runtimeSet = await twPatcher.getClassSet();
|
|
196
213
|
setMangleRuntimeSet(runtimeSet);
|
|
197
214
|
debug("get runtimeSet, class count: %d", runtimeSet.size);
|
|
198
|
-
const
|
|
215
|
+
const tasks = [];
|
|
199
216
|
if (Array.isArray(groupedEntries.html)) {
|
|
200
|
-
for (const
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
const source = cache.get(file);
|
|
210
|
-
if (source) {
|
|
211
|
-
originalSource.source = source;
|
|
212
|
-
debug("html cache hit: %s", file);
|
|
213
|
-
} else {
|
|
214
|
-
return false;
|
|
215
|
-
}
|
|
217
|
+
for (const [file, originalSource] of groupedEntries.html) {
|
|
218
|
+
const rawSource = originalSource.source.toString();
|
|
219
|
+
tasks.push(
|
|
220
|
+
processCachedTask({
|
|
221
|
+
cache,
|
|
222
|
+
cacheKey: file,
|
|
223
|
+
rawSource,
|
|
224
|
+
applyResult(source) {
|
|
225
|
+
originalSource.source = source;
|
|
216
226
|
},
|
|
217
|
-
|
|
218
|
-
|
|
227
|
+
onCacheHit() {
|
|
228
|
+
debug("html cache hit: %s", file);
|
|
229
|
+
},
|
|
230
|
+
async transform() {
|
|
231
|
+
const transformed = await templateHandler(rawSource, {
|
|
219
232
|
runtimeSet
|
|
220
233
|
});
|
|
221
|
-
onUpdate(file,
|
|
234
|
+
onUpdate(file, rawSource, transformed);
|
|
222
235
|
debug("html handle: %s", file);
|
|
223
236
|
return {
|
|
224
|
-
|
|
225
|
-
source: originalSource.source
|
|
237
|
+
result: transformed
|
|
226
238
|
};
|
|
227
239
|
}
|
|
228
|
-
)
|
|
240
|
+
})
|
|
229
241
|
);
|
|
230
242
|
}
|
|
231
243
|
}
|
|
232
244
|
if (Array.isArray(groupedEntries.js)) {
|
|
233
|
-
for (const
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
const source = cache.get(file);
|
|
243
|
-
if (source) {
|
|
245
|
+
for (const [file, originalSource] of groupedEntries.js) {
|
|
246
|
+
if (originalSource.type === "chunk") {
|
|
247
|
+
const rawSource = originalSource.code;
|
|
248
|
+
tasks.push(
|
|
249
|
+
processCachedTask({
|
|
250
|
+
cache,
|
|
251
|
+
cacheKey: file,
|
|
252
|
+
rawSource,
|
|
253
|
+
applyResult(source) {
|
|
244
254
|
originalSource.code = source;
|
|
255
|
+
},
|
|
256
|
+
onCacheHit() {
|
|
245
257
|
debug("js cache hit: %s", file);
|
|
246
|
-
} else {
|
|
247
|
-
return false;
|
|
248
|
-
}
|
|
249
|
-
},
|
|
250
|
-
async () => {
|
|
251
|
-
const { code } = await jsHandler(rawSource, runtimeSet);
|
|
252
|
-
originalSource.code = code;
|
|
253
|
-
onUpdate(file, rawSource, code);
|
|
254
|
-
debug("js handle: %s", file);
|
|
255
|
-
return {
|
|
256
|
-
key: file,
|
|
257
|
-
source: code
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
)
|
|
261
|
-
);
|
|
262
|
-
}
|
|
263
|
-
if (uniAppX) {
|
|
264
|
-
for (const element of groupedEntries.js.filter((x) => x[1].type === "asset")) {
|
|
265
|
-
const [file, originalSource] = element;
|
|
266
|
-
const rawSource = originalSource.source.toString();
|
|
267
|
-
const hash = cache.computeHash(rawSource);
|
|
268
|
-
cache.calcHashValueChanged(file, hash);
|
|
269
|
-
promises.push(
|
|
270
|
-
cache.process(
|
|
271
|
-
file,
|
|
272
|
-
() => {
|
|
273
|
-
const source = cache.get(file);
|
|
274
|
-
if (source) {
|
|
275
|
-
originalSource.source = source;
|
|
276
|
-
debug("js cache hit: %s", file);
|
|
277
|
-
} else {
|
|
278
|
-
return false;
|
|
279
|
-
}
|
|
280
258
|
},
|
|
281
|
-
async ()
|
|
282
|
-
const { code } = await jsHandler(rawSource, runtimeSet
|
|
283
|
-
uniAppX,
|
|
284
|
-
babelParserOptions: {
|
|
285
|
-
plugins: [
|
|
286
|
-
"typescript"
|
|
287
|
-
],
|
|
288
|
-
sourceType: "unambiguous"
|
|
289
|
-
}
|
|
290
|
-
});
|
|
291
|
-
originalSource.source = code;
|
|
259
|
+
async transform() {
|
|
260
|
+
const { code } = await jsHandler(rawSource, runtimeSet);
|
|
292
261
|
onUpdate(file, rawSource, code);
|
|
293
262
|
debug("js handle: %s", file);
|
|
294
263
|
return {
|
|
295
|
-
|
|
296
|
-
source: code
|
|
264
|
+
result: code
|
|
297
265
|
};
|
|
298
266
|
}
|
|
299
|
-
)
|
|
267
|
+
})
|
|
300
268
|
);
|
|
301
269
|
}
|
|
302
270
|
}
|
|
271
|
+
if (uniAppX) {
|
|
272
|
+
for (const [file, originalSource] of groupedEntries.js) {
|
|
273
|
+
if (originalSource.type === "asset") {
|
|
274
|
+
const rawSource = originalSource.source.toString();
|
|
275
|
+
tasks.push(
|
|
276
|
+
processCachedTask({
|
|
277
|
+
cache,
|
|
278
|
+
cacheKey: file,
|
|
279
|
+
rawSource,
|
|
280
|
+
applyResult(source) {
|
|
281
|
+
originalSource.source = source;
|
|
282
|
+
},
|
|
283
|
+
onCacheHit() {
|
|
284
|
+
debug("js cache hit: %s", file);
|
|
285
|
+
},
|
|
286
|
+
async transform() {
|
|
287
|
+
const { code } = await jsHandler(rawSource, runtimeSet, {
|
|
288
|
+
uniAppX,
|
|
289
|
+
babelParserOptions: {
|
|
290
|
+
plugins: [
|
|
291
|
+
"typescript"
|
|
292
|
+
],
|
|
293
|
+
sourceType: "unambiguous"
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
onUpdate(file, rawSource, code);
|
|
297
|
+
debug("js handle: %s", file);
|
|
298
|
+
return {
|
|
299
|
+
result: code
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
})
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
303
307
|
}
|
|
304
308
|
if (Array.isArray(groupedEntries.css)) {
|
|
305
|
-
for (const
|
|
306
|
-
const [file, originalSource] = element;
|
|
309
|
+
for (const [file, originalSource] of groupedEntries.css) {
|
|
307
310
|
const rawSource = originalSource.source.toString();
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
()
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
} else {
|
|
319
|
-
return false;
|
|
320
|
-
}
|
|
311
|
+
tasks.push(
|
|
312
|
+
processCachedTask({
|
|
313
|
+
cache,
|
|
314
|
+
cacheKey: file,
|
|
315
|
+
rawSource,
|
|
316
|
+
applyResult(source) {
|
|
317
|
+
originalSource.source = source;
|
|
318
|
+
},
|
|
319
|
+
onCacheHit() {
|
|
320
|
+
debug("css cache hit: %s", file);
|
|
321
321
|
},
|
|
322
|
-
async ()
|
|
322
|
+
async transform() {
|
|
323
323
|
const { css } = await styleHandler(rawSource, {
|
|
324
324
|
isMainChunk: mainCssChunkMatcher(originalSource.fileName, appType),
|
|
325
325
|
postcssOptions: {
|
|
@@ -329,19 +329,17 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
|
329
329
|
},
|
|
330
330
|
majorVersion: twPatcher.majorVersion
|
|
331
331
|
});
|
|
332
|
-
originalSource.source = css;
|
|
333
332
|
onUpdate(file, rawSource, css);
|
|
334
333
|
debug("css handle: %s", file);
|
|
335
334
|
return {
|
|
336
|
-
|
|
337
|
-
source: css
|
|
335
|
+
result: css
|
|
338
336
|
};
|
|
339
337
|
}
|
|
340
|
-
)
|
|
338
|
+
})
|
|
341
339
|
);
|
|
342
340
|
}
|
|
343
341
|
}
|
|
344
|
-
await Promise.all(
|
|
342
|
+
await Promise.all(tasks);
|
|
345
343
|
onEnd();
|
|
346
344
|
debug("end");
|
|
347
345
|
}
|