@nx/eslint 21.0.0-beta.1 → 21.0.0-beta.11
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/migrations.json +48 -85
- package/package.json +3 -3
- package/src/generators/lint-project/lint-project.js +8 -4
- package/src/generators/utils/eslint-file.js +19 -6
- package/src/generators/utils/flat-config/ast-utils.d.ts +2 -0
- package/src/generators/utils/flat-config/ast-utils.js +51 -0
- package/src/generators/utils/linter.d.ts +3 -0
- package/src/generators/utils/linter.js +2 -2
- package/src/plugins/plugin.js +8 -8
- package/src/utils/versions.d.ts +2 -1
- package/src/utils/versions.js +3 -2
- package/src/migrations/update-17-0-0-rename-to-eslint/update-17-0-0-rename-to-eslint.d.ts +0 -2
- package/src/migrations/update-17-0-0-rename-to-eslint/update-17-0-0-rename-to-eslint.js +0 -47
- package/src/migrations/update-17-1-0/update-typescript-eslint.d.ts +0 -2
- package/src/migrations/update-17-1-0/update-typescript-eslint.js +0 -74
- package/src/migrations/update-17-2-0/simplify-eslint-patterns.d.ts +0 -2
- package/src/migrations/update-17-2-0/simplify-eslint-patterns.js +0 -46
- package/src/migrations/update-17-2-9/move-options-to-target-defaults.d.ts +0 -2
- package/src/migrations/update-17-2-9/move-options-to-target-defaults.js +0 -107
package/migrations.json
CHANGED
@@ -1,25 +1,5 @@
|
|
1
1
|
{
|
2
2
|
"generators": {
|
3
|
-
"update-17-0-0-rename-to-eslint": {
|
4
|
-
"version": "17.0.0-beta.7",
|
5
|
-
"description": "update-17-0-0-rename-to-eslint",
|
6
|
-
"implementation": "./src/migrations/update-17-0-0-rename-to-eslint/update-17-0-0-rename-to-eslint"
|
7
|
-
},
|
8
|
-
"update-typescript-eslint": {
|
9
|
-
"version": "17.1.0-beta.1",
|
10
|
-
"description": "Updates for @typescript-utils/utils v6.9.1+",
|
11
|
-
"implementation": "./src/migrations/update-17-1-0/update-typescript-eslint"
|
12
|
-
},
|
13
|
-
"simplify-eslint-patterns": {
|
14
|
-
"version": "17.2.0-beta.0",
|
15
|
-
"description": "Simplify eslintFilePatterns",
|
16
|
-
"implementation": "./src/migrations/update-17-2-0/simplify-eslint-patterns"
|
17
|
-
},
|
18
|
-
"move-options-to-target-defaults": {
|
19
|
-
"version": "17.2.9",
|
20
|
-
"description": "Move executor options to target defaults",
|
21
|
-
"implementation": "./src/migrations/update-17-2-9/move-options-to-target-defaults"
|
22
|
-
},
|
23
3
|
"update-typescript-eslint-v8.13.0": {
|
24
4
|
"version": "20.2.0-beta.5",
|
25
5
|
"description": "Update TypeScript ESLint packages to v8.13.0 if they are already on v8",
|
@@ -32,67 +12,6 @@
|
|
32
12
|
}
|
33
13
|
},
|
34
14
|
"packageJsonUpdates": {
|
35
|
-
"17.0.0": {
|
36
|
-
"version": "17.0.0-rc.2",
|
37
|
-
"packages": {
|
38
|
-
"eslint-config-prettier": {
|
39
|
-
"version": "^9.0.0"
|
40
|
-
}
|
41
|
-
}
|
42
|
-
},
|
43
|
-
"17.1.0": {
|
44
|
-
"version": "17.1.0-beta.1",
|
45
|
-
"packages": {
|
46
|
-
"@typescript-eslint/parser": {
|
47
|
-
"version": "^6.9.1"
|
48
|
-
},
|
49
|
-
"@typescript-eslint/eslint-plugin": {
|
50
|
-
"version": "^6.9.1"
|
51
|
-
},
|
52
|
-
"@typescript-eslint/utils": {
|
53
|
-
"version": "^6.9.1"
|
54
|
-
}
|
55
|
-
}
|
56
|
-
},
|
57
|
-
"17.2.0": {
|
58
|
-
"version": "17.2.0-beta.2",
|
59
|
-
"packages": {
|
60
|
-
"eslint": {
|
61
|
-
"version": "~8.48.0"
|
62
|
-
}
|
63
|
-
}
|
64
|
-
},
|
65
|
-
"17.3.0": {
|
66
|
-
"version": "17.3.0-beta.0",
|
67
|
-
"packages": {
|
68
|
-
"@typescript-eslint/parser": {
|
69
|
-
"version": "^6.13.2"
|
70
|
-
},
|
71
|
-
"@typescript-eslint/eslint-plugin": {
|
72
|
-
"version": "^6.13.2"
|
73
|
-
},
|
74
|
-
"@typescript-eslint/utils": {
|
75
|
-
"version": "^6.13.2"
|
76
|
-
}
|
77
|
-
}
|
78
|
-
},
|
79
|
-
"18.2.0": {
|
80
|
-
"version": "18.2.0-beta.0",
|
81
|
-
"packages": {
|
82
|
-
"@typescript-eslint/parser": {
|
83
|
-
"version": "^7.3.0"
|
84
|
-
},
|
85
|
-
"@typescript-eslint/eslint-plugin": {
|
86
|
-
"version": "^7.3.0"
|
87
|
-
},
|
88
|
-
"@typescript-eslint/utils": {
|
89
|
-
"version": "^7.3.0"
|
90
|
-
},
|
91
|
-
"eslint": {
|
92
|
-
"version": "~8.57.0"
|
93
|
-
}
|
94
|
-
}
|
95
|
-
},
|
96
15
|
"19.5.0": {
|
97
16
|
"version": "19.5.0-beta.1",
|
98
17
|
"packages": {
|
@@ -104,6 +23,18 @@
|
|
104
23
|
},
|
105
24
|
"@typescript-eslint/utils": {
|
106
25
|
"version": "^7.16.0"
|
26
|
+
},
|
27
|
+
"@typescript-eslint/rule-tester": {
|
28
|
+
"version": "^7.16.0",
|
29
|
+
"alwaysAddToPackageJson": false
|
30
|
+
},
|
31
|
+
"@typescript-eslint/scope-manager": {
|
32
|
+
"version": "^7.16.0",
|
33
|
+
"alwaysAddToPackageJson": false
|
34
|
+
},
|
35
|
+
"@typescript-eslint/typescript-estree": {
|
36
|
+
"version": "^7.16.0",
|
37
|
+
"alwaysAddToPackageJson": false
|
107
38
|
}
|
108
39
|
}
|
109
40
|
},
|
@@ -116,14 +47,26 @@
|
|
116
47
|
"typescript-eslint": {
|
117
48
|
"version": "^8.19.0"
|
118
49
|
},
|
119
|
-
"@typescript-eslint/
|
50
|
+
"@typescript-eslint/eslint-plugin": {
|
120
51
|
"version": "^8.19.0"
|
121
52
|
},
|
122
|
-
"@typescript-eslint/
|
53
|
+
"@typescript-eslint/parser": {
|
123
54
|
"version": "^8.19.0"
|
124
55
|
},
|
125
56
|
"@typescript-eslint/utils": {
|
126
57
|
"version": "^8.19.0"
|
58
|
+
},
|
59
|
+
"@typescript-eslint/rule-tester": {
|
60
|
+
"version": "^8.19.0",
|
61
|
+
"alwaysAddToPackageJson": false
|
62
|
+
},
|
63
|
+
"@typescript-eslint/scope-manager": {
|
64
|
+
"version": "^8.19.0",
|
65
|
+
"alwaysAddToPackageJson": false
|
66
|
+
},
|
67
|
+
"@typescript-eslint/typescript-estree": {
|
68
|
+
"version": "^8.19.0",
|
69
|
+
"alwaysAddToPackageJson": false
|
127
70
|
}
|
128
71
|
}
|
129
72
|
},
|
@@ -136,14 +79,34 @@
|
|
136
79
|
"typescript-eslint": {
|
137
80
|
"version": "^8.19.0"
|
138
81
|
},
|
139
|
-
"@typescript-eslint/
|
82
|
+
"@typescript-eslint/eslint-plugin": {
|
140
83
|
"version": "^8.19.0"
|
141
84
|
},
|
142
|
-
"@typescript-eslint/
|
85
|
+
"@typescript-eslint/parser": {
|
143
86
|
"version": "^8.19.0"
|
144
87
|
},
|
145
88
|
"@typescript-eslint/utils": {
|
146
89
|
"version": "^8.19.0"
|
90
|
+
},
|
91
|
+
"@typescript-eslint/rule-tester": {
|
92
|
+
"version": "^8.19.0",
|
93
|
+
"alwaysAddToPackageJson": false
|
94
|
+
},
|
95
|
+
"@typescript-eslint/scope-manager": {
|
96
|
+
"version": "^8.19.0",
|
97
|
+
"alwaysAddToPackageJson": false
|
98
|
+
},
|
99
|
+
"@typescript-eslint/typescript-estree": {
|
100
|
+
"version": "^8.19.0",
|
101
|
+
"alwaysAddToPackageJson": false
|
102
|
+
}
|
103
|
+
}
|
104
|
+
},
|
105
|
+
"20.7.0": {
|
106
|
+
"version": "20.7.0-beta.4",
|
107
|
+
"packages": {
|
108
|
+
"eslint-config-prettier": {
|
109
|
+
"version": "^10.0.0"
|
147
110
|
}
|
148
111
|
}
|
149
112
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nx/eslint",
|
3
|
-
"version": "21.0.0-beta.
|
3
|
+
"version": "21.0.0-beta.11",
|
4
4
|
"private": false,
|
5
5
|
"description": "The ESLint plugin for Nx contains executors, generators and utilities used for linting JavaScript/TypeScript projects within an Nx workspace.",
|
6
6
|
"repository": {
|
@@ -35,8 +35,8 @@
|
|
35
35
|
"eslint": "^8.0.0 || ^9.0.0"
|
36
36
|
},
|
37
37
|
"dependencies": {
|
38
|
-
"@nx/devkit": "21.0.0-beta.
|
39
|
-
"@nx/js": "21.0.0-beta.
|
38
|
+
"@nx/devkit": "21.0.0-beta.11",
|
39
|
+
"@nx/js": "21.0.0-beta.11",
|
40
40
|
"semver": "^7.5.3",
|
41
41
|
"tslib": "^2.3.0",
|
42
42
|
"typescript": "~5.7.2"
|
@@ -12,6 +12,7 @@ const flat_config_1 = require("../../utils/flat-config");
|
|
12
12
|
const ast_utils_1 = require("../utils/flat-config/ast-utils");
|
13
13
|
const config_file_1 = require("../../utils/config-file");
|
14
14
|
const plugin_1 = require("../utils/plugin");
|
15
|
+
const versions_1 = require("../../utils/versions");
|
15
16
|
const setup_root_eslint_1 = require("./setup-root-eslint");
|
16
17
|
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
17
18
|
function lintProjectGenerator(tree, options) {
|
@@ -96,7 +97,12 @@ async function lintProjectGeneratorInternal(tree, options) {
|
|
96
97
|
// additionally, the companion e2e app would have `rootProject: true`
|
97
98
|
// so we need to check for the root path as well
|
98
99
|
if (!options.rootProject || projectConfig.root !== '.') {
|
99
|
-
|
100
|
+
const addDependencyChecks = options.addPackageJsonDependencyChecks ||
|
101
|
+
isBuildableLibraryProject(tree, projectConfig);
|
102
|
+
createEsLintConfiguration(tree, options, projectConfig, options.setParserOptionsProject, options.rootProject, addDependencyChecks);
|
103
|
+
if (addDependencyChecks) {
|
104
|
+
tasks.push((0, devkit_1.addDependenciesToPackageJson)(tree, {}, { 'jsonc-eslint-parser': versions_1.jsoncEslintParserVersion }, undefined, true));
|
105
|
+
}
|
100
106
|
}
|
101
107
|
// Buildable libs need source analysis enabled for linting `package.json`.
|
102
108
|
if (isBuildableLibraryProject(tree, projectConfig) &&
|
@@ -114,7 +120,7 @@ async function lintProjectGeneratorInternal(tree, options) {
|
|
114
120
|
}
|
115
121
|
return (0, devkit_1.runTasksInSerial)(...tasks);
|
116
122
|
}
|
117
|
-
function createEsLintConfiguration(tree, options, projectConfig, setParserOptionsProject, rootProject) {
|
123
|
+
function createEsLintConfiguration(tree, options, projectConfig, setParserOptionsProject, rootProject, addDependencyChecks) {
|
118
124
|
// we are only extending root for non-standalone projects or their complementary e2e apps
|
119
125
|
const extendedRootConfig = rootProject ? undefined : (0, eslint_file_1.findEslintFile)(tree);
|
120
126
|
const pathToRootConfig = extendedRootConfig
|
@@ -132,8 +138,6 @@ function createEsLintConfiguration(tree, options, projectConfig, setParserOption
|
|
132
138
|
options.eslintConfigFormat = (0, eslint_file_1.determineEslintConfigFormat)(tree.read(extendedRootConfig, 'utf-8'));
|
133
139
|
}
|
134
140
|
}
|
135
|
-
const addDependencyChecks = options.addPackageJsonDependencyChecks ||
|
136
|
-
isBuildableLibraryProject(tree, projectConfig);
|
137
141
|
const overrides = (0, flat_config_1.useFlatConfig)(tree)
|
138
142
|
? // For flat configs, we don't need to generate different overrides for each file. Users should add their own overrides as needed.
|
139
143
|
[]
|
@@ -357,9 +357,9 @@ function addExtendsToLintConfig(tree, root, plugin, insertAtTheEnd = false) {
|
|
357
357
|
}
|
358
358
|
tree.write(fileName, content);
|
359
359
|
if (shouldImportEslintCompat) {
|
360
|
-
return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { '@eslint/compat': versions_1.eslintCompat }, undefined, true);
|
360
|
+
return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { '@eslint/compat': versions_1.eslintCompat, '@eslint/eslintrc': versions_1.eslintrcVersion }, undefined, true);
|
361
361
|
}
|
362
|
-
return ()
|
362
|
+
return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { '@eslint/eslintrc': versions_1.eslintrcVersion }, undefined, true);
|
363
363
|
}
|
364
364
|
else {
|
365
365
|
const plugins = (Array.isArray(plugin) ? plugin : [plugin]).map((p) => typeof p === 'string' ? p : p.name);
|
@@ -430,13 +430,26 @@ function addIgnoresToLintConfig(tree, root, ignorePatterns) {
|
|
430
430
|
break;
|
431
431
|
}
|
432
432
|
}
|
433
|
-
|
434
|
-
|
435
|
-
}
|
436
|
-
|
433
|
+
if (!fileName) {
|
434
|
+
return;
|
435
|
+
}
|
436
|
+
let content = tree.read(fileName, 'utf8');
|
437
|
+
if ((0, ast_utils_1.hasFlatConfigIgnoresBlock)(content)) {
|
438
|
+
content = (0, ast_utils_1.addPatternsToFlatConfigIgnoresBlock)(content, ignorePatterns);
|
439
|
+
tree.write(fileName, content);
|
440
|
+
}
|
441
|
+
else {
|
442
|
+
const block = (0, ast_utils_1.generateAst)({
|
443
|
+
ignores: ignorePatterns.map((path) => (0, path_utils_1.mapFilePath)(path)),
|
444
|
+
});
|
445
|
+
tree.write(fileName, (0, ast_utils_1.addBlockToFlatConfigExport)(content, block));
|
446
|
+
}
|
437
447
|
}
|
438
448
|
else {
|
439
449
|
const fileName = (0, devkit_1.joinPathFragments)(root, '.eslintrc.json');
|
450
|
+
if (!tree.exists(fileName)) {
|
451
|
+
return;
|
452
|
+
}
|
440
453
|
(0, devkit_1.updateJson)(tree, fileName, (json) => {
|
441
454
|
const ignoreSet = new Set([
|
442
455
|
...(json.ignorePatterns ?? []),
|
@@ -4,6 +4,8 @@ import * as ts from 'typescript';
|
|
4
4
|
* Remove all overrides from the config file
|
5
5
|
*/
|
6
6
|
export declare function removeOverridesFromLintConfig(content: string): string;
|
7
|
+
export declare function addPatternsToFlatConfigIgnoresBlock(content: string, ignorePatterns: string[]): string;
|
8
|
+
export declare function hasFlatConfigIgnoresBlock(content: string): boolean;
|
7
9
|
export declare function hasOverride(content: string, lookup: (override: Linter.ConfigOverride<Linter.RulesRecord>) => boolean): boolean;
|
8
10
|
/**
|
9
11
|
* Finds an override matching the lookup function and applies the update function to it
|
@@ -1,6 +1,8 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.removeOverridesFromLintConfig = removeOverridesFromLintConfig;
|
4
|
+
exports.addPatternsToFlatConfigIgnoresBlock = addPatternsToFlatConfigIgnoresBlock;
|
5
|
+
exports.hasFlatConfigIgnoresBlock = hasFlatConfigIgnoresBlock;
|
4
6
|
exports.hasOverride = hasOverride;
|
5
7
|
exports.replaceOverride = replaceOverride;
|
6
8
|
exports.addImportToFlatConfig = addImportToFlatConfig;
|
@@ -73,6 +75,55 @@ function findModuleExports(source) {
|
|
73
75
|
}
|
74
76
|
});
|
75
77
|
}
|
78
|
+
function addPatternsToFlatConfigIgnoresBlock(content, ignorePatterns) {
|
79
|
+
const source = ts.createSourceFile('', content, ts.ScriptTarget.Latest, true, ts.ScriptKind.JS);
|
80
|
+
const format = content.includes('export default') ? 'mjs' : 'cjs';
|
81
|
+
const exportsArray = format === 'mjs' ? findExportDefault(source) : findModuleExports(source);
|
82
|
+
if (!exportsArray) {
|
83
|
+
return content;
|
84
|
+
}
|
85
|
+
const changes = [];
|
86
|
+
for (const node of exportsArray) {
|
87
|
+
if (!isFlatConfigIgnoresBlock(node)) {
|
88
|
+
continue;
|
89
|
+
}
|
90
|
+
const start = node.properties.pos + 1; // keep leading line break
|
91
|
+
const data = parseTextToJson(node.getFullText());
|
92
|
+
changes.push({
|
93
|
+
type: devkit_1.ChangeType.Delete,
|
94
|
+
start,
|
95
|
+
length: node.properties.end - start,
|
96
|
+
});
|
97
|
+
data.ignores = Array.from(new Set([...(data.ignores ?? []), ...ignorePatterns]));
|
98
|
+
changes.push({
|
99
|
+
type: devkit_1.ChangeType.Insert,
|
100
|
+
index: start,
|
101
|
+
text: ' ' +
|
102
|
+
JSON.stringify(data, null, 2)
|
103
|
+
.slice(2, -2) // Remove curly braces and start/end line breaks
|
104
|
+
.replaceAll(/\n/g, '\n '), // Maintain indentation
|
105
|
+
});
|
106
|
+
break;
|
107
|
+
}
|
108
|
+
return (0, devkit_1.applyChangesToString)(content, changes);
|
109
|
+
}
|
110
|
+
function hasFlatConfigIgnoresBlock(content) {
|
111
|
+
const source = ts.createSourceFile('', content, ts.ScriptTarget.Latest, true, ts.ScriptKind.JS);
|
112
|
+
const format = content.includes('export default') ? 'mjs' : 'cjs';
|
113
|
+
const exportsArray = format === 'mjs' ? findExportDefault(source) : findModuleExports(source);
|
114
|
+
if (!exportsArray) {
|
115
|
+
return false;
|
116
|
+
}
|
117
|
+
return exportsArray.some(isFlatConfigIgnoresBlock);
|
118
|
+
}
|
119
|
+
function isFlatConfigIgnoresBlock(node) {
|
120
|
+
return (ts.isObjectLiteralExpression(node) &&
|
121
|
+
node.properties.length === 1 &&
|
122
|
+
(node.properties[0].name.getText() === 'ignores' ||
|
123
|
+
node.properties[0].name.getText() === '"ignores"') &&
|
124
|
+
ts.isPropertyAssignment(node.properties[0]) &&
|
125
|
+
ts.isArrayLiteralExpression(node.properties[0].initializer));
|
126
|
+
}
|
76
127
|
function isOverride(node) {
|
77
128
|
return ((ts.isObjectLiteralExpression(node) &&
|
78
129
|
node.properties.some((p) => p.name.getText() === 'files' || p.name.getText() === '"files"')) ||
|
@@ -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. It will be removed in Nx v22.
|
6
6
|
*/
|
7
7
|
var Linter;
|
8
8
|
(function (Linter) {
|
package/src/plugins/plugin.js
CHANGED
@@ -107,7 +107,7 @@ const internalCreateNodes = async (configFilePath, options, context, projectsCac
|
|
107
107
|
projects,
|
108
108
|
};
|
109
109
|
};
|
110
|
-
const internalCreateNodesV2 = async (configFilePath, options, context,
|
110
|
+
const internalCreateNodesV2 = async (configFilePath, options, context, projectRootsByEslintRoots, lintableFilesPerProjectRoot, projectsCache, hashByRoot) => {
|
111
111
|
const configDir = (0, posix_1.dirname)(configFilePath);
|
112
112
|
const ESLint = await (0, resolve_eslint_class_1.resolveESLintClass)({
|
113
113
|
useFlatConfigOverrideVal: (0, config_file_1.isFlatConfig)(configFilePath),
|
@@ -115,12 +115,7 @@ const internalCreateNodesV2 = async (configFilePath, options, context, eslintCon
|
|
115
115
|
const eslintVersion = ESLint.version;
|
116
116
|
const projects = {};
|
117
117
|
await Promise.all(projectRootsByEslintRoots.get(configDir).map(async (projectRoot) => {
|
118
|
-
const
|
119
|
-
const hash = await (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options, {
|
120
|
-
configFiles: eslintConfigFiles,
|
121
|
-
nxJsonConfiguration: context.nxJsonConfiguration,
|
122
|
-
workspaceRoot: context.workspaceRoot,
|
123
|
-
}, [...parentConfigs, (0, posix_1.join)(projectRoot, '.eslintignore')]);
|
118
|
+
const hash = hashByRoot.get(projectRoot);
|
124
119
|
if (projectsCache[hash]) {
|
125
120
|
// We can reuse the projects in the cache.
|
126
121
|
Object.assign(projects, projectsCache[hash]);
|
@@ -165,8 +160,13 @@ exports.createNodesV2 = [
|
|
165
160
|
const targetsCache = readTargetsCache(cachePath);
|
166
161
|
const { eslintConfigFiles, projectRoots, projectRootsByEslintRoots } = splitConfigFiles(configFiles);
|
167
162
|
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
168
|
try {
|
169
|
-
return await (0, devkit_1.createNodesFromFiles)((configFile, options, context) => internalCreateNodesV2(configFile, options, context,
|
169
|
+
return await (0, devkit_1.createNodesFromFiles)((configFile, options, context) => internalCreateNodesV2(configFile, options, context, projectRootsByEslintRoots, lintableFilesPerProjectRoot, targetsCache, hashByRoot), eslintConfigFiles, options, context);
|
170
170
|
}
|
171
171
|
finally {
|
172
172
|
writeTargetsToCache(cachePath, targetsCache);
|
package/src/utils/versions.d.ts
CHANGED
@@ -1,8 +1,9 @@
|
|
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 = "^10.0.0";
|
5
5
|
export declare const typescriptESLintVersion = "^7.16.0";
|
6
|
+
export declare const jsoncEslintParserVersion = "^2.1.0";
|
6
7
|
export declare const eslint9__typescriptESLintVersion = "^8.19.0";
|
7
8
|
export declare const eslint9__eslintVersion = "^9.8.0";
|
8
9
|
export declare const eslintCompat = "^1.1.1";
|
package/src/utils/versions.js
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.eslintCompat = exports.eslint9__eslintVersion = exports.eslint9__typescriptESLintVersion = exports.typescriptESLintVersion = exports.eslintConfigPrettierVersion = exports.eslintrcVersion = exports.eslintVersion = exports.nxVersion = void 0;
|
3
|
+
exports.eslintCompat = exports.eslint9__eslintVersion = exports.eslint9__typescriptESLintVersion = exports.jsoncEslintParserVersion = 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 = '^10.0.0';
|
8
8
|
exports.typescriptESLintVersion = '^7.16.0';
|
9
|
+
exports.jsoncEslintParserVersion = '^2.1.0';
|
9
10
|
// Updated linting stack for ESLint v9, typescript-eslint v8
|
10
11
|
exports.eslint9__typescriptESLintVersion = '^8.19.0';
|
11
12
|
exports.eslint9__eslintVersion = '^9.8.0';
|
@@ -1,47 +0,0 @@
|
|
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
|
-
}
|
@@ -1,74 +0,0 @@
|
|
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
|
-
}
|
@@ -1,46 +0,0 @@
|
|
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
|
-
}
|
@@ -1,107 +0,0 @@
|
|
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
|
-
}
|