@nx/eslint 23.0.0-pr.35465.2bc2643 → 23.0.0-rc.1
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/{index.d.ts → dist/index.d.ts} +0 -1
- package/dist/internal.d.ts +7 -0
- package/dist/internal.js +33 -0
- package/{plugin.d.ts → dist/plugin.d.ts} +0 -1
- package/{src → dist/src}/executors/lint/lint.impl.d.ts +0 -1
- package/{src → dist/src}/executors/lint/lint.impl.js +9 -6
- package/{src → dist/src}/executors/lint/schema.json +1 -0
- package/{src → dist/src}/executors/lint/utility/eslint-utils.d.ts +0 -1
- package/{src → dist/src}/generators/convert-to-flat-config/converters/json-converter.d.ts +1 -1
- package/{src → dist/src}/generators/convert-to-flat-config/converters/json-converter.js +76 -16
- package/{src → dist/src}/generators/convert-to-flat-config/generator.d.ts +0 -1
- package/dist/src/generators/convert-to-flat-config/generator.js +262 -0
- package/{src → dist/src}/generators/convert-to-flat-config/schema.json +7 -0
- package/{src → dist/src}/generators/convert-to-inferred/convert-to-inferred.d.ts +0 -1
- package/{src → dist/src}/generators/convert-to-inferred/convert-to-inferred.js +6 -5
- package/{src → dist/src}/generators/convert-to-inferred/lib/target-options-map.d.ts +0 -1
- package/{src → dist/src}/generators/init/global-eslint-config.d.ts +0 -1
- package/{src → dist/src}/generators/init/init-migration.d.ts +0 -1
- package/{src → dist/src}/generators/init/init-migration.js +4 -3
- package/{src → dist/src}/generators/init/init.d.ts +0 -1
- package/{src → dist/src}/generators/init/init.js +34 -18
- package/{src → dist/src}/generators/init/schema.json +1 -1
- package/{src → dist/src}/generators/lint-project/lint-project.d.ts +0 -1
- package/{src → dist/src}/generators/lint-project/lint-project.js +4 -2
- package/{src → dist/src}/generators/lint-project/setup-root-eslint.d.ts +0 -1
- package/{src → dist/src}/generators/lint-project/setup-root-eslint.js +21 -17
- package/{src → dist/src}/generators/utils/eslint-file.d.ts +0 -1
- package/{src → dist/src}/generators/utils/eslint-file.js +3 -5
- package/{src → dist/src}/generators/utils/eslint-targets.d.ts +0 -1
- package/dist/src/generators/utils/eslint-targets.js +17 -0
- package/{src → dist/src}/generators/utils/flat-config/ast-utils.d.ts +1 -2
- package/{src → dist/src}/generators/utils/flat-config/ast-utils.js +19 -16
- package/{src → dist/src}/generators/utils/flat-config/path-utils.d.ts +0 -1
- package/{src → dist/src}/generators/utils/linter.d.ts +0 -1
- package/{src → dist/src}/generators/utils/plugin.d.ts +0 -1
- package/{src → dist/src}/generators/workspace-rule/files/__name__.spec.ts__tmpl__ +1 -1
- package/{src → dist/src}/generators/workspace-rule/workspace-rule.d.ts +0 -1
- package/{src → dist/src}/generators/workspace-rule/workspace-rule.js +17 -5
- package/{src → dist/src}/generators/workspace-rules-project/workspace-rules-project.d.ts +0 -1
- package/{src → dist/src}/generators/workspace-rules-project/workspace-rules-project.js +28 -10
- package/{src → dist/src}/migrations/update-21-6-0/update-executor-lint-inputs.d.ts +0 -1
- package/{src → dist/src}/migrations/update-21-6-0/update-executor-lint-inputs.js +9 -3
- package/dist/src/migrations/update-23-0-0/migrate-create-nodes-v2-to-create-nodes.d.ts +9 -0
- package/dist/src/migrations/update-23-0-0/migrate-create-nodes-v2-to-create-nodes.js +223 -0
- package/dist/src/migrations/update-23-0-0/migrate-create-nodes-v2-to-create-nodes.md +25 -0
- package/dist/src/migrations/update-23-0-0/rewrite-internal-subpath-imports.d.ts +3 -0
- package/dist/src/migrations/update-23-0-0/rewrite-internal-subpath-imports.js +198 -0
- package/dist/src/plugins/plugin.d.ts +7 -0
- package/{src → dist/src}/plugins/plugin.js +30 -28
- package/dist/src/utils/assert-supported-eslint-version.d.ts +2 -0
- package/dist/src/utils/assert-supported-eslint-version.js +12 -0
- package/{src → dist/src}/utils/config-file.d.ts +0 -1
- package/dist/src/utils/deprecation.d.ts +5 -0
- package/dist/src/utils/deprecation.js +25 -0
- package/{src → dist/src}/utils/flat-config.d.ts +0 -1
- package/{src → dist/src}/utils/resolve-eslint-class.d.ts +0 -1
- package/dist/src/utils/resolve-eslint-class.js +28 -0
- package/{src → dist/src}/utils/rules-requiring-type-checking.d.ts +0 -1
- package/dist/src/utils/versions.d.ts +17 -0
- package/dist/src/utils/versions.js +49 -0
- package/{src → dist/src}/utils/workspace-lint-rules.d.ts +0 -1
- package/executors.json +2 -2
- package/generators.json +10 -10
- package/migrations.json +12 -83
- package/package.json +50 -11
- package/index.d.ts.map +0 -1
- package/plugin.d.ts.map +0 -1
- package/src/executors/lint/lint.impl.d.ts.map +0 -1
- package/src/executors/lint/utility/eslint-utils.d.ts.map +0 -1
- package/src/generators/convert-to-flat-config/converters/json-converter.d.ts.map +0 -1
- package/src/generators/convert-to-flat-config/generator.d.ts.map +0 -1
- package/src/generators/convert-to-flat-config/generator.js +0 -162
- package/src/generators/convert-to-inferred/convert-to-inferred.d.ts.map +0 -1
- package/src/generators/convert-to-inferred/lib/target-options-map.d.ts.map +0 -1
- package/src/generators/init/global-eslint-config.d.ts.map +0 -1
- package/src/generators/init/init-migration.d.ts.map +0 -1
- package/src/generators/init/init.d.ts.map +0 -1
- package/src/generators/lint-project/lint-project.d.ts.map +0 -1
- package/src/generators/lint-project/setup-root-eslint.d.ts.map +0 -1
- package/src/generators/utils/eslint-file.d.ts.map +0 -1
- package/src/generators/utils/eslint-targets.d.ts.map +0 -1
- package/src/generators/utils/eslint-targets.js +0 -17
- package/src/generators/utils/flat-config/ast-utils.d.ts.map +0 -1
- package/src/generators/utils/flat-config/path-utils.d.ts.map +0 -1
- package/src/generators/utils/linter.d.ts.map +0 -1
- package/src/generators/utils/plugin.d.ts.map +0 -1
- package/src/generators/workspace-rule/workspace-rule.d.ts.map +0 -1
- package/src/generators/workspace-rules-project/workspace-rules-project.d.ts.map +0 -1
- package/src/migrations/update-20-2-0/update-typescript-eslint-v8-13-0.d.ts +0 -3
- package/src/migrations/update-20-2-0/update-typescript-eslint-v8-13-0.d.ts.map +0 -1
- package/src/migrations/update-20-2-0/update-typescript-eslint-v8-13-0.js +0 -23
- package/src/migrations/update-20-3-0/add-file-extensions-to-overrides.d.ts +0 -3
- package/src/migrations/update-20-3-0/add-file-extensions-to-overrides.d.ts.map +0 -1
- package/src/migrations/update-20-3-0/add-file-extensions-to-overrides.js +0 -50
- package/src/migrations/update-21-6-0/update-executor-lint-inputs.d.ts.map +0 -1
- package/src/plugins/plugin.d.ts +0 -8
- package/src/plugins/plugin.d.ts.map +0 -1
- package/src/utils/config-file.d.ts.map +0 -1
- package/src/utils/flat-config.d.ts.map +0 -1
- package/src/utils/resolve-eslint-class.d.ts.map +0 -1
- package/src/utils/resolve-eslint-class.js +0 -61
- package/src/utils/rules-requiring-type-checking.d.ts.map +0 -1
- package/src/utils/version-utils.d.ts +0 -5
- package/src/utils/version-utils.d.ts.map +0 -1
- package/src/utils/version-utils.js +0 -49
- package/src/utils/versions.d.ts +0 -10
- package/src/utils/versions.d.ts.map +0 -1
- package/src/utils/versions.js +0 -13
- package/src/utils/workspace-lint-rules.d.ts.map +0 -1
- /package/{LICENSE → dist/LICENSE} +0 -0
- /package/{index.js → dist/index.js} +0 -0
- /package/{plugin.js → dist/plugin.js} +0 -0
- /package/{src → dist/src}/executors/lint/schema.d.ts +0 -0
- /package/{src → dist/src}/executors/lint/utility/eslint-utils.js +0 -0
- /package/{src → dist/src}/generators/convert-to-flat-config/schema.d.ts +0 -0
- /package/{src → dist/src}/generators/convert-to-inferred/lib/target-options-map.js +0 -0
- /package/{src → dist/src}/generators/convert-to-inferred/schema.json +0 -0
- /package/{src → dist/src}/generators/init/global-eslint-config.js +0 -0
- /package/{src → dist/src}/generators/utils/flat-config/path-utils.js +0 -0
- /package/{src → dist/src}/generators/utils/linter.js +0 -0
- /package/{src → dist/src}/generators/utils/plugin.js +0 -0
- /package/{src → dist/src}/generators/workspace-rule/files/__name__.ts__tmpl__ +0 -0
- /package/{src → dist/src}/generators/workspace-rule/schema.json +0 -0
- /package/{src → dist/src}/generators/workspace-rules-project/files/index.ts__tmpl__ +0 -0
- /package/{src → dist/src}/generators/workspace-rules-project/files/tsconfig.json__tmpl__ +0 -0
- /package/{src → dist/src}/generators/workspace-rules-project/files/tsconfig.lint.json__tmpl__ +0 -0
- /package/{src → dist/src}/generators/workspace-rules-project/schema.json +0 -0
- /package/{src → dist/src}/utils/config-file.js +0 -0
- /package/{src → dist/src}/utils/flat-config.js +0 -0
- /package/{src → dist/src}/utils/rules-requiring-type-checking.js +0 -0
- /package/{src → dist/src}/utils/workspace-lint-rules.js +0 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { addExtendsToLintConfig, addIgnoresToLintConfig, addOverrideToLintConfig, addPluginsToLintConfig, addPredefinedConfigToFlatLintConfig, findEslintFile, isEslintConfigSupported, lintConfigHasOverride, replaceOverridesInLintConfig, updateOverrideInLintConfig, updateRelativePathsInConfig, } from './src/generators/utils/eslint-file';
|
|
2
|
+
export { addImportToFlatConfig } from './src/generators/utils/flat-config/ast-utils';
|
|
3
|
+
export { useFlatConfig } from './src/utils/flat-config';
|
|
4
|
+
export { javaScriptOverride, typeScriptOverride, } from './src/generators/init/global-eslint-config';
|
|
5
|
+
export { setupRootEsLint } from './src/generators/lint-project/setup-root-eslint';
|
|
6
|
+
export { getInstalledEslintVersion, typescriptESLintVersion, versions, } from './src/utils/versions';
|
|
7
|
+
export type { Schema } from './src/executors/lint/schema';
|
package/dist/internal.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Semi-private surface for first-party Nx packages.
|
|
3
|
+
//
|
|
4
|
+
// External plugins should NOT import from here — this entry is curated for
|
|
5
|
+
// internal consumers and may change without semver protection. Mirrors
|
|
6
|
+
// `@nx/devkit/internal`.
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.versions = exports.typescriptESLintVersion = exports.getInstalledEslintVersion = exports.setupRootEsLint = exports.typeScriptOverride = exports.javaScriptOverride = exports.useFlatConfig = exports.addImportToFlatConfig = exports.updateRelativePathsInConfig = exports.updateOverrideInLintConfig = exports.replaceOverridesInLintConfig = exports.lintConfigHasOverride = exports.isEslintConfigSupported = exports.findEslintFile = exports.addPredefinedConfigToFlatLintConfig = exports.addPluginsToLintConfig = exports.addOverrideToLintConfig = exports.addIgnoresToLintConfig = exports.addExtendsToLintConfig = void 0;
|
|
9
|
+
var eslint_file_1 = require("./src/generators/utils/eslint-file");
|
|
10
|
+
Object.defineProperty(exports, "addExtendsToLintConfig", { enumerable: true, get: function () { return eslint_file_1.addExtendsToLintConfig; } });
|
|
11
|
+
Object.defineProperty(exports, "addIgnoresToLintConfig", { enumerable: true, get: function () { return eslint_file_1.addIgnoresToLintConfig; } });
|
|
12
|
+
Object.defineProperty(exports, "addOverrideToLintConfig", { enumerable: true, get: function () { return eslint_file_1.addOverrideToLintConfig; } });
|
|
13
|
+
Object.defineProperty(exports, "addPluginsToLintConfig", { enumerable: true, get: function () { return eslint_file_1.addPluginsToLintConfig; } });
|
|
14
|
+
Object.defineProperty(exports, "addPredefinedConfigToFlatLintConfig", { enumerable: true, get: function () { return eslint_file_1.addPredefinedConfigToFlatLintConfig; } });
|
|
15
|
+
Object.defineProperty(exports, "findEslintFile", { enumerable: true, get: function () { return eslint_file_1.findEslintFile; } });
|
|
16
|
+
Object.defineProperty(exports, "isEslintConfigSupported", { enumerable: true, get: function () { return eslint_file_1.isEslintConfigSupported; } });
|
|
17
|
+
Object.defineProperty(exports, "lintConfigHasOverride", { enumerable: true, get: function () { return eslint_file_1.lintConfigHasOverride; } });
|
|
18
|
+
Object.defineProperty(exports, "replaceOverridesInLintConfig", { enumerable: true, get: function () { return eslint_file_1.replaceOverridesInLintConfig; } });
|
|
19
|
+
Object.defineProperty(exports, "updateOverrideInLintConfig", { enumerable: true, get: function () { return eslint_file_1.updateOverrideInLintConfig; } });
|
|
20
|
+
Object.defineProperty(exports, "updateRelativePathsInConfig", { enumerable: true, get: function () { return eslint_file_1.updateRelativePathsInConfig; } });
|
|
21
|
+
var ast_utils_1 = require("./src/generators/utils/flat-config/ast-utils");
|
|
22
|
+
Object.defineProperty(exports, "addImportToFlatConfig", { enumerable: true, get: function () { return ast_utils_1.addImportToFlatConfig; } });
|
|
23
|
+
var flat_config_1 = require("./src/utils/flat-config");
|
|
24
|
+
Object.defineProperty(exports, "useFlatConfig", { enumerable: true, get: function () { return flat_config_1.useFlatConfig; } });
|
|
25
|
+
var global_eslint_config_1 = require("./src/generators/init/global-eslint-config");
|
|
26
|
+
Object.defineProperty(exports, "javaScriptOverride", { enumerable: true, get: function () { return global_eslint_config_1.javaScriptOverride; } });
|
|
27
|
+
Object.defineProperty(exports, "typeScriptOverride", { enumerable: true, get: function () { return global_eslint_config_1.typeScriptOverride; } });
|
|
28
|
+
var setup_root_eslint_1 = require("./src/generators/lint-project/setup-root-eslint");
|
|
29
|
+
Object.defineProperty(exports, "setupRootEsLint", { enumerable: true, get: function () { return setup_root_eslint_1.setupRootEsLint; } });
|
|
30
|
+
var versions_1 = require("./src/utils/versions");
|
|
31
|
+
Object.defineProperty(exports, "getInstalledEslintVersion", { enumerable: true, get: function () { return versions_1.getInstalledEslintVersion; } });
|
|
32
|
+
Object.defineProperty(exports, "typescriptESLintVersion", { enumerable: true, get: function () { return versions_1.typescriptESLintVersion; } });
|
|
33
|
+
Object.defineProperty(exports, "versions", { enumerable: true, get: function () { return versions_1.versions; } });
|
|
@@ -2,12 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = run;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
5
6
|
const fs_1 = require("fs");
|
|
6
7
|
const utils_1 = require("nx/src/tasks-runner/utils");
|
|
7
8
|
const path_1 = require("path");
|
|
9
|
+
const semver_1 = require("semver");
|
|
8
10
|
const config_file_1 = require("../../utils/config-file");
|
|
11
|
+
const deprecation_1 = require("../../utils/deprecation");
|
|
12
|
+
const versions_1 = require("../../utils/versions");
|
|
9
13
|
const eslint_utils_1 = require("./utility/eslint-utils");
|
|
10
14
|
async function run(options, context) {
|
|
15
|
+
(0, deprecation_1.warnEslintExecutorDeprecation)();
|
|
11
16
|
// hasTypeAwareRules is deprecated and no longer used, delete it so it's not passed to ESLint
|
|
12
17
|
delete options.hasTypeAwareRules;
|
|
13
18
|
const systemRoot = context.root;
|
|
@@ -42,12 +47,10 @@ async function run(options, context) {
|
|
|
42
47
|
? (0, path_1.resolve)(systemRoot, normalizedOptions.eslintConfig)
|
|
43
48
|
: undefined;
|
|
44
49
|
const { eslint, ESLint } = await (0, eslint_utils_1.resolveAndInstantiateESLint)(eslintConfigPath, normalizedOptions, hasFlatConfig);
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
(Number(version[0]) === 7 && Number(version[1]) < 6)) {
|
|
50
|
-
throw new Error('ESLint must be version 7.6 or higher.');
|
|
50
|
+
(0, internal_1.assertSupportedInstalledPackageVersion)('eslint', versions_1.minSupportedEslintVersion);
|
|
51
|
+
const installedEslintVersion = (0, internal_1.getInstalledPackageVersion)('eslint');
|
|
52
|
+
if (installedEslintVersion && (0, semver_1.major)(installedEslintVersion) === 8) {
|
|
53
|
+
(0, deprecation_1.warnEslintV8Deprecation)();
|
|
51
54
|
}
|
|
52
55
|
if (printConfig) {
|
|
53
56
|
try {
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
"description": "ESLint Lint Target.",
|
|
7
7
|
"cli": "nx",
|
|
8
8
|
"type": "object",
|
|
9
|
+
"x-deprecated": "The `@nx/eslint:lint` executor is deprecated and will be removed in Nx v24. Run `nx g @nx/eslint:convert-to-inferred` to migrate to the `@nx/eslint/plugin` inferred plugin. See https://nx.dev/docs/guides/tasks--caching/convert-to-inferred for details.",
|
|
9
10
|
"properties": {
|
|
10
11
|
"eslintConfig": {
|
|
11
12
|
"type": "string",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Tree } from '@nx/devkit';
|
|
2
2
|
import { ESLint } from 'eslint';
|
|
3
|
+
export declare function renameLegacyEslintrcFile(path: string, format: 'mjs' | 'cjs'): string;
|
|
3
4
|
/**
|
|
4
5
|
* Converts an ESLint JSON config to a flat config.
|
|
5
6
|
* Deletes the original file along with .eslintignore if it exists.
|
|
@@ -9,4 +10,3 @@ export declare function convertEslintJsonToFlatConfig(tree: Tree, root: string,
|
|
|
9
10
|
addESLintRC: boolean;
|
|
10
11
|
addESLintJS: boolean;
|
|
11
12
|
};
|
|
12
|
-
//# sourceMappingURL=json-converter.d.ts.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.renameLegacyEslintrcFile = renameLegacyEslintrcFile;
|
|
3
4
|
exports.convertEslintJsonToFlatConfig = convertEslintJsonToFlatConfig;
|
|
4
5
|
const tslib_1 = require("tslib");
|
|
5
6
|
const devkit_1 = require("@nx/devkit");
|
|
@@ -7,6 +8,57 @@ const ts = tslib_1.__importStar(require("typescript"));
|
|
|
7
8
|
const ast_utils_1 = require("../../utils/flat-config/ast-utils");
|
|
8
9
|
const eslint_file_1 = require("../../utils/eslint-file");
|
|
9
10
|
const path_utils_1 = require("../../utils/flat-config/path-utils");
|
|
11
|
+
// Rewrites legacy `.eslintrc[.base][.json]` / `.eslintignore` filenames to their flat-config
|
|
12
|
+
// counterparts. Used for `extends` local paths, rule option values that embed these filenames,
|
|
13
|
+
// and nx.json / project.json input globs that referenced the deleted files. Accepts
|
|
14
|
+
// extensionless `.eslintrc` since ESLint treats that as JSON by convention.
|
|
15
|
+
function renameLegacyEslintrcFile(path, format) {
|
|
16
|
+
return path
|
|
17
|
+
.replace(/(^|.*?)\.eslintrc(\.base)?(\.json)?$/, `$1eslint$2.config.${format}`)
|
|
18
|
+
.replace(/(^|.*?)\.eslintignore$/, `$1eslint.config.${format}`);
|
|
19
|
+
}
|
|
20
|
+
// In flat config, `@nx/workspace/<rule>` is parsed as plugin `@nx/workspace`, rule `<rule>`.
|
|
21
|
+
// The `@nx` plugin already exposes workspace rules under both `workspace/<rule>` and `workspace-<rule>` keys.
|
|
22
|
+
// Rewriting to `@nx/workspace-<rule>` makes ESLint resolve them via the already-registered `@nx` plugin.
|
|
23
|
+
function renameLegacyWorkspaceRules(rules) {
|
|
24
|
+
const renamed = {};
|
|
25
|
+
for (const [key, value] of Object.entries(rules)) {
|
|
26
|
+
const newKey = key.startsWith('@nx/workspace/')
|
|
27
|
+
? '@nx/workspace-' + key.slice('@nx/workspace/'.length)
|
|
28
|
+
: key;
|
|
29
|
+
renamed[newKey] = value;
|
|
30
|
+
}
|
|
31
|
+
return renamed;
|
|
32
|
+
}
|
|
33
|
+
// Rewrites references to the legacy `.eslintrc[.base].json` / `.eslintignore` that may appear
|
|
34
|
+
// inside rule option values (e.g. `@nx/dependency-checks`'s `ignoredFiles`) to point at the
|
|
35
|
+
// generated flat-config files instead. Without this, rule options keep pointing at files that
|
|
36
|
+
// no longer exist after the conversion.
|
|
37
|
+
function rewriteStaleEslintrcRefs(value, format) {
|
|
38
|
+
if (typeof value === 'string') {
|
|
39
|
+
return renameLegacyEslintrcFile(value, format);
|
|
40
|
+
}
|
|
41
|
+
if (Array.isArray(value)) {
|
|
42
|
+
const mapped = value.map((v) => rewriteStaleEslintrcRefs(v, format));
|
|
43
|
+
// Rewriting may collapse distinct strings (e.g. `.eslintrc.json` and
|
|
44
|
+
// `.eslintrc.base.json`) into identical entries; dedupe string arrays.
|
|
45
|
+
if (mapped.every((v) => typeof v === 'string')) {
|
|
46
|
+
return Array.from(new Set(mapped));
|
|
47
|
+
}
|
|
48
|
+
return mapped;
|
|
49
|
+
}
|
|
50
|
+
if (value && typeof value === 'object') {
|
|
51
|
+
const out = {};
|
|
52
|
+
for (const [k, v] of Object.entries(value)) {
|
|
53
|
+
out[k] = rewriteStaleEslintrcRefs(v, format);
|
|
54
|
+
}
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
function preprocessRules(rules, format) {
|
|
60
|
+
return rewriteStaleEslintrcRefs(renameLegacyWorkspaceRules(rules), format);
|
|
61
|
+
}
|
|
10
62
|
/**
|
|
11
63
|
* Converts an ESLint JSON config to a flat config.
|
|
12
64
|
* Deletes the original file along with .eslintignore if it exists.
|
|
@@ -18,10 +70,17 @@ function convertEslintJsonToFlatConfig(tree, root, config, ignorePaths, format)
|
|
|
18
70
|
let isESLintJSNeeded = false;
|
|
19
71
|
let combinedConfig = [];
|
|
20
72
|
let languageOptions = [];
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
73
|
+
if (config.rules) {
|
|
74
|
+
config.rules = preprocessRules(config.rules, format);
|
|
75
|
+
}
|
|
76
|
+
if (config.overrides) {
|
|
77
|
+
config.overrides = config.overrides.map((override) => override.rules
|
|
78
|
+
? {
|
|
79
|
+
...override,
|
|
80
|
+
rules: preprocessRules(override.rules, format),
|
|
81
|
+
}
|
|
82
|
+
: override);
|
|
83
|
+
}
|
|
25
84
|
if (config.extends) {
|
|
26
85
|
const extendsResult = addExtends(importsMap, exportElements, config, format);
|
|
27
86
|
isFlatCompatNeeded = extendsResult.isFlatCompatNeeded;
|
|
@@ -101,28 +160,30 @@ function convertEslintJsonToFlatConfig(tree, root, config, ignorePaths, format)
|
|
|
101
160
|
if (Object.keys(remainingRest).length > 0 || hasNonEmptyRules) {
|
|
102
161
|
if (remainingOverride.env ||
|
|
103
162
|
remainingOverride.extends ||
|
|
104
|
-
remainingOverride.plugins
|
|
105
|
-
remainingOverride.parser) {
|
|
163
|
+
remainingOverride.plugins) {
|
|
106
164
|
isFlatCompatNeeded = true;
|
|
107
165
|
}
|
|
108
|
-
exportElements.push((0, ast_utils_1.generateFlatOverride)(remainingOverride, format));
|
|
166
|
+
exportElements.push((0, ast_utils_1.generateFlatOverride)(remainingOverride, format, importsMap));
|
|
109
167
|
}
|
|
110
168
|
return;
|
|
111
169
|
}
|
|
112
170
|
}
|
|
113
|
-
if (override.env ||
|
|
114
|
-
override.extends ||
|
|
115
|
-
override.plugins ||
|
|
116
|
-
override.parser) {
|
|
171
|
+
if (override.env || override.extends || override.plugins) {
|
|
117
172
|
isFlatCompatNeeded = true;
|
|
118
173
|
}
|
|
119
|
-
exportElements.push((0, ast_utils_1.generateFlatOverride)(override, format));
|
|
174
|
+
exportElements.push((0, ast_utils_1.generateFlatOverride)(override, format, importsMap));
|
|
120
175
|
});
|
|
121
176
|
}
|
|
122
177
|
if (config.ignorePatterns) {
|
|
123
178
|
const patterns = (Array.isArray(config.ignorePatterns)
|
|
124
179
|
? config.ignorePatterns
|
|
125
|
-
: [config.ignorePatterns]).filter((pattern) =>
|
|
180
|
+
: [config.ignorePatterns]).filter((pattern) =>
|
|
181
|
+
// Drop patterns that are meaningless in flat config. `'**/*'` and
|
|
182
|
+
// `'!**/*'` were eslintrc cascading toggles; `node_modules` is already
|
|
183
|
+
// ignored by default. Real negations like `['dist/**', '!dist/keep.js']`
|
|
184
|
+
// are preserved — flat config still supports un-ignoring within a
|
|
185
|
+
// broader ignores block.
|
|
186
|
+
!['**/*', '!**/*', 'node_modules'].includes(pattern));
|
|
126
187
|
if (patterns.length > 0) {
|
|
127
188
|
exportElements.push((0, ast_utils_1.generateAst)({
|
|
128
189
|
ignores: patterns.map((path) => (0, path_utils_1.mapFilePath)(path)),
|
|
@@ -165,11 +226,10 @@ function addExtends(importsMap, configBlocks, config, format) {
|
|
|
165
226
|
extendsConfig
|
|
166
227
|
.filter((imp) => imp.match(/^\.?(\.\/)/))
|
|
167
228
|
.forEach((imp, index) => {
|
|
168
|
-
if (imp.match(/\.eslintrc(
|
|
229
|
+
if (imp.match(/\.eslintrc(\.base)?(\.json)?$/)) {
|
|
169
230
|
const localName = index ? `baseConfig${index}` : 'baseConfig';
|
|
170
231
|
configBlocks.push((0, ast_utils_1.generateSpreadElement)(localName));
|
|
171
|
-
|
|
172
|
-
importsMap.set(newImport, localName);
|
|
232
|
+
importsMap.set(renameLegacyEslintrcFile(imp, format), localName);
|
|
173
233
|
}
|
|
174
234
|
else {
|
|
175
235
|
eslintrcConfigs.push(imp);
|
|
@@ -2,4 +2,3 @@ import { GeneratorCallback, Tree } from '@nx/devkit';
|
|
|
2
2
|
import { ConvertToFlatConfigGeneratorSchema } from './schema';
|
|
3
3
|
export declare function convertToFlatConfigGenerator(tree: Tree, options: ConvertToFlatConfigGeneratorSchema): Promise<void | GeneratorCallback>;
|
|
4
4
|
export default convertToFlatConfigGenerator;
|
|
5
|
-
//# sourceMappingURL=generator.d.ts.map
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertToFlatConfigGenerator = convertToFlatConfigGenerator;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const eslint_file_1 = require("../utils/eslint-file");
|
|
6
|
+
const plugin_1 = require("../utils/plugin");
|
|
7
|
+
const path_1 = require("path");
|
|
8
|
+
const assert_supported_eslint_version_1 = require("../../utils/assert-supported-eslint-version");
|
|
9
|
+
const versions_1 = require("../../utils/versions");
|
|
10
|
+
const json_converter_1 = require("./converters/json-converter");
|
|
11
|
+
async function convertToFlatConfigGenerator(tree, options) {
|
|
12
|
+
(0, assert_supported_eslint_version_1.assertSupportedEslintVersion)(tree);
|
|
13
|
+
const eslintFile = (0, eslint_file_1.findEslintFile)(tree);
|
|
14
|
+
if (!eslintFile) {
|
|
15
|
+
throw new Error('Could not find root eslint file');
|
|
16
|
+
}
|
|
17
|
+
if (eslintFile.endsWith('.js')) {
|
|
18
|
+
throw new Error('Only json and yaml eslint config files are supported for conversion');
|
|
19
|
+
}
|
|
20
|
+
options.eslintConfigFormat ??= 'mjs';
|
|
21
|
+
const eslintIgnoreFiles = new Set(['.eslintignore']);
|
|
22
|
+
// convert root eslint config to eslint.config.cjs or eslint.base.config.mjs based on eslintConfigFormat
|
|
23
|
+
convertRootToFlatConfig(tree, eslintFile, options.eslintConfigFormat);
|
|
24
|
+
// convert project eslint files to eslint.config.cjs
|
|
25
|
+
const projects = (0, devkit_1.getProjects)(tree);
|
|
26
|
+
for (const [project, projectConfig] of projects) {
|
|
27
|
+
convertProjectToFlatConfig(tree, project, projectConfig, (0, devkit_1.readNxJson)(tree), eslintIgnoreFiles, options.eslintConfigFormat);
|
|
28
|
+
}
|
|
29
|
+
// delete all .eslintignore files
|
|
30
|
+
for (const ignoreFile of eslintIgnoreFiles) {
|
|
31
|
+
tree.delete(ignoreFile);
|
|
32
|
+
}
|
|
33
|
+
// replace references in nx.json and project.json files
|
|
34
|
+
updateNxJsonConfig(tree, options.eslintConfigFormat);
|
|
35
|
+
updateProjectConfigsInputs(tree, options.eslintConfigFormat);
|
|
36
|
+
// install missing packages
|
|
37
|
+
if (!options.skipFormat) {
|
|
38
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
39
|
+
}
|
|
40
|
+
return () => (0, devkit_1.installPackagesTask)(tree);
|
|
41
|
+
}
|
|
42
|
+
exports.default = convertToFlatConfigGenerator;
|
|
43
|
+
function convertRootToFlatConfig(tree, eslintFile, format) {
|
|
44
|
+
if (/\.base\.(js|json|yml|yaml)$/.test(eslintFile)) {
|
|
45
|
+
convertConfigToFlatConfig(tree, '', eslintFile, `eslint.base.config.${format}`, format);
|
|
46
|
+
}
|
|
47
|
+
convertConfigToFlatConfig(tree, '', eslintFile.replace('.base.', '.'), `eslint.config.${format}`, format);
|
|
48
|
+
}
|
|
49
|
+
const ESLINT_LINT_EXECUTOR = '@nx/eslint:lint';
|
|
50
|
+
function isEslintTarget(target) {
|
|
51
|
+
return (target.executor === ESLINT_LINT_EXECUTOR ||
|
|
52
|
+
target.command?.includes('eslint'));
|
|
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
|
+
function convertProjectToFlatConfig(tree, project, projectConfig, nxJson, eslintIgnoreFiles, format) {
|
|
67
|
+
const eslintFile = (0, eslint_file_1.findEslintFile)(tree, projectConfig.root);
|
|
68
|
+
if (!eslintFile || eslintFile.endsWith('.js')) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
// Clean up obsolete target options and detect explicit ESLint targets
|
|
72
|
+
let ignorePath;
|
|
73
|
+
const eslintTargets = projectConfig.targets
|
|
74
|
+
? Object.keys(projectConfig.targets).filter((t) => isEslintTarget(projectConfig.targets[t]))
|
|
75
|
+
: [];
|
|
76
|
+
for (const target of eslintTargets) {
|
|
77
|
+
if (projectConfig.targets[target].options?.eslintConfig) {
|
|
78
|
+
delete projectConfig.targets[target].options.eslintConfig;
|
|
79
|
+
}
|
|
80
|
+
if (projectConfig.targets[target].options?.ignorePath) {
|
|
81
|
+
ignorePath = projectConfig.targets[target].options.ignorePath;
|
|
82
|
+
delete projectConfig.targets[target].options.ignorePath;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (eslintTargets.length > 0) {
|
|
86
|
+
(0, devkit_1.updateProjectConfiguration)(tree, project, projectConfig);
|
|
87
|
+
}
|
|
88
|
+
const hasEslintTargetDefaults = hasMatchingEslintTargetDefault(projectConfig, nxJson.targetDefaults);
|
|
89
|
+
if (eslintTargets.length === 0 &&
|
|
90
|
+
!hasEslintTargetDefaults &&
|
|
91
|
+
!(0, plugin_1.hasEslintPlugin)(tree)) {
|
|
92
|
+
devkit_1.logger.warn(`Skipping "${project}": found ${eslintFile} but no ESLint lint target detected. Convert manually if needed.`);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
convertConfigToFlatConfig(tree, projectConfig.root, eslintFile, `eslint.config.${format}`, format, ignorePath);
|
|
96
|
+
eslintIgnoreFiles.add(`${projectConfig.root}/.eslintignore`);
|
|
97
|
+
if (ignorePath) {
|
|
98
|
+
eslintIgnoreFiles.add(ignorePath);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// Rewrites input entries that reference legacy `.eslintrc[.base].json` / `.eslintignore`
|
|
102
|
+
// files to their flat-config counterparts, then dedupes so the rewrite doesn't produce
|
|
103
|
+
// duplicates of entries that already pointed at the flat config. Leaves non-string /
|
|
104
|
+
// non-fileset inputs (runtime/env/dependentTasksOutputFiles/etc.) untouched.
|
|
105
|
+
function rewriteLegacyInputs(inputs, format) {
|
|
106
|
+
const seenStrings = new Set();
|
|
107
|
+
const result = [];
|
|
108
|
+
for (const entry of inputs) {
|
|
109
|
+
if (typeof entry === 'string') {
|
|
110
|
+
const rewritten = (0, json_converter_1.renameLegacyEslintrcFile)(entry, format);
|
|
111
|
+
if (seenStrings.has(rewritten))
|
|
112
|
+
continue;
|
|
113
|
+
seenStrings.add(rewritten);
|
|
114
|
+
result.push(rewritten);
|
|
115
|
+
}
|
|
116
|
+
else if ('fileset' in entry) {
|
|
117
|
+
const rewritten = (0, json_converter_1.renameLegacyEslintrcFile)(entry.fileset, format);
|
|
118
|
+
// Preserve the original reference when nothing changed so downstream identity
|
|
119
|
+
// checks (e.g. `inputsEqual`) don't see a spurious mutation.
|
|
120
|
+
result.push(rewritten === entry.fileset ? entry : { ...entry, fileset: rewritten });
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
result.push(entry);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return result;
|
|
127
|
+
}
|
|
128
|
+
// Adds `value` to `inputs` (after rewriting) when the rewritten set doesn't already contain it.
|
|
129
|
+
function ensureInputPresent(inputs, value, format) {
|
|
130
|
+
const rewritten = rewriteLegacyInputs(inputs, format);
|
|
131
|
+
if (!rewritten.some((entry) => entry === value)) {
|
|
132
|
+
rewritten.push(value);
|
|
133
|
+
}
|
|
134
|
+
return rewritten;
|
|
135
|
+
}
|
|
136
|
+
// Updates nx.json: rewrites stale eslintrc/eslintignore references across all targetDefaults
|
|
137
|
+
// 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`.
|
|
140
|
+
function updateNxJsonConfig(tree, format) {
|
|
141
|
+
if (!tree.exists('nx.json')) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
(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
|
+
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
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (json.namedInputs) {
|
|
167
|
+
for (const [name, inputs] of Object.entries(json.namedInputs)) {
|
|
168
|
+
json.namedInputs[name] =
|
|
169
|
+
name === 'production'
|
|
170
|
+
? ensureInputPresent(inputs, `!{projectRoot}/eslint.config.${format}`, format)
|
|
171
|
+
: rewriteLegacyInputs(inputs, format);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return json;
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
// Walks every project's `targets.*.inputs` and `namedInputs.*`, rewriting stale references.
|
|
178
|
+
function updateProjectConfigsInputs(tree, format) {
|
|
179
|
+
for (const [project, projectConfig] of (0, devkit_1.getProjects)(tree)) {
|
|
180
|
+
let changed = false;
|
|
181
|
+
if (projectConfig.targets) {
|
|
182
|
+
for (const target of Object.values(projectConfig.targets)) {
|
|
183
|
+
if (!target.inputs)
|
|
184
|
+
continue;
|
|
185
|
+
const rewritten = rewriteLegacyInputs(target.inputs, format);
|
|
186
|
+
if (!inputsEqual(target.inputs, rewritten)) {
|
|
187
|
+
target.inputs = rewritten;
|
|
188
|
+
changed = true;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (projectConfig.namedInputs) {
|
|
193
|
+
for (const [name, inputs] of Object.entries(projectConfig.namedInputs)) {
|
|
194
|
+
const rewritten = rewriteLegacyInputs(inputs, format);
|
|
195
|
+
if (!inputsEqual(inputs, rewritten)) {
|
|
196
|
+
projectConfig.namedInputs[name] = rewritten;
|
|
197
|
+
changed = true;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (changed) {
|
|
202
|
+
(0, devkit_1.updateProjectConfiguration)(tree, project, projectConfig);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function inputsEqual(a, b) {
|
|
207
|
+
return a.length === b.length && a.every((entry, i) => entry === b[i]);
|
|
208
|
+
}
|
|
209
|
+
function convertConfigToFlatConfig(tree, root, source, target, format, ignorePath) {
|
|
210
|
+
const ignorePaths = ignorePath
|
|
211
|
+
? [ignorePath, `${root}/.eslintignore`]
|
|
212
|
+
: [`${root}/.eslintignore`];
|
|
213
|
+
// `.eslintrc` (no extension) is JSON by convention.
|
|
214
|
+
if (source.endsWith('.json') || (0, path_1.basename)(source) === '.eslintrc') {
|
|
215
|
+
const config = (0, devkit_1.readJson)(tree, `${root}/${source}`);
|
|
216
|
+
const conversionResult = (0, json_converter_1.convertEslintJsonToFlatConfig)(tree, root, config, ignorePaths, format);
|
|
217
|
+
return processConvertedConfig(tree, root, source, target, conversionResult);
|
|
218
|
+
}
|
|
219
|
+
if (source.endsWith('.yaml') || source.endsWith('.yml')) {
|
|
220
|
+
const originalContent = tree.read(`${root}/${source}`, 'utf-8');
|
|
221
|
+
const { load } = require('@zkochan/js-yaml');
|
|
222
|
+
const config = load(originalContent, {
|
|
223
|
+
json: true,
|
|
224
|
+
filename: source,
|
|
225
|
+
});
|
|
226
|
+
const conversionResult = (0, json_converter_1.convertEslintJsonToFlatConfig)(tree, root, config, ignorePaths, format);
|
|
227
|
+
return processConvertedConfig(tree, root, source, target, conversionResult);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
function processConvertedConfig(tree, root, source, target, { content, addESLintRC, addESLintJS, }) {
|
|
231
|
+
// remove original config file
|
|
232
|
+
tree.delete((0, path_1.join)(root, source));
|
|
233
|
+
// save new
|
|
234
|
+
tree.write((0, path_1.join)(root, target), content);
|
|
235
|
+
// Once converted to flat config, the workspace is on the v9 ESLint stack —
|
|
236
|
+
// install the latest typescript-eslint v8 lane explicitly rather than
|
|
237
|
+
// routing through `versions(tree)` which would pick the legacy lane based
|
|
238
|
+
// on the pre-conversion `eslintrc` workspace state.
|
|
239
|
+
const devDependencies = {
|
|
240
|
+
eslint: versions_1.eslintVersion,
|
|
241
|
+
'eslint-config-prettier': versions_1.eslintConfigPrettierVersion,
|
|
242
|
+
'typescript-eslint': versions_1.typescriptESLintVersion,
|
|
243
|
+
'@typescript-eslint/eslint-plugin': versions_1.typescriptESLintVersion,
|
|
244
|
+
'@typescript-eslint/parser': versions_1.typescriptESLintVersion,
|
|
245
|
+
};
|
|
246
|
+
if ((0, devkit_1.getDependencyVersionFromPackageJson)(tree, '@typescript-eslint/utils')) {
|
|
247
|
+
devDependencies['@typescript-eslint/utils'] = versions_1.typescriptESLintVersion;
|
|
248
|
+
}
|
|
249
|
+
if ((0, devkit_1.getDependencyVersionFromPackageJson)(tree, '@typescript-eslint/type-utils')) {
|
|
250
|
+
devDependencies['@typescript-eslint/type-utils'] = versions_1.typescriptESLintVersion;
|
|
251
|
+
}
|
|
252
|
+
// add missing packages
|
|
253
|
+
if (addESLintRC) {
|
|
254
|
+
devDependencies['@eslint/eslintrc'] = versions_1.eslintrcVersion;
|
|
255
|
+
}
|
|
256
|
+
if (addESLintJS) {
|
|
257
|
+
devDependencies['@eslint/js'] = versions_1.eslintVersion;
|
|
258
|
+
}
|
|
259
|
+
// Convert-to-flat-config is an opt-in "upgrade" — we intentionally overwrite
|
|
260
|
+
// existing pins to land the workspace on the latest flat-config-ready stack.
|
|
261
|
+
(0, devkit_1.addDependenciesToPackageJson)(tree, {}, devDependencies);
|
|
262
|
+
}
|
|
@@ -10,6 +10,13 @@
|
|
|
10
10
|
"description": "Skip formatting files.",
|
|
11
11
|
"default": false,
|
|
12
12
|
"x-priority": "internal"
|
|
13
|
+
},
|
|
14
|
+
"eslintConfigFormat": {
|
|
15
|
+
"type": "string",
|
|
16
|
+
"description": "The format of the generated ESLint flat config files.",
|
|
17
|
+
"enum": ["mjs", "cjs"],
|
|
18
|
+
"default": "mjs",
|
|
19
|
+
"x-priority": "internal"
|
|
13
20
|
}
|
|
14
21
|
},
|
|
15
22
|
"additionalProperties": false,
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.convertToInferred = convertToInferred;
|
|
4
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
4
5
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const executor_to_plugin_migrator_1 = require("@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator");
|
|
6
|
-
const plugin_migration_utils_1 = require("@nx/devkit/src/generators/plugin-migrations/plugin-migration-utils");
|
|
7
6
|
const posix_1 = require("node:path/posix");
|
|
8
7
|
const utils_1 = require("nx/src/tasks-runner/utils");
|
|
9
8
|
const plugin_1 = require("../../plugins/plugin");
|
|
9
|
+
const assert_supported_eslint_version_1 = require("../../utils/assert-supported-eslint-version");
|
|
10
10
|
const config_file_1 = require("../../utils/config-file");
|
|
11
11
|
const target_options_map_1 = require("./lib/target-options-map");
|
|
12
12
|
async function convertToInferred(tree, options) {
|
|
13
|
+
(0, assert_supported_eslint_version_1.assertSupportedEslintVersion)(tree);
|
|
13
14
|
const projectGraph = await (0, devkit_1.createProjectGraphAsync)();
|
|
14
|
-
const migratedProjects = await (0,
|
|
15
|
+
const migratedProjects = await (0, internal_1.migrateProjectExecutorsToPlugin)(tree, projectGraph, '@nx/eslint/plugin', plugin_1.createNodes, { targetName: 'lint' }, [
|
|
15
16
|
{
|
|
16
17
|
executors: ['@nx/eslint:lint', '@nrwl/linter:eslint'],
|
|
17
18
|
postTargetTransformer,
|
|
@@ -20,7 +21,7 @@ async function convertToInferred(tree, options) {
|
|
|
20
21
|
},
|
|
21
22
|
], options.project);
|
|
22
23
|
if (migratedProjects.size === 0) {
|
|
23
|
-
throw new
|
|
24
|
+
throw new internal_1.NoTargetsToMigrateError();
|
|
24
25
|
}
|
|
25
26
|
if (!options.skipFormat) {
|
|
26
27
|
await (0, devkit_1.formatFiles)(tree);
|
|
@@ -75,7 +76,7 @@ function postTargetTransformer(target, tree, projectDetails, inferredTargetConfi
|
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
78
|
if (target.outputs) {
|
|
78
|
-
(0,
|
|
79
|
+
(0, internal_1.processTargetOutputs)(target, [], inferredTargetConfiguration, {
|
|
79
80
|
projectName: projectDetails.projectName,
|
|
80
81
|
projectRoot: projectDetails.root,
|
|
81
82
|
});
|
|
@@ -27,4 +27,3 @@ export declare const javaScriptOverride: {
|
|
|
27
27
|
};
|
|
28
28
|
export declare const getGlobalEsLintConfiguration: (unitTestRunner?: string, rootProject?: boolean) => Linter.LegacyConfig;
|
|
29
29
|
export declare const getGlobalFlatEslintConfiguration: (format: "cjs" | "mjs", rootProject?: boolean) => string;
|
|
30
|
-
//# sourceMappingURL=global-eslint-config.d.ts.map
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import { GeneratorCallback, ProjectConfiguration, TargetConfiguration, Tree } from '@nx/devkit';
|
|
2
2
|
export declare function migrateConfigToMonorepoStyle(projects: ProjectConfiguration[], tree: Tree, unitTestRunner: string, eslintConfigFormat: 'mjs' | 'cjs', keepExistingVersions?: boolean): GeneratorCallback;
|
|
3
3
|
export declare function findLintTarget(project: ProjectConfiguration): TargetConfiguration;
|
|
4
|
-
//# sourceMappingURL=init-migration.d.ts.map
|
|
@@ -34,9 +34,10 @@ function migrateConfigToMonorepoStyle(projects, tree, unitTestRunner, eslintConf
|
|
|
34
34
|
else {
|
|
35
35
|
if ((0, flat_config_1.useFlatConfig)(tree)) {
|
|
36
36
|
// we need this for the compat
|
|
37
|
+
const { eslintVersion } = (0, versions_1.versions)(tree);
|
|
37
38
|
(0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
|
|
38
|
-
'@eslint/js':
|
|
39
|
-
}, undefined, keepExistingVersions);
|
|
39
|
+
'@eslint/js': eslintVersion,
|
|
40
|
+
}, undefined, keepExistingVersions ?? true);
|
|
40
41
|
tree.write(tree.exists(`eslint.config.${eslintConfigFormat}`)
|
|
41
42
|
? `eslint.base.config.${eslintConfigFormat}`
|
|
42
43
|
: `eslint.config.${eslintConfigFormat}`, (0, global_eslint_config_1.getGlobalFlatEslintConfiguration)(eslintConfigFormat));
|
|
@@ -77,7 +78,7 @@ function migrateConfigToMonorepoStyle(projects, tree, unitTestRunner, eslintConf
|
|
|
77
78
|
});
|
|
78
79
|
return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
|
|
79
80
|
'@nx/eslint-plugin': versions_1.nxVersion,
|
|
80
|
-
});
|
|
81
|
+
}, undefined, keepExistingVersions ?? true);
|
|
81
82
|
}
|
|
82
83
|
function findLintTarget(project) {
|
|
83
84
|
return Object.values(project.targets ?? {}).find((target) => target.executor === '@nx/eslint:lint' ||
|
|
@@ -8,4 +8,3 @@ export interface LinterInitOptions {
|
|
|
8
8
|
}
|
|
9
9
|
export declare function initEsLint(tree: Tree, options: LinterInitOptions): Promise<GeneratorCallback>;
|
|
10
10
|
export declare function lintInitGenerator(tree: Tree, options: LinterInitOptions): Promise<GeneratorCallback>;
|
|
11
|
-
//# sourceMappingURL=init.d.ts.map
|