@nx/eslint 0.0.0-pr-31222-862e973 → 0.0.0-pr-31313-387cdca
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/LICENSE +1 -1
- package/README.md +1 -1
- package/migrations.json +69 -112
- package/package.json +6 -7
- package/src/executors/lint/utility/eslint-utils.js +6 -0
- package/src/generators/convert-to-flat-config/converters/json-converter.d.ts +1 -1
- package/src/generators/convert-to-flat-config/converters/json-converter.js +10 -18
- package/src/generators/convert-to-flat-config/generator.js +18 -17
- package/src/generators/convert-to-flat-config/schema.d.ts +2 -0
- package/src/generators/convert-to-inferred/convert-to-inferred.js +2 -1
- package/src/generators/init/global-eslint-config.d.ts +1 -1
- package/src/generators/init/global-eslint-config.js +17 -6
- package/src/generators/init/init-migration.d.ts +1 -1
- package/src/generators/init/init-migration.js +18 -13
- package/src/generators/init/init.d.ts +1 -0
- package/src/generators/init/init.js +31 -6
- package/src/generators/lint-project/lint-project.d.ts +1 -0
- package/src/generators/lint-project/lint-project.js +37 -15
- package/src/generators/lint-project/setup-root-eslint.d.ts +1 -0
- package/src/generators/lint-project/setup-root-eslint.js +2 -1
- package/src/generators/utils/eslint-file.d.ts +3 -2
- package/src/generators/utils/eslint-file.js +160 -28
- package/src/generators/utils/flat-config/ast-utils.d.ts +12 -4
- package/src/generators/utils/flat-config/ast-utils.js +412 -63
- package/src/generators/utils/linter.d.ts +3 -0
- package/src/generators/utils/linter.js +2 -2
- package/src/generators/workspace-rule/files/__name__.spec.ts__tmpl__ +11 -2
- package/src/generators/workspace-rule/workspace-rule.d.ts +2 -2
- package/src/generators/workspace-rule/workspace-rule.js +11 -3
- package/src/generators/workspace-rules-project/workspace-rules-project.js +4 -1
- package/src/migrations/update-20-2-0/update-typescript-eslint-v8-13-0.d.ts +2 -0
- package/src/migrations/update-20-2-0/update-typescript-eslint-v8-13-0.js +23 -0
- package/src/migrations/update-20-3-0/add-file-extensions-to-overrides.d.ts +2 -0
- package/src/migrations/update-20-3-0/add-file-extensions-to-overrides.js +49 -0
- package/src/plugins/plugin.js +21 -10
- package/src/utils/config-file.d.ts +3 -1
- package/src/utils/config-file.js +5 -2
- package/src/utils/flat-config.d.ts +1 -0
- package/src/utils/flat-config.js +9 -3
- package/src/utils/version-utils.d.ts +1 -0
- package/src/utils/version-utils.js +13 -9
- package/src/utils/versions.d.ts +3 -2
- package/src/utils/versions.js +4 -3
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +0 -2
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +0 -9
- package/src/migrations/update-16-8-0-add-ignored-files/update-16-8-0-add-ignored-files.d.ts +0 -2
- package/src/migrations/update-16-8-0-add-ignored-files/update-16-8-0-add-ignored-files.js +0 -44
- package/src/migrations/update-17-0-0-rename-to-eslint/update-17-0-0-rename-to-eslint.d.ts +0 -2
- package/src/migrations/update-17-0-0-rename-to-eslint/update-17-0-0-rename-to-eslint.js +0 -47
- package/src/migrations/update-17-1-0/update-typescript-eslint.d.ts +0 -2
- package/src/migrations/update-17-1-0/update-typescript-eslint.js +0 -74
- package/src/migrations/update-17-2-0/simplify-eslint-patterns.d.ts +0 -2
- package/src/migrations/update-17-2-0/simplify-eslint-patterns.js +0 -46
- package/src/migrations/update-17-2-9/move-options-to-target-defaults.d.ts +0 -2
- package/src/migrations/update-17-2-9/move-options-to-target-defaults.js +0 -107
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Linter = void 0;
|
|
4
|
-
|
|
5
|
-
* @deprecated Use LinterType instead
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated Use LinterType instead. It will be removed in Nx v22.
|
|
6
6
|
*/
|
|
7
7
|
var Linter;
|
|
8
8
|
(function (Linter) {
|
|
@@ -1,10 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
<% if (flatConfig) { %>import { RuleTester } from '@typescript-eslint/rule-tester';
|
|
2
|
+
import type { RuleTesterConfig } from '@typescript-eslint/rule-tester';
|
|
3
|
+
import { rule, RULE_NAME } from './<%= name %>';
|
|
4
|
+
|
|
5
|
+
const ruleTester = new RuleTester({
|
|
6
|
+
languageOptions: {
|
|
7
|
+
parser: require('@typescript-eslint/parser'),
|
|
8
|
+
},
|
|
9
|
+
} as RuleTesterConfig);
|
|
10
|
+
<% } else { %>import { TSESLint } from '@typescript-eslint/utils';
|
|
2
11
|
import { rule, RULE_NAME } from './<%= name %>';
|
|
3
12
|
|
|
4
13
|
const ruleTester = new TSESLint.RuleTester({
|
|
5
14
|
parser: require.resolve('@typescript-eslint/parser'),
|
|
6
15
|
});
|
|
7
|
-
|
|
16
|
+
<% } %>
|
|
8
17
|
ruleTester.run(RULE_NAME, rule, {
|
|
9
18
|
valid: [`const example = true;`],
|
|
10
19
|
invalid: [],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Tree } from '@nx/devkit';
|
|
1
|
+
import { GeneratorCallback, Tree } from '@nx/devkit';
|
|
2
2
|
export interface LintWorkspaceRuleGeneratorOptions {
|
|
3
3
|
name: string;
|
|
4
4
|
directory: string;
|
|
5
5
|
}
|
|
6
|
-
export declare function lintWorkspaceRuleGenerator(tree: Tree, options: LintWorkspaceRuleGeneratorOptions): Promise<
|
|
6
|
+
export declare function lintWorkspaceRuleGenerator(tree: Tree, options: LintWorkspaceRuleGeneratorOptions): Promise<GeneratorCallback>;
|
|
@@ -7,19 +7,27 @@ const path_1 = require("path");
|
|
|
7
7
|
const ts = require("typescript");
|
|
8
8
|
const workspace_lint_rules_1 = require("../../utils/workspace-lint-rules");
|
|
9
9
|
const workspace_rules_project_1 = require("../workspace-rules-project/workspace-rules-project");
|
|
10
|
+
const flat_config_1 = require("../../utils/flat-config");
|
|
11
|
+
const versions_1 = require("../../utils/versions");
|
|
10
12
|
async function lintWorkspaceRuleGenerator(tree, options) {
|
|
13
|
+
const tasks = [];
|
|
14
|
+
const flatConfig = (0, flat_config_1.useFlatConfig)(tree);
|
|
11
15
|
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
12
16
|
// Ensure that the workspace rules project has been created
|
|
13
|
-
|
|
17
|
+
tasks.push(await (0, workspace_rules_project_1.lintWorkspaceRulesProjectGenerator)(tree, {
|
|
14
18
|
skipFormat: true,
|
|
15
19
|
addPlugin: process.env.NX_ADD_PLUGINS !== 'false' &&
|
|
16
20
|
nxJson.useInferencePlugins !== false,
|
|
17
|
-
});
|
|
21
|
+
}));
|
|
22
|
+
if (flatConfig) {
|
|
23
|
+
tasks.push((0, devkit_1.addDependenciesToPackageJson)(tree, {}, { '@typescript-eslint/rule-tester': versions_1.eslint9__typescriptESLintVersion }));
|
|
24
|
+
}
|
|
18
25
|
const ruleDir = (0, devkit_1.joinPathFragments)(workspace_lint_rules_1.workspaceLintPluginDir, options.directory ?? '');
|
|
19
26
|
// Generate the required files for the new rule
|
|
20
27
|
(0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, 'files'), ruleDir, {
|
|
21
28
|
tmpl: '',
|
|
22
29
|
name: options.name,
|
|
30
|
+
flatConfig,
|
|
23
31
|
});
|
|
24
32
|
const nameCamelCase = (0, string_utils_1.camelize)(options.name);
|
|
25
33
|
/**
|
|
@@ -73,5 +81,5 @@ async function lintWorkspaceRuleGenerator(tree, options) {
|
|
|
73
81
|
"@nx/workspace-${options.name}": "error"
|
|
74
82
|
}
|
|
75
83
|
`);
|
|
76
|
-
return
|
|
84
|
+
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
77
85
|
}
|
|
@@ -5,6 +5,7 @@ exports.lintWorkspaceRulesProjectGenerator = lintWorkspaceRulesProjectGenerator;
|
|
|
5
5
|
const devkit_1 = require("@nx/devkit");
|
|
6
6
|
const js_1 = require("@nx/js");
|
|
7
7
|
const add_swc_dependencies_1 = require("@nx/js/src/utils/swc/add-swc-dependencies");
|
|
8
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
8
9
|
const path_1 = require("path");
|
|
9
10
|
const versions_1 = require("../../utils/versions");
|
|
10
11
|
const workspace_lint_rules_1 = require("../../utils/workspace-lint-rules");
|
|
@@ -47,11 +48,13 @@ async function lintWorkspaceRulesProjectGenerator(tree, options = {}) {
|
|
|
47
48
|
supportTsx: false,
|
|
48
49
|
skipSerializers: true,
|
|
49
50
|
setupFile: 'none',
|
|
50
|
-
compiler: 'tsc',
|
|
51
|
+
compiler: (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree) ? 'swc' : 'tsc',
|
|
51
52
|
skipFormat: true,
|
|
53
|
+
testEnvironment: 'node',
|
|
52
54
|
}));
|
|
53
55
|
(0, devkit_1.updateJson)(tree, (0, path_1.join)(workspace_lint_rules_1.workspaceLintPluginDir, 'tsconfig.spec.json'), (json) => {
|
|
54
56
|
delete json.compilerOptions?.module;
|
|
57
|
+
delete json.compilerOptions?.moduleResolution;
|
|
55
58
|
if (json.include) {
|
|
56
59
|
json.include = json.include.map((v) => {
|
|
57
60
|
if (v.startsWith('src/**')) {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = default_1;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const semver_1 = require("semver");
|
|
6
|
+
const version_utils_1 = require("../../utils/version-utils");
|
|
7
|
+
async function default_1(tree) {
|
|
8
|
+
const devDependencies = {};
|
|
9
|
+
const checkPackageAndMigrate = (pkgName) => {
|
|
10
|
+
const pkgVersion = (0, version_utils_1.getInstalledPackageVersion)(pkgName, tree);
|
|
11
|
+
if (!!pkgVersion && (0, semver_1.gte)(pkgVersion, '8.0.0') && (0, semver_1.lt)(pkgVersion, '8.13.0')) {
|
|
12
|
+
devDependencies[pkgName] = '^8.13.0';
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
checkPackageAndMigrate('typescript-eslint');
|
|
16
|
+
checkPackageAndMigrate('@typescript-eslint/eslint-plugin');
|
|
17
|
+
checkPackageAndMigrate('@typescript-eslint/parser');
|
|
18
|
+
checkPackageAndMigrate('@typescript-eslint/utils');
|
|
19
|
+
if (Object.keys(devDependencies).length > 0) {
|
|
20
|
+
return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, devDependencies);
|
|
21
|
+
}
|
|
22
|
+
return () => { };
|
|
23
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = default_1;
|
|
4
|
+
const ts = require("typescript");
|
|
5
|
+
const js_1 = require("@nx/js");
|
|
6
|
+
async function default_1(tree) {
|
|
7
|
+
let rootConfig;
|
|
8
|
+
// NOTE: we don't support generating ESM base config currently so they are not handled.
|
|
9
|
+
for (const candidate of ['eslint.config.js', 'eslint.config.cjs']) {
|
|
10
|
+
if (tree.exists(candidate)) {
|
|
11
|
+
rootConfig = candidate;
|
|
12
|
+
break;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
if (!rootConfig)
|
|
16
|
+
return;
|
|
17
|
+
updateOverrideFileExtensions(tree, rootConfig, 'plugin:@nx/typescript', [`'**/*.ts'`, `'**/*.tsx'`], [`'**/*.cts'`, `'**/*.mts'`]);
|
|
18
|
+
updateOverrideFileExtensions(tree, rootConfig, 'plugin:@nx/javascript', [`'**/*.js'`, `'**/*.jsx'`], [`'**/*.cjs'`, `'**/*.mjs'`]);
|
|
19
|
+
}
|
|
20
|
+
function updateOverrideFileExtensions(tree, configFile, plugin, matchingExts, newExts) {
|
|
21
|
+
const content = tree.read(configFile, 'utf-8');
|
|
22
|
+
const source = ts.createSourceFile('', content, ts.ScriptTarget.Latest, true, ts.ScriptKind.JS);
|
|
23
|
+
let compatNode;
|
|
24
|
+
const spreadElementNodes = (0, js_1.findNodes)(source, ts.SyntaxKind.SpreadElement);
|
|
25
|
+
for (const a of spreadElementNodes) {
|
|
26
|
+
const assignmentNodes = (0, js_1.findNodes)(a, ts.SyntaxKind.PropertyAssignment);
|
|
27
|
+
if (assignmentNodes.length === 0)
|
|
28
|
+
continue;
|
|
29
|
+
for (const b of assignmentNodes) {
|
|
30
|
+
if (b.name.getText() === 'extends' &&
|
|
31
|
+
b.initializer.getText().includes(plugin)) {
|
|
32
|
+
compatNode = a;
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (compatNode) {
|
|
38
|
+
const arrayNodes = (0, js_1.findNodes)(compatNode, ts.SyntaxKind.ArrayLiteralExpression);
|
|
39
|
+
for (const a of arrayNodes) {
|
|
40
|
+
if (matchingExts.every((ext) => a.elements.some((e) => e.getText() === ext))) {
|
|
41
|
+
const exts = new Set(a.elements.map((e) => e.getText()));
|
|
42
|
+
for (const ext of newExts) {
|
|
43
|
+
exts.add(ext);
|
|
44
|
+
}
|
|
45
|
+
(0, js_1.replaceChange)(tree, source, configFile, a.getStart(a.getSourceFile()), `[${Array.from(exts).join(', ')}]`, a.getText()).getText();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
package/src/plugins/plugin.js
CHANGED
|
@@ -13,7 +13,18 @@ const semver_1 = require("semver");
|
|
|
13
13
|
const config_file_1 = require("../utils/config-file");
|
|
14
14
|
const resolve_eslint_class_1 = require("../utils/resolve-eslint-class");
|
|
15
15
|
const pmc = (0, devkit_1.getPackageManagerCommand)();
|
|
16
|
-
const DEFAULT_EXTENSIONS = [
|
|
16
|
+
const DEFAULT_EXTENSIONS = [
|
|
17
|
+
'ts',
|
|
18
|
+
'cts',
|
|
19
|
+
'mts',
|
|
20
|
+
'tsx',
|
|
21
|
+
'js',
|
|
22
|
+
'cjs',
|
|
23
|
+
'mjs',
|
|
24
|
+
'jsx',
|
|
25
|
+
'html',
|
|
26
|
+
'vue',
|
|
27
|
+
];
|
|
17
28
|
const PROJECT_CONFIG_FILENAMES = ['project.json', 'package.json'];
|
|
18
29
|
const ESLINT_CONFIG_GLOB_V1 = (0, globs_1.combineGlobPatterns)(config_file_1.ESLINT_CONFIG_FILENAMES.map((f) => `**/${f}`));
|
|
19
30
|
const ESLINT_CONFIG_GLOB_V2 = (0, globs_1.combineGlobPatterns)([
|
|
@@ -96,7 +107,7 @@ const internalCreateNodes = async (configFilePath, options, context, projectsCac
|
|
|
96
107
|
projects,
|
|
97
108
|
};
|
|
98
109
|
};
|
|
99
|
-
const internalCreateNodesV2 = async (configFilePath, options, context,
|
|
110
|
+
const internalCreateNodesV2 = async (configFilePath, options, context, projectRootsByEslintRoots, lintableFilesPerProjectRoot, projectsCache, hashByRoot) => {
|
|
100
111
|
const configDir = (0, posix_1.dirname)(configFilePath);
|
|
101
112
|
const ESLint = await (0, resolve_eslint_class_1.resolveESLintClass)({
|
|
102
113
|
useFlatConfigOverrideVal: (0, config_file_1.isFlatConfig)(configFilePath),
|
|
@@ -104,12 +115,7 @@ const internalCreateNodesV2 = async (configFilePath, options, context, eslintCon
|
|
|
104
115
|
const eslintVersion = ESLint.version;
|
|
105
116
|
const projects = {};
|
|
106
117
|
await Promise.all(projectRootsByEslintRoots.get(configDir).map(async (projectRoot) => {
|
|
107
|
-
const
|
|
108
|
-
const hash = await (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options, {
|
|
109
|
-
configFiles: eslintConfigFiles,
|
|
110
|
-
nxJsonConfiguration: context.nxJsonConfiguration,
|
|
111
|
-
workspaceRoot: context.workspaceRoot,
|
|
112
|
-
}, [...parentConfigs, (0, posix_1.join)(projectRoot, '.eslintignore')]);
|
|
118
|
+
const hash = hashByRoot.get(projectRoot);
|
|
113
119
|
if (projectsCache[hash]) {
|
|
114
120
|
// We can reuse the projects in the cache.
|
|
115
121
|
Object.assign(projects, projectsCache[hash]);
|
|
@@ -154,8 +160,13 @@ exports.createNodesV2 = [
|
|
|
154
160
|
const targetsCache = readTargetsCache(cachePath);
|
|
155
161
|
const { eslintConfigFiles, projectRoots, projectRootsByEslintRoots } = splitConfigFiles(configFiles);
|
|
156
162
|
const lintableFilesPerProjectRoot = await collectLintableFilesByProjectRoot(projectRoots, options, context);
|
|
163
|
+
const hashes = await (0, calculate_hash_for_create_nodes_1.calculateHashesForCreateNodes)(projectRoots, options, context, projectRoots.map((root) => {
|
|
164
|
+
const parentConfigs = eslintConfigFiles.filter((eslintConfig) => isSubDir(root, (0, posix_1.dirname)(eslintConfig)));
|
|
165
|
+
return [...parentConfigs, (0, posix_1.join)(root, '.eslintignore')];
|
|
166
|
+
}));
|
|
167
|
+
const hashByRoot = new Map(projectRoots.map((r, i) => [r, hashes[i]]));
|
|
157
168
|
try {
|
|
158
|
-
return await (0, devkit_1.createNodesFromFiles)((configFile, options, context) => internalCreateNodesV2(configFile, options, context,
|
|
169
|
+
return await (0, devkit_1.createNodesFromFiles)((configFile, options, context) => internalCreateNodesV2(configFile, options, context, projectRootsByEslintRoots, lintableFilesPerProjectRoot, targetsCache, hashByRoot), eslintConfigFiles, options, context);
|
|
159
170
|
}
|
|
160
171
|
finally {
|
|
161
172
|
writeTargetsToCache(cachePath, targetsCache);
|
|
@@ -230,7 +241,7 @@ function getRootForDirectory(directory, roots) {
|
|
|
230
241
|
function getProjectUsingESLintConfig(configFilePath, projectRoot, eslintVersion, options, context) {
|
|
231
242
|
const rootEslintConfig = [
|
|
232
243
|
config_file_1.baseEsLintConfigFile,
|
|
233
|
-
config_file_1.
|
|
244
|
+
...config_file_1.BASE_ESLINT_CONFIG_FILENAMES,
|
|
234
245
|
...config_file_1.ESLINT_CONFIG_FILENAMES,
|
|
235
246
|
].find((f) => (0, node_fs_1.existsSync)((0, posix_1.join)(context.workspaceRoot, f)));
|
|
236
247
|
// Add a lint target for each child project without an eslint config, with the root level config as an input
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export declare const ESLINT_FLAT_CONFIG_FILENAMES: string[];
|
|
2
2
|
export declare const ESLINT_OLD_CONFIG_FILENAMES: string[];
|
|
3
3
|
export declare const ESLINT_CONFIG_FILENAMES: string[];
|
|
4
|
+
export declare const BASE_ESLINT_CONFIG_FILENAMES: string[];
|
|
4
5
|
export declare const baseEsLintConfigFile = ".eslintrc.base.json";
|
|
5
|
-
export declare const baseEsLintFlatConfigFile = "eslint.base.config.
|
|
6
|
+
export declare const baseEsLintFlatConfigFile = "eslint.base.config.mjs";
|
|
7
|
+
export declare const legacyBaseEsLintFlatConfigFile = "eslint.base.config.js";
|
|
6
8
|
export declare function isFlatConfig(configFilePath: string): boolean;
|
|
7
9
|
export declare function findFlatConfigFile(directory: string, workspaceRoot: string): string | null;
|
|
8
10
|
export declare function findOldConfigFile(filePathOrDirectory: string, workspaceRoot: string): string | null;
|
package/src/utils/config-file.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.baseEsLintFlatConfigFile = exports.baseEsLintConfigFile = exports.ESLINT_CONFIG_FILENAMES = exports.ESLINT_OLD_CONFIG_FILENAMES = exports.ESLINT_FLAT_CONFIG_FILENAMES = void 0;
|
|
3
|
+
exports.legacyBaseEsLintFlatConfigFile = exports.baseEsLintFlatConfigFile = exports.baseEsLintConfigFile = exports.BASE_ESLINT_CONFIG_FILENAMES = exports.ESLINT_CONFIG_FILENAMES = exports.ESLINT_OLD_CONFIG_FILENAMES = exports.ESLINT_FLAT_CONFIG_FILENAMES = void 0;
|
|
4
4
|
exports.isFlatConfig = isFlatConfig;
|
|
5
5
|
exports.findFlatConfigFile = findFlatConfigFile;
|
|
6
6
|
exports.findOldConfigFile = findOldConfigFile;
|
|
@@ -20,8 +20,11 @@ exports.ESLINT_CONFIG_FILENAMES = [
|
|
|
20
20
|
...exports.ESLINT_OLD_CONFIG_FILENAMES,
|
|
21
21
|
...exports.ESLINT_FLAT_CONFIG_FILENAMES,
|
|
22
22
|
];
|
|
23
|
+
exports.BASE_ESLINT_CONFIG_FILENAMES = flat_config_1.baseEslintConfigFilenames;
|
|
23
24
|
exports.baseEsLintConfigFile = '.eslintrc.base.json';
|
|
24
|
-
exports.baseEsLintFlatConfigFile = 'eslint.base.config.
|
|
25
|
+
exports.baseEsLintFlatConfigFile = 'eslint.base.config.mjs';
|
|
26
|
+
// Make sure we can handle previous file extension as well for migrations or custom generators.
|
|
27
|
+
exports.legacyBaseEsLintFlatConfigFile = 'eslint.base.config.js';
|
|
25
28
|
function isFlatConfig(configFilePath) {
|
|
26
29
|
const configFileName = (0, path_1.basename)(configFilePath);
|
|
27
30
|
return exports.ESLINT_FLAT_CONFIG_FILENAMES.includes(configFileName);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Tree } from '@nx/devkit';
|
|
2
2
|
export declare const eslintFlatConfigFilenames: string[];
|
|
3
|
+
export declare const baseEslintConfigFilenames: string[];
|
|
3
4
|
export declare function getRootESLintFlatConfigFilename(tree: Tree): string;
|
|
4
5
|
export declare function useFlatConfig(tree?: Tree): boolean;
|
package/src/utils/flat-config.js
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.eslintFlatConfigFilenames = void 0;
|
|
3
|
+
exports.baseEslintConfigFilenames = exports.eslintFlatConfigFilenames = void 0;
|
|
4
4
|
exports.getRootESLintFlatConfigFilename = getRootESLintFlatConfigFilename;
|
|
5
5
|
exports.useFlatConfig = useFlatConfig;
|
|
6
6
|
const semver_1 = require("semver");
|
|
7
|
-
// todo: add support for eslint.config.mjs,
|
|
8
7
|
exports.eslintFlatConfigFilenames = [
|
|
9
|
-
'eslint.config.js',
|
|
10
8
|
'eslint.config.cjs',
|
|
9
|
+
'eslint.config.js',
|
|
10
|
+
'eslint.config.mjs',
|
|
11
|
+
];
|
|
12
|
+
exports.baseEslintConfigFilenames = [
|
|
13
|
+
'eslint.base.js',
|
|
14
|
+
'eslint.base.config.cjs',
|
|
15
|
+
'eslint.base.config.js',
|
|
16
|
+
'eslint.base.config.mjs',
|
|
11
17
|
];
|
|
12
18
|
function getRootESLintFlatConfigFilename(tree) {
|
|
13
19
|
for (const file of exports.eslintFlatConfigFilenames) {
|
|
@@ -1,31 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getInstalledPackageVersion = getInstalledPackageVersion;
|
|
3
4
|
exports.getInstalledEslintVersion = getInstalledEslintVersion;
|
|
4
5
|
const devkit_1 = require("@nx/devkit");
|
|
5
6
|
const semver_1 = require("@nx/devkit/src/utils/semver");
|
|
6
7
|
const devkit_internals_1 = require("nx/src/devkit-internals");
|
|
7
|
-
function
|
|
8
|
+
function getInstalledPackageVersion(pkgName, tree) {
|
|
8
9
|
try {
|
|
9
|
-
const
|
|
10
|
-
return
|
|
10
|
+
const packageJson = (0, devkit_internals_1.readModulePackageJson)(pkgName).packageJson;
|
|
11
|
+
return packageJson.version;
|
|
11
12
|
}
|
|
12
13
|
catch { }
|
|
13
|
-
//
|
|
14
|
+
// the package is not installed on disk, it could be in the package.json
|
|
14
15
|
// but waiting to be installed
|
|
15
16
|
const rootPackageJson = tree
|
|
16
17
|
? (0, devkit_1.readJson)(tree, 'package.json')
|
|
17
18
|
: (0, devkit_1.readJsonFile)('package.json');
|
|
18
|
-
const
|
|
19
|
-
rootPackageJson.dependencies?.[
|
|
20
|
-
if (!
|
|
21
|
-
//
|
|
19
|
+
const pkgVersionInRootPackageJson = rootPackageJson.devDependencies?.[pkgName] ??
|
|
20
|
+
rootPackageJson.dependencies?.[pkgName];
|
|
21
|
+
if (!pkgVersionInRootPackageJson) {
|
|
22
|
+
// the package is not installed
|
|
22
23
|
return null;
|
|
23
24
|
}
|
|
24
25
|
try {
|
|
25
26
|
// try to parse and return the version
|
|
26
|
-
return (0, semver_1.checkAndCleanWithSemver)(
|
|
27
|
+
return (0, semver_1.checkAndCleanWithSemver)(pkgName, pkgVersionInRootPackageJson);
|
|
27
28
|
}
|
|
28
29
|
catch { }
|
|
29
30
|
// we could not resolve the version
|
|
30
31
|
return null;
|
|
31
32
|
}
|
|
33
|
+
function getInstalledEslintVersion(tree) {
|
|
34
|
+
return getInstalledPackageVersion('eslint', tree);
|
|
35
|
+
}
|
package/src/utils/versions.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export declare const nxVersion: any;
|
|
2
2
|
export declare const eslintVersion = "~8.57.0";
|
|
3
3
|
export declare const eslintrcVersion = "^2.1.1";
|
|
4
|
-
export declare const eslintConfigPrettierVersion = "^
|
|
4
|
+
export declare const eslintConfigPrettierVersion = "^10.0.0";
|
|
5
5
|
export declare const typescriptESLintVersion = "^7.16.0";
|
|
6
|
-
export declare const
|
|
6
|
+
export declare const jsoncEslintParserVersion = "^2.1.0";
|
|
7
|
+
export declare const eslint9__typescriptESLintVersion = "^8.19.0";
|
|
7
8
|
export declare const eslint9__eslintVersion = "^9.8.0";
|
|
8
9
|
export declare const eslintCompat = "^1.1.1";
|
package/src/utils/versions.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.eslintCompat = exports.eslint9__eslintVersion = exports.eslint9__typescriptESLintVersion = exports.typescriptESLintVersion = exports.eslintConfigPrettierVersion = exports.eslintrcVersion = exports.eslintVersion = exports.nxVersion = void 0;
|
|
3
|
+
exports.eslintCompat = exports.eslint9__eslintVersion = exports.eslint9__typescriptESLintVersion = exports.jsoncEslintParserVersion = exports.typescriptESLintVersion = exports.eslintConfigPrettierVersion = exports.eslintrcVersion = exports.eslintVersion = exports.nxVersion = void 0;
|
|
4
4
|
exports.nxVersion = require('../../package.json').version;
|
|
5
5
|
exports.eslintVersion = '~8.57.0';
|
|
6
6
|
exports.eslintrcVersion = '^2.1.1';
|
|
7
|
-
exports.eslintConfigPrettierVersion = '^
|
|
7
|
+
exports.eslintConfigPrettierVersion = '^10.0.0';
|
|
8
8
|
exports.typescriptESLintVersion = '^7.16.0';
|
|
9
|
+
exports.jsoncEslintParserVersion = '^2.1.0';
|
|
9
10
|
// Updated linting stack for ESLint v9, typescript-eslint v8
|
|
10
|
-
exports.eslint9__typescriptESLintVersion = '^8.
|
|
11
|
+
exports.eslint9__typescriptESLintVersion = '^8.19.0';
|
|
11
12
|
exports.eslint9__eslintVersion = '^9.8.0';
|
|
12
13
|
exports.eslintCompat = '^1.1.1';
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = replacePackage;
|
|
4
|
-
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const replace_package_1 = require("@nx/devkit/src/utils/replace-package");
|
|
6
|
-
async function replacePackage(tree) {
|
|
7
|
-
await (0, replace_package_1.replaceNrwlPackageWithNxPackage)(tree, '@nrwl/linter', '@nx/linter');
|
|
8
|
-
await (0, devkit_1.formatFiles)(tree);
|
|
9
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = update;
|
|
4
|
-
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
|
|
6
|
-
const eslint_file_1 = require("../../generators/utils/eslint-file");
|
|
7
|
-
// Add `ignoredFiles` pattern to projects using vite, esbuild, and rollup.
|
|
8
|
-
// This is needed because the @nx/dependency-checks lint rule will complain
|
|
9
|
-
// about dependencies used in build config files, even though they are not
|
|
10
|
-
// production dependencies.
|
|
11
|
-
function update(tree) {
|
|
12
|
-
const projects = (0, devkit_1.getProjects)(tree);
|
|
13
|
-
const addIgnorePattern = (ignorePattern) => (_options, projectName) => {
|
|
14
|
-
const project = projects.get(projectName);
|
|
15
|
-
if (!(0, eslint_file_1.findEslintFile)(tree, project.root) ||
|
|
16
|
-
!(0, eslint_file_1.isEslintConfigSupported)(tree)) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
if ((0, eslint_file_1.lintConfigHasOverride)(tree, project.root, (o) => Array.isArray(o.files)
|
|
20
|
-
? o.files.some((f) => f.match(/\.json$/))
|
|
21
|
-
: !!o.files?.match(/\.json$/), true)) {
|
|
22
|
-
(0, eslint_file_1.updateOverrideInLintConfig)(tree, project.root, (o) => !!o.rules?.['@nx/dependency-checks'], (o) => {
|
|
23
|
-
const value = o.rules['@nx/dependency-checks'];
|
|
24
|
-
let ruleSeverity;
|
|
25
|
-
let ruleOptions;
|
|
26
|
-
if (Array.isArray(value)) {
|
|
27
|
-
ruleSeverity = value[0];
|
|
28
|
-
ruleOptions = value[1];
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
ruleSeverity = value;
|
|
32
|
-
ruleOptions = {};
|
|
33
|
-
}
|
|
34
|
-
ruleOptions.ignoredFiles = [ignorePattern];
|
|
35
|
-
o.rules['@nx/dependency-checks'] = [ruleSeverity, ruleOptions];
|
|
36
|
-
return o;
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
(0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/vite:build', addIgnorePattern('{projectRoot}/vite.config.{js,ts,mjs,mts}'));
|
|
41
|
-
(0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/vite:test', addIgnorePattern('{projectRoot}/vite.config.{js,ts,mjs,mts}'));
|
|
42
|
-
(0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/esbuild:esbuild', addIgnorePattern('{projectRoot}/esbuild.config.{js,ts,mjs,mts}'));
|
|
43
|
-
(0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/rollup:rollup', addIgnorePattern('{projectRoot}/rollup.config.{js,ts,mjs,mts}'));
|
|
44
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = replacePackage;
|
|
4
|
-
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const replace_package_1 = require("@nx/devkit/src/utils/replace-package");
|
|
6
|
-
async function replacePackage(tree) {
|
|
7
|
-
await (0, replace_package_1.replaceNrwlPackageWithNxPackage)(tree, '@nx/linter', '@nx/eslint');
|
|
8
|
-
// executor name change from :eslint to :lint
|
|
9
|
-
updateNxJsonExecutor(tree);
|
|
10
|
-
updateProjectExecutor(tree);
|
|
11
|
-
await (0, devkit_1.formatFiles)(tree);
|
|
12
|
-
}
|
|
13
|
-
function updateNxJsonExecutor(tree) {
|
|
14
|
-
if (!tree.exists('nx.json')) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
18
|
-
let needsUpdate = false;
|
|
19
|
-
for (const [targetName, targetConfig] of Object.entries(nxJson.targetDefaults ?? {})) {
|
|
20
|
-
// this will be in a broken state after the package is globally renamed
|
|
21
|
-
if (targetConfig.executor !== '@nx/eslint:eslint') {
|
|
22
|
-
continue;
|
|
23
|
-
}
|
|
24
|
-
needsUpdate = true;
|
|
25
|
-
nxJson.targetDefaults[targetName].executor = '@nx/eslint:lint';
|
|
26
|
-
}
|
|
27
|
-
if (needsUpdate) {
|
|
28
|
-
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
function updateProjectExecutor(tree) {
|
|
32
|
-
const projects = (0, devkit_1.getProjects)(tree);
|
|
33
|
-
for (const [projectName, projectConfiguration] of projects) {
|
|
34
|
-
let needsUpdate = false;
|
|
35
|
-
for (const [targetName, targetConfig] of Object.entries(projectConfiguration.targets ?? {})) {
|
|
36
|
-
// this will be in a broken state after the package is globally renamed
|
|
37
|
-
if (targetConfig.executor !== '@nx/eslint:eslint') {
|
|
38
|
-
continue;
|
|
39
|
-
}
|
|
40
|
-
needsUpdate = true;
|
|
41
|
-
projectConfiguration.targets[targetName].executor = '@nx/eslint:lint';
|
|
42
|
-
}
|
|
43
|
-
if (needsUpdate) {
|
|
44
|
-
(0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfiguration);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = update;
|
|
4
|
-
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const versions_1 = require("../../utils/versions");
|
|
6
|
-
const path_1 = require("path");
|
|
7
|
-
const typescript_1 = require("typescript");
|
|
8
|
-
function updateJestConfig(tree) {
|
|
9
|
-
const jestConfigPath = 'tools/eslint-rules/jest.config.ts';
|
|
10
|
-
if (tree.exists(jestConfigPath)) {
|
|
11
|
-
const { removePropertyFromJestConfig } = (0, devkit_1.ensurePackage)('@nx/jest', versions_1.nxVersion);
|
|
12
|
-
removePropertyFromJestConfig(tree, jestConfigPath, [
|
|
13
|
-
'moduleNameMapper',
|
|
14
|
-
'@eslint/eslintrc',
|
|
15
|
-
]);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
function updateTsConfigs(tree) {
|
|
19
|
-
const tsConfigPath = 'tools/eslint-rules/tsconfig.json';
|
|
20
|
-
if (tree.exists(tsConfigPath)) {
|
|
21
|
-
(0, devkit_1.updateJson)(tree, tsConfigPath, (tsConfig) => {
|
|
22
|
-
tsConfig.compilerOptions ??= {};
|
|
23
|
-
tsConfig.compilerOptions.moduleResolution = 'node16';
|
|
24
|
-
tsConfig.compilerOptions.module = 'node16';
|
|
25
|
-
return tsConfig;
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
const tsConfigSpec = 'tools/eslint-rules/tsconfig.spec.json';
|
|
29
|
-
if (tree.exists(tsConfigSpec)) {
|
|
30
|
-
(0, devkit_1.updateJson)(tree, tsConfigSpec, (tsConfigSpec) => {
|
|
31
|
-
delete tsConfigSpec.compilerOptions?.module;
|
|
32
|
-
delete tsConfigSpec.compilerOptions?.moduleResolution;
|
|
33
|
-
return tsConfigSpec;
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
function updateRecommended(tree) {
|
|
38
|
-
(0, devkit_1.visitNotIgnoredFiles)(tree, 'tools/eslint-rules', (path) => {
|
|
39
|
-
if ((0, path_1.extname)(path) !== '.ts') {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
const contents = tree.read(path, 'utf-8');
|
|
43
|
-
const sourceFile = (0, typescript_1.createSourceFile)(path, contents, typescript_1.ScriptTarget.ESNext, true);
|
|
44
|
-
const changes = [];
|
|
45
|
-
const visit = (node) => {
|
|
46
|
-
if ((0, typescript_1.isPropertyAssignment)(node) &&
|
|
47
|
-
(0, typescript_1.isIdentifier)(node.name) &&
|
|
48
|
-
node.name.text === 'recommended' &&
|
|
49
|
-
(0, typescript_1.isStringLiteral)(node.initializer)) {
|
|
50
|
-
changes.push({
|
|
51
|
-
type: devkit_1.ChangeType.Delete,
|
|
52
|
-
start: node.initializer.getStart(sourceFile),
|
|
53
|
-
length: node.initializer.getWidth(sourceFile),
|
|
54
|
-
});
|
|
55
|
-
changes.push({
|
|
56
|
-
type: devkit_1.ChangeType.Insert,
|
|
57
|
-
index: node.initializer.getStart(sourceFile),
|
|
58
|
-
text: "'recommended'",
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
(0, typescript_1.forEachChild)(node, visit);
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
(0, typescript_1.forEachChild)(sourceFile, visit);
|
|
66
|
-
tree.write(path, (0, devkit_1.applyChangesToString)(contents, changes));
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
async function update(tree) {
|
|
70
|
-
updateJestConfig(tree);
|
|
71
|
-
updateTsConfigs(tree);
|
|
72
|
-
updateRecommended(tree);
|
|
73
|
-
await (0, devkit_1.formatFiles)(tree);
|
|
74
|
-
}
|