weapp-tailwindcss 4.8.4 → 4.8.5-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 (50) hide show
  1. package/dist/{chunk-7KTLLGAG.mjs → chunk-3XGTIDA6.mjs} +72 -49
  2. package/dist/{chunk-6EATUPTN.js → chunk-5KVCFUCR.js} +27 -20
  3. package/dist/{chunk-JMYADIPN.mjs → chunk-67CD2S5L.mjs} +1 -1
  4. package/dist/{chunk-K234IGOT.js → chunk-AB45L5FP.js} +2 -2
  5. package/dist/{chunk-IHJU6M6B.mjs → chunk-E4WMGIBB.mjs} +13 -6
  6. package/dist/{chunk-KSHK56CW.mjs → chunk-EQP3XJUM.mjs} +1 -1
  7. package/dist/chunk-GBKTM7HE.mjs +29 -0
  8. package/dist/{chunk-NLLCK6RM.mjs → chunk-NE4IF47K.mjs} +11 -4
  9. package/dist/{chunk-UUVGNRUM.mjs → chunk-NMUFIIAM.mjs} +36 -23
  10. package/dist/{chunk-MG4O3AGN.js → chunk-OQGFV6TW.js} +14 -7
  11. package/dist/{chunk-47NJZTIW.js → chunk-OR5KGJ46.js} +5 -5
  12. package/dist/{chunk-5P342MNS.js → chunk-QZ5JL3U3.js} +52 -39
  13. package/dist/chunk-R6ERGDBQ.js +29 -0
  14. package/dist/{chunk-ZXU4EYKV.js → chunk-RJRLVYVJ.js} +77 -54
  15. package/dist/{chunk-WTOLVORM.mjs → chunk-T25LQFYZ.mjs} +389 -52
  16. package/dist/{chunk-WGLBMNPG.js → chunk-UTZLVU3M.js} +1 -1
  17. package/dist/{chunk-AXEKXGG7.js → chunk-YKMZHWQ4.js} +427 -90
  18. package/dist/cli.js +217 -20
  19. package/dist/cli.mjs +215 -18
  20. package/dist/core.js +19 -11
  21. package/dist/core.mjs +14 -6
  22. package/dist/css-macro/postcss.js +1 -1
  23. package/dist/css-macro/postcss.mjs +1 -1
  24. package/dist/css-macro.js +1 -1
  25. package/dist/css-macro.mjs +1 -1
  26. package/dist/defaults.js +1 -1
  27. package/dist/defaults.mjs +1 -1
  28. package/dist/gulp.js +6 -5
  29. package/dist/gulp.mjs +5 -4
  30. package/dist/index.js +10 -9
  31. package/dist/index.mjs +8 -7
  32. package/dist/postcss-html-transform.js +1 -1
  33. package/dist/postcss-html-transform.mjs +1 -1
  34. package/dist/presets.js +4 -6
  35. package/dist/presets.mjs +3 -5
  36. package/dist/reset.d.mts +30 -0
  37. package/dist/reset.d.ts +32 -0
  38. package/dist/reset.js +161 -0
  39. package/dist/reset.mjs +161 -0
  40. package/dist/types.js +1 -1
  41. package/dist/types.mjs +1 -1
  42. package/dist/vite.js +7 -6
  43. package/dist/vite.mjs +5 -4
  44. package/dist/webpack.js +8 -7
  45. package/dist/webpack.mjs +6 -5
  46. package/dist/webpack4.js +29 -22
  47. package/dist/webpack4.mjs +14 -7
  48. package/package.json +11 -4
  49. package/dist/chunk-OXASK55Q.js +0 -6
  50. package/dist/chunk-PMF2CCKK.mjs +0 -6
package/dist/cli.js CHANGED
@@ -1,16 +1,17 @@
1
1
  "use strict"; 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 _chunkOXASK55Qjs = require('./chunk-OXASK55Q.js');
4
3
 
5
4
 
6
5
 
6
+ var _chunkYKMZHWQ4js = require('./chunk-YKMZHWQ4.js');
7
7
 
8
8
 
9
- var _chunkAXEKXGG7js = require('./chunk-AXEKXGG7.js');
10
- require('./chunk-ZXU4EYKV.js');
9
+
10
+
11
+ var _chunkRJRLVYVJjs = require('./chunk-RJRLVYVJ.js');
11
12
  require('./chunk-ZSTF2AEN.js');
12
13
  require('./chunk-UW3WHSZ5.js');
13
- require('./chunk-WGLBMNPG.js');
14
+ require('./chunk-UTZLVU3M.js');
14
15
 
15
16
  // src/cli.ts
16
17
  var _process = require('process'); var _process2 = _interopRequireDefault(_process);
@@ -98,12 +99,12 @@ async function ensureDir(dir) {
98
99
  }
99
100
  function handleCliError(error) {
100
101
  if (error instanceof Error) {
101
- _chunkOXASK55Qjs.logger.error(error.message);
102
+ _chunkRJRLVYVJjs.logger.error(error.message);
102
103
  if (error.stack && _process2.default.env.WEAPP_TW_DEBUG === "1") {
103
- _chunkOXASK55Qjs.logger.error(error.stack);
104
+ _chunkRJRLVYVJjs.logger.error(error.stack);
104
105
  }
105
106
  } else {
106
- _chunkOXASK55Qjs.logger.error(String(error));
107
+ _chunkRJRLVYVJjs.logger.error(String(error));
107
108
  }
108
109
  }
