tailwind-unwind 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +97 -252
- package/dist/{chunk-4GXMK3NB.js → chunk-UXXIEFP4.js} +351 -101
- package/dist/chunk-UXXIEFP4.js.map +1 -0
- package/dist/cli/index.js +60 -6
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +71 -27
- package/dist/index.js +11 -1
- package/package.json +3 -2
- package/dist/chunk-4GXMK3NB.js.map +0 -1
package/dist/cli/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/cli/index.ts","../../src/cli/defaults.ts","../../src/cli/parseOptions.ts","../../src/cli/version.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { Command } from 'commander';\nimport chalk from 'chalk';\nimport { analyzeCommand } from '../commands/analyze.js';\nimport { applyCommand } from '../commands/apply.js';\nimport { generateCommand } from '../commands/generate.js';\nimport { ANALYZE_DEFAULTS, GENERATE_DEFAULTS } from './defaults.js';\nimport { resolveCommandOptions, withNumericDefaults } from './parseOptions.js';\nimport { CLI_VERSION } from './version.js';\n\nconst program = new Command();\n\nfunction addSharedOptions(command: Command): Command {\n return command\n .option('--config <file>', 'Path to tailwind-unwind config file')\n .option(\n '--include <patterns>',\n 'Comma-separated glob include patterns (e.g. \"src/**/*.tsx\")',\n )\n .option(\n '--exclude <patterns>',\n 'Comma-separated glob exclude patterns (e.g. \"**/*.test.tsx\")',\n );\n}\n\nprogram\n .name('tailwind-unwind')\n .description('Analyze Tailwind CSS class usage in React/Next.js projects')\n .version(CLI_VERSION);\n\naddSharedOptions(\n program\n .command('analyze')\n .description('Scan a directory and report frequent Tailwind class combinations')\n .argument('<path>', 'Directory to analyze')\n .option('--min-occurrences <n>', 'Minimum occurrences threshold')\n .option('--min-size <n>', 'Minimum classes per combination')\n .option('--max-size <n>', 'Maximum classes per combination')\n .option('--top <n>', 'Number of top combinations to show')\n .option('--format <type>', 'Output format: console or json', 'console')\n .option('--no-dedupe-subsets', 'Include subset combinations in results'),\n).action(async (targetPath: string, opts) => {\n try {\n const resolved = withNumericDefaults(\n await resolveCommandOptions('analyze', opts, targetPath),\n opts,\n ANALYZE_DEFAULTS,\n );\n\n await analyzeCommand(targetPath, {\n minOccurrences: resolved.minOccurrences,\n minSize: resolved.minSize,\n maxSize: resolved.maxSize,\n top: resolved.top,\n format: resolved.format,\n dedupeSubsets: process.argv.includes('--no-dedupe-subsets')\n ? false\n : (resolved.dedupeSubsets ?? true),\n include: resolved.include,\n exclude: resolved.exclude,\n configPath: resolved.configPath,\n });\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n console.error('Unexpected error:', message);\n process.exit(1);\n }\n});\n\naddSharedOptions(\n program\n .command('generate')\n .description('Generate @layer components CSS from repeated className sets')\n .argument('[path]', 'Directory to analyze')\n .option('--output <file>', 'Output CSS file path')\n .option('--from-report <file>', 'Generate from analyze JSON report')\n .option('--extractable-only', 'Only generate extractable patterns from analyze')\n .option('--format <type>', 'Output format: console or json', 'console')\n .option('--min-occurrences <n>', 'Minimum occurrences threshold')\n .option('--min-size <n>', 'Minimum classes per combination')\n .option('--max-size <n>', 'Maximum classes per combination')\n .option('--top <n>', 'Number of combinations to generate')\n .option('--prefix <name>', 'Namespace prefix for generated classes'),\n).action(async (targetPath: string | undefined, opts) => {\n try {\n const resolved = withNumericDefaults(\n await resolveCommandOptions('generate', opts, targetPath),\n opts,\n GENERATE_DEFAULTS,\n );\n const output = opts.output ?? resolved.output;\n const scanPath = targetPath ?? '.';\n\n if (!output) {\n console.error(chalk.red('Error: --output is required'));\n process.exit(1);\n }\n\n if (!opts.fromReport && !resolved.fromReport && !targetPath) {\n console.error(chalk.red('Error: <path> is required without --from-report'));\n process.exit(1);\n }\n\n await generateCommand(scanPath, {\n output,\n minOccurrences: resolved.minOccurrences,\n minSize: resolved.minSize,\n maxSize: resolved.maxSize,\n top: resolved.top,\n prefix: resolved.prefix,\n include: resolved.include,\n exclude: resolved.exclude,\n configPath: resolved.configPath,\n names: resolved.names,\n format: resolved.format,\n fromReport: opts.fromReport ?? resolved.fromReport,\n extractableOnly: Boolean(opts.extractableOnly || resolved.extractableOnly),\n });\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n console.error('Unexpected error:', message);\n process.exit(1);\n }\n});\n\naddSharedOptions(\n program\n .command('apply')\n .description('Replace repeated className strings with generated component classes')\n .argument('<path>', 'Directory to modify')\n .option('--output <file>', 'Output CSS file path')\n .option('--from-report <file>', 'Use component list from analyze JSON report')\n .option('--extractable-only', 'Only apply extractable patterns from analyze')\n .option('--format <type>', 'Output format: console or json', 'console')\n .option('--prettier', 'Format modified files with Prettier when available')\n .option('--min-occurrences <n>', 'Minimum occurrences threshold')\n .option('--min-size <n>', 'Minimum classes per combination')\n .option('--max-size <n>', 'Maximum classes per combination')\n .option('--top <n>', 'Number of component classes to use')\n .option('--dry-run', 'Preview replacements without writing files')\n .option('--prefix <name>', 'Namespace prefix for generated classes'),\n).action(async (targetPath: string, opts) => {\n try {\n const resolved = withNumericDefaults(\n await resolveCommandOptions('apply', opts, targetPath),\n opts,\n GENERATE_DEFAULTS,\n );\n const output = opts.output ?? resolved.output;\n\n if (!output) {\n console.error(chalk.red('Error: --output is required'));\n process.exit(1);\n }\n\n await applyCommand(targetPath, {\n output,\n minOccurrences: resolved.minOccurrences,\n minSize: resolved.minSize,\n maxSize: resolved.maxSize,\n top: resolved.top,\n prefix: resolved.prefix,\n include: resolved.include,\n exclude: resolved.exclude,\n configPath: resolved.configPath,\n names: resolved.names,\n format: resolved.format,\n fromReport: opts.fromReport ?? resolved.fromReport,\n extractableOnly: Boolean(opts.extractableOnly || resolved.extractableOnly),\n dryRun: process.argv.includes('--dry-run')\n ? true\n : Boolean(resolved.dryRun),\n prettier: Boolean(opts.prettier || resolved.prettier),\n });\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n console.error('Unexpected error:', message);\n process.exit(1);\n }\n});\n\nprogram.parse();\n","export const ANALYZE_DEFAULTS = {\n minOccurrences: 5,\n minSize: 2,\n maxSize: 5,\n top: 10,\n} as const;\n\nexport const GENERATE_DEFAULTS = {\n minOccurrences: 3,\n minSize: 2,\n maxSize: 5,\n top: 10,\n prefix: 'twu-',\n} as const;\n","import { loadCommandOptions } from '../config/loadConfig.js';\nimport type { CliCommand } from '../config/types.js';\nimport type { AnalyzeOptions } from '../parser/types.js';\n\nfunction splitPatterns(value: unknown): string[] | undefined {\n if (typeof value !== 'string' || value.trim().length === 0) {\n return undefined;\n }\n\n return value\n .split(',')\n .map((part) => part.trim())\n .filter((part) => part.length > 0);\n}\n\nfunction optionalNumber(value: unknown): number | undefined {\n if (value === undefined || value === null || value === '') {\n return undefined;\n }\n\n const parsed = Number(value);\n return Number.isFinite(parsed) ? parsed : undefined;\n}\n\nexport interface RawCliOptions {\n config?: string;\n minOccurrences?: string | number;\n minSize?: string | number;\n maxSize?: string | number;\n top?: string | number;\n prefix?: string;\n dedupeSubsets?: boolean;\n include?: string;\n exclude?: string;\n output?: string;\n format?: string;\n dryRun?: boolean;\n prettier?: boolean;\n fromReport?: string;\n extractableOnly?: boolean;\n}\n\nfunction cliNumber(\n value: string | number | undefined,\n fallback: number,\n): number {\n const parsed = optionalNumber(value);\n return parsed ?? fallback;\n}\n\n/**\n * Merge config file values with CLI flags (CLI wins).\n */\nexport async function resolveCommandOptions(\n command: CliCommand,\n opts: RawCliOptions,\n targetPath?: string,\n): Promise<\n AnalyzeOptions & { output?: string; dryRun?: boolean; names?: Record<string, string> }\n> {\n const resolved = await loadCommandOptions(\n command,\n {\n configPath: opts.config,\n minOccurrences: optionalNumber(opts.minOccurrences),\n minSize: optionalNumber(opts.minSize),\n maxSize: optionalNumber(opts.maxSize),\n top: optionalNumber(opts.top),\n prefix: opts.prefix,\n dedupeSubsets: opts.dedupeSubsets,\n include: splitPatterns(opts.include),\n exclude: splitPatterns(opts.exclude),\n output: opts.output,\n dryRun: opts.dryRun,\n prettier: opts.prettier,\n fromReport: opts.fromReport,\n extractableOnly: opts.extractableOnly,\n },\n { targetPath },\n );\n\n return {\n minOccurrences: resolved.minOccurrences,\n minSize: resolved.minSize,\n maxSize: resolved.maxSize,\n top: resolved.top,\n prefix: resolved.prefix,\n dedupeSubsets: resolved.dedupeSubsets,\n include: resolved.include,\n exclude: resolved.exclude,\n configPath: resolved.configPath,\n output: resolved.output,\n names: resolved.names,\n format: opts.format === 'json' ? 'json' : 'console',\n dryRun: opts.dryRun ?? resolved.dryRun,\n prettier: opts.prettier ?? resolved.prettier,\n fromReport: opts.fromReport ?? resolved.fromReport,\n extractableOnly: opts.extractableOnly ?? resolved.extractableOnly,\n };\n}\n\nexport function withNumericDefaults(\n resolved: Awaited<ReturnType<typeof resolveCommandOptions>>,\n opts: RawCliOptions,\n defaults: {\n minOccurrences: number;\n minSize: number;\n maxSize: number;\n top: number;\n prefix?: string;\n },\n) {\n return {\n ...resolved,\n minOccurrences:\n resolved.minOccurrences ??\n cliNumber(opts.minOccurrences, defaults.minOccurrences),\n minSize: resolved.minSize ?? cliNumber(opts.minSize, defaults.minSize),\n maxSize: resolved.maxSize ?? cliNumber(opts.maxSize, defaults.maxSize),\n top: resolved.top ?? cliNumber(opts.top, defaults.top),\n prefix: resolved.prefix ?? opts.prefix ?? defaults.prefix,\n };\n}\n\n/** @deprecated Use resolveCommandOptions */\nexport const resolveAnalyzeOptions = (\n opts: RawCliOptions,\n targetPath?: string,\n) => resolveCommandOptions('analyze', opts, targetPath);\n","import { readFileSync } from 'node:fs';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nfunction readPackageVersion(): string {\n const currentDir = path.dirname(fileURLToPath(import.meta.url));\n const packageJsonPath = path.join(currentDir, '../../package.json');\n const raw = readFileSync(packageJsonPath, 'utf-8');\n const pkg = JSON.parse(raw) as { version?: string };\n return pkg.version ?? '0.0.0';\n}\n\nexport const CLI_VERSION = readPackageVersion();\n"],"mappings":";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AAAA,IACtD,CAAC;AAAA,EACH,SAAS,OAAO;AACd,UAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AACrE,YAAQ,MAAM,qBAAqB,OAAO;AAC1C,YAAQ,KAAK,CAAC;AAAA,EAChB;AACF,CAAC;AAED,QAAQ,MAAM;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/cli/index.ts","../../src/cli/defaults.ts","../../src/cli/parseOptions.ts","../../src/cli/version.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { Command } from 'commander';\nimport chalk from 'chalk';\nimport { analyzeCommand } from '../commands/analyze.js';\nimport { applyCommand } from '../commands/apply.js';\nimport { generateCommand } from '../commands/generate.js';\nimport { initCommand } from '../commands/init.js';\nimport { ANALYZE_DEFAULTS, GENERATE_DEFAULTS } from './defaults.js';\nimport { resolveCommandOptions, withNumericDefaults } from './parseOptions.js';\nimport { CLI_VERSION } from './version.js';\n\nconst program = new Command();\n\nfunction addSharedOptions(command: Command): Command {\n return command\n .option('--config <file>', 'Path to tailwind-unwind config file')\n .option(\n '--include <patterns>',\n 'Comma-separated glob include patterns (e.g. \"src/**/*.tsx\")',\n )\n .option(\n '--exclude <patterns>',\n 'Comma-separated glob exclude patterns (e.g. \"**/*.test.tsx\")',\n )\n .option(\n '--changed [ref]',\n 'Only scan git-changed files (optional ref, default: working tree vs HEAD)',\n );\n}\n\nfunction resolveChangedFlag(opts: { changed?: string | boolean }): boolean | string | undefined {\n if (!process.argv.includes('--changed')) {\n return undefined;\n }\n\n if (typeof opts.changed === 'string' && opts.changed.length > 0) {\n return opts.changed;\n }\n\n return true;\n}\n\nprogram\n .name('tailwind-unwind')\n .description('Analyze Tailwind CSS class usage in React/Next.js projects')\n .version(CLI_VERSION);\n\nprogram\n .command('init')\n .description('Create a starter tailwind-unwind.config.json from project scan')\n .argument('<path>', 'Project directory')\n .option('--output <file>', 'Config output path')\n .option('--force', 'Overwrite existing config file')\n .option('--min-occurrences <n>', 'Minimum occurrences threshold')\n .option('--top <n>', 'Number of patterns to include in names')\n .option('--prefix <name>', 'Namespace prefix for generated classes')\n .action(async (targetPath: string, opts) => {\n try {\n const resolved = withNumericDefaults(\n await resolveCommandOptions('init', opts, targetPath),\n opts,\n ANALYZE_DEFAULTS,\n );\n\n await initCommand(targetPath, {\n output: opts.output ?? resolved.output,\n force: Boolean(opts.force || resolved.force),\n minOccurrences: resolved.minOccurrences,\n top: resolved.top,\n prefix: resolved.prefix ?? GENERATE_DEFAULTS.prefix,\n include: resolved.include,\n exclude: resolved.exclude,\n });\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n console.error(chalk.red(`Error: ${message}`));\n process.exit(1);\n }\n });\n\naddSharedOptions(\n program\n .command('analyze')\n .description('Scan a directory and report frequent Tailwind class combinations')\n .argument('<path>', 'Directory to analyze')\n .option('--min-occurrences <n>', 'Minimum occurrences threshold')\n .option('--min-size <n>', 'Minimum classes per combination')\n .option('--max-size <n>', 'Maximum classes per combination')\n .option('--top <n>', 'Number of top combinations to show')\n .option('--format <type>', 'Output format: console or json', 'console')\n .option('--no-dedupe-subsets', 'Include subset combinations in results'),\n).action(async (targetPath: string, opts) => {\n try {\n const resolved = withNumericDefaults(\n await resolveCommandOptions('analyze', { ...opts, changed: resolveChangedFlag(opts) }, targetPath),\n opts,\n ANALYZE_DEFAULTS,\n );\n\n await analyzeCommand(targetPath, {\n minOccurrences: resolved.minOccurrences,\n minSize: resolved.minSize,\n maxSize: resolved.maxSize,\n top: resolved.top,\n format: resolved.format,\n dedupeSubsets: process.argv.includes('--no-dedupe-subsets')\n ? false\n : (resolved.dedupeSubsets ?? true),\n include: resolved.include,\n exclude: resolved.exclude,\n changed: resolved.changed,\n configPath: resolved.configPath,\n });\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n console.error('Unexpected error:', message);\n process.exit(1);\n }\n});\n\naddSharedOptions(\n program\n .command('generate')\n .description('Generate @layer components CSS from repeated className sets')\n .argument('[path]', 'Directory to analyze')\n .option('--output <file>', 'Output CSS file path')\n .option('--from-report <file>', 'Generate from analyze JSON report')\n .option('--extractable-only', 'Only generate extractable patterns from analyze')\n .option('--format <type>', 'Output format: console or json', 'console')\n .option('--min-occurrences <n>', 'Minimum occurrences threshold')\n .option('--min-size <n>', 'Minimum classes per combination')\n .option('--max-size <n>', 'Maximum classes per combination')\n .option('--top <n>', 'Number of combinations to generate')\n .option('--prefix <name>', 'Namespace prefix for generated classes'),\n).action(async (targetPath: string | undefined, opts) => {\n try {\n const resolved = withNumericDefaults(\n await resolveCommandOptions('generate', { ...opts, changed: resolveChangedFlag(opts) }, targetPath),\n opts,\n GENERATE_DEFAULTS,\n );\n const output = opts.output ?? resolved.output;\n const scanPath = targetPath ?? '.';\n\n if (!output) {\n console.error(chalk.red('Error: --output is required'));\n process.exit(1);\n }\n\n if (!opts.fromReport && !resolved.fromReport && !targetPath) {\n console.error(chalk.red('Error: <path> is required without --from-report'));\n process.exit(1);\n }\n\n await generateCommand(scanPath, {\n output,\n minOccurrences: resolved.minOccurrences,\n minSize: resolved.minSize,\n maxSize: resolved.maxSize,\n top: resolved.top,\n prefix: resolved.prefix,\n include: resolved.include,\n exclude: resolved.exclude,\n changed: resolved.changed,\n configPath: resolved.configPath,\n names: resolved.names,\n format: resolved.format,\n fromReport: opts.fromReport ?? resolved.fromReport,\n extractableOnly: Boolean(opts.extractableOnly || resolved.extractableOnly),\n });\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n console.error('Unexpected error:', message);\n process.exit(1);\n }\n});\n\naddSharedOptions(\n program\n .command('apply')\n .description('Replace repeated className strings with generated component classes')\n .argument('<path>', 'Directory to modify')\n .option('--output <file>', 'Output CSS file path')\n .option('--from-report <file>', 'Use component list from analyze JSON report')\n .option('--extractable-only', 'Only apply extractable patterns from analyze')\n .option('--format <type>', 'Output format: console or json', 'console')\n .option('--prettier', 'Format modified files with Prettier when available')\n .option('--min-occurrences <n>', 'Minimum occurrences threshold')\n .option('--min-size <n>', 'Minimum classes per combination')\n .option('--max-size <n>', 'Maximum classes per combination')\n .option('--top <n>', 'Number of component classes to use')\n .option('--dry-run', 'Preview replacements without writing files')\n .option('--prefix <name>', 'Namespace prefix for generated classes'),\n).action(async (targetPath: string, opts) => {\n try {\n const resolved = withNumericDefaults(\n await resolveCommandOptions('apply', { ...opts, changed: resolveChangedFlag(opts) }, targetPath),\n opts,\n GENERATE_DEFAULTS,\n );\n const output = opts.output ?? resolved.output;\n\n if (!output) {\n console.error(chalk.red('Error: --output is required'));\n process.exit(1);\n }\n\n await applyCommand(targetPath, {\n output,\n minOccurrences: resolved.minOccurrences,\n minSize: resolved.minSize,\n maxSize: resolved.maxSize,\n top: resolved.top,\n prefix: resolved.prefix,\n include: resolved.include,\n exclude: resolved.exclude,\n changed: resolved.changed,\n configPath: resolved.configPath,\n names: resolved.names,\n format: resolved.format,\n fromReport: opts.fromReport ?? resolved.fromReport,\n extractableOnly: Boolean(opts.extractableOnly || resolved.extractableOnly),\n dryRun: process.argv.includes('--dry-run')\n ? true\n : Boolean(resolved.dryRun),\n prettier: Boolean(opts.prettier || resolved.prettier),\n });\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n console.error('Unexpected error:', message);\n process.exit(1);\n }\n});\n\nprogram.parse();\n","export const ANALYZE_DEFAULTS = {\n minOccurrences: 5,\n minSize: 2,\n maxSize: 5,\n top: 10,\n} as const;\n\nexport const GENERATE_DEFAULTS = {\n minOccurrences: 3,\n minSize: 2,\n maxSize: 5,\n top: 10,\n prefix: 'twu-',\n} as const;\n","import { loadCommandOptions } from '../config/loadConfig.js';\nimport type { CliCommand } from '../config/types.js';\nimport type { AnalyzeOptions } from '../parser/types.js';\n\nfunction splitPatterns(value: unknown): string[] | undefined {\n if (typeof value !== 'string' || value.trim().length === 0) {\n return undefined;\n }\n\n return value\n .split(',')\n .map((part) => part.trim())\n .filter((part) => part.length > 0);\n}\n\nfunction optionalNumber(value: unknown): number | undefined {\n if (value === undefined || value === null || value === '') {\n return undefined;\n }\n\n const parsed = Number(value);\n return Number.isFinite(parsed) ? parsed : undefined;\n}\n\nexport interface RawCliOptions {\n config?: string;\n minOccurrences?: string | number;\n minSize?: string | number;\n maxSize?: string | number;\n top?: string | number;\n prefix?: string;\n dedupeSubsets?: boolean;\n include?: string;\n exclude?: string;\n output?: string;\n format?: string;\n dryRun?: boolean;\n prettier?: boolean;\n fromReport?: string;\n extractableOnly?: boolean;\n changed?: string | boolean;\n force?: boolean;\n}\n\nfunction cliNumber(\n value: string | number | undefined,\n fallback: number,\n): number {\n const parsed = optionalNumber(value);\n return parsed ?? fallback;\n}\n\n/**\n * Merge config file values with CLI flags (CLI wins).\n */\nexport async function resolveCommandOptions(\n command: CliCommand,\n opts: RawCliOptions,\n targetPath?: string,\n): Promise<\n AnalyzeOptions & { output?: string; dryRun?: boolean; names?: Record<string, string> }\n> {\n const resolved = await loadCommandOptions(\n command,\n {\n configPath: opts.config,\n minOccurrences: optionalNumber(opts.minOccurrences),\n minSize: optionalNumber(opts.minSize),\n maxSize: optionalNumber(opts.maxSize),\n top: optionalNumber(opts.top),\n prefix: opts.prefix,\n dedupeSubsets: opts.dedupeSubsets,\n include: splitPatterns(opts.include),\n exclude: splitPatterns(opts.exclude),\n output: opts.output,\n dryRun: opts.dryRun,\n prettier: opts.prettier,\n fromReport: opts.fromReport,\n extractableOnly: opts.extractableOnly,\n changed: parseChanged(opts.changed),\n force: opts.force,\n },\n { targetPath },\n );\n\n return {\n minOccurrences: resolved.minOccurrences,\n minSize: resolved.minSize,\n maxSize: resolved.maxSize,\n top: resolved.top,\n prefix: resolved.prefix,\n dedupeSubsets: resolved.dedupeSubsets,\n include: resolved.include,\n exclude: resolved.exclude,\n configPath: resolved.configPath,\n output: resolved.output,\n names: resolved.names,\n format: opts.format === 'json' ? 'json' : 'console',\n dryRun: opts.dryRun ?? resolved.dryRun,\n prettier: opts.prettier ?? resolved.prettier,\n fromReport: opts.fromReport ?? resolved.fromReport,\n extractableOnly: opts.extractableOnly ?? resolved.extractableOnly,\n changed: parseChanged(opts.changed) ?? resolved.changed,\n force: opts.force ?? resolved.force,\n };\n}\n\nfunction parseChanged(value: unknown): boolean | string | undefined {\n if (value === undefined || value === null || value === '') {\n return undefined;\n }\n\n if (value === true || value === 'true') {\n return true;\n }\n\n if (typeof value === 'string') {\n return value;\n }\n\n return undefined;\n}\n\nexport function withNumericDefaults(\n resolved: Awaited<ReturnType<typeof resolveCommandOptions>>,\n opts: RawCliOptions,\n defaults: {\n minOccurrences: number;\n minSize: number;\n maxSize: number;\n top: number;\n prefix?: string;\n },\n) {\n return {\n ...resolved,\n minOccurrences:\n resolved.minOccurrences ??\n cliNumber(opts.minOccurrences, defaults.minOccurrences),\n minSize: resolved.minSize ?? cliNumber(opts.minSize, defaults.minSize),\n maxSize: resolved.maxSize ?? cliNumber(opts.maxSize, defaults.maxSize),\n top: resolved.top ?? cliNumber(opts.top, defaults.top),\n prefix: resolved.prefix ?? opts.prefix ?? defaults.prefix,\n };\n}\n\n/** @deprecated Use resolveCommandOptions */\nexport const resolveAnalyzeOptions = (\n opts: RawCliOptions,\n targetPath?: string,\n) => resolveCommandOptions('analyze', opts, targetPath);\n","import { readFileSync } from 'node:fs';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nfunction readPackageVersion(): string {\n const currentDir = path.dirname(fileURLToPath(import.meta.url));\n const packageJsonPath = path.join(currentDir, '../../package.json');\n const raw = readFileSync(packageJsonPath, 'utf-8');\n const pkg = JSON.parse(raw) as { version?: string };\n return pkg.version ?? '0.0.0';\n}\n\nexport const CLI_VERSION = readPackageVersion();\n"],"mappings":";;;;;;;;;;AAEA,SAAS,eAAe;AACxB,OAAO,WAAW;;;ACHX,IAAM,mBAAmB;AAAA,EAC9B,gBAAgB;AAAA,EAChB,SAAS;AAAA,EACT,SAAS;AAAA,EACT,KAAK;AACP;AAEO,IAAM,oBAAoB;AAAA,EAC/B,gBAAgB;AAAA,EAChB,SAAS;AAAA,EACT,SAAS;AAAA,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C,iBAAiB,QAAQ,KAAK,mBAAmB,SAAS,eAAe;AAAA,MACzE,QAAQ,QAAQ,KAAK,SAAS,WAAW,IACrC,OACA,QAAQ,SAAS,MAAM;AAAA,MAC3B,UAAU,QAAQ,KAAK,YAAY,SAAS,QAAQ;AAAA,IACtD,CAAC;AAAA,EACH,SAAS,OAAO;AACd,UAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AACrE,YAAQ,MAAM,qBAAqB,OAAO;AAC1C,YAAQ,KAAK,CAAC;AAAA,EAChB;AACF,CAAC;AAED,QAAQ,MAAM;","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Node, CallExpression, Expression, JSXAttribute } from '@babel/types';
|
|
2
2
|
|
|
3
|
-
type CliCommand = 'analyze' | 'generate' | 'apply';
|
|
3
|
+
type CliCommand = 'analyze' | 'generate' | 'apply' | 'init';
|
|
4
4
|
interface CommandConfig {
|
|
5
5
|
minOccurrences?: number;
|
|
6
6
|
minSize?: number;
|
|
@@ -31,6 +31,8 @@ interface TailwindUnwindConfig extends CommandConfig {
|
|
|
31
31
|
}
|
|
32
32
|
interface ResolvedCommandOptions extends TailwindUnwindConfig {
|
|
33
33
|
configPath?: string;
|
|
34
|
+
changed?: boolean | string;
|
|
35
|
+
force?: boolean;
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
/**
|
|
@@ -105,13 +107,76 @@ interface AnalyzeOptions {
|
|
|
105
107
|
prettier?: boolean;
|
|
106
108
|
fromReport?: string;
|
|
107
109
|
extractableOnly?: boolean;
|
|
110
|
+
changed?: boolean | string;
|
|
111
|
+
force?: boolean;
|
|
108
112
|
}
|
|
109
113
|
|
|
114
|
+
interface InitOptions extends AnalyzeOptions {
|
|
115
|
+
output?: string;
|
|
116
|
+
force?: boolean;
|
|
117
|
+
}
|
|
118
|
+
interface InitResult {
|
|
119
|
+
configPath: string;
|
|
120
|
+
extractablePatterns: number;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Scan a project and write a starter tailwind-unwind.config.json.
|
|
124
|
+
*/
|
|
125
|
+
declare function initCommand(targetPath: string, options?: InitOptions): Promise<InitResult>;
|
|
126
|
+
|
|
110
127
|
/**
|
|
111
128
|
* Run the full analyze pipeline: scan → parse → find patterns → report.
|
|
112
129
|
*/
|
|
113
130
|
declare function analyzeCommand(targetPath: string, options?: AnalyzeOptions): Promise<AnalysisReport>;
|
|
114
131
|
|
|
132
|
+
interface ClassReplacement {
|
|
133
|
+
filePath: string;
|
|
134
|
+
line?: number;
|
|
135
|
+
from: string;
|
|
136
|
+
to: string;
|
|
137
|
+
partial?: boolean;
|
|
138
|
+
}
|
|
139
|
+
interface SkippedReplacement {
|
|
140
|
+
filePath: string;
|
|
141
|
+
line?: number;
|
|
142
|
+
reason: string;
|
|
143
|
+
classes: string[];
|
|
144
|
+
}
|
|
145
|
+
interface ReplaceClassNamesResult {
|
|
146
|
+
source: string;
|
|
147
|
+
replacements: ClassReplacement[];
|
|
148
|
+
skipped: SkippedReplacement[];
|
|
149
|
+
changed: boolean;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Replace exact matching className/class values with generated component classes.
|
|
153
|
+
* Supports partial replacement inside cn()/clsx() when dynamic args are present.
|
|
154
|
+
*/
|
|
155
|
+
declare function replaceClassNamesInSource(source: string, replacementMap: Map<string, string>, filePath: string): ReplaceClassNamesResult;
|
|
156
|
+
|
|
157
|
+
interface SavingsReport {
|
|
158
|
+
replacementCount: number;
|
|
159
|
+
utilityTokensBefore: number;
|
|
160
|
+
utilityTokensAfter: number;
|
|
161
|
+
tokensSaved: number;
|
|
162
|
+
percentReduction: number;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Estimate utility-token savings from applied replacements.
|
|
166
|
+
* Each replacement collapses N utilities into 1 component class.
|
|
167
|
+
*/
|
|
168
|
+
declare function calculateSavings(replacements: ClassReplacement[]): SavingsReport;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* List source files changed relative to a git ref (default: working tree vs HEAD).
|
|
172
|
+
*/
|
|
173
|
+
declare function getChangedSourceFiles(rootPath: string, ref?: string): Promise<string[]>;
|
|
174
|
+
declare function isGitRepository(rootPath: string): Promise<boolean>;
|
|
175
|
+
/**
|
|
176
|
+
* Changed source files under `scopePath`, resolved to absolute paths.
|
|
177
|
+
*/
|
|
178
|
+
declare function getChangedFilesInScope(scopePath: string, ref?: string): Promise<string[]>;
|
|
179
|
+
|
|
115
180
|
interface GeneratedComponent {
|
|
116
181
|
className: string;
|
|
117
182
|
classes: string[];
|
|
@@ -177,31 +242,6 @@ declare function buildComponents(occurrences: ClassNameOccurrence[], options: Bu
|
|
|
177
242
|
/** Build components from pre-selected combinations (e.g. analyze report). */
|
|
178
243
|
declare function buildComponentsFromCombinations(combinations: ClassCombination[], options: BuildComponentsOptions): BuildComponentsResult;
|
|
179
244
|
|
|
180
|
-
interface ClassReplacement {
|
|
181
|
-
filePath: string;
|
|
182
|
-
line?: number;
|
|
183
|
-
from: string;
|
|
184
|
-
to: string;
|
|
185
|
-
partial?: boolean;
|
|
186
|
-
}
|
|
187
|
-
interface SkippedReplacement {
|
|
188
|
-
filePath: string;
|
|
189
|
-
line?: number;
|
|
190
|
-
reason: string;
|
|
191
|
-
classes: string[];
|
|
192
|
-
}
|
|
193
|
-
interface ReplaceClassNamesResult {
|
|
194
|
-
source: string;
|
|
195
|
-
replacements: ClassReplacement[];
|
|
196
|
-
skipped: SkippedReplacement[];
|
|
197
|
-
changed: boolean;
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Replace exact matching className/class values with generated component classes.
|
|
201
|
-
* Supports partial replacement inside cn()/clsx() when dynamic args are present.
|
|
202
|
-
*/
|
|
203
|
-
declare function replaceClassNamesInSource(source: string, replacementMap: Map<string, string>, filePath: string): ReplaceClassNamesResult;
|
|
204
|
-
|
|
205
245
|
interface GenerateJsonReport {
|
|
206
246
|
command: 'generate';
|
|
207
247
|
outputPath: string;
|
|
@@ -219,6 +259,7 @@ interface ApplyJsonReport {
|
|
|
219
259
|
components: GeneratedComponent[];
|
|
220
260
|
replacements: ClassReplacement[];
|
|
221
261
|
skipped: SkippedReplacement[];
|
|
262
|
+
savings: SavingsReport;
|
|
222
263
|
}
|
|
223
264
|
declare function printGenerateJsonReport(report: GenerateJsonReport): void;
|
|
224
265
|
declare function printApplyJsonReport(report: ApplyJsonReport): void;
|
|
@@ -236,6 +277,7 @@ interface ApplyResult {
|
|
|
236
277
|
replacements: ApplyJsonReport['replacements'];
|
|
237
278
|
skipped: ApplyJsonReport['skipped'];
|
|
238
279
|
prettierFormatted: string[];
|
|
280
|
+
savings: SavingsReport;
|
|
239
281
|
}
|
|
240
282
|
/**
|
|
241
283
|
* Generate component CSS and replace matching className strings in source files.
|
|
@@ -248,6 +290,8 @@ interface ScanProjectOptions extends PatternFinderOptions {
|
|
|
248
290
|
exclude?: string[];
|
|
249
291
|
/** Threshold used to mark combinations as extractable by generate/apply */
|
|
250
292
|
extractableMinOccurrences?: number;
|
|
293
|
+
/** Scan only git-changed files; string value is the git ref to diff against */
|
|
294
|
+
changed?: boolean | string;
|
|
251
295
|
}
|
|
252
296
|
interface ScanProjectResult {
|
|
253
297
|
resolvedPath: string;
|
|
@@ -397,4 +441,4 @@ declare const IGNORED_DIRECTORIES: readonly ["node_modules", ".next", "dist", "b
|
|
|
397
441
|
/** fast-glob ignore patterns — match directories at any depth. */
|
|
398
442
|
declare const IGNORE_PATTERNS: string[];
|
|
399
443
|
|
|
400
|
-
export { type AnalysisReport, type AnalysisStats, type AnalyzeOptions, type ApplyOptions, type ApplyResult, CLASS_MERGE_CALLEES, type ClassCombination, type ClassNameExtraction, type ClassNameOccurrence, type ClassReplacement, type CliCommand, type CombinationLocation, type CommandConfig, type CssGeneratorOptions, type CssGeneratorResult, type CustomNamesConfig, DEFAULT_CLASS_PREFIX, type GenerateOptions, type GenerateResult, type GeneratedComponent, IGNORED_DIRECTORIES, IGNORE_PATTERNS, type ParseResult, type ReplaceClassNamesResult, type SkippedReplacement, type TailwindUnwindConfig, type TailwindUnwindConfigFile, VARIANT_CALLEES, analyzeCommand, applyCommand, assignComponentClassNames, buildComponents, buildComponentsFromCombinations, calculatePotentialReduction, collectVariantRegistry, dedupeSubsetCombinations, extractClassesFromExpression, extractClassesFromVariantCall, extractFromJSXAttribute, findFrequentPatterns, findRepeatedClassSets, formatModifiedFiles, formatSource, generateCombinations, generateCommand, generateComponentCss, isClassAttribute, isStrictSubset, isVariantCallee, loadCommandOptions, loadExtractableCombinations, normalizeClassPrefix, normalizeClasses, normalizeNamesConfig, parseFile, parseSource, parseSourceToAst, printApplyJsonReport, printConsoleReport, printGenerateJsonReport, printJsonReport, replaceClassNamesInSource, scanProject, splitClassString, suggestClassName, validateConfigFile, walkSourceFiles, withClassPrefix };
|
|
444
|
+
export { type AnalysisReport, type AnalysisStats, type AnalyzeOptions, type ApplyOptions, type ApplyResult, CLASS_MERGE_CALLEES, type ClassCombination, type ClassNameExtraction, type ClassNameOccurrence, type ClassReplacement, type CliCommand, type CombinationLocation, type CommandConfig, type CssGeneratorOptions, type CssGeneratorResult, type CustomNamesConfig, DEFAULT_CLASS_PREFIX, type GenerateOptions, type GenerateResult, type GeneratedComponent, IGNORED_DIRECTORIES, IGNORE_PATTERNS, type ParseResult, type ReplaceClassNamesResult, type SkippedReplacement, type TailwindUnwindConfig, type TailwindUnwindConfigFile, VARIANT_CALLEES, analyzeCommand, applyCommand, assignComponentClassNames, buildComponents, buildComponentsFromCombinations, calculatePotentialReduction, calculateSavings, collectVariantRegistry, dedupeSubsetCombinations, extractClassesFromExpression, extractClassesFromVariantCall, extractFromJSXAttribute, findFrequentPatterns, findRepeatedClassSets, formatModifiedFiles, formatSource, generateCombinations, generateCommand, generateComponentCss, getChangedFilesInScope, getChangedSourceFiles, initCommand, isClassAttribute, isGitRepository, isStrictSubset, isVariantCallee, loadCommandOptions, loadExtractableCombinations, normalizeClassPrefix, normalizeClasses, normalizeNamesConfig, parseFile, parseSource, parseSourceToAst, printApplyJsonReport, printConsoleReport, printGenerateJsonReport, printJsonReport, replaceClassNamesInSource, scanProject, splitClassString, suggestClassName, validateConfigFile, walkSourceFiles, withClassPrefix };
|
package/dist/index.js
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
buildComponents,
|
|
11
11
|
buildComponentsFromCombinations,
|
|
12
12
|
calculatePotentialReduction,
|
|
13
|
+
calculateSavings,
|
|
13
14
|
collectVariantRegistry,
|
|
14
15
|
dedupeSubsetCombinations,
|
|
15
16
|
extractClassesFromExpression,
|
|
@@ -22,7 +23,11 @@ import {
|
|
|
22
23
|
generateCombinations,
|
|
23
24
|
generateCommand,
|
|
24
25
|
generateComponentCss,
|
|
26
|
+
getChangedFilesInScope,
|
|
27
|
+
getChangedSourceFiles,
|
|
28
|
+
initCommand,
|
|
25
29
|
isClassAttribute,
|
|
30
|
+
isGitRepository,
|
|
26
31
|
isStrictSubset,
|
|
27
32
|
isVariantCallee,
|
|
28
33
|
loadCommandOptions,
|
|
@@ -44,7 +49,7 @@ import {
|
|
|
44
49
|
validateConfigFile,
|
|
45
50
|
walkSourceFiles,
|
|
46
51
|
withClassPrefix
|
|
47
|
-
} from "./chunk-
|
|
52
|
+
} from "./chunk-UXXIEFP4.js";
|
|
48
53
|
export {
|
|
49
54
|
CLASS_MERGE_CALLEES,
|
|
50
55
|
DEFAULT_CLASS_PREFIX,
|
|
@@ -57,6 +62,7 @@ export {
|
|
|
57
62
|
buildComponents,
|
|
58
63
|
buildComponentsFromCombinations,
|
|
59
64
|
calculatePotentialReduction,
|
|
65
|
+
calculateSavings,
|
|
60
66
|
collectVariantRegistry,
|
|
61
67
|
dedupeSubsetCombinations,
|
|
62
68
|
extractClassesFromExpression,
|
|
@@ -69,7 +75,11 @@ export {
|
|
|
69
75
|
generateCombinations,
|
|
70
76
|
generateCommand,
|
|
71
77
|
generateComponentCss,
|
|
78
|
+
getChangedFilesInScope,
|
|
79
|
+
getChangedSourceFiles,
|
|
80
|
+
initCommand,
|
|
72
81
|
isClassAttribute,
|
|
82
|
+
isGitRepository,
|
|
73
83
|
isStrictSubset,
|
|
74
84
|
isVariantCallee,
|
|
75
85
|
loadCommandOptions,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tailwind-unwind",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Analyze Tailwind CSS class usage patterns in React/Next.js projects",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -60,7 +60,8 @@
|
|
|
60
60
|
"chalk": "^5.4.1",
|
|
61
61
|
"cli-table3": "^0.6.5",
|
|
62
62
|
"commander": "^13.1.0",
|
|
63
|
-
"fast-glob": "^3.3.3"
|
|
63
|
+
"fast-glob": "^3.3.3",
|
|
64
|
+
"jiti": "^2.4.2"
|
|
64
65
|
},
|
|
65
66
|
"devDependencies": {
|
|
66
67
|
"@types/babel__generator": "^7.6.8",
|