@nx/eslint 19.1.0-canary.20240510-1a85787 → 19.1.0-canary.20240514-cc9b7f3
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.1.0-canary.
|
3
|
+
"version": "19.1.0-canary.20240514-cc9b7f3",
|
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": "19.1.0-canary.
|
37
|
-
"@nx/js": "19.1.0-canary.
|
36
|
+
"@nx/devkit": "19.1.0-canary.20240514-cc9b7f3",
|
37
|
+
"@nx/js": "19.1.0-canary.20240514-cc9b7f3",
|
38
38
|
"eslint": "^8.0.0",
|
39
39
|
"tslib": "^2.3.0",
|
40
40
|
"typescript": "~5.4.2",
|
41
|
-
"@nx/linter": "19.1.0-canary.
|
41
|
+
"@nx/linter": "19.1.0-canary.20240514-cc9b7f3"
|
42
42
|
},
|
43
43
|
"peerDependenciesMeta": {
|
44
44
|
"js-yaml": {
|
@@ -38,7 +38,6 @@ async function initEsLint(tree, options) {
|
|
38
38
|
options.addPlugin ??= addPluginDefault;
|
39
39
|
const hasPlugin = (0, plugin_2.hasEslintPlugin)(tree);
|
40
40
|
const rootEslintFile = (0, eslint_file_1.findEslintFile)(tree);
|
41
|
-
const graph = await (0, devkit_1.createProjectGraphAsync)();
|
42
41
|
const lintTargetNames = [
|
43
42
|
'lint',
|
44
43
|
'eslint:lint',
|
@@ -48,7 +47,7 @@ async function initEsLint(tree, options) {
|
|
48
47
|
'_eslint-lint',
|
49
48
|
];
|
50
49
|
if (rootEslintFile && options.addPlugin && !hasPlugin) {
|
51
|
-
await (0, add_plugin_1.addPlugin)(tree,
|
50
|
+
await (0, add_plugin_1.addPlugin)(tree, '@nx/eslint/plugin', plugin_1.createNodes, {
|
52
51
|
targetName: lintTargetNames,
|
53
52
|
}, options.updatePackageScripts);
|
54
53
|
return () => { };
|
@@ -58,7 +57,7 @@ async function initEsLint(tree, options) {
|
|
58
57
|
}
|
59
58
|
updateProductionFileset(tree);
|
60
59
|
if (options.addPlugin) {
|
61
|
-
await (0, add_plugin_1.addPlugin)(tree,
|
60
|
+
await (0, add_plugin_1.addPlugin)(tree, '@nx/eslint/plugin', plugin_1.createNodes, {
|
62
61
|
targetName: lintTargetNames,
|
63
62
|
}, options.updatePackageScripts);
|
64
63
|
}
|
@@ -73,7 +73,8 @@ async function lintProjectGeneratorInternal(tree, options) {
|
|
73
73
|
if (!options.rootProject) {
|
74
74
|
const projects = {};
|
75
75
|
(0, project_configuration_1.getProjects)(tree).forEach((v, k) => (projects[k] = v));
|
76
|
-
|
76
|
+
const graph = await (0, devkit_1.createProjectGraphAsync)();
|
77
|
+
if (isMigrationToMonorepoNeeded(tree, graph)) {
|
77
78
|
// we only migrate project configurations that have been created
|
78
79
|
const filteredProjects = [];
|
79
80
|
Object.entries(projects).forEach(([name, project]) => {
|
@@ -198,30 +199,24 @@ function isBuildableLibraryProject(projectConfig) {
|
|
198
199
|
* Detect based on the state of lint target configuration of the root project
|
199
200
|
* if we should migrate eslint configs to monorepo style
|
200
201
|
*/
|
201
|
-
function isMigrationToMonorepoNeeded(
|
202
|
+
function isMigrationToMonorepoNeeded(tree, graph) {
|
202
203
|
// the base config is already created, migration has been done
|
203
204
|
if (tree.exists(config_file_1.baseEsLintConfigFile) ||
|
204
205
|
tree.exists(config_file_1.baseEsLintFlatConfigFile)) {
|
205
206
|
return false;
|
206
207
|
}
|
207
|
-
const
|
208
|
-
if (configs.length === 1) {
|
209
|
-
return false;
|
210
|
-
}
|
208
|
+
const nodes = Object.values(graph.nodes);
|
211
209
|
// get root project
|
212
|
-
const rootProject =
|
213
|
-
if (!rootProject || !rootProject.targets) {
|
210
|
+
const rootProject = nodes.find((p) => p.data.root === '.');
|
211
|
+
if (!rootProject || !rootProject.data.targets) {
|
214
212
|
return false;
|
215
213
|
}
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
}
|
214
|
+
for (const targetConfig of Object.values(rootProject.data.targets ?? {})) {
|
215
|
+
if (['@nx/eslint:lint', '@nrwl/linter:eslint', '@nx/linter:eslint'].includes(targetConfig.executor) ||
|
216
|
+
(targetConfig.executor === 'nx:run-commands' &&
|
217
|
+
targetConfig.options?.command.startsWith('eslint '))) {
|
218
|
+
return true;
|
222
219
|
}
|
223
220
|
}
|
224
|
-
|
225
|
-
const lintTarget = (0, init_migration_1.findLintTarget)(rootProject);
|
226
|
-
return !!lintTarget;
|
221
|
+
return false;
|
227
222
|
}
|
@@ -4,6 +4,11 @@ exports.generateAst = exports.mapFilePaths = exports.generateFlatOverride = expo
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
5
5
|
const ts = require("typescript");
|
6
6
|
const path_utils_1 = require("./path-utils");
|
7
|
+
/**
|
8
|
+
* Supports direct identifiers, and those nested within an object (of arbitrary depth)
|
9
|
+
* E.g. `...foo` and `...foo.bar.baz.qux` etc
|
10
|
+
*/
|
11
|
+
const SPREAD_ELEMENTS_REGEXP = /\s*\.\.\.[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*,?\n?/g;
|
7
12
|
/**
|
8
13
|
* Remove all overrides from the config file
|
9
14
|
*/
|
@@ -58,11 +63,13 @@ function hasOverride(content, lookup) {
|
|
58
63
|
let objSource;
|
59
64
|
if (ts.isObjectLiteralExpression(node)) {
|
60
65
|
objSource = node.getFullText();
|
66
|
+
// strip any spread elements
|
67
|
+
objSource = objSource.replace(SPREAD_ELEMENTS_REGEXP, '');
|
61
68
|
}
|
62
69
|
else {
|
63
70
|
const fullNodeText = node['expression'].arguments[0].body.expression.getFullText();
|
64
71
|
// strip any spread elements
|
65
|
-
objSource = fullNodeText.replace(
|
72
|
+
objSource = fullNodeText.replace(SPREAD_ELEMENTS_REGEXP, '');
|
66
73
|
}
|
67
74
|
const data = (0, devkit_1.parseJson)(objSource
|
68
75
|
// ensure property names have double quotes so that JSON.parse works
|
@@ -76,7 +83,6 @@ function hasOverride(content, lookup) {
|
|
76
83
|
return false;
|
77
84
|
}
|
78
85
|
exports.hasOverride = hasOverride;
|
79
|
-
const STRIP_SPREAD_ELEMENTS = /\s*\.\.\.[a-zA-Z0-9_]+,?\n?/g;
|
80
86
|
function parseTextToJson(text) {
|
81
87
|
return (0, devkit_1.parseJson)(text
|
82
88
|
// ensure property names have double quotes so that JSON.parse works
|
@@ -105,7 +111,7 @@ function replaceOverride(content, root, lookup, update) {
|
|
105
111
|
else {
|
106
112
|
const fullNodeText = node['expression'].arguments[0].body.expression.getFullText();
|
107
113
|
// strip any spread elements
|
108
|
-
objSource = fullNodeText.replace(
|
114
|
+
objSource = fullNodeText.replace(SPREAD_ELEMENTS_REGEXP, '');
|
109
115
|
start =
|
110
116
|
node['expression'].arguments[0].body.expression.properties.pos +
|
111
117
|
(fullNodeText.length - objSource.length);
|
@@ -283,7 +289,7 @@ function removePlugin(content, pluginName, pluginImport) {
|
|
283
289
|
const pluginsArray = pluginsElem.initializer;
|
284
290
|
const plugins = parseTextToJson(pluginsElem.initializer
|
285
291
|
.getText()
|
286
|
-
.replace(
|
292
|
+
.replace(SPREAD_ELEMENTS_REGEXP, ''));
|
287
293
|
if (plugins.length > 1) {
|
288
294
|
changes.push({
|
289
295
|
type: devkit_1.ChangeType.Delete,
|
@@ -504,7 +510,7 @@ function generateFlatOverride(override) {
|
|
504
510
|
!override.parser) {
|
505
511
|
if (override.parserOptions) {
|
506
512
|
const { parserOptions, ...rest } = override;
|
507
|
-
return generateAst({ ...rest,
|
513
|
+
return generateAst({ ...rest, languageOptions: { parserOptions } });
|
508
514
|
}
|
509
515
|
return generateAst(override);
|
510
516
|
}
|
@@ -525,7 +531,7 @@ function generateFlatOverride(override) {
|
|
525
531
|
];
|
526
532
|
objectLiteralElements.push(ts.factory.createPropertyAssignment('rules', ts.factory.createObjectLiteralExpression(updatedRulesProperties, true)));
|
527
533
|
if (parserOptions) {
|
528
|
-
addTSObjectProperty(objectLiteralElements, '
|
534
|
+
addTSObjectProperty(objectLiteralElements, 'languageOptions', {
|
529
535
|
parserOptions,
|
530
536
|
});
|
531
537
|
}
|