weapp-tailwindcss 4.10.1 → 4.10.2

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 (47) hide show
  1. package/dist/{chunk-EE4DYM4E.js → chunk-3R7FDZJL.js} +27 -17
  2. package/dist/{chunk-K7CTHHN2.js → chunk-6VKE7EWV.js} +28 -27
  3. package/dist/{chunk-GKT5AE7D.mjs → chunk-ACNOEKQI.mjs} +1 -1
  4. package/dist/{chunk-4QCL7FBX.mjs → chunk-BZCCVPSU.mjs} +1 -1
  5. package/dist/{chunk-P65O2L27.js → chunk-HJVZ4TO3.js} +3 -3
  6. package/dist/{chunk-7K3R5LV6.js → chunk-I35XJD75.js} +235 -63
  7. package/dist/{chunk-3BKE5AJQ.mjs → chunk-LHBUALTK.mjs} +4 -3
  8. package/dist/{chunk-RB7YN5XZ.js → chunk-M2ATX5ZS.js} +3 -3
  9. package/dist/{chunk-RXM5ERRJ.mjs → chunk-MPVAZKRB.mjs} +201 -29
  10. package/dist/{chunk-7ZI6WVIU.mjs → chunk-N6JOG5K3.mjs} +3 -2
  11. package/dist/{chunk-W3EZEDKD.js → chunk-NPZ5QQC7.js} +8 -7
  12. package/dist/{chunk-ESIT2XWD.mjs → chunk-WJU62RPV.mjs} +13 -3
  13. package/dist/cli.js +9 -9
  14. package/dist/cli.mjs +1 -1
  15. package/dist/core.d.mts +1 -1
  16. package/dist/core.d.ts +1 -1
  17. package/dist/core.js +22 -9
  18. package/dist/core.mjs +17 -4
  19. package/dist/defaults.d.mts +1 -1
  20. package/dist/defaults.d.ts +1 -1
  21. package/dist/gulp.d.mts +1 -1
  22. package/dist/gulp.d.ts +1 -1
  23. package/dist/gulp.js +4 -4
  24. package/dist/gulp.mjs +3 -3
  25. package/dist/{index-BESv5MWf.d.ts → index-t_VBjwYm.d.mts} +11 -0
  26. package/dist/{index-BESv5MWf.d.mts → index-t_VBjwYm.d.ts} +11 -0
  27. package/dist/index.d.mts +1 -1
  28. package/dist/index.d.ts +1 -1
  29. package/dist/index.js +7 -7
  30. package/dist/index.mjs +6 -6
  31. package/dist/presets.d.mts +1 -1
  32. package/dist/presets.d.ts +1 -1
  33. package/dist/types.d.mts +14 -2
  34. package/dist/types.d.ts +14 -2
  35. package/dist/vite.d.mts +1 -1
  36. package/dist/vite.d.ts +1 -1
  37. package/dist/vite.js +4 -4
  38. package/dist/vite.mjs +3 -3
  39. package/dist/webpack.d.mts +1 -1
  40. package/dist/webpack.d.ts +1 -1
  41. package/dist/webpack.js +5 -5
  42. package/dist/webpack.mjs +4 -4
  43. package/dist/webpack4.d.mts +1 -1
  44. package/dist/webpack4.d.ts +1 -1
  45. package/dist/webpack4.js +27 -26
  46. package/dist/webpack4.mjs +4 -3
  47. package/package.json +4 -4