109
110
  function commandAction(handler) {
@@ -237,15 +238,189 @@ async function generateVscodeIntellisenseEntry(options) {
237
238
  return { outputPath, cssEntryPath };
238
239
  }
239
240
 
241
+ // src/cli/workspace.ts
242
+
243
+
244
+
245
+ var _fastglob = require('fast-glob'); var _fastglob2 = _interopRequireDefault(_fastglob);
246
+
247
+ var _yaml = require('yaml');
248
+ function tryReadJson(file) {
249
+ try {
250
+ const content = _fs.readFileSync.call(void 0, file, "utf8");
251
+ return JSON.parse(content);
252
+ } catch (e) {
253
+ return void 0;
254
+ }
255
+ }
256
+ function parseWorkspaceGlobsFromPackageJson(workspaceRoot) {
257
+ const pkgJsonPath = _path2.default.join(workspaceRoot, "package.json");
258
+ const pkg = tryReadJson(pkgJsonPath);
259
+ if (!_optionalChain([pkg, 'optionalAccess', _3 => _3.workspaces])) {
260
+ return [];
261
+ }
262
+ if (Array.isArray(pkg.workspaces)) {
263
+ return pkg.workspaces.filter(Boolean);
264
+ }
265
+ if (Array.isArray(pkg.workspaces.packages)) {
266
+ return pkg.workspaces.packages.filter(Boolean);
267
+ }
268
+ return [];
269
+ }
270
+ function parseWorkspaceGlobsFromWorkspaceFile(workspaceRoot) {
271
+ const workspaceFile = _path2.default.join(workspaceRoot, "pnpm-workspace.yaml");
272
+ if (!_fs.existsSync.call(void 0, workspaceFile)) {
273
+ return [];
274
+ }
275
+ try {
276
+ const parsed = _yaml.parse.call(void 0, _fs.readFileSync.call(void 0, workspaceFile, "utf8"));
277
+ return Array.isArray(_optionalChain([parsed, 'optionalAccess', _4 => _4.packages])) ? parsed.packages.filter(Boolean) : [];
278
+ } catch (e2) {
279
+ return [];
280
+ }
281
+ }
282
+ function parseImportersFromLock(workspaceRoot) {
283
+ const lockPath = _path2.default.join(workspaceRoot, "pnpm-lock.yaml");
284
+ if (!_fs.existsSync.call(void 0, lockPath)) {
285
+ return [];
286
+ }
287
+ try {
288
+ const parsed = _yaml.parse.call(void 0, _fs.readFileSync.call(void 0, lockPath, "utf8"));
289
+ const importers = _optionalChain([parsed, 'optionalAccess', _5 => _5.importers]);
290
+ if (!importers) {
291
+ return [];
292
+ }
293
+ return Object.keys(importers).map((key) => {
294
+ if (!key || key === ".") {
295
+ return workspaceRoot;
296
+ }
297
+ return _path2.default.join(workspaceRoot, key);
298
+ });
299
+ } catch (e3) {
300
+ return [];
301
+ }
302
+ }
303
+ async function resolveWorkspacePackageDirs(workspaceRoot) {
304
+ const dirs = /* @__PURE__ */ new Set();
305
+ for (const importerDir of parseImportersFromLock(workspaceRoot)) {
306
+ dirs.add(_path2.default.normalize(importerDir));
307
+ }
308
+ if (!dirs.size) {
309
+ let globs = parseWorkspaceGlobsFromWorkspaceFile(workspaceRoot);
310
+ if (!globs.length) {
311
+ globs = parseWorkspaceGlobsFromPackageJson(workspaceRoot);
312
+ }
313
+ if (globs.length > 0) {
314
+ const patterns = globs.map((pattern) => {
315
+ const normalized = pattern.replace(/\\/g, "/").replace(/\/+$/, "");
316
+ return normalized.endsWith("package.json") ? normalized : `${normalized}/package.json`;
317
+ });
318
+ const packageJsonFiles = await _fastglob2.default.call(void 0, patterns, {
319
+ cwd: workspaceRoot,
320
+ absolute: true,
321
+ onlyFiles: true,
322
+ unique: true,
323
+ ignore: ["**/node_modules/**", "**/.git/**"]
324
+ });
325
+ for (const file of packageJsonFiles) {
326
+ dirs.add(_path2.default.normalize(_path2.default.dirname(file)));
327
+ }
328
+ }
329
+ }
330
+ const rootPkg = _path2.default.join(workspaceRoot, "package.json");
331
+ if (_fs.existsSync.call(void 0, rootPkg)) {
332
+ dirs.add(_path2.default.normalize(workspaceRoot));
333
+ }
334
+ return [...dirs];
335
+ }
336
+ function createWorkspacePatcher(cwd) {
337
+ const normalized = _tailwindcsspatch.normalizeOptions.call(void 0, {
338
+ cwd
339
+ });
340
+ return new (0, _tailwindcsspatch.TailwindcssPatcher)(normalized);
341
+ }
342
+ function formatDisplayName(workspaceRoot, dir, name) {
343
+ const relative = _path2.default.relative(workspaceRoot, dir) || ".";
344
+ return name ? `${name} (${relative})` : relative;
345
+ }
346
+ async function patchWorkspace(options) {
347
+ const cwd = _nullishCoalesce(options.cwd, () => ( _process2.default.cwd()));
348
+ const workspaceRoot = _nullishCoalesce(_chunkRJRLVYVJjs.findWorkspaceRoot.call(void 0, cwd), () => ( cwd));
349
+ const packageDirs = await resolveWorkspacePackageDirs(workspaceRoot);
350
+ if (packageDirs.length === 0) {
351
+ _chunkRJRLVYVJjs.logger.warn("\u672A\u5728 %s \u68C0\u6D4B\u5230 workspace \u5305\uFF0C\u5DF2\u8DF3\u8FC7\u6279\u91CF patch\u3002", workspaceRoot);
352
+ return;
353
+ }
354
+ const results = [];
355
+ for (const dir of packageDirs) {
356
+ const pkgJsonPath = _path2.default.join(dir, "package.json");
357
+ const pkgJson = tryReadJson(pkgJsonPath);
358
+ const displayName = formatDisplayName(workspaceRoot, dir, _optionalChain([pkgJson, 'optionalAccess', _6 => _6.name]));
359
+ const tailwindInfo = _chunkRJRLVYVJjs.getTailwindcssPackageInfo.call(void 0, { paths: [dir] });
360
+ if (!_optionalChain([tailwindInfo, 'optionalAccess', _7 => _7.rootPath])) {
361
+ results.push({
362
+ dir,
363
+ name: _optionalChain([pkgJson, 'optionalAccess', _8 => _8.name]),
364
+ status: "skipped",
365
+ message: "tailwindcss \u672A\u5B89\u88C5\uFF0C\u5DF2\u8DF3\u8FC7\u3002"
366
+ });
367
+ _chunkRJRLVYVJjs.logger.info("[workspace] \u8DF3\u8FC7 %s\uFF08tailwindcss \u672A\u5B89\u88C5\uFF09\u3002", displayName);
368
+ continue;
369
+ }
370
+ try {
371
+ const patcher = createWorkspacePatcher(dir);
372
+ if (options.clearCache) {
373
+ await _chunkYKMZHWQ4js.clearTailwindcssPatcherCache.call(void 0, patcher, { removeDirectory: true });
374
+ }
375
+ const recorder = _chunkYKMZHWQ4js.createPatchTargetRecorder.call(void 0, dir, patcher, {
376
+ source: "cli",
377
+ cwd: dir,
378
+ recordTarget: options.recordTarget !== false,
379
+ alwaysRecord: true
380
+ });
381
+ if (_optionalChain([recorder, 'optionalAccess', _9 => _9.message])) {
382
+ _chunkRJRLVYVJjs.logger.info("[workspace] %s %s", displayName, recorder.message);
383
+ }
384
+ _chunkYKMZHWQ4js.logTailwindcssTarget.call(void 0, "cli", patcher, dir);
385
+ await patcher.patch();
386
+ if (_optionalChain([recorder, 'optionalAccess', _10 => _10.onPatched])) {
387
+ await recorder.onPatched();
388
+ }
389
+ results.push({
390
+ dir,
391
+ name: _optionalChain([pkgJson, 'optionalAccess', _11 => _11.name]),
392
+ status: "patched",
393
+ message: "\u5DF2\u5B8C\u6210 patch\u3002"
394
+ });
395
+ _chunkRJRLVYVJjs.logger.success("[workspace] \u5DF2\u8865\u4E01 %s", displayName);
396
+ } catch (error) {
397
+ const reason = error instanceof Error ? error.message : String(error);
398
+ const suggestion = `\u8BF7\u5728 ${dir} \u8FD0\u884C "weapp-tw patch --cwd ${dir}".`;
399
+ const message = `${reason}\uFF0C${suggestion}`;
400
+ results.push({
401
+ dir,
402
+ name: _optionalChain([pkgJson, 'optionalAccess', _12 => _12.name]),
403
+ status: "failed",
404
+ message
405
+ });
406
+ _chunkRJRLVYVJjs.logger.error("[workspace] \u8865\u4E01\u5931\u8D25 %s\uFF1A%s", displayName, message);
407
+ }
408
+ }
409
+ const patched = results.filter((result) => result.status === "patched").length;
410
+ const skipped = results.filter((result) => result.status === "skipped").length;
411
+ const failed = results.filter((result) => result.status === "failed").length;
412
+ _chunkRJRLVYVJjs.logger.info("[workspace] \u6C47\u603B\uFF1A\u5DF2\u8865\u4E01 %d\uFF0C\u8DF3\u8FC7 %d\uFF0C\u5931\u8D25 %d", patched, skipped, failed);
413
+ }
414
+
240
415
  // src/cli.ts
241
416
  function handleCliError2(error) {
242
417
  if (error instanceof Error) {
243
- _chunkOXASK55Qjs.logger.error(error.message);
418
+ _chunkRJRLVYVJjs.logger.error(error.message);
244
419
  if (error.stack && _process2.default.env.WEAPP_TW_DEBUG === "1") {
245
- _chunkOXASK55Qjs.logger.error(error.stack);
420
+ _chunkRJRLVYVJjs.logger.error(error.stack);
246
421
  }
247
422
  } else {
248
- _chunkOXASK55Qjs.logger.error(String(error));
423
+ _chunkRJRLVYVJjs.logger.error(String(error));
249
424
  }
250
425
  }
251
426
  function withCommandErrorHandling(handler) {
@@ -273,6 +448,10 @@ var mountOptions = {
273
448
  {
274
449
  flags: "--clear-cache",
275
450
  description: "Clear tailwindcss-patch cache before patch (opt-in)"
451
+ },
452
+ {
453
+ flags: "--workspace",
454
+ description: "Scan pnpm workspace packages and patch each Tailwind CSS dependency"
276
455
  }
277
456
  ]
278
457
  }
@@ -281,19 +460,37 @@ var mountOptions = {
281
460
  install: withCommandErrorHandling(async (ctx) => {
282
461
  const shouldClearCache = toBoolean(ctx.args.clearCache, false);
283
462
  const shouldRecordTarget = toBoolean(ctx.args.recordTarget, true);
463
+ const runWorkspace = toBoolean(ctx.args.workspace, false);
464
+ if (runWorkspace) {
465
+ await patchWorkspace({
466
+ cwd: ctx.cwd,
467
+ clearCache: shouldClearCache,
468
+ recordTarget: shouldRecordTarget
469
+ });
470
+ return;
471
+ }
284
472
  const patcher = await ctx.createPatcher();
285
473
  if (shouldClearCache) {
286
- await _chunkAXEKXGG7js.clearTailwindcssPatcherCache.call(void 0, patcher, { removeDirectory: true });
474
+ await _chunkYKMZHWQ4js.clearTailwindcssPatcherCache.call(void 0, patcher, { removeDirectory: true });
475
+ }
476
+ const recorder = _chunkYKMZHWQ4js.createPatchTargetRecorder.call(void 0, ctx.cwd, patcher, {
477
+ source: "cli",
478
+ cwd: ctx.cwd,
479
+ recordTarget: shouldRecordTarget,
480
+ alwaysRecord: true
481
+ });
482
+ if (_optionalChain([recorder, 'optionalAccess', _13 => _13.message])) {
483
+ _chunkRJRLVYVJjs.logger.info(recorder.message);
287
484
  }
288
- _chunkAXEKXGG7js.logTailwindcssTarget.call(void 0, "cli", patcher, ctx.cwd);
485
+ _chunkYKMZHWQ4js.logTailwindcssTarget.call(void 0, "cli", patcher, ctx.cwd);
289
486
  await patcher.patch();
290
- if (shouldRecordTarget) {
291
- const recordPath = await _chunkAXEKXGG7js.saveCliPatchTargetRecord.call(void 0, ctx.cwd, patcher);
487
+ if (_optionalChain([recorder, 'optionalAccess', _14 => _14.onPatched])) {
488
+ const recordPath = await recorder.onPatched();
292
489
  if (recordPath) {
293
- _chunkOXASK55Qjs.logger.info(`\u8BB0\u5F55 weapp-tw patch \u76EE\u6807 -> ${formatOutputPath(recordPath, ctx.cwd)}`);
490
+ _chunkRJRLVYVJjs.logger.info(`\u8BB0\u5F55 weapp-tw patch \u76EE\u6807 -> ${formatOutputPath(recordPath, ctx.cwd)}`);
294
491
  }
295
492
  }
296
- _chunkOXASK55Qjs.logger.success("Tailwind CSS \u8FD0\u884C\u65F6\u8865\u4E01\u5DF2\u5B8C\u6210\u3002");
493
+ _chunkRJRLVYVJjs.logger.success("Tailwind CSS \u8FD0\u884C\u65F6\u8865\u4E01\u5DF2\u5B8C\u6210\u3002");
297
494
  }),
298
495
  extract: withCommandErrorHandling(async (_ctx, next) => next()),
299
496
  tokens: withCommandErrorHandling(async (_ctx, next) => next()),
@@ -301,9 +498,9 @@ var mountOptions = {
301
498
  }
302
499
  };
303
500
  _process2.default.title = "node (weapp-tailwindcss)";
304
- if (_semver2.default.lt(_process2.default.versions.node, _chunkAXEKXGG7js.WEAPP_TW_REQUIRED_NODE_VERSION)) {
305
- _chunkOXASK55Qjs.logger.warn(
306
- `You are using Node.js ${_process2.default.versions.node}. For weapp-tailwindcss, Node.js version >= v${_chunkAXEKXGG7js.WEAPP_TW_REQUIRED_NODE_VERSION} is required.`
501
+ if (_semver2.default.lt(_process2.default.versions.node, _chunkYKMZHWQ4js.WEAPP_TW_REQUIRED_NODE_VERSION)) {
502
+ _chunkRJRLVYVJjs.logger.warn(
503
+ `You are using Node.js ${_process2.default.versions.node}. For weapp-tailwindcss, Node.js version >= v${_chunkYKMZHWQ4js.WEAPP_TW_REQUIRED_NODE_VERSION} is required.`
307
504
  );
308
505
  }
309
506
  var cli = _tailwindcsspatch.createTailwindcssPatchCli.call(void 0, {
@@ -328,7 +525,7 @@ cli.command("vscode-entry", "Generate a VS Code helper CSS for Tailwind IntelliS
328
525
  sources,
329
526
  force
330
527
  });
331
- _chunkOXASK55Qjs.logger.success(
528
+ _chunkRJRLVYVJjs.logger.success(
332
529
  `VS Code helper generated -> ${formatOutputPath(result.outputPath, resolvedCwd)}`
333
530
  );
334
531
  })
package/dist/cli.mjs CHANGED
@@ -1,19 +1,20 @@
1
- import {
2
- logger
3
- } from "./chunk-PMF2CCKK.mjs";
4
1
  import {
5
2
  WEAPP_TW_REQUIRED_NODE_VERSION,
6
3
  clearTailwindcssPatcherCache,
7
- logTailwindcssTarget,
8
- saveCliPatchTargetRecord
9
- } from "./chunk-WTOLVORM.mjs";
10
- import "./chunk-7KTLLGAG.mjs";
4
+ createPatchTargetRecorder,
5
+ logTailwindcssTarget
6
+ } from "./chunk-T25LQFYZ.mjs";
7
+ import {
8
+ findWorkspaceRoot,
9
+ getTailwindcssPackageInfo,
10
+ logger
11
+ } from "./chunk-3XGTIDA6.mjs";
11
12
  import "./chunk-DKPIYG24.mjs";
12
13
  import "./chunk-ZNKIYZRQ.mjs";
13
- import "./chunk-JMYADIPN.mjs";
14
+ import "./chunk-67CD2S5L.mjs";
14
15
 
15
16
  // src/cli.ts
16
- import process3 from "process";
17
+ import process4 from "process";
17
18
  import semver from "semver";
18
19
  import { createTailwindcssPatchCli } from "tailwindcss-patch";
19
20
 
@@ -237,11 +238,185 @@ async function generateVscodeIntellisenseEntry(options) {
237
238
  return { outputPath, cssEntryPath };
238
239
  }
239
240
 
241
+ // src/cli/workspace.ts
242
+ import { existsSync, readFileSync } from "fs";
243
+ import path4 from "path";
244
+ import process3 from "process";
245
+ import fg from "fast-glob";
246
+ import { normalizeOptions, TailwindcssPatcher } from "tailwindcss-patch";
247
+ import { parse as parseYaml } from "yaml";
248
+ function tryReadJson(file) {
249
+ try {
250
+ const content = readFileSync(file, "utf8");
251
+ return JSON.parse(content);
252
+ } catch {
253
+ return void 0;
254
+ }
255
+ }
256
+ function parseWorkspaceGlobsFromPackageJson(workspaceRoot) {
257
+ const pkgJsonPath = path4.join(workspaceRoot, "package.json");
258
+ const pkg = tryReadJson(pkgJsonPath);
259
+ if (!pkg?.workspaces) {
260
+ return [];
261
+ }
262
+ if (Array.isArray(pkg.workspaces)) {
263
+ return pkg.workspaces.filter(Boolean);
264
+ }
265
+ if (Array.isArray(pkg.workspaces.packages)) {
266
+ return pkg.workspaces.packages.filter(Boolean);
267
+ }
268
+ return [];
269
+ }
270
+ function parseWorkspaceGlobsFromWorkspaceFile(workspaceRoot) {
271
+ const workspaceFile = path4.join(workspaceRoot, "pnpm-workspace.yaml");
272
+ if (!existsSync(workspaceFile)) {
273
+ return [];
274
+ }
275
+ try {
276
+ const parsed = parseYaml(readFileSync(workspaceFile, "utf8"));
277
+ return Array.isArray(parsed?.packages) ? parsed.packages.filter(Boolean) : [];
278
+ } catch {
279
+ return [];
280
+ }
281
+ }
282
+ function parseImportersFromLock(workspaceRoot) {
283
+ const lockPath = path4.join(workspaceRoot, "pnpm-lock.yaml");
284
+ if (!existsSync(lockPath)) {
285
+ return [];
286
+ }
287
+ try {
288
+ const parsed = parseYaml(readFileSync(lockPath, "utf8"));
289
+ const importers = parsed?.importers;
290
+ if (!importers) {
291
+ return [];
292
+ }
293
+ return Object.keys(importers).map((key) => {
294
+ if (!key || key === ".") {
295
+ return workspaceRoot;
296
+ }
297
+ return path4.join(workspaceRoot, key);
298
+ });
299
+ } catch {
300
+ return [];
301
+ }
302
+ }
303
+ async function resolveWorkspacePackageDirs(workspaceRoot) {
304
+ const dirs = /* @__PURE__ */ new Set();
305
+ for (const importerDir of parseImportersFromLock(workspaceRoot)) {
306
+ dirs.add(path4.normalize(importerDir));
307
+ }
308
+ if (!dirs.size) {
309
+ let globs = parseWorkspaceGlobsFromWorkspaceFile(workspaceRoot);
310
+ if (!globs.length) {
311
+ globs = parseWorkspaceGlobsFromPackageJson(workspaceRoot);
312
+ }
313
+ if (globs.length > 0) {
314
+ const patterns = globs.map((pattern) => {
315
+ const normalized = pattern.replace(/\\/g, "/").replace(/\/+$/, "");
316
+ return normalized.endsWith("package.json") ? normalized : `${normalized}/package.json`;
317
+ });
318
+ const packageJsonFiles = await fg(patterns, {
319
+ cwd: workspaceRoot,
320
+ absolute: true,
321
+ onlyFiles: true,
322
+ unique: true,
323
+ ignore: ["**/node_modules/**", "**/.git/**"]
324
+ });
325
+ for (const file of packageJsonFiles) {
326
+ dirs.add(path4.normalize(path4.dirname(file)));
327
+ }
328
+ }
329
+ }
330
+ const rootPkg = path4.join(workspaceRoot, "package.json");
331
+ if (existsSync(rootPkg)) {
332
+ dirs.add(path4.normalize(workspaceRoot));
333
+ }
334
+ return [...dirs];
335
+ }
336
+ function createWorkspacePatcher(cwd) {
337
+ const normalized = normalizeOptions({
338
+ cwd
339
+ });
340
+ return new TailwindcssPatcher(normalized);
341
+ }
342
+ function formatDisplayName(workspaceRoot, dir, name) {
343
+ const relative = path4.relative(workspaceRoot, dir) || ".";
344
+ return name ? `${name} (${relative})` : relative;
345
+ }
346
+ async function patchWorkspace(options) {
347
+ const cwd = options.cwd ?? process3.cwd();
348
+ const workspaceRoot = findWorkspaceRoot(cwd) ?? cwd;
349
+ const packageDirs = await resolveWorkspacePackageDirs(workspaceRoot);
350
+ if (packageDirs.length === 0) {
351
+ logger.warn("\u672A\u5728 %s \u68C0\u6D4B\u5230 workspace \u5305\uFF0C\u5DF2\u8DF3\u8FC7\u6279\u91CF patch\u3002", workspaceRoot);
352
+ return;
353
+ }
354
+ const results = [];
355
+ for (const dir of packageDirs) {
356
+ const pkgJsonPath = path4.join(dir, "package.json");
357
+ const pkgJson = tryReadJson(pkgJsonPath);
358
+ const displayName = formatDisplayName(workspaceRoot, dir, pkgJson?.name);
359
+ const tailwindInfo = getTailwindcssPackageInfo({ paths: [dir] });
360
+ if (!tailwindInfo?.rootPath) {
361
+ results.push({
362
+ dir,
363
+ name: pkgJson?.name,
364
+ status: "skipped",
365
+ message: "tailwindcss \u672A\u5B89\u88C5\uFF0C\u5DF2\u8DF3\u8FC7\u3002"
366
+ });
367
+ logger.info("[workspace] \u8DF3\u8FC7 %s\uFF08tailwindcss \u672A\u5B89\u88C5\uFF09\u3002", displayName);
368
+ continue;
369
+ }
370
+ try {
371
+ const patcher = createWorkspacePatcher(dir);
372
+ if (options.clearCache) {
373
+ await clearTailwindcssPatcherCache(patcher, { removeDirectory: true });
374
+ }
375
+ const recorder = createPatchTargetRecorder(dir, patcher, {
376
+ source: "cli",
377
+ cwd: dir,
378
+ recordTarget: options.recordTarget !== false,
379
+ alwaysRecord: true
380
+ });
381
+ if (recorder?.message) {
382
+ logger.info("[workspace] %s %s", displayName, recorder.message);
383
+ }
384
+ logTailwindcssTarget("cli", patcher, dir);
385
+ await patcher.patch();
386
+ if (recorder?.onPatched) {
387
+ await recorder.onPatched();
388
+ }
389
+ results.push({
390
+ dir,
391
+ name: pkgJson?.name,
392
+ status: "patched",
393
+ message: "\u5DF2\u5B8C\u6210 patch\u3002"
394
+ });
395
+ logger.success("[workspace] \u5DF2\u8865\u4E01 %s", displayName);
396
+ } catch (error) {
397
+ const reason = error instanceof Error ? error.message : String(error);
398
+ const suggestion = `\u8BF7\u5728 ${dir} \u8FD0\u884C "weapp-tw patch --cwd ${dir}".`;
399
+ const message = `${reason}\uFF0C${suggestion}`;
400
+ results.push({
401
+ dir,
402
+ name: pkgJson?.name,
403
+ status: "failed",
404
+ message
405
+ });
406
+ logger.error("[workspace] \u8865\u4E01\u5931\u8D25 %s\uFF1A%s", displayName, message);
407
+ }
408
+ }
409
+ const patched = results.filter((result) => result.status === "patched").length;
410
+ const skipped = results.filter((result) => result.status === "skipped").length;
411
+ const failed = results.filter((result) => result.status === "failed").length;
412
+ logger.info("[workspace] \u6C47\u603B\uFF1A\u5DF2\u8865\u4E01 %d\uFF0C\u8DF3\u8FC7 %d\uFF0C\u5931\u8D25 %d", patched, skipped, failed);
413
+ }
414
+
240
415
  // src/cli.ts
241
416
  function handleCliError2(error) {
242
417
  if (error instanceof Error) {
243
418
  logger.error(error.message);
244
- if (error.stack && process3.env.WEAPP_TW_DEBUG === "1") {
419
+ if (error.stack && process4.env.WEAPP_TW_DEBUG === "1") {
245
420
  logger.error(error.stack);
246
421
  }
247
422
  } else {
@@ -254,7 +429,7 @@ function withCommandErrorHandling(handler) {
254
429
  return await handler(ctx, next);
255
430
  } catch (error) {
256
431
  handleCliError2(error);
257
- process3.exitCode = 1;
432
+ process4.exitCode = 1;
258
433
  return void 0;
259
434
  }
260
435
  });
@@ -273,6 +448,10 @@ var mountOptions = {
273
448
  {
274
449
  flags: "--clear-cache",
275
450
  description: "Clear tailwindcss-patch cache before patch (opt-in)"
451
+ },
452
+ {
453
+ flags: "--workspace",
454
+ description: "Scan pnpm workspace packages and patch each Tailwind CSS dependency"
276
455
  }
277
456
  ]
278
457
  }
@@ -281,14 +460,32 @@ var mountOptions = {
281
460
  install: withCommandErrorHandling(async (ctx) => {
282
461
  const shouldClearCache = toBoolean(ctx.args.clearCache, false);
283
462
  const shouldRecordTarget = toBoolean(ctx.args.recordTarget, true);
463
+ const runWorkspace = toBoolean(ctx.args.workspace, false);
464
+ if (runWorkspace) {
465
+ await patchWorkspace({
466
+ cwd: ctx.cwd,
467
+ clearCache: shouldClearCache,
468
+ recordTarget: shouldRecordTarget
469
+ });
470
+ return;
471
+ }
284
472
  const patcher = await ctx.createPatcher();
285
473
  if (shouldClearCache) {
286
474
  await clearTailwindcssPatcherCache(patcher, { removeDirectory: true });
287
475
  }
476
+ const recorder = createPatchTargetRecorder(ctx.cwd, patcher, {
477
+ source: "cli",
478
+ cwd: ctx.cwd,
479
+ recordTarget: shouldRecordTarget,
480
+ alwaysRecord: true
481
+ });
482
+ if (recorder?.message) {
483
+ logger.info(recorder.message);
484
+ }
288
485
  logTailwindcssTarget("cli", patcher, ctx.cwd);
289
486
  await patcher.patch();
290
- if (shouldRecordTarget) {
291
- const recordPath = await saveCliPatchTargetRecord(ctx.cwd, patcher);
487
+ if (recorder?.onPatched) {
488
+ const recordPath = await recorder.onPatched();
292
489
  if (recordPath) {
293
490
  logger.info(`\u8BB0\u5F55 weapp-tw patch \u76EE\u6807 -> ${formatOutputPath(recordPath, ctx.cwd)}`);
294
491
  }
@@ -300,10 +497,10 @@ var mountOptions = {
300
497
  init: withCommandErrorHandling(async (_ctx, next) => next())
301
498
  }
302
499
  };
303
- process3.title = "node (weapp-tailwindcss)";
304
- if (semver.lt(process3.versions.node, WEAPP_TW_REQUIRED_NODE_VERSION)) {
500
+ process4.title = "node (weapp-tailwindcss)";
501
+ if (semver.lt(process4.versions.node, WEAPP_TW_REQUIRED_NODE_VERSION)) {
305
502
  logger.warn(
306
- `You are using Node.js ${process3.versions.node}. For weapp-tailwindcss, Node.js version >= v${WEAPP_TW_REQUIRED_NODE_VERSION} is required.`
503
+ `You are using Node.js ${process4.versions.node}. For weapp-tailwindcss, Node.js version >= v${WEAPP_TW_REQUIRED_NODE_VERSION} is required.`
307
504
  );
308
505
  }
309
506
  var cli = createTailwindcssPatchCli({
@@ -313,7 +510,7 @@ var cli = createTailwindcssPatchCli({
313
510
  cli.command("vscode-entry", "Generate a VS Code helper CSS for Tailwind IntelliSense").option("--cwd <dir>", "Working directory").option("--css <file>", "Path to the CSS file that imports weapp-tailwindcss (required)").option("--output <file>", `Helper output path. Defaults to ${DEFAULT_VSCODE_ENTRY_OUTPUT}`).option("--source <pattern>", "Additional @source glob (can be repeated)").option("--force", "Overwrite the helper file when it already exists").action(
314
511
  commandAction(async (options) => {
315
512
  const resolvedCwd = resolveCliCwd(options.cwd);
316
- const baseDir = resolvedCwd ?? process3.cwd();
513
+ const baseDir = resolvedCwd ?? process4.cwd();
317
514
  const cssEntry = readStringOption("css", options.css);
318
515
  if (!cssEntry) {
319
516
  throw new Error('Option "--css" is required.');
@@ -334,5 +531,5 @@ cli.command("vscode-entry", "Generate a VS Code helper CSS for Tailwind IntelliS
334
531
  })
335
532
  );
336
533
  cli.help();
337
- cli.version(process3.env.npm_package_version ?? "0.0.0");
534
+ cli.version(process4.env.npm_package_version ?? "0.0.0");
338
535
  cli.parse();
package/dist/core.js CHANGED
@@ -1,27 +1,35 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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; }
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 _chunkR6ERGDBQjs = require('./chunk-R6ERGDBQ.js');
3
4
 
4
5
 
5
6
 
6
- var _chunkAXEKXGG7js = require('./chunk-AXEKXGG7.js');
7
- require('./chunk-ZXU4EYKV.js');
7
+
8
+ var _chunkYKMZHWQ4js = require('./chunk-YKMZHWQ4.js');
9
+ require('./chunk-RJRLVYVJ.js');
8
10
  require('./chunk-ZSTF2AEN.js');
9
11
  require('./chunk-UW3WHSZ5.js');
10
- require('./chunk-WGLBMNPG.js');
12
+ require('./chunk-UTZLVU3M.js');
11
13
 
12
14
  // src/core.ts
15
+ var _process = require('process'); var _process2 = _interopRequireDefault(_process);
13
16
  var _shared = require('@weapp-tailwindcss/shared');
14
17
  function createContext(options = {}) {
15
- const opts = _chunkAXEKXGG7js.getCompilerContext.call(void 0, options);
18
+ const opts = _chunkYKMZHWQ4js.getCompilerContext.call(void 0, options);
16
19
  const { templateHandler, styleHandler, jsHandler, twPatcher: initialTwPatcher, refreshTailwindcssPatcher } = opts;
20
+ const patchRecorderState = _chunkR6ERGDBQjs.setupPatchRecorder.call(void 0, initialTwPatcher, opts.tailwindcssBasedir, {
21
+ source: "runtime",
22
+ cwd: _nullishCoalesce(opts.tailwindcssBasedir, () => ( _process2.default.cwd()))
23
+ });
17
24
  let runtimeSet = /* @__PURE__ */ new Set();
18
25
  const runtimeState = {
19
26
  twPatcher: initialTwPatcher,
20
- patchPromise: _chunkAXEKXGG7js.createTailwindPatchPromise.call(void 0, initialTwPatcher),
21
- refreshTailwindcssPatcher
27
+ patchPromise: patchRecorderState.patchPromise,
28
+ refreshTailwindcssPatcher,
29
+ onPatchCompleted: patchRecorderState.onPatchCompleted
22
30
  };
23
31
  async function refreshRuntimeState(force) {
24
- await _chunkAXEKXGG7js.refreshTailwindRuntimeState.call(void 0, runtimeState, force);
32
+ await _chunkYKMZHWQ4js.refreshTailwindRuntimeState.call(void 0, runtimeState, force);
25
33
  }
26
34
  async function transformWxss(rawCss, options2) {
27
35
  await runtimeState.patchPromise;
@@ -30,7 +38,7 @@ function createContext(options = {}) {
30
38
  }));
31
39
  await refreshRuntimeState(true);
32
40
  await runtimeState.patchPromise;
33
- runtimeSet = await _chunkAXEKXGG7js.collectRuntimeClassSet.call(void 0, runtimeState.twPatcher, { force: true, skipRefresh: true });
41
+ runtimeSet = await _chunkYKMZHWQ4js.collectRuntimeClassSet.call(void 0, runtimeState.twPatcher, { force: true, skipRefresh: true });
34
42
  return result;
35
43
  }
36
44
  async function transformJs(rawJs, options2 = {}) {
@@ -40,7 +48,7 @@ function createContext(options = {}) {
40
48
  } else {
41
49
  await refreshRuntimeState(true);
42
50
  await runtimeState.patchPromise;
43
- runtimeSet = await _chunkAXEKXGG7js.collectRuntimeClassSet.call(void 0, runtimeState.twPatcher, { force: true, skipRefresh: true });
51
+ runtimeSet = await _chunkYKMZHWQ4js.collectRuntimeClassSet.call(void 0, runtimeState.twPatcher, { force: true, skipRefresh: true });
44
52
  }
45
53
  return await jsHandler(rawJs, runtimeSet, options2);
46
54
  }
@@ -49,7 +57,7 @@ function createContext(options = {}) {
49
57
  if (!_optionalChain([options2, 'optionalAccess', _2 => _2.runtimeSet]) && runtimeSet.size === 0) {
50
58
  await refreshRuntimeState(true);
51
59
  await runtimeState.patchPromise;
52
- runtimeSet = await _chunkAXEKXGG7js.collectRuntimeClassSet.call(void 0, runtimeState.twPatcher, { force: true, skipRefresh: true });
60
+ runtimeSet = await _chunkYKMZHWQ4js.collectRuntimeClassSet.call(void 0, runtimeState.twPatcher, { force: true, skipRefresh: true });
53
61
  }
54
62
  return templateHandler(rawWxml, _shared.defuOverrideArray.call(void 0, options2, {
55
63
  runtimeSet