weapp-tailwindcss 4.3.2 → 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.
Files changed (55) hide show
  1. package/dist/chunk-2F7HOQQY.mjs +8 -0
  2. package/dist/chunk-2NRTWL47.js +43 -0
  3. package/dist/{chunk-YNMM5ZP5.mjs → chunk-3MSGCIVH.mjs} +128 -138
  4. package/dist/chunk-6GP37C26.js +8 -0
  5. package/dist/{chunk-GRWK73SM.js → chunk-AEJDBNAX.js} +567 -309
  6. package/dist/{chunk-IDYXPWF6.mjs → chunk-AXYGCCZW.mjs} +51 -63
  7. package/dist/chunk-E2LRXNZ3.js +122 -0
  8. package/dist/{chunk-BXPTS6UP.mjs → chunk-FBGUUXQV.mjs} +1 -1
  9. package/dist/{chunk-72PXDJ7I.js → chunk-FOSGDQZ7.js} +34 -43
  10. package/dist/chunk-H4JTYYOI.mjs +43 -0
  11. package/dist/{chunk-3YIQPUK7.mjs → chunk-IHKVNALD.mjs} +29 -38
  12. package/dist/chunk-KAKRCCPX.mjs +122 -0
  13. package/dist/{chunk-AMSF25MI.js → chunk-NZ7VALIM.js} +130 -140
  14. package/dist/{chunk-YSVQIZ4W.js → chunk-PPTSD6TQ.js} +51 -63
  15. package/dist/{chunk-K6IPKJSY.js → chunk-RBRSMHFS.js} +1 -1
  16. package/dist/chunk-UW3WHSZ5.js +39 -0
  17. package/dist/{chunk-DGVVFKNF.mjs → chunk-WCIVXE2D.mjs} +566 -308
  18. package/dist/chunk-ZNKIYZRQ.mjs +39 -0
  19. package/dist/cli.js +5 -8
  20. package/dist/cli.mjs +4 -7
  21. package/dist/core.js +5 -5
  22. package/dist/core.mjs +4 -4
  23. package/dist/css-macro/postcss.js +1 -1
  24. package/dist/css-macro/postcss.mjs +1 -1
  25. package/dist/css-macro.js +3 -3
  26. package/dist/css-macro.mjs +2 -2
  27. package/dist/defaults.js +4 -4
  28. package/dist/defaults.mjs +3 -3
  29. package/dist/escape.js +1 -1
  30. package/dist/escape.mjs +1 -1
  31. package/dist/gulp.js +7 -7
  32. package/dist/gulp.mjs +6 -6
  33. package/dist/index.js +10 -9
  34. package/dist/index.mjs +9 -8
  35. package/dist/postcss-html-transform.js +1 -1
  36. package/dist/postcss-html-transform.mjs +1 -1
  37. package/dist/presets.js +3 -3
  38. package/dist/presets.mjs +2 -2
  39. package/dist/types.d.mts +248 -194
  40. package/dist/types.d.ts +248 -194
  41. package/dist/types.js +1 -1
  42. package/dist/types.mjs +1 -1
  43. package/dist/vite.js +7 -7
  44. package/dist/vite.mjs +6 -6
  45. package/dist/webpack.js +8 -7
  46. package/dist/webpack.mjs +7 -6
  47. package/dist/webpack4.js +53 -68
  48. package/dist/webpack4.mjs +52 -67
  49. package/package.json +10 -12
  50. package/dist/chunk-3AUX4FGE.mjs +0 -13
  51. package/dist/chunk-JXBLHLFR.mjs +0 -27
  52. package/dist/chunk-K3KFCISK.js +0 -145
  53. package/dist/chunk-LSSLYD6B.js +0 -13
  54. package/dist/chunk-O335YLYH.js +0 -27
  55. package/dist/chunk-RC2KZ2LO.mjs +0 -145
