@nx/eslint 24.0.0-canary.20261020-e7ffd79 → 24.0.0-rc.0
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/dist/src/generators/lint-project/lint-project.d.ts +0 -4
- package/dist/src/generators/lint-project/lint-project.js +1 -1
- package/dist/src/generators/utils/eslint-file.d.ts +2 -5
- package/dist/src/generators/utils/eslint-file.js +3 -5
- package/dist/src/migrations/update-24-0-0/replace-set-parser-options-project.d.ts +4 -0
- package/dist/src/migrations/update-24-0-0/replace-set-parser-options-project.js +192 -0
- package/dist/src/migrations/update-24-0-0/replace-set-parser-options-project.md +77 -0
- package/migrations.json +6 -0
- package/package.json +5 -5
|
@@ -7,10 +7,6 @@ interface LintProjectOptions {
|
|
|
7
7
|
tsConfigPaths?: string[];
|
|
8
8
|
skipFormat: boolean;
|
|
9
9
|
enableTypedLinting?: boolean;
|
|
10
|
-
/**
|
|
11
|
-
* @deprecated Use `enableTypedLinting` instead. This option will be removed in Nx v24.
|
|
12
|
-
*/
|
|
13
|
-
setParserOptionsProject?: boolean;
|
|
14
10
|
skipPackageJson?: boolean;
|
|
15
11
|
unitTestRunner?: string;
|
|
16
12
|
rootProject?: boolean;
|
|
@@ -76,7 +76,7 @@ async function lintProjectGeneratorInternal(tree, options) {
|
|
|
76
76
|
if (!options.rootProject || projectConfig.root !== '.') {
|
|
77
77
|
const addDependencyChecks = options.addPackageJsonDependencyChecks ||
|
|
78
78
|
isBuildableLibraryProject(tree, projectConfig);
|
|
79
|
-
createEsLintConfiguration(tree, options, projectConfig,
|
|
79
|
+
createEsLintConfiguration(tree, options, projectConfig, options.enableTypedLinting, options.rootProject, addDependencyChecks);
|
|
80
80
|
if (addDependencyChecks) {
|
|
81
81
|
tasks.push((0, devkit_1.addDependenciesToPackageJson)(tree, {}, { 'jsonc-eslint-parser': versions_1.jsoncEslintParserVersion }, undefined, true));
|
|
82
82
|
}
|
|
@@ -5,14 +5,11 @@ export declare function isEslintConfigSupported(tree: Tree, projectRoot?: string
|
|
|
5
5
|
export declare function updateRelativePathsInConfig(tree: Tree, sourcePath: string, destinationPath: string): void;
|
|
6
6
|
export declare function determineEslintConfigFormat(content: string): 'mjs' | 'cjs';
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
* (
|
|
10
|
-
* generator whose `enableTypedLinting` schema default is `false` must still
|
|
11
|
-
* honor a user who set the deprecated flag.
|
|
8
|
+
* Plugins this repo installs from npm still import this, and its specs load them.
|
|
9
|
+
* TODO(v24): remove once the root `nx` catalog is on a release whose plugins no longer import it.
|
|
12
10
|
*/
|
|
13
11
|
export declare function isTypedLintingEnabled(options: {
|
|
14
12
|
enableTypedLinting?: boolean;
|
|
15
|
-
setParserOptionsProject?: boolean;
|
|
16
13
|
}): boolean;
|
|
17
14
|
/**
|
|
18
15
|
* What a config says about typed linting.
|
|
@@ -152,13 +152,11 @@ function determineEslintConfigFormat(content) {
|
|
|
152
152
|
return (0, ast_utils_1.isEsmExport)(sourceFile) ? 'mjs' : 'cjs';
|
|
153
153
|
}
|
|
154
154
|
/**
|
|
155
|
-
*
|
|
156
|
-
* (
|
|
157
|
-
* generator whose `enableTypedLinting` schema default is `false` must still
|
|
158
|
-
* honor a user who set the deprecated flag.
|
|
155
|
+
* Plugins this repo installs from npm still import this, and its specs load them.
|
|
156
|
+
* TODO(v24): remove once the root `nx` catalog is on a release whose plugins no longer import it.
|
|
159
157
|
*/
|
|
160
158
|
function isTypedLintingEnabled(options) {
|
|
161
|
-
return !!
|
|
159
|
+
return !!options.enableTypedLinting;
|
|
162
160
|
}
|
|
163
161
|
/**
|
|
164
162
|
* What a config says about typed linting.
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = update;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
// Generators that declared `setParserOptionsProject` in Nx 23 and still exist in Nx 24.
|
|
6
|
+
const GENERATORS = {
|
|
7
|
+
'@nx/angular': ['add-linting', 'application', 'library'],
|
|
8
|
+
'@nx/cypress': ['configuration'],
|
|
9
|
+
'@nx/detox': ['application'],
|
|
10
|
+
'@nx/expo': ['application', 'library'],
|
|
11
|
+
'@nx/express': ['application'],
|
|
12
|
+
'@nx/js': ['library'],
|
|
13
|
+
'@nx/nest': ['application', 'library'],
|
|
14
|
+
'@nx/next': ['application', 'library'],
|
|
15
|
+
'@nx/node': ['application', 'library'],
|
|
16
|
+
'@nx/nuxt': ['application'],
|
|
17
|
+
'@nx/playwright': ['configuration'],
|
|
18
|
+
'@nx/plugin': ['plugin'],
|
|
19
|
+
'@nx/react': ['application', 'library'],
|
|
20
|
+
'@nx/react-native': ['application', 'library'],
|
|
21
|
+
'@nx/vue': ['application', 'library'],
|
|
22
|
+
'@nx/web': ['application'],
|
|
23
|
+
};
|
|
24
|
+
const REMOVED = 'setParserOptionsProject';
|
|
25
|
+
const REPLACEMENT = 'enableTypedLinting';
|
|
26
|
+
async function update(tree) {
|
|
27
|
+
let changed = false;
|
|
28
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
29
|
+
const fromNxJson = new Map();
|
|
30
|
+
if (nxJson && migrateGenerators([nxJson], fromNxJson)[0]) {
|
|
31
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
32
|
+
changed = true;
|
|
33
|
+
}
|
|
34
|
+
const angularJson = tree.exists('angular.json')
|
|
35
|
+
? (0, devkit_1.readJson)(tree, 'angular.json')
|
|
36
|
+
: undefined;
|
|
37
|
+
let angularJsonChanged = false;
|
|
38
|
+
for (const [projectName, { root }] of (0, devkit_1.getProjects)(tree)) {
|
|
39
|
+
// Edit each file in place: `updateProjectConfiguration` would write the
|
|
40
|
+
// merged configuration to `project.json` and leave `package.json` as is.
|
|
41
|
+
const packageJsonPath = (0, devkit_1.joinPathFragments)(root, 'package.json');
|
|
42
|
+
const projectJsonPath = (0, devkit_1.joinPathFragments)(root, 'project.json');
|
|
43
|
+
const packageJson = tree.exists(packageJsonPath)
|
|
44
|
+
? (0, devkit_1.readJson)(tree, packageJsonPath)
|
|
45
|
+
: undefined;
|
|
46
|
+
const projectJson = tree.exists(projectJsonPath)
|
|
47
|
+
? (0, devkit_1.readJson)(tree, projectJsonPath)
|
|
48
|
+
: undefined;
|
|
49
|
+
// Nx reads an `angular.json` project's `schematics` as its `generators`.
|
|
50
|
+
const angularJsonProject = angularJson?.projects?.[projectName];
|
|
51
|
+
const angularJsonKey = angularJsonProject?.schematics !== undefined
|
|
52
|
+
? 'schematics'
|
|
53
|
+
: 'generators';
|
|
54
|
+
const angularJsonDefaults = {
|
|
55
|
+
generators: angularJsonProject?.[angularJsonKey],
|
|
56
|
+
};
|
|
57
|
+
// Nx merges `angular.json`, then `package.json`, then `project.json`.
|
|
58
|
+
const [angularJsonProjectChanged, packageJsonChanged, projectJsonChanged] = migrateGenerators([
|
|
59
|
+
angularJsonDefaults,
|
|
60
|
+
isRecord(packageJson?.nx) ? packageJson.nx : {},
|
|
61
|
+
projectJson ?? {},
|
|
62
|
+
], new Map(fromNxJson));
|
|
63
|
+
if (angularJsonProjectChanged) {
|
|
64
|
+
if (!angularJsonDefaults.generators) {
|
|
65
|
+
delete angularJsonProject[angularJsonKey];
|
|
66
|
+
}
|
|
67
|
+
angularJsonChanged = true;
|
|
68
|
+
}
|
|
69
|
+
if (packageJsonChanged) {
|
|
70
|
+
(0, devkit_1.writeJson)(tree, packageJsonPath, packageJson);
|
|
71
|
+
changed = true;
|
|
72
|
+
}
|
|
73
|
+
if (projectJsonChanged) {
|
|
74
|
+
(0, devkit_1.writeJson)(tree, projectJsonPath, projectJson);
|
|
75
|
+
changed = true;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (angularJsonChanged) {
|
|
79
|
+
(0, devkit_1.writeJson)(tree, 'angular.json', angularJson);
|
|
80
|
+
changed = true;
|
|
81
|
+
}
|
|
82
|
+
if (!changed) {
|
|
83
|
+
return { skipAgentic: true };
|
|
84
|
+
}
|
|
85
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Rewrites the defaults so the merged `enableTypedLinting` equals the pre-migration
|
|
89
|
+
* `enableTypedLinting || setParserOptionsProject`. `owners` merge in order, a later
|
|
90
|
+
* one taking precedence. `resolutions` holds the layers beneath `owners` and is
|
|
91
|
+
* updated to include them. Returns which owners changed.
|
|
92
|
+
*/
|
|
93
|
+
function migrateGenerators(owners, resolutions) {
|
|
94
|
+
const changed = owners.map(() => false);
|
|
95
|
+
const sources = owners.map((owner) => isRecord(owner.generators) ? owner.generators : undefined);
|
|
96
|
+
for (const [collection, names] of Object.entries(GENERATORS)) {
|
|
97
|
+
for (const name of names) {
|
|
98
|
+
const flatKey = `${collection}:${name}`;
|
|
99
|
+
const beneath = resolutions.get(flatKey) ?? {
|
|
100
|
+
enableTypedLinting: false,
|
|
101
|
+
setParserOptionsProject: false,
|
|
102
|
+
};
|
|
103
|
+
// Nested before flat: the order `getGeneratorDefaults` merges them in.
|
|
104
|
+
// A later owner's nested entry replaces an earlier one's entirely.
|
|
105
|
+
let resolution = beneath;
|
|
106
|
+
for (const [i, generators] of sources.entries()) {
|
|
107
|
+
const nested = generators?.[collection];
|
|
108
|
+
if (!isRecord(nested) || !(name in nested)) {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
const result = migrateEntry(nested, name, beneath);
|
|
112
|
+
resolution = result.resolution;
|
|
113
|
+
if (result.changed) {
|
|
114
|
+
changed[i] = true;
|
|
115
|
+
if (isEmpty(nested)) {
|
|
116
|
+
delete generators[collection];
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// Flat entries merge option by option.
|
|
121
|
+
for (const [i, generators] of sources.entries()) {
|
|
122
|
+
if (!generators) {
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
const result = migrateEntry(generators, flatKey, resolution);
|
|
126
|
+
resolution = result.resolution;
|
|
127
|
+
if (result.changed) {
|
|
128
|
+
changed[i] = true;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
resolutions.set(flatKey, resolution);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
for (const [i, owner] of owners.entries()) {
|
|
135
|
+
if (changed[i] && isEmpty(owner.generators)) {
|
|
136
|
+
delete owner.generators;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return changed;
|
|
140
|
+
}
|
|
141
|
+
/** Migrates `container[key]` and removes it when the migration leaves it empty. */
|
|
142
|
+
function migrateEntry(container, key, below) {
|
|
143
|
+
const defaults = container[key];
|
|
144
|
+
if (!isRecord(defaults)) {
|
|
145
|
+
return { resolution: below, changed: false };
|
|
146
|
+
}
|
|
147
|
+
const result = migrateDefaults(defaults, below);
|
|
148
|
+
if (result.changed && isEmpty(defaults)) {
|
|
149
|
+
delete container[key];
|
|
150
|
+
}
|
|
151
|
+
return result;
|
|
152
|
+
}
|
|
153
|
+
function migrateDefaults(defaults, below) {
|
|
154
|
+
const hasRemoved = REMOVED in defaults;
|
|
155
|
+
const hasReplacement = REPLACEMENT in defaults;
|
|
156
|
+
if (!hasRemoved && !hasReplacement) {
|
|
157
|
+
return { resolution: below, changed: false };
|
|
158
|
+
}
|
|
159
|
+
const resolution = {
|
|
160
|
+
enableTypedLinting: hasReplacement
|
|
161
|
+
? toBoolean(defaults[REPLACEMENT])
|
|
162
|
+
: below.enableTypedLinting,
|
|
163
|
+
setParserOptionsProject: hasRemoved
|
|
164
|
+
? toBoolean(defaults[REMOVED])
|
|
165
|
+
: below.setParserOptionsProject,
|
|
166
|
+
};
|
|
167
|
+
const expected = resolution.enableTypedLinting || resolution.setParserOptionsProject;
|
|
168
|
+
// Layers beneath this one are already migrated to their own merged value.
|
|
169
|
+
const migratedWithoutChange = hasReplacement
|
|
170
|
+
? toBoolean(defaults[REPLACEMENT])
|
|
171
|
+
: below.enableTypedLinting || below.setParserOptionsProject;
|
|
172
|
+
let changed = false;
|
|
173
|
+
if (hasRemoved) {
|
|
174
|
+
delete defaults[REMOVED];
|
|
175
|
+
changed = true;
|
|
176
|
+
}
|
|
177
|
+
if (migratedWithoutChange !== expected) {
|
|
178
|
+
defaults[REPLACEMENT] = expected;
|
|
179
|
+
changed = true;
|
|
180
|
+
}
|
|
181
|
+
return { resolution, changed };
|
|
182
|
+
}
|
|
183
|
+
// Mirrors how nx coerces a boolean option: only `true` and `'true'` enable it.
|
|
184
|
+
function toBoolean(value) {
|
|
185
|
+
return value === true || value === 'true';
|
|
186
|
+
}
|
|
187
|
+
function isRecord(value) {
|
|
188
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
189
|
+
}
|
|
190
|
+
function isEmpty(value) {
|
|
191
|
+
return Object.keys(value).length === 0;
|
|
192
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
#### Replace `setParserOptionsProject` with `enableTypedLinting` in generator defaults
|
|
2
|
+
|
|
3
|
+
Nx 24 removes the deprecated `setParserOptionsProject` generator option, which `enableTypedLinting` replaces. The migration rewrites the generator defaults in `nx.json`, in `angular.json` projects, in `project.json` files and in the `nx` key of project `package.json` files. It handles both the flat form (`@nx/react:library`) and the nested form (`@nx/react` -> `library`).
|
|
4
|
+
|
|
5
|
+
It covers every generator that accepted the option and still exists in Nx 24:
|
|
6
|
+
|
|
7
|
+
- `application`: `@nx/angular`, `@nx/detox`, `@nx/expo`, `@nx/express`, `@nx/nest`, `@nx/next`, `@nx/node`, `@nx/nuxt`, `@nx/react`, `@nx/react-native`, `@nx/vue` and `@nx/web`
|
|
8
|
+
- `library`: `@nx/angular`, `@nx/expo`, `@nx/js`, `@nx/nest`, `@nx/next`, `@nx/node`, `@nx/react`, `@nx/react-native` and `@nx/vue`
|
|
9
|
+
- `configuration`: `@nx/cypress` and `@nx/playwright`
|
|
10
|
+
- `@nx/angular:add-linting` and `@nx/plugin:plugin`
|
|
11
|
+
|
|
12
|
+
Generators enabled typed linting when either option was `true`, and the migrated defaults keep that result. `setParserOptionsProject: true` becomes `enableTypedLinting: true`, and `setParserOptionsProject: false` is dropped. When the options are set in several places (nested and flat keys, `nx.json`, `angular.json`, `project.json` and `package.json`), the migration rewrites each one so the merged default doesn't change.
|
|
13
|
+
|
|
14
|
+
The migration doesn't update scripts that pass `--setParserOptionsProject` to `nx g`. Pass `--enableTypedLinting` instead. Most generators ignore the removed flag without an error, so an unchanged script generates projects without typed linting.
|
|
15
|
+
|
|
16
|
+
#### Sample code changes
|
|
17
|
+
|
|
18
|
+
##### Before
|
|
19
|
+
|
|
20
|
+
```json title="nx.json"
|
|
21
|
+
{
|
|
22
|
+
"generators": {
|
|
23
|
+
"@nx/react:library": {
|
|
24
|
+
"setParserOptionsProject": true
|
|
25
|
+
},
|
|
26
|
+
"@nx/node": {
|
|
27
|
+
"application": {
|
|
28
|
+
"setParserOptionsProject": false,
|
|
29
|
+
"framework": "express"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
##### After
|
|
37
|
+
|
|
38
|
+
```json title="nx.json"
|
|
39
|
+
{
|
|
40
|
+
"generators": {
|
|
41
|
+
"@nx/react:library": {
|
|
42
|
+
"enableTypedLinting": true
|
|
43
|
+
},
|
|
44
|
+
"@nx/node": {
|
|
45
|
+
"application": {
|
|
46
|
+
"framework": "express"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
A project default of `enableTypedLinting: false` didn't turn typed linting off while `nx.json` set `setParserOptionsProject: true`, so the migration sets it to `true`:
|
|
54
|
+
|
|
55
|
+
##### Before
|
|
56
|
+
|
|
57
|
+
```json title="libs/my-lib/project.json"
|
|
58
|
+
{
|
|
59
|
+
"generators": {
|
|
60
|
+
"@nx/react:library": {
|
|
61
|
+
"enableTypedLinting": false
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
##### After
|
|
68
|
+
|
|
69
|
+
```json title="libs/my-lib/project.json"
|
|
70
|
+
{
|
|
71
|
+
"generators": {
|
|
72
|
+
"@nx/react:library": {
|
|
73
|
+
"enableTypedLinting": true
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
```
|
package/migrations.json
CHANGED
|
@@ -41,6 +41,12 @@
|
|
|
41
41
|
"implementation": "./dist/src/migrations/update-24-0-0/remove-deprecated-executors",
|
|
42
42
|
"prompt": "./dist/src/migrations/update-24-0-0/finish-inferred-conversion.md",
|
|
43
43
|
"documentation": "./dist/src/migrations/update-24-0-0/remove-deprecated-executors.md"
|
|
44
|
+
},
|
|
45
|
+
"update-24-0-0-replace-set-parser-options-project": {
|
|
46
|
+
"version": "24.0.0-beta.5",
|
|
47
|
+
"description": "Replaces the removed `setParserOptionsProject` generator option with `enableTypedLinting` in the generator defaults of `nx.json` and project configuration, so generators resolve typed linting as before.",
|
|
48
|
+
"implementation": "./dist/src/migrations/update-24-0-0/replace-set-parser-options-project",
|
|
49
|
+
"documentation": "./dist/src/migrations/update-24-0-0/replace-set-parser-options-project.md"
|
|
44
50
|
}
|
|
45
51
|
},
|
|
46
52
|
"packageJsonUpdates": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/eslint",
|
|
3
|
-
"version": "24.0.0-
|
|
3
|
+
"version": "24.0.0-rc.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"files": [
|
|
@@ -71,19 +71,19 @@
|
|
|
71
71
|
}
|
|
72
72
|
},
|
|
73
73
|
"peerDependencies": {
|
|
74
|
-
"@nx/jest": "24.0.0-
|
|
74
|
+
"@nx/jest": "24.0.0-rc.0",
|
|
75
75
|
"@zkochan/js-yaml": "0.0.7",
|
|
76
76
|
"eslint": "^9.0.0 || ^10.0.0"
|
|
77
77
|
},
|
|
78
78
|
"dependencies": {
|
|
79
|
-
"@nx/devkit": "24.0.0-
|
|
80
|
-
"@nx/js": "24.0.0-
|
|
79
|
+
"@nx/devkit": "24.0.0-rc.0",
|
|
80
|
+
"@nx/js": "24.0.0-rc.0",
|
|
81
81
|
"semver": "^7.6.3",
|
|
82
82
|
"tslib": "^2.3.0",
|
|
83
83
|
"typescript": "~6.0.3"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
|
-
"nx": "24.0.0-
|
|
86
|
+
"nx": "24.0.0-rc.0"
|
|
87
87
|
},
|
|
88
88
|
"peerDependenciesMeta": {
|
|
89
89
|
"@nx/jest": {
|