@nx/eslint 18.1.0 → 18.1.1
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/package.json +4 -4
- package/src/plugins/plugin.d.ts +1 -0
- package/src/plugins/plugin.js +75 -50
- package/src/utils/config-file.d.ts +0 -1
- package/src/utils/config-file.js +1 -18
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nx/eslint",
|
3
|
-
"version": "18.1.
|
3
|
+
"version": "18.1.1",
|
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": {
|
@@ -33,12 +33,12 @@
|
|
33
33
|
"js-yaml": "4.1.0"
|
34
34
|
},
|
35
35
|
"dependencies": {
|
36
|
-
"@nx/devkit": "18.1.
|
37
|
-
"@nx/js": "18.1.
|
36
|
+
"@nx/devkit": "18.1.1",
|
37
|
+
"@nx/js": "18.1.1",
|
38
38
|
"eslint": "^8.0.0",
|
39
39
|
"tslib": "^2.3.0",
|
40
40
|
"typescript": "~5.3.2",
|
41
|
-
"@nx/linter": "18.1.
|
41
|
+
"@nx/linter": "18.1.1"
|
42
42
|
},
|
43
43
|
"peerDependenciesMeta": {
|
44
44
|
"js-yaml": {
|
package/src/plugins/plugin.d.ts
CHANGED
package/src/plugins/plugin.js
CHANGED
@@ -1,78 +1,96 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.createNodes = void 0;
|
4
|
-
const
|
5
|
-
const
|
4
|
+
const node_fs_1 = require("node:fs");
|
5
|
+
const node_path_1 = require("node:path");
|
6
6
|
const globs_1 = require("nx/src/utils/globs");
|
7
|
+
const workspace_context_1 = require("nx/src/utils/workspace-context");
|
7
8
|
const config_file_1 = require("../utils/config-file");
|
9
|
+
const DEFAULT_EXTENSIONS = ['ts', 'tsx', 'js', 'jsx', 'html', 'vue'];
|
8
10
|
exports.createNodes = [
|
9
|
-
(0, globs_1.combineGlobPatterns)([
|
11
|
+
(0, globs_1.combineGlobPatterns)([
|
12
|
+
...config_file_1.ESLINT_CONFIG_FILENAMES.map((f) => `**/${f}`),
|
13
|
+
config_file_1.baseEsLintConfigFile,
|
14
|
+
config_file_1.baseEsLintFlatConfigFile,
|
15
|
+
]),
|
10
16
|
(configFilePath, options, context) => {
|
11
|
-
const projectRoot = (0, path_1.dirname)(configFilePath);
|
12
17
|
options = normalizeOptions(options);
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
18
|
+
// Ensure that configFiles are set, e2e-run fails due to them being undefined in CI (does not occur locally)
|
19
|
+
// TODO(JamesHenry): Further troubleshoot this in CI
|
20
|
+
context.configFiles = context.configFiles ?? [];
|
21
|
+
// Create a Set of all the directories containing eslint configs
|
22
|
+
const eslintRoots = new Set(context.configFiles.map(node_path_1.dirname));
|
23
|
+
const configDir = (0, node_path_1.dirname)(configFilePath);
|
24
|
+
const childProjectRoots = (0, workspace_context_1.globWithWorkspaceContext)(context.workspaceRoot, [
|
25
|
+
'project.json',
|
26
|
+
'package.json',
|
27
|
+
'**/project.json',
|
28
|
+
'**/package.json',
|
29
|
+
].map((f) => (0, node_path_1.join)(configDir, f)))
|
30
|
+
.map((f) => (0, node_path_1.dirname)(f))
|
31
|
+
.filter((childProjectRoot) => {
|
32
|
+
// Filter out projects under other eslint configs
|
33
|
+
let root = childProjectRoot;
|
34
|
+
// Traverse up from the childProjectRoot to either the workspaceRoot or the dir of this config file
|
35
|
+
while (root !== (0, node_path_1.dirname)(root) && root !== (0, node_path_1.dirname)(configFilePath)) {
|
36
|
+
if (eslintRoots.has(root)) {
|
37
|
+
return false;
|
38
|
+
}
|
39
|
+
root = (0, node_path_1.dirname)(root);
|
40
|
+
}
|
41
|
+
return true;
|
42
|
+
})
|
43
|
+
.filter((dir) => {
|
44
|
+
// Ignore project roots where the project does not contain any lintable files
|
45
|
+
const lintableFiles = (0, workspace_context_1.globWithWorkspaceContext)(context.workspaceRoot, [
|
46
|
+
(0, node_path_1.join)(dir, `**/*.{${options.extensions.join(',')}}`),
|
47
|
+
]);
|
48
|
+
return lintableFiles.length > 0;
|
49
|
+
});
|
50
|
+
const uniqueChildProjectRoots = Array.from(new Set(childProjectRoots));
|
17
51
|
return {
|
18
|
-
projects:
|
19
|
-
[projectRoot]: {
|
20
|
-
targets: buildEslintTargets(eslintConfigs, projectRoot, options),
|
21
|
-
},
|
22
|
-
},
|
52
|
+
projects: getProjectsUsingESLintConfig(configFilePath, uniqueChildProjectRoots, options, context),
|
23
53
|
};
|
24
54
|
},
|
25
55
|
];
|
26
|
-
function
|
27
|
-
const
|
28
|
-
const
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
56
|
+
function getProjectsUsingESLintConfig(configFilePath, childProjectRoots, options, context) {
|
57
|
+
const projects = {};
|
58
|
+
const rootEslintConfig = context.configFiles.find((f) => f === config_file_1.baseEsLintConfigFile ||
|
59
|
+
f === config_file_1.baseEsLintFlatConfigFile ||
|
60
|
+
config_file_1.ESLINT_CONFIG_FILENAMES.includes(f));
|
61
|
+
// Add a lint target for each child project without an eslint config, with the root level config as an input
|
62
|
+
for (const projectRoot of childProjectRoots) {
|
63
|
+
// If there's no src folder, it's not a standalone project, do not add the target at all
|
64
|
+
const isStandaloneWorkspace = projectRoot === '.' &&
|
65
|
+
(0, node_fs_1.existsSync)((0, node_path_1.join)(context.workspaceRoot, projectRoot, 'src')) &&
|
66
|
+
(0, node_fs_1.existsSync)((0, node_path_1.join)(context.workspaceRoot, projectRoot, 'package.json'));
|
67
|
+
if (projectRoot === '.' && !isStandaloneWorkspace) {
|
68
|
+
continue;
|
37
69
|
}
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
return [];
|
42
|
-
}
|
43
|
-
detectedConfigs.add(config);
|
44
|
-
return Array.from(detectedConfigs);
|
45
|
-
}
|
46
|
-
while (projectRoot !== '.') {
|
47
|
-
// if it has an eslint config it's lintable
|
48
|
-
const config = siblingFiles.find((f) => config_file_1.ESLINT_CONFIG_FILENAMES.includes(f));
|
49
|
-
if (config) {
|
50
|
-
detectedConfigs.add(`${projectRoot}/${config}`);
|
51
|
-
return Array.from(detectedConfigs);
|
70
|
+
const eslintConfigs = [configFilePath];
|
71
|
+
if (rootEslintConfig && !eslintConfigs.includes(rootEslintConfig)) {
|
72
|
+
eslintConfigs.unshift(rootEslintConfig);
|
52
73
|
}
|
53
|
-
projectRoot =
|
54
|
-
|
55
|
-
|
56
|
-
// check whether the root has an eslint config
|
57
|
-
const config = (0, fs_1.readdirSync)(workspaceRoot).find((f) => config_file_1.ESLINT_CONFIG_FILENAMES.includes(f));
|
58
|
-
if (config) {
|
59
|
-
detectedConfigs.add(config);
|
60
|
-
return Array.from(detectedConfigs);
|
74
|
+
projects[projectRoot] = {
|
75
|
+
targets: buildEslintTargets(eslintConfigs, projectRoot, options, isStandaloneWorkspace),
|
76
|
+
};
|
61
77
|
}
|
62
|
-
return
|
78
|
+
return projects;
|
63
79
|
}
|
64
|
-
function buildEslintTargets(eslintConfigs, projectRoot, options) {
|
80
|
+
function buildEslintTargets(eslintConfigs, projectRoot, options, isStandaloneWorkspace = false) {
|
65
81
|
const isRootProject = projectRoot === '.';
|
66
82
|
const targets = {};
|
67
83
|
const targetConfig = {
|
68
|
-
command: `eslint ${isRootProject ? './src' : '.'}`,
|
84
|
+
command: `eslint ${isRootProject && isStandaloneWorkspace ? './src' : '.'}`,
|
69
85
|
cache: true,
|
70
86
|
options: {
|
71
87
|
cwd: projectRoot,
|
72
88
|
},
|
73
89
|
inputs: [
|
74
90
|
'default',
|
75
|
-
|
91
|
+
// Certain lint rules can be impacted by changes to dependencies
|
92
|
+
'^default',
|
93
|
+
...eslintConfigs.map((config) => `{workspaceRoot}/${config}`.replace(`{workspaceRoot}/${projectRoot}`, isRootProject ? '{projectRoot}/' : '{projectRoot}')),
|
76
94
|
'{workspaceRoot}/tools/eslint-rules/**/*',
|
77
95
|
{ externalDependencies: ['eslint'] },
|
78
96
|
],
|
@@ -88,5 +106,12 @@ function buildEslintTargets(eslintConfigs, projectRoot, options) {
|
|
88
106
|
function normalizeOptions(options) {
|
89
107
|
options ??= {};
|
90
108
|
options.targetName ??= 'lint';
|
109
|
+
// Normalize user input for extensions (strip leading . characters)
|
110
|
+
if (Array.isArray(options.extensions)) {
|
111
|
+
options.extensions = options.extensions.map((f) => f.replace(/^\.+/, ''));
|
112
|
+
}
|
113
|
+
else {
|
114
|
+
options.extensions = DEFAULT_EXTENSIONS;
|
115
|
+
}
|
91
116
|
return options;
|
92
117
|
}
|
@@ -1,5 +1,4 @@
|
|
1
1
|
export declare const ESLINT_CONFIG_FILENAMES: string[];
|
2
2
|
export declare const baseEsLintConfigFile = ".eslintrc.base.json";
|
3
3
|
export declare const baseEsLintFlatConfigFile = "eslint.base.config.js";
|
4
|
-
export declare function findBaseEslintFile(workspaceRoot?: string): string | null;
|
5
4
|
export declare function isFlatConfig(configFilePath: string): boolean;
|
package/src/utils/config-file.js
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.isFlatConfig = exports.
|
4
|
-
const devkit_1 = require("@nx/devkit");
|
5
|
-
const fs_1 = require("fs");
|
3
|
+
exports.isFlatConfig = exports.baseEsLintFlatConfigFile = exports.baseEsLintConfigFile = exports.ESLINT_CONFIG_FILENAMES = void 0;
|
6
4
|
exports.ESLINT_CONFIG_FILENAMES = [
|
7
5
|
'.eslintrc',
|
8
6
|
'.eslintrc.js',
|
@@ -14,21 +12,6 @@ exports.ESLINT_CONFIG_FILENAMES = [
|
|
14
12
|
];
|
15
13
|
exports.baseEsLintConfigFile = '.eslintrc.base.json';
|
16
14
|
exports.baseEsLintFlatConfigFile = 'eslint.base.config.js';
|
17
|
-
function findBaseEslintFile(workspaceRoot = '') {
|
18
|
-
if ((0, fs_1.existsSync)((0, devkit_1.joinPathFragments)(workspaceRoot, exports.baseEsLintConfigFile))) {
|
19
|
-
return exports.baseEsLintConfigFile;
|
20
|
-
}
|
21
|
-
if ((0, fs_1.existsSync)((0, devkit_1.joinPathFragments)(workspaceRoot, exports.baseEsLintFlatConfigFile))) {
|
22
|
-
return exports.baseEsLintFlatConfigFile;
|
23
|
-
}
|
24
|
-
for (const file of exports.ESLINT_CONFIG_FILENAMES) {
|
25
|
-
if ((0, fs_1.existsSync)((0, devkit_1.joinPathFragments)(workspaceRoot, file))) {
|
26
|
-
return file;
|
27
|
-
}
|
28
|
-
}
|
29
|
-
return null;
|
30
|
-
}
|
31
|
-
exports.findBaseEslintFile = findBaseEslintFile;
|
32
15
|
function isFlatConfig(configFilePath) {
|
33
16
|
return configFilePath.endsWith('.config.js');
|
34
17
|
}
|