@nx/next
Version:
69 lines (68 loc) • 3.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.addLinting = addLinting;
const eslint_1 = require("@nx/eslint");
const devkit_1 = require("@nx/devkit");
const lint_1 = require("@nx/react/src/utils/lint");
const eslint_file_1 = require("@nx/eslint/src/generators/utils/eslint-file");
const versions_1 = require("../../../utils/versions");
const flat_config_1 = require("@nx/eslint/src/utils/flat-config");
async function addLinting(host, options) {
if (options.linter !== 'eslint')
return () => { };
const tasks = [];
tasks.push(await (0, eslint_1.lintProjectGenerator)(host, {
linter: options.linter,
project: options.projectName,
tsConfigPaths: [
(0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
],
unitTestRunner: options.unitTestRunner,
skipFormat: true,
rootProject: options.rootProject,
setParserOptionsProject: options.setParserOptionsProject,
addPlugin: options.addPlugin,
}));
if (options.linter === 'eslint' && (0, eslint_file_1.isEslintConfigSupported)(host)) {
if ((0, flat_config_1.useFlatConfig)(host)) {
(0, eslint_file_1.addPredefinedConfigToFlatLintConfig)(host, options.appProjectRoot, 'flat/react-typescript');
// Since Next.js does not support flat configs yet, we need to use compat fixup.
const addExtendsTask = (0, eslint_file_1.addExtendsToLintConfig)(host, options.appProjectRoot, [
{ name: 'next', needCompatFixup: true },
{ name: 'next/core-web-vitals', needCompatFixup: true },
]);
tasks.push(addExtendsTask);
}
else {
const addExtendsTask = (0, eslint_file_1.addExtendsToLintConfig)(host, options.appProjectRoot, [
'plugin:@nx/react-typescript',
{ name: 'next', needCompatFixup: true },
{ name: 'next/core-web-vitals', needCompatFixup: true },
]);
tasks.push(addExtendsTask);
}
(0, eslint_file_1.updateOverrideInLintConfig)(host, options.appProjectRoot, (o) => Array.isArray(o.files) &&
o.files.some((f) => f.match(/\*\.ts$/)) &&
o.files.some((f) => f.match(/\*\.tsx$/)) &&
o.files.some((f) => f.match(/\*\.js$/)) &&
o.files.some((f) => f.match(/\*\.jsx$/)), (o) => ({
...o,
rules: {
...o.rules,
'@next/next/no-html-link-for-pages': [
'error',
`${options.appProjectRoot}/pages`,
],
},
}));
(0, eslint_file_1.addIgnoresToLintConfig)(host, options.appProjectRoot, ['.next/**/*']);
}
if (!options.skipPackageJson) {
tasks.push((0, devkit_1.addDependenciesToPackageJson)(host, lint_1.extraEslintDependencies.dependencies, {
...lint_1.extraEslintDependencies.devDependencies,
'eslint-config-next': versions_1.eslintConfigNextVersion,
'@next/eslint-plugin-next': versions_1.eslintConfigNextVersion,
}));
}
return (0, devkit_1.runTasksInSerial)(...tasks);
}