@nx/eslint 17.3.0-canary.20240109-2360918 → 17.3.0-canary.20240110-6307a83

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 CHANGED
@@ -37,6 +37,11 @@
37
37
  "version": "17.2.0-beta.0",
38
38
  "description": "Simplify eslintFilePatterns",
39
39
  "implementation": "./src/migrations/update-17-2-0/simplify-eslint-patterns"
40
+ },
41
+ "move-options-to-target-defaults": {
42
+ "version": "17.2.9",
43
+ "description": "Move executor options to target defaults",
44
+ "implementation": "./src/migrations/update-17-2-9/move-options-to-target-defaults"
40
45
  }
41
46
  },
42
47
  "packageJsonUpdates": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/eslint",
3
- "version": "17.3.0-canary.20240109-2360918",
3
+ "version": "17.3.0-canary.20240110-6307a83",
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,11 +34,11 @@
34
34
  "js-yaml": "4.1.0"
35
35
  },
36
36
  "dependencies": {
37
- "@nx/devkit": "17.3.0-canary.20240109-2360918",
38
- "@nx/js": "17.3.0-canary.20240109-2360918",
37
+ "@nx/devkit": "17.3.0-canary.20240110-6307a83",
38
+ "@nx/js": "17.3.0-canary.20240110-6307a83",
39
39
  "tslib": "^2.3.0",
40
40
  "typescript": "~5.2.2",
41
- "@nx/linter": "17.3.0-canary.20240109-2360918"
41
+ "@nx/linter": "17.3.0-canary.20240110-6307a83"
42
42
  },
