@nx/eslint 19.2.0-beta.4 → 19.2.0-beta.6
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/generators/convert-to-flat-config/generator.d.ts +2 -2
- package/src/generators/convert-to-flat-config/generator.js +6 -0
- package/src/generators/convert-to-inferred/convert-to-inferred.js +4 -4
- package/src/generators/lint-project/lint-project.d.ts +1 -0
- package/src/generators/lint-project/lint-project.js +4 -3
- package/src/plugins/plugin.js +16 -10
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nx/eslint",
|
3
|
-
"version": "19.2.0-beta.
|
3
|
+
"version": "19.2.0-beta.6",
|
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.2.0-beta.
|
39
|
-
"@nx/js": "19.2.0-beta.
|
38
|
+
"@nx/devkit": "19.2.0-beta.6",
|
39
|
+
"@nx/js": "19.2.0-beta.6",
|
40
40
|
"semver": "^7.5.3",
|
41
41
|
"tslib": "^2.3.0",
|
42
42
|
"typescript": "~5.4.2",
|
43
|
-
"@nx/linter": "19.2.0-beta.
|
43
|
+
"@nx/linter": "19.2.0-beta.6"
|
44
44
|
},
|
45
45
|
"peerDependenciesMeta": {
|
46
46
|
"@zkochan/js-yaml": {
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Tree } from '@nx/devkit';
|
1
|
+
import { GeneratorCallback, Tree } from '@nx/devkit';
|
2
2
|
import { ConvertToFlatConfigGeneratorSchema } from './schema';
|
3
|
-
export declare function convertToFlatConfigGenerator(tree: Tree, options: ConvertToFlatConfigGeneratorSchema): Promise<void>;
|
3
|
+
export declare function convertToFlatConfigGenerator(tree: Tree, options: ConvertToFlatConfigGeneratorSchema): Promise<void | GeneratorCallback>;
|
4
4
|
export default convertToFlatConfigGenerator;
|
@@ -6,6 +6,7 @@ const eslint_file_1 = require("../utils/eslint-file");
|
|
6
6
|
const path_1 = require("path");
|
7
7
|
const versions_1 = require("../../utils/versions");
|
8
8
|
const json_converter_1 = require("./converters/json-converter");
|
9
|
+
let shouldInstallDeps = false;
|
9
10
|
async function convertToFlatConfigGenerator(tree, options) {
|
10
11
|
const eslintFile = (0, eslint_file_1.findEslintFile)(tree);
|
11
12
|
if (!eslintFile) {
|
@@ -32,6 +33,9 @@ async function convertToFlatConfigGenerator(tree, options) {
|
|
32
33
|
if (!options.skipFormat) {
|
33
34
|
await (0, devkit_1.formatFiles)(tree);
|
34
35
|
}
|
36
|
+
if (shouldInstallDeps) {
|
37
|
+
return () => (0, devkit_1.installPackagesTask)(tree);
|
38
|
+
}
|
35
39
|
}
|
36
40
|
exports.convertToFlatConfigGenerator = convertToFlatConfigGenerator;
|
37
41
|
exports.default = convertToFlatConfigGenerator;
|
@@ -127,11 +131,13 @@ function processConvertedConfig(tree, root, source, target, { content, addESLint
|
|
127
131
|
tree.write((0, path_1.join)(root, target), content);
|
128
132
|
// add missing packages
|
129
133
|
if (addESLintRC) {
|
134
|
+
shouldInstallDeps = true;
|
130
135
|
(0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
|
131
136
|
'@eslint/eslintrc': versions_1.eslintrcVersion,
|
132
137
|
});
|
133
138
|
}
|
134
139
|
if (addESLintJS) {
|
140
|
+
shouldInstallDeps = true;
|
135
141
|
(0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
|
136
142
|
'@eslint/js': versions_1.eslintVersion,
|
137
143
|
});
|
@@ -8,8 +8,8 @@ const target_options_map_1 = require("./lib/target-options-map");
|
|
8
8
|
const utils_1 = require("nx/src/tasks-runner/utils");
|
9
9
|
async function convertToInferred(tree, options) {
|
10
10
|
const projectGraph = await (0, devkit_1.createProjectGraphAsync)();
|
11
|
-
const migratedProjectsModern = await (0, executor_to_plugin_migrator_1.
|
12
|
-
const migratedProjectsLegacy = await (0, executor_to_plugin_migrator_1.
|
11
|
+
const migratedProjectsModern = await (0, executor_to_plugin_migrator_1.migrateExecutorToPluginV1)(tree, projectGraph, '@nx/eslint:lint', '@nx/eslint/plugin', (targetName) => ({ targetName }), postTargetTransformer, plugin_1.createNodes, options.project);
|
12
|
+
const migratedProjectsLegacy = await (0, executor_to_plugin_migrator_1.migrateExecutorToPluginV1)(tree, projectGraph, '@nrwl/linter:eslint', '@nx/eslint/plugin', (targetName) => ({ targetName }), postTargetTransformer, plugin_1.createNodes, options.project);
|
13
13
|
const migratedProjects = migratedProjectsModern.size + migratedProjectsLegacy.size;
|
14
14
|
if (migratedProjects === 0) {
|
15
15
|
throw new Error('Could not find any targets to migrate.');
|
@@ -21,14 +21,14 @@ async function convertToInferred(tree, options) {
|
|
21
21
|
exports.convertToInferred = convertToInferred;
|
22
22
|
function postTargetTransformer(target, tree, projectDetails) {
|
23
23
|
if (target.inputs) {
|
24
|
-
|
24
|
+
const inputs = target.inputs.filter((input) => typeof input === 'string' &&
|
25
25
|
![
|
26
26
|
'default',
|
27
27
|
'{workspaceRoot}/.eslintrc.json',
|
28
28
|
'{workspaceRoot}/.eslintignore',
|
29
29
|
'{workspaceRoot}/eslint.config.js',
|
30
30
|
].includes(input));
|
31
|
-
if (
|
31
|
+
if (inputs.length === 0) {
|
32
32
|
delete target.inputs;
|
33
33
|
}
|
34
34
|
}
|
@@ -16,6 +16,7 @@ interface LintProjectOptions {
|
|
16
16
|
* @internal
|
17
17
|
*/
|
18
18
|
addExplicitTargets?: boolean;
|
19
|
+
addPackageJsonDependencyChecks?: boolean;
|
19
20
|
}
|
20
21
|
export declare function lintProjectGenerator(tree: Tree, options: LintProjectOptions): Promise<GeneratorCallback>;
|
21
22
|
export declare function lintProjectGeneratorInternal(tree: Tree, options: LintProjectOptions): Promise<GeneratorCallback>;
|
@@ -89,7 +89,7 @@ async function lintProjectGeneratorInternal(tree, options) {
|
|
89
89
|
// additionally, the companion e2e app would have `rootProject: true`
|
90
90
|
// so we need to check for the root path as well
|
91
91
|
if (!options.rootProject || projectConfig.root !== '.') {
|
92
|
-
createEsLintConfiguration(tree, projectConfig, options.setParserOptionsProject, options.rootProject);
|
92
|
+
createEsLintConfiguration(tree, options, projectConfig, options.setParserOptionsProject, options.rootProject);
|
93
93
|
}
|
94
94
|
// Buildable libs need source analysis enabled for linting `package.json`.
|
95
95
|
if (isBuildableLibraryProject(projectConfig) &&
|
@@ -108,7 +108,7 @@ async function lintProjectGeneratorInternal(tree, options) {
|
|
108
108
|
return (0, devkit_1.runTasksInSerial)(...tasks);
|
109
109
|
}
|
110
110
|
exports.lintProjectGeneratorInternal = lintProjectGeneratorInternal;
|
111
|
-
function createEsLintConfiguration(tree, projectConfig, setParserOptionsProject, rootProject) {
|
111
|
+
function createEsLintConfiguration(tree, options, projectConfig, setParserOptionsProject, rootProject) {
|
112
112
|
// we are only extending root for non-standalone projects or their complementary e2e apps
|
113
113
|
const extendedRootConfig = rootProject ? undefined : (0, eslint_file_1.findEslintFile)(tree);
|
114
114
|
const pathToRootConfig = extendedRootConfig
|
@@ -151,7 +151,8 @@ function createEsLintConfiguration(tree, projectConfig, setParserOptionsProject,
|
|
151
151
|
rules: {},
|
152
152
|
},
|
153
153
|
];
|
154
|
-
if (
|
154
|
+
if (options.addPackageJsonDependencyChecks ||
|
155
|
+
isBuildableLibraryProject(projectConfig)) {
|
155
156
|
overrides.push({
|
156
157
|
files: ['*.json'],
|
157
158
|
parser: 'jsonc-eslint-parser',
|
package/src/plugins/plugin.js
CHANGED
@@ -32,7 +32,7 @@ exports.createNodes = [
|
|
32
32
|
nestedEslintRootPatterns.push(`${eslintRootDir}/**/*`);
|
33
33
|
}
|
34
34
|
}
|
35
|
-
const projectFiles = (0, workspace_context_1.globWithWorkspaceContext)(context.workspaceRoot, [
|
35
|
+
const projectFiles = await (0, workspace_context_1.globWithWorkspaceContext)(context.workspaceRoot, [
|
36
36
|
'project.json',
|
37
37
|
'package.json',
|
38
38
|
'**/project.json',
|
@@ -48,7 +48,7 @@ exports.createNodes = [
|
|
48
48
|
// anything after is either a nested project or a sibling project, can be excluded
|
49
49
|
const nestedProjectRootPatterns = excludePatterns.slice(index + 1);
|
50
50
|
// Ignore project roots where the project does not contain any lintable files
|
51
|
-
const lintableFiles = (0, workspace_context_1.globWithWorkspaceContext)(context.workspaceRoot, [(0, node_path_1.join)(childProjectRoot, `**/*.{${options.extensions.join(',')}}`)],
|
51
|
+
const lintableFiles = await (0, workspace_context_1.globWithWorkspaceContext)(context.workspaceRoot, [(0, node_path_1.join)(childProjectRoot, `**/*.{${options.extensions.join(',')}}`)],
|
52
52
|
// exclude nested eslint roots and nested project roots
|
53
53
|
[...nestedEslintRootPatterns, ...nestedProjectRootPatterns]);
|
54
54
|
const eslint = new ESLint({
|
@@ -76,11 +76,17 @@ function getProjectsUsingESLintConfig(configFilePath, childProjectRoots, eslintV
|
|
76
76
|
].find((f) => (0, node_fs_1.existsSync)((0, node_path_1.join)(context.workspaceRoot, f)));
|
77
77
|
// Add a lint target for each child project without an eslint config, with the root level config as an input
|
78
78
|
for (const projectRoot of childProjectRoots) {
|
79
|
-
|
80
|
-
|
81
|
-
(0, node_fs_1.existsSync)((0, node_path_1.join)(context.workspaceRoot, projectRoot, '
|
82
|
-
(0, node_fs_1.existsSync)((0, node_path_1.join)(context.workspaceRoot, projectRoot, '
|
83
|
-
|
79
|
+
let standaloneSrcPath;
|
80
|
+
if (projectRoot === '.' &&
|
81
|
+
(0, node_fs_1.existsSync)((0, node_path_1.join)(context.workspaceRoot, projectRoot, 'package.json'))) {
|
82
|
+
if ((0, node_fs_1.existsSync)((0, node_path_1.join)(context.workspaceRoot, projectRoot, 'src'))) {
|
83
|
+
standaloneSrcPath = 'src';
|
84
|
+
}
|
85
|
+
else if ((0, node_fs_1.existsSync)((0, node_path_1.join)(context.workspaceRoot, projectRoot, 'lib'))) {
|
86
|
+
standaloneSrcPath = 'lib';
|
87
|
+
}
|
88
|
+
}
|
89
|
+
if (projectRoot === '.' && !standaloneSrcPath) {
|
84
90
|
continue;
|
85
91
|
}
|
86
92
|
const eslintConfigs = [configFilePath];
|
@@ -88,16 +94,16 @@ function getProjectsUsingESLintConfig(configFilePath, childProjectRoots, eslintV
|
|
88
94
|
eslintConfigs.unshift(rootEslintConfig);
|
89
95
|
}
|
90
96
|
projects[projectRoot] = {
|
91
|
-
targets: buildEslintTargets(eslintConfigs, eslintVersion, projectRoot, context.workspaceRoot, options,
|
97
|
+
targets: buildEslintTargets(eslintConfigs, eslintVersion, projectRoot, context.workspaceRoot, options, standaloneSrcPath),
|
92
98
|
};
|
93
99
|
}
|
94
100
|
return projects;
|
95
101
|
}
|
96
|
-
function buildEslintTargets(eslintConfigs, eslintVersion, projectRoot, workspaceRoot, options,
|
102
|
+
function buildEslintTargets(eslintConfigs, eslintVersion, projectRoot, workspaceRoot, options, standaloneSrcPath) {
|
97
103
|
const isRootProject = projectRoot === '.';
|
98
104
|
const targets = {};
|
99
105
|
const targetConfig = {
|
100
|
-
command: `eslint ${isRootProject &&
|
106
|
+
command: `eslint ${isRootProject && standaloneSrcPath ? `./${standaloneSrcPath}` : '.'}`,
|
101
107
|
cache: true,
|
102
108
|
options: {
|
103
109
|
cwd: projectRoot,
|