@nx/eslint 19.4.2 → 19.4.4
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 +4 -4
- package/src/plugins/plugin.js +32 -32
package/README.md
CHANGED
@@ -59,7 +59,7 @@ npx nx@latest init
|
|
59
59
|
- [Nx.Dev: Documentation, Guides, Tutorials](https://nx.dev)
|
60
60
|
- [Intro to Nx](https://nx.dev/getting-started/intro)
|
61
61
|
- [Official Nx YouTube Channel](https://www.youtube.com/@NxDevtools)
|
62
|
-
- [Blog Posts About Nx](https://
|
62
|
+
- [Blog Posts About Nx](https://nx.dev/blog)
|
63
63
|
|
64
64
|
<p style="text-align: center;"><a href="https://nx.dev/#learning-materials" target="_blank" rel="noreferrer"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-courses-and-videos.svg"
|
65
65
|
width="100%" alt="Nx - Smart Monorepos · Fast CI"></a></p>
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nx/eslint",
|
3
|
-
"version": "19.4.
|
3
|
+
"version": "19.4.4",
|
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,12 +35,12 @@
|
|
35
35
|
"eslint": "^8.0.0 || ^9.0.0"
|
36
36
|
},
|
37
37
|
"dependencies": {
|
38
|
-
"@nx/devkit": "19.4.
|
39
|
-
"@nx/js": "19.4.
|
38
|
+
"@nx/devkit": "19.4.4",
|
39
|
+
"@nx/js": "19.4.4",
|
40
40
|
"semver": "^7.5.3",
|
41
41
|
"tslib": "^2.3.0",
|
42
42
|
"typescript": "~5.4.2",
|
43
|
-
"@nx/linter": "19.4.
|
43
|
+
"@nx/linter": "19.4.4"
|
44
44
|
},
|
45
45
|
"peerDependenciesMeta": {
|
46
46
|
"@zkochan/js-yaml": {
|
package/src/plugins/plugin.js
CHANGED
@@ -4,7 +4,7 @@ exports.createNodes = exports.createNodesV2 = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
5
5
|
const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
|
6
6
|
const node_fs_1 = require("node:fs");
|
7
|
-
const
|
7
|
+
const posix_1 = require("node:path/posix");
|
8
8
|
const file_hasher_1 = require("nx/src/hasher/file-hasher");
|
9
9
|
const cache_directory_1 = require("nx/src/utils/cache-directory");
|
10
10
|
const globs_1 = require("nx/src/utils/globs");
|
@@ -30,7 +30,7 @@ function writeTargetsToCache(cachePath, results) {
|
|
30
30
|
}
|
31
31
|
const internalCreateNodes = async (configFilePath, options, context, projectsCache) => {
|
32
32
|
options = normalizeOptions(options);
|
33
|
-
const configDir = (0,
|
33
|
+
const configDir = (0, posix_1.dirname)(configFilePath);
|
34
34
|
// Ensure that configFiles are set, e2e-run fails due to them being undefined in CI (does not occur locally)
|
35
35
|
// TODO(JamesHenry): Further troubleshoot this in CI
|
36
36
|
context.configFiles = context.configFiles ?? [];
|
@@ -38,14 +38,14 @@ const internalCreateNodes = async (configFilePath, options, context, projectsCac
|
|
38
38
|
// list of globs to exclude from child projects
|
39
39
|
const nestedEslintRootPatterns = [];
|
40
40
|
for (const configFile of context.configFiles) {
|
41
|
-
const eslintRootDir = (0,
|
41
|
+
const eslintRootDir = (0, posix_1.dirname)(configFile);
|
42
42
|
if (eslintRootDir !== configDir && isSubDir(configDir, eslintRootDir)) {
|
43
43
|
nestedEslintRootPatterns.push(`${eslintRootDir}/**/*`);
|
44
44
|
}
|
45
45
|
}
|
46
|
-
const projectFiles = await (0, workspace_context_1.globWithWorkspaceContext)(context.workspaceRoot, ['project.json', 'package.json', '**/project.json', '**/package.json'].map((f) => (0,
|
46
|
+
const projectFiles = await (0, workspace_context_1.globWithWorkspaceContext)(context.workspaceRoot, ['project.json', 'package.json', '**/project.json', '**/package.json'].map((f) => (0, posix_1.join)(configDir, f)), nestedEslintRootPatterns.length ? nestedEslintRootPatterns : undefined);
|
47
47
|
// dedupe and sort project roots by depth for more efficient traversal
|
48
|
-
const dedupedProjectRoots = Array.from(new Set(projectFiles.map((f) => (0,
|
48
|
+
const dedupedProjectRoots = Array.from(new Set(projectFiles.map((f) => (0, posix_1.dirname)(f)))).sort((a, b) => (a !== b && isSubDir(a, b) ? -1 : 1));
|
49
49
|
const excludePatterns = dedupedProjectRoots.map((root) => `${root}/**/*`);
|
50
50
|
const ESLint = await (0, resolve_eslint_class_1.resolveESLintClass)((0, config_file_1.isFlatConfig)(configFilePath));
|
51
51
|
const eslintVersion = ESLint.version;
|
@@ -54,22 +54,22 @@ const internalCreateNodes = async (configFilePath, options, context, projectsCac
|
|
54
54
|
// anything after is either a nested project or a sibling project, can be excluded
|
55
55
|
const nestedProjectRootPatterns = excludePatterns.slice(index + 1);
|
56
56
|
// Ignore project roots where the project does not contain any lintable files
|
57
|
-
const lintableFiles = await (0, workspace_context_1.globWithWorkspaceContext)(context.workspaceRoot, [(0,
|
57
|
+
const lintableFiles = await (0, workspace_context_1.globWithWorkspaceContext)(context.workspaceRoot, [(0, posix_1.join)(childProjectRoot, `**/*.{${options.extensions.join(',')}}`)],
|
58
58
|
// exclude nested eslint roots and nested project roots
|
59
59
|
[...nestedEslintRootPatterns, ...nestedProjectRootPatterns]);
|
60
|
-
const parentConfigs = context.configFiles.filter((eslintConfig) => isSubDir(childProjectRoot, (0,
|
61
|
-
const hash = await (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(childProjectRoot, options, context, [...parentConfigs, (0,
|
60
|
+
const parentConfigs = context.configFiles.filter((eslintConfig) => isSubDir(childProjectRoot, (0, posix_1.dirname)(eslintConfig)));
|
61
|
+
const hash = await (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(childProjectRoot, options, context, [...parentConfigs, (0, posix_1.join)(childProjectRoot, '.eslintignore')]);
|
62
62
|
if (projectsCache[hash]) {
|
63
63
|
// We can reuse the projects in the cache.
|
64
64
|
Object.assign(projects, projectsCache[hash]);
|
65
65
|
return;
|
66
66
|
}
|
67
67
|
const eslint = new ESLint({
|
68
|
-
cwd: (0,
|
68
|
+
cwd: (0, posix_1.join)(context.workspaceRoot, childProjectRoot),
|
69
69
|
});
|
70
70
|
let hasNonIgnoredLintableFiles = false;
|
71
71
|
for (const file of lintableFiles) {
|
72
|
-
if (!(await eslint.isPathIgnored((0,
|
72
|
+
if (!(await eslint.isPathIgnored((0, posix_1.join)(context.workspaceRoot, file)))) {
|
73
73
|
hasNonIgnoredLintableFiles = true;
|
74
74
|
break;
|
75
75
|
}
|
@@ -96,17 +96,17 @@ const internalCreateNodes = async (configFilePath, options, context, projectsCac
|
|
96
96
|
};
|
97
97
|
let collectingLintableFilesPromise;
|
98
98
|
const internalCreateNodesV2 = async (configFilePath, options, context, eslintConfigFiles, allProjectRoots, projectRootsByEslintRoots, lintableFilesPerProjectRoot, projectsCache) => {
|
99
|
-
const configDir = (0,
|
99
|
+
const configDir = (0, posix_1.dirname)(configFilePath);
|
100
100
|
const ESLint = await (0, resolve_eslint_class_1.resolveESLintClass)((0, config_file_1.isFlatConfig)(configFilePath));
|
101
101
|
const eslintVersion = ESLint.version;
|
102
102
|
const projects = {};
|
103
103
|
await Promise.all(projectRootsByEslintRoots.get(configDir).map(async (projectRoot) => {
|
104
|
-
const parentConfigs = eslintConfigFiles.filter((eslintConfig) => isSubDir(projectRoot, (0,
|
104
|
+
const parentConfigs = eslintConfigFiles.filter((eslintConfig) => isSubDir(projectRoot, (0, posix_1.dirname)(eslintConfig)));
|
105
105
|
const hash = await (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options, {
|
106
106
|
configFiles: eslintConfigFiles,
|
107
107
|
nxJsonConfiguration: context.nxJsonConfiguration,
|
108
108
|
workspaceRoot: context.workspaceRoot,
|
109
|
-
}, [...parentConfigs, (0,
|
109
|
+
}, [...parentConfigs, (0, posix_1.join)(projectRoot, '.eslintignore')]);
|
110
110
|
if (projectsCache[hash]) {
|
111
111
|
// We can reuse the projects in the cache.
|
112
112
|
Object.assign(projects, projectsCache[hash]);
|
@@ -118,11 +118,11 @@ const internalCreateNodesV2 = async (configFilePath, options, context, eslintCon
|
|
118
118
|
collectingLintableFilesPromise = null;
|
119
119
|
}
|
120
120
|
const eslint = new ESLint({
|
121
|
-
cwd: (0,
|
121
|
+
cwd: (0, posix_1.join)(context.workspaceRoot, projectRoot),
|
122
122
|
});
|
123
123
|
let hasNonIgnoredLintableFiles = false;
|
124
124
|
for (const file of lintableFilesPerProjectRoot.get(projectRoot) ?? []) {
|
125
|
-
if (!(await eslint.isPathIgnored((0,
|
125
|
+
if (!(await eslint.isPathIgnored((0, posix_1.join)(context.workspaceRoot, file)))) {
|
126
126
|
hasNonIgnoredLintableFiles = true;
|
127
127
|
break;
|
128
128
|
}
|
@@ -152,7 +152,7 @@ exports.createNodesV2 = [
|
|
152
152
|
async (configFiles, options, context) => {
|
153
153
|
options = normalizeOptions(options);
|
154
154
|
const optionsHash = (0, file_hasher_1.hashObject)(options);
|
155
|
-
const cachePath = (0,
|
155
|
+
const cachePath = (0, posix_1.join)(cache_directory_1.workspaceDataDirectory, `eslint-${optionsHash}.hash`);
|
156
156
|
const targetsCache = readTargetsCache(cachePath);
|
157
157
|
const { eslintConfigFiles, projectRoots, projectRootsByEslintRoots } = splitConfigFiles(configFiles);
|
158
158
|
const lintableFilesPerProjectRoot = new Map();
|
@@ -175,8 +175,8 @@ function splitConfigFiles(configFiles) {
|
|
175
175
|
const eslintConfigFiles = [];
|
176
176
|
const projectRoots = new Set();
|
177
177
|
for (const configFile of configFiles) {
|
178
|
-
if (PROJECT_CONFIG_FILENAMES.includes((0,
|
179
|
-
projectRoots.add((0,
|
178
|
+
if (PROJECT_CONFIG_FILENAMES.includes((0, posix_1.basename)(configFile))) {
|
179
|
+
projectRoots.add((0, posix_1.dirname)(configFile));
|
180
180
|
}
|
181
181
|
else {
|
182
182
|
eslintConfigFiles.push(configFile);
|
@@ -193,7 +193,7 @@ function splitConfigFiles(configFiles) {
|
|
193
193
|
function groupProjectRootsByEslintRoots(eslintConfigFiles, projectRoots) {
|
194
194
|
const projectRootsByEslintRoots = new Map();
|
195
195
|
for (const eslintConfig of eslintConfigFiles) {
|
196
|
-
projectRootsByEslintRoots.set((0,
|
196
|
+
projectRootsByEslintRoots.set((0, posix_1.dirname)(eslintConfig), []);
|
197
197
|
}
|
198
198
|
for (const projectRoot of projectRoots) {
|
199
199
|
const eslintRoot = getRootForDirectory(projectRoot, projectRootsByEslintRoots);
|
@@ -211,19 +211,19 @@ async function collectLintableFilesByProjectRoot(lintableFilesPerProjectRoot, pr
|
|
211
211
|
lintableFilesPerProjectRoot.set(projectRoot, []);
|
212
212
|
}
|
213
213
|
for (const file of lintableFiles) {
|
214
|
-
const projectRoot = getRootForDirectory((0,
|
214
|
+
const projectRoot = getRootForDirectory((0, posix_1.dirname)(file), lintableFilesPerProjectRoot);
|
215
215
|
if (projectRoot) {
|
216
216
|
lintableFilesPerProjectRoot.get(projectRoot).push(file);
|
217
217
|
}
|
218
218
|
}
|
219
219
|
}
|
220
220
|
function getRootForDirectory(directory, roots) {
|
221
|
-
let currentPath = (0,
|
222
|
-
while (currentPath !== (0,
|
221
|
+
let currentPath = (0, posix_1.normalize)(directory);
|
222
|
+
while (currentPath !== (0, posix_1.dirname)(currentPath)) {
|
223
223
|
if (roots.has(currentPath)) {
|
224
224
|
return currentPath;
|
225
225
|
}
|
226
|
-
currentPath = (0,
|
226
|
+
currentPath = (0, posix_1.dirname)(currentPath);
|
227
227
|
}
|
228
228
|
return roots.has(currentPath) ? currentPath : null;
|
229
229
|
}
|
@@ -232,15 +232,15 @@ function getProjectUsingESLintConfig(configFilePath, projectRoot, eslintVersion,
|
|
232
232
|
config_file_1.baseEsLintConfigFile,
|
233
233
|
config_file_1.baseEsLintFlatConfigFile,
|
234
234
|
...config_file_1.ESLINT_CONFIG_FILENAMES,
|
235
|
-
].find((f) => (0, node_fs_1.existsSync)((0,
|
235
|
+
].find((f) => (0, node_fs_1.existsSync)((0, posix_1.join)(context.workspaceRoot, f)));
|
236
236
|
// Add a lint target for each child project without an eslint config, with the root level config as an input
|
237
237
|
let standaloneSrcPath;
|
238
238
|
if (projectRoot === '.' &&
|
239
|
-
(0, node_fs_1.existsSync)((0,
|
240
|
-
if ((0, node_fs_1.existsSync)((0,
|
239
|
+
(0, node_fs_1.existsSync)((0, posix_1.join)(context.workspaceRoot, projectRoot, 'package.json'))) {
|
240
|
+
if ((0, node_fs_1.existsSync)((0, posix_1.join)(context.workspaceRoot, projectRoot, 'src'))) {
|
241
241
|
standaloneSrcPath = 'src';
|
242
242
|
}
|
243
|
-
else if ((0, node_fs_1.existsSync)((0,
|
243
|
+
else if ((0, node_fs_1.existsSync)((0, posix_1.join)(context.workspaceRoot, projectRoot, 'lib'))) {
|
244
244
|
standaloneSrcPath = 'lib';
|
245
245
|
}
|
246
246
|
}
|
@@ -269,7 +269,7 @@ function buildEslintTargets(eslintConfigs, eslintVersion, projectRoot, workspace
|
|
269
269
|
// Certain lint rules can be impacted by changes to dependencies
|
270
270
|
'^default',
|
271
271
|
...eslintConfigs.map((config) => `{workspaceRoot}/${config}`.replace(`{workspaceRoot}/${projectRoot}`, isRootProject ? '{projectRoot}/' : '{projectRoot}')),
|
272
|
-
...((0, node_fs_1.existsSync)((0,
|
272
|
+
...((0, node_fs_1.existsSync)((0, posix_1.join)(workspaceRoot, projectRoot, '.eslintignore'))
|
273
273
|
? ['{projectRoot}/.eslintignore']
|
274
274
|
: []),
|
275
275
|
'{workspaceRoot}/tools/eslint-rules/**/*',
|
@@ -323,10 +323,10 @@ function isSubDir(parent, child) {
|
|
323
323
|
if (parent === '.') {
|
324
324
|
return true;
|
325
325
|
}
|
326
|
-
parent = (0,
|
327
|
-
child = (0,
|
328
|
-
if (!parent.endsWith(
|
329
|
-
parent +=
|
326
|
+
parent = (0, posix_1.normalize)(parent);
|
327
|
+
child = (0, posix_1.normalize)(child);
|
328
|
+
if (!parent.endsWith(posix_1.sep)) {
|
329
|
+
parent += posix_1.sep;
|
330
330
|
}
|
331
331
|
return child.startsWith(parent);
|
332
332
|
}
|