@nx/eslint 19.1.1 → 19.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/eslint",
3
- "version": "19.1.1",
3
+ "version": "19.1.2",
4
4
  "private": false,
5
5
  "description": "The ESLint plugin for Nx contains executors, generators and utilities used for linting JavaScript/TypeScript projects within an Nx workspace.",
6
6
  "repository": {
@@ -35,12 +35,12 @@
35
35
  "eslint": "^8.0.0 || ^9.0.0"
36
36
  },
37
37
  "dependencies": {
38
- "@nx/devkit": "19.1.1",
39
- "@nx/js": "19.1.1",
38
+ "@nx/devkit": "19.1.2",
39
+ "@nx/js": "19.1.2",
40
40
  "semver": "^7.5.3",
41
41
  "tslib": "^2.3.0",
42
42
  "typescript": "~5.4.2",
43
- "@nx/linter": "19.1.1"
43
+ "@nx/linter": "19.1.2"
44
44
  },
45
45
  "peerDependenciesMeta": {
46
46
  "@zkochan/js-yaml": {
@@ -1,4 +1,4 @@
1
- import { Tree } from '@nx/devkit';
1
+ import { GeneratorCallback, Tree } from '@nx/devkit';
2
2
  import { ConvertToFlatConfigGeneratorSchema } from './schema';
3
- export declare function convertToFlatConfigGenerator(tree: Tree, options: ConvertToFlatConfigGeneratorSchema): Promise<void>;
3
+ export declare function convertToFlatConfigGenerator(tree: Tree, options: ConvertToFlatConfigGeneratorSchema): Promise<void | GeneratorCallback>;
4
4
  export default convertToFlatConfigGenerator;
@@ -6,6 +6,7 @@ const eslint_file_1 = require("../utils/eslint-file");
6
6
  const path_1 = require("path");
7
7
  const versions_1 = require("../../utils/versions");
8
8
  const json_converter_1 = require("./converters/json-converter");
9
+ let shouldInstallDeps = false;
9
10
  async function convertToFlatConfigGenerator(tree, options) {
10
11
  const eslintFile = (0, eslint_file_1.findEslintFile)(tree);
11
12
  if (!eslintFile) {
@@ -32,6 +33,9 @@ async function convertToFlatConfigGenerator(tree, options) {
32
33
  if (!options.skipFormat) {
33
34
  await (0, devkit_1.formatFiles)(tree);
34
35
  }
36
+ if (shouldInstallDeps) {
37
+ return () => (0, devkit_1.installPackagesTask)(tree);
38
+ }
35
39
  }
36
40
  exports.convertToFlatConfigGenerator = convertToFlatConfigGenerator;
37
41
  exports.default = convertToFlatConfigGenerator;
@@ -127,11 +131,13 @@ function processConvertedConfig(tree, root, source, target, { content, addESLint
127
131
  tree.write((0, path_1.join)(root, target), content);
128
132
  // add missing packages
129
133
  if (addESLintRC) {
134
+ shouldInstallDeps = true;
130
135
  (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
131
136
  '@eslint/eslintrc': versions_1.eslintrcVersion,
132
137
  });
133
138
  }
134
139
  if (addESLintJS) {
140
+ shouldInstallDeps = true;
135
141
  (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
136
142
  '@eslint/js': versions_1.eslintVersion,
137
143
  });
@@ -21,14 +21,14 @@ async function convertToInferred(tree, options) {
21
21
  exports.convertToInferred = convertToInferred;
22
22
  function postTargetTransformer(target, tree, projectDetails) {
23
23
  if (target.inputs) {
24
- target.inputs = target.inputs.filter((input) => typeof input === 'string' &&
24
+ const inputs = target.inputs.filter((input) => typeof input === 'string' &&
25
25
  ![
26
26
  'default',
27
27
  '{workspaceRoot}/.eslintrc.json',
28
28
  '{workspaceRoot}/.eslintignore',
29
29
  '{workspaceRoot}/eslint.config.js',
30
30
  ].includes(input));
31
- if (target.inputs.length === 0) {
31
+ if (inputs.length === 0) {
32
32
  delete target.inputs;
33
33
  }
34
34
  }
@@ -76,11 +76,17 @@ function getProjectsUsingESLintConfig(configFilePath, childProjectRoots, eslintV
76
76
  ].find((f) => (0, node_fs_1.existsSync)((0, node_path_1.join)(context.workspaceRoot, f)));
77
77
  // Add a lint target for each child project without an eslint config, with the root level config as an input
78
78
  for (const projectRoot of childProjectRoots) {
79
- // If there's no src folder, it's not a standalone project, do not add the target at all
80
- const isStandaloneWorkspace = projectRoot === '.' &&
81
- (0, node_fs_1.existsSync)((0, node_path_1.join)(context.workspaceRoot, projectRoot, 'src')) &&
82
- (0, node_fs_1.existsSync)((0, node_path_1.join)(context.workspaceRoot, projectRoot, 'package.json'));
83
- if (projectRoot === '.' && !isStandaloneWorkspace) {
79
+ let standaloneSrcPath;
80
+ if (projectRoot === '.' &&
81
+ (0, node_fs_1.existsSync)((0, node_path_1.join)(context.workspaceRoot, projectRoot, 'package.json'))) {
82
+ if ((0, node_fs_1.existsSync)((0, node_path_1.join)(context.workspaceRoot, projectRoot, 'src'))) {
83
+ standaloneSrcPath = 'src';
84
+ }
85
+ else if ((0, node_fs_1.existsSync)((0, node_path_1.join)(context.workspaceRoot, projectRoot, 'lib'))) {
86
+ standaloneSrcPath = 'lib';
87
+ }
88
+ }
89
+ if (projectRoot === '.' && !standaloneSrcPath) {
84
90
  continue;
85
91
  }
86
92
  const eslintConfigs = [configFilePath];
@@ -88,16 +94,16 @@ function getProjectsUsingESLintConfig(configFilePath, childProjectRoots, eslintV
88
94
  eslintConfigs.unshift(rootEslintConfig);
89
95
  }
90
96
  projects[projectRoot] = {
91
- targets: buildEslintTargets(eslintConfigs, eslintVersion, projectRoot, context.workspaceRoot, options, isStandaloneWorkspace),
97
+ targets: buildEslintTargets(eslintConfigs, eslintVersion, projectRoot, context.workspaceRoot, options, standaloneSrcPath),
92
98
  };
93
99
  }
94
100
  return projects;
95
101
  }
96
- function buildEslintTargets(eslintConfigs, eslintVersion, projectRoot, workspaceRoot, options, isStandaloneWorkspace = false) {
102
+ function buildEslintTargets(eslintConfigs, eslintVersion, projectRoot, workspaceRoot, options, standaloneSrcPath) {
97
103
  const isRootProject = projectRoot === '.';
98
104
  const targets = {};
99
105
  const targetConfig = {
100
- command: `eslint ${isRootProject && isStandaloneWorkspace ? './src' : '.'}`,
106
+ command: `eslint ${isRootProject && standaloneSrcPath ? `./${standaloneSrcPath}` : '.'}`,
101
107
  cache: true,
102
108
  options: {
103
109
  cwd: projectRoot,