tailwindcss-patch 9.0.0-alpha.2 → 9.0.0-alpha.3

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.
@@ -20,10 +20,13 @@ var _pathe = require('pathe'); var _pathe2 = _interopRequireDefault(_pathe);
20
20
  // package.json
21
21
  var package_default = {
22
22
  name: "tailwindcss-patch",
23
- version: "9.0.0-alpha.2",
23
+ version: "9.0.0-alpha.3",
24
24
  description: "patch tailwindcss for exposing context and extract classes",
25
25
  author: "ice breaker <1324318532@qq.com>",
26
26
  license: "MIT",
27
+ engines: {
28
+ node: ">=18.0.0"
29
+ },
27
30
  homepage: "https://mangle.icebreaker.top/",
28
31
  repository: {
29
32
  type: "git",
@@ -2405,8 +2408,8 @@ function transformProcessTailwindFeaturesReturnContextV2(content) {
2405
2408
  });
2406
2409
  let hasPatched = false;
2407
2410
  traverse(ast, {
2408
- FunctionDeclaration(path18) {
2409
- const node = path18.node;
2411
+ FunctionDeclaration(path15) {
2412
+ const node = path15.node;
2410
2413
  if (_optionalChain([node, 'access', _78 => _78.id, 'optionalAccess', _79 => _79.name]) !== "processTailwindFeatures" || node.body.body.length !== 1 || !t.isReturnStatement(node.body.body[0])) {
2411
2414
  return;
2412
2415
  }
@@ -2437,8 +2440,8 @@ function transformPostcssPluginV2(content, options) {
2437
2440
  const ast = _parser.parse.call(void 0, content);
2438
2441
  let hasPatched = false;
2439
2442
  traverse(ast, {
2440
- Program(path18) {
2441
- const program = path18.node;
2443
+ Program(path15) {
2444
+ const program = path15.node;
2442
2445
  const index = program.body.findIndex((statement) => {
2443
2446
  return t.isFunctionDeclaration(statement) && _optionalChain([statement, 'access', _80 => _80.id, 'optionalAccess', _81 => _81.name]) === "_default";
2444
2447
  });
@@ -2477,11 +2480,11 @@ function transformPostcssPluginV2(content, options) {
2477
2480
  );
2478
2481
  }
2479
2482
  },
2480
- FunctionDeclaration(path18) {
2483
+ FunctionDeclaration(path15) {
2481
2484
  if (hasPatched) {
2482
2485
  return;
2483
2486
  }
2484
- const fn = path18.node;
2487
+ const fn = path15.node;
2485
2488
  if (_optionalChain([fn, 'access', _82 => _82.id, 'optionalAccess', _83 => _83.name]) !== "_default") {
2486
2489
  return;
2487
2490
  }
@@ -2570,8 +2573,8 @@ function transformProcessTailwindFeaturesReturnContext(content) {
2570
2573
  const ast = _parser.parse.call(void 0, content);
2571
2574
  let hasPatched = false;
2572
2575
  traverse(ast, {
2573
- FunctionDeclaration(path18) {
2574
- const node = path18.node;
2576
+ FunctionDeclaration(path15) {
2577
+ const node = path15.node;
2575
2578
  if (_optionalChain([node, 'access', _84 => _84.id, 'optionalAccess', _85 => _85.name]) !== "processTailwindFeatures" || node.body.body.length !== 1) {
2576
2579
  return;
2577
2580
  }
@@ -2603,8 +2606,8 @@ function transformPostcssPlugin(content, { refProperty }) {
2603
2606
  const valueMember = t2.memberExpression(refIdentifier, t2.identifier("value"));
2604
2607
  let hasPatched = false;
2605
2608
  traverse(ast, {
2606
- Program(path18) {
2607
- const program = path18.node;
2609
+ Program(path15) {
2610
+ const program = path15.node;
2608
2611
  const index = program.body.findIndex((statement) => {
2609
2612
  return t2.isExpressionStatement(statement) && t2.isAssignmentExpression(statement.expression) && t2.isMemberExpression(statement.expression.left) && t2.isFunctionExpression(statement.expression.right) && _optionalChain([statement, 'access', _86 => _86.expression, 'access', _87 => _87.right, 'access', _88 => _88.id, 'optionalAccess', _89 => _89.name]) === "tailwindcss";
2610
2613
  });
@@ -2647,11 +2650,11 @@ function transformPostcssPlugin(content, { refProperty }) {
2647
2650
  );
2648
2651
  }
2649
2652
  },
2650
- FunctionExpression(path18) {
2653
+ FunctionExpression(path15) {
2651
2654
  if (hasPatched) {
2652
2655
  return;
2653
2656
  }
2654
- const fn = path18.node;
2657
+ const fn = path15.node;
2655
2658
  if (_optionalChain([fn, 'access', _90 => _90.id, 'optionalAccess', _91 => _91.name]) !== "tailwindcss" || fn.body.body.length !== 1) {
2656
2659
  return;
2657
2660
  }
@@ -2730,21 +2733,21 @@ function updateLengthUnitsArray(content, options) {
2730
2733
  let arrayRef;
2731
2734
  let changed = false;
2732
2735
  traverse(ast, {
2733
- Identifier(path18) {
2734
- if (path18.node.name === variableName && t3.isVariableDeclarator(path18.parent) && t3.isArrayExpression(path18.parent.init)) {
2735
- arrayRef = path18.parent.init;
2736
+ Identifier(path15) {
2737
+ if (path15.node.name === variableName && t3.isVariableDeclarator(path15.parent) && t3.isArrayExpression(path15.parent.init)) {
2738
+ arrayRef = path15.parent.init;
2736
2739
  const existing = new Set(
2737
- path18.parent.init.elements.map((element) => t3.isStringLiteral(element) ? element.value : void 0).filter(Boolean)
2740
+ path15.parent.init.elements.map((element) => t3.isStringLiteral(element) ? element.value : void 0).filter(Boolean)
2738
2741
  );
2739
2742
  for (const unit of units) {
2740
2743
  if (!existing.has(unit)) {
2741
- path18.parent.init.elements = path18.parent.init.elements.map((element) => {
2744
+ path15.parent.init.elements = path15.parent.init.elements.map((element) => {
2742
2745
  if (t3.isStringLiteral(element)) {
2743
2746
  return t3.stringLiteral(element.value);
2744
2747
  }
2745
2748
  return element;
2746
2749
  });
2747
- path18.parent.init.elements.push(t3.stringLiteral(unit));
2750
+ path15.parent.init.elements.push(t3.stringLiteral(unit));
2748
2751
  changed = true;
2749
2752
  }
2750
2753
  }
@@ -2825,13 +2828,13 @@ function applyExtendLengthUnitsPatchV4(rootDir, options) {
2825
2828
  const { code, file, match } = item;
2826
2829
  const ast = _parser.parse.call(void 0, match[0], { sourceType: "unambiguous" });
2827
2830
  traverse(ast, {
2828
- ArrayExpression(path18) {
2831
+ ArrayExpression(path15) {
2829
2832
  for (const unit of opts.units) {
2830
- if (path18.node.elements.some((element) => t3.isStringLiteral(element) && element.value === unit)) {
2833
+ if (path15.node.elements.some((element) => t3.isStringLiteral(element) && element.value === unit)) {
2831
2834
  item.hasPatched = true;
2832
2835
  return;
2833
2836
  }
2834
- path18.node.elements.push(t3.stringLiteral(unit));
2837
+ path15.node.elements.push(t3.stringLiteral(unit));
2835
2838
  }
2836
2839
  }
2837
2840
  });
@@ -2867,14 +2870,14 @@ function inspectLengthUnitsArray(content, variableName, units) {
2867
2870
  let found = false;
2868
2871
  let missingUnits = [];
2869
2872
  traverse(ast, {
2870
- Identifier(path18) {
2871
- if (path18.node.name === variableName && t4.isVariableDeclarator(path18.parent) && t4.isArrayExpression(path18.parent.init)) {
2873
+ Identifier(path15) {
2874
+ if (path15.node.name === variableName && t4.isVariableDeclarator(path15.parent) && t4.isArrayExpression(path15.parent.init)) {
2872
2875
  found = true;
2873
2876
  const existing = new Set(
2874
- path18.parent.init.elements.map((element) => t4.isStringLiteral(element) ? element.value : void 0).filter(Boolean)
2877
+ path15.parent.init.elements.map((element) => t4.isStringLiteral(element) ? element.value : void 0).filter(Boolean)
2875
2878
  );
2876
2879
  missingUnits = units.filter((unit) => !existing.has(unit));
2877
- path18.stop();
2880
+ path15.stop();
2878
2881
  }
2879
2882
  }
2880
2883
  });
@@ -4278,6 +4281,9 @@ async function restoreConfigFiles(options) {
4278
4281
  };
4279
4282
  }
4280
4283
 
4284
+ // src/commands/types.ts
4285
+ var tailwindcssPatchCommands = ["install", "extract", "tokens", "init", "migrate", "restore", "validate", "status"];
4286
+
4281
4287
  // src/commands/validate.ts
4282
4288
  var VALIDATE_EXIT_CODES = {
4283
4289
  OK: 0,
@@ -4336,703 +4342,6 @@ var ValidateCommandError = class extends Error {
4336
4342
  }
4337
4343
  };
4338
4344
 
4339
- // src/commands/types.ts
4340
- var tailwindcssPatchCommands = ["install", "extract", "tokens", "init", "migrate", "restore", "validate", "status"];
4341
-
4342
- // src/commands/cli.ts
4343
- var _cac = require('cac'); var _cac2 = _interopRequireDefault(_cac);
4344
-
4345
- // src/commands/command-definitions.ts
4346
-
4347
-
4348
- // src/commands/token-output.ts
4349
- var TOKEN_FORMATS = ["json", "lines", "grouped-json"];
4350
- var DEFAULT_TOKEN_REPORT = ".tw-patch/tw-token-report.json";
4351
- function formatTokenLine(entry) {
4352
- return `${entry.relativeFile}:${entry.line}:${entry.column} ${entry.rawCandidate} (${entry.start}-${entry.end})`;
4353
- }
4354
- function formatGroupedPreview(map, limit = 3) {
4355
- const files = Object.keys(map);
4356
- if (!files.length) {
4357
- return { preview: "", moreFiles: 0 };
4358
- }
4359
- const lines = files.slice(0, limit).map((file) => {
4360
- const tokens = _nullishCoalesce(map[file], () => ( []));
4361
- const sample = tokens.slice(0, 3).map((token) => token.rawCandidate).join(", ");
4362
- const suffix = tokens.length > 3 ? ", \u2026" : "";
4363
- return `${file}: ${tokens.length} tokens (${sample}${suffix})`;
4364
- });
4365
- return {
4366
- preview: lines.join("\n"),
4367
- moreFiles: Math.max(0, files.length - limit)
4368
- };
4369
- }
4370
-
4371
- // src/commands/command-definitions.ts
4372
- function createCwdOptionDefinition(description = "Working directory") {
4373
- return {
4374
- flags: "--cwd <dir>",
4375
- description,
4376
- config: { default: _process2.default.cwd() }
4377
- };
4378
- }
4379
- function buildDefaultCommandDefinitions() {
4380
- return {
4381
- install: {
4382
- description: "Apply Tailwind CSS runtime patches",
4383
- optionDefs: [createCwdOptionDefinition()]
4384
- },
4385
- extract: {
4386
- description: "Collect generated class names into a cache file",
4387
- optionDefs: [
4388
- createCwdOptionDefinition(),
4389
- { flags: "--output <file>", description: "Override output file path" },
4390
- { flags: "--format <format>", description: "Output format (json|lines)" },
4391
- { flags: "--css <file>", description: "Tailwind CSS entry CSS when using v4" },
4392
- { flags: "--no-write", description: "Skip writing to disk" }
4393
- ]
4394
- },
4395
- tokens: {
4396
- description: "Extract Tailwind tokens with file/position metadata",
4397
- optionDefs: [
4398
- createCwdOptionDefinition(),
4399
- { flags: "--output <file>", description: "Override output file path", config: { default: DEFAULT_TOKEN_REPORT } },
4400
- {
4401
- flags: "--format <format>",
4402
- description: "Output format (json|lines|grouped-json)",
4403
- config: { default: "json" }
4404
- },
4405
- {
4406
- flags: "--group-key <key>",
4407
- description: "Grouping key for grouped-json output (relative|absolute)",
4408
- config: { default: "relative" }
4409
- },
4410
- { flags: "--no-write", description: "Skip writing to disk" }
4411
- ]
4412
- },
4413
- init: {
4414
- description: "Generate a tailwindcss-patch config file",
4415
- optionDefs: [createCwdOptionDefinition()]
4416
- },
4417
- migrate: {
4418
- description: "Migrate deprecated config fields to modern options",
4419
- optionDefs: [
4420
- createCwdOptionDefinition(),
4421
- { flags: "--config <file>", description: "Migrate a specific config file path" },
4422
- { flags: "--workspace", description: "Scan workspace recursively for config files" },
4423
- { flags: "--max-depth <n>", description: "Maximum recursion depth for --workspace", config: { default: 6 } },
4424
- { flags: "--include <glob>", description: "Only migrate files that match this glob (repeatable)" },
4425
- { flags: "--exclude <glob>", description: "Skip files that match this glob (repeatable)" },
4426
- { flags: "--report-file <file>", description: "Write migration report JSON to a file" },
4427
- { flags: "--backup-dir <dir>", description: "Write pre-migration backups into this directory" },
4428
- { flags: "--check", description: "Exit with an error when migration changes are required" },
4429
- { flags: "--json", description: "Print the migration report as JSON" },
4430
- { flags: "--dry-run", description: "Preview changes without writing files" }
4431
- ]
4432
- },
4433
- restore: {
4434
- description: "Restore config files from a previous migration report backup snapshot",
4435
- optionDefs: [
4436
- createCwdOptionDefinition(),
4437
- { flags: "--report-file <file>", description: "Migration report file generated by migrate" },
4438
- { flags: "--dry-run", description: "Preview restore targets without writing files" },
4439
- { flags: "--strict", description: "Fail when any backup file is missing" },
4440
- { flags: "--json", description: "Print the restore result as JSON" }
4441
- ]
4442
- },
4443
- validate: {
4444
- description: "Validate migration report compatibility without modifying files",
4445
- optionDefs: [
4446
- createCwdOptionDefinition(),
4447
- { flags: "--report-file <file>", description: "Migration report file to validate" },
4448
- { flags: "--strict", description: "Fail when any backup file is missing" },
4449
- { flags: "--json", description: "Print validation result as JSON" }
4450
- ]
4451
- },
4452
- status: {
4453
- description: "Check which Tailwind patches are applied",
4454
- optionDefs: [
4455
- createCwdOptionDefinition(),
4456
- { flags: "--json", description: "Print a JSON report of patch status" }
4457
- ]
4458
- }
4459
- };
4460
- }
4461
-
4462
- // src/commands/command-metadata.ts
4463
- function addPrefixIfMissing(value, prefix) {
4464
- if (!prefix || value.startsWith(prefix)) {
4465
- return value;
4466
- }
4467
- return `${prefix}${value}`;
4468
- }
4469
- function resolveCommandNames(command, mountOptions, prefix) {
4470
- const override = _optionalChain([mountOptions, 'access', _122 => _122.commandOptions, 'optionalAccess', _123 => _123[command]]);
4471
- const baseName = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _124 => _124.name]), () => ( command));
4472
- const name = addPrefixIfMissing(baseName, prefix);
4473
- const aliases = (_nullishCoalesce(_optionalChain([override, 'optionalAccess', _125 => _125.aliases]), () => ( []))).map((alias) => addPrefixIfMissing(alias, prefix));
4474
- return { name, aliases };
4475
- }
4476
- function resolveOptionDefinitions(defaults, override) {
4477
- if (!override) {
4478
- return defaults;
4479
- }
4480
- const appendDefaults = _nullishCoalesce(override.appendDefaultOptions, () => ( true));
4481
- const customDefs = _nullishCoalesce(override.optionDefs, () => ( []));
4482
- if (!appendDefaults) {
4483
- return customDefs;
4484
- }
4485
- if (customDefs.length === 0) {
4486
- return defaults;
4487
- }
4488
- return [...defaults, ...customDefs];
4489
- }
4490
- function resolveCommandMetadata(command, mountOptions, prefix, defaults) {
4491
- const names = resolveCommandNames(command, mountOptions, prefix);
4492
- const definition = defaults[command];
4493
- const override = _optionalChain([mountOptions, 'access', _126 => _126.commandOptions, 'optionalAccess', _127 => _127[command]]);
4494
- const description = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _128 => _128.description]), () => ( definition.description));
4495
- const optionDefs = resolveOptionDefinitions(definition.optionDefs, override);
4496
- return { ...names, description, optionDefs };
4497
- }
4498
- function applyCommandOptions(command, optionDefs) {
4499
- for (const option of optionDefs) {
4500
- command.option(option.flags, _nullishCoalesce(option.description, () => ( "")), option.config);
4501
- }
4502
- }
4503
-
4504
- // src/commands/command-context.ts
4505
-
4506
-
4507
- function resolveCommandCwd(rawCwd) {
4508
- if (!rawCwd) {
4509
- return _process2.default.cwd();
4510
- }
4511
- return _pathe2.default.resolve(rawCwd);
4512
- }
4513
- function createMemoizedPromiseRunner(factory) {
4514
- let promise;
4515
- return () => {
4516
- if (!promise) {
4517
- promise = factory();
4518
- }
4519
- return promise;
4520
- };
4521
- }
4522
- function createTailwindcssPatchCommandContext(cli, command, commandName, args, cwd) {
4523
- const loadCachedConfig = createMemoizedPromiseRunner(
4524
- () => loadWorkspaceConfigModule().then((mod) => mod.getConfig(cwd))
4525
- );
4526
- const loadCachedPatchOptions = createMemoizedPromiseRunner(
4527
- () => loadPatchOptionsForWorkspace(cwd)
4528
- );
4529
- const createCachedPatcher = createMemoizedPromiseRunner(async () => {
4530
- const patchOptions = await loadCachedPatchOptions();
4531
- return new TailwindcssPatcher(patchOptions);
4532
- });
4533
- const loadPatchOptionsForContext = (overrides) => {
4534
- if (overrides) {
4535
- return loadPatchOptionsForWorkspace(cwd, overrides);
4536
- }
4537
- return loadCachedPatchOptions();
4538
- };
4539
- const createPatcherForContext = async (overrides) => {
4540
- if (overrides) {
4541
- const patchOptions = await loadPatchOptionsForWorkspace(cwd, overrides);
4542
- return new TailwindcssPatcher(patchOptions);
4543
- }
4544
- return createCachedPatcher();
4545
- };
4546
- return {
4547
- cli,
4548
- command,
4549
- commandName,
4550
- args,
4551
- cwd,
4552
- logger: logger_default,
4553
- loadConfig: loadCachedConfig,
4554
- loadPatchOptions: loadPatchOptionsForContext,
4555
- createPatcher: createPatcherForContext
4556
- };
4557
- }
4558
-
4559
- // src/commands/command-runtime.ts
4560
- function runWithCommandHandler(cli, command, commandName, args, handler, defaultHandler) {
4561
- const cwd = resolveCommandCwd(args.cwd);
4562
- const context = createTailwindcssPatchCommandContext(cli, command, commandName, args, cwd);
4563
- const runDefault = createMemoizedPromiseRunner(() => defaultHandler(context));
4564
- if (!handler) {
4565
- return runDefault();
4566
- }
4567
- return handler(context, runDefault);
4568
- }
4569
-
4570
- // src/commands/basic-handlers.ts
4571
-
4572
-
4573
-
4574
- var DEFAULT_CONFIG_NAME = "tailwindcss-mangle";
4575
- async function installCommandDefaultHandler(_ctx) {
4576
- const patcher = await _ctx.createPatcher();
4577
- await patcher.patch();
4578
- logger_default.success("Tailwind CSS runtime patched successfully.");
4579
- }
4580
- async function extractCommandDefaultHandler(ctx) {
4581
- const { args } = ctx;
4582
- const overrides = {};
4583
- let hasOverrides = false;
4584
- if (args.output || args.format) {
4585
- overrides.extract = {
4586
- ...args.output === void 0 ? {} : { file: args.output },
4587
- ...args.format === void 0 ? {} : { format: args.format }
4588
- };
4589
- hasOverrides = true;
4590
- }
4591
- if (args.css) {
4592
- overrides.tailwindcss = {
4593
- v4: {
4594
- cssEntries: [args.css]
4595
- }
4596
- };
4597
- hasOverrides = true;
4598
- }
4599
- const patcher = await ctx.createPatcher(hasOverrides ? overrides : void 0);
4600
- const extractOptions = args.write === void 0 ? {} : { write: args.write };
4601
- const result = await patcher.extract(extractOptions);
4602
- if (result.filename) {
4603
- logger_default.success(`Collected ${result.classList.length} classes \u2192 ${result.filename}`);
4604
- } else {
4605
- logger_default.success(`Collected ${result.classList.length} classes.`);
4606
- }
4607
- return result;
4608
- }
4609
- async function tokensCommandDefaultHandler(ctx) {
4610
- const { args } = ctx;
4611
- const patcher = await ctx.createPatcher();
4612
- const report = await patcher.collectContentTokens();
4613
- const shouldWrite = _nullishCoalesce(args.write, () => ( true));
4614
- let format = _nullishCoalesce(args.format, () => ( "json"));
4615
- if (!TOKEN_FORMATS.includes(format)) {
4616
- format = "json";
4617
- }
4618
- const targetFile = _nullishCoalesce(args.output, () => ( DEFAULT_TOKEN_REPORT));
4619
- const groupKey = args.groupKey === "absolute" ? "absolute" : "relative";
4620
- const buildGrouped = () => groupTokensByFile(report, {
4621
- key: groupKey,
4622
- stripAbsolutePaths: groupKey !== "absolute"
4623
- });
4624
- const grouped = format === "grouped-json" ? buildGrouped() : null;
4625
- const resolveGrouped = () => _nullishCoalesce(grouped, () => ( buildGrouped()));
4626
- if (shouldWrite) {
4627
- const target = _pathe2.default.resolve(targetFile);
4628
- await _fsextra2.default.ensureDir(_pathe2.default.dirname(target));
4629
- if (format === "json") {
4630
- await _fsextra2.default.writeJSON(target, report, { spaces: 2 });
4631
- } else if (format === "grouped-json") {
4632
- await _fsextra2.default.writeJSON(target, resolveGrouped(), { spaces: 2 });
4633
- } else {
4634
- const lines = report.entries.map(formatTokenLine);
4635
- await _fsextra2.default.writeFile(target, `${lines.join("\n")}
4636
- `, "utf8");
4637
- }
4638
- logger_default.success(`Collected ${report.entries.length} tokens (${format}) \u2192 ${target.replace(_process2.default.cwd(), ".")}`);
4639
- } else {
4640
- logger_default.success(`Collected ${report.entries.length} tokens from ${report.filesScanned} files.`);
4641
- if (format === "lines") {
4642
- const preview = report.entries.slice(0, 5).map(formatTokenLine).join("\n");
4643
- if (preview) {
4644
- logger_default.log("");
4645
- logger_default.info(preview);
4646
- if (report.entries.length > 5) {
4647
- logger_default.info(`\u2026and ${report.entries.length - 5} more.`);
4648
- }
4649
- }
4650
- } else if (format === "grouped-json") {
4651
- const map = resolveGrouped();
4652
- const { preview, moreFiles } = formatGroupedPreview(map);
4653
- if (preview) {
4654
- logger_default.log("");
4655
- logger_default.info(preview);
4656
- if (moreFiles > 0) {
4657
- logger_default.info(`\u2026and ${moreFiles} more files.`);
4658
- }
4659
- }
4660
- } else {
4661
- const previewEntries = report.entries.slice(0, 3);
4662
- if (previewEntries.length) {
4663
- logger_default.log("");
4664
- logger_default.info(JSON.stringify(previewEntries, null, 2));
4665
- }
4666
- }
4667
- }
4668
- if (report.skippedFiles.length) {
4669
- logger_default.warn("Skipped files:");
4670
- for (const skipped of report.skippedFiles) {
4671
- logger_default.warn(` \u2022 ${skipped.file} (${skipped.reason})`);
4672
- }
4673
- }
4674
- return report;
4675
- }
4676
- async function initCommandDefaultHandler(ctx) {
4677
- const configModule = await loadWorkspaceConfigModule();
4678
- await configModule.initConfig(ctx.cwd);
4679
- const configName = configModule.CONFIG_NAME || DEFAULT_CONFIG_NAME;
4680
- logger_default.success(`\u2728 ${configName}.config.ts initialized!`);
4681
- }
4682
-
4683
- // src/commands/migration-args.ts
4684
- function normalizePatternArgs(value) {
4685
- if (!value) {
4686
- return void 0;
4687
- }
4688
- const raw = Array.isArray(value) ? value : [value];
4689
- const values = raw.flatMap((item) => item.split(",")).map((item) => item.trim()).filter(Boolean);
4690
- return values.length > 0 ? values : void 0;
4691
- }
4692
- function parseMaxDepth(value) {
4693
- if (value === void 0) {
4694
- return {
4695
- maxDepth: void 0,
4696
- hasInvalidMaxDepth: false
4697
- };
4698
- }
4699
- const parsed = Number(value);
4700
- if (!Number.isFinite(parsed) || parsed < 0) {
4701
- return {
4702
- maxDepth: void 0,
4703
- hasInvalidMaxDepth: true
4704
- };
4705
- }
4706
- return {
4707
- maxDepth: Math.floor(parsed),
4708
- hasInvalidMaxDepth: false
4709
- };
4710
- }
4711
- function resolveMigrateCommandArgs(args) {
4712
- const include = normalizePatternArgs(args.include);
4713
- const exclude = normalizePatternArgs(args.exclude);
4714
- const { maxDepth, hasInvalidMaxDepth } = parseMaxDepth(args.maxDepth);
4715
- const checkMode = _nullishCoalesce(args.check, () => ( false));
4716
- const dryRun = _nullishCoalesce(args.dryRun, () => ( checkMode));
4717
- return {
4718
- include,
4719
- exclude,
4720
- maxDepth,
4721
- checkMode,
4722
- dryRun,
4723
- hasInvalidMaxDepth
4724
- };
4725
- }
4726
- function resolveRestoreCommandArgs(args) {
4727
- return {
4728
- reportFile: _nullishCoalesce(args.reportFile, () => ( ".tw-patch/migrate-report.json")),
4729
- dryRun: _nullishCoalesce(args.dryRun, () => ( false)),
4730
- strict: _nullishCoalesce(args.strict, () => ( false))
4731
- };
4732
- }
4733
- function resolveValidateCommandArgs(args) {
4734
- return {
4735
- reportFile: _nullishCoalesce(args.reportFile, () => ( ".tw-patch/migrate-report.json")),
4736
- strict: _nullishCoalesce(args.strict, () => ( false))
4737
- };
4738
- }
4739
-
4740
- // src/commands/migration-output.ts
4741
-
4742
-
4743
-
4744
- function formatPathForLog(file) {
4745
- return file.replace(_process2.default.cwd(), ".");
4746
- }
4747
- function createMigrationCheckFailureError(changedFiles) {
4748
- return new Error(`Migration check failed: ${changedFiles} file(s) still need migration.`);
4749
- }
4750
- async function writeMigrationReportFile(cwd, reportFile, report) {
4751
- const reportPath = _pathe2.default.resolve(cwd, reportFile);
4752
- await _fsextra2.default.ensureDir(_pathe2.default.dirname(reportPath));
4753
- await _fsextra2.default.writeJSON(reportPath, report, { spaces: 2 });
4754
- logger_default.info(`Migration report written: ${formatPathForLog(reportPath)}`);
4755
- }
4756
- function logMigrationReportAsJson(report) {
4757
- logger_default.log(JSON.stringify(report, null, 2));
4758
- }
4759
- function logNoMigrationConfigFilesWarning() {
4760
- logger_default.warn("No config files found for migration.");
4761
- }
4762
- function logMigrationEntries(report, dryRun) {
4763
- for (const entry of report.entries) {
4764
- const fileLabel = formatPathForLog(entry.file);
4765
- if (!entry.changed) {
4766
- logger_default.info(`No changes: ${fileLabel}`);
4767
- continue;
4768
- }
4769
- if (dryRun) {
4770
- logger_default.info(`[dry-run] ${fileLabel}`);
4771
- } else {
4772
- logger_default.success(`Migrated: ${fileLabel}`);
4773
- }
4774
- for (const change of entry.changes) {
4775
- logger_default.info(` - ${change}`);
4776
- }
4777
- if (entry.backupFile) {
4778
- logger_default.info(` - backup: ${formatPathForLog(entry.backupFile)}`);
4779
- }
4780
- }
4781
- }
4782
- function logMigrationSummary(report) {
4783
- logger_default.info(
4784
- `Migration summary: scanned=${report.scannedFiles}, changed=${report.changedFiles}, written=${report.writtenFiles}, backups=${report.backupsWritten}, missing=${report.missingFiles}, unchanged=${report.unchangedFiles}`
4785
- );
4786
- }
4787
- function logRestoreResultAsJson(result) {
4788
- logger_default.log(JSON.stringify(result, null, 2));
4789
- }
4790
- function logRestoreSummary(result) {
4791
- logger_default.info(
4792
- `Restore summary: scanned=${result.scannedEntries}, restorable=${result.restorableEntries}, restored=${result.restoredFiles}, missingBackups=${result.missingBackups}, skipped=${result.skippedEntries}`
4793
- );
4794
- if (result.restored.length > 0) {
4795
- const preview = result.restored.slice(0, 5);
4796
- for (const file of preview) {
4797
- logger_default.info(` - ${formatPathForLog(file)}`);
4798
- }
4799
- if (result.restored.length > preview.length) {
4800
- logger_default.info(` ...and ${result.restored.length - preview.length} more`);
4801
- }
4802
- }
4803
- }
4804
- function logValidateSuccessAsJson(result) {
4805
- const payload = {
4806
- ok: true,
4807
- ...result
4808
- };
4809
- logger_default.log(JSON.stringify(payload, null, 2));
4810
- }
4811
- function logValidateSuccessSummary(result) {
4812
- logger_default.success(
4813
- `Migration report validated: scanned=${result.scannedEntries}, restorable=${result.restorableEntries}, missingBackups=${result.missingBackups}, skipped=${result.skippedEntries}`
4814
- );
4815
- if (result.reportKind || result.reportSchemaVersion !== void 0) {
4816
- const kind = _nullishCoalesce(result.reportKind, () => ( "unknown"));
4817
- const schema = result.reportSchemaVersion === void 0 ? "unknown" : String(result.reportSchemaVersion);
4818
- logger_default.info(` metadata: kind=${kind}, schema=${schema}`);
4819
- }
4820
- }
4821
- function logValidateFailureAsJson(summary) {
4822
- const payload = {
4823
- ok: false,
4824
- reason: summary.reason,
4825
- exitCode: summary.exitCode,
4826
- message: summary.message
4827
- };
4828
- logger_default.log(JSON.stringify(payload, null, 2));
4829
- }
4830
- function logValidateFailureSummary(summary) {
4831
- logger_default.error(`Validation failed [${summary.reason}] (exit ${summary.exitCode}): ${summary.message}`);
4832
- }
4833
-
4834
- // src/commands/migrate-handler.ts
4835
- async function migrateCommandDefaultHandler(ctx) {
4836
- const { args } = ctx;
4837
- const {
4838
- include,
4839
- exclude,
4840
- maxDepth,
4841
- checkMode,
4842
- dryRun,
4843
- hasInvalidMaxDepth
4844
- } = resolveMigrateCommandArgs(args);
4845
- if (args.workspace && hasInvalidMaxDepth) {
4846
- logger_default.warn(`Invalid --max-depth value "${String(args.maxDepth)}", fallback to default depth.`);
4847
- }
4848
- const report = await migrateConfigFiles({
4849
- cwd: ctx.cwd,
4850
- dryRun,
4851
- ...args.config ? { files: [args.config] } : {},
4852
- ...args.workspace ? { workspace: true } : {},
4853
- ...args.workspace && maxDepth !== void 0 ? { maxDepth } : {},
4854
- ...args.backupDir ? { backupDir: args.backupDir } : {},
4855
- ...include ? { include } : {},
4856
- ...exclude ? { exclude } : {}
4857
- });
4858
- if (args.reportFile) {
4859
- await writeMigrationReportFile(ctx.cwd, args.reportFile, report);
4860
- }
4861
- if (args.json) {
4862
- logMigrationReportAsJson(report);
4863
- if (checkMode && report.changedFiles > 0) {
4864
- throw createMigrationCheckFailureError(report.changedFiles);
4865
- }
4866
- if (report.scannedFiles === 0) {
4867
- logNoMigrationConfigFilesWarning();
4868
- }
4869
- return report;
4870
- }
4871
- if (report.scannedFiles === 0) {
4872
- logNoMigrationConfigFilesWarning();
4873
- return report;
4874
- }
4875
- logMigrationEntries(report, dryRun);
4876
- logMigrationSummary(report);
4877
- if (checkMode && report.changedFiles > 0) {
4878
- throw createMigrationCheckFailureError(report.changedFiles);
4879
- }
4880
- return report;
4881
- }
4882
-
4883
- // src/commands/restore-handler.ts
4884
- async function restoreCommandDefaultHandler(ctx) {
4885
- const { args } = ctx;
4886
- const restoreArgs = resolveRestoreCommandArgs(args);
4887
- const result = await restoreConfigFiles({
4888
- cwd: ctx.cwd,
4889
- reportFile: restoreArgs.reportFile,
4890
- dryRun: restoreArgs.dryRun,
4891
- strict: restoreArgs.strict
4892
- });
4893
- if (args.json) {
4894
- logRestoreResultAsJson(result);
4895
- return result;
4896
- }
4897
- logRestoreSummary(result);
4898
- return result;
4899
- }
4900
-
4901
- // src/commands/status-output.ts
4902
- function formatFilesHint(entry) {
4903
- if (!entry.files.length) {
4904
- return "";
4905
- }
4906
- return ` (${entry.files.join(", ")})`;
4907
- }
4908
- function formatPackageLabel(report) {
4909
- return `${_nullishCoalesce(report.package.name, () => ( "tailwindcss"))}@${_nullishCoalesce(report.package.version, () => ( "unknown"))}`;
4910
- }
4911
- function partitionStatusEntries(report) {
4912
- return {
4913
- applied: report.entries.filter((entry) => entry.status === "applied"),
4914
- pending: report.entries.filter((entry) => entry.status === "not-applied"),
4915
- skipped: report.entries.filter((entry) => entry.status === "skipped" || entry.status === "unsupported")
4916
- };
4917
- }
4918
- function logStatusReportAsJson(report) {
4919
- logger_default.log(JSON.stringify(report, null, 2));
4920
- }
4921
- function logStatusReportSummary(report) {
4922
- const {
4923
- applied,
4924
- pending,
4925
- skipped
4926
- } = partitionStatusEntries(report);
4927
- logger_default.info(`Patch status for ${formatPackageLabel(report)} (v${report.majorVersion})`);
4928
- if (applied.length) {
4929
- logger_default.success("Applied:");
4930
- applied.forEach((entry) => logger_default.success(` \u2022 ${entry.name}${formatFilesHint(entry)}`));
4931
- }
4932
- if (pending.length) {
4933
- logger_default.warn("Needs attention:");
4934
- pending.forEach((entry) => {
4935
- const details = entry.reason ? ` - ${entry.reason}` : "";
4936
- logger_default.warn(` \u2022 ${entry.name}${formatFilesHint(entry)}${details}`);
4937
- });
4938
- } else {
4939
- logger_default.success("All applicable patches are applied.");
4940
- }
4941
- if (skipped.length) {
4942
- logger_default.info("Skipped:");
4943
- skipped.forEach((entry) => {
4944
- const details = entry.reason ? ` - ${entry.reason}` : "";
4945
- logger_default.info(` \u2022 ${entry.name}${details}`);
4946
- });
4947
- }
4948
- }
4949
-
4950
- // src/commands/status-handler.ts
4951
- async function statusCommandDefaultHandler(ctx) {
4952
- const patcher = await ctx.createPatcher();
4953
- const report = await patcher.getPatchStatus();
4954
- if (ctx.args.json) {
4955
- logStatusReportAsJson(report);
4956
- return report;
4957
- }
4958
- logStatusReportSummary(report);
4959
- return report;
4960
- }
4961
-
4962
- // src/commands/validate-handler.ts
4963
- async function validateCommandDefaultHandler(ctx) {
4964
- const { args } = ctx;
4965
- const validateArgs = resolveValidateCommandArgs(args);
4966
- try {
4967
- const result = await restoreConfigFiles({
4968
- cwd: ctx.cwd,
4969
- reportFile: validateArgs.reportFile,
4970
- dryRun: true,
4971
- strict: validateArgs.strict
4972
- });
4973
- if (args.json) {
4974
- logValidateSuccessAsJson(result);
4975
- return result;
4976
- }
4977
- logValidateSuccessSummary(result);
4978
- return result;
4979
- } catch (error) {
4980
- const summary = classifyValidateError(error);
4981
- if (args.json) {
4982
- logValidateFailureAsJson(summary);
4983
- } else {
4984
- logValidateFailureSummary(summary);
4985
- }
4986
- throw new ValidateCommandError(summary, { cause: error });
4987
- }
4988
- }
4989
-
4990
- // src/commands/default-handler-map.ts
4991
- var defaultCommandHandlers = {
4992
- install: installCommandDefaultHandler,
4993
- extract: extractCommandDefaultHandler,
4994
- tokens: tokensCommandDefaultHandler,
4995
- init: initCommandDefaultHandler,
4996
- migrate: migrateCommandDefaultHandler,
4997
- restore: restoreCommandDefaultHandler,
4998
- validate: validateCommandDefaultHandler,
4999
- status: statusCommandDefaultHandler
5000
- };
5001
-
5002
- // src/commands/command-registrar.ts
5003
- function registerTailwindcssPatchCommand(cli, commandName, options, prefix, defaultDefinitions) {
5004
- const metadata = resolveCommandMetadata(commandName, options, prefix, defaultDefinitions);
5005
- const command = cli.command(metadata.name, metadata.description);
5006
- applyCommandOptions(command, metadata.optionDefs);
5007
- command.action(async (args) => {
5008
- const defaultHandler = defaultCommandHandlers[commandName];
5009
- return runWithCommandHandler(
5010
- cli,
5011
- command,
5012
- commandName,
5013
- args,
5014
- _optionalChain([options, 'access', _129 => _129.commandHandlers, 'optionalAccess', _130 => _130[commandName]]),
5015
- defaultHandler
5016
- );
5017
- });
5018
- metadata.aliases.forEach((alias) => command.alias(alias));
5019
- }
5020
-
5021
- // src/commands/cli.ts
5022
- function mountTailwindcssPatchCommands(cli, options = {}) {
5023
- const prefix = _nullishCoalesce(options.commandPrefix, () => ( ""));
5024
- const selectedCommands = _nullishCoalesce(options.commands, () => ( tailwindcssPatchCommands));
5025
- const defaultDefinitions = buildDefaultCommandDefinitions();
5026
- for (const name of selectedCommands) {
5027
- registerTailwindcssPatchCommand(cli, name, options, prefix, defaultDefinitions);
5028
- }
5029
- return cli;
5030
- }
5031
- function createTailwindcssPatchCli(options = {}) {
5032
- const cli = _cac2.default.call(void 0, _nullishCoalesce(options.name, () => ( "tw-patch")));
5033
- mountTailwindcssPatchCommands(cli, options.mountOptions);
5034
- return cli;
5035
- }
5036
4345
 
5037
4346
 
5038
4347
 
@@ -5059,4 +4368,4 @@ function createTailwindcssPatchCli(options = {}) {
5059
4368
 
5060
4369
 
5061
4370
 
5062
- exports.logger_default = logger_default; exports.CacheStore = CacheStore; exports.normalizeOptions = normalizeOptions; exports.extractRawCandidatesWithPositions = extractRawCandidatesWithPositions; exports.extractRawCandidates = extractRawCandidates; exports.extractValidCandidates = extractValidCandidates; exports.extractProjectCandidatesWithPositions = extractProjectCandidatesWithPositions; exports.groupTokensByFile = groupTokensByFile; exports.collectClassesFromContexts = collectClassesFromContexts; exports.collectClassesFromTailwindV4 = collectClassesFromTailwindV4; exports.loadRuntimeContexts = loadRuntimeContexts; exports.runTailwindBuild = runTailwindBuild; exports.getPatchStatusReport = getPatchStatusReport; exports.TailwindcssPatcher = TailwindcssPatcher; exports.MIGRATION_REPORT_KIND = MIGRATION_REPORT_KIND; exports.MIGRATION_REPORT_SCHEMA_VERSION = MIGRATION_REPORT_SCHEMA_VERSION; exports.migrateConfigFiles = migrateConfigFiles; exports.restoreConfigFiles = restoreConfigFiles; exports.VALIDATE_EXIT_CODES = VALIDATE_EXIT_CODES; exports.VALIDATE_FAILURE_REASONS = VALIDATE_FAILURE_REASONS; exports.ValidateCommandError = ValidateCommandError; exports.tailwindcssPatchCommands = tailwindcssPatchCommands; exports.mountTailwindcssPatchCommands = mountTailwindcssPatchCommands; exports.createTailwindcssPatchCli = createTailwindcssPatchCli;
4371
+ exports.logger_default = logger_default; exports.CacheStore = CacheStore; exports.normalizeOptions = normalizeOptions; exports.loadWorkspaceConfigModule = loadWorkspaceConfigModule; exports.loadPatchOptionsForWorkspace = loadPatchOptionsForWorkspace; exports.extractRawCandidatesWithPositions = extractRawCandidatesWithPositions; exports.extractRawCandidates = extractRawCandidates; exports.extractValidCandidates = extractValidCandidates; exports.extractProjectCandidatesWithPositions = extractProjectCandidatesWithPositions; exports.groupTokensByFile = groupTokensByFile; exports.collectClassesFromContexts = collectClassesFromContexts; exports.collectClassesFromTailwindV4 = collectClassesFromTailwindV4; exports.loadRuntimeContexts = loadRuntimeContexts; exports.runTailwindBuild = runTailwindBuild; exports.getPatchStatusReport = getPatchStatusReport; exports.TailwindcssPatcher = TailwindcssPatcher; exports.MIGRATION_REPORT_KIND = MIGRATION_REPORT_KIND; exports.MIGRATION_REPORT_SCHEMA_VERSION = MIGRATION_REPORT_SCHEMA_VERSION; exports.migrateConfigFiles = migrateConfigFiles; exports.restoreConfigFiles = restoreConfigFiles; exports.tailwindcssPatchCommands = tailwindcssPatchCommands; exports.VALIDATE_EXIT_CODES = VALIDATE_EXIT_CODES; exports.VALIDATE_FAILURE_REASONS = VALIDATE_FAILURE_REASONS; exports.classifyValidateError = classifyValidateError; exports.ValidateCommandError = ValidateCommandError;