@nx/eslint 21.2.0-beta.1 → 21.2.0-beta.3
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/README.md +1 -1
- package/package.json +3 -3
- package/src/generators/convert-to-flat-config/converters/json-converter.js +1 -1
- package/src/generators/convert-to-inferred/convert-to-inferred.js +23 -8
- package/src/generators/init/global-eslint-config.js +1 -1
- package/src/generators/lint-project/lint-project.js +4 -2
- package/src/plugins/plugin.js +14 -4
- package/src/utils/flat-config.js +7 -0
package/README.md
CHANGED
@@ -22,7 +22,7 @@
|
|
22
22
|
|
23
23
|
# Nx: Smart Repos · Fast Builds
|
24
24
|
|
25
|
-
|
25
|
+
An AI-first build platform that connects everything from your editor to CI. Helping you deliver fast, without breaking things.
|
26
26
|
|
27
27
|
## Getting Started
|
28
28
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nx/eslint",
|
3
|
-
"version": "21.2.0-beta.
|
3
|
+
"version": "21.2.0-beta.3",
|
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.2.0-beta.
|
39
|
-
"@nx/js": "21.2.0-beta.
|
38
|
+
"@nx/devkit": "21.2.0-beta.3",
|
39
|
+
"@nx/js": "21.2.0-beta.3",
|
40
40
|
"semver": "^7.5.3",
|
41
41
|
"tslib": "^2.3.0",
|
42
42
|
"typescript": "~5.8.2"
|
@@ -91,7 +91,7 @@ function convertEslintJsonToFlatConfig(tree, root, config, ignorePaths, format)
|
|
91
91
|
if (tree.exists(ignorePath)) {
|
92
92
|
const patterns = tree
|
93
93
|
.read(ignorePath, 'utf-8')
|
94
|
-
.split(
|
94
|
+
.split(/\r\n|\r|\n/)
|
95
95
|
.filter((line) => line.length > 0 && line !== 'node_modules')
|
96
96
|
.map((path) => (0, path_utils_1.mapFilePath)(path));
|
97
97
|
if (patterns.length > 0) {
|
@@ -28,14 +28,29 @@ async function convertToInferred(tree, options) {
|
|
28
28
|
}
|
29
29
|
function postTargetTransformer(target, tree, projectDetails, inferredTargetConfiguration) {
|
30
30
|
if (target.inputs) {
|
31
|
-
const
|
32
|
-
|
33
|
-
'
|
34
|
-
'{
|
35
|
-
'{
|
36
|
-
|
37
|
-
|
38
|
-
|
31
|
+
const normalizeInput = (input) => {
|
32
|
+
return input
|
33
|
+
.replace('{workspaceRoot}', '')
|
34
|
+
.replace('{projectRoot}', projectDetails.root)
|
35
|
+
.replace('{projectName}', projectDetails.projectName)
|
36
|
+
.replace(/^\//, '');
|
37
|
+
};
|
38
|
+
const inputs = target.inputs.filter((input) => {
|
39
|
+
if (typeof input === 'string') {
|
40
|
+
// if the input is a string, check if it is inferred by the plugin
|
41
|
+
// if it is, filter it out
|
42
|
+
return !inferredTargetConfiguration.inputs.some((inferredInput) => typeof inferredInput === 'string' &&
|
43
|
+
normalizeInput(inferredInput) === normalizeInput(input));
|
44
|
+
}
|
45
|
+
else if ('externalDependencies' in input) {
|
46
|
+
// if the input is an object with an externalDependencies property,
|
47
|
+
// check if all the external dependencies are inferred by the plugin
|
48
|
+
// if they are, filter it out
|
49
|
+
return !input.externalDependencies.every((externalDependency) => inferredTargetConfiguration.inputs.some((inferredInput) => typeof inferredInput === 'object' &&
|
50
|
+
'externalDependencies' in inferredInput &&
|
51
|
+
inferredInput.externalDependencies.includes(externalDependency)));
|
52
|
+
}
|
53
|
+
});
|
39
54
|
if (inputs.length === 0) {
|
40
55
|
delete target.inputs;
|
41
56
|
}
|
@@ -99,7 +99,7 @@ const getGlobalFlatEslintConfiguration = (format, rootProject) => {
|
|
99
99
|
allow: [
|
100
100
|
// This allows a root project to be present without causing lint errors
|
101
101
|
// since all projects will depend on this base file.
|
102
|
-
'^.*/eslint(\\.base)?\\.config\\.[cm]?
|
102
|
+
'^.*/eslint(\\.base)?\\.config\\.[cm]?[jt]s$',
|
103
103
|
],
|
104
104
|
depConstraints: [
|
105
105
|
{ sourceTag: '*', onlyDependOnLibsWithTags: ['*'] },
|
@@ -185,8 +185,10 @@ function createEsLintConfiguration(tree, options, projectConfig, setParserOption
|
|
185
185
|
'@nx/dependency-checks': [
|
186
186
|
'error',
|
187
187
|
{
|
188
|
-
// With flat configs, we don't want to include imports in the eslint js/cjs/mjs files to be checked
|
189
|
-
ignoredFiles: [
|
188
|
+
// With flat configs, we don't want to include imports in the eslint js/cjs/mjs/ts/cts/mts files to be checked
|
189
|
+
ignoredFiles: [
|
190
|
+
'{projectRoot}/eslint.config.{js,cjs,mjs,ts,cts,mts}',
|
191
|
+
],
|
190
192
|
},
|
191
193
|
],
|
192
194
|
},
|
package/src/plugins/plugin.js
CHANGED
@@ -71,7 +71,12 @@ const internalCreateNodes = async (configFilePath, options, context, projectsCac
|
|
71
71
|
// exclude nested eslint roots and nested project roots
|
72
72
|
[...nestedEslintRootPatterns, ...nestedProjectRootPatterns]);
|
73
73
|
const parentConfigs = context.configFiles.filter((eslintConfig) => isSubDir(childProjectRoot, (0, posix_1.dirname)(eslintConfig)));
|
74
|
-
const hash = await (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(childProjectRoot,
|
74
|
+
const hash = await (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(childProjectRoot, {
|
75
|
+
...options,
|
76
|
+
// change this to bust the cache when making changes that would yield
|
77
|
+
// different results for the same hash
|
78
|
+
bust: 1,
|
79
|
+
}, context, [...parentConfigs, (0, posix_1.join)(childProjectRoot, '.eslintignore')]);
|
75
80
|
if (projectsCache[hash]) {
|
76
81
|
// We can reuse the projects in the cache.
|
77
82
|
Object.assign(projects, projectsCache[hash]);
|
@@ -162,7 +167,12 @@ exports.createNodesV2 = [
|
|
162
167
|
const targetsCache = readTargetsCache(cachePath);
|
163
168
|
const { eslintConfigFiles, projectRoots, projectRootsByEslintRoots } = splitConfigFiles(configFiles);
|
164
169
|
const lintableFilesPerProjectRoot = await collectLintableFilesByProjectRoot(projectRoots, options, context);
|
165
|
-
const hashes = await (0, calculate_hash_for_create_nodes_1.calculateHashesForCreateNodes)(projectRoots,
|
170
|
+
const hashes = await (0, calculate_hash_for_create_nodes_1.calculateHashesForCreateNodes)(projectRoots, {
|
171
|
+
...options,
|
172
|
+
// change this to bust the cache when making changes that would yield
|
173
|
+
// different results for the same hash
|
174
|
+
bust: 1,
|
175
|
+
}, context, projectRoots.map((root) => {
|
166
176
|
const parentConfigs = eslintConfigFiles.filter((eslintConfig) => isSubDir(root, (0, posix_1.dirname)(eslintConfig)));
|
167
177
|
return [...parentConfigs, (0, posix_1.join)(root, '.eslintignore')];
|
168
178
|
}));
|
@@ -287,9 +297,9 @@ function buildEslintTargets(eslintConfigs, eslintVersion, projectRoot, workspace
|
|
287
297
|
'default',
|
288
298
|
// Certain lint rules can be impacted by changes to dependencies
|
289
299
|
'^default',
|
290
|
-
...eslintConfigs.map((config) => `{workspaceRoot}/${config}
|
300
|
+
...eslintConfigs.map((config) => `{workspaceRoot}/${config}`),
|
291
301
|
...((0, node_fs_1.existsSync)((0, posix_1.join)(workspaceRoot, projectRoot, '.eslintignore'))
|
292
|
-
? ['{projectRoot
|
302
|
+
? [(0, posix_1.join)('{workspaceRoot}', projectRoot, '.eslintignore')]
|
293
303
|
: []),
|
294
304
|
'{workspaceRoot}/tools/eslint-rules/**/*',
|
295
305
|
{ externalDependencies: ['eslint'] },
|
package/src/utils/flat-config.js
CHANGED
@@ -8,12 +8,19 @@ exports.eslintFlatConfigFilenames = [
|
|
8
8
|
'eslint.config.cjs',
|
9
9
|
'eslint.config.js',
|
10
10
|
'eslint.config.mjs',
|
11
|
+
'eslint.config.cts',
|
12
|
+
'eslint.config.ts',
|
13
|
+
'eslint.config.mts',
|
11
14
|
];
|
12
15
|
exports.baseEslintConfigFilenames = [
|
13
16
|
'eslint.base.js',
|
17
|
+
'eslint.base.ts',
|
14
18
|
'eslint.base.config.cjs',
|
15
19
|
'eslint.base.config.js',
|
16
20
|
'eslint.base.config.mjs',
|
21
|
+
'eslint.base.config.cts',
|
22
|
+
'eslint.base.config.ts',
|
23
|
+
'eslint.base.config.mts',
|
17
24
|
];
|
18
25
|
function getRootESLintFlatConfigFilename(tree) {
|
19
26
|
for (const file of exports.eslintFlatConfigFilenames) {
|