43
43
  "peerDependenciesMeta": {
44
44
  "eslint": {
@@ -20,9 +20,9 @@ function updateProductionFileset(tree) {
20
20
  function addTargetDefaults(tree) {
21
21
  const nxJson = (0, devkit_1.readNxJson)(tree);
22
22
  nxJson.targetDefaults ??= {};
23
- nxJson.targetDefaults.lint ??= {};
24
- nxJson.targetDefaults.lint.cache ??= true;
25
- nxJson.targetDefaults.lint.inputs ??= [
23
+ nxJson.targetDefaults['@nx/eslint:lint'] ??= {};
24
+ nxJson.targetDefaults['@nx/eslint:lint'].cache ??= true;
25
+ nxJson.targetDefaults['@nx/eslint:lint'].inputs ??= [
26
26
  'default',
27
27
  `{workspaceRoot}/.eslintrc.json`,
28
28
  `{workspaceRoot}/.eslintignore`,
@@ -44,7 +44,6 @@ async function lintProjectGenerator(tree, options) {
44
44
  else {
45
45
  projectConfig.targets['lint'] = {
46
46
  executor: '@nx/eslint:lint',
47
- outputs: ['{options.outputFile}'],
48
47
  };
49
48
  if (lintFilePatterns && lintFilePatterns.length) {
50
49
  // only add lintFilePatterns if they are explicitly defined
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export default function update(tree: Tree): Promise<void>;
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const devkit_1 = require("@nx/devkit");
4
+ const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
5
+ const eslint_file_1 = require("../../generators/utils/eslint-file");
6
+ const project_configuration_utils_1 = require("nx/src/project-graph/utils/project-configuration-utils");
7
+ async function update(tree) {
8
+ const nxJson = (0, devkit_1.readNxJson)(tree);
9
+ // Don't override anything if there are already target defaults for eslint
10
+ if (nxJson.targetDefaults?.['@nx/eslint:lint']) {
11
+ return;
12
+ }
13
+ nxJson.targetDefaults ??= {};
14
+ const graph = await (0, devkit_1.createProjectGraphAsync)();
15
+ const lintTargets = new Set();
16
+ (0, executor_options_utils_1.forEachExecutorOptionsInGraph)(graph, '@nx/eslint:lint', (value, proj, targetName) => {
17
+ lintTargets.add(targetName);
18
+ });
19
+ // Workspace does not use eslint?
20
+ if (lintTargets.size === 0) {
21
+ return;
22
+ }
23
+ const lintDefaults = (nxJson.targetDefaults['@nx/eslint:lint'] = {});
24
+ // All eslint targets have the same name
25
+ if (lintTargets.size === 1) {
26
+ const targetName = Array.from(lintTargets)[0];
27
+ if (nxJson.targetDefaults[targetName]) {
28
+ Object.assign(lintDefaults, nxJson.targetDefaults[targetName]);
29
+ }
30
+ }
31
+ lintDefaults.cache ??= true;
32
+ if (!lintDefaults.inputs) {
33
+ const eslintConfig = (0, eslint_file_1.findEslintFile)(tree);
34
+ lintDefaults.inputs = [
35
+ 'default',
36
+ ...(eslintConfig ? [`{workspaceRoot}/${eslintConfig}`] : []),
37
+ '{workspaceRoot}/tools/eslint-rules/**/*',
38
+ ];
39
+ }
40
+ // Cleanup old target defaults
41
+ const projects = graph.nodes;
42
+ const projectMap = (0, devkit_1.getProjects)(tree);
43
+ for (const [targetDefaultKey, targetDefault] of Object.entries(nxJson.targetDefaults)) {
44
+ if (!isTargetDefaultUsed(targetDefault, nxJson.targetDefaults, projects, projectMap)) {
45
+ delete nxJson.targetDefaults[targetDefaultKey];
46
+ }
47
+ }
48
+ let addOutputs = false;
49
+ (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/eslint:lint', (options, proj, targetName, configuration) => {
50
+ const projConfig = projectMap.get(proj);
51
+ // modify lint file patterns
52
+ if (options.lintFilePatterns) {
53
+ const projectRootRegex = new RegExp(`^${projConfig.root}/`);
54
+ projConfig.targets[targetName].options.lintFilePatterns =
55
+ options.lintFilePatterns
56
+ .filter((filePattern) => filePattern !== '{projectRoot}' &&
57
+ filePattern !== projConfig.root)
58
+ .map((filePattern) => filePattern.replace(projectRootRegex, '{projectRoot}/'));
59
+ // remove lintFilePatterns if empty
60
+ if (projConfig.targets[targetName].options.lintFilePatterns.length === 0) {
61
+ delete projConfig.targets[targetName].options.lintFilePatterns;
62
+ }
63
+ }
64
+ // remove inputs if they are not bringing any new inputs
65
+ if (projConfig.targets[targetName].inputs &&
66
+ projConfig.targets[targetName].inputs.every((i) => lintDefaults.inputs.includes(i))) {
67
+ delete projConfig.targets[targetName].inputs;
68
+ }
69
+ // remove obsolete eslint config definition, unless it's a custom one
70
+ const projectEslintConfig = (0, eslint_file_1.findEslintFile)(tree, projConfig.root);
71
+ if (options.eslintConfig === `${projConfig.root}/${projectEslintConfig}` ||
72
+ options.eslintConfig === `{projectRoot}/${projectEslintConfig}`) {
73
+ delete projConfig.targets[targetName].options.eslintConfig;
74
+ }
75
+ // remove options if empty
76
+ if (Object.keys(projConfig.targets[targetName].options).length === 0) {
77
+ delete projConfig.targets[targetName].options;
78
+ }
79
+ // track output
80
+ if (options.outputFile) {
81
+ addOutputs = true;
82
+ }
83
+ if (projConfig.targets[targetName].outputs?.length === 1 &&
84
+ projConfig.targets[targetName].outputs[0] === '{options.outputFile}') {
85
+ delete projConfig.targets[targetName].outputs;
86
+ }
87
+ (0, devkit_1.updateProjectConfiguration)(tree, proj, projConfig);
88
+ });
89
+ if (addOutputs) {
90
+ lintDefaults.outputs = ['{options.outputFile}'];
91
+ }
92
+ (0, devkit_1.updateNxJson)(tree, nxJson);
93
+ await (0, devkit_1.formatFiles)(tree);
94
+ }
95
+ exports.default = update;
96
+ function isTargetDefaultUsed(targetDefault, targetDefaults, projects, projectMap) {
97
+ for (const p of Object.values(projects)) {
98
+ for (const targetName in p.data?.targets ?? {}) {
99
+ if ((0, project_configuration_utils_1.readTargetDefaultsForTarget)(targetName, targetDefaults,
100
+ // It might seem like we should use the graph here too but we don't want to pass an executor which was processed in the graph
101
+ projectMap.get(p.name)?.targets?.[targetName]?.executor) === targetDefault) {
102
+ return true;
103
+ }
104
+ }
105
+ }
106
+ return false;
107
+ }
@@ -17,7 +17,7 @@ exports.createNodes = [
17
17
  return {
18
18
  projects: {
19
19
  [projectRoot]: {
20
- targets: buildEslintTargets(eslintConfigs, projectRoot, options, context),
20
+ targets: buildEslintTargets(eslintConfigs, projectRoot, options),
21
21
  },
22
22
  },
23
23
  };
@@ -61,33 +61,28 @@ function getEslintConfigsForProject(projectRoot, workspaceRoot) {
61
61
  }
62
62
  return [];
63
63
  }
64
- function buildEslintTargets(eslintConfigs, projectRoot, options, context) {
64
+ function buildEslintTargets(eslintConfigs, projectRoot, options) {
65
65
  const isRootProject = projectRoot === '.';
66
66
  const targets = {};
67
- const baseTargetConfig = {
67
+ const targetConfig = {
68
68
  command: `eslint ${isRootProject ? './src' : '.'}`,
69
+ cache: true,
69
70
  options: {
70
71
  cwd: projectRoot,
71
72
  },
72
- };
73
- if (eslintConfigs.some((config) => (0, config_file_1.isFlatConfig)(config))) {
74
- baseTargetConfig.options.env = {
75
- ESLINT_USE_FLAT_CONFIG: 'true',
76
- };
77
- }
78
- targets[options.targetName] = {
79
- ...baseTargetConfig,
80
- cache: true,
81
73
  inputs: [
82
74
  'default',
83
75
  ...eslintConfigs.map((config) => `{workspaceRoot}/${config}`),
84
76
  '{workspaceRoot}/tools/eslint-rules/**/*',
85
77
  { externalDependencies: ['eslint'] },
86
78
  ],
87
- options: {
88
- ...baseTargetConfig.options,
89
- },
90
79
  };
80
+ if (eslintConfigs.some((config) => (0, config_file_1.isFlatConfig)(config))) {
81
+ targetConfig.options.env = {
82
+ ESLINT_USE_FLAT_CONFIG: 'true',
83
+ };
84
+ }
85
+ targets[options.targetName] = targetConfig;
91
86
  return targets;
92
87
  }
93
88
  function normalizeOptions(options) {