@nx/eslint 19.2.0-canary.20240530-316dcb9 → 19.2.0-canary.20240601-6f22300

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.2.0-canary.20240530-316dcb9",
3
+ "version": "19.2.0-canary.20240601-6f22300",
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.2.0-canary.20240530-316dcb9",
39
- "@nx/js": "19.2.0-canary.20240530-316dcb9",
38
+ "@nx/devkit": "19.2.0-canary.20240601-6f22300",
39
+ "@nx/js": "19.2.0-canary.20240601-6f22300",
40
40
  "semver": "^7.5.3",
41
41
  "tslib": "^2.3.0",
42
42
  "typescript": "~5.4.2",
43
- "@nx/linter": "19.2.0-canary.20240530-316dcb9"
43
+ "@nx/linter": "19.2.0-canary.20240601-6f22300"
44
44
  },
45
45
  "peerDependenciesMeta": {
46
46
  "@zkochan/js-yaml": {
@@ -8,8 +8,8 @@ const target_options_map_1 = require("./lib/target-options-map");
8
8
  const utils_1 = require("nx/src/tasks-runner/utils");
9
9
  async function convertToInferred(tree, options) {
10
10
  const projectGraph = await (0, devkit_1.createProjectGraphAsync)();
11
- const migratedProjectsModern = await (0, executor_to_plugin_migrator_1.migrateExecutorToPlugin)(tree, projectGraph, '@nx/eslint:lint', '@nx/eslint/plugin', (targetName) => ({ targetName }), postTargetTransformer, plugin_1.createNodes, options.project);
12
- const migratedProjectsLegacy = await (0, executor_to_plugin_migrator_1.migrateExecutorToPlugin)(tree, projectGraph, '@nrwl/linter:eslint', '@nx/eslint/plugin', (targetName) => ({ targetName }), postTargetTransformer, plugin_1.createNodes, options.project);
11
+ const migratedProjectsModern = await (0, executor_to_plugin_migrator_1.migrateExecutorToPluginV1)(tree, projectGraph, '@nx/eslint:lint', '@nx/eslint/plugin', (targetName) => ({ targetName }), postTargetTransformer, plugin_1.createNodes, options.project);
12
+ const migratedProjectsLegacy = await (0, executor_to_plugin_migrator_1.migrateExecutorToPluginV1)(tree, projectGraph, '@nrwl/linter:eslint', '@nx/eslint/plugin', (targetName) => ({ targetName }), postTargetTransformer, plugin_1.createNodes, options.project);
13
13
  const migratedProjects = migratedProjectsModern.size + migratedProjectsLegacy.size;
14
14
  if (migratedProjects === 0) {
15
15
  throw new Error('Could not find any targets to migrate.');
@@ -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
  }
@@ -48,7 +48,7 @@ async function initEsLint(tree, options) {
48
48
  '_eslint-lint',
49
49
  ];
50
50
  if (rootEslintFile && options.addPlugin && !hasPlugin) {
51
- await (0, add_plugin_1.addPlugin)(tree, graph, '@nx/eslint/plugin', plugin_1.createNodes, {
51
+ await (0, add_plugin_1.addPluginV1)(tree, graph, '@nx/eslint/plugin', plugin_1.createNodes, {
52
52
  targetName: lintTargetNames,
53
53
  }, options.updatePackageScripts);
54
54
  return () => { };
@@ -58,7 +58,7 @@ async function initEsLint(tree, options) {
58
58
  }
59
59
  updateProductionFileset(tree);
60
60
  if (options.addPlugin) {
61
- await (0, add_plugin_1.addPlugin)(tree, graph, '@nx/eslint/plugin', plugin_1.createNodes, {
61
+ await (0, add_plugin_1.addPluginV1)(tree, graph, '@nx/eslint/plugin', plugin_1.createNodes, {
62
62
  targetName: lintTargetNames,
63
63
  }, options.updatePackageScripts);
64
64
  }
@@ -16,6 +16,7 @@ interface LintProjectOptions {
16
16
  * @internal
17
17
  */
18
18
  addExplicitTargets?: boolean;
19
+ addPackageJsonDependencyChecks?: boolean;
19
20
  }
20
21
  export declare function lintProjectGenerator(tree: Tree, options: LintProjectOptions): Promise<GeneratorCallback>;
21
22
  export declare function lintProjectGeneratorInternal(tree: Tree, options: LintProjectOptions): Promise<GeneratorCallback>;
@@ -89,7 +89,7 @@ async function lintProjectGeneratorInternal(tree, options) {
89
89
  // additionally, the companion e2e app would have `rootProject: true`
90
90
  // so we need to check for the root path as well
91
91
  if (!options.rootProject || projectConfig.root !== '.') {
92
- createEsLintConfiguration(tree, projectConfig, options.setParserOptionsProject, options.rootProject);
92
+ createEsLintConfiguration(tree, options, projectConfig, options.setParserOptionsProject, options.rootProject);
93
93
  }
94
94
  // Buildable libs need source analysis enabled for linting `package.json`.
95
95
  if (isBuildableLibraryProject(projectConfig) &&
@@ -108,7 +108,7 @@ async function lintProjectGeneratorInternal(tree, options) {
108
108
  return (0, devkit_1.runTasksInSerial)(...tasks);
109
109
  }
110
110
  exports.lintProjectGeneratorInternal = lintProjectGeneratorInternal;
111
- function createEsLintConfiguration(tree, projectConfig, setParserOptionsProject, rootProject) {
111
+ function createEsLintConfiguration(tree, options, projectConfig, setParserOptionsProject, rootProject) {
112
112
  // we are only extending root for non-standalone projects or their complementary e2e apps
113
113
  const extendedRootConfig = rootProject ? undefined : (0, eslint_file_1.findEslintFile)(tree);
114
114
  const pathToRootConfig = extendedRootConfig
@@ -151,7 +151,8 @@ function createEsLintConfiguration(tree, projectConfig, setParserOptionsProject,
151
151
  rules: {},
152
152
  },
153
153
  ];
154
- if (isBuildableLibraryProject(projectConfig)) {
154
+ if (options.addPackageJsonDependencyChecks ||
155
+ isBuildableLibraryProject(projectConfig)) {
155
156
  overrides.push({
156
157
  files: ['*.json'],
157
158
  parser: 'jsonc-eslint-parser',
@@ -32,7 +32,7 @@ exports.createNodes = [
32
32
  nestedEslintRootPatterns.push(`${eslintRootDir}/**/*`);
33
33
  }
34
34
  }
35
- const projectFiles = (0, workspace_context_1.globWithWorkspaceContext)(context.workspaceRoot, [
35
+ const projectFiles = await (0, workspace_context_1.globWithWorkspaceContext)(context.workspaceRoot, [
36
36
  'project.json',
37
37
  'package.json',
38
38
  '**/project.json',
@@ -48,7 +48,7 @@ exports.createNodes = [
48
48
  // anything after is either a nested project or a sibling project, can be excluded
49
49
  const nestedProjectRootPatterns = excludePatterns.slice(index + 1);
50
50
  // Ignore project roots where the project does not contain any lintable files
51
- const lintableFiles = (0, workspace_context_1.globWithWorkspaceContext)(context.workspaceRoot, [(0, node_path_1.join)(childProjectRoot, `**/*.{${options.extensions.join(',')}}`)],
51
+ const lintableFiles = await (0, workspace_context_1.globWithWorkspaceContext)(context.workspaceRoot, [(0, node_path_1.join)(childProjectRoot, `**/*.{${options.extensions.join(',')}}`)],
52
52
  // exclude nested eslint roots and nested project roots
53
53
  [...nestedEslintRootPatterns, ...nestedProjectRootPatterns]);
54
54
  const eslint = new ESLint({
@@ -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,