@nx/eslint 17.2.0-beta.1 → 17.2.0-beta.11
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/migrations.json +13 -0
- package/package.json +10 -6
- package/plugin.d.ts +1 -0
- package/plugin.js +5 -0
- package/src/executors/lint/hasher.js +1 -1
- package/src/executors/lint/lint.impl.js +10 -2
- package/src/executors/lint/schema.json +1 -2
- package/src/generators/convert-to-flat-config/converters/json-converter.d.ts +6 -1
- package/src/generators/convert-to-flat-config/converters/json-converter.js +19 -25
- package/src/generators/convert-to-flat-config/generator.js +42 -8
- package/src/generators/init/global-eslint-config.js +5 -5
- package/src/generators/init/init-migration.js +1 -1
- package/src/generators/init/init.js +44 -12
- package/src/generators/lint-project/lint-project.d.ts +0 -1
- package/src/generators/lint-project/lint-project.js +47 -31
- package/src/generators/utils/eslint-file.d.ts +0 -3
- package/src/generators/utils/eslint-file.js +19 -27
- package/src/generators/utils/flat-config/ast-utils.d.ts +3 -4
- package/src/generators/utils/flat-config/ast-utils.js +18 -32
- package/src/generators/utils/flat-config/path-utils.d.ts +2 -1
- package/src/generators/utils/flat-config/path-utils.js +9 -12
- package/src/migrations/update-15-0-0/add-eslint-inputs.js +2 -2
- package/src/migrations/update-15-7-1/add-eslint-ignore.js +2 -2
- package/src/migrations/update-17-2-0/simplify-eslint-patterns.d.ts +2 -0
- package/src/migrations/update-17-2-0/simplify-eslint-patterns.js +46 -0
- package/src/plugins/plugin.d.ts +5 -0
- package/src/plugins/plugin.js +99 -0
- package/src/utils/config-file.d.ts +5 -0
- package/src/utils/config-file.js +35 -0
- package/src/utils/versions.d.ts +1 -1
- package/src/utils/versions.js +1 -1
package/migrations.json
CHANGED
|
@@ -32,6 +32,11 @@
|
|
|
32
32
|
"version": "17.1.0-beta.1",
|
|
33
33
|
"description": "Updates for @typescript-utils/utils v6.9.1+",
|
|
34
34
|
"implementation": "./src/migrations/update-17-1-0/update-typescript-eslint"
|
|
35
|
+
},
|
|
36
|
+
"simplify-eslint-patterns": {
|
|
37
|
+
"version": "17.2.0-beta.0",
|
|
38
|
+
"description": "Simplify eslintFilePatterns",
|
|
39
|
+
"implementation": "./src/migrations/update-17-2-0/simplify-eslint-patterns"
|
|
35
40
|
}
|
|
36
41
|
},
|
|
37
42
|
"packageJsonUpdates": {
|
|
@@ -101,6 +106,14 @@
|
|
|
101
106
|
"version": "^6.9.1"
|
|
102
107
|
}
|
|
103
108
|
}
|
|
109
|
+
},
|
|
110
|
+
"17.2.0": {
|
|
111
|
+
"version": "17.2.0-beta.2",
|
|
112
|
+
"packages": {
|
|
113
|
+
"eslint": {
|
|
114
|
+
"version": "~8.48.0"
|
|
115
|
+
}
|
|
116
|
+
}
|
|
104
117
|
}
|
|
105
118
|
}
|
|
106
119
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/eslint",
|
|
3
|
-
"version": "17.2.0-beta.
|
|
3
|
+
"version": "17.2.0-beta.11",
|
|
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": {
|
|
@@ -27,21 +27,25 @@
|
|
|
27
27
|
"requirements": {},
|
|
28
28
|
"migrations": "./migrations.json"
|
|
29
29
|
},
|
|
30
|
-
"executors": "./executors.json",
|
|
31
30
|
"generators": "./generators.json",
|
|
31
|
+
"executors": "./executors.json",
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"eslint": "^8.0.0"
|
|
33
|
+
"eslint": "^8.0.0",
|
|
34
|
+
"js-yaml": "4.1.0"
|
|
34
35
|
},
|
|
35
36
|
"dependencies": {
|
|
37
|
+
"@nx/devkit": "17.2.0-beta.11",
|
|
38
|
+
"@nx/js": "17.2.0-beta.11",
|
|
36
39
|
"tslib": "^2.3.0",
|
|
37
|
-
"@nx/devkit": "17.2.0-beta.1",
|
|
38
|
-
"@nx/js": "17.2.0-beta.1",
|
|
39
40
|
"typescript": "~5.2.2",
|
|
40
|
-
"@nx/linter": "17.2.0-beta.
|
|
41
|
+
"@nx/linter": "17.2.0-beta.11"
|
|
41
42
|
},
|
|
42
43
|
"peerDependenciesMeta": {
|
|
43
44
|
"eslint": {
|
|
44
45
|
"optional": true
|
|
46
|
+
},
|
|
47
|
+
"js-yaml": {
|
|
48
|
+
"optional": true
|
|
45
49
|
}
|
|
46
50
|
},
|
|
47
51
|
"publishConfig": {
|
package/plugin.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createNodes, EslintPluginOptions } from './src/plugins/plugin';
|
package/plugin.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createNodes = void 0;
|
|
4
|
+
var plugin_1 = require("./src/plugins/plugin");
|
|
5
|
+
Object.defineProperty(exports, "createNodes", { enumerable: true, get: function () { return plugin_1.createNodes; } });
|
|
@@ -17,7 +17,7 @@ async function run(task, context) {
|
|
|
17
17
|
}
|
|
18
18
|
const nodes = {};
|
|
19
19
|
const hashes = [];
|
|
20
|
-
for (const d of Object.keys(res.details.nodes)) {
|
|
20
|
+
for (const d of Object.keys(res.details.nodes).sort()) {
|
|
21
21
|
if (d.indexOf('$fileset') === -1) {
|
|
22
22
|
nodes[d] = res.details.nodes[d];
|
|
23
23
|
hashes.push(res.details.nodes[d]);
|
|
@@ -4,6 +4,7 @@ const devkit_1 = require("@nx/devkit");
|
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
5
|
const path_1 = require("path");
|
|
6
6
|
const eslint_utils_1 = require("./utility/eslint-utils");
|
|
7
|
+
const utils_1 = require("nx/src/tasks-runner/utils");
|
|
7
8
|
async function run(options, context) {
|
|
8
9
|
// this is only used for the hasher
|
|
9
10
|
delete options.hasTypeAwareRules;
|
|
@@ -58,8 +59,15 @@ async function run(options, context) {
|
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
let lintResults = [];
|
|
62
|
+
const normalizedLintFilePatterns = normalizedOptions.lintFilePatterns.map((pattern) => {
|
|
63
|
+
return (0, utils_1.interpolate)(pattern, {
|
|
64
|
+
workspaceRoot: '',
|
|
65
|
+
projectRoot: context.projectsConfigurations.projects[context.projectName].root,
|
|
66
|
+
projectName: context.projectName,
|
|
67
|
+
});
|
|
68
|
+
});
|
|
61
69
|
try {
|
|
62
|
-
lintResults = await eslint.lintFiles(
|
|
70
|
+
lintResults = await eslint.lintFiles(normalizedLintFilePatterns);
|
|
63
71
|
}
|
|
64
72
|
catch (err) {
|
|
65
73
|
if (err.message.includes('You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser')) {
|
|
@@ -81,7 +89,7 @@ Please see https://nx.dev/guides/eslint for full guidance on how to resolve this
|
|
|
81
89
|
throw err;
|
|
82
90
|
}
|
|
83
91
|
if (lintResults.length === 0 && errorOnUnmatchedPattern) {
|
|
84
|
-
const ignoredPatterns = (await Promise.all(
|
|
92
|
+
const ignoredPatterns = (await Promise.all(normalizedLintFilePatterns.map(async (pattern) => (await eslint.isPathIgnored(pattern)) ? pattern : null)))
|
|
85
93
|
.filter((pattern) => !!pattern)
|
|
86
94
|
.map((pattern) => `- '${pattern}'`);
|
|
87
95
|
if (ignoredPatterns.length) {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"lintFilePatterns": {
|
|
18
18
|
"type": "array",
|
|
19
19
|
"description": "One or more files/dirs/globs to pass directly to ESLint's `lintFiles()` method.",
|
|
20
|
-
"default": [],
|
|
20
|
+
"default": ["{projectRoot}"],
|
|
21
21
|
"items": {
|
|
22
22
|
"type": "string"
|
|
23
23
|
}
|
|
@@ -144,6 +144,5 @@
|
|
|
144
144
|
"default": true
|
|
145
145
|
}
|
|
146
146
|
},
|
|
147
|
-
"required": ["lintFilePatterns"],
|
|
148
147
|
"examplesFile": "../../../docs/eslint-examples.md"
|
|
149
148
|
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { Tree } from '@nx/devkit';
|
|
2
|
+
import { ESLint } from 'eslint';
|
|
2
3
|
/**
|
|
3
4
|
* Converts an ESLint JSON config to a flat config.
|
|
4
5
|
* Deletes the original file along with .eslintignore if it exists.
|
|
5
6
|
*/
|
|
6
|
-
export declare function convertEslintJsonToFlatConfig(tree: Tree, root: string,
|
|
7
|
+
export declare function convertEslintJsonToFlatConfig(tree: Tree, root: string, config: ESLint.ConfigData, ignorePaths: string[]): {
|
|
8
|
+
content: string;
|
|
9
|
+
addESLintRC: boolean;
|
|
10
|
+
addESLintJS: boolean;
|
|
11
|
+
};
|
|
@@ -2,25 +2,25 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.convertEslintJsonToFlatConfig = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const path_1 = require("path");
|
|
6
5
|
const ts = require("typescript");
|
|
7
|
-
const versions_1 = require("../../../utils/versions");
|
|
8
6
|
const ast_utils_1 = require("../../utils/flat-config/ast-utils");
|
|
9
7
|
const eslint_file_1 = require("../../utils/eslint-file");
|
|
8
|
+
const path_utils_1 = require("../../utils/flat-config/path-utils");
|
|
10
9
|
/**
|
|
11
10
|
* Converts an ESLint JSON config to a flat config.
|
|
12
11
|
* Deletes the original file along with .eslintignore if it exists.
|
|
13
12
|
*/
|
|
14
|
-
function convertEslintJsonToFlatConfig(tree, root,
|
|
13
|
+
function convertEslintJsonToFlatConfig(tree, root, config, ignorePaths) {
|
|
15
14
|
const importsMap = new Map();
|
|
16
15
|
const exportElements = [];
|
|
17
16
|
let isFlatCompatNeeded = false;
|
|
17
|
+
let isESLintJSNeeded = false;
|
|
18
18
|
let combinedConfig = [];
|
|
19
19
|
let languageOptions = [];
|
|
20
|
-
// read original config
|
|
21
|
-
const config = (0, devkit_1.readJson)(tree, `${root}/${sourceFile}`);
|
|
22
20
|
if (config.extends) {
|
|
23
|
-
|
|
21
|
+
const extendsResult = addExtends(importsMap, exportElements, config);
|
|
22
|
+
isFlatCompatNeeded = extendsResult.isFlatCompatNeeded;
|
|
23
|
+
isESLintJSNeeded = extendsResult.isESLintJSNeeded;
|
|
24
24
|
}
|
|
25
25
|
if (config.plugins) {
|
|
26
26
|
addPlugins(importsMap, exportElements, config);
|
|
@@ -70,7 +70,7 @@ function convertEslintJsonToFlatConfig(tree, root, sourceFile, destinationFile,
|
|
|
70
70
|
override.parser) {
|
|
71
71
|
isFlatCompatNeeded = true;
|
|
72
72
|
}
|
|
73
|
-
exportElements.push((0, ast_utils_1.generateFlatOverride)(override
|
|
73
|
+
exportElements.push((0, ast_utils_1.generateFlatOverride)(override));
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
76
|
if (config.ignorePatterns) {
|
|
@@ -79,7 +79,7 @@ function convertEslintJsonToFlatConfig(tree, root, sourceFile, destinationFile,
|
|
|
79
79
|
: [config.ignorePatterns]).filter((pattern) => !['**/*', '!**/*', 'node_modules'].includes(pattern)); // these are useless in a flat config
|
|
80
80
|
if (patterns.length > 0) {
|
|
81
81
|
exportElements.push((0, ast_utils_1.generateAst)({
|
|
82
|
-
ignores: patterns.map((path) => (0,
|
|
82
|
+
ignores: patterns.map((path) => (0, path_utils_1.mapFilePath)(path)),
|
|
83
83
|
}));
|
|
84
84
|
}
|
|
85
85
|
}
|
|
@@ -89,27 +89,25 @@ function convertEslintJsonToFlatConfig(tree, root, sourceFile, destinationFile,
|
|
|
89
89
|
.read(ignorePath, 'utf-8')
|
|
90
90
|
.split('\n')
|
|
91
91
|
.filter((line) => line.length > 0 && line !== 'node_modules')
|
|
92
|
-
.map((path) => (0,
|
|
92
|
+
.map((path) => (0, path_utils_1.mapFilePath)(path));
|
|
93
93
|
if (patterns.length > 0) {
|
|
94
94
|
exportElements.push((0, ast_utils_1.generateAst)({ ignores: patterns }));
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
-
tree.delete((0, path_1.join)(root, sourceFile));
|
|
99
98
|
// create the node list and print it to new file
|
|
100
99
|
const nodeList = (0, ast_utils_1.createNodeList)(importsMap, exportElements, isFlatCompatNeeded);
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
});
|
|
107
|
-
}
|
|
100
|
+
return {
|
|
101
|
+
content: (0, ast_utils_1.stringifyNodeList)(nodeList),
|
|
102
|
+
addESLintRC: isFlatCompatNeeded,
|
|
103
|
+
addESLintJS: isESLintJSNeeded,
|
|
104
|
+
};
|
|
108
105
|
}
|
|
109
106
|
exports.convertEslintJsonToFlatConfig = convertEslintJsonToFlatConfig;
|
|
110
107
|
// add parsed extends to export blocks and add import statements
|
|
111
|
-
function addExtends(importsMap, configBlocks, config
|
|
108
|
+
function addExtends(importsMap, configBlocks, config) {
|
|
112
109
|
let isFlatCompatNeeded = false;
|
|
110
|
+
let isESLintJSNeeded = false;
|
|
113
111
|
const extendsConfig = Array.isArray(config.extends)
|
|
114
112
|
? config.extends
|
|
115
113
|
: [config.extends];
|
|
@@ -138,9 +136,7 @@ function addExtends(importsMap, configBlocks, config, tree) {
|
|
|
138
136
|
}
|
|
139
137
|
});
|
|
140
138
|
if (eslintPluginExtends.length) {
|
|
141
|
-
|
|
142
|
-
'@eslint/js': versions_1.eslintVersion,
|
|
143
|
-
});
|
|
139
|
+
isESLintJSNeeded = true;
|
|
144
140
|
importsMap.set('@eslint/js', 'js');
|
|
145
141
|
eslintPluginExtends.forEach((plugin) => {
|
|
146
142
|
configBlocks.push(ts.factory.createPropertyAccessExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier('js'), ts.factory.createIdentifier('configs')), ts.factory.createIdentifier(plugin.slice(7)) // strip 'eslint:' prefix
|
|
@@ -150,12 +146,10 @@ function addExtends(importsMap, configBlocks, config, tree) {
|
|
|
150
146
|
}
|
|
151
147
|
if (eslintrcConfigs.length) {
|
|
152
148
|
isFlatCompatNeeded = true;
|
|
153
|
-
|
|
154
|
-
'@eslint/js': versions_1.eslintVersion,
|
|
155
|
-
});
|
|
149
|
+
isESLintJSNeeded = true;
|
|
156
150
|
configBlocks.push((0, ast_utils_1.generatePluginExtendsElement)(eslintrcConfigs));
|
|
157
151
|
}
|
|
158
|
-
return isFlatCompatNeeded;
|
|
152
|
+
return { isFlatCompatNeeded, isESLintJSNeeded };
|
|
159
153
|
}
|
|
160
154
|
function addPlugins(importsMap, configBlocks, config) {
|
|
161
155
|
const mappedPlugins = [];
|
|
@@ -3,14 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.convertToFlatConfigGenerator = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const eslint_file_1 = require("../utils/eslint-file");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const versions_1 = require("../../utils/versions");
|
|
6
8
|
const json_converter_1 = require("./converters/json-converter");
|
|
9
|
+
const js_yaml_1 = require("js-yaml");
|
|
7
10
|
async function convertToFlatConfigGenerator(tree, options) {
|
|
8
11
|
const eslintFile = (0, eslint_file_1.findEslintFile)(tree);
|
|
9
12
|
if (!eslintFile) {
|
|
10
13
|
throw new Error('Could not find root eslint file');
|
|
11
14
|
}
|
|
12
|
-
if (
|
|
13
|
-
throw new Error('Only json eslint config files are supported for conversion');
|
|
15
|
+
if (eslintFile.endsWith('.js')) {
|
|
16
|
+
throw new Error('Only json and yaml eslint config files are supported for conversion');
|
|
14
17
|
}
|
|
15
18
|
const eslintIgnoreFiles = new Set(['.eslintignore']);
|
|
16
19
|
// convert root eslint config to eslint.config.js
|
|
@@ -34,13 +37,14 @@ async function convertToFlatConfigGenerator(tree, options) {
|
|
|
34
37
|
exports.convertToFlatConfigGenerator = convertToFlatConfigGenerator;
|
|
35
38
|
exports.default = convertToFlatConfigGenerator;
|
|
36
39
|
function convertRootToFlatConfig(tree, eslintFile) {
|
|
37
|
-
if (
|
|
38
|
-
convertConfigToFlatConfig(tree, '',
|
|
40
|
+
if (/\.base\.(js|json|yml|yaml)$/.test(eslintFile)) {
|
|
41
|
+
convertConfigToFlatConfig(tree, '', eslintFile, 'eslint.base.config.js');
|
|
39
42
|
}
|
|
40
|
-
convertConfigToFlatConfig(tree, '', '.
|
|
43
|
+
convertConfigToFlatConfig(tree, '', eslintFile.replace('.base.', '.'), 'eslint.config.js');
|
|
41
44
|
}
|
|
42
45
|
function convertProjectToFlatConfig(tree, project, projectConfig, nxJson, eslintIgnoreFiles) {
|
|
43
|
-
|
|
46
|
+
const eslintFile = (0, eslint_file_1.findEslintFile)(tree, projectConfig.root);
|
|
47
|
+
if (eslintFile && !eslintFile.endsWith('.js')) {
|
|
44
48
|
if (projectConfig.targets) {
|
|
45
49
|
const eslintTargets = Object.keys(projectConfig.targets || {}).filter((t) => projectConfig.targets[t].executor === '@nx/eslint:lint');
|
|
46
50
|
let ignorePath;
|
|
@@ -59,7 +63,7 @@ function convertProjectToFlatConfig(tree, project, projectConfig, nxJson, eslint
|
|
|
59
63
|
nxJson.targetDefaults[t].executor === '@nx/eslint:lint') &&
|
|
60
64
|
projectConfig.targets?.[t]);
|
|
61
65
|
if (nxHasLintTargets || eslintTargets.length > 0) {
|
|
62
|
-
convertConfigToFlatConfig(tree, projectConfig.root,
|
|
66
|
+
convertConfigToFlatConfig(tree, projectConfig.root, eslintFile, 'eslint.config.js', ignorePath);
|
|
63
67
|
eslintIgnoreFiles.add(`${projectConfig.root}/.eslintignore`);
|
|
64
68
|
if (ignorePath) {
|
|
65
69
|
eslintIgnoreFiles.add(ignorePath);
|
|
@@ -96,5 +100,35 @@ function convertConfigToFlatConfig(tree, root, source, target, ignorePath) {
|
|
|
96
100
|
const ignorePaths = ignorePath
|
|
97
101
|
? [ignorePath, `${root}/.eslintignore`]
|
|
98
102
|
: [`${root}/.eslintignore`];
|
|
99
|
-
(
|
|
103
|
+
if (source.endsWith('.json')) {
|
|
104
|
+
const config = (0, devkit_1.readJson)(tree, `${root}/${source}`);
|
|
105
|
+
const conversionResult = (0, json_converter_1.convertEslintJsonToFlatConfig)(tree, root, config, ignorePaths);
|
|
106
|
+
return processConvertedConfig(tree, root, source, target, conversionResult);
|
|
107
|
+
}
|
|
108
|
+
if (source.endsWith('.yaml') || source.endsWith('.yml')) {
|
|
109
|
+
const originalContent = tree.read(`${root}/${source}`, 'utf-8');
|
|
110
|
+
const config = (0, js_yaml_1.load)(originalContent, {
|
|
111
|
+
json: true,
|
|
112
|
+
filename: source,
|
|
113
|
+
});
|
|
114
|
+
const conversionResult = (0, json_converter_1.convertEslintJsonToFlatConfig)(tree, root, config, ignorePaths);
|
|
115
|
+
return processConvertedConfig(tree, root, source, target, conversionResult);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function processConvertedConfig(tree, root, source, target, { content, addESLintRC, addESLintJS, }) {
|
|
119
|
+
// remove original config file
|
|
120
|
+
tree.delete((0, path_1.join)(root, source));
|
|
121
|
+
// save new
|
|
122
|
+
tree.write((0, path_1.join)(root, target), content);
|
|
123
|
+
// add missing packages
|
|
124
|
+
if (addESLintRC) {
|
|
125
|
+
(0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
|
|
126
|
+
'@eslint/eslintrc': versions_1.eslintrcVersion,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
if (addESLintJS) {
|
|
130
|
+
(0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
|
|
131
|
+
'@eslint/js': versions_1.eslintVersion,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
100
134
|
}
|
|
@@ -80,18 +80,18 @@ const getGlobalEsLintConfiguration = (unitTestRunner, rootProject) => {
|
|
|
80
80
|
exports.getGlobalEsLintConfiguration = getGlobalEsLintConfiguration;
|
|
81
81
|
const getGlobalFlatEslintConfiguration = (unitTestRunner, rootProject) => {
|
|
82
82
|
const nodeList = (0, ast_utils_1.createNodeList)(new Map(), [], true);
|
|
83
|
-
let content = (0, ast_utils_1.stringifyNodeList)(nodeList
|
|
83
|
+
let content = (0, ast_utils_1.stringifyNodeList)(nodeList);
|
|
84
84
|
content = (0, ast_utils_1.addImportToFlatConfig)(content, 'nxPlugin', '@nx/eslint-plugin');
|
|
85
85
|
content = (0, ast_utils_1.addPluginsToExportsBlock)(content, [
|
|
86
86
|
{ name: '@nx', varName: 'nxPlugin', imp: '@nx/eslint-plugin' },
|
|
87
87
|
]);
|
|
88
88
|
if (!rootProject) {
|
|
89
|
-
content = (0, ast_utils_1.addBlockToFlatConfigExport)(content, (0, ast_utils_1.generateFlatOverride)(moduleBoundariesOverride
|
|
89
|
+
content = (0, ast_utils_1.addBlockToFlatConfigExport)(content, (0, ast_utils_1.generateFlatOverride)(moduleBoundariesOverride));
|
|
90
90
|
}
|
|
91
|
-
content = (0, ast_utils_1.addBlockToFlatConfigExport)(content, (0, ast_utils_1.generateFlatOverride)(exports.typeScriptOverride
|
|
92
|
-
content = (0, ast_utils_1.addBlockToFlatConfigExport)(content, (0, ast_utils_1.generateFlatOverride)(exports.javaScriptOverride
|
|
91
|
+
content = (0, ast_utils_1.addBlockToFlatConfigExport)(content, (0, ast_utils_1.generateFlatOverride)(exports.typeScriptOverride));
|
|
92
|
+
content = (0, ast_utils_1.addBlockToFlatConfigExport)(content, (0, ast_utils_1.generateFlatOverride)(exports.javaScriptOverride));
|
|
93
93
|
if (unitTestRunner === 'jest') {
|
|
94
|
-
content = (0, ast_utils_1.addBlockToFlatConfigExport)(content, (0, ast_utils_1.generateFlatOverride)(jestOverride
|
|
94
|
+
content = (0, ast_utils_1.addBlockToFlatConfigExport)(content, (0, ast_utils_1.generateFlatOverride)(jestOverride));
|
|
95
95
|
}
|
|
96
96
|
return content;
|
|
97
97
|
};
|
|
@@ -23,7 +23,7 @@ function migrateConfigToMonorepoStyle(projects, tree, unitTestRunner) {
|
|
|
23
23
|
projects.forEach((project) => {
|
|
24
24
|
const lintTarget = findLintTarget(project);
|
|
25
25
|
if (lintTarget) {
|
|
26
|
-
const eslintFile = lintTarget.options
|
|
26
|
+
const eslintFile = lintTarget.options?.eslintConfig || (0, eslint_file_1.findEslintFile)(tree, project.root);
|
|
27
27
|
if (eslintFile) {
|
|
28
28
|
const projectEslintPath = (0, devkit_1.joinPathFragments)(project.root, eslintFile);
|
|
29
29
|
migrateEslintFile(projectEslintPath, tree);
|
|
@@ -5,18 +5,22 @@ const devkit_1 = require("@nx/devkit");
|
|
|
5
5
|
const versions_1 = require("../../utils/versions");
|
|
6
6
|
const eslint_file_1 = require("../utils/eslint-file");
|
|
7
7
|
const global_eslint_config_1 = require("./global-eslint-config");
|
|
8
|
-
function
|
|
8
|
+
function updateProductionFileset(tree) {
|
|
9
9
|
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
10
10
|
const productionFileSet = nxJson.namedInputs?.production;
|
|
11
11
|
if (productionFileSet) {
|
|
12
|
-
// Remove .eslintrc.json
|
|
13
12
|
productionFileSet.push('!{projectRoot}/.eslintrc.json');
|
|
14
13
|
productionFileSet.push('!{projectRoot}/eslint.config.js');
|
|
15
14
|
// Dedupe and set
|
|
16
15
|
nxJson.namedInputs.production = Array.from(new Set(productionFileSet));
|
|
17
16
|
}
|
|
17
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
18
|
+
}
|
|
19
|
+
function addTargetDefaults(tree) {
|
|
20
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
18
21
|
nxJson.targetDefaults ??= {};
|
|
19
22
|
nxJson.targetDefaults.lint ??= {};
|
|
23
|
+
nxJson.targetDefaults.lint.cache ??= true;
|
|
20
24
|
nxJson.targetDefaults.lint.inputs ??= [
|
|
21
25
|
'default',
|
|
22
26
|
`{workspaceRoot}/.eslintrc.json`,
|
|
@@ -25,6 +29,36 @@ function addTargetDefaults(tree) {
|
|
|
25
29
|
];
|
|
26
30
|
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
27
31
|
}
|
|
32
|
+
function addPlugin(tree) {
|
|
33
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
34
|
+
nxJson.plugins ??= [];
|
|
35
|
+
for (const plugin of nxJson.plugins) {
|
|
36
|
+
if (typeof plugin === 'string'
|
|
37
|
+
? plugin === '@nx/eslint/plugin'
|
|
38
|
+
: plugin.plugin === '@nx/eslint/plugin') {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
nxJson.plugins.push({
|
|
43
|
+
plugin: '@nx/eslint/plugin',
|
|
44
|
+
options: {
|
|
45
|
+
targetName: 'lint',
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
49
|
+
}
|
|
50
|
+
function updateVSCodeExtensions(tree) {
|
|
51
|
+
if (tree.exists('.vscode/extensions.json')) {
|
|
52
|
+
(0, devkit_1.updateJson)(tree, '.vscode/extensions.json', (json) => {
|
|
53
|
+
json.recommendations ||= [];
|
|
54
|
+
const extension = 'dbaeumer.vscode-eslint';
|
|
55
|
+
if (!json.recommendations.includes(extension)) {
|
|
56
|
+
json.recommendations.push(extension);
|
|
57
|
+
}
|
|
58
|
+
return json;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
28
62
|
/**
|
|
29
63
|
* Initializes ESLint configuration in a workspace and adds necessary dependencies.
|
|
30
64
|
*/
|
|
@@ -37,17 +71,15 @@ function initEsLint(tree, options) {
|
|
|
37
71
|
}
|
|
38
72
|
(0, devkit_1.writeJson)(tree, '.eslintrc.json', (0, global_eslint_config_1.getGlobalEsLintConfiguration)(options.unitTestRunner, options.rootProject));
|
|
39
73
|
tree.write('.eslintignore', 'node_modules\n');
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
return json;
|
|
49
|
-
});
|
|
74
|
+
updateProductionFileset(tree);
|
|
75
|
+
const addPlugins = process.env.NX_PCV3 === 'true';
|
|
76
|
+
if (addPlugins) {
|
|
77
|
+
addPlugin(tree);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
addTargetDefaults(tree);
|
|
50
81
|
}
|
|
82
|
+
updateVSCodeExtensions(tree);
|
|
51
83
|
return !options.skipPackageJson
|
|
52
84
|
? (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
|
|
53
85
|
'@nx/eslint': versions_1.nxVersion,
|
|
@@ -11,6 +11,5 @@ interface LintProjectOptions {
|
|
|
11
11
|
unitTestRunner?: string;
|
|
12
12
|
rootProject?: boolean;
|
|
13
13
|
}
|
|
14
|
-
export declare function mapLintPattern(projectRoot: string, extension: string, rootProject?: boolean): string;
|
|
15
14
|
export declare function lintProjectGenerator(tree: Tree, options: LintProjectOptions): Promise<import("@nx/devkit").GeneratorCallback>;
|
|
16
15
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.lintProjectGenerator =
|
|
3
|
+
exports.lintProjectGenerator = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const eslint_file_1 = require("../utils/eslint-file");
|
|
6
6
|
const path_1 = require("path");
|
|
@@ -9,15 +9,7 @@ const init_migration_1 = require("../init/init-migration");
|
|
|
9
9
|
const project_configuration_1 = require("nx/src/generators/utils/project-configuration");
|
|
10
10
|
const flat_config_1 = require("../../utils/flat-config");
|
|
11
11
|
const ast_utils_1 = require("../utils/flat-config/ast-utils");
|
|
12
|
-
|
|
13
|
-
if (rootProject && (projectRoot === '.' || projectRoot === '')) {
|
|
14
|
-
return `${projectRoot}/src/**/*.${extension}`;
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
return `${projectRoot}/**/*.${extension}`;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
exports.mapLintPattern = mapLintPattern;
|
|
12
|
+
const config_file_1 = require("../../utils/config-file");
|
|
21
13
|
async function lintProjectGenerator(tree, options) {
|
|
22
14
|
const installTask = (0, init_1.lintInitGenerator)(tree, {
|
|
23
15
|
linter: options.linter,
|
|
@@ -26,17 +18,40 @@ async function lintProjectGenerator(tree, options) {
|
|
|
26
18
|
rootProject: options.rootProject,
|
|
27
19
|
});
|
|
28
20
|
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
29
|
-
|
|
30
|
-
if (
|
|
31
|
-
lintFilePatterns
|
|
21
|
+
let lintFilePatterns = options.eslintFilePatterns;
|
|
22
|
+
if (!lintFilePatterns && options.rootProject && projectConfig.root === '.') {
|
|
23
|
+
lintFilePatterns = ['./src'];
|
|
24
|
+
}
|
|
25
|
+
if (lintFilePatterns &&
|
|
26
|
+
lintFilePatterns.length &&
|
|
27
|
+
!lintFilePatterns.includes('{projectRoot}') &&
|
|
28
|
+
isBuildableLibraryProject(projectConfig)) {
|
|
29
|
+
lintFilePatterns.push(`{projectRoot}/package.json`);
|
|
30
|
+
}
|
|
31
|
+
const usePlugin = process.env.NX_PCV3 === 'true';
|
|
32
|
+
if (usePlugin) {
|
|
33
|
+
if (lintFilePatterns &&
|
|
34
|
+
lintFilePatterns.length &&
|
|
35
|
+
lintFilePatterns.some((p) => !['./src', '{projectRoot}', projectConfig.root].includes(p))) {
|
|
36
|
+
projectConfig.targets['lint'] = {
|
|
37
|
+
command: `eslint ${lintFilePatterns
|
|
38
|
+
.join(' ')
|
|
39
|
+
.replace('{projectRoot}', projectConfig.root)}`,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
projectConfig.targets['lint'] = {
|
|
45
|
+
executor: '@nx/eslint:lint',
|
|
46
|
+
outputs: ['{options.outputFile}'],
|
|
47
|
+
};
|
|
48
|
+
if (lintFilePatterns && lintFilePatterns.length) {
|
|
49
|
+
// only add lintFilePatterns if they are explicitly defined
|
|
50
|
+
projectConfig.targets['lint'].options = {
|
|
51
|
+
lintFilePatterns,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
32
54
|
}
|
|
33
|
-
projectConfig.targets['lint'] = {
|
|
34
|
-
executor: '@nx/eslint:lint',
|
|
35
|
-
outputs: ['{options.outputFile}'],
|
|
36
|
-
options: {
|
|
37
|
-
lintFilePatterns: lintFilePatterns,
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
55
|
// we are adding new project which is not the root project or
|
|
41
56
|
// companion e2e app so we should check if migration to
|
|
42
57
|
// monorepo style is needed
|
|
@@ -58,7 +73,7 @@ async function lintProjectGenerator(tree, options) {
|
|
|
58
73
|
// additionally, the companion e2e app would have `rootProject: true`
|
|
59
74
|
// so we need to check for the root path as well
|
|
60
75
|
if (!options.rootProject || projectConfig.root !== '.') {
|
|
61
|
-
createEsLintConfiguration(tree, projectConfig, options.setParserOptionsProject);
|
|
76
|
+
createEsLintConfiguration(tree, projectConfig, options.setParserOptionsProject, options.rootProject);
|
|
62
77
|
}
|
|
63
78
|
// Buildable libs need source analysis enabled for linting `package.json`.
|
|
64
79
|
if (isBuildableLibraryProject(projectConfig) &&
|
|
@@ -77,10 +92,11 @@ async function lintProjectGenerator(tree, options) {
|
|
|
77
92
|
return installTask;
|
|
78
93
|
}
|
|
79
94
|
exports.lintProjectGenerator = lintProjectGenerator;
|
|
80
|
-
function createEsLintConfiguration(tree, projectConfig, setParserOptionsProject) {
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
|
|
95
|
+
function createEsLintConfiguration(tree, projectConfig, setParserOptionsProject, rootProject) {
|
|
96
|
+
// we are only extending root for non-standalone projects or their complementary e2e apps
|
|
97
|
+
const extendedRootConfig = rootProject ? undefined : (0, eslint_file_1.findEslintFile)(tree);
|
|
98
|
+
const pathToRootConfig = extendedRootConfig
|
|
99
|
+
? `${(0, devkit_1.offsetFromRoot)(projectConfig.root)}${extendedRootConfig}`
|
|
84
100
|
: undefined;
|
|
85
101
|
const addDependencyChecks = isBuildableLibraryProject(projectConfig);
|
|
86
102
|
const overrides = [
|
|
@@ -132,20 +148,20 @@ function createEsLintConfiguration(tree, projectConfig, setParserOptionsProject)
|
|
|
132
148
|
const isCompatNeeded = addDependencyChecks;
|
|
133
149
|
const nodes = [];
|
|
134
150
|
const importMap = new Map();
|
|
135
|
-
if (
|
|
151
|
+
if (extendedRootConfig) {
|
|
136
152
|
importMap.set(pathToRootConfig, 'baseConfig');
|
|
137
153
|
nodes.push((0, ast_utils_1.generateSpreadElement)('baseConfig'));
|
|
138
154
|
}
|
|
139
155
|
overrides.forEach((override) => {
|
|
140
|
-
nodes.push((0, ast_utils_1.generateFlatOverride)(override
|
|
156
|
+
nodes.push((0, ast_utils_1.generateFlatOverride)(override));
|
|
141
157
|
});
|
|
142
158
|
const nodeList = (0, ast_utils_1.createNodeList)(importMap, nodes, isCompatNeeded);
|
|
143
|
-
const content = (0, ast_utils_1.stringifyNodeList)(nodeList
|
|
159
|
+
const content = (0, ast_utils_1.stringifyNodeList)(nodeList);
|
|
144
160
|
tree.write((0, path_1.join)(projectConfig.root, 'eslint.config.js'), content);
|
|
145
161
|
}
|
|
146
162
|
else {
|
|
147
163
|
(0, devkit_1.writeJson)(tree, (0, path_1.join)(projectConfig.root, `.eslintrc.json`), {
|
|
148
|
-
extends:
|
|
164
|
+
extends: extendedRootConfig ? [pathToRootConfig] : undefined,
|
|
149
165
|
// Include project files to be linted since the global one excludes all files.
|
|
150
166
|
ignorePatterns: ['!**/*'],
|
|
151
167
|
overrides,
|
|
@@ -169,8 +185,8 @@ function isBuildableLibraryProject(projectConfig) {
|
|
|
169
185
|
*/
|
|
170
186
|
function isMigrationToMonorepoNeeded(projects, tree) {
|
|
171
187
|
// the base config is already created, migration has been done
|
|
172
|
-
if (tree.exists(
|
|
173
|
-
tree.exists(
|
|
188
|
+
if (tree.exists(config_file_1.baseEsLintConfigFile) ||
|
|
189
|
+
tree.exists(config_file_1.baseEsLintFlatConfigFile)) {
|
|
174
190
|
return false;
|
|
175
191
|
}
|
|
176
192
|
const configs = Object.values(projects);
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { Tree } from '@nx/devkit';
|
|
2
2
|
import { Linter } from 'eslint';
|
|
3
|
-
export declare const eslintConfigFileWhitelist: string[];
|
|
4
|
-
export declare const baseEsLintConfigFile = ".eslintrc.base.json";
|
|
5
|
-
export declare const baseEsLintFlatConfigFile = "eslint.base.config.js";
|
|
6
3
|
export declare function findEslintFile(tree: Tree, projectRoot?: string): string | null;
|
|
7
4
|
export declare function isEslintConfigSupported(tree: Tree, projectRoot?: string): boolean;
|
|
8
5
|
export declare function updateRelativePathsInConfig(tree: Tree, sourcePath: string, destinationPath: string): void;
|
|
@@ -1,28 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPluginImport = exports.addIgnoresToLintConfig = exports.addPluginsToLintConfig = exports.addExtendsToLintConfig = exports.replaceOverridesInLintConfig = exports.lintConfigHasOverride = exports.updateOverrideInLintConfig = exports.addOverrideToLintConfig = exports.updateRelativePathsInConfig = exports.isEslintConfigSupported = exports.findEslintFile =
|
|
3
|
+
exports.getPluginImport = exports.addIgnoresToLintConfig = exports.addPluginsToLintConfig = exports.addExtendsToLintConfig = exports.replaceOverridesInLintConfig = exports.lintConfigHasOverride = exports.updateOverrideInLintConfig = exports.addOverrideToLintConfig = exports.updateRelativePathsInConfig = exports.isEslintConfigSupported = exports.findEslintFile = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const flat_config_1 = require("../../utils/flat-config");
|
|
6
6
|
const ast_utils_1 = require("./flat-config/ast-utils");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
'.eslintrc.yml',
|
|
13
|
-
'.eslintrc.json',
|
|
14
|
-
'eslint.config.js',
|
|
15
|
-
];
|
|
16
|
-
exports.baseEsLintConfigFile = '.eslintrc.base.json';
|
|
17
|
-
exports.baseEsLintFlatConfigFile = 'eslint.base.config.js';
|
|
18
|
-
function findEslintFile(tree, projectRoot = '') {
|
|
19
|
-
if (projectRoot === '' && tree.exists(exports.baseEsLintConfigFile)) {
|
|
20
|
-
return exports.baseEsLintConfigFile;
|
|
7
|
+
const path_utils_1 = require("./flat-config/path-utils");
|
|
8
|
+
const config_file_1 = require("../../utils/config-file");
|
|
9
|
+
function findEslintFile(tree, projectRoot) {
|
|
10
|
+
if (projectRoot === undefined && tree.exists(config_file_1.baseEsLintConfigFile)) {
|
|
11
|
+
return config_file_1.baseEsLintConfigFile;
|
|
21
12
|
}
|
|
22
|
-
if (projectRoot ===
|
|
23
|
-
return
|
|
13
|
+
if (projectRoot === undefined && tree.exists(config_file_1.baseEsLintFlatConfigFile)) {
|
|
14
|
+
return config_file_1.baseEsLintFlatConfigFile;
|
|
24
15
|
}
|
|
25
|
-
|
|
16
|
+
projectRoot ??= '';
|
|
17
|
+
for (const file of config_file_1.ESLINT_CONFIG_FILENAMES) {
|
|
26
18
|
if (tree.exists((0, devkit_1.joinPathFragments)(projectRoot, file))) {
|
|
27
19
|
return file;
|
|
28
20
|
}
|
|
@@ -93,7 +85,7 @@ function replaceFlatConfigPaths(config, sourceRoot, offset, destinationRoot, tre
|
|
|
93
85
|
return newConfig;
|
|
94
86
|
}
|
|
95
87
|
function offsetFilePath(projectRoot, pathToFile, offset, tree) {
|
|
96
|
-
if (
|
|
88
|
+
if (config_file_1.ESLINT_CONFIG_FILENAMES.some((eslintFile) => pathToFile.includes(eslintFile))) {
|
|
97
89
|
// if the file is point to base eslint
|
|
98
90
|
const rootEslint = findEslintFile(tree);
|
|
99
91
|
if (rootEslint) {
|
|
@@ -111,8 +103,8 @@ function addOverrideToLintConfig(tree, root, override, options = {
|
|
|
111
103
|
}) {
|
|
112
104
|
const isBase = options.checkBaseConfig && findEslintFile(tree, root).includes('.base');
|
|
113
105
|
if ((0, flat_config_1.useFlatConfig)(tree)) {
|
|
114
|
-
const fileName = (0, devkit_1.joinPathFragments)(root, isBase ?
|
|
115
|
-
const flatOverride = (0, ast_utils_1.generateFlatOverride)(override
|
|
106
|
+
const fileName = (0, devkit_1.joinPathFragments)(root, isBase ? config_file_1.baseEsLintFlatConfigFile : 'eslint.config.js');
|
|
107
|
+
const flatOverride = (0, ast_utils_1.generateFlatOverride)(override);
|
|
116
108
|
let content = tree.read(fileName, 'utf8');
|
|
117
109
|
// we will be using compat here so we need to make sure it's added
|
|
118
110
|
if (overrideNeedsCompat(override)) {
|
|
@@ -121,9 +113,9 @@ function addOverrideToLintConfig(tree, root, override, options = {
|
|
|
121
113
|
tree.write(fileName, (0, ast_utils_1.addBlockToFlatConfigExport)(content, flatOverride, options));
|
|
122
114
|
}
|
|
123
115
|
else {
|
|
124
|
-
const fileName = (0, devkit_1.joinPathFragments)(root, isBase ?
|
|
116
|
+
const fileName = (0, devkit_1.joinPathFragments)(root, isBase ? config_file_1.baseEsLintConfigFile : '.eslintrc.json');
|
|
125
117
|
(0, devkit_1.updateJson)(tree, fileName, (json) => {
|
|
126
|
-
json.overrides
|
|
118
|
+
json.overrides ??= [];
|
|
127
119
|
if (options.insertAtTheEnd) {
|
|
128
120
|
json.overrides.push(override);
|
|
129
121
|
}
|
|
@@ -163,12 +155,12 @@ function lintConfigHasOverride(tree, root, lookup, checkBaseConfig = false) {
|
|
|
163
155
|
}
|
|
164
156
|
const isBase = checkBaseConfig && findEslintFile(tree, root).includes('.base');
|
|
165
157
|
if ((0, flat_config_1.useFlatConfig)(tree)) {
|
|
166
|
-
const fileName = (0, devkit_1.joinPathFragments)(root, isBase ?
|
|
158
|
+
const fileName = (0, devkit_1.joinPathFragments)(root, isBase ? config_file_1.baseEsLintFlatConfigFile : 'eslint.config.js');
|
|
167
159
|
const content = tree.read(fileName, 'utf8');
|
|
168
160
|
return (0, ast_utils_1.hasOverride)(content, lookup);
|
|
169
161
|
}
|
|
170
162
|
else {
|
|
171
|
-
const fileName = (0, devkit_1.joinPathFragments)(root, isBase ?
|
|
163
|
+
const fileName = (0, devkit_1.joinPathFragments)(root, isBase ? config_file_1.baseEsLintConfigFile : '.eslintrc.json');
|
|
172
164
|
return (0, devkit_1.readJson)(tree, fileName).overrides?.some(lookup) || false;
|
|
173
165
|
}
|
|
174
166
|
}
|
|
@@ -183,7 +175,7 @@ function replaceOverridesInLintConfig(tree, root, overrides) {
|
|
|
183
175
|
}
|
|
184
176
|
content = (0, ast_utils_1.removeOverridesFromLintConfig)(content);
|
|
185
177
|
overrides.forEach((override) => {
|
|
186
|
-
const flatOverride = (0, ast_utils_1.generateFlatOverride)(override
|
|
178
|
+
const flatOverride = (0, ast_utils_1.generateFlatOverride)(override);
|
|
187
179
|
(0, ast_utils_1.addBlockToFlatConfigExport)(content, flatOverride);
|
|
188
180
|
});
|
|
189
181
|
tree.write(fileName, content);
|
|
@@ -247,7 +239,7 @@ function addIgnoresToLintConfig(tree, root, ignorePatterns) {
|
|
|
247
239
|
if ((0, flat_config_1.useFlatConfig)(tree)) {
|
|
248
240
|
const fileName = (0, devkit_1.joinPathFragments)(root, 'eslint.config.js');
|
|
249
241
|
const block = (0, ast_utils_1.generateAst)({
|
|
250
|
-
ignores: ignorePatterns.map((path) => (0,
|
|
242
|
+
ignores: ignorePatterns.map((path) => (0, path_utils_1.mapFilePath)(path)),
|
|
251
243
|
});
|
|
252
244
|
tree.write(fileName, (0, ast_utils_1.addBlockToFlatConfigExport)(tree.read(fileName, 'utf8'), block));
|
|
253
245
|
}
|
|
@@ -44,7 +44,7 @@ export declare function generatePluginExtendsElement(plugins: string[]): ts.Spre
|
|
|
44
44
|
/**
|
|
45
45
|
* Stringifies TS nodes to file content string
|
|
46
46
|
*/
|
|
47
|
-
export declare function stringifyNodeList(nodes: ts.NodeArray<ts.VariableStatement | ts.Identifier | ts.ExpressionStatement | ts.SourceFile
|
|
47
|
+
export declare function stringifyNodeList(nodes: ts.NodeArray<ts.VariableStatement | ts.Identifier | ts.ExpressionStatement | ts.SourceFile>): string;
|
|
48
48
|
/**
|
|
49
49
|
* generates AST require statement
|
|
50
50
|
*/
|
|
@@ -52,9 +52,8 @@ export declare function generateRequire(variableName: string | ts.ObjectBindingP
|
|
|
52
52
|
/**
|
|
53
53
|
* Generates AST object or spread element based on JSON override object
|
|
54
54
|
*/
|
|
55
|
-
export declare function generateFlatOverride(override: Linter.ConfigOverride<Linter.RulesRecord
|
|
56
|
-
export declare function mapFilePaths(override: Linter.ConfigOverride<Linter.RulesRecord
|
|
57
|
-
export declare function mapFilePath(filePath: string, root: string): string;
|
|
55
|
+
export declare function generateFlatOverride(override: Linter.ConfigOverride<Linter.RulesRecord>): ts.ObjectLiteralExpression | ts.SpreadElement;
|
|
56
|
+
export declare function mapFilePaths(override: Linter.ConfigOverride<Linter.RulesRecord>): void;
|
|
58
57
|
/**
|
|
59
58
|
* Generates an AST from a JSON-type input
|
|
60
59
|
*/
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateAst = exports.
|
|
3
|
+
exports.generateAst = exports.mapFilePaths = exports.generateFlatOverride = exports.generateRequire = exports.stringifyNodeList = exports.generatePluginExtendsElement = exports.generateSpreadElement = exports.createNodeList = exports.addCompatToFlatConfig = exports.addPluginsToExportsBlock = exports.removeCompatExtends = exports.removePlugin = exports.addBlockToFlatConfigExport = exports.addImportToFlatConfig = exports.replaceOverride = exports.hasOverride = exports.removeOverridesFromLintConfig = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const ts = require("typescript");
|
|
6
|
+
const path_utils_1 = require("./path-utils");
|
|
6
7
|
/**
|
|
7
8
|
* Remove all overrides from the config file
|
|
8
9
|
*/
|
|
@@ -63,7 +64,7 @@ function hasOverride(content, lookup) {
|
|
|
63
64
|
// strip any spread elements
|
|
64
65
|
objSource = fullNodeText.replace(/\s*\.\.\.[a-zA-Z0-9_]+,?\n?/, '');
|
|
65
66
|
}
|
|
66
|
-
const data =
|
|
67
|
+
const data = (0, devkit_1.parseJson)(objSource
|
|
67
68
|
// ensure property names have double quotes so that JSON.parse works
|
|
68
69
|
.replace(/'/g, '"')
|
|
69
70
|
.replace(/\s([a-zA-Z0-9_]+)\s*:/g, ' "$1": '));
|
|
@@ -77,7 +78,7 @@ function hasOverride(content, lookup) {
|
|
|
77
78
|
exports.hasOverride = hasOverride;
|
|
78
79
|
const STRIP_SPREAD_ELEMENTS = /\s*\.\.\.[a-zA-Z0-9_]+,?\n?/g;
|
|
79
80
|
function parseTextToJson(text) {
|
|
80
|
-
return
|
|
81
|
+
return (0, devkit_1.parseJson)(text
|
|
81
82
|
// ensure property names have double quotes so that JSON.parse works
|
|
82
83
|
.replace(/'/g, '"')
|
|
83
84
|
.replace(/\s([a-zA-Z0-9_]+)\s*:/g, ' "$1": '));
|
|
@@ -118,7 +119,7 @@ function replaceOverride(content, root, lookup, update) {
|
|
|
118
119
|
length: end - start,
|
|
119
120
|
});
|
|
120
121
|
const updatedData = update(data);
|
|
121
|
-
mapFilePaths(updatedData
|
|
122
|
+
mapFilePaths(updatedData);
|
|
122
123
|
changes.push({
|
|
123
124
|
type: devkit_1.ChangeType.Insert,
|
|
124
125
|
index: start,
|
|
@@ -470,10 +471,15 @@ exports.generatePluginExtendsElement = generatePluginExtendsElement;
|
|
|
470
471
|
/**
|
|
471
472
|
* Stringifies TS nodes to file content string
|
|
472
473
|
*/
|
|
473
|
-
function stringifyNodeList(nodes
|
|
474
|
+
function stringifyNodeList(nodes) {
|
|
474
475
|
const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
|
|
475
|
-
const resultFile = ts.createSourceFile(
|
|
476
|
-
return printer
|
|
476
|
+
const resultFile = ts.createSourceFile('', '', ts.ScriptTarget.Latest, true, ts.ScriptKind.JS);
|
|
477
|
+
return (printer
|
|
478
|
+
.printList(ts.ListFormat.MultiLine, nodes, resultFile)
|
|
479
|
+
// add new line before compat initialization
|
|
480
|
+
.replace(/const compat = new FlatCompat/, '\nconst compat = new FlatCompat')
|
|
481
|
+
// add new line before module.exports = ...
|
|
482
|
+
.replace(/module\.exports/, '\nmodule.exports'));
|
|
477
483
|
}
|
|
478
484
|
exports.stringifyNodeList = stringifyNodeList;
|
|
479
485
|
/**
|
|
@@ -488,8 +494,8 @@ exports.generateRequire = generateRequire;
|
|
|
488
494
|
/**
|
|
489
495
|
* Generates AST object or spread element based on JSON override object
|
|
490
496
|
*/
|
|
491
|
-
function generateFlatOverride(override
|
|
492
|
-
mapFilePaths(override
|
|
497
|
+
function generateFlatOverride(override) {
|
|
498
|
+
mapFilePaths(override);
|
|
493
499
|
if (!override.env &&
|
|
494
500
|
!override.extends &&
|
|
495
501
|
!override.plugins &&
|
|
@@ -510,41 +516,21 @@ function generateFlatOverride(override, root) {
|
|
|
510
516
|
]));
|
|
511
517
|
}
|
|
512
518
|
exports.generateFlatOverride = generateFlatOverride;
|
|
513
|
-
function mapFilePaths(override
|
|
519
|
+
function mapFilePaths(override) {
|
|
514
520
|
if (override.files) {
|
|
515
521
|
override.files = Array.isArray(override.files)
|
|
516
522
|
? override.files
|
|
517
523
|
: [override.files];
|
|
518
|
-
override.files = override.files.map((file) =>
|
|
524
|
+
override.files = override.files.map((file) => (0, path_utils_1.mapFilePath)(file));
|
|
519
525
|
}
|
|
520
526
|
if (override.excludedFiles) {
|
|
521
527
|
override.excludedFiles = Array.isArray(override.excludedFiles)
|
|
522
528
|
? override.excludedFiles
|
|
523
529
|
: [override.excludedFiles];
|
|
524
|
-
override.excludedFiles = override.excludedFiles.map((file) =>
|
|
530
|
+
override.excludedFiles = override.excludedFiles.map((file) => (0, path_utils_1.mapFilePath)(file));
|
|
525
531
|
}
|
|
526
532
|
}
|
|
527
533
|
exports.mapFilePaths = mapFilePaths;
|
|
528
|
-
function mapFilePath(filePath, root) {
|
|
529
|
-
if (filePath.startsWith('!')) {
|
|
530
|
-
const fileWithoutBang = filePath.slice(1);
|
|
531
|
-
if (fileWithoutBang.startsWith('*.')) {
|
|
532
|
-
return `!${(0, devkit_1.joinPathFragments)(root, '**', fileWithoutBang)}`;
|
|
533
|
-
}
|
|
534
|
-
else if (!fileWithoutBang.startsWith(root)) {
|
|
535
|
-
return `!${(0, devkit_1.joinPathFragments)(root, fileWithoutBang)}`;
|
|
536
|
-
}
|
|
537
|
-
return filePath;
|
|
538
|
-
}
|
|
539
|
-
if (filePath.startsWith('*.')) {
|
|
540
|
-
return (0, devkit_1.joinPathFragments)(root, '**', filePath);
|
|
541
|
-
}
|
|
542
|
-
else if (!filePath.startsWith(root)) {
|
|
543
|
-
return (0, devkit_1.joinPathFragments)(root, filePath);
|
|
544
|
-
}
|
|
545
|
-
return filePath;
|
|
546
|
-
}
|
|
547
|
-
exports.mapFilePath = mapFilePath;
|
|
548
534
|
function addTSObjectProperty(elements, key, value) {
|
|
549
535
|
if (value) {
|
|
550
536
|
elements.push(ts.factory.createPropertyAssignment(key, generateAst(value)));
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import type { Linter } from 'eslint';
|
|
2
|
-
export declare function updateFiles(override: Linter.ConfigOverride<Linter.RulesRecord
|
|
2
|
+
export declare function updateFiles(override: Linter.ConfigOverride<Linter.RulesRecord>): Linter.ConfigOverride<Linter.RulesRecord>;
|
|
3
|
+
export declare function mapFilePath(filePath: string): string;
|
|
@@ -1,31 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.updateFiles = void 0;
|
|
3
|
+
exports.mapFilePath = exports.updateFiles = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
function updateFiles(override
|
|
5
|
+
function updateFiles(override) {
|
|
6
6
|
if (override.files) {
|
|
7
7
|
override.files = Array.isArray(override.files)
|
|
8
8
|
? override.files
|
|
9
9
|
: [override.files];
|
|
10
|
-
override.files = override.files.map((file) => mapFilePath(file
|
|
10
|
+
override.files = override.files.map((file) => mapFilePath(file));
|
|
11
11
|
}
|
|
12
12
|
return override;
|
|
13
13
|
}
|
|
14
14
|
exports.updateFiles = updateFiles;
|
|
15
|
-
function mapFilePath(filePath
|
|
15
|
+
function mapFilePath(filePath) {
|
|
16
16
|
if (filePath.startsWith('!')) {
|
|
17
17
|
const fileWithoutBang = filePath.slice(1);
|
|
18
18
|
if (fileWithoutBang.startsWith('*.')) {
|
|
19
|
-
return `!${(0, devkit_1.joinPathFragments)(
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
return `!${(0, devkit_1.joinPathFragments)(root, fileWithoutBang)}`;
|
|
19
|
+
return `!${(0, devkit_1.joinPathFragments)('**', fileWithoutBang)}`;
|
|
23
20
|
}
|
|
21
|
+
return filePath;
|
|
24
22
|
}
|
|
25
23
|
if (filePath.startsWith('*.')) {
|
|
26
|
-
return (0, devkit_1.joinPathFragments)(
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
return (0, devkit_1.joinPathFragments)(root, filePath);
|
|
24
|
+
return (0, devkit_1.joinPathFragments)('**', filePath);
|
|
30
25
|
}
|
|
26
|
+
return filePath;
|
|
31
27
|
}
|
|
28
|
+
exports.mapFilePath = mapFilePath;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const devkit_1 = require("@nx/devkit");
|
|
4
|
-
const eslint_file_1 = require("../../generators/utils/eslint-file");
|
|
5
4
|
const eslint_targets_1 = require("../../generators/utils/eslint-targets");
|
|
5
|
+
const config_file_1 = require("../../utils/config-file");
|
|
6
6
|
async function addEslintInputs(tree) {
|
|
7
7
|
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
8
|
-
const globalEslintFile =
|
|
8
|
+
const globalEslintFile = config_file_1.ESLINT_CONFIG_FILENAMES.find((file) => tree.exists(file));
|
|
9
9
|
if (globalEslintFile && nxJson.namedInputs?.production) {
|
|
10
10
|
const productionFileset = new Set(nxJson.namedInputs.production);
|
|
11
11
|
productionFileset.add(`!{projectRoot}/${globalEslintFile}`);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const devkit_1 = require("@nx/devkit");
|
|
4
|
-
const eslint_file_1 = require("../../generators/utils/eslint-file");
|
|
5
4
|
const eslint_targets_1 = require("../../generators/utils/eslint-targets");
|
|
5
|
+
const config_file_1 = require("../../utils/config-file");
|
|
6
6
|
async function addEslintIgnore(tree) {
|
|
7
7
|
const nxJson = (0, devkit_1.readJson)(tree, 'nx.json');
|
|
8
|
-
const globalEslintFile =
|
|
8
|
+
const globalEslintFile = config_file_1.ESLINT_CONFIG_FILENAMES.find((file) => tree.exists(file));
|
|
9
9
|
if (globalEslintFile) {
|
|
10
10
|
if (tree.exists('.eslintignore')) {
|
|
11
11
|
const content = tree.read('.eslintignore', 'utf-8');
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const devkit_1 = require("@nx/devkit");
|
|
4
|
+
async function update(tree) {
|
|
5
|
+
const projects = (0, devkit_1.getProjects)(tree);
|
|
6
|
+
for (const [projectName, projectConfiguration] of projects) {
|
|
7
|
+
let needsUpdate = false;
|
|
8
|
+
for (const [targetName, targetConfig] of Object.entries(projectConfiguration.targets ?? {})) {
|
|
9
|
+
if (targetConfig.executor !== '@nx/eslint:lint') {
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
needsUpdate = true;
|
|
13
|
+
if (projectConfiguration.targets[targetName].options?.lintFilePatterns) {
|
|
14
|
+
const rootPattern = getLintRoot(projectConfiguration);
|
|
15
|
+
const nonRootPatterns = projectConfiguration.targets[targetName].options.lintFilePatterns.filter((p) => !p.startsWith(rootPattern) && !p.startsWith('{projectRoot}'));
|
|
16
|
+
if (nonRootPatterns.length === 0 &&
|
|
17
|
+
rootPattern === projectConfiguration.root) {
|
|
18
|
+
// delete the lintFilePatterns option if it's the only option and matches the root of the project
|
|
19
|
+
delete projectConfiguration.targets[targetName].options
|
|
20
|
+
.lintFilePatterns;
|
|
21
|
+
if (Object.keys(projectConfiguration.targets[targetName].options)
|
|
22
|
+
.length === 0) {
|
|
23
|
+
delete projectConfiguration.targets[targetName].options;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
projectConfiguration.targets[targetName].options.lintFilePatterns = [
|
|
28
|
+
rootPattern,
|
|
29
|
+
...nonRootPatterns,
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (needsUpdate) {
|
|
35
|
+
(0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfiguration);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
39
|
+
}
|
|
40
|
+
exports.default = update;
|
|
41
|
+
function getLintRoot({ root, sourceRoot }) {
|
|
42
|
+
if (root === '' || root === '.') {
|
|
43
|
+
return sourceRoot || './src';
|
|
44
|
+
}
|
|
45
|
+
return root;
|
|
46
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createNodes = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const project_configuration_utils_1 = require("nx/src/project-graph/utils/project-configuration-utils");
|
|
6
|
+
const fs_1 = require("fs");
|
|
7
|
+
const globs_1 = require("nx/src/utils/globs");
|
|
8
|
+
const config_file_1 = require("../utils/config-file");
|
|
9
|
+
exports.createNodes = [
|
|
10
|
+
(0, globs_1.combineGlobPatterns)(['**/project.json', '**/package.json']),
|
|
11
|
+
(configFilePath, options, context) => {
|
|
12
|
+
const projectRoot = (0, path_1.dirname)(configFilePath);
|
|
13
|
+
options = normalizeOptions(options);
|
|
14
|
+
const eslintConfigs = getEslintConfigsForProject(projectRoot, context.workspaceRoot);
|
|
15
|
+
if (!eslintConfigs.length) {
|
|
16
|
+
return {};
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
projects: {
|
|
20
|
+
[projectRoot]: {
|
|
21
|
+
targets: buildEslintTargets(eslintConfigs, projectRoot, options, context),
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
];
|
|
27
|
+
function getEslintConfigsForProject(projectRoot, workspaceRoot) {
|
|
28
|
+
const detectedConfigs = new Set();
|
|
29
|
+
const baseConfig = (0, config_file_1.findBaseEslintFile)(workspaceRoot);
|
|
30
|
+
if (baseConfig) {
|
|
31
|
+
detectedConfigs.add(baseConfig);
|
|
32
|
+
}
|
|
33
|
+
let siblingFiles = (0, fs_1.readdirSync)((0, path_1.join)(workspaceRoot, projectRoot));
|
|
34
|
+
if (projectRoot === '.') {
|
|
35
|
+
// If there's no src folder, it's not a standalone project
|
|
36
|
+
if (!siblingFiles.includes('src')) {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
// If it's standalone but doesn't have eslint config, it's not a lintable
|
|
40
|
+
const config = siblingFiles.find((f) => config_file_1.ESLINT_CONFIG_FILENAMES.includes(f));
|
|
41
|
+
if (!config) {
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
detectedConfigs.add(config);
|
|
45
|
+
return Array.from(detectedConfigs);
|
|
46
|
+
}
|
|
47
|
+
while (projectRoot !== '.') {
|
|
48
|
+
// if it has an eslint config it's lintable
|
|
49
|
+
const config = siblingFiles.find((f) => config_file_1.ESLINT_CONFIG_FILENAMES.includes(f));
|
|
50
|
+
if (config) {
|
|
51
|
+
detectedConfigs.add(`${projectRoot}/${config}`);
|
|
52
|
+
return Array.from(detectedConfigs);
|
|
53
|
+
}
|
|
54
|
+
projectRoot = (0, path_1.dirname)(projectRoot);
|
|
55
|
+
siblingFiles = (0, fs_1.readdirSync)((0, path_1.join)(workspaceRoot, projectRoot));
|
|
56
|
+
}
|
|
57
|
+
// check whether the root has an eslint config
|
|
58
|
+
const config = (0, fs_1.readdirSync)(workspaceRoot).find((f) => config_file_1.ESLINT_CONFIG_FILENAMES.includes(f));
|
|
59
|
+
if (config) {
|
|
60
|
+
detectedConfigs.add(config);
|
|
61
|
+
return Array.from(detectedConfigs);
|
|
62
|
+
}
|
|
63
|
+
return [];
|
|
64
|
+
}
|
|
65
|
+
function buildEslintTargets(eslintConfigs, projectRoot, options, context) {
|
|
66
|
+
const targetDefaults = (0, project_configuration_utils_1.readTargetDefaultsForTarget)(options.targetName, context.nxJsonConfiguration.targetDefaults, '@nx/eslint:lint');
|
|
67
|
+
const isRootProject = projectRoot === '.';
|
|
68
|
+
const targets = {};
|
|
69
|
+
const baseTargetConfig = {
|
|
70
|
+
command: `eslint ${isRootProject ? './src' : '.'}`,
|
|
71
|
+
options: {
|
|
72
|
+
cwd: projectRoot,
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
if (eslintConfigs.some((config) => (0, config_file_1.isFlatConfig)(config))) {
|
|
76
|
+
baseTargetConfig.options.env = {
|
|
77
|
+
ESLINT_USE_FLAT_CONFIG: 'true',
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
targets[options.targetName] = {
|
|
81
|
+
...baseTargetConfig,
|
|
82
|
+
cache: targetDefaults?.cache ?? true,
|
|
83
|
+
inputs: targetDefaults?.inputs ?? [
|
|
84
|
+
'default',
|
|
85
|
+
...eslintConfigs.map((config) => `{workspaceRoot}/${config}`),
|
|
86
|
+
'{workspaceRoot}/tools/eslint-rules/**/*',
|
|
87
|
+
{ externalDependencies: ['eslint'] },
|
|
88
|
+
],
|
|
89
|
+
options: {
|
|
90
|
+
...baseTargetConfig.options,
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
return targets;
|
|
94
|
+
}
|
|
95
|
+
function normalizeOptions(options) {
|
|
96
|
+
options ??= {};
|
|
97
|
+
options.targetName ??= 'lint';
|
|
98
|
+
return options;
|
|
99
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const ESLINT_CONFIG_FILENAMES: string[];
|
|
2
|
+
export declare const baseEsLintConfigFile = ".eslintrc.base.json";
|
|
3
|
+
export declare const baseEsLintFlatConfigFile = "eslint.base.config.js";
|
|
4
|
+
export declare function findBaseEslintFile(workspaceRoot?: string): string | null;
|
|
5
|
+
export declare function isFlatConfig(configFilePath: string): boolean;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isFlatConfig = exports.findBaseEslintFile = exports.baseEsLintFlatConfigFile = exports.baseEsLintConfigFile = exports.ESLINT_CONFIG_FILENAMES = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
exports.ESLINT_CONFIG_FILENAMES = [
|
|
7
|
+
'.eslintrc',
|
|
8
|
+
'.eslintrc.js',
|
|
9
|
+
'.eslintrc.cjs',
|
|
10
|
+
'.eslintrc.yaml',
|
|
11
|
+
'.eslintrc.yml',
|
|
12
|
+
'.eslintrc.json',
|
|
13
|
+
'eslint.config.js',
|
|
14
|
+
];
|
|
15
|
+
exports.baseEsLintConfigFile = '.eslintrc.base.json';
|
|
16
|
+
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
|
+
function isFlatConfig(configFilePath) {
|
|
33
|
+
return configFilePath.endsWith('.config.js');
|
|
34
|
+
}
|
|
35
|
+
exports.isFlatConfig = isFlatConfig;
|
package/src/utils/versions.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const nxVersion: any;
|
|
2
|
-
export declare const eslintVersion = "~8.
|
|
2
|
+
export declare const eslintVersion = "~8.48.0";
|
|
3
3
|
export declare const eslintrcVersion = "^2.1.1";
|
|
4
4
|
export declare const eslintConfigPrettierVersion = "^9.0.0";
|
|
5
5
|
export declare const typescriptESLintVersion = "^6.9.1";
|
package/src/utils/versions.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.typescriptESLintVersion = exports.eslintConfigPrettierVersion = exports.eslintrcVersion = exports.eslintVersion = exports.nxVersion = void 0;
|
|
4
4
|
exports.nxVersion = require('../../package.json').version;
|
|
5
|
-
exports.eslintVersion = '~8.
|
|
5
|
+
exports.eslintVersion = '~8.48.0';
|
|
6
6
|
exports.eslintrcVersion = '^2.1.1';
|
|
7
7
|
exports.eslintConfigPrettierVersion = '^9.0.0';
|
|
8
8
|
exports.typescriptESLintVersion = '^6.9.1';
|