@nx/eslint 23.0.0-rc.3 → 23.0.0-rc.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.
@@ -51,18 +51,6 @@ function isEslintTarget(target) {
51
51
  return (target.executor === ESLINT_LINT_EXECUTOR ||
52
52
  target.command?.includes('eslint'));
53
53
  }
54
- function hasMatchingEslintTargetDefault(projectConfig, targetDefaults) {
55
- if (!projectConfig.targets || !targetDefaults) {
56
- return false;
57
- }
58
- if (Array.isArray(targetDefaults)) {
59
- return targetDefaults.some((entry) => entry.target !== undefined &&
60
- projectConfig.targets[entry.target] !== undefined &&
61
- (entry.target === ESLINT_LINT_EXECUTOR || isEslintTarget(entry)));
62
- }
63
- return Object.entries(targetDefaults).some(([targetName, targetConfig]) => projectConfig.targets[targetName] !== undefined &&
64
- (targetName === ESLINT_LINT_EXECUTOR || isEslintTarget(targetConfig)));
65
- }
66
54
  function convertProjectToFlatConfig(tree, project, projectConfig, nxJson, eslintIgnoreFiles, format) {
67
55
  const eslintFile = (0, eslint_file_1.findEslintFile)(tree, projectConfig.root);
68
56
  if (!eslintFile || eslintFile.endsWith('.js')) {
@@ -85,7 +73,10 @@ function convertProjectToFlatConfig(tree, project, projectConfig, nxJson, eslint
85
73
  if (eslintTargets.length > 0) {
86
74
  (0, devkit_1.updateProjectConfiguration)(tree, project, projectConfig);
87
75
  }
88
- const hasEslintTargetDefaults = hasMatchingEslintTargetDefault(projectConfig, nxJson.targetDefaults);
76
+ const hasEslintTargetDefaults = projectConfig.targets &&
77
+ Object.keys(nxJson.targetDefaults || {}).some((t) => (t === ESLINT_LINT_EXECUTOR ||
78
+ isEslintTarget(nxJson.targetDefaults[t])) &&
79
+ projectConfig.targets[t]);
89
80
  if (eslintTargets.length === 0 &&
90
81
  !hasEslintTargetDefaults &&
91
82
  !(0, plugin_1.hasEslintPlugin)(tree)) {
@@ -135,32 +126,20 @@ function ensureInputPresent(inputs, value, format) {
135
126
  }
136
127
  // Updates nx.json: rewrites stale eslintrc/eslintignore references across all targetDefaults
137
128
  // inputs and namedInputs, and ensures lint targets include the new flat config file as an input
138
- // (and `production` excludes it). Handles both the legacy record shape and the new array shape
139
- // of `targetDefaults`.
129
+ // (and `production` excludes it).
140
130
  function updateNxJsonConfig(tree, format) {
141
131
  if (!tree.exists('nx.json')) {
142
132
  return;
143
133
  }
144
134
  (0, devkit_1.updateJson)(tree, 'nx.json', (json) => {
145
- const rewriteTargetInputs = (target, isLintTarget) => {
146
- if (!target.inputs)
147
- return;
148
- target.inputs = isLintTarget
149
- ? ensureInputPresent(target.inputs, `{workspaceRoot}/eslint.config.${format}`, format)
150
- : rewriteLegacyInputs(target.inputs, format);
151
- };
152
135
  if (json.targetDefaults) {
153
- if (Array.isArray(json.targetDefaults)) {
154
- for (const entry of json.targetDefaults) {
155
- const isLintTarget = entry.target === 'lint' || entry.target === ESLINT_LINT_EXECUTOR;
156
- rewriteTargetInputs(entry, isLintTarget);
157
- }
158
- }
159
- else {
160
- for (const [name, target] of Object.entries(json.targetDefaults)) {
161
- const isLintTarget = name === 'lint' || name === ESLINT_LINT_EXECUTOR;
162
- rewriteTargetInputs(target, isLintTarget);
163
- }
136
+ for (const [name, target] of Object.entries(json.targetDefaults)) {
137
+ if (!target.inputs)
138
+ continue;
139
+ const isLintTarget = name === 'lint' || name === ESLINT_LINT_EXECUTOR;
140
+ target.inputs = isLintTarget
141
+ ? ensureInputPresent(target.inputs, `{workspaceRoot}/eslint.config.${format}`, format)
142
+ : rewriteLegacyInputs(target.inputs, format);
164
143
  }
165
144
  }
166
145
  if (json.namedInputs) {
@@ -22,32 +22,19 @@ function updateProductionFileset(tree, format = 'mjs') {
22
22
  (0, devkit_1.updateNxJson)(tree, nxJson);
23
23
  }
24
24
  function addTargetDefaults(tree, format) {
25
- const nxJson = (0, devkit_1.readNxJson)(tree) ?? {};
26
- // `@nx/eslint:lint` is an executor identifier — match defaults keyed on
27
- // the executor, not on a target named that string.
28
- const existing = (0, internal_1.findTargetDefault)(nxJson.targetDefaults, {
29
- executor: '@nx/eslint:lint',
30
- });
31
- const patch = {};
32
- if (existing?.cache === undefined)
33
- patch.cache = true;
34
- if (existing?.inputs === undefined) {
35
- patch.inputs = [
36
- 'default',
37
- '^default',
38
- `{workspaceRoot}/.eslintrc.json`,
39
- `{workspaceRoot}/.eslintignore`,
40
- `{workspaceRoot}/eslint.config.${format}`,
41
- '{workspaceRoot}/tools/eslint-rules/**/*',
42
- ];
43
- }
44
- if (Object.keys(patch).length > 0) {
45
- (0, internal_1.upsertTargetDefault)(tree, nxJson, {
46
- executor: '@nx/eslint:lint',
47
- ...patch,
48
- });
49
- (0, devkit_1.updateNxJson)(tree, nxJson);
50
- }
25
+ const nxJson = (0, devkit_1.readNxJson)(tree);
26
+ nxJson.targetDefaults ??= {};
27
+ nxJson.targetDefaults['@nx/eslint:lint'] ??= {};
28
+ nxJson.targetDefaults['@nx/eslint:lint'].cache ??= true;
29
+ nxJson.targetDefaults['@nx/eslint:lint'].inputs ??= [
30
+ 'default',
31
+ '^default',
32
+ `{workspaceRoot}/.eslintrc.json`,
33
+ `{workspaceRoot}/.eslintignore`,
34
+ `{workspaceRoot}/eslint.config.${format}`,
35
+ '{workspaceRoot}/tools/eslint-rules/**/*',
36
+ ];
37
+ (0, devkit_1.updateNxJson)(tree, nxJson);
51
38
  }
52
39
  function updateVsCodeRecommendedExtensions(host) {
53
40
  if (!host.exists('.vscode/extensions.json')) {
@@ -38,9 +38,8 @@ async function lintWorkspaceRulesProjectGenerator(tree, options = {}) {
38
38
  * TODO: Explore writing a ProjectGraph plugin to make this more surgical.
39
39
  */
40
40
  const nxJson = (0, devkit_1.readNxJson)(tree);
41
- const lintEntry = findLintTargetDefault(nxJson.targetDefaults);
42
- if (lintEntry?.inputs) {
43
- lintEntry.inputs.push(`{workspaceRoot}/${exports.WORKSPACE_PLUGIN_DIR}/**/*`);
41
+ if (nxJson.targetDefaults?.lint?.inputs) {
42
+ nxJson.targetDefaults.lint.inputs.push(`{workspaceRoot}/${exports.WORKSPACE_PLUGIN_DIR}/**/*`);
44
43
  (0, devkit_1.updateNxJson)(tree, nxJson);
45
44
  }
46
45
  // Add jest to the project and return installation task
@@ -93,13 +92,3 @@ async function lintWorkspaceRulesProjectGenerator(tree, options = {}) {
93
92
  }
94
93
  return (0, devkit_1.runTasksInSerial)(...tasks);
95
94
  }
96
- function findLintTargetDefault(td) {
97
- if (!td)
98
- return undefined;
99
- if (Array.isArray(td)) {
100
- return td.find((e) => e.target === 'lint' &&
101
- e.projects === undefined &&
102
- e.plugin === undefined);
103
- }
104
- return td['lint'];
105
- }
@@ -2,18 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = default_1;
4
4
  const devkit_1 = require("@nx/devkit");
5
- const internal_1 = require("@nx/devkit/internal");
6
5
  async function default_1(tree) {
7
- const nxJson = (0, devkit_1.readNxJson)(tree) ?? {};
6
+ const nxJson = (0, devkit_1.readNxJson)(tree);
8
7
  const executor = '@nx/eslint:lint';
9
- const existing = (0, internal_1.normalizeTargetDefaults)(nxJson.targetDefaults).find((e) => e.executor === executor &&
10
- e.target === undefined &&
11
- e.projects === undefined &&
12
- e.plugin === undefined);
13
- if (!existing?.inputs) {
8
+ if (!nxJson.targetDefaults?.[executor]?.inputs) {
14
9
  return;
15
10
  }
16
- const inputs = [...existing.inputs];
11
+ const inputs = nxJson.targetDefaults[executor].inputs;
17
12
  if (!inputs.includes('^default')) {
18
13
  // Add after 'default' if present, otherwise at the beginning
19
14
  const defaultIndex = inputs.indexOf('default');
@@ -27,7 +22,6 @@ async function default_1(tree) {
27
22
  if (!inputs.includes('{workspaceRoot}/tools/eslint-rules/**/*')) {
28
23
  inputs.push('{workspaceRoot}/tools/eslint-rules/**/*');
29
24
  }
30
- (0, internal_1.upsertTargetDefault)(tree, nxJson, { executor, inputs });
31
25
  (0, devkit_1.updateNxJson)(tree, nxJson);
32
26
  await (0, devkit_1.formatFiles)(tree);
33
27
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/eslint",
3
- "version": "23.0.0-rc.3",
3
+ "version": "23.0.0-rc.4",
4
4
  "private": false,
5
5
  "type": "commonjs",
6
6
  "files": [
@@ -73,17 +73,17 @@
73
73
  "peerDependencies": {
74
74
  "@zkochan/js-yaml": "0.0.7",
75
75
  "eslint": "^8.0.0 || ^9.0.0 || ^10.0.0",
76
- "@nx/jest": "23.0.0-rc.3"
76
+ "@nx/jest": "23.0.0-rc.4"
77
77
  },
78
78
  "dependencies": {
79
79
  "semver": "^7.6.3",
80
80
  "tslib": "^2.3.0",
81
81
  "typescript": "~5.9.2",
82
- "@nx/devkit": "23.0.0-rc.3",
83
- "@nx/js": "23.0.0-rc.3"
82
+ "@nx/devkit": "23.0.0-rc.4",
83
+ "@nx/js": "23.0.0-rc.4"
84
84
  },
85
85
  "devDependencies": {
86
- "nx": "23.0.0-rc.3"
86
+ "nx": "23.0.0-rc.4"
87
87
  },
88
88
  "peerDependenciesMeta": {
89
89
  "@nx/jest": {