@nx/eslint 0.0.0-pr-31231-180f614 → 0.0.0-pr-31222-862e973
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/LICENSE +1 -1
- package/README.md +1 -1
- package/migrations.json +112 -69
- package/package.json +7 -6
- package/src/executors/lint/utility/eslint-utils.js +0 -6
- package/src/generators/convert-to-flat-config/converters/json-converter.d.ts +1 -1
- package/src/generators/convert-to-flat-config/converters/json-converter.js +18 -10
- package/src/generators/convert-to-flat-config/generator.js +17 -18
- package/src/generators/convert-to-flat-config/schema.d.ts +0 -2
- package/src/generators/convert-to-inferred/convert-to-inferred.js +1 -2
- package/src/generators/init/global-eslint-config.d.ts +1 -1
- package/src/generators/init/global-eslint-config.js +6 -17
- package/src/generators/init/init-migration.d.ts +1 -1
- package/src/generators/init/init-migration.js +13 -18
- package/src/generators/init/init.d.ts +0 -1
- package/src/generators/init/init.js +6 -31
- package/src/generators/lint-project/lint-project.d.ts +0 -1
- package/src/generators/lint-project/lint-project.js +15 -37
- package/src/generators/lint-project/setup-root-eslint.d.ts +0 -1
- package/src/generators/lint-project/setup-root-eslint.js +1 -2
- package/src/generators/utils/eslint-file.d.ts +2 -3
- package/src/generators/utils/eslint-file.js +28 -160
- package/src/generators/utils/flat-config/ast-utils.d.ts +4 -12
- package/src/generators/utils/flat-config/ast-utils.js +63 -412
- package/src/generators/utils/linter.d.ts +0 -3
- package/src/generators/utils/linter.js +2 -2
- package/src/generators/workspace-rules-project/workspace-rules-project.js +1 -3
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +9 -0
- package/src/migrations/update-16-8-0-add-ignored-files/update-16-8-0-add-ignored-files.d.ts +2 -0
- package/src/migrations/update-16-8-0-add-ignored-files/update-16-8-0-add-ignored-files.js +44 -0
- package/src/migrations/update-17-0-0-rename-to-eslint/update-17-0-0-rename-to-eslint.d.ts +2 -0
- package/src/migrations/update-17-0-0-rename-to-eslint/update-17-0-0-rename-to-eslint.js +47 -0
- package/src/migrations/update-17-1-0/update-typescript-eslint.d.ts +2 -0
- package/src/migrations/update-17-1-0/update-typescript-eslint.js +74 -0
- package/src/migrations/update-17-2-0/simplify-eslint-patterns.d.ts +2 -0
- package/src/migrations/update-17-2-0/simplify-eslint-patterns.js +46 -0
- package/src/migrations/update-17-2-9/move-options-to-target-defaults.d.ts +2 -0
- package/src/migrations/update-17-2-9/move-options-to-target-defaults.js +107 -0
- package/src/plugins/plugin.js +10 -21
- package/src/utils/config-file.d.ts +1 -3
- package/src/utils/config-file.js +2 -5
- package/src/utils/flat-config.d.ts +0 -1
- package/src/utils/flat-config.js +3 -9
- package/src/utils/version-utils.d.ts +0 -1
- package/src/utils/version-utils.js +9 -13
- package/src/utils/versions.d.ts +2 -3
- package/src/utils/versions.js +3 -4
- package/src/migrations/update-20-2-0/update-typescript-eslint-v8-13-0.d.ts +0 -2
- package/src/migrations/update-20-2-0/update-typescript-eslint-v8-13-0.js +0 -23
- package/src/migrations/update-20-3-0/add-file-extensions-to-overrides.d.ts +0 -2
- package/src/migrations/update-20-3-0/add-file-extensions-to-overrides.js +0 -49
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Linter = void 0;
|
|
4
|
-
|
|
5
|
-
* @deprecated Use LinterType instead
|
|
4
|
+
/*
|
|
5
|
+
* @deprecated Use LinterType instead
|
|
6
6
|
*/
|
|
7
7
|
var Linter;
|
|
8
8
|
(function (Linter) {
|
|
@@ -5,7 +5,6 @@ exports.lintWorkspaceRulesProjectGenerator = lintWorkspaceRulesProjectGenerator;
|
|
|
5
5
|
const devkit_1 = require("@nx/devkit");
|
|
6
6
|
const js_1 = require("@nx/js");
|
|
7
7
|
const add_swc_dependencies_1 = require("@nx/js/src/utils/swc/add-swc-dependencies");
|
|
8
|
-
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
9
8
|
const path_1 = require("path");
|
|
10
9
|
const versions_1 = require("../../utils/versions");
|
|
11
10
|
const workspace_lint_rules_1 = require("../../utils/workspace-lint-rules");
|
|
@@ -48,12 +47,11 @@ async function lintWorkspaceRulesProjectGenerator(tree, options = {}) {
|
|
|
48
47
|
supportTsx: false,
|
|
49
48
|
skipSerializers: true,
|
|
50
49
|
setupFile: 'none',
|
|
51
|
-
compiler:
|
|
50
|
+
compiler: 'tsc',
|
|
52
51
|
skipFormat: true,
|
|
53
52
|
}));
|
|
54
53
|
(0, devkit_1.updateJson)(tree, (0, path_1.join)(workspace_lint_rules_1.workspaceLintPluginDir, 'tsconfig.spec.json'), (json) => {
|
|
55
54
|
delete json.compilerOptions?.module;
|
|
56
|
-
delete json.compilerOptions?.moduleResolution;
|
|
57
55
|
if (json.include) {
|
|
58
56
|
json.include = json.include.map((v) => {
|
|
59
57
|
if (v.startsWith('src/**')) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = replacePackage;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const replace_package_1 = require("@nx/devkit/src/utils/replace-package");
|
|
6
|
+
async function replacePackage(tree) {
|
|
7
|
+
await (0, replace_package_1.replaceNrwlPackageWithNxPackage)(tree, '@nrwl/linter', '@nx/linter');
|
|
8
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
9
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = update;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
|
|
6
|
+
const eslint_file_1 = require("../../generators/utils/eslint-file");
|
|
7
|
+
// Add `ignoredFiles` pattern to projects using vite, esbuild, and rollup.
|
|
8
|
+
// This is needed because the @nx/dependency-checks lint rule will complain
|
|
9
|
+
// about dependencies used in build config files, even though they are not
|
|
10
|
+
// production dependencies.
|
|
11
|
+
function update(tree) {
|
|
12
|
+
const projects = (0, devkit_1.getProjects)(tree);
|
|
13
|
+
const addIgnorePattern = (ignorePattern) => (_options, projectName) => {
|
|
14
|
+
const project = projects.get(projectName);
|
|
15
|
+
if (!(0, eslint_file_1.findEslintFile)(tree, project.root) ||
|
|
16
|
+
!(0, eslint_file_1.isEslintConfigSupported)(tree)) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if ((0, eslint_file_1.lintConfigHasOverride)(tree, project.root, (o) => Array.isArray(o.files)
|
|
20
|
+
? o.files.some((f) => f.match(/\.json$/))
|
|
21
|
+
: !!o.files?.match(/\.json$/), true)) {
|
|
22
|
+
(0, eslint_file_1.updateOverrideInLintConfig)(tree, project.root, (o) => !!o.rules?.['@nx/dependency-checks'], (o) => {
|
|
23
|
+
const value = o.rules['@nx/dependency-checks'];
|
|
24
|
+
let ruleSeverity;
|
|
25
|
+
let ruleOptions;
|
|
26
|
+
if (Array.isArray(value)) {
|
|
27
|
+
ruleSeverity = value[0];
|
|
28
|
+
ruleOptions = value[1];
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
ruleSeverity = value;
|
|
32
|
+
ruleOptions = {};
|
|
33
|
+
}
|
|
34
|
+
ruleOptions.ignoredFiles = [ignorePattern];
|
|
35
|
+
o.rules['@nx/dependency-checks'] = [ruleSeverity, ruleOptions];
|
|
36
|
+
return o;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
(0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/vite:build', addIgnorePattern('{projectRoot}/vite.config.{js,ts,mjs,mts}'));
|
|
41
|
+
(0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/vite:test', addIgnorePattern('{projectRoot}/vite.config.{js,ts,mjs,mts}'));
|
|
42
|
+
(0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/esbuild:esbuild', addIgnorePattern('{projectRoot}/esbuild.config.{js,ts,mjs,mts}'));
|
|
43
|
+
(0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/rollup:rollup', addIgnorePattern('{projectRoot}/rollup.config.{js,ts,mjs,mts}'));
|
|
44
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = replacePackage;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const replace_package_1 = require("@nx/devkit/src/utils/replace-package");
|
|
6
|
+
async function replacePackage(tree) {
|
|
7
|
+
await (0, replace_package_1.replaceNrwlPackageWithNxPackage)(tree, '@nx/linter', '@nx/eslint');
|
|
8
|
+
// executor name change from :eslint to :lint
|
|
9
|
+
updateNxJsonExecutor(tree);
|
|
10
|
+
updateProjectExecutor(tree);
|
|
11
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
12
|
+
}
|
|
13
|
+
function updateNxJsonExecutor(tree) {
|
|
14
|
+
if (!tree.exists('nx.json')) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
18
|
+
let needsUpdate = false;
|
|
19
|
+
for (const [targetName, targetConfig] of Object.entries(nxJson.targetDefaults ?? {})) {
|
|
20
|
+
// this will be in a broken state after the package is globally renamed
|
|
21
|
+
if (targetConfig.executor !== '@nx/eslint:eslint') {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
needsUpdate = true;
|
|
25
|
+
nxJson.targetDefaults[targetName].executor = '@nx/eslint:lint';
|
|
26
|
+
}
|
|
27
|
+
if (needsUpdate) {
|
|
28
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function updateProjectExecutor(tree) {
|
|
32
|
+
const projects = (0, devkit_1.getProjects)(tree);
|
|
33
|
+
for (const [projectName, projectConfiguration] of projects) {
|
|
34
|
+
let needsUpdate = false;
|
|
35
|
+
for (const [targetName, targetConfig] of Object.entries(projectConfiguration.targets ?? {})) {
|
|
36
|
+
// this will be in a broken state after the package is globally renamed
|
|
37
|
+
if (targetConfig.executor !== '@nx/eslint:eslint') {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
needsUpdate = true;
|
|
41
|
+
projectConfiguration.targets[targetName].executor = '@nx/eslint:lint';
|
|
42
|
+
}
|
|
43
|
+
if (needsUpdate) {
|
|
44
|
+
(0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfiguration);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = update;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const versions_1 = require("../../utils/versions");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const typescript_1 = require("typescript");
|
|
8
|
+
function updateJestConfig(tree) {
|
|
9
|
+
const jestConfigPath = 'tools/eslint-rules/jest.config.ts';
|
|
10
|
+
if (tree.exists(jestConfigPath)) {
|
|
11
|
+
const { removePropertyFromJestConfig } = (0, devkit_1.ensurePackage)('@nx/jest', versions_1.nxVersion);
|
|
12
|
+
removePropertyFromJestConfig(tree, jestConfigPath, [
|
|
13
|
+
'moduleNameMapper',
|
|
14
|
+
'@eslint/eslintrc',
|
|
15
|
+
]);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function updateTsConfigs(tree) {
|
|
19
|
+
const tsConfigPath = 'tools/eslint-rules/tsconfig.json';
|
|
20
|
+
if (tree.exists(tsConfigPath)) {
|
|
21
|
+
(0, devkit_1.updateJson)(tree, tsConfigPath, (tsConfig) => {
|
|
22
|
+
tsConfig.compilerOptions ??= {};
|
|
23
|
+
tsConfig.compilerOptions.moduleResolution = 'node16';
|
|
24
|
+
tsConfig.compilerOptions.module = 'node16';
|
|
25
|
+
return tsConfig;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
const tsConfigSpec = 'tools/eslint-rules/tsconfig.spec.json';
|
|
29
|
+
if (tree.exists(tsConfigSpec)) {
|
|
30
|
+
(0, devkit_1.updateJson)(tree, tsConfigSpec, (tsConfigSpec) => {
|
|
31
|
+
delete tsConfigSpec.compilerOptions?.module;
|
|
32
|
+
delete tsConfigSpec.compilerOptions?.moduleResolution;
|
|
33
|
+
return tsConfigSpec;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function updateRecommended(tree) {
|
|
38
|
+
(0, devkit_1.visitNotIgnoredFiles)(tree, 'tools/eslint-rules', (path) => {
|
|
39
|
+
if ((0, path_1.extname)(path) !== '.ts') {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const contents = tree.read(path, 'utf-8');
|
|
43
|
+
const sourceFile = (0, typescript_1.createSourceFile)(path, contents, typescript_1.ScriptTarget.ESNext, true);
|
|
44
|
+
const changes = [];
|
|
45
|
+
const visit = (node) => {
|
|
46
|
+
if ((0, typescript_1.isPropertyAssignment)(node) &&
|
|
47
|
+
(0, typescript_1.isIdentifier)(node.name) &&
|
|
48
|
+
node.name.text === 'recommended' &&
|
|
49
|
+
(0, typescript_1.isStringLiteral)(node.initializer)) {
|
|
50
|
+
changes.push({
|
|
51
|
+
type: devkit_1.ChangeType.Delete,
|
|
52
|
+
start: node.initializer.getStart(sourceFile),
|
|
53
|
+
length: node.initializer.getWidth(sourceFile),
|
|
54
|
+
});
|
|
55
|
+
changes.push({
|
|
56
|
+
type: devkit_1.ChangeType.Insert,
|
|
57
|
+
index: node.initializer.getStart(sourceFile),
|
|
58
|
+
text: "'recommended'",
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
(0, typescript_1.forEachChild)(node, visit);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
(0, typescript_1.forEachChild)(sourceFile, visit);
|
|
66
|
+
tree.write(path, (0, devkit_1.applyChangesToString)(contents, changes));
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
async function update(tree) {
|
|
70
|
+
updateJestConfig(tree);
|
|
71
|
+
updateTsConfigs(tree);
|
|
72
|
+
updateRecommended(tree);
|
|
73
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
74
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = update;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
async function update(tree) {
|
|
6
|
+
const projects = (0, devkit_1.getProjects)(tree);
|
|
7
|
+
for (const [projectName, projectConfiguration] of projects) {
|
|
8
|
+
let needsUpdate = false;
|
|
9
|
+
for (const [targetName, targetConfig] of Object.entries(projectConfiguration.targets ?? {})) {
|
|
10
|
+
if (targetConfig.executor !== '@nx/eslint:lint') {
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
needsUpdate = true;
|
|
14
|
+
if (projectConfiguration.targets[targetName].options?.lintFilePatterns) {
|
|
15
|
+
const rootPattern = getLintRoot(projectConfiguration);
|
|
16
|
+
const nonRootPatterns = projectConfiguration.targets[targetName].options.lintFilePatterns.filter((p) => !p.startsWith(rootPattern) && !p.startsWith('{projectRoot}'));
|
|
17
|
+
if (nonRootPatterns.length === 0 &&
|
|
18
|
+
rootPattern === projectConfiguration.root) {
|
|
19
|
+
// delete the lintFilePatterns option if it's the only option and matches the root of the project
|
|
20
|
+
delete projectConfiguration.targets[targetName].options
|
|
21
|
+
.lintFilePatterns;
|
|
22
|
+
if (Object.keys(projectConfiguration.targets[targetName].options)
|
|
23
|
+
.length === 0) {
|
|
24
|
+
delete projectConfiguration.targets[targetName].options;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
projectConfiguration.targets[targetName].options.lintFilePatterns = [
|
|
29
|
+
rootPattern,
|
|
30
|
+
...nonRootPatterns,
|
|
31
|
+
];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (needsUpdate) {
|
|
36
|
+
(0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfiguration);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
40
|
+
}
|
|
41
|
+
function getLintRoot({ root, sourceRoot }) {
|
|
42
|
+
if (root === '' || root === '.') {
|
|
43
|
+
return sourceRoot || './src';
|
|
44
|
+
}
|
|
45
|
+
return root;
|
|
46
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = update;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
|
|
6
|
+
const eslint_file_1 = require("../../generators/utils/eslint-file");
|
|
7
|
+
const project_configuration_utils_1 = require("nx/src/project-graph/utils/project-configuration-utils");
|
|
8
|
+
async function update(tree) {
|
|
9
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
10
|
+
// Don't override anything if there are already target defaults for eslint
|
|
11
|
+
if (nxJson.targetDefaults?.['@nx/eslint:lint']) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
nxJson.targetDefaults ??= {};
|
|
15
|
+
const graph = await (0, devkit_1.createProjectGraphAsync)();
|
|
16
|
+
const lintTargets = new Set();
|
|
17
|
+
(0, executor_options_utils_1.forEachExecutorOptionsInGraph)(graph, '@nx/eslint:lint', (value, proj, targetName) => {
|
|
18
|
+
lintTargets.add(targetName);
|
|
19
|
+
});
|
|
20
|
+
// Workspace does not use eslint?
|
|
21
|
+
if (lintTargets.size === 0) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const lintDefaults = (nxJson.targetDefaults['@nx/eslint:lint'] = {});
|
|
25
|
+
// All eslint targets have the same name
|
|
26
|
+
if (lintTargets.size === 1) {
|
|
27
|
+
const targetName = Array.from(lintTargets)[0];
|
|
28
|
+
if (nxJson.targetDefaults[targetName]) {
|
|
29
|
+
Object.assign(lintDefaults, nxJson.targetDefaults[targetName]);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
lintDefaults.cache ??= true;
|
|
33
|
+
if (!lintDefaults.inputs) {
|
|
34
|
+
const eslintConfig = (0, eslint_file_1.findEslintFile)(tree);
|
|
35
|
+
lintDefaults.inputs = [
|
|
36
|
+
'default',
|
|
37
|
+
...(eslintConfig ? [`{workspaceRoot}/${eslintConfig}`] : []),
|
|
38
|
+
'{workspaceRoot}/tools/eslint-rules/**/*',
|
|
39
|
+
];
|
|
40
|
+
}
|
|
41
|
+
// Cleanup old target defaults
|
|
42
|
+
const projects = graph.nodes;
|
|
43
|
+
const projectMap = (0, devkit_1.getProjects)(tree);
|
|
44
|
+
for (const [targetDefaultKey, targetDefault] of Object.entries(nxJson.targetDefaults)) {
|
|
45
|
+
if (!isTargetDefaultUsed(targetDefault, nxJson.targetDefaults, projects, projectMap)) {
|
|
46
|
+
delete nxJson.targetDefaults[targetDefaultKey];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
let addOutputs = false;
|
|
50
|
+
(0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/eslint:lint', (options, proj, targetName, configuration) => {
|
|
51
|
+
const projConfig = projectMap.get(proj);
|
|
52
|
+
// modify lint file patterns
|
|
53
|
+
if (options.lintFilePatterns) {
|
|
54
|
+
const projectRootRegex = new RegExp(`^${projConfig.root}/`);
|
|
55
|
+
projConfig.targets[targetName].options.lintFilePatterns =
|
|
56
|
+
options.lintFilePatterns
|
|
57
|
+
.filter((filePattern) => filePattern !== '{projectRoot}' &&
|
|
58
|
+
filePattern !== projConfig.root)
|
|
59
|
+
.map((filePattern) => filePattern.replace(projectRootRegex, '{projectRoot}/'));
|
|
60
|
+
// remove lintFilePatterns if empty
|
|
61
|
+
if (projConfig.targets[targetName].options.lintFilePatterns.length === 0) {
|
|
62
|
+
delete projConfig.targets[targetName].options.lintFilePatterns;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// remove inputs if they are not bringing any new inputs
|
|
66
|
+
if (projConfig.targets[targetName].inputs &&
|
|
67
|
+
projConfig.targets[targetName].inputs.every((i) => lintDefaults.inputs.includes(i))) {
|
|
68
|
+
delete projConfig.targets[targetName].inputs;
|
|
69
|
+
}
|
|
70
|
+
// remove obsolete eslint config definition, unless it's a custom one
|
|
71
|
+
const projectEslintConfig = (0, eslint_file_1.findEslintFile)(tree, projConfig.root);
|
|
72
|
+
if (options.eslintConfig === `${projConfig.root}/${projectEslintConfig}` ||
|
|
73
|
+
options.eslintConfig === `{projectRoot}/${projectEslintConfig}`) {
|
|
74
|
+
delete projConfig.targets[targetName].options.eslintConfig;
|
|
75
|
+
}
|
|
76
|
+
// remove options if empty
|
|
77
|
+
if (Object.keys(projConfig.targets[targetName]?.options ?? {}).length === 0) {
|
|
78
|
+
delete projConfig.targets[targetName].options;
|
|
79
|
+
}
|
|
80
|
+
// track output
|
|
81
|
+
if (options.outputFile) {
|
|
82
|
+
addOutputs = true;
|
|
83
|
+
}
|
|
84
|
+
if (projConfig.targets[targetName].outputs?.length === 1 &&
|
|
85
|
+
projConfig.targets[targetName].outputs[0] === '{options.outputFile}') {
|
|
86
|
+
delete projConfig.targets[targetName].outputs;
|
|
87
|
+
}
|
|
88
|
+
(0, devkit_1.updateProjectConfiguration)(tree, proj, projConfig);
|
|
89
|
+
});
|
|
90
|
+
if (addOutputs) {
|
|
91
|
+
lintDefaults.outputs = ['{options.outputFile}'];
|
|
92
|
+
}
|
|
93
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
94
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
95
|
+
}
|
|
96
|
+
function isTargetDefaultUsed(targetDefault, targetDefaults, projects, projectMap) {
|
|
97
|
+
for (const p of Object.values(projects)) {
|
|
98
|
+
for (const targetName in p.data?.targets ?? {}) {
|
|
99
|
+
if ((0, project_configuration_utils_1.readTargetDefaultsForTarget)(targetName, targetDefaults,
|
|
100
|
+
// It might seem like we should use the graph here too but we don't want to pass an executor which was processed in the graph
|
|
101
|
+
projectMap.get(p.name)?.targets?.[targetName]?.executor) === targetDefault) {
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return false;
|
|
107
|
+
}
|
package/src/plugins/plugin.js
CHANGED
|
@@ -13,18 +13,7 @@ const semver_1 = require("semver");
|
|
|
13
13
|
const config_file_1 = require("../utils/config-file");
|
|
14
14
|
const resolve_eslint_class_1 = require("../utils/resolve-eslint-class");
|
|
15
15
|
const pmc = (0, devkit_1.getPackageManagerCommand)();
|
|
16
|
-
const DEFAULT_EXTENSIONS = [
|
|
17
|
-
'ts',
|
|
18
|
-
'cts',
|
|
19
|
-
'mts',
|
|
20
|
-
'tsx',
|
|
21
|
-
'js',
|
|
22
|
-
'cjs',
|
|
23
|
-
'mjs',
|
|
24
|
-
'jsx',
|
|
25
|
-
'html',
|
|
26
|
-
'vue',
|
|
27
|
-
];
|
|
16
|
+
const DEFAULT_EXTENSIONS = ['ts', 'tsx', 'js', 'jsx', 'html', 'vue'];
|
|
28
17
|
const PROJECT_CONFIG_FILENAMES = ['project.json', 'package.json'];
|
|
29
18
|
const ESLINT_CONFIG_GLOB_V1 = (0, globs_1.combineGlobPatterns)(config_file_1.ESLINT_CONFIG_FILENAMES.map((f) => `**/${f}`));
|
|
30
19
|
const ESLINT_CONFIG_GLOB_V2 = (0, globs_1.combineGlobPatterns)([
|
|
@@ -107,7 +96,7 @@ const internalCreateNodes = async (configFilePath, options, context, projectsCac
|
|
|
107
96
|
projects,
|
|
108
97
|
};
|
|
109
98
|
};
|
|
110
|
-
const internalCreateNodesV2 = async (configFilePath, options, context, projectRootsByEslintRoots, lintableFilesPerProjectRoot, projectsCache
|
|
99
|
+
const internalCreateNodesV2 = async (configFilePath, options, context, eslintConfigFiles, projectRootsByEslintRoots, lintableFilesPerProjectRoot, projectsCache) => {
|
|
111
100
|
const configDir = (0, posix_1.dirname)(configFilePath);
|
|
112
101
|
const ESLint = await (0, resolve_eslint_class_1.resolveESLintClass)({
|
|
113
102
|
useFlatConfigOverrideVal: (0, config_file_1.isFlatConfig)(configFilePath),
|
|
@@ -115,7 +104,12 @@ const internalCreateNodesV2 = async (configFilePath, options, context, projectRo
|
|
|
115
104
|
const eslintVersion = ESLint.version;
|
|
116
105
|
const projects = {};
|
|
117
106
|
await Promise.all(projectRootsByEslintRoots.get(configDir).map(async (projectRoot) => {
|
|
118
|
-
const
|
|
107
|
+
const parentConfigs = eslintConfigFiles.filter((eslintConfig) => isSubDir(projectRoot, (0, posix_1.dirname)(eslintConfig)));
|
|
108
|
+
const hash = await (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options, {
|
|
109
|
+
configFiles: eslintConfigFiles,
|
|
110
|
+
nxJsonConfiguration: context.nxJsonConfiguration,
|
|
111
|
+
workspaceRoot: context.workspaceRoot,
|
|
112
|
+
}, [...parentConfigs, (0, posix_1.join)(projectRoot, '.eslintignore')]);
|
|
119
113
|
if (projectsCache[hash]) {
|
|
120
114
|
// We can reuse the projects in the cache.
|
|
121
115
|
Object.assign(projects, projectsCache[hash]);
|
|
@@ -160,13 +154,8 @@ exports.createNodesV2 = [
|
|
|
160
154
|
const targetsCache = readTargetsCache(cachePath);
|
|
161
155
|
const { eslintConfigFiles, projectRoots, projectRootsByEslintRoots } = splitConfigFiles(configFiles);
|
|
162
156
|
const lintableFilesPerProjectRoot = await collectLintableFilesByProjectRoot(projectRoots, options, context);
|
|
163
|
-
const hashes = await (0, calculate_hash_for_create_nodes_1.calculateHashesForCreateNodes)(projectRoots, options, context, projectRoots.map((root) => {
|
|
164
|
-
const parentConfigs = eslintConfigFiles.filter((eslintConfig) => isSubDir(root, (0, posix_1.dirname)(eslintConfig)));
|
|
165
|
-
return [...parentConfigs, (0, posix_1.join)(root, '.eslintignore')];
|
|
166
|
-
}));
|
|
167
|
-
const hashByRoot = new Map(projectRoots.map((r, i) => [r, hashes[i]]));
|
|
168
157
|
try {
|
|
169
|
-
return await (0, devkit_1.createNodesFromFiles)((configFile, options, context) => internalCreateNodesV2(configFile, options, context, projectRootsByEslintRoots, lintableFilesPerProjectRoot, targetsCache
|
|
158
|
+
return await (0, devkit_1.createNodesFromFiles)((configFile, options, context) => internalCreateNodesV2(configFile, options, context, eslintConfigFiles, projectRootsByEslintRoots, lintableFilesPerProjectRoot, targetsCache), eslintConfigFiles, options, context);
|
|
170
159
|
}
|
|
171
160
|
finally {
|
|
172
161
|
writeTargetsToCache(cachePath, targetsCache);
|
|
@@ -241,7 +230,7 @@ function getRootForDirectory(directory, roots) {
|
|
|
241
230
|
function getProjectUsingESLintConfig(configFilePath, projectRoot, eslintVersion, options, context) {
|
|
242
231
|
const rootEslintConfig = [
|
|
243
232
|
config_file_1.baseEsLintConfigFile,
|
|
244
|
-
|
|
233
|
+
config_file_1.baseEsLintFlatConfigFile,
|
|
245
234
|
...config_file_1.ESLINT_CONFIG_FILENAMES,
|
|
246
235
|
].find((f) => (0, node_fs_1.existsSync)((0, posix_1.join)(context.workspaceRoot, f)));
|
|
247
236
|
// Add a lint target for each child project without an eslint config, with the root level config as an input
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
export declare const ESLINT_FLAT_CONFIG_FILENAMES: string[];
|
|
2
2
|
export declare const ESLINT_OLD_CONFIG_FILENAMES: string[];
|
|
3
3
|
export declare const ESLINT_CONFIG_FILENAMES: string[];
|
|
4
|
-
export declare const BASE_ESLINT_CONFIG_FILENAMES: string[];
|
|
5
4
|
export declare const baseEsLintConfigFile = ".eslintrc.base.json";
|
|
6
|
-
export declare const baseEsLintFlatConfigFile = "eslint.base.config.
|
|
7
|
-
export declare const legacyBaseEsLintFlatConfigFile = "eslint.base.config.js";
|
|
5
|
+
export declare const baseEsLintFlatConfigFile = "eslint.base.config.js";
|
|
8
6
|
export declare function isFlatConfig(configFilePath: string): boolean;
|
|
9
7
|
export declare function findFlatConfigFile(directory: string, workspaceRoot: string): string | null;
|
|
10
8
|
export declare function findOldConfigFile(filePathOrDirectory: string, workspaceRoot: string): string | null;
|
package/src/utils/config-file.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.baseEsLintFlatConfigFile = exports.baseEsLintConfigFile = exports.ESLINT_CONFIG_FILENAMES = exports.ESLINT_OLD_CONFIG_FILENAMES = exports.ESLINT_FLAT_CONFIG_FILENAMES = void 0;
|
|
4
4
|
exports.isFlatConfig = isFlatConfig;
|
|
5
5
|
exports.findFlatConfigFile = findFlatConfigFile;
|
|
6
6
|
exports.findOldConfigFile = findOldConfigFile;
|
|
@@ -20,11 +20,8 @@ exports.ESLINT_CONFIG_FILENAMES = [
|
|
|
20
20
|
...exports.ESLINT_OLD_CONFIG_FILENAMES,
|
|
21
21
|
...exports.ESLINT_FLAT_CONFIG_FILENAMES,
|
|
22
22
|
];
|
|
23
|
-
exports.BASE_ESLINT_CONFIG_FILENAMES = flat_config_1.baseEslintConfigFilenames;
|
|
24
23
|
exports.baseEsLintConfigFile = '.eslintrc.base.json';
|
|
25
|
-
exports.baseEsLintFlatConfigFile = 'eslint.base.config.
|
|
26
|
-
// Make sure we can handle previous file extension as well for migrations or custom generators.
|
|
27
|
-
exports.legacyBaseEsLintFlatConfigFile = 'eslint.base.config.js';
|
|
24
|
+
exports.baseEsLintFlatConfigFile = 'eslint.base.config.js';
|
|
28
25
|
function isFlatConfig(configFilePath) {
|
|
29
26
|
const configFileName = (0, path_1.basename)(configFilePath);
|
|
30
27
|
return exports.ESLINT_FLAT_CONFIG_FILENAMES.includes(configFileName);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Tree } from '@nx/devkit';
|
|
2
2
|
export declare const eslintFlatConfigFilenames: string[];
|
|
3
|
-
export declare const baseEslintConfigFilenames: string[];
|
|
4
3
|
export declare function getRootESLintFlatConfigFilename(tree: Tree): string;
|
|
5
4
|
export declare function useFlatConfig(tree?: Tree): boolean;
|
package/src/utils/flat-config.js
CHANGED
|
@@ -1,19 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.eslintFlatConfigFilenames = void 0;
|
|
4
4
|
exports.getRootESLintFlatConfigFilename = getRootESLintFlatConfigFilename;
|
|
5
5
|
exports.useFlatConfig = useFlatConfig;
|
|
6
6
|
const semver_1 = require("semver");
|
|
7
|
+
// todo: add support for eslint.config.mjs,
|
|
7
8
|
exports.eslintFlatConfigFilenames = [
|
|
8
|
-
'eslint.config.cjs',
|
|
9
9
|
'eslint.config.js',
|
|
10
|
-
'eslint.config.
|
|
11
|
-
];
|
|
12
|
-
exports.baseEslintConfigFilenames = [
|
|
13
|
-
'eslint.base.js',
|
|
14
|
-
'eslint.base.config.cjs',
|
|
15
|
-
'eslint.base.config.js',
|
|
16
|
-
'eslint.base.config.mjs',
|
|
10
|
+
'eslint.config.cjs',
|
|
17
11
|
];
|
|
18
12
|
function getRootESLintFlatConfigFilename(tree) {
|
|
19
13
|
for (const file of exports.eslintFlatConfigFilenames) {
|
|
@@ -1,35 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getInstalledPackageVersion = getInstalledPackageVersion;
|
|
4
3
|
exports.getInstalledEslintVersion = getInstalledEslintVersion;
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
5
|
const semver_1 = require("@nx/devkit/src/utils/semver");
|
|
7
6
|
const devkit_internals_1 = require("nx/src/devkit-internals");
|
|
8
|
-
function
|
|
7
|
+
function getInstalledEslintVersion(tree) {
|
|
9
8
|
try {
|
|
10
|
-
const
|
|
11
|
-
return
|
|
9
|
+
const eslintPackageJson = (0, devkit_internals_1.readModulePackageJson)('eslint').packageJson;
|
|
10
|
+
return eslintPackageJson.version;
|
|
12
11
|
}
|
|
13
12
|
catch { }
|
|
14
|
-
//
|
|
13
|
+
// eslint is not installed on disk, it could be in the package.json
|
|
15
14
|
// but waiting to be installed
|
|
16
15
|
const rootPackageJson = tree
|
|
17
16
|
? (0, devkit_1.readJson)(tree, 'package.json')
|
|
18
17
|
: (0, devkit_1.readJsonFile)('package.json');
|
|
19
|
-
const
|
|
20
|
-
rootPackageJson.dependencies?.[
|
|
21
|
-
if (!
|
|
22
|
-
//
|
|
18
|
+
const eslintVersionInRootPackageJson = rootPackageJson.devDependencies?.['eslint'] ??
|
|
19
|
+
rootPackageJson.dependencies?.['eslint'];
|
|
20
|
+
if (!eslintVersionInRootPackageJson) {
|
|
21
|
+
// eslint is not installed
|
|
23
22
|
return null;
|
|
24
23
|
}
|
|
25
24
|
try {
|
|
26
25
|
// try to parse and return the version
|
|
27
|
-
return (0, semver_1.checkAndCleanWithSemver)(
|
|
26
|
+
return (0, semver_1.checkAndCleanWithSemver)('eslint', eslintVersionInRootPackageJson);
|
|
28
27
|
}
|
|
29
28
|
catch { }
|
|
30
29
|
// we could not resolve the version
|
|
31
30
|
return null;
|
|
32
31
|
}
|
|
33
|
-
function getInstalledEslintVersion(tree) {
|
|
34
|
-
return getInstalledPackageVersion('eslint', tree);
|
|
35
|
-
}
|
package/src/utils/versions.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
export declare const nxVersion: any;
|
|
2
2
|
export declare const eslintVersion = "~8.57.0";
|
|
3
3
|
export declare const eslintrcVersion = "^2.1.1";
|
|
4
|
-
export declare const eslintConfigPrettierVersion = "^
|
|
4
|
+
export declare const eslintConfigPrettierVersion = "^9.0.0";
|
|
5
5
|
export declare const typescriptESLintVersion = "^7.16.0";
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const eslint9__typescriptESLintVersion = "^8.19.0";
|
|
6
|
+
export declare const eslint9__typescriptESLintVersion = "^8.0.0";
|
|
8
7
|
export declare const eslint9__eslintVersion = "^9.8.0";
|
|
9
8
|
export declare const eslintCompat = "^1.1.1";
|
package/src/utils/versions.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.eslintCompat = exports.eslint9__eslintVersion = exports.eslint9__typescriptESLintVersion = exports.
|
|
3
|
+
exports.eslintCompat = exports.eslint9__eslintVersion = exports.eslint9__typescriptESLintVersion = exports.typescriptESLintVersion = exports.eslintConfigPrettierVersion = exports.eslintrcVersion = exports.eslintVersion = exports.nxVersion = void 0;
|
|
4
4
|
exports.nxVersion = require('../../package.json').version;
|
|
5
5
|
exports.eslintVersion = '~8.57.0';
|
|
6
6
|
exports.eslintrcVersion = '^2.1.1';
|
|
7
|
-
exports.eslintConfigPrettierVersion = '^
|
|
7
|
+
exports.eslintConfigPrettierVersion = '^9.0.0';
|
|
8
8
|
exports.typescriptESLintVersion = '^7.16.0';
|
|
9
|
-
exports.jsoncEslintParserVersion = '^2.1.0';
|
|
10
9
|
// Updated linting stack for ESLint v9, typescript-eslint v8
|
|
11
|
-
exports.eslint9__typescriptESLintVersion = '^8.
|
|
10
|
+
exports.eslint9__typescriptESLintVersion = '^8.0.0';
|
|
12
11
|
exports.eslint9__eslintVersion = '^9.8.0';
|
|
13
12
|
exports.eslintCompat = '^1.1.1';
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = default_1;
|
|
4
|
-
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const semver_1 = require("semver");
|
|
6
|
-
const version_utils_1 = require("../../utils/version-utils");
|
|
7
|
-
async function default_1(tree) {
|
|
8
|
-
const devDependencies = {};
|
|
9
|
-
const checkPackageAndMigrate = (pkgName) => {
|
|
10
|
-
const pkgVersion = (0, version_utils_1.getInstalledPackageVersion)(pkgName, tree);
|
|
11
|
-
if (!!pkgVersion && (0, semver_1.gte)(pkgVersion, '8.0.0') && (0, semver_1.lt)(pkgVersion, '8.13.0')) {
|
|
12
|
-
devDependencies[pkgName] = '^8.13.0';
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
checkPackageAndMigrate('typescript-eslint');
|
|
16
|
-
checkPackageAndMigrate('@typescript-eslint/eslint-plugin');
|
|
17
|
-
checkPackageAndMigrate('@typescript-eslint/parser');
|
|
18
|
-
checkPackageAndMigrate('@typescript-eslint/utils');
|
|
19
|
-
if (Object.keys(devDependencies).length > 0) {
|
|
20
|
-
return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, devDependencies);
|
|
21
|
-
}
|
|
22
|
-
return () => { };
|
|
23
|
-
}
|