@@ -0,0 +1,8 @@
1
+ // src/bundlers/webpack/BaseUnifiedPlugin/shared.ts
2
+ function getCacheKey(filename) {
3
+ return filename;
4
+ }
5
+
6
+ export {
7
+ getCacheKey
8
+ };
@@ -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
- } from "./chunk-3AUX4FGE.mjs";
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-DGVVFKNF.mjs";
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-JXBLHLFR.mjs";
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.forEach((child) => traverse(child, visitor));
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
- let extractClassNames2 = function(node) {
47
- if (node.type === NodeTypes.ELEMENT) {
48
- node.props.forEach((prop) => {
49
- if (prop.type === NodeTypes.ATTRIBUTE && prop.name === "class" && prop.value) {
50
- ms.update(prop.value.loc.start.offset + 1, prop.value.loc.end.offset - 1, replaceWxml(prop.value.content));
51
- }
52
- if (prop.type === NodeTypes.DIRECTIVE && prop.name === "bind" && prop.arg?.type === NodeTypes.SIMPLE_EXPRESSION && prop.arg.content === "class") {
53
- if (prop.exp?.type === NodeTypes.SIMPLE_EXPRESSION) {
54
- const code2 = generateCode(prop.exp.content, {
55
- jsHandler,
56
- runtimeSet
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;
62
74
  }
63
- };
64
- var extractClassNames = extractClassNames2;
65
- traverse(descriptor.template.ast, extractClassNames2);
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
+ }
81
+ }
82
+ });
66
83
  }
67
84
  if (descriptor.script) {
68
85
  const { code: code2 } = jsHandler(descriptor.script.content, runtimeSet ?? /* @__PURE__ */ new Set(), defaultCreateJsHandlerOptions);
@@ -172,10 +189,6 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
172
189
  let runtimeSet;
173
190
  onLoad();
174
191
  const plugins = [
175
- // {
176
- // name: `${vitePluginName}:pre`,
177
- // enforce: 'pre',
178
- // },
179
192
  {
180
193
  name: `${vitePluginName}:post`,
181
194
  enforce: "post",
@@ -199,134 +212,114 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
199
212
  runtimeSet = await twPatcher.getClassSet();
200
213
  setMangleRuntimeSet(runtimeSet);
201
214
  debug("get runtimeSet, class count: %d", runtimeSet.size);
202
- const promises = [];
215
+ const tasks = [];
203
216
  if (Array.isArray(groupedEntries.html)) {
204
- for (const element of groupedEntries.html) {
205
- const [file, originalSource] = element;
206
- const oldVal = originalSource.source.toString();
207
- const hash = cache.computeHash(oldVal);
208
- cache.calcHashValueChanged(file, hash);
209
- promises.push(
210
- cache.process(
211
- file,
212
- () => {
213
- const source = cache.get(file);
214
- if (source) {
215
- originalSource.source = source;
216
- debug("html cache hit: %s", file);
217
- } else {
218
- return false;
219
- }
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;
226
+ },
227
+ onCacheHit() {
228
+ debug("html cache hit: %s", file);
220
229
  },
221
- async () => {
222
- originalSource.source = await templateHandler(oldVal, {
230
+ async transform() {
231
+ const transformed = await templateHandler(rawSource, {
223
232
  runtimeSet
224
233
  });
225
- onUpdate(file, oldVal, originalSource.source);
234
+ onUpdate(file, rawSource, transformed);
226
235
  debug("html handle: %s", file);
227
236
  return {
228
- key: file,
229
- source: originalSource.source
237
+ result: transformed
230
238
  };
231
239
  }
232
- )
240
+ })
233
241
  );
234
242
  }
235
243
  }
236
244
  if (Array.isArray(groupedEntries.js)) {
237
- for (const element of groupedEntries.js.filter((x) => x[1].type === "chunk")) {
238
- const [file, originalSource] = element;
239
- const rawSource = originalSource.code;
240
- const hash = cache.computeHash(rawSource);
241
- cache.calcHashValueChanged(file, hash);
242
- promises.push(
243
- cache.process(
244
- file,
245
- () => {
246
- const source = cache.get(file);
247
- 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) {
248
254
  originalSource.code = source;
255
+ },
256
+ onCacheHit() {
249
257
  debug("js cache hit: %s", file);
250
- } else {
251
- return false;
252
- }
253
- },
254
- async () => {
255
- const { code } = await jsHandler(rawSource, runtimeSet, {
256
- // generateMap: hasSourceMap,
257
- });
258
- originalSource.code = code;
259
- onUpdate(file, rawSource, code);
260
- debug("js handle: %s", file);
261
- return {
262
- key: file,
263
- source: code
264
- };
265
- }
266
- )
267
- );
268
- }
269
- if (uniAppX) {
270
- for (const element of groupedEntries.js.filter((x) => x[1].type === "asset")) {
271
- const [file, originalSource] = element;
272
- const rawSource = originalSource.source.toString();
273
- const hash = cache.computeHash(rawSource);
274
- cache.calcHashValueChanged(file, hash);
275
- promises.push(
276
- cache.process(
277
- file,
278
- () => {
279
- const source = cache.get(file);
280
- if (source) {
281
- originalSource.source = source;
282
- debug("js cache hit: %s", file);
283
- } else {
284
- return false;
285
- }
286
258
  },
287
- async () => {
288
- const { code } = await jsHandler(rawSource, runtimeSet, {
289
- // generateMap: hasSourceMap,
290
- uniAppX,
291
- babelParserOptions: {
292
- plugins: [
293
- "typescript"
294
- ],
295
- sourceType: "unambiguous"
296
- }
297
- });
298
- originalSource.source = code;
259
+ async transform() {
260
+ const { code } = await jsHandler(rawSource, runtimeSet);
299
261
  onUpdate(file, rawSource, code);
300
262
  debug("js handle: %s", file);
301
263
  return {
302
- key: file,
303
- source: code
264
+ result: code
304
265
  };
305
266
  }
306
- )
267
+ })
307
268
  );
308
269
  }
309
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
+ }
310
307
  }
311
308
  if (Array.isArray(groupedEntries.css)) {
312
- for (const element of groupedEntries.css) {
313
- const [file, originalSource] = element;
309
+ for (const [file, originalSource] of groupedEntries.css) {
314
310
  const rawSource = originalSource.source.toString();
315
- const hash = cache.computeHash(rawSource);
316
- cache.calcHashValueChanged(file, hash);
317
- promises.push(
318
- cache.process(
319
- file,
320
- () => {
321
- const source = cache.get(file);
322
- if (source) {
323
- originalSource.source = source;
324
- debug("css cache hit: %s", file);
325
- } else {
326
- return false;
327
- }
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);
328
321
  },
329
- async () => {
322
+ async transform() {
330
323
  const { css } = await styleHandler(rawSource, {
331
324
  isMainChunk: mainCssChunkMatcher(originalSource.fileName, appType),
332
325
  postcssOptions: {
@@ -336,19 +329,17 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
336
329
  },
337
330
  majorVersion: twPatcher.majorVersion
338
331
  });
339
- originalSource.source = css;
340
332
  onUpdate(file, rawSource, css);
341
333
  debug("css handle: %s", file);
342
334
  return {
343
- key: file,
344
- source: css
335
+ result: css
345
336
  };
346
337
  }
347
- )
338
+ })
348
339
  );
349
340
  }
350
341
  }
351
- await Promise.all(promises);
342
+ await Promise.all(tasks);
352
343
  onEnd();
353
344
  debug("end");
354
345
  }
@@ -375,8 +366,7 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
375
366
  // postcss may return virtual files
376
367
  // we cannot obtain content of them, so this needs to be enabled
377
368
  sourcesContent: true
378
- // when "prev: preprocessorMap", the result map may include duplicate filename in `postcssResult.map.sources`
379
- // prev: preprocessorMap,
369
+ // when a previous preprocessor map is provided, duplicates may appear in `postcssResult.map.sources`
380
370
  }
381
371
  }
382
372
  }
@@ -0,0 +1,8 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/bundlers/webpack/BaseUnifiedPlugin/shared.ts
2
+ function getCacheKey(filename) {
3
+ return filename;
4
+ }
5
+
6
+
7
+
8
+ exports.getCacheKey = getCacheKey;