@nrwl/linter 15.3.0-beta.1 → 15.3.0-beta.11
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +1 -1
- package/package.json +5 -5
- package/src/generators/init/global-eslint-config.d.ts +36 -0
- package/src/generators/init/global-eslint-config.js +77 -0
- package/src/generators/init/global-eslint-config.js.map +1 -0
- package/src/generators/init/init-migration.d.ts +3 -0
- package/src/generators/init/init-migration.js +68 -0
- package/src/generators/init/init-migration.js.map +1 -0
- package/src/generators/init/init.d.ts +1 -0
- package/src/generators/init/init.js +2 -72
- package/src/generators/init/init.js.map +1 -1
- package/src/generators/lint-project/lint-project.d.ts +2 -0
- package/src/generators/lint-project/lint-project.js +59 -2
- package/src/generators/lint-project/lint-project.js.map +1 -1
- package/src/generators/utils/eslint-file.d.ts +3 -2
- package/src/generators/utils/eslint-file.js +9 -3
- package/src/generators/utils/eslint-file.js.map +1 -1
package/CHANGELOG.md
CHANGED
@@ -3,6 +3,6 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
5
5
|
|
6
|
-
# [15.3.0-beta.
|
6
|
+
# [15.3.0-beta.11](https://github.com/nrwl/nx/compare/15.2.0...15.3.0-beta.11) (2022-12-01)
|
7
7
|
|
8
8
|
**Note:** Version bump only for package @nrwl/linter
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nrwl/linter",
|
3
|
-
"version": "15.3.0-beta.
|
3
|
+
"version": "15.3.0-beta.11",
|
4
4
|
"private": false,
|
5
5
|
"description": "The Linter plugin for Nx contains executors, generators and utilities used for linting JavaScript/TypeScript projects within an Nx workspace.",
|
6
6
|
"repository": {
|
@@ -33,10 +33,10 @@
|
|
33
33
|
"eslint": "^8.0.0"
|
34
34
|
},
|
35
35
|
"dependencies": {
|
36
|
-
"@nrwl/devkit": "15.3.0-beta.
|
37
|
-
"@nrwl/jest": "15.3.0-beta.
|
36
|
+
"@nrwl/devkit": "15.3.0-beta.11",
|
37
|
+
"@nrwl/jest": "15.3.0-beta.11",
|
38
38
|
"@phenomnomnominal/tsquery": "4.1.1",
|
39
|
-
"nx": "15.3.0-beta.
|
39
|
+
"nx": "15.3.0-beta.11",
|
40
40
|
"tmp": "~0.2.1",
|
41
41
|
"tslib": "^2.3.0"
|
42
42
|
},
|
@@ -49,5 +49,5 @@
|
|
49
49
|
"access": "public"
|
50
50
|
},
|
51
51
|
"types": "./index.d.ts",
|
52
|
-
"gitHead": "
|
52
|
+
"gitHead": "4c723de4448fef0b7d0da2f47af3b27d847b2816"
|
53
53
|
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import { ESLint, Linter as LinterType } from 'eslint';
|
2
|
+
/**
|
3
|
+
* This configuration is intended to apply to all TypeScript source files.
|
4
|
+
* See the eslint-plugin-nx package for what is in the referenced shareable config.
|
5
|
+
*/
|
6
|
+
export declare const globalTypeScriptOverrides: {
|
7
|
+
files: string[];
|
8
|
+
extends: string[];
|
9
|
+
/**
|
10
|
+
* Having an empty rules object present makes it more obvious to the user where they would
|
11
|
+
* extend things from if they needed to
|
12
|
+
*/
|
13
|
+
rules: {};
|
14
|
+
};
|
15
|
+
/**
|
16
|
+
* This configuration is intended to apply to all JavaScript source files.
|
17
|
+
* See the eslint-plugin-nx package for what is in the referenced shareable config.
|
18
|
+
*/
|
19
|
+
export declare const globalJavaScriptOverrides: {
|
20
|
+
files: string[];
|
21
|
+
extends: string[];
|
22
|
+
/**
|
23
|
+
* Having an empty rules object present makes it more obvious to the user where they would
|
24
|
+
* extend things from if they needed to
|
25
|
+
*/
|
26
|
+
rules: {};
|
27
|
+
};
|
28
|
+
/**
|
29
|
+
* This configuration is intended to apply to all "source code" (but not
|
30
|
+
* markup like HTML, or other custom file types like GraphQL)
|
31
|
+
*/
|
32
|
+
export declare const moduleBoundariesOverride: {
|
33
|
+
files: string[];
|
34
|
+
rules: LinterType.RulesRecord;
|
35
|
+
};
|
36
|
+
export declare const getGlobalEsLintConfiguration: (unitTestRunner?: string, rootProject?: boolean) => ESLint.ConfigData<LinterType.RulesRecord>;
|
@@ -0,0 +1,77 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getGlobalEsLintConfiguration = exports.moduleBoundariesOverride = exports.globalJavaScriptOverrides = exports.globalTypeScriptOverrides = void 0;
|
4
|
+
/**
|
5
|
+
* This configuration is intended to apply to all TypeScript source files.
|
6
|
+
* See the eslint-plugin-nx package for what is in the referenced shareable config.
|
7
|
+
*/
|
8
|
+
exports.globalTypeScriptOverrides = {
|
9
|
+
files: ['*.ts', '*.tsx'],
|
10
|
+
extends: ['plugin:@nrwl/nx/typescript'],
|
11
|
+
/**
|
12
|
+
* Having an empty rules object present makes it more obvious to the user where they would
|
13
|
+
* extend things from if they needed to
|
14
|
+
*/
|
15
|
+
rules: {},
|
16
|
+
};
|
17
|
+
/**
|
18
|
+
* This configuration is intended to apply to all JavaScript source files.
|
19
|
+
* See the eslint-plugin-nx package for what is in the referenced shareable config.
|
20
|
+
*/
|
21
|
+
exports.globalJavaScriptOverrides = {
|
22
|
+
files: ['*.js', '*.jsx'],
|
23
|
+
extends: ['plugin:@nrwl/nx/javascript'],
|
24
|
+
/**
|
25
|
+
* Having an empty rules object present makes it more obvious to the user where they would
|
26
|
+
* extend things from if they needed to
|
27
|
+
*/
|
28
|
+
rules: {},
|
29
|
+
};
|
30
|
+
/**
|
31
|
+
* This configuration is intended to apply to all "source code" (but not
|
32
|
+
* markup like HTML, or other custom file types like GraphQL)
|
33
|
+
*/
|
34
|
+
exports.moduleBoundariesOverride = {
|
35
|
+
files: ['*.ts', '*.tsx', '*.js', '*.jsx'],
|
36
|
+
rules: {
|
37
|
+
'@nrwl/nx/enforce-module-boundaries': [
|
38
|
+
'error',
|
39
|
+
{
|
40
|
+
enforceBuildableLibDependency: true,
|
41
|
+
allow: [],
|
42
|
+
depConstraints: [{ sourceTag: '*', onlyDependOnLibsWithTags: ['*'] }],
|
43
|
+
},
|
44
|
+
],
|
45
|
+
},
|
46
|
+
};
|
47
|
+
const getGlobalEsLintConfiguration = (unitTestRunner, rootProject) => {
|
48
|
+
const config = {
|
49
|
+
root: true,
|
50
|
+
ignorePatterns: rootProject ? ['!**/*'] : ['**/*'],
|
51
|
+
plugins: ['@nrwl/nx'],
|
52
|
+
/**
|
53
|
+
* We leverage ESLint's "overrides" capability so that we can set up a root config which will support
|
54
|
+
* all permutations of Nx workspaces across all frameworks, libraries and tools.
|
55
|
+
*
|
56
|
+
* The key point is that we need entirely different ESLint config to apply to different types of files,
|
57
|
+
* but we still want to share common config where possible.
|
58
|
+
*/
|
59
|
+
overrides: [
|
60
|
+
...(rootProject ? [] : [exports.moduleBoundariesOverride]),
|
61
|
+
exports.globalTypeScriptOverrides,
|
62
|
+
exports.globalJavaScriptOverrides,
|
63
|
+
],
|
64
|
+
};
|
65
|
+
if (unitTestRunner === 'jest') {
|
66
|
+
config.overrides.push({
|
67
|
+
files: ['*.spec.ts', '*.spec.tsx', '*.spec.js', '*.spec.jsx'],
|
68
|
+
env: {
|
69
|
+
jest: true,
|
70
|
+
},
|
71
|
+
rules: {},
|
72
|
+
});
|
73
|
+
}
|
74
|
+
return config;
|
75
|
+
};
|
76
|
+
exports.getGlobalEsLintConfiguration = getGlobalEsLintConfiguration;
|
77
|
+
//# sourceMappingURL=global-eslint-config.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"global-eslint-config.js","sourceRoot":"","sources":["../../../../../../packages/linter/src/generators/init/global-eslint-config.ts"],"names":[],"mappings":";;;AAEA;;;GAGG;AACU,QAAA,yBAAyB,GAAG;IACvC,KAAK,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC;IACxB,OAAO,EAAE,CAAC,4BAA4B,CAAC;IACvC;;;OAGG;IACH,KAAK,EAAE,EAAE;CACV,CAAC;AAEF;;;GAGG;AACU,QAAA,yBAAyB,GAAG;IACvC,KAAK,EAAE,CA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import { ProjectConfiguration, TargetConfiguration, Tree } from '@nrwl/devkit';
|
2
|
+
export declare function migrateConfigToMonorepoStyle(projects: ProjectConfiguration[], tree: Tree, unitTestRunner: string): void;
|
3
|
+
export declare function findLintTarget(project: ProjectConfiguration): TargetConfiguration;
|
@@ -0,0 +1,68 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.findLintTarget = exports.migrateConfigToMonorepoStyle = void 0;
|
4
|
+
const devkit_1 = require("@nrwl/devkit");
|
5
|
+
const path_1 = require("path");
|
6
|
+
const eslint_file_1 = require("../utils/eslint-file");
|
7
|
+
const global_eslint_config_1 = require("./global-eslint-config");
|
8
|
+
function migrateConfigToMonorepoStyle(projects, tree, unitTestRunner) {
|
9
|
+
(0, devkit_1.writeJson)(tree, '.eslintrc.base.json', (0, global_eslint_config_1.getGlobalEsLintConfiguration)(unitTestRunner));
|
10
|
+
// update extens in all projects' eslint configs
|
11
|
+
projects.forEach((project) => {
|
12
|
+
const lintTarget = findLintTarget(project);
|
13
|
+
if (lintTarget) {
|
14
|
+
const projectEslintPath = (0, devkit_1.joinPathFragments)(project.root, lintTarget.options.eslintConfig || (0, eslint_file_1.findEslintFile)(tree, project.root));
|
15
|
+
migrateEslintFile(projectEslintPath, tree);
|
16
|
+
}
|
17
|
+
});
|
18
|
+
}
|
19
|
+
exports.migrateConfigToMonorepoStyle = migrateConfigToMonorepoStyle;
|
20
|
+
function findLintTarget(project) {
|
21
|
+
var _a;
|
22
|
+
return (_a = Object.entries(project.targets).find(([name, target]) => name === 'lint' || target.executor === '@nrwl/linter:eslint')) === null || _a === void 0 ? void 0 : _a[1];
|
23
|
+
}
|
24
|
+
exports.findLintTarget = findLintTarget;
|
25
|
+
function migrateEslintFile(projectEslintPath, tree) {
|
26
|
+
if (projectEslintPath.endsWith('.json') ||
|
27
|
+
projectEslintPath.endsWith('.eslintrc')) {
|
28
|
+
(0, devkit_1.updateJson)(tree, projectEslintPath, (json) => {
|
29
|
+
// we have a new root now
|
30
|
+
delete json.root;
|
31
|
+
// remove nrwl/nx plugins
|
32
|
+
if (json.plugins) {
|
33
|
+
json.plugins = json.plugins.filter((p) => p !== '@nrwl/nx');
|
34
|
+
if (json.plugins.length === 0) {
|
35
|
+
delete json.plugins;
|
36
|
+
}
|
37
|
+
}
|
38
|
+
// add extends
|
39
|
+
json.extends = json.extends || [];
|
40
|
+
const pathToRootConfig = `${(0, devkit_1.offsetFromRoot)((0, path_1.dirname)(projectEslintPath))}.eslintrc.base.json`;
|
41
|
+
if (json.extends.indexOf(pathToRootConfig) === -1) {
|
42
|
+
json.extends.push(pathToRootConfig);
|
43
|
+
}
|
44
|
+
// cleanup overrides
|
45
|
+
if (json.overrides) {
|
46
|
+
json.overrides.forEach((override) => {
|
47
|
+
if (override.extends) {
|
48
|
+
override.extends = override.extends.filter((ext) => ext !== 'plugin:@nrwl/nx/typescript' &&
|
49
|
+
ext !== 'plugin:@nrwl/nx/javascript');
|
50
|
+
if (override.extends.length === 0) {
|
51
|
+
delete override.extends;
|
52
|
+
}
|
53
|
+
}
|
54
|
+
});
|
55
|
+
}
|
56
|
+
return json;
|
57
|
+
});
|
58
|
+
return;
|
59
|
+
}
|
60
|
+
if (projectEslintPath.endsWith('.yml') ||
|
61
|
+
projectEslintPath.endsWith('.yaml')) {
|
62
|
+
console.warn('YAML eslint config is not supported yet for migration');
|
63
|
+
}
|
64
|
+
if (projectEslintPath.endsWith('.js') || projectEslintPath.endsWith('.cjs')) {
|
65
|
+
console.warn('YAML eslint config is not supported yet for migration');
|
66
|
+
}
|
67
|
+
}
|
68
|
+
//# sourceMappingURL=init-migration.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"init-migration.js","sourceRoot":"","sources":["../../../../../../packages/linter/src/generators/init/init-migration.ts"],"names":[],"mappings":";;;AAAA,yCAQsB;AACtB,+BAA+B;AAC/B,sDAAsD;AACtD,iEAAsE;AAEtE,SAAgB,4BAA4B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AAQ,CAAC,KAAK,CAAC,IAAI,iBAAiB,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;QAC3E,OAAO,CAAC,IAAI,CAAC,uDAAuD,CAAC,CAAC;KACvE;AACH,CAAC"}
|
@@ -4,77 +4,7 @@ exports.lintInitGenerator = void 0;
|
|
4
4
|
const devkit_1 = require("@nrwl/devkit");
|
5
5
|
const versions_1 = require("../../utils/versions");
|
6
6
|
const eslint_file_1 = require("../utils/eslint-file");
|
7
|
-
const
|
8
|
-
const config = {
|
9
|
-
root: true,
|
10
|
-
ignorePatterns: ['**/*'],
|
11
|
-
plugins: ['@nrwl/nx'],
|
12
|
-
/**
|
13
|
-
* We leverage ESLint's "overrides" capability so that we can set up a root config which will support
|
14
|
-
* all permutations of Nx workspaces across all frameworks, libraries and tools.
|
15
|
-
*
|
16
|
-
* The key point is that we need entirely different ESLint config to apply to different types of files,
|
17
|
-
* but we still want to share common config where possible.
|
18
|
-
*/
|
19
|
-
overrides: [
|
20
|
-
/**
|
21
|
-
* This configuration is intended to apply to all "source code" (but not
|
22
|
-
* markup like HTML, or other custom file types like GraphQL)
|
23
|
-
*/
|
24
|
-
{
|
25
|
-
files: ['*.ts', '*.tsx', '*.js', '*.jsx'],
|
26
|
-
rules: {
|
27
|
-
'@nrwl/nx/enforce-module-boundaries': [
|
28
|
-
'error',
|
29
|
-
{
|
30
|
-
enforceBuildableLibDependency: true,
|
31
|
-
allow: [],
|
32
|
-
depConstraints: [
|
33
|
-
{ sourceTag: '*', onlyDependOnLibsWithTags: ['*'] },
|
34
|
-
],
|
35
|
-
},
|
36
|
-
],
|
37
|
-
},
|
38
|
-
},
|
39
|
-
/**
|
40
|
-
* This configuration is intended to apply to all TypeScript source files.
|
41
|
-
* See the eslint-plugin-nx package for what is in the referenced shareable config.
|
42
|
-
*/
|
43
|
-
{
|
44
|
-
files: ['*.ts', '*.tsx'],
|
45
|
-
extends: ['plugin:@nrwl/nx/typescript'],
|
46
|
-
/**
|
47
|
-
* Having an empty rules object present makes it more obvious to the user where they would
|
48
|
-
* extend things from if they needed to
|
49
|
-
*/
|
50
|
-
rules: {},
|
51
|
-
},
|
52
|
-
/**
|
53
|
-
* This configuration is intended to apply to all JavaScript source files.
|
54
|
-
* See the eslint-plugin-nx package for what is in the referenced shareable config.
|
55
|
-
*/
|
56
|
-
{
|
57
|
-
files: ['*.js', '*.jsx'],
|
58
|
-
extends: ['plugin:@nrwl/nx/javascript'],
|
59
|
-
/**
|
60
|
-
* Having an empty rules object present makes it more obvious to the user where they would
|
61
|
-
* extend things from if they needed to
|
62
|
-
*/
|
63
|
-
rules: {},
|
64
|
-
},
|
65
|
-
],
|
66
|
-
};
|
67
|
-
if (unitTestRunner === 'jest') {
|
68
|
-
config.overrides.push({
|
69
|
-
files: ['*.spec.ts', '*.spec.tsx', '*.spec.js', '*.spec.jsx'],
|
70
|
-
env: {
|
71
|
-
jest: true,
|
72
|
-
},
|
73
|
-
rules: {},
|
74
|
-
});
|
75
|
-
}
|
76
|
-
return config;
|
77
|
-
};
|
7
|
+
const global_eslint_config_1 = require("./global-eslint-config");
|
78
8
|
function addTargetDefaults(tree) {
|
79
9
|
var _a, _b, _c, _d;
|
80
10
|
var _e, _f;
|
@@ -101,7 +31,7 @@ function initEsLint(tree, options) {
|
|
101
31
|
if (!options.skipPackageJson) {
|
102
32
|
(0, devkit_1.removeDependenciesFromPackageJson)(tree, ['@nrwl/linter'], []);
|
103
33
|
}
|
104
|
-
(0, devkit_1.writeJson)(tree, '.eslintrc.json', getGlobalEsLintConfiguration(options.unitTestRunner));
|
34
|
+
(0, devkit_1.writeJson)(tree, '.eslintrc.json', (0, global_eslint_config_1.getGlobalEsLintConfiguration)(options.unitTestRunner, options.rootProject));
|
105
35
|
addTargetDefaults(tree);
|
106
36
|
if (tree.exists('.vscode/extensions.json')) {
|
107
37
|
(0, devkit_1.updateJson)(tree, '.vscode/extensions.json', (json) => {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../../../../../packages/linter/src/generators/init/init.ts"],"names":[],"mappings":";;;AACA,yCAOsB;AACtB,mDAK8B;AAG9B,sDAAsD;
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../../../../../packages/linter/src/generators/init/init.ts"],"names":[],"mappings":";;;AACA,yCAOsB;AACtB,mDAK8B;AAG9B,sDAAsD;AACtD,iEAAsE;AAStE,SAAS,iBAAiB,CAAC,IAAU;;;IACnC,MAAM,sBAAsB,GAAG,IAAA,mCAA0B,EAAC,IAAI,CAAC,CAAC;IAEhE,MAAM,iBAAiB,GAAG,MAAA,sBAAsB,CAAC,WAAW,0CAAE,UAAU,CAAC;IACzE,IAAI,iBAAiB,EAAE;QACrB,wBAAwB;QACxB,iBAAiB,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC;QACxD,iBAAiB;QACjB,sBAAsB,CAAC,WAAW,CAAC,UAAU,GAAG,KAAK,CAAC,IAAI,CACxD,IAAI,GAAG,CAAC,iBAAiB,CAAC,CAC3B,CAAC;KACH;IAED,MAAA,sBAAsB,CAAC,cAAc,oCAArC,sBAAsB,CAAC,cAAc,GAAK,EAAE,EAAC;IAE7C,YAAA,sBAAsB,CAAC,cAAc,EAAC,IAAI,uCAAJ,IAAI,GAAK,EAAE,EAAC;IAClD,YAAA,sBAAsB,CAAC,cAAc,CAAC,IAAI,EAAC,MAAM,uCAAN,MAAM,GAAK;QACpD,SAAS;QACT,gCAAgC;KACjC,EAAC;IACF,IAAA,qCAA4B,EAAC,IAAI,EAAE,sBAAsB,CAAC,CAAC;AAC7D,CAAC;AAED,SAAS,UAAU,CAAC,IAAU,EAAE,OAA0B;IACxD,IAAI,IAAA,4BAAc,EAAC,IAAI,CAAC,EAAE;QACxB,OAAO,GAAG,EAAE,GAAE,CAAC,CAAC;KACjB;IAED,IAAI,CAAC,OAAO,CAAC,eAAe,EAAE;QAC5B,IAAA,0CAAiC,EAAC,IAAI,EAAE,CAAC,cAAc,CAAC,EAAE,EAAE,CAAC,CAAC;KAC/D;IAED,IAAA,kBAAS,EACP,IAAI,EACJ,gBAAgB,EAChB,IAAA,mDAA4B,EAAC,OAAO,CAAC,cAAc,EAAE,OAAO,CAAC,WAAW,CAAC,CAC1E,CAAC;IACF,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAExB,IAAI,IAAI,CAAC,MAAM,CAAC,yBAAyB,CAAC,EAAE;QAC1C,IAAA,mBAAU,EAAC,IAAI,EAAE,yBAAyB,EAAE,CAAC,IAAI,EAAE,EAAE;YACnD,IAAI,CAAC,eAAe,KAApB,IAAI,CAAC,eAAe,GAAK,EAAE,EAAC;YAC5B,MAAM,SAAS,GAAG,wBAAwB,CAAC;YAC3C,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;gBAC7C,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;aACtC;YACD,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CAAC;KACJ;IAED,OAAO,CAAC,OAAO,CAAC,eAAe;QAC7B,CAAC,CAAC,IAAA,qCAA4B,EAC1B,IAAI,EACJ,EAAE,EACF;YACE,cAAc,EAAE,oBAAS;YACzB,wBAAwB,EAAE,oBAAS;YACnC,2BAA2B,EAAE,kCAAuB;YACpD,kCAAkC,EAAE,kCAAuB;YAC3D,MAAM,EAAE,wBAAa;YACrB,wBAAwB,EAAE,sCAA2B;SACtD,CACF;QACH,CAAC,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC;AACf,CAAC;AAED,SAAgB,iBAAiB,CAAC,IAAU,EAAE,OAA0B;IACtE,OAAO,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AACnC,CAAC;AAFD,8CAEC"}
|
@@ -9,6 +9,8 @@ interface LintProjectOptions {
|
|
9
9
|
setParserOptionsProject?: boolean;
|
10
10
|
skipPackageJson?: boolean;
|
11
11
|
unitTestRunner?: string;
|
12
|
+
rootProject?: boolean;
|
12
13
|
}
|
14
|
+
export declare function mapLintPattern(projectRoot: string, extension: string, rootProject?: boolean): string;
|
13
15
|
export declare function lintProjectGenerator(tree: Tree, options: LintProjectOptions): Promise<import("@nrwl/devkit").GeneratorCallback>;
|
14
16
|
export {};
|
@@ -1,11 +1,13 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.lintProjectGenerator = void 0;
|
3
|
+
exports.lintProjectGenerator = exports.mapLintPattern = void 0;
|
4
4
|
const tslib_1 = require("tslib");
|
5
5
|
const devkit_1 = require("@nrwl/devkit");
|
6
6
|
const eslint_file_1 = require("../utils/eslint-file");
|
7
7
|
const path_1 = require("path");
|
8
8
|
const init_1 = require("../init/init");
|
9
|
+
const init_migration_1 = require("../init/init-migration");
|
10
|
+
const project_configuration_1 = require("nx/src/generators/utils/project-configuration");
|
9
11
|
function createEsLintConfiguration(tree, projectConfig, setParserOptionsProject) {
|
10
12
|
const eslintConfig = (0, eslint_file_1.findEslintFile)(tree);
|
11
13
|
(0, devkit_1.writeJson)(tree, (0, path_1.join)(projectConfig.root, `.eslintrc.json`), {
|
@@ -52,12 +54,18 @@ function createEsLintConfiguration(tree, projectConfig, setParserOptionsProject)
|
|
52
54
|
],
|
53
55
|
});
|
54
56
|
}
|
57
|
+
function mapLintPattern(projectRoot, extension, rootProject) {
|
58
|
+
const infix = rootProject ? 'src/' : '';
|
59
|
+
return `${projectRoot}/${infix}**/*.${extension}`;
|
60
|
+
}
|
61
|
+
exports.mapLintPattern = mapLintPattern;
|
55
62
|
function lintProjectGenerator(tree, options) {
|
56
63
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
57
64
|
const installTask = (0, init_1.lintInitGenerator)(tree, {
|
58
65
|
linter: options.linter,
|
59
66
|
unitTestRunner: options.unitTestRunner,
|
60
67
|
skipPackageJson: options.skipPackageJson,
|
68
|
+
rootProject: options.rootProject,
|
61
69
|
});
|
62
70
|
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
63
71
|
projectConfig.targets['lint'] = {
|
@@ -67,7 +75,28 @@ function lintProjectGenerator(tree, options) {
|
|
67
75
|
lintFilePatterns: options.eslintFilePatterns,
|
68
76
|
},
|
69
77
|
};
|
70
|
-
|
78
|
+
// we are adding new project which is not the root project or
|
79
|
+
// companion e2e app so we should check if migration to
|
80
|
+
// monorepo style is needed
|
81
|
+
if (!options.rootProject) {
|
82
|
+
const projects = (0, project_configuration_1.readWorkspace)(tree).projects;
|
83
|
+
if (isMigrationToMonorepoNeeded(projects, tree)) {
|
84
|
+
// we only migrate project configurations that have been created
|
85
|
+
const filteredProjects = [];
|
86
|
+
Object.entries(projects).forEach(([name, project]) => {
|
87
|
+
if (name !== options.project) {
|
88
|
+
filteredProjects.push(project);
|
89
|
+
}
|
90
|
+
});
|
91
|
+
(0, init_migration_1.migrateConfigToMonorepoStyle)(filteredProjects, tree, options.unitTestRunner);
|
92
|
+
}
|
93
|
+
}
|
94
|
+
// our root `.eslintrc` is already the project config, so we should not override it
|
95
|
+
// additionally, the companion e2e app would have `rootProject: true`
|
96
|
+
// so we need to check for the root path as well
|
97
|
+
if (!options.rootProject || projectConfig.root !== '.') {
|
98
|
+
createEsLintConfiguration(tree, projectConfig, options.setParserOptionsProject);
|
99
|
+
}
|
71
100
|
(0, devkit_1.updateProjectConfiguration)(tree, options.project, projectConfig);
|
72
101
|
if (!options.skipFormat) {
|
73
102
|
yield (0, devkit_1.formatFiles)(tree);
|
@@ -76,4 +105,32 @@ function lintProjectGenerator(tree, options) {
|
|
76
105
|
});
|
77
106
|
}
|
78
107
|
exports.lintProjectGenerator = lintProjectGenerator;
|
108
|
+
/**
|
109
|
+
* Detect based on the state of lint target configuration of the root project
|
110
|
+
* if we should migrate eslint configs to monorepo style
|
111
|
+
*
|
112
|
+
* @param tree
|
113
|
+
* @returns
|
114
|
+
*/
|
115
|
+
function isMigrationToMonorepoNeeded(projects, tree) {
|
116
|
+
// the base config is already created, migration has been done
|
117
|
+
if (tree.exists('.eslintrc.base.json')) {
|
118
|
+
return false;
|
119
|
+
}
|
120
|
+
const configs = Object.values(projects);
|
121
|
+
if (configs.length === 1) {
|
122
|
+
return false;
|
123
|
+
}
|
124
|
+
// get root project
|
125
|
+
const rootProject = configs.find((p) => p.root === '.');
|
126
|
+
if (!rootProject || !rootProject.targets) {
|
127
|
+
return false;
|
128
|
+
}
|
129
|
+
// find if root project has lint target
|
130
|
+
const lintTarget = (0, init_migration_1.findLintTarget)(rootProject);
|
131
|
+
if (!lintTarget) {
|
132
|
+
return false;
|
133
|
+
}
|
134
|
+
return true;
|
135
|
+
}
|
79
136
|
//# sourceMappingURL=lint-project.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"lint-project.js","sourceRoot":"","sources":["../../../../../../packages/linter/src/generators/lint-project/lint-project.ts"],"names":[],"mappings":";;;;AACA,yCAMsB;AAGtB,sDAAsD;AACtD,+BAA4B;AAC5B,uCAAiD;
|
1
|
+
{"version":3,"file":"lint-project.js","sourceRoot":"","sources":["../../../../../../packages/linter/src/generators/lint-project/lint-project.ts"],"names":[],"mappings":";;;;AACA,yCAMsB;AAGtB,sDAAsD;AACtD,+BAA4B;AAC5B,uCAAiD;AACjD,2DAGgC;AAChC,yFAA8E;AAc9E,SAAS,yBAAyB,CAChC,IAAU,EACV,aAAmC,EACnC,uBAAgC;IAEhC,MAAM,YAAY,GAAG,IAAA,4BAAc,EAAC,IAAI,CAAC,CAAC;IAC1C,IAAA,kBAAS,EAAC,IAAI,EAAE,IAAA,WAAI,EAAC,aAAa,CAAC,IAAI,EAAE,gBAAgB,CAAC,EAAE;QAC1D,OAAO,EAAE,YAAY;YACnB,CAAC,CAAC,CAAC,GAAG,IAAA,uBAAc,EAAC,aAAa,CAAC,IAAI,CAAC,GAAG,YAAY,EAAE,CAAC;YAC1D,CAAC,CAAC,SAAS;QACb,8EAA8E;QAC9E,cAAc,EAAE,CAAC,OAAO,CAAC;QACzB,SAAS,EAA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tC,OAAO,KAAK,CAAC;KACd;IAED,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACxC,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;QACxB,OAAO,KAAK,CAAC;KACd;IAED,mBAAmB;IACnB,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC;IACxD,IAAI,CAAC,WAAW,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE;QACxC,OAAO,KAAK,CAAC;KACd;IACD,uCAAuC;IACvC,MAAM,UAAU,GAAG,IAAA,+BAAc,EAAC,WAAW,CAAC,CAAC;IAC/C,IAAI,CAAC,UAAU,EAAE;QACf,OAAO,KAAK,CAAC;KACd;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
@@ -1,3 +1,4 @@
|
|
1
|
-
import
|
1
|
+
import { Tree } from '@nrwl/devkit';
|
2
2
|
export declare const eslintConfigFileWhitelist: string[];
|
3
|
-
export declare
|
3
|
+
export declare const baseEsLintConfigFile = ".eslintrc.base.json";
|
4
|
+
export declare function findEslintFile(tree: Tree, projectRoot?: string): string | null;
|
@@ -1,6 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.findEslintFile = exports.eslintConfigFileWhitelist = void 0;
|
3
|
+
exports.findEslintFile = exports.baseEsLintConfigFile = exports.eslintConfigFileWhitelist = void 0;
|
4
|
+
const devkit_1 = require("@nrwl/devkit");
|
4
5
|
exports.eslintConfigFileWhitelist = [
|
5
6
|
'.eslintrc',
|
6
7
|
'.eslintrc.js',
|
@@ -8,10 +9,15 @@ exports.eslintConfigFileWhitelist = [
|
|
8
9
|
'.eslintrc.yaml',
|
9
10
|
'.eslintrc.yml',
|
10
11
|
'.eslintrc.json',
|
12
|
+
'eslint.config.js', // new format that requires `ESLINT_USE_FLAT_CONFIG=true`
|
11
13
|
];
|
12
|
-
|
14
|
+
exports.baseEsLintConfigFile = '.eslintrc.base.json';
|
15
|
+
function findEslintFile(tree, projectRoot = '') {
|
16
|
+
if (projectRoot === '' && tree.exists(exports.baseEsLintConfigFile)) {
|
17
|
+
return exports.baseEsLintConfigFile;
|
18
|
+
}
|
13
19
|
for (const file of exports.eslintConfigFileWhitelist) {
|
14
|
-
if (tree.exists(file)) {
|
20
|
+
if (tree.exists((0, devkit_1.joinPathFragments)(projectRoot, file))) {
|
15
21
|
return file;
|
16
22
|
}
|
17
23
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"eslint-file.js","sourceRoot":"","sources":["../../../../../../packages/linter/src/generators/utils/eslint-file.ts"],"names":[],"mappings":";;;
|
1
|
+
{"version":3,"file":"eslint-file.js","sourceRoot":"","sources":["../../../../../../packages/linter/src/generators/utils/eslint-file.ts"],"names":[],"mappings":";;;AAAA,yCAAuD;AAE1C,QAAA,yBAAyB,GAAG;IACvC,WAAW;IACX,cAAc;IACd,eAAe;IACf,gBAAgB;IAChB,eAAe;IACf,gBAAgB;IAChB,kBAAkB,EAAE,yDAAyD;CAC9E,CAAC;AAEW,QAAA,oBAAoB,GAAG,qBAAqB,CAAC;AAE1D,SAAgB,cAAc,CAAC,IAAU,EAAE,WAAW,GAAG,EAAE;IACzD,IAAI,WAAW,KAAK,EAAE,IAAI,IAAI,CAAC,MAAM,CAAC,4BAAoB,CAAC,EAAE;QAC3D,OAAO,4BAAoB,CAAC;KAC7B;IACD,KAAK,MAAM,IAAI,IAAI,iCAAyB,EAAE;QAC5C,IAAI,IAAI,CAAC,MAAM,CAAC,IAAA,0BAAiB,EAAC,WAAW,EAAE,IAAI,CAAC,CAAC,EAAE;YACrD,OAAO,IAAI,CAAC;SACb;KACF;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAXD,wCAWC"}
|