Initial boiler plate project
This commit is contained in:
70
node_modules/next/dist/esm/lib/eslint/customFormatter.js
generated
vendored
Normal file
70
node_modules/next/dist/esm/lib/eslint/customFormatter.js
generated
vendored
Normal file
@ -0,0 +1,70 @@
|
||||
import { bold, cyan, gray, red, yellow } from "../picocolors";
|
||||
import path from "path";
|
||||
export var MessageSeverity;
|
||||
(function(MessageSeverity) {
|
||||
MessageSeverity[MessageSeverity["Warning"] = 1] = "Warning";
|
||||
MessageSeverity[MessageSeverity["Error"] = 2] = "Error";
|
||||
})(MessageSeverity || (MessageSeverity = {}));
|
||||
function pluginCount(messages) {
|
||||
let nextPluginWarningCount = 0;
|
||||
let nextPluginErrorCount = 0;
|
||||
for(let i = 0; i < messages.length; i++){
|
||||
const { severity, ruleId } = messages[i];
|
||||
if (ruleId == null ? void 0 : ruleId.includes("@next/next")) {
|
||||
if (severity === 1) {
|
||||
nextPluginWarningCount += 1;
|
||||
} else {
|
||||
nextPluginErrorCount += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
nextPluginErrorCount,
|
||||
nextPluginWarningCount
|
||||
};
|
||||
}
|
||||
function formatMessage(dir, messages, filePath) {
|
||||
let fileName = path.posix.normalize(path.relative(dir, filePath).replace(/\\/g, "/"));
|
||||
if (!fileName.startsWith(".")) {
|
||||
fileName = "./" + fileName;
|
||||
}
|
||||
let output = "\n" + cyan(fileName);
|
||||
for(let i = 0; i < messages.length; i++){
|
||||
const { message, severity, line, column, ruleId } = messages[i];
|
||||
output = output + "\n";
|
||||
if (line && column) {
|
||||
output = output + yellow(line.toString()) + ":" + yellow(column.toString()) + " ";
|
||||
}
|
||||
if (severity === 1) {
|
||||
output += yellow(bold("Warning")) + ": ";
|
||||
} else {
|
||||
output += red(bold("Error")) + ": ";
|
||||
}
|
||||
output += message;
|
||||
if (ruleId) {
|
||||
output += " " + gray(bold(ruleId));
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
export function formatResults(baseDir, results, format) {
|
||||
let totalNextPluginErrorCount = 0;
|
||||
let totalNextPluginWarningCount = 0;
|
||||
let resultsWithMessages = results.filter(({ messages })=>messages == null ? void 0 : messages.length);
|
||||
// Track number of Next.js plugin errors and warnings
|
||||
resultsWithMessages.forEach(({ messages })=>{
|
||||
const res = pluginCount(messages);
|
||||
totalNextPluginErrorCount += res.nextPluginErrorCount;
|
||||
totalNextPluginWarningCount += res.nextPluginWarningCount;
|
||||
});
|
||||
// Use user defined formatter or Next.js's built-in custom formatter
|
||||
const output = format ? format(resultsWithMessages) : resultsWithMessages.map(({ messages, filePath })=>formatMessage(baseDir, messages, filePath)).join("\n");
|
||||
return {
|
||||
output: output,
|
||||
outputWithMessages: resultsWithMessages.length > 0 ? output + `\n\n${cyan("info")} - Need to disable some ESLint rules? Learn more here: https://nextjs.org/docs/basic-features/eslint#disabling-rules` : "",
|
||||
totalNextPluginErrorCount,
|
||||
totalNextPluginWarningCount
|
||||
};
|
||||
}
|
||||
|
||||
//# sourceMappingURL=customFormatter.js.map
|
||||
1
node_modules/next/dist/esm/lib/eslint/customFormatter.js.map
generated
vendored
Normal file
1
node_modules/next/dist/esm/lib/eslint/customFormatter.js.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../src/lib/eslint/customFormatter.ts"],"names":["bold","cyan","gray","red","yellow","path","MessageSeverity","pluginCount","messages","nextPluginWarningCount","nextPluginErrorCount","i","length","severity","ruleId","includes","formatMessage","dir","filePath","fileName","posix","normalize","relative","replace","startsWith","output","message","line","column","toString","formatResults","baseDir","results","format","totalNextPluginErrorCount","totalNextPluginWarningCount","resultsWithMessages","filter","forEach","res","map","join","outputWithMessages"],"mappings":"AAAA,SAASA,IAAI,EAAEC,IAAI,EAAEC,IAAI,EAAEC,GAAG,EAAEC,MAAM,QAAQ,gBAAe;AAC7D,OAAOC,UAAU,OAAM;;UAGXC;;;GAAAA,oBAAAA;AAsBZ,SAASC,YAAYC,QAAuB;IAI1C,IAAIC,yBAAyB;IAC7B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IC,sBAAsBJ,QAAQK,MAAM,CAAC,CAAC,EAAE7B,QAAQ,EAAE,GAAKA,4BAAAA,SAAUI,MAAM;IAE3E,qDAAqD;IACrDwB,oBAAoBE,OAAO,CAAC,CAAC,EAAE9B,QAAQ,EAAE;QACvC,MAAM+B,MAAMhC,YAAYC;QACxB0B,6BAA6BK,IAAI7B,oBAAoB;QACrDyB,+BAA+BI,IAAI9B,sBAAsB;IAC3D;IAEA,oEAAoE;IACpE,MAAMgB,SAASQ,SACXA,OAAOG,uBACPA,oBACGI,GAAG,CAAC,CAAC,EAAEhC,QAAQ,EAAEU,QAAQ,EAAE,GAC1BF,cAAce,SAASvB,UAAUU,WAElCuB,IAAI,CAAC;IAEZ,OAAO;QACLhB,QAAQA;QACRiB,oBACEN,oBAAoBxB,MAAM,GAAG,IACzBa,SACA,CAAC,IAAI,EAAExB,KACL,QACA,qHAAqH,CAAC,GACxH;QACNiC;QACAC;IACF;AACF"}
|
||||
34
node_modules/next/dist/esm/lib/eslint/getESLintPromptValues.js
generated
vendored
Normal file
34
node_modules/next/dist/esm/lib/eslint/getESLintPromptValues.js
generated
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
import findUp from "next/dist/compiled/find-up";
|
||||
export const getESLintStrictValue = async (cwd)=>{
|
||||
const tsConfigLocation = await findUp("tsconfig.json", {
|
||||
cwd
|
||||
});
|
||||
const hasTSConfig = tsConfigLocation !== undefined;
|
||||
return {
|
||||
title: "Strict",
|
||||
recommended: true,
|
||||
config: {
|
||||
extends: hasTSConfig ? [
|
||||
"next/core-web-vitals",
|
||||
"next/typescript"
|
||||
] : "next/core-web-vitals"
|
||||
}
|
||||
};
|
||||
};
|
||||
export const getESLintPromptValues = async (cwd)=>{
|
||||
return [
|
||||
await getESLintStrictValue(cwd),
|
||||
{
|
||||
title: "Base",
|
||||
config: {
|
||||
extends: "next"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Cancel",
|
||||
config: null
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
//# sourceMappingURL=getESLintPromptValues.js.map
|
||||
1
node_modules/next/dist/esm/lib/eslint/getESLintPromptValues.js.map
generated
vendored
Normal file
1
node_modules/next/dist/esm/lib/eslint/getESLintPromptValues.js.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../src/lib/eslint/getESLintPromptValues.ts"],"names":["findUp","getESLintStrictValue","cwd","tsConfigLocation","hasTSConfig","undefined","title","recommended","config","extends","getESLintPromptValues"],"mappings":"AAAA,OAAOA,YAAY,6BAA4B;AAE/C,OAAO,MAAMC,uBAAuB,OAAOC;IACzC,MAAMC,mBAAmB,MAAMH,OAAO,iBAAiB;QAAEE;IAAI;IAC7D,MAAME,cAAcD,qBAAqBE;IAEzC,OAAO;QACLC,OAAO;QACPC,aAAa;QACbC,QAAQ;YACNC,SAASL,cACL;gBAAC;gBAAwB;aAAkB,GAC3C;QACN;IACF;AACF,EAAC;AAED,OAAO,MAAMM,wBAAwB,OAAOR;IAC1C,OAAO;QACL,MAAMD,qBAAqBC;QAC3B;YACEI,OAAO;YACPE,QAAQ;gBACNC,SAAS;YACX;QACF;QACA;YACEH,OAAO;YACPE,QAAQ;QACV;KACD;AACH,EAAC"}
|
||||
27
node_modules/next/dist/esm/lib/eslint/hasEslintConfiguration.js
generated
vendored
Normal file
27
node_modules/next/dist/esm/lib/eslint/hasEslintConfiguration.js
generated
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
import { promises as fs } from "fs";
|
||||
export async function hasEslintConfiguration(eslintrcFile, packageJsonConfig) {
|
||||
const configObject = {
|
||||
exists: false,
|
||||
emptyEslintrc: false,
|
||||
emptyPkgJsonConfig: false
|
||||
};
|
||||
if (eslintrcFile) {
|
||||
const content = await fs.readFile(eslintrcFile, {
|
||||
encoding: "utf8"
|
||||
}).then((txt)=>txt.trim().replace(/\n/g, ""), ()=>null);
|
||||
if (content === "" || content === "{}" || content === "---" || content === "module.exports = {}") {
|
||||
configObject.emptyEslintrc = true;
|
||||
} else {
|
||||
configObject.exists = true;
|
||||
}
|
||||
} else if (packageJsonConfig == null ? void 0 : packageJsonConfig.eslintConfig) {
|
||||
if (Object.keys(packageJsonConfig.eslintConfig).length) {
|
||||
configObject.exists = true;
|
||||
} else {
|
||||
configObject.emptyPkgJsonConfig = true;
|
||||
}
|
||||
}
|
||||
return configObject;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=hasEslintConfiguration.js.map
|
||||
1
node_modules/next/dist/esm/lib/eslint/hasEslintConfiguration.js.map
generated
vendored
Normal file
1
node_modules/next/dist/esm/lib/eslint/hasEslintConfiguration.js.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../src/lib/eslint/hasEslintConfiguration.ts"],"names":["promises","fs","hasEslintConfiguration","eslintrcFile","packageJsonConfig","configObject","exists","emptyEslintrc","emptyPkgJsonConfig","content","readFile","encoding","then","txt","trim","replace","eslintConfig","Object","keys","length"],"mappings":"AAAA,SAASA,YAAYC,EAAE,QAAQ,KAAI;AASnC,OAAO,eAAeC,uBACpBC,YAA2B,EAC3BC,iBAA+C;IAE/C,MAAMC,eAAe;QACnBC,QAAQ;QACRC,eAAe;QACfC,oBAAoB;IACtB;IAEA,IAAIL,cAAc;QAChB,MAAMM,UAAU,MAAMR,GAAGS,QAAQ,CAACP,cAAc;YAAEQ,UAAU;QAAO,GAAGC,IAAI,CACxE,CAACC,MAAQA,IAAIC,IAAI,GAAGC,OAAO,CAAC,OAAO,KACnC,IAAM;QAGR,IACEN,YAAY,MACZA,YAAY,QACZA,YAAY,SACZA,YAAY,uBACZ;YACAJ,aAAaE,aAAa,GAAG;QAC/B,OAAO;YACLF,aAAaC,MAAM,GAAG;QACxB;IACF,OAAO,IAAIF,qCAAAA,kBAAmBY,YAAY,EAAE;QAC1C,IAAIC,OAAOC,IAAI,CAACd,kBAAkBY,YAAY,EAAEG,MAAM,EAAE;YACtDd,aAAaC,MAAM,GAAG;QACxB,OAAO;YACLD,aAAaG,kBAAkB,GAAG;QACpC;IACF;IACA,OAAOH;AACT"}
|
||||
260
node_modules/next/dist/esm/lib/eslint/runLintCheck.js
generated
vendored
Normal file
260
node_modules/next/dist/esm/lib/eslint/runLintCheck.js
generated
vendored
Normal file
@ -0,0 +1,260 @@
|
||||
import { promises as fs, existsSync } from "fs";
|
||||
import { bold, cyan, red, underline, yellow } from "../picocolors";
|
||||
import path from "path";
|
||||
import findUp from "next/dist/compiled/find-up";
|
||||
import semver from "next/dist/compiled/semver";
|
||||
import * as CommentJson from "next/dist/compiled/comment-json";
|
||||
import { formatResults } from "./customFormatter";
|
||||
import { writeDefaultConfig } from "./writeDefaultConfig";
|
||||
import { hasEslintConfiguration } from "./hasEslintConfiguration";
|
||||
import { writeOutputFile } from "./writeOutputFile";
|
||||
import { findPagesDir } from "../find-pages-dir";
|
||||
import { installDependencies } from "../install-dependencies";
|
||||
import { hasNecessaryDependencies } from "../has-necessary-dependencies";
|
||||
import * as Log from "../../build/output/log";
|
||||
import isError, { getProperError } from "../is-error";
|
||||
import { getPkgManager } from "../helpers/get-pkg-manager";
|
||||
import { getESLintStrictValue, getESLintPromptValues } from "./getESLintPromptValues";
|
||||
// 0 is off, 1 is warn, 2 is error. See https://eslint.org/docs/user-guide/configuring/rules#configuring-rules
|
||||
const VALID_SEVERITY = [
|
||||
"off",
|
||||
"warn",
|
||||
"error"
|
||||
];
|
||||
function isValidSeverity(severity) {
|
||||
return VALID_SEVERITY.includes(severity);
|
||||
}
|
||||
const requiredPackages = [
|
||||
{
|
||||
file: "eslint",
|
||||
pkg: "eslint",
|
||||
exportsRestrict: false
|
||||
},
|
||||
{
|
||||
file: "eslint-config-next",
|
||||
pkg: "eslint-config-next",
|
||||
exportsRestrict: false
|
||||
}
|
||||
];
|
||||
async function cliPrompt(cwd) {
|
||||
console.log(bold(`${cyan("?")} How would you like to configure ESLint? https://nextjs.org/docs/basic-features/eslint`));
|
||||
try {
|
||||
const cliSelect = (await Promise.resolve(require("next/dist/compiled/cli-select"))).default;
|
||||
const { value } = await cliSelect({
|
||||
values: await getESLintPromptValues(cwd),
|
||||
valueRenderer: ({ title, recommended }, selected)=>{
|
||||
const name = selected ? bold(underline(cyan(title))) : title;
|
||||
return name + (recommended ? bold(yellow(" (recommended)")) : "");
|
||||
},
|
||||
selected: cyan("❯ "),
|
||||
unselected: " "
|
||||
});
|
||||
return {
|
||||
config: (value == null ? void 0 : value.config) ?? null
|
||||
};
|
||||
} catch {
|
||||
return {
|
||||
config: null
|
||||
};
|
||||
}
|
||||
}
|
||||
async function lint(baseDir, lintDirs, eslintrcFile, pkgJsonPath, { lintDuringBuild = false, eslintOptions = null, reportErrorsOnly = false, maxWarnings = -1, formatter = null, outputFile = null }) {
|
||||
try {
|
||||
var _mod_CLIEngine, _ESLint_getErrorResults;
|
||||
// Load ESLint after we're sure it exists:
|
||||
const deps = await hasNecessaryDependencies(baseDir, requiredPackages);
|
||||
const packageManager = getPkgManager(baseDir);
|
||||
if (deps.missing.some((dep)=>dep.pkg === "eslint")) {
|
||||
Log.error(`ESLint must be installed${lintDuringBuild ? " in order to run during builds:" : ":"} ${bold(cyan((packageManager === "yarn" ? "yarn add --dev" : packageManager === "pnpm" ? "pnpm install --save-dev" : "npm install --save-dev") + " eslint"))}`);
|
||||
return null;
|
||||
}
|
||||
const mod = await Promise.resolve(require(deps.resolved.get("eslint")));
|
||||
const { ESLint } = mod;
|
||||
let eslintVersion = (ESLint == null ? void 0 : ESLint.version) ?? ((_mod_CLIEngine = mod.CLIEngine) == null ? void 0 : _mod_CLIEngine.version);
|
||||
if (!eslintVersion || semver.lt(eslintVersion, "7.0.0")) {
|
||||
return `${red("error")} - Your project has an older version of ESLint installed${eslintVersion ? " (" + eslintVersion + ")" : ""}. Please upgrade to ESLint version 7 or above`;
|
||||
}
|
||||
let options = {
|
||||
useEslintrc: true,
|
||||
baseConfig: {},
|
||||
errorOnUnmatchedPattern: false,
|
||||
extensions: [
|
||||
".js",
|
||||
".jsx",
|
||||
".ts",
|
||||
".tsx"
|
||||
],
|
||||
cache: true,
|
||||
...eslintOptions
|
||||
};
|
||||
let eslint = new ESLint(options);
|
||||
let nextEslintPluginIsEnabled = false;
|
||||
const nextRulesEnabled = new Map();
|
||||
for (const configFile of [
|
||||
eslintrcFile,
|
||||
pkgJsonPath
|
||||
]){
|
||||
var _completeConfig_plugins;
|
||||
if (!configFile) continue;
|
||||
const completeConfig = await eslint.calculateConfigForFile(configFile);
|
||||
if ((_completeConfig_plugins = completeConfig.plugins) == null ? void 0 : _completeConfig_plugins.includes("@next/next")) {
|
||||
nextEslintPluginIsEnabled = true;
|
||||
for (const [name, [severity]] of Object.entries(completeConfig.rules)){
|
||||
if (!name.startsWith("@next/next/")) {
|
||||
continue;
|
||||
}
|
||||
if (typeof severity === "number" && severity >= 0 && severity < VALID_SEVERITY.length) {
|
||||
nextRulesEnabled.set(name, VALID_SEVERITY[severity]);
|
||||
} else if (typeof severity === "string" && isValidSeverity(severity)) {
|
||||
nextRulesEnabled.set(name, severity);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
const pagesDir = findPagesDir(baseDir).pagesDir;
|
||||
const pagesDirRules = pagesDir ? [
|
||||
"@next/next/no-html-link-for-pages"
|
||||
] : [];
|
||||
if (nextEslintPluginIsEnabled) {
|
||||
let updatedPagesDir = false;
|
||||
for (const rule of pagesDirRules){
|
||||
var _options_baseConfig_rules, _options_baseConfig_rules1;
|
||||
if (!((_options_baseConfig_rules = options.baseConfig.rules) == null ? void 0 : _options_baseConfig_rules[rule]) && !((_options_baseConfig_rules1 = options.baseConfig.rules) == null ? void 0 : _options_baseConfig_rules1[rule.replace("@next/next", "@next/babel-plugin-next")])) {
|
||||
if (!options.baseConfig.rules) {
|
||||
options.baseConfig.rules = {};
|
||||
}
|
||||
options.baseConfig.rules[rule] = [
|
||||
1,
|
||||
pagesDir
|
||||
];
|
||||
updatedPagesDir = true;
|
||||
}
|
||||
}
|
||||
if (updatedPagesDir) {
|
||||
eslint = new ESLint(options);
|
||||
}
|
||||
} else {
|
||||
Log.warn("");
|
||||
Log.warn("The Next.js plugin was not detected in your ESLint configuration. See https://nextjs.org/docs/basic-features/eslint#migrating-existing-config");
|
||||
}
|
||||
const lintStart = process.hrtime();
|
||||
let results = await eslint.lintFiles(lintDirs);
|
||||
let selectedFormatter = null;
|
||||
if (options.fix) await ESLint.outputFixes(results);
|
||||
if (reportErrorsOnly) results = await ESLint.getErrorResults(results) // Only return errors if --quiet flag is used
|
||||
;
|
||||
if (formatter) selectedFormatter = await eslint.loadFormatter(formatter);
|
||||
const formattedResult = formatResults(baseDir, results, selectedFormatter == null ? void 0 : selectedFormatter.format);
|
||||
const lintEnd = process.hrtime(lintStart);
|
||||
const totalWarnings = results.reduce((sum, file)=>sum + file.warningCount, 0);
|
||||
if (outputFile) await writeOutputFile(outputFile, formattedResult.output);
|
||||
return {
|
||||
output: formattedResult.outputWithMessages,
|
||||
isError: ((_ESLint_getErrorResults = ESLint.getErrorResults(results)) == null ? void 0 : _ESLint_getErrorResults.length) > 0 || maxWarnings >= 0 && totalWarnings > maxWarnings,
|
||||
eventInfo: {
|
||||
durationInSeconds: lintEnd[0],
|
||||
eslintVersion: eslintVersion,
|
||||
lintedFilesCount: results.length,
|
||||
lintFix: !!options.fix,
|
||||
nextEslintPluginVersion: nextEslintPluginIsEnabled && deps.resolved.has("eslint-config-next") ? require(path.join(path.dirname(deps.resolved.get("eslint-config-next")), "package.json")).version : null,
|
||||
nextEslintPluginErrorsCount: formattedResult.totalNextPluginErrorCount,
|
||||
nextEslintPluginWarningsCount: formattedResult.totalNextPluginWarningCount,
|
||||
nextRulesEnabled: Object.fromEntries(nextRulesEnabled)
|
||||
}
|
||||
};
|
||||
} catch (err) {
|
||||
if (lintDuringBuild) {
|
||||
Log.error(`ESLint: ${isError(err) && err.message ? err.message.replace(/\n/g, " ") : err}`);
|
||||
return null;
|
||||
} else {
|
||||
throw getProperError(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
export async function runLintCheck(baseDir, lintDirs, opts) {
|
||||
const { lintDuringBuild = false, eslintOptions = null, reportErrorsOnly = false, maxWarnings = -1, formatter = null, outputFile = null, strict = false } = opts;
|
||||
try {
|
||||
// Find user's .eslintrc file
|
||||
// See: https://eslint.org/docs/user-guide/configuring/configuration-files#configuration-file-formats
|
||||
const eslintrcFile = await findUp([
|
||||
".eslintrc.js",
|
||||
".eslintrc.cjs",
|
||||
".eslintrc.yaml",
|
||||
".eslintrc.yml",
|
||||
".eslintrc.json",
|
||||
".eslintrc"
|
||||
], {
|
||||
cwd: baseDir
|
||||
}) ?? null;
|
||||
const pkgJsonPath = await findUp("package.json", {
|
||||
cwd: baseDir
|
||||
}) ?? null;
|
||||
let packageJsonConfig = null;
|
||||
if (pkgJsonPath) {
|
||||
const pkgJsonContent = await fs.readFile(pkgJsonPath, {
|
||||
encoding: "utf8"
|
||||
});
|
||||
packageJsonConfig = CommentJson.parse(pkgJsonContent);
|
||||
}
|
||||
const config = await hasEslintConfiguration(eslintrcFile, packageJsonConfig);
|
||||
let deps;
|
||||
if (config.exists) {
|
||||
// Run if ESLint config exists
|
||||
return await lint(baseDir, lintDirs, eslintrcFile, pkgJsonPath, {
|
||||
lintDuringBuild,
|
||||
eslintOptions,
|
||||
reportErrorsOnly,
|
||||
maxWarnings,
|
||||
formatter,
|
||||
outputFile
|
||||
});
|
||||
} else {
|
||||
// Display warning if no ESLint configuration is present inside
|
||||
// config file during "next build", no warning is shown when
|
||||
// no eslintrc file is present
|
||||
if (lintDuringBuild) {
|
||||
if (config.emptyPkgJsonConfig || config.emptyEslintrc) {
|
||||
Log.warn(`No ESLint configuration detected. Run ${bold(cyan("next lint"))} to begin setup`);
|
||||
}
|
||||
return null;
|
||||
} else {
|
||||
// Ask user what config they would like to start with for first time "next lint" setup
|
||||
const { config: selectedConfig } = strict ? await getESLintStrictValue(baseDir) : await cliPrompt(baseDir);
|
||||
if (selectedConfig == null) {
|
||||
// Show a warning if no option is selected in prompt
|
||||
Log.warn("If you set up ESLint yourself, we recommend adding the Next.js ESLint plugin. See https://nextjs.org/docs/basic-features/eslint#migrating-existing-config");
|
||||
return null;
|
||||
} else {
|
||||
// Check if necessary deps installed, and install any that are missing
|
||||
deps = await hasNecessaryDependencies(baseDir, requiredPackages);
|
||||
if (deps.missing.length > 0) {
|
||||
deps.missing.forEach((dep)=>{
|
||||
if (dep.pkg === "eslint") {
|
||||
// eslint v9 has breaking changes, so lock to 8 until dependency plugins fully support v9.
|
||||
dep.pkg = "eslint@^8";
|
||||
}
|
||||
});
|
||||
await installDependencies(baseDir, deps.missing, true);
|
||||
}
|
||||
// Write default ESLint config.
|
||||
// Check for /pages and src/pages is to make sure this happens in Next.js folder
|
||||
if ([
|
||||
"app",
|
||||
"src/app",
|
||||
"pages",
|
||||
"src/pages"
|
||||
].some((dir)=>existsSync(path.join(baseDir, dir)))) {
|
||||
await writeDefaultConfig(baseDir, config, selectedConfig, eslintrcFile, pkgJsonPath, packageJsonConfig);
|
||||
}
|
||||
}
|
||||
Log.ready(`ESLint has successfully been configured. Run ${bold(cyan("next lint"))} again to view warnings and errors.`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=runLintCheck.js.map
|
||||
1
node_modules/next/dist/esm/lib/eslint/runLintCheck.js.map
generated
vendored
Normal file
1
node_modules/next/dist/esm/lib/eslint/runLintCheck.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
31
node_modules/next/dist/esm/lib/eslint/writeDefaultConfig.js
generated
vendored
Normal file
31
node_modules/next/dist/esm/lib/eslint/writeDefaultConfig.js
generated
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
import { promises as fs } from "fs";
|
||||
import { bold, green } from "../picocolors";
|
||||
import os from "os";
|
||||
import path from "path";
|
||||
import * as CommentJson from "next/dist/compiled/comment-json";
|
||||
import * as Log from "../../build/output/log";
|
||||
export async function writeDefaultConfig(baseDir, { exists, emptyEslintrc, emptyPkgJsonConfig }, selectedConfig, eslintrcFile, pkgJsonPath, packageJsonConfig) {
|
||||
if (!exists && emptyEslintrc && eslintrcFile) {
|
||||
const ext = path.extname(eslintrcFile);
|
||||
let newFileContent;
|
||||
if (ext === ".yaml" || ext === ".yml") {
|
||||
newFileContent = "extends: 'next'";
|
||||
} else {
|
||||
newFileContent = CommentJson.stringify(selectedConfig, null, 2);
|
||||
if (ext === ".js") {
|
||||
newFileContent = "module.exports = " + newFileContent;
|
||||
}
|
||||
}
|
||||
await fs.writeFile(eslintrcFile, newFileContent + os.EOL);
|
||||
Log.info(`We detected an empty ESLint configuration file (${bold(path.basename(eslintrcFile))}) and updated it for you!`);
|
||||
} else if (!exists && emptyPkgJsonConfig && packageJsonConfig) {
|
||||
packageJsonConfig.eslintConfig = selectedConfig;
|
||||
if (pkgJsonPath) await fs.writeFile(pkgJsonPath, CommentJson.stringify(packageJsonConfig, null, 2) + os.EOL);
|
||||
Log.info(`We detected an empty ${bold("eslintConfig")} field in package.json and updated it for you!`);
|
||||
} else if (!exists) {
|
||||
await fs.writeFile(path.join(baseDir, ".eslintrc.json"), CommentJson.stringify(selectedConfig, null, 2) + os.EOL);
|
||||
console.log(green(`We created the ${bold(".eslintrc.json")} file for you and included your selected configuration.`));
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=writeDefaultConfig.js.map
|
||||
1
node_modules/next/dist/esm/lib/eslint/writeDefaultConfig.js.map
generated
vendored
Normal file
1
node_modules/next/dist/esm/lib/eslint/writeDefaultConfig.js.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../src/lib/eslint/writeDefaultConfig.ts"],"names":["promises","fs","bold","green","os","path","CommentJson","Log","writeDefaultConfig","baseDir","exists","emptyEslintrc","emptyPkgJsonConfig","selectedConfig","eslintrcFile","pkgJsonPath","packageJsonConfig","ext","extname","newFileContent","stringify","writeFile","EOL","info","basename","eslintConfig","join","console","log"],"mappings":"AAAA,S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,GAAG,CACTzB,MACE,CAAC,eAAe,EAAED,KAChB,kBACA,uDAAuD,CAAC;IAGhE;AACF"}
|
||||
36
node_modules/next/dist/esm/lib/eslint/writeOutputFile.js
generated
vendored
Normal file
36
node_modules/next/dist/esm/lib/eslint/writeOutputFile.js
generated
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
import { promises as fs } from "fs";
|
||||
import path from "path";
|
||||
import * as Log from "../../build/output/log";
|
||||
import isError from "../../lib/is-error";
|
||||
/**
|
||||
* Check if a given file path is a directory or not.
|
||||
* Returns `true` if the path is a directory.
|
||||
*/ function isDirectory(/** The path to a file to check. */ filePath) {
|
||||
return fs.stat(filePath).then((stat)=>stat.isDirectory()).catch((error)=>{
|
||||
if (isError(error) && (error.code === "ENOENT" || error.code === "ENOTDIR")) {
|
||||
return false;
|
||||
}
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Create a file with eslint output data
|
||||
*/ export async function writeOutputFile(/** The name file that needs to be created */ outputFile, /** The data that needs to be inserted into the file */ outputData) {
|
||||
const filePath = path.resolve(process.cwd(), outputFile);
|
||||
if (await isDirectory(filePath)) {
|
||||
Log.error(`Cannot write to output file path, it is a directory: ${filePath}`);
|
||||
} else {
|
||||
try {
|
||||
await fs.mkdir(path.dirname(filePath), {
|
||||
recursive: true
|
||||
});
|
||||
await fs.writeFile(filePath, outputData);
|
||||
Log.info(`The output file has been created: ${filePath}`);
|
||||
} catch (err) {
|
||||
Log.error(`There was a problem writing the output file: ${filePath}`);
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=writeOutputFile.js.map
|
||||
1
node_modules/next/dist/esm/lib/eslint/writeOutputFile.js.map
generated
vendored
Normal file
1
node_modules/next/dist/esm/lib/eslint/writeOutputFile.js.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../src/lib/eslint/writeOutputFile.ts"],"names":["promises","fs","path","Log","isError","isDirectory","filePath","stat","then","catch","error","code","writeOutputFile","outputFile","outputData","resolve","process","cwd","mkdir","dirname","recursive","writeFile","info","err","console"],"mappings":"AAAA,SAASA,YAAYC,EAAE,QAAQ,KAAI;AACnC,OAAOC,UAAU,OAAM;AACvB,YAAYC,SAAS,yBAAwB;AAC7C,OAAOC,aAAa,qBAAoB;AAExC;;;CAGC,GACD,SAASC,YACP,kCAAkC,GAClCC,QAAgB;IAEhB,OAAOL,GACJM,IAAI,CAACD,UACLE,IAAI,CAAC,CAACD,OAASA,KAAKF,WAAW,IAC/BI,KAAK,CAAC,CAACC;QACN,IACEN,QAAQM,UACPA,CAAAA,MAAMC,IAAI,KAAK,YAAYD,MAAMC,IAAI,KAAK,SAAQ,GACnD;YACA,OAAO;QACT;QACA,MAAMD;IACR;AACJ;AACA;;CAEC,GACD,OAAO,eAAeE,gBACpB,2CAA2C,GAC3CC,UAAkB,EAClB,qDAAqD,GACrDC,UAAkB;IAElB,MAAMR,WAAWJ,KAAKa,OAAO,CAACC,QAAQC,GAAG,IAAIJ;IAE7C,IAAI,MAAMR,YAAYC,WAAW;QAC/BH,IAAIO,KAAK,CACP,CAAC,qDAAqD,EAAEJ,SAAS,CAAC;IAEtE,OAAO;QACL,IAAI;YACF,MAAML,GAAGiB,KAAK,CAAChB,KAAKiB,OAAO,CAACb,WAAW;gBAAEc,WAAW;YAAK;YACzD,MAAMnB,GAAGoB,SAAS,CAACf,UAAUQ;YAC7BX,IAAImB,IAAI,CAAC,CAAC,kCAAkC,EAAEhB,SAAS,CAAC;QAC1D,EAAE,OAAOiB,KAAK;YACZpB,IAAIO,KAAK,CAAC,CAAC,6CAA6C,EAAEJ,SAAS,CAAC;YACpEkB,QAAQd,KAAK,CAACa;QAChB;IACF;AACF"}
|
||||
Reference in New Issue
Block a user