{"version":3,"file":"fix-auth-protection-cli.mjs","names":[],"sources":["../../src/next/fix-auth-protection-cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport path from 'node:path';\nimport { parseArgs } from 'node:util';\n\nimport { fixAuthProtection } from './fix-auth-protection';\n\nfunction relative(filePath: string): string {\n  return path.relative(process.cwd(), filePath) || filePath;\n}\n\nconst HELP = `clerk-next-fix-auth-protection\n\nApply the @clerk/eslint-plugin \\`require-auth-protection\\` rule's\n\\`await auth.protect()\\` suggestions across your project. Uses your existing\nESLint config (so the protected/public folder globs are honored).\n\nUsage\n  clerk-next-fix-auth-protection [patterns...] [options]\n\nArguments\n  patterns            Files, directories, or globs to scan (default: \".\")\n\nOptions\n  --dry-run           Report what would change without writing any files\n  -h, --help          Show this help\n\nExamples\n  clerk-next-fix-auth-protection\n  clerk-next-fix-auth-protection \"app/**\" --dry-run\n`;\n\nfunction pluralize(count: number, noun: string): string {\n  return `${count} ${noun}${count === 1 ? '' : 's'}`;\n}\n\nasync function main(): Promise<number> {\n  const { values, positionals } = parseArgs({\n    allowPositionals: true,\n    options: {\n      'dry-run': { type: 'boolean' },\n      help: { type: 'boolean', short: 'h' },\n    },\n  });\n\n  if (values.help) {\n    console.log(HELP);\n    return 0;\n  }\n\n  const patterns = positionals.length > 0 ? positionals : ['.'];\n  const dryRun = Boolean(values['dry-run']);\n  const verb = dryRun ? 'Would protect' : 'Protected';\n\n  console.log(`Scanning: ${patterns.join(', ')}`);\n\n  const { fixed, unresolved } = await fixAuthProtection({\n    patterns,\n    dryRun,\n    onConfigResolved(configFile) {\n      console.log(`Config:   ${configFile ? relative(configFile) : '(resolved by ESLint from the working directory)'}`);\n      console.log('');\n      console.log('Scanning for unprotected resources…');\n      console.log('This lints your whole project, so it can take a while on large codebases.');\n    },\n    onScanComplete(fileCount) {\n      if (fileCount === 0) {\n        return;\n      }\n      console.log('');\n      console.log(`Found ${pluralize(fileCount, 'file')} to update. ${dryRun ? 'Previewing' : 'Applying'} fixes…`);\n    },\n    onFileFixed(file) {\n      console.log(`  ${verb} ${relative(file.filePath)} (${pluralize(file.protections, 'resource')})`);\n    },\n  });\n\n  if (fixed.length === 0 && unresolved.length === 0) {\n    console.log('');\n    console.log('No unprotected resources found. Nothing to do.');\n    return 0;\n  }\n\n  if (unresolved.length > 0) {\n    console.log('');\n    console.log('Needs manual attention (no safe automatic fix):');\n    for (const file of unresolved) {\n      for (const issue of file.issues) {\n        console.log(`  ${relative(file.filePath)}:${issue.line}:${issue.column} ${issue.message}`);\n      }\n    }\n  }\n\n  const totalProtections = fixed.reduce((sum, file) => sum + file.protections, 0);\n  console.log('');\n  console.log(\n    `${verb} ${pluralize(totalProtections, 'resource')} across ${pluralize(fixed.length, 'file')}.` +\n      (dryRun ? ' Run without --dry-run to apply.' : ''),\n  );\n\n  if (fixed.length > 0) {\n    console.log('');\n    console.log(\n      'Warning: Adding `await auth.protect()` changes your application\\u2019s runtime behavior \\u2014 it enforces',\n    );\n    console.log('authentication where there potentially was none, or might override custom auth checks that were');\n    console.log('already in place. Always review the changes and test your application.');\n  }\n\n  // Non-zero when there is still work to do (manual fixes, or pending changes in\n  // a dry run) so CI can gate on it.\n  return unresolved.length > 0 || (dryRun && fixed.length > 0) ? 1 : 0;\n}\n\nmain()\n  .then(code => {\n    process.exitCode = code;\n  })\n  .catch((error: unknown) => {\n    console.error(error instanceof Error ? error.message : error);\n    process.exitCode = 1;\n  });\n"],"mappings":";;;;;;AAMA,SAAS,SAAS,UAA0B;CAC1C,OAAO,KAAK,SAAS,QAAQ,IAAI,GAAG,QAAQ,KAAK;AACnD;AAEA,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;AAqBb,SAAS,UAAU,OAAe,MAAsB;CACtD,OAAO,GAAG,MAAM,GAAG,OAAO,UAAU,IAAI,KAAK;AAC/C;AAEA,eAAe,OAAwB;CACrC,MAAM,EAAE,QAAQ,gBAAgB,UAAU;EACxC,kBAAkB;EAClB,SAAS;GACP,WAAW,EAAE,MAAM,UAAU;G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