@nx/eslint 19.0.5 → 19.0.7
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
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nx/eslint",
|
3
|
-
"version": "19.0.
|
3
|
+
"version": "19.0.7",
|
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": {
|
@@ -13,9 +13,10 @@
|
|
13
13
|
"Web",
|
14
14
|
"Lint",
|
15
15
|
"ESLint",
|
16
|
-
"CLI"
|
16
|
+
"CLI",
|
17
|
+
"Testing"
|
17
18
|
],
|
18
|
-
"main": "./index
|
19
|
+
"main": "./index",
|
19
20
|
"typings": "./index.d.ts",
|
20
21
|
"author": "Victor Savkin",
|
21
22
|
"license": "MIT",
|
@@ -33,12 +34,13 @@
|
|
33
34
|
"js-yaml": "npm:@zkochan/js-yaml@0.0.7"
|
34
35
|
},
|
35
36
|
"dependencies": {
|
36
|
-
"@nx/devkit": "19.0.
|
37
|
-
"@nx/js": "19.0.
|
37
|
+
"@nx/devkit": "19.0.7",
|
38
|
+
"@nx/js": "19.0.7",
|
38
39
|
"eslint": "^8.0.0",
|
40
|
+
"semver": "^7.5.3",
|
39
41
|
"tslib": "^2.3.0",
|
40
42
|
"typescript": "~5.4.2",
|
41
|
-
"@nx/linter": "19.0.
|
43
|
+
"@nx/linter": "19.0.7"
|
42
44
|
},
|
43
45
|
"peerDependenciesMeta": {
|
44
46
|
"js-yaml": {
|
@@ -1,26 +1,14 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.resolveAndInstantiateESLint = void 0;
|
4
|
-
|
5
|
-
try {
|
6
|
-
if (!useFlatConfig) {
|
7
|
-
return (await Promise.resolve().then(() => require('eslint'))).ESLint;
|
8
|
-
}
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
10
|
-
const { FlatESLint } = require('eslint/use-at-your-own-risk');
|
11
|
-
return FlatESLint;
|
12
|
-
}
|
13
|
-
catch {
|
14
|
-
throw new Error('Unable to find ESLint. Ensure ESLint is installed.');
|
15
|
-
}
|
16
|
-
}
|
4
|
+
const resolve_eslint_class_1 = require("../../../utils/resolve-eslint-class");
|
17
5
|
async function resolveAndInstantiateESLint(eslintConfigPath, options, useFlatConfig = false) {
|
18
6
|
if (useFlatConfig &&
|
19
7
|
eslintConfigPath &&
|
20
8
|
!eslintConfigPath?.endsWith('eslint.config.js')) {
|
21
9
|
throw new Error('When using the new Flat Config with ESLint, all configs must be named eslint.config.js and .eslintrc files may not be used. See https://eslint.org/docs/latest/use/configure/configuration-files-new');
|
22
10
|
}
|
23
|
-
const ESLint = await resolveESLintClass(useFlatConfig);
|
11
|
+
const ESLint = await (0, resolve_eslint_class_1.resolveESLintClass)(useFlatConfig);
|
24
12
|
const eslintOptions = {
|
25
13
|
overrideConfigFile: eslintConfigPath,
|
26
14
|
fix: !!options.fix,
|
package/src/plugins/plugin.js
CHANGED
@@ -6,6 +6,8 @@ const node_path_1 = require("node:path");
|
|
6
6
|
const globs_1 = require("nx/src/utils/globs");
|
7
7
|
const workspace_context_1 = require("nx/src/utils/workspace-context");
|
8
8
|
const config_file_1 = require("../utils/config-file");
|
9
|
+
const resolve_eslint_class_1 = require("../utils/resolve-eslint-class");
|
10
|
+
const semver_1 = require("semver");
|
9
11
|
const DEFAULT_EXTENSIONS = ['ts', 'tsx', 'js', 'jsx', 'html', 'vue'];
|
10
12
|
exports.createNodes = [
|
11
13
|
(0, globs_1.combineGlobPatterns)([
|
@@ -39,7 +41,8 @@ exports.createNodes = [
|
|
39
41
|
// dedupe and sort project roots by depth for more efficient traversal
|
40
42
|
const dedupedProjectRoots = Array.from(new Set(projectFiles.map((f) => (0, node_path_1.dirname)(f)))).sort((a, b) => (a !== b && isSubDir(a, b) ? -1 : 1));
|
41
43
|
const excludePatterns = dedupedProjectRoots.map((root) => `${root}/**/*`);
|
42
|
-
const ESLint = resolveESLintClass((0, config_file_1.isFlatConfig)(configFilePath));
|
44
|
+
const ESLint = await (0, resolve_eslint_class_1.resolveESLintClass)((0, config_file_1.isFlatConfig)(configFilePath));
|
45
|
+
const eslintVersion = ESLint.version;
|
43
46
|
const childProjectRoots = new Set();
|
44
47
|
await Promise.all(dedupedProjectRoots.map(async (childProjectRoot, index) => {
|
45
48
|
// anything after is either a nested project or a sibling project, can be excluded
|
@@ -60,11 +63,11 @@ exports.createNodes = [
|
|
60
63
|
}));
|
61
64
|
const uniqueChildProjectRoots = Array.from(childProjectRoots);
|
62
65
|
return {
|
63
|
-
projects: getProjectsUsingESLintConfig(configFilePath, uniqueChildProjectRoots, options, context),
|
66
|
+
projects: getProjectsUsingESLintConfig(configFilePath, uniqueChildProjectRoots, eslintVersion, options, context),
|
64
67
|
};
|
65
68
|
},
|
66
69
|
];
|
67
|
-
function getProjectsUsingESLintConfig(configFilePath, childProjectRoots, options, context) {
|
70
|
+
function getProjectsUsingESLintConfig(configFilePath, childProjectRoots, eslintVersion, options, context) {
|
68
71
|
const projects = {};
|
69
72
|
const rootEslintConfig = [
|
70
73
|
config_file_1.baseEsLintConfigFile,
|
@@ -85,12 +88,12 @@ function getProjectsUsingESLintConfig(configFilePath, childProjectRoots, options
|
|
85
88
|
eslintConfigs.unshift(rootEslintConfig);
|
86
89
|
}
|
87
90
|
projects[projectRoot] = {
|
88
|
-
targets: buildEslintTargets(eslintConfigs, projectRoot, context.workspaceRoot, options, isStandaloneWorkspace),
|
91
|
+
targets: buildEslintTargets(eslintConfigs, eslintVersion, projectRoot, context.workspaceRoot, options, isStandaloneWorkspace),
|
89
92
|
};
|
90
93
|
}
|
91
94
|
return projects;
|
92
95
|
}
|
93
|
-
function buildEslintTargets(eslintConfigs, projectRoot, workspaceRoot, options, isStandaloneWorkspace = false) {
|
96
|
+
function buildEslintTargets(eslintConfigs, eslintVersion, projectRoot, workspaceRoot, options, isStandaloneWorkspace = false) {
|
94
97
|
const isRootProject = projectRoot === '.';
|
95
98
|
const targets = {};
|
96
99
|
const targetConfig = {
|
@@ -112,9 +115,13 @@ function buildEslintTargets(eslintConfigs, projectRoot, workspaceRoot, options,
|
|
112
115
|
],
|
113
116
|
outputs: ['{options.outputFile}'],
|
114
117
|
};
|
115
|
-
|
118
|
+
// Always set the environment variable to ensure that the ESLint CLI can run on eslint v8 and v9
|
119
|
+
const useFlatConfig = eslintConfigs.some((config) => (0, config_file_1.isFlatConfig)(config));
|
120
|
+
// Flat config is default for 9.0.0+
|
121
|
+
const defaultSetting = (0, semver_1.gte)(eslintVersion, '9.0.0');
|
122
|
+
if (useFlatConfig !== defaultSetting) {
|
116
123
|
targetConfig.options.env = {
|
117
|
-
ESLINT_USE_FLAT_CONFIG: 'true',
|
124
|
+
ESLINT_USE_FLAT_CONFIG: useFlatConfig ? 'true' : 'false',
|
118
125
|
};
|
119
126
|
}
|
120
127
|
targets[options.targetName] = targetConfig;
|
@@ -132,17 +139,6 @@ function normalizeOptions(options) {
|
|
132
139
|
}
|
133
140
|
return options;
|
134
141
|
}
|
135
|
-
function resolveESLintClass(useFlatConfig = false) {
|
136
|
-
try {
|
137
|
-
if (!useFlatConfig) {
|
138
|
-
return require('eslint').ESLint;
|
139
|
-
}
|
140
|
-
return require('eslint/use-at-your-own-risk').FlatESLint;
|
141
|
-
}
|
142
|
-
catch {
|
143
|
-
throw new Error('Unable to find ESLint. Ensure ESLint is installed.');
|
144
|
-
}
|
145
|
-
}
|
146
142
|
/**
|
147
143
|
* Determines if `child` is a subdirectory of `parent`. This is a simplified
|
148
144
|
* version that takes into account that paths are always relative to the
|
@@ -0,0 +1,23 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.resolveESLintClass = void 0;
|
4
|
+
async function resolveESLintClass(useFlatConfig = false) {
|
5
|
+
try {
|
6
|
+
// In eslint 8.57.0 (the final v8 version), a dedicated API was added for resolving the correct ESLint class.
|
7
|
+
const eslint = await Promise.resolve().then(() => require('eslint'));
|
8
|
+
if (typeof eslint.loadESLint === 'function') {
|
9
|
+
return await eslint.loadESLint({ useFlatConfig });
|
10
|
+
}
|
11
|
+
// If that API is not available (an older version of v8), we need to use the old way of resolving the ESLint class.
|
12
|
+
if (!useFlatConfig) {
|
13
|
+
return eslint.ESLint;
|
14
|
+
}
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
16
|
+
const { FlatESLint } = require('eslint/use-at-your-own-risk');
|
17
|
+
return FlatESLint;
|
18
|
+
}
|
19
|
+
catch {
|
20
|
+
throw new Error('Unable to find ESLint. Ensure ESLint is installed.');
|
21
|
+
}
|
22
|
+
}
|
23
|
+
exports.resolveESLintClass = resolveESLintClass;
|