@nx/eslint 17.1.0-beta.2 → 17.1.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/eslint",
3
- "version": "17.1.0-beta.2",
3
+ "version": "17.1.0-beta.4",
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": {
@@ -34,10 +34,10 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "tslib": "^2.3.0",
37
- "@nx/devkit": "17.1.0-beta.2",
38
- "@nx/js": "17.1.0-beta.2",
39
- "typescript": "~5.1.3",
40
- "@nx/linter": "17.1.0-beta.2"
37
+ "@nx/devkit": "17.1.0-beta.4",
38
+ "@nx/js": "17.1.0-beta.4",
39
+ "typescript": "~5.2.2",
40
+ "@nx/linter": "17.1.0-beta.4"
41
41
  },
42
42
  "peerDependenciesMeta": {
43
43
  "eslint": {
@@ -34,10 +34,6 @@ async function run(options, context) {
34
34
  * their root ESLint config to use eslint.config.js
35
35
  */
36
36
  const hasFlatConfig = (0, fs_1.existsSync)((0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, 'eslint.config.js'));
37
- if (!eslintConfigPath && hasFlatConfig) {
38
- const projectRoot = context.projectsConfigurations.projects[context.projectName].root;
39
- eslintConfigPath = (0, devkit_1.joinPathFragments)(projectRoot, 'eslint.config.js');
40
- }
41
37
  const { eslint, ESLint } = await (0, eslint_utils_1.resolveAndInstantiateESLint)(eslintConfigPath, normalizedOptions, hasFlatConfig);
42
38
  const version = ESLint.version?.split('.');
43
39
  if (!version ||
@@ -3,4 +3,4 @@ import { Tree } from '@nx/devkit';
3
3
  * Converts an ESLint JSON config to a flat config.
4
4
  * Deletes the original file along with .eslintignore if it exists.
5
5
  */
6
- export declare function convertEslintJsonToFlatConfig(tree: Tree, root: string, sourceFile: string, destinationFile: string): void;
6
+ export declare function convertEslintJsonToFlatConfig(tree: Tree, root: string, sourceFile: string, destinationFile: string, ignorePaths: string[]): void;
@@ -11,7 +11,7 @@ const eslint_file_1 = require("../../utils/eslint-file");
11
11
  * Converts an ESLint JSON config to a flat config.
12
12
  * Deletes the original file along with .eslintignore if it exists.
13
13
  */
14
- function convertEslintJsonToFlatConfig(tree, root, sourceFile, destinationFile) {
14
+ function convertEslintJsonToFlatConfig(tree, root, sourceFile, destinationFile, ignorePaths) {
15
15
  const importsMap = new Map();
16
16
  const exportElements = [];
17
17
  let isFlatCompatNeeded = false;
@@ -83,18 +83,19 @@ function convertEslintJsonToFlatConfig(tree, root, sourceFile, destinationFile)
83
83
  }));
84
84
  }
85
85
  }
86
- if (tree.exists(`${root}/.eslintignore`)) {
87
- const patterns = tree
88
- .read(`${root}/.eslintignore`, 'utf-8')
89
- .split('\n')
90
- .filter((line) => line.length > 0 && line !== 'node_modules')
91
- .map((path) => (0, ast_utils_1.mapFilePath)(path, root));
92
- if (patterns.length > 0) {
93
- exportElements.push((0, ast_utils_1.generateAst)({ ignores: patterns }));
86
+ for (const ignorePath of ignorePaths) {
87
+ if (tree.exists(ignorePath)) {
88
+ const patterns = tree
89
+ .read(ignorePath, 'utf-8')
90
+ .split('\n')
91
+ .filter((line) => line.length > 0 && line !== 'node_modules')
92
+ .map((path) => (0, ast_utils_1.mapFilePath)(path, root));
93
+ if (patterns.length > 0) {
94
+ exportElements.push((0, ast_utils_1.generateAst)({ ignores: patterns }));
95
+ }
94
96
  }
95
97
  }
96
98
  tree.delete((0, path_1.join)(root, sourceFile));
97
- tree.delete((0, path_1.join)(root, '.eslintignore'));
98
99
  // create the node list and print it to new file
99
100
  const nodeList = (0, ast_utils_1.createNodeList)(importsMap, exportElements, isFlatCompatNeeded);
100
101
  const content = (0, ast_utils_1.stringifyNodeList)(nodeList, root, destinationFile);
@@ -12,12 +12,17 @@ async function convertToFlatConfigGenerator(tree, options) {
12
12
  if (!eslintFile.endsWith('.json')) {
13
13
  throw new Error('Only json eslint config files are supported for conversion');
14
14
  }
15
- // rename root eslint config to eslint.config.js
15
+ const eslintIgnoreFiles = new Set(['.eslintignore']);
16
+ // convert root eslint config to eslint.config.js
16
17
  convertRootToFlatConfig(tree, eslintFile);
17
- // rename and map files
18
+ // convert project eslint files to eslint.config.js
18
19
  const projects = (0, devkit_1.getProjects)(tree);
19
20
  for (const [project, projectConfig] of projects) {
20
- convertProjectToFlatConfig(tree, project, projectConfig, (0, devkit_1.readNxJson)(tree));
21
+ convertProjectToFlatConfig(tree, project, projectConfig, (0, devkit_1.readNxJson)(tree), eslintIgnoreFiles);
22
+ }
23
+ // delete all .eslintignore files
24
+ for (const ignoreFile of eslintIgnoreFiles) {
25
+ tree.delete(ignoreFile);
21
26
  }
22
27
  // replace references in nx.json
23
28
  updateNxJsonConfig(tree);
@@ -34,22 +39,31 @@ function convertRootToFlatConfig(tree, eslintFile) {
34
39
  }
35
40
  convertConfigToFlatConfig(tree, '', '.eslintrc.json', 'eslint.config.js');
36
41
  }
37
- function convertProjectToFlatConfig(tree, project, projectConfig, nxJson) {
42
+ function convertProjectToFlatConfig(tree, project, projectConfig, nxJson, eslintIgnoreFiles) {
38
43
  if (tree.exists(`${projectConfig.root}/.eslintrc.json`)) {
39
44
  if (projectConfig.targets) {
40
45
  const eslintTargets = Object.keys(projectConfig.targets || {}).filter((t) => projectConfig.targets[t].executor === '@nx/eslint:lint');
46
+ let ignorePath;
41
47
  for (const target of eslintTargets) {
42
48
  // remove any obsolete `eslintConfig` options pointing to the old config file
43
49
  if (projectConfig.targets[target].options?.eslintConfig) {
44
50
  delete projectConfig.targets[target].options.eslintConfig;
45
51
  }
52
+ if (projectConfig.targets[target].options?.ignorePath) {
53
+ ignorePath = projectConfig.targets[target].options.ignorePath;
54
+ delete projectConfig.targets[target].options.ignorePath;
55
+ }
46
56
  (0, devkit_1.updateProjectConfiguration)(tree, project, projectConfig);
47
57
  }
48
58
  const nxHasLintTargets = Object.keys(nxJson.targetDefaults || {}).some((t) => (t === '@nx/eslint:lint' ||
49
59
  nxJson.targetDefaults[t].executor === '@nx/eslint:lint') &&
50
60
  projectConfig.targets?.[t]);
51
61
  if (nxHasLintTargets || eslintTargets.length > 0) {
52
- convertConfigToFlatConfig(tree, projectConfig.root, '.eslintrc.json', 'eslint.config.js');
62
+ convertConfigToFlatConfig(tree, projectConfig.root, '.eslintrc.json', 'eslint.config.js', ignorePath);
63
+ eslintIgnoreFiles.add(`${projectConfig.root}/.eslintignore`);
64
+ if (ignorePath) {
65
+ eslintIgnoreFiles.add(ignorePath);
66
+ }
53
67
  }
54
68
  }
55
69
  }
@@ -78,6 +92,9 @@ function updateNxJsonConfig(tree) {
78
92
  });
79
93
  }
80
94
  }
81
- function convertConfigToFlatConfig(tree, root, source, target) {
82
- (0, json_converter_1.convertEslintJsonToFlatConfig)(tree, root, source, target);
95
+ function convertConfigToFlatConfig(tree, root, source, target, ignorePath) {
96
+ const ignorePaths = ignorePath
97
+ ? [ignorePath, `${root}/.eslintignore`]
98
+ : [`${root}/.eslintignore`];
99
+ (0, json_converter_1.convertEslintJsonToFlatConfig)(tree, root, source, target, ignorePaths);
83
100
  }