1 | {"version":3,"sources":["../../cli/next-lint.ts"],"names":["eslintOptions","args","overrideConfigFile","extensions","resolvePluginsRelativeTo","rulePaths","fix","fixTypes","ignorePath","ignore","Boolean","allowInlineConfig","reportUnusedDisableDirectives","cache","cacheLocation","errorOnUnmatchedPattern","nextLint","argv","validArgs","String","validEslintArgs","error","code","message","baseDir","_","dirs","lintDirs","ESLINT_DEFAULT_DIRS","reduce","res","d","currDir","push","reportErrorsOnly","then","lintResults","lintOutput","output","eventInfo","conf","PHASE_PRODUCTION_BUILD","telemetry","Telemetry","distDir","record","buildLint","flush","isError","CompileError","console","log","chalk","green","catch","err"],"mappings":"AAAA;6DACA,sBACA,8EACA,0BACA,oDAGA,2CACA,wDACA,0CACA,6CACA,4EACA,wDACA,2CACA,kD,mFAEA,KAAMA,CAAAA,aAAa,CAAIC,IAAD,0EAAqB,CACzCC,kBAAkB,CAAED,IAAI,CAAC,UAAD,CAAJ,EAAoB,IADC,CAEzCE,UAAU,YAAEF,IAAI,CAAC,OAAD,CAAN,kBAAmB,CAAC,KAAD,CAAQ,MAAR,CAAgB,KAAhB,CAAuB,MAAvB,CAFY,CAGzCG,wBAAwB,CAAEH,IAAI,CAAC,+BAAD,CAAJ,EAAyC,IAH1B,CAIzCI,SAAS,iBAAEJ,IAAI,CAAC,YAAD,CAAN,uBAAwB,EAJQ,CAKzCK,GAAG,YAAEL,IAAI,CAAC,OAAD,CAAN,kBAAmB,KALmB,CAMzCM,QAAQ,gBAAEN,IAAI,CAAC,YAAD,CAAN,sBAAwB,IANS,CAOzCO,UAAU,CAAEP,IAAI,CAAC,eAAD,CAAJ,EAAyB,IAPI,CAQzCQ,MAAM,CAAE,CAACC,OAAO,CAACT,IAAI,CAAC,aAAD,CAAL,CARyB,CASzCU,iBAAiB,CAAE,CAACD,OAAO,CAACT,IAAI,CAAC,oBAAD,CAAL,CATc,CAUzCW,6BAA6B,CAC3BX,IAAI,CAAC,oCAAD,CAAJ,EAA8C,IAXP,CAYzCY,KAAK,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mCA,WAAW,CAAEG,SAApD,CAA+D,CAC7D,KAAMC,CAAAA,IAAI,CAAG,KAAM,oBAAWC,kCAAX,CAAmCjB,OAAnC,CAAnB,CACA,KAAMkB,CAAAA,SAAS,CAAG,GAAIC,mBAAJ,CAAc,CAC9BC,OAAO,CAAE,eAAKpB,OAAL,CAAcgB,IAAI,CAACI,OAAnB,CADqB,CAAd,CAAlB,CAGAF,SAAS,CAACG,MAAV,CACE,oCAAwB,CACtB,GAAGT,WAAW,CAACG,SADO,CAEtBO,SAAS,CAAE,KAFW,CAAxB,CADF,EAMA,KAAMJ,CAAAA,SAAS,CAACK,KAAV,EAAN,CACD,CAED,GACE,MAAOX,CAAAA,WAAP,GAAuB,QAAvB,EACAA,WADA,QACAA,WAAW,CAAEY,OADb,EAEAX,UAHF,CAIE,CACA,KAAM,IAAIY,2BAAJ,CAAiBZ,UAAjB,CAAN,CACD,CAED,GAAIA,UAAJ,CAAgB,CACda,OAAO,CAACC,GAAR,CAAYd,UAAZ,EACD,CAFD,IAEO,CACLa,OAAO,CAACC,GAAR,CAAYC,eAAMC,KAAN,CAAY,gCAAZ,CAAZ,EACD,CACF,CAhCH,EAiCGC,KAjCH,CAiCUC,GAAD,EAAS,CACd,wBAAaA,GAAG,CAAChC,OAAjB,EACD,CAnCH,EAoCD,CArJD,C","sourcesContent":["#!/usr/bin/env node\nimport { existsSync } from 'fs'\nimport arg from 'next/dist/compiled/arg/index.js'\nimport { resolve, join } from 'path'\nimport chalk from 'chalk'\n\nimport { cliCommand } from '../bin/next'\nimport { ESLINT_DEFAULT_DIRS } from '../lib/constants'\nimport { runLintCheck } from '../lib/eslint/runLintCheck'\nimport { printAndExit } from '../server/lib/utils'\nimport { Telemetry } from '../telemetry/storage'\nimport loadConfig from '../next-server/server/config'\nimport { PHASE_PRODUCTION_BUILD } from '../next-server/lib/constants'\nimport { eventLintCheckCompleted } from '../telemetry/events'\nimport { CompileError } from '../lib/compile-error'\n\nconst eslintOptions = (args: arg.Spec) => ({\n overrideConfigFile: args['--config'] || null,\n extensions: args['--ext'] ?? ['.js', '.jsx', '.ts', '.tsx'],\n resolvePluginsRelativeTo: args['--resolve-plugins-relative-to'] || null,\n rulePaths: args['--rulesdir'] ?? [],\n fix: args['--fix'] ?? false,\n fixTypes: args['--fix-type'] ?? null,\n ignorePath: args['--ignore-path'] || null,\n ignore: !Boolean(args['--no-ignore']),\n allowInlineConfig: !Boolean(args['--no-inline-config']),\n reportUnusedDisableDirectives:\n args['--report-unused-disable-directives'] || null,\n cache: args['--cache'] ?? false,\n cacheLocation: args['--cache-location'] || '.eslintcache',\n errorOnUnmatchedPattern: !Boolean(args['--no-error-on-unmatched-pattern']),\n})\n\nconst nextLint: cliCommand = (argv) => {\n const validArgs: arg.Spec = {\n // Types\n '--help': Boolean,\n '--base-dir': String,\n '--dir': [String],\n\n // Aliases\n '-h': '--help',\n '-b': '--base-dir',\n '-d': '--dir',\n }\n\n const validEslintArgs: arg.Spec = {\n // Types\n '--config': String,\n '--ext': [String],\n '--resolve-plugins-relative-to': String,\n '--rulesdir': [String],\n '--fix': Boolean,\n '--fix-type': [String],\n '--ignore-path': String,\n '--no-ignore': Boolean,\n '--quiet': Boolean,\n '--no-inline-config': Boolean,\n '--report-unused-disable-directives': String,\n '--cache': Boolean,\n '--cache-location': String,\n '--no-error-on-unmatched-pattern': Boolean,\n\n // Aliases\n '-c': '--config',\n }\n\n let args: arg.Result<arg.Spec>\n try {\n args = arg({ ...validArgs, ...validEslintArgs }, { argv })\n } catch (error) {\n if (error.code === 'ARG_UNKNOWN_OPTION') {\n return printAndExit(error.message, 1)\n }\n throw error\n }\n if (args['--help']) {\n printAndExit(\n `\n Description\n Run ESLint on every file in specified directories. \n If not configured, ESLint will be set up for the first time.\n\n Usage\n $ next lint <baseDir> [options]\n \n <baseDir> represents the directory of the Next.js application.\n If no directory is provided, the current directory will be used.\n\n Options\n Basic configuration:\n -h, --help List this help\n -d, --dir Array Set directory, or directories, to run ESLint - default: 'pages', 'components', and 'lib'\n -c, --config path::String Use this configuration file, overriding all other config options\n --ext [String] Specify JavaScript file extensions - default: .js, .jsx, .ts, .tsx\n --resolve-plugins-relative-to path::String A folder where plugins should be resolved from, CWD by default\n\n Specifying rules:\n --rulesdir [path::String] Use additional rules from this directory\n\n Fixing problems:\n --fix Automatically fix problems\n --fix-type Array Specify the types of fixes to apply (problem, suggestion, layout)\n\n Ignoring files:\n --ignore-path path::String Specify path of ignore file\n --no-ignore Disable use of ignore files and patterns\n\n Handling warnings:\n --quiet Report errors only - default: false\n\n Inline configuration comments:\n --no-inline-config Prevent comments from changing config or rules\n --report-unused-disable-directives Adds reported errors for unused eslint-disable directives (\"error\" | \"warn\" | \"off\")\n\n Caching:\n --cache Only check changed files - default: false\n --cache-location path::String Path to the cache file or directory - default: .eslintcache\n \n Miscellaneous:\n --no-error-on-unmatched-pattern Prevent errors when pattern is unmatched - default: false\n `,\n 0\n )\n }\n\n const baseDir = resolve(args._[0] || '.')\n\n // Check if the provided directory exists\n if (!existsSync(baseDir)) {\n printAndExit(`> No such directory exists as the project root: ${baseDir}`)\n }\n\n const dirs: string[] = args['--dir']\n const lintDirs = (dirs ?? ESLINT_DEFAULT_DIRS).reduce(\n (res: string[], d: string) => {\n const currDir = join(baseDir, d)\n if (!existsSync(currDir)) return res\n res.push(currDir)\n return res\n },\n []\n )\n\n const reportErrorsOnly = Boolean(args['--quiet'])\n\n runLintCheck(baseDir, lintDirs, false, eslintOptions(args), reportErrorsOnly)\n .then(async (lintResults) => {\n const lintOutput =\n typeof lintResults === 'string' ? lintResults : lintResults?.output\n\n if (typeof lintResults !== 'string' && lintResults?.eventInfo) {\n const conf = await loadConfig(PHASE_PRODUCTION_BUILD, baseDir)\n const telemetry = new Telemetry({\n distDir: join(baseDir, conf.distDir),\n })\n telemetry.record(\n eventLintCheckCompleted({\n ...lintResults.eventInfo,\n buildLint: false,\n })\n )\n await telemetry.flush()\n }\n\n if (\n typeof lintResults !== 'string' &&\n lintResults?.isError &&\n lintOutput\n ) {\n throw new CompileError(lintOutput)\n }\n\n if (lintOutput) {\n console.log(lintOutput)\n } else {\n console.log(chalk.green('✔ No ESLint warnings or errors'))\n }\n })\n .catch((err) => {\n printAndExit(err.message)\n })\n}\n\nexport { nextLint }\n"]} |