@@ -16,10 +16,10 @@ import {
16
16
  import _createDebug from "debug";
17
17
  var _debug = _createDebug("weapp-tw");
18
18
  function createDebug(prefix) {
19
- function debug2(formatter, ...args) {
19
+ function debug3(formatter, ...args) {
20
20
  return _debug((prefix ?? "") + formatter, ...args);
21
21
  }
22
- return debug2;
22
+ return debug3;
23
23
  }
24
24
 
25
25
  // src/tailwindcss/runtime/cache.ts
@@ -285,7 +285,7 @@ async function collectRuntimeClassSet(twPatcher, options = {}) {
285
285
  // package.json
286
286
  var package_default = {
287
287
  name: "weapp-tailwindcss",
288
- version: "4.10.1",
288
+ version: "4.10.2",
289
289
  description: "\u628A tailwindcss \u539F\u5B50\u5316\u6837\u5F0F\u601D\u60F3\uFF0C\u5E26\u7ED9\u5C0F\u7A0B\u5E8F\u5F00\u53D1\u8005\u4EEC! bring tailwindcss to miniprogram developers!",
290
290
  author: "ice breaker <1324318532@qq.com>",
291
291
  license: "MIT",
@@ -1189,22 +1189,80 @@ import { jsStringEscape } from "@ast-core/escape";
1189
1189
  import { escapeStringRegexp as escapeStringRegexp2 } from "@weapp-core/regex";
1190
1190
  import { splitCode } from "@weapp-tailwindcss/shared/extractors";
1191
1191
 
1192
+ // src/wxml/shared.ts
1193
+ import { escape, MappingChars2String } from "@weapp-core/escape";
1194
+ function replaceWxml(original, options = {
1195
+ keepEOL: false,
1196
+ escapeMap: MappingChars2String
1197
+ }) {
1198
+ const { keepEOL, escapeMap, ignoreHead } = options;
1199
+ let res = original;
1200
+ if (!keepEOL) {
1201
+ res = res.replaceAll(/[\n\r]+/g, "");
1202
+ }
1203
+ res = escape(res, {
1204
+ map: escapeMap,
1205
+ ignoreHead
1206
+ });
1207
+ return res;
1208
+ }
1209
+
1192
1210
  // src/shared/classname-transform.ts
1193
- function shouldTransformClassNameCandidate(candidate, {
1211
+ function isArbitraryValueCandidate(candidate) {
1212
+ const normalized = candidate.trim();
1213
+ if (!normalized.includes("[") || !normalized.includes("]")) {
1214
+ return false;
1215
+ }
1216
+ if (/^(?:https?:)?\/\//.test(normalized)) {
1217
+ return false;
1218
+ }
1219
+ return true;
1220
+ }
1221
+ function shouldEnableArbitraryValueFallback({
1222
+ classNameSet,
1223
+ jsArbitraryValueFallback,
1224
+ tailwindcssMajorVersion
1225
+ }) {
1226
+ if (jsArbitraryValueFallback === true) {
1227
+ return true;
1228
+ }
1229
+ if (jsArbitraryValueFallback === false) {
1230
+ return false;
1231
+ }
1232
+ return tailwindcssMajorVersion === 4 && (!classNameSet || classNameSet.size === 0);
1233
+ }
1234
+ function resolveClassNameTransformDecision(candidate, {
1194
1235
  alwaysEscape,
1195
1236
  classNameSet,
1196
- jsPreserveClass
1237
+ escapeMap,
1238
+ jsArbitraryValueFallback,
1239
+ jsPreserveClass,
1240
+ tailwindcssMajorVersion,
1241
+ classContext
1197
1242
  }) {
1198
1243
  if (alwaysEscape) {
1199
- return true;
1244
+ return "direct";
1200
1245
  }
1201
1246
  if (jsPreserveClass?.(candidate)) {
1202
- return false;
1247
+ return "skip";
1203
1248
  }
1204
- if (!classNameSet || classNameSet.size === 0) {
1205
- return false;
1249
+ if (classNameSet?.has(candidate)) {
1250
+ return "direct";
1251
+ }
1252
+ if (classNameSet && classNameSet.size > 0) {
1253
+ const escapedCandidate = replaceWxml(candidate, { escapeMap });
1254
+ if (escapedCandidate !== candidate && classNameSet.has(escapedCandidate)) {
1255
+ return "escaped";
1256
+ }
1257
+ }
1258
+ if (classContext && isArbitraryValueCandidate(candidate) && shouldEnableArbitraryValueFallback({
1259
+ classNameSet,
1260
+ jsArbitraryValueFallback,
1261
+ tailwindcssMajorVersion
1262
+ })) {
1263
+ return "fallback";
1206
1264
  }
1207
- return classNameSet.has(candidate);
1265
+ return "skip";
1208
1266
  }
1209
1267
 
1210
1268
  // src/utils/decode.ts
@@ -1230,25 +1288,105 @@ function decodeUnicode2(input) {
1230
1288
  }
1231
1289
  }
1232
1290
 
1233
- // src/wxml/shared.ts
1234
- import { escape, MappingChars2String } from "@weapp-core/escape";
1235
- function replaceWxml(original, options = {
1236
- keepEOL: false,
1237
- escapeMap: MappingChars2String
1238
- }) {
1239
- const { keepEOL, escapeMap, ignoreHead } = options;
1240
- let res = original;
1241
- if (!keepEOL) {
1242
- res = res.replaceAll(/[\n\r]+/g, "");
1291
+ // src/js/class-context.ts
1292
+ var CLASS_LIKE_KEYWORDS = /* @__PURE__ */ new Set([
1293
+ "class",
1294
+ "classname",
1295
+ "hoverclass",
1296
+ "virtualhostclass",
1297
+ "rootclass"
1298
+ ]);
1299
+ var CLASS_HELPER_IDENTIFIERS = /* @__PURE__ */ new Set([
1300
+ "cn",
1301
+ "clsx",
1302
+ "classnames",
1303
+ "twmerge",
1304
+ "cva",
1305
+ "tv",
1306
+ "cx",
1307
+ "r"
1308
+ ]);
1309
+ function normalizeKeyword(name) {
1310
+ return name.replace(/[-_:]/g, "").toLowerCase();
1311
+ }
1312
+ function readObjectKeyName(path5) {
1313
+ if (path5.isIdentifier()) {
1314
+ return path5.node.name;
1243
1315
  }
1244
- res = escape(res, {
1245
- map: escapeMap,
1246
- ignoreHead
1247
- });
1248
- return res;
1316
+ if (path5.isStringLiteral()) {
1317
+ return path5.node.value;
1318
+ }
1319
+ if (path5.isTemplateLiteral() && path5.node.expressions.length === 0) {
1320
+ return path5.node.quasis[0]?.value.cooked ?? path5.node.quasis[0]?.value.raw;
1321
+ }
1322
+ return void 0;
1323
+ }
1324
+ function isClassLikeObjectProperty(path5, valuePath) {
1325
+ if (!path5.isObjectProperty()) {
1326
+ return false;
1327
+ }
1328
+ if (path5.get("value") !== valuePath) {
1329
+ return false;
1330
+ }
1331
+ const keyName = readObjectKeyName(path5.get("key"));
1332
+ if (!keyName) {
1333
+ return false;
1334
+ }
1335
+ return CLASS_LIKE_KEYWORDS.has(normalizeKeyword(keyName));
1336
+ }
1337
+ function isClassLikeJsxAttribute(path5) {
1338
+ if (!path5.isJSXAttribute()) {
1339
+ return false;
1340
+ }
1341
+ const namePath = path5.get("name");
1342
+ if (!namePath.isJSXIdentifier()) {
1343
+ return false;
1344
+ }
1345
+ return CLASS_LIKE_KEYWORDS.has(normalizeKeyword(namePath.node.name));
1346
+ }
1347
+ function isClassLikeCallExpression(path5, valuePath) {
1348
+ if (!path5.isCallExpression()) {
1349
+ return false;
1350
+ }
1351
+ const args = path5.get("arguments");
1352
+ if (!args.includes(valuePath)) {
1353
+ return false;
1354
+ }
1355
+ const calleePath = path5.get("callee");
1356
+ if (calleePath.isIdentifier()) {
1357
+ return CLASS_HELPER_IDENTIFIERS.has(normalizeKeyword(calleePath.node.name));
1358
+ }
1359
+ if (calleePath.isMemberExpression()) {
1360
+ const propertyPath = calleePath.get("property");
1361
+ if (propertyPath.isIdentifier()) {
1362
+ return CLASS_HELPER_IDENTIFIERS.has(normalizeKeyword(propertyPath.node.name));
1363
+ }
1364
+ if (propertyPath.isStringLiteral()) {
1365
+ return CLASS_HELPER_IDENTIFIERS.has(normalizeKeyword(propertyPath.node.value));
1366
+ }
1367
+ }
1368
+ return false;
1369
+ }
1370
+ function isClassContextLiteralPath(path5) {
1371
+ let current = path5;
1372
+ while (current.parentPath) {
1373
+ const parent = current.parentPath;
1374
+ if (isClassLikeObjectProperty(parent, current)) {
1375
+ return true;
1376
+ }
1377
+ if (isClassLikeJsxAttribute(parent)) {
1378
+ return true;
1379
+ }
1380
+ if (isClassLikeCallExpression(parent, current)) {
1381
+ return true;
1382
+ }
1383
+ current = parent;
1384
+ }
1385
+ return false;
1249
1386
  }
1250
1387
 
1251
1388
  // src/js/handlers.ts
1389
+ var debug2 = createDebug("[js:handlers] ");
1252
1390
  var patternCache = /* @__PURE__ */ new Map();
1253
1391
  var replacementCacheByEscapeMap = /* @__PURE__ */ new WeakMap();
1254
1392
  var defaultReplacementCache = /* @__PURE__ */ new Map();
@@ -1313,7 +1451,9 @@ function replaceHandleValue(path5, options) {
1313
1451
  needEscaped = false
1314
1452
  } = options;
1315
1453
  const { classNameSet, alwaysEscape } = options;
1316
- if (!alwaysEscape && (!classNameSet || classNameSet.size === 0)) {
1454
+ const fallbackEnabled = shouldEnableArbitraryValueFallback(options);
1455
+ const classContext = options.wrapExpression || isClassContextLiteralPath(path5);
1456
+ if (!alwaysEscape && !fallbackEnabled && (!classNameSet || classNameSet.size === 0)) {
1317
1457
  return void 0;
1318
1458
  }
1319
1459
  const { literal, original, allowDoubleQuotes, offset } = extractLiteralValue(path5, options);
@@ -1326,10 +1466,24 @@ function replaceHandleValue(path5, options) {
1326
1466
  }
1327
1467
  let transformed = literal;
1328
1468
  let mutated = false;
1469
+ let matchedCandidateCount = 0;
1470
+ let escapedDecisionCount = 0;
1471
+ let fallbackDecisionCount = 0;
1329
1472
  for (const candidate of candidates) {
1330
- if (!shouldTransformClassNameCandidate(candidate, options)) {
1473
+ const decision = resolveClassNameTransformDecision(candidate, {
1474
+ ...options,
1475
+ classContext
1476
+ });
1477
+ if (decision === "skip") {
1331
1478
  continue;
1332
1479
  }
1480
+ matchedCandidateCount += 1;
1481
+ if (decision === "escaped") {
1482
+ escapedDecisionCount += 1;
1483
+ }
1484
+ if (decision === "fallback") {
1485
+ fallbackDecisionCount += 1;
1486
+ }
1333
1487
  if (!transformed.includes(candidate)) {
1334
1488
  continue;
1335
1489
  }
@@ -1345,6 +1499,16 @@ function replaceHandleValue(path5, options) {
1345
1499
  if (!mutated || typeof node.start !== "number" || typeof node.end !== "number") {
1346
1500
  return void 0;
1347
1501
  }
1502
+ if (debug2.enabled) {
1503
+ debug2(
1504
+ "runtimeSet size=%d fallbackTriggered=%s matchedCandidates=%d escapedHits=%d file=%s",
1505
+ classNameSet?.size ?? 0,
1506
+ fallbackDecisionCount > 0,
1507
+ matchedCandidateCount,
1508
+ escapedDecisionCount,
1509
+ options.filename ?? "unknown"
1510
+ );
1511
+ }
1348
1512
  const start = node.start + offset;
1349
1513
  const end = node.end - offset;
1350
1514
  if (start >= end || transformed === original) {
@@ -2394,6 +2558,8 @@ function createJsHandler(options) {
2394
2558
  arbitraryValues,
2395
2559
  escapeMap,
2396
2560
  staleClassNameFallback,
2561
+ jsArbitraryValueFallback,
2562
+ tailwindcssMajorVersion,
2397
2563
  jsPreserveClass,
2398
2564
  generateMap,
2399
2565
  needEscaped,
@@ -2416,6 +2582,8 @@ function createJsHandler(options) {
2416
2582
  classNameSet,
2417
2583
  escapeMap,
2418
2584
  staleClassNameFallback,
2585
+ jsArbitraryValueFallback,
2586
+ tailwindcssMajorVersion,
2419
2587
  arbitraryValues,
2420
2588
  jsPreserveClass,
2421
2589
  generateMap,
@@ -2879,7 +3047,7 @@ function resolveRuntimePackageReplacements(option) {
2879
3047
  }
2880
3048
  return Object.keys(normalized).length > 0 ? normalized : void 0;
2881
3049
  }
2882
- function createHandlersFromContext(ctx, customAttributesEntities, cssCalcOptions) {
3050
+ function createHandlersFromContext(ctx, customAttributesEntities, cssCalcOptions, tailwindcssMajorVersion) {
2883
3051
  const {
2884
3052
  cssPreflight,
2885
3053
  cssPreflightRange,
@@ -2898,6 +3066,7 @@ function createHandlersFromContext(ctx, customAttributesEntities, cssCalcOptions
2898
3066
  arbitraryValues,
2899
3067
  jsPreserveClass,
2900
3068
  staleClassNameFallback,
3069
+ jsArbitraryValueFallback,
2901
3070
  babelParserOptions,
2902
3071
  ignoreCallExpressionIdentifiers,
2903
3072
  ignoreTaggedTemplateExpressionIdentifiers,
@@ -2928,6 +3097,8 @@ function createHandlersFromContext(ctx, customAttributesEntities, cssCalcOptions
2928
3097
  arbitraryValues,
2929
3098
  jsPreserveClass,
2930
3099
  staleClassNameFallback,
3100
+ jsArbitraryValueFallback: jsArbitraryValueFallback ?? "auto",
3101
+ tailwindcssMajorVersion,
2931
3102
  generateMap: true,
2932
3103
  babelParserOptions,
2933
3104
  ignoreCallExpressionIdentifiers,
@@ -3029,7 +3200,8 @@ function createInternalCompilerContext(opts) {
3029
3200
  const { styleHandler, jsHandler: jsHandler2, templateHandler } = createHandlersFromContext(
3030
3201
  ctx,
3031
3202
  customAttributesEntities,
3032
- cssCalcOptions
3203
+ cssCalcOptions,
3204
+ twPatcher.majorVersion
3033
3205
  );
3034
3206
  ctx.styleHandler = styleHandler;
3035
3207
  ctx.jsHandler = jsHandler2;
@@ -3,13 +3,13 @@ import {
3
3
  } from "./chunk-RRHPTTCP.mjs";
4
4
  import {
5
5
  setupPatchRecorder
6
- } from "./chunk-4QCL7FBX.mjs";
6
+ } from "./chunk-BZCCVPSU.mjs";
7
7
  import {
8
8
  createDebug,
9
9
  ensureRuntimeClassSet,
10
10
  getCompilerContext,
11
11
  refreshTailwindRuntimeState
12
- } from "./chunk-RXM5ERRJ.mjs";
12
+ } from "./chunk-MPVAZKRB.mjs";
13
13
 
14
14
  // src/bundlers/gulp/index.ts
15
15
  import { Buffer } from "buffer";
@@ -164,6 +164,7 @@ function createPlugins(options = {}) {
164
164
  ...options2,
165
165
  filename,
166
166
  moduleGraph,
167
+ tailwindcssMajorVersion: runtimeState.twPatcher.majorVersion,
167
168
  babelParserOptions: {
168
169
  ...options2?.babelParserOptions ?? {},
169
170
  sourceFilename: filename
@@ -3,13 +3,13 @@
3
3
  var _chunkLTJQUORKjs = require('./chunk-LTJQUORK.js');
4
4
 
5
5
 
6
- var _chunkRB7YN5XZjs = require('./chunk-RB7YN5XZ.js');
6
+ var _chunkM2ATX5ZSjs = require('./chunk-M2ATX5ZS.js');
7
7
 
8
8
 
9
9
 
10
10
 
11
11
 
12
- var _chunk7K3R5LV6js = require('./chunk-7K3R5LV6.js');
12
+ var _chunkI35XJD75js = require('./chunk-I35XJD75.js');
13
13
 
14
14
  // src/bundlers/gulp/index.ts
15
15
  var _buffer = require('buffer');
@@ -17,12 +17,12 @@ var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
17
17
  var _path = require('path'); var _path2 = _interopRequireDefault(_path);
18
18
  var _process = require('process'); var _process2 = _interopRequireDefault(_process);
19
19
  var _stream = require('stream'); var _stream2 = _interopRequireDefault(_stream);
20
- var debug = _chunk7K3R5LV6js.createDebug.call(void 0, );
20
+ var debug = _chunkI35XJD75js.createDebug.call(void 0, );
21
21
  var Transform = _stream2.default.Transform;
22
22
  function createPlugins(options = {}) {
23
- const opts = _chunk7K3R5LV6js.getCompilerContext.call(void 0, options);
23
+ const opts = _chunkI35XJD75js.getCompilerContext.call(void 0, options);
24
24
  const { templateHandler, styleHandler, jsHandler, cache, twPatcher: initialTwPatcher, refreshTailwindcssPatcher } = opts;
25
- const patchRecorderState = _chunkRB7YN5XZjs.setupPatchRecorder.call(void 0, initialTwPatcher, opts.tailwindcssBasedir, {
25
+ const patchRecorderState = _chunkM2ATX5ZSjs.setupPatchRecorder.call(void 0, initialTwPatcher, opts.tailwindcssBasedir, {
26
26
  source: "runtime",
27
27
  cwd: _nullishCoalesce(opts.tailwindcssBasedir, () => ( _process2.default.cwd()))
28
28
  });
@@ -36,13 +36,13 @@ function createPlugins(options = {}) {
36
36
  const MODULE_EXTENSIONS = [".js", ".mjs", ".cjs", ".ts", ".tsx", ".jsx"];
37
37
  let runtimeSetInitialized = false;
38
38
  async function refreshRuntimeState(force) {
39
- await _chunk7K3R5LV6js.refreshTailwindRuntimeState.call(void 0, runtimeState, force);
39
+ await _chunkI35XJD75js.refreshTailwindRuntimeState.call(void 0, runtimeState, force);
40
40
  }
41
41
  async function refreshRuntimeSet(force = false) {
42
42
  if (!force && runtimeSetInitialized) {
43
43
  return runtimeSet;
44
44
  }
45
- runtimeSet = await _chunk7K3R5LV6js.ensureRuntimeClassSet.call(void 0, runtimeState, {
45
+ runtimeSet = await _chunkI35XJD75js.ensureRuntimeClassSet.call(void 0, runtimeState, {
46
46
  forceRefresh: force,
47
47
  forceCollect: force,
48
48
  clearCache: force,
@@ -164,6 +164,7 @@ function createPlugins(options = {}) {
164
164
  ...options2,
165
165
  filename,
166
166
  moduleGraph,
167
+ tailwindcssMajorVersion: runtimeState.twPatcher.majorVersion,
167
168
  babelParserOptions: {
168
169
  ..._nullishCoalesce(_optionalChain([options2, 'optionalAccess', _ => _.babelParserOptions]), () => ( {})),
169
170
  sourceFilename: filename
@@ -12,7 +12,7 @@ import {
12
12
  } from "./chunk-RRHPTTCP.mjs";
13
13
  import {
14
14
  setupPatchRecorder
15
- } from "./chunk-4QCL7FBX.mjs";
15
+ } from "./chunk-BZCCVPSU.mjs";
16
16
  import {
17
17
  collectRuntimeClassSet,
18
18
  createAttributeMatcher,
@@ -24,12 +24,13 @@ import {
24
24
  replaceWxml,
25
25
  toCustomAttributesEntities,
26
26
  vitePluginName
27
- } from "./chunk-RXM5ERRJ.mjs";
27
+ } from "./chunk-MPVAZKRB.mjs";
28
28
  import {
29
29
  resolveUniUtsPlatform
30
30
  } from "./chunk-OOHJLO5M.mjs";
31
31
 
32
32
  // src/bundlers/vite/index.ts
33
+ import path3 from "path";
33
34
  import process3 from "process";
34
35
  import postcssHtmlTransform from "@weapp-tailwindcss/postcss/html-transform";
35
36
 
@@ -756,6 +757,7 @@ function createGenerateBundleHook(context) {
756
757
  const createHandlerOptions = (absoluteFilename, extra) => ({
757
758
  ...extra,
758
759
  filename: absoluteFilename,
760
+ tailwindcssMajorVersion: runtimeState.twPatcher.majorVersion,
759
761
  moduleGraph: moduleGraphOptions,
760
762
  babelParserOptions: {
761
763
  ...extra?.babelParserOptions ?? {},
@@ -1082,6 +1084,7 @@ var weappTailwindcssPackageDir = resolvePackageDir("weapp-tailwindcss");
1082
1084
  var weappTailwindcssDirPosix = slash(weappTailwindcssPackageDir);
1083
1085
  function UnifiedViteWeappTailwindcssPlugin(options = {}) {
1084
1086
  const rewriteCssImportsSpecified = Object.prototype.hasOwnProperty.call(options, "rewriteCssImports");
1087
+ const hasExplicitTailwindcssBasedir = typeof options.tailwindcssBasedir === "string" && options.tailwindcssBasedir.trim().length > 0;
1085
1088
  const opts = getCompilerContext(options);
1086
1089
  const {
1087
1090
  disabled,
@@ -1205,8 +1208,15 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
1205
1208
  {
1206
1209
  name: `${vitePluginName}:post`,
1207
1210
  enforce: "post",
1208
- configResolved(config) {
1211
+ async configResolved(config) {
1209
1212
  resolvedConfig = config;
1213
+ const resolvedRoot = config.root ? path3.resolve(config.root) : void 0;
1214
+ if (!hasExplicitTailwindcssBasedir && resolvedRoot && opts.tailwindcssBasedir !== resolvedRoot) {
1215
+ const previousBasedir = opts.tailwindcssBasedir;
1216
+ opts.tailwindcssBasedir = resolvedRoot;
1217
+ debug("align tailwindcss basedir with vite root: %s -> %s", previousBasedir ?? "undefined", resolvedRoot);
1218
+ await refreshRuntimeState(true);
1219
+ }
1210
1220
  if (typeof config.css.postcss === "object" && Array.isArray(config.css.postcss.plugins)) {
1211
1221
  const idx = config.css.postcss.plugins.findIndex((x) => (
1212
1222
  // @ts-ignore
package/dist/cli.js CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
 
5
5
 
6
- var _chunk7K3R5LV6js = require('./chunk-7K3R5LV6.js');
6
+ var _chunkI35XJD75js = require('./chunk-I35XJD75.js');
7
7
 
8
8
 
9
9
 
@@ -404,9 +404,9 @@ async function patchWorkspacePackage(workspaceRoot, dir, pkgName, options) {
404
404
  try {
405
405
  const patcher = createWorkspacePatcher(dir);
406
406
  if (options.clearCache) {
407
- await _chunk7K3R5LV6js.clearTailwindcssPatcherCache.call(void 0, patcher, { removeDirectory: true });
407
+ await _chunkI35XJD75js.clearTailwindcssPatcherCache.call(void 0, patcher, { removeDirectory: true });
408
408
  }
409
- const recorder = _chunk7K3R5LV6js.createPatchTargetRecorder.call(void 0, dir, patcher, {
409
+ const recorder = _chunkI35XJD75js.createPatchTargetRecorder.call(void 0, dir, patcher, {
410
410
  source: "cli",
411
411
  cwd: dir,
412
412
  recordTarget: options.recordTarget !== false,
@@ -415,7 +415,7 @@ async function patchWorkspacePackage(workspaceRoot, dir, pkgName, options) {
415
415
  if (_optionalChain([recorder, 'optionalAccess', _12 => _12.message])) {
416
416
  _chunk5APD2MNVjs.logger.info("[workspace] %s %s", displayName, recorder.message);
417
417
  }
418
- _chunk7K3R5LV6js.logTailwindcssTarget.call(void 0, "cli", patcher, dir);
418
+ _chunkI35XJD75js.logTailwindcssTarget.call(void 0, "cli", patcher, dir);
419
419
  await patcher.patch();
420
420
  if (_optionalChain([recorder, 'optionalAccess', _13 => _13.onPatched])) {
421
421
  await recorder.onPatched();
@@ -546,9 +546,9 @@ var mountOptions = {
546
546
  }
547
547
  const patcher = await createPatcherWithDefaultExtendLengthUnits(ctx);
548
548
  if (shouldClearCache) {
549
- await _chunk7K3R5LV6js.clearTailwindcssPatcherCache.call(void 0, patcher, { removeDirectory: true });
549
+ await _chunkI35XJD75js.clearTailwindcssPatcherCache.call(void 0, patcher, { removeDirectory: true });
550
550
  }
551
- const recorder = _chunk7K3R5LV6js.createPatchTargetRecorder.call(void 0, ctx.cwd, patcher, {
551
+ const recorder = _chunkI35XJD75js.createPatchTargetRecorder.call(void 0, ctx.cwd, patcher, {
552
552
  source: "cli",
553
553
  cwd: ctx.cwd,
554
554
  recordTarget: shouldRecordTarget,
@@ -557,7 +557,7 @@ var mountOptions = {
557
557
  if (_optionalChain([recorder, 'optionalAccess', _15 => _15.message])) {
558
558
  _chunk5APD2MNVjs.logger.info(recorder.message);
559
559
  }
560
- _chunk7K3R5LV6js.logTailwindcssTarget.call(void 0, "cli", patcher, ctx.cwd);
560
+ _chunkI35XJD75js.logTailwindcssTarget.call(void 0, "cli", patcher, ctx.cwd);
561
561
  await patcher.patch();
562
562
  if (_optionalChain([recorder, 'optionalAccess', _16 => _16.onPatched])) {
563
563
  const recordPath = await recorder.onPatched();
@@ -705,9 +705,9 @@ async function generateVscodeIntellisenseEntry(options) {
705
705
 
706
706
  // src/cli.ts
707
707
  _process2.default.title = "node (weapp-tailwindcss)";
708
- if (_semver2.default.lt(_process2.default.versions.node, _chunk7K3R5LV6js.WEAPP_TW_REQUIRED_NODE_VERSION)) {
708
+ if (_semver2.default.lt(_process2.default.versions.node, _chunkI35XJD75js.WEAPP_TW_REQUIRED_NODE_VERSION)) {
709
709
  _chunk5APD2MNVjs.logger.warn(
710
- `You are using Node.js ${_process2.default.versions.node}. For weapp-tailwindcss, Node.js version >= v${_chunk7K3R5LV6js.WEAPP_TW_REQUIRED_NODE_VERSION} is required.`
710
+ `You are using Node.js ${_process2.default.versions.node}. For weapp-tailwindcss, Node.js version >= v${_chunkI35XJD75js.WEAPP_TW_REQUIRED_NODE_VERSION} is required.`
711
711
  );
712
712
  }
713
713
  var cli = _tailwindcsspatch.createTailwindcssPatchCli.call(void 0, {
package/dist/cli.mjs CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  clearTailwindcssPatcherCache,
4
4
  createPatchTargetRecorder,
5
5
  logTailwindcssTarget
6
- } from "./chunk-RXM5ERRJ.mjs";
6
+ } from "./chunk-MPVAZKRB.mjs";
7
7
  import {
8
8
  findWorkspaceRoot,
9
9
  logger
package/dist/core.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ITemplateHandlerOptions, CreateJsHandlerOptions, JsHandlerResult } from './types.mjs';
2
2
  import * as postcss from 'postcss';
3
- import { U as UserDefinedOptions } from './index-BESv5MWf.mjs';
3
+ import { U as UserDefinedOptions } from './index-t_VBjwYm.mjs';
4
4
  import { IStyleHandlerOptions } from '@weapp-tailwindcss/postcss';
5
5
  import '@babel/parser';
6
6
  import 'magic-string';
package/dist/core.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ITemplateHandlerOptions, CreateJsHandlerOptions, JsHandlerResult } from './types.js';
2
2
  import * as postcss from 'postcss';
3
- import { U as UserDefinedOptions } from './index-BESv5MWf.js';
3
+ import { U as UserDefinedOptions } from './index-t_VBjwYm.js';
4
4
  import { IStyleHandlerOptions } from '@weapp-tailwindcss/postcss';
5
5
  import '@babel/parser';
6
6
  import 'magic-string';
package/dist/core.js CHANGED
@@ -1,10 +1,10 @@
1
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; }
2
2
 
3
- var _chunkRB7YN5XZjs = require('./chunk-RB7YN5XZ.js');
3
+ var _chunkM2ATX5ZSjs = require('./chunk-M2ATX5ZS.js');
4
4
 
5
5
 
6
6
 
7
- var _chunk7K3R5LV6js = require('./chunk-7K3R5LV6.js');
7
+ var _chunkI35XJD75js = require('./chunk-I35XJD75.js');
8
8
  require('./chunk-5APD2MNV.js');
9
9
  require('./chunk-5U24PLVV.js');
10
10
  require('./chunk-DYLQ6UOI.js');
@@ -14,9 +14,9 @@ require('./chunk-DBAAU4LK.js');
14
14
  var _process = require('process'); var _process2 = _interopRequireDefault(_process);
15
15
  var _shared = require('@weapp-tailwindcss/shared');
16
16
  function createContext(options = {}) {
17
- const opts = _chunk7K3R5LV6js.getCompilerContext.call(void 0, options);
17
+ const opts = _chunkI35XJD75js.getCompilerContext.call(void 0, options);
18
18
  const { templateHandler, styleHandler, jsHandler, twPatcher: initialTwPatcher, refreshTailwindcssPatcher } = opts;
19
- const patchRecorderState = _chunkRB7YN5XZjs.setupPatchRecorder.call(void 0, initialTwPatcher, opts.tailwindcssBasedir, {
19
+ const patchRecorderState = _chunkM2ATX5ZSjs.setupPatchRecorder.call(void 0, initialTwPatcher, opts.tailwindcssBasedir, {
20
20
  source: "runtime",
21
21
  cwd: _nullishCoalesce(opts.tailwindcssBasedir, () => ( _process2.default.cwd()))
22
22
  });
@@ -27,12 +27,25 @@ function createContext(options = {}) {
27
27
  refreshTailwindcssPatcher,
28
28
  onPatchCompleted: patchRecorderState.onPatchCompleted
29
29
  };
30
+ function withRuntimeTailwindMajorVersion(options2) {
31
+ const resolvedOptions = {
32
+ ..._nullishCoalesce(options2, () => ( {}))
33
+ };
34
+ if (typeof resolvedOptions.tailwindcssMajorVersion === "number") {
35
+ return resolvedOptions;
36
+ }
37
+ const majorVersion = runtimeState.twPatcher.majorVersion;
38
+ if (typeof majorVersion === "number") {
39
+ resolvedOptions.tailwindcssMajorVersion = majorVersion;
40
+ }
41
+ return resolvedOptions;
42
+ }
30
43
  async function transformWxss(rawCss, options2) {
31
44
  await runtimeState.patchPromise;
32
45
  const result = await styleHandler(rawCss, _shared.defuOverrideArray.call(void 0, options2, {
33
46
  isMainChunk: true
34
47
  }));
35
- runtimeSet = await _chunk7K3R5LV6js.ensureRuntimeClassSet.call(void 0, runtimeState, {
48
+ runtimeSet = await _chunkI35XJD75js.ensureRuntimeClassSet.call(void 0, runtimeState, {
36
49
  forceRefresh: true,
37
50
  forceCollect: true
38
51
  });
@@ -43,16 +56,16 @@ function createContext(options = {}) {
43
56
  if (_optionalChain([options2, 'optionalAccess', _ => _.runtimeSet])) {
44
57
  runtimeSet = options2.runtimeSet;
45
58
  } else if (runtimeSet.size === 0) {
46
- runtimeSet = await _chunk7K3R5LV6js.ensureRuntimeClassSet.call(void 0, runtimeState, {
59
+ runtimeSet = await _chunkI35XJD75js.ensureRuntimeClassSet.call(void 0, runtimeState, {
47
60
  forceCollect: true
48
61
  });
49
62
  }
50
- return await jsHandler(rawJs, runtimeSet, options2);
63
+ return await jsHandler(rawJs, runtimeSet, withRuntimeTailwindMajorVersion(options2));
51
64
  }
52
65
  async function transformWxml(rawWxml, options2) {
53
66
  await runtimeState.patchPromise;
54
67
  if (!_optionalChain([options2, 'optionalAccess', _2 => _2.runtimeSet]) && runtimeSet.size === 0) {
55
- runtimeSet = await _chunk7K3R5LV6js.ensureRuntimeClassSet.call(void 0, runtimeState, {
68
+ runtimeSet = await _chunkI35XJD75js.ensureRuntimeClassSet.call(void 0, runtimeState, {
56
69
  forceCollect: true
57
70
  });
58
71
  }
@@ -60,7 +73,7 @@ function createContext(options = {}) {
60
73
  return templateHandler(rawWxml, _shared.defuOverrideArray.call(void 0, options2, {
61
74
  runtimeSet,
62
75
  jsHandler: (source, runtime, handlerOptions) => {
63
- return runtimeJsHandler(source, runtime, handlerOptions);
76
+ return runtimeJsHandler(source, runtime, withRuntimeTailwindMajorVersion(handlerOptions));
64
77
  }
65
78
  }));
66
79
  }