@nx/eslint-plugin 17.0.3 → 17.0.5
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/LICENSE +1 -1
- package/README.md +9 -4
- package/migrations.json +6 -0
- package/package.json +8 -8
- package/src/configs/angular.js +1 -15
- package/src/configs/javascript.d.ts +20 -0
- package/src/configs/javascript.js +20 -0
- package/src/configs/react-base.js +3 -2
- package/src/configs/typescript.d.ts +20 -0
- package/src/configs/typescript.js +20 -0
- package/src/constants.d.ts +3 -2
- package/src/constants.js +5 -4
- package/src/index.js +12 -11
- package/src/migrations/update-17-2-6-rename-workspace-rules/rename-workspace-rules.d.ts +2 -0
- package/src/migrations/update-17-2-6-rename-workspace-rules/rename-workspace-rules.js +29 -0
- package/src/resolve-workspace-rules.js +3 -1
- package/src/rules/dependency-checks.d.ts +3 -1
- package/src/rules/dependency-checks.js +11 -6
- package/src/rules/enforce-module-boundaries.d.ts +3 -2
- package/src/rules/enforce-module-boundaries.js +15 -9
- package/src/rules/nx-plugin-checks.js +7 -6
- package/src/utils/ast-utils.js +11 -10
- package/src/utils/package-json-utils.js +6 -3
- package/src/utils/runtime-lint-utils.d.ts +4 -6
- package/src/utils/runtime-lint-utils.js +34 -18
- package/src/utils/create-eslint-rule.d.ts +0 -2
- package/src/utils/create-eslint-rule.js +0 -5
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
<p style="text-align: center;"
|
|
1
|
+
<p style="text-align: center;">
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-dark.svg">
|
|
4
|
+
<img alt="Nx - Smart Monorepos · Fast CI" src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-light.svg" width="100%">
|
|
5
|
+
</picture>
|
|
6
|
+
</p>
|
|
2
7
|
|
|
3
8
|
<div style="text-align: center;">
|
|
4
9
|
|
|
@@ -15,9 +20,9 @@
|
|
|
15
20
|
|
|
16
21
|
<hr>
|
|
17
22
|
|
|
18
|
-
# Nx: Smart
|
|
23
|
+
# Nx: Smart Monorepos · Fast CI
|
|
19
24
|
|
|
20
|
-
Nx is a
|
|
25
|
+
Nx is a build system with built-in tooling and advanced CI capabilities. It helps you maintain and scale monorepos, both locally and on CI.
|
|
21
26
|
|
|
22
27
|
This package is an ESLint plugin for Nx.
|
|
23
28
|
|
|
@@ -59,5 +64,5 @@ npx nx@latest init
|
|
|
59
64
|
- [Blog Posts About Nx](https://blog.nrwl.io/nx/home)
|
|
60
65
|
|
|
61
66
|
<p style="text-align: center;"><a href="https://nx.dev/#learning-materials" target="_blank" rel="noreferrer"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-courses-and-videos.svg"
|
|
62
|
-
width="100%" alt="Nx - Smart
|
|
67
|
+
width="100%" alt="Nx - Smart Monorepos · Fast CI"></a></p>
|
|
63
68
|
|
package/migrations.json
CHANGED
|
@@ -5,6 +5,12 @@
|
|
|
5
5
|
"version": "16.0.0-beta.1",
|
|
6
6
|
"description": "Replace @nrwl/eslint-plugin-nx with @nx/eslint-plugin",
|
|
7
7
|
"implementation": "./src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages"
|
|
8
|
+
},
|
|
9
|
+
"update-17-2-6-rename-workspace-rules": {
|
|
10
|
+
"cli": "nx",
|
|
11
|
+
"version": "17.2.6-beta.1",
|
|
12
|
+
"description": "Rename workspace rules from @nx/workspace/name to @nx/workspace-name",
|
|
13
|
+
"implementation": "./src/migrations/update-17-2-6-rename-workspace-rules/rename-workspace-rules"
|
|
8
14
|
}
|
|
9
15
|
},
|
|
10
16
|
"packageJsonUpdates": {},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/eslint-plugin",
|
|
3
|
-
"version": "17.0.
|
|
3
|
+
"version": "17.0.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The eslint-plugin package is an ESLint plugin that contains a collection of recommended ESLint rule configurations which you can extend from in your own ESLint configs, as well as an Nx-specific lint rule called enforce-module-boundaries.",
|
|
6
6
|
"repository": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"homepage": "https://nx.dev",
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@typescript-eslint/parser": "^
|
|
27
|
+
"@typescript-eslint/parser": "^6.13.2 || ^7.0.0",
|
|
28
28
|
"eslint-config-prettier": "^9.0.0"
|
|
29
29
|
},
|
|
30
30
|
"peerDependenciesMeta": {
|
|
@@ -33,16 +33,16 @@
|
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@nx/devkit": "17.0.
|
|
37
|
-
"@nx/js": "17.0.
|
|
38
|
-
"@typescript-eslint/type-utils": "^
|
|
39
|
-
"@typescript-eslint/utils": "^
|
|
36
|
+
"@nx/devkit": "17.0.5",
|
|
37
|
+
"@nx/js": "17.0.5",
|
|
38
|
+
"@typescript-eslint/type-utils": "^7.3.0",
|
|
39
|
+
"@typescript-eslint/utils": "^7.3.0",
|
|
40
40
|
"chalk": "^4.1.0",
|
|
41
41
|
"confusing-browser-globals": "^1.0.9",
|
|
42
42
|
"jsonc-eslint-parser": "^2.1.0",
|
|
43
|
-
"semver": "7.5.3",
|
|
43
|
+
"semver": "^7.5.3",
|
|
44
44
|
"tslib": "^2.3.0",
|
|
45
|
-
"@nrwl/eslint-plugin-nx": "17.0.
|
|
45
|
+
"@nrwl/eslint-plugin-nx": "17.0.5"
|
|
46
46
|
},
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public"
|
package/src/configs/angular.js
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
let angularEslintPlugin;
|
|
4
|
-
try {
|
|
5
|
-
angularEslintPlugin = require('@angular-eslint/eslint-plugin');
|
|
6
|
-
}
|
|
7
|
-
catch { }
|
|
8
3
|
/**
|
|
9
4
|
* This configuration is intended to be applied to ALL .ts files in Angular
|
|
10
5
|
* projects within an Nx workspace.
|
|
@@ -23,16 +18,7 @@ exports.default = {
|
|
|
23
18
|
node: true,
|
|
24
19
|
},
|
|
25
20
|
plugins: ['@angular-eslint'],
|
|
26
|
-
extends: [
|
|
27
|
-
'plugin:@angular-eslint/recommended',
|
|
28
|
-
/**
|
|
29
|
-
* TODO: Consider dropping this extends and explicitly carrying over rules we care about
|
|
30
|
-
* into our typescript preset in v13
|
|
31
|
-
*/
|
|
32
|
-
...(angularEslintPlugin?.configs?.['recommended--extra']
|
|
33
|
-
? ['plugin:@angular-eslint/recommended--extra']
|
|
34
|
-
: []),
|
|
35
|
-
],
|
|
21
|
+
extends: ['plugin:@angular-eslint/recommended'],
|
|
36
22
|
parserOptions: {
|
|
37
23
|
// Unset the default value for parserOptions.project that is found in earlier versions of @angular-eslint
|
|
38
24
|
project: [],
|
|
@@ -37,6 +37,26 @@ declare const _default: {
|
|
|
37
37
|
* having to frequently use "eslint-disable-next-line" in their configs.
|
|
38
38
|
*/
|
|
39
39
|
'@typescript-eslint/no-var-requires': string;
|
|
40
|
+
/**
|
|
41
|
+
* From https://typescript-eslint.io/blog/announcing-typescript-eslint-v6/#updated-configuration-rules
|
|
42
|
+
*
|
|
43
|
+
* The following rules were added to preserve the linting rules that were
|
|
44
|
+
* previously defined v5 of `@typescript-eslint`. v6 of `@typescript-eslint`
|
|
45
|
+
* changed how configurations are defined.
|
|
46
|
+
*
|
|
47
|
+
* TODO(v19): re-evalute these deviations from @typescript-eslint/recommended in v19 of Nx
|
|
48
|
+
*/
|
|
49
|
+
'no-extra-semi': string;
|
|
50
|
+
'@typescript-eslint/no-extra-semi': string;
|
|
51
|
+
'@typescript-eslint/no-non-null-assertion': string;
|
|
52
|
+
'@typescript-eslint/adjacent-overload-signatures': string;
|
|
53
|
+
'@typescript-eslint/prefer-namespace-keyword': string;
|
|
54
|
+
'no-empty-function': string;
|
|
55
|
+
'@typescript-eslint/no-empty-function': string;
|
|
56
|
+
'@typescript-eslint/no-inferrable-types': string;
|
|
57
|
+
'@typescript-eslint/no-unused-vars': string;
|
|
58
|
+
'@typescript-eslint/no-empty-interface': string;
|
|
59
|
+
'@typescript-eslint/no-explicit-any': string;
|
|
40
60
|
};
|
|
41
61
|
};
|
|
42
62
|
export default _default;
|
|
@@ -46,5 +46,25 @@ exports.default = {
|
|
|
46
46
|
* having to frequently use "eslint-disable-next-line" in their configs.
|
|
47
47
|
*/
|
|
48
48
|
'@typescript-eslint/no-var-requires': 'off',
|
|
49
|
+
/**
|
|
50
|
+
* From https://typescript-eslint.io/blog/announcing-typescript-eslint-v6/#updated-configuration-rules
|
|
51
|
+
*
|
|
52
|
+
* The following rules were added to preserve the linting rules that were
|
|
53
|
+
* previously defined v5 of `@typescript-eslint`. v6 of `@typescript-eslint`
|
|
54
|
+
* changed how configurations are defined.
|
|
55
|
+
*
|
|
56
|
+
* TODO(v19): re-evalute these deviations from @typescript-eslint/recommended in v19 of Nx
|
|
57
|
+
*/
|
|
58
|
+
'no-extra-semi': 'off',
|
|
59
|
+
'@typescript-eslint/no-extra-semi': 'error',
|
|
60
|
+
'@typescript-eslint/no-non-null-assertion': 'warn',
|
|
61
|
+
'@typescript-eslint/adjacent-overload-signatures': 'error',
|
|
62
|
+
'@typescript-eslint/prefer-namespace-keyword': 'error',
|
|
63
|
+
'no-empty-function': 'off',
|
|
64
|
+
'@typescript-eslint/no-empty-function': 'error',
|
|
65
|
+
'@typescript-eslint/no-inferrable-types': 'error',
|
|
66
|
+
'@typescript-eslint/no-unused-vars': 'warn',
|
|
67
|
+
'@typescript-eslint/no-empty-interface': 'error',
|
|
68
|
+
'@typescript-eslint/no-explicit-any': 'warn',
|
|
49
69
|
},
|
|
50
70
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
3
4
|
/**
|
|
4
5
|
* This configuration is intended to be applied to ALL files within a React
|
|
5
6
|
* project in an Nx workspace.
|
|
@@ -10,7 +11,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
10
11
|
* This configuration is intended to be combined with other configs from this
|
|
11
12
|
* package.
|
|
12
13
|
*/
|
|
13
|
-
const
|
|
14
|
+
const confusing_browser_globals_1 = tslib_1.__importDefault(require("confusing-browser-globals"));
|
|
14
15
|
/**
|
|
15
16
|
* Rule set originally adapted from:
|
|
16
17
|
* https://github.com/facebook/create-react-app/blob/567f36c9235f1e1fd4a76dc6d1ae00be754ca047/packages/eslint-config-react-app/index.js
|
|
@@ -91,7 +92,7 @@ exports.default = {
|
|
|
91
92
|
'no-template-curly-in-string': 'warn',
|
|
92
93
|
'no-this-before-super': 'warn',
|
|
93
94
|
'no-throw-literal': 'warn',
|
|
94
|
-
'no-restricted-globals': ['error'].concat(
|
|
95
|
+
'no-restricted-globals': ['error'].concat(confusing_browser_globals_1.default),
|
|
95
96
|
'no-unexpected-multiline': 'warn',
|
|
96
97
|
'no-unreachable': 'warn',
|
|
97
98
|
'no-unused-expressions': 'off',
|
|
@@ -19,6 +19,26 @@ declare const _default: {
|
|
|
19
19
|
'@typescript-eslint/explicit-module-boundary-types': string;
|
|
20
20
|
'@typescript-eslint/explicit-function-return-type': string;
|
|
21
21
|
'@typescript-eslint/no-parameter-properties': string;
|
|
22
|
+
/**
|
|
23
|
+
* From https://typescript-eslint.io/blog/announcing-typescript-eslint-v6/#updated-configuration-rules
|
|
24
|
+
*
|
|
25
|
+
* The following rules were added to preserve the linting rules that were
|
|
26
|
+
* previously defined v5 of `@typescript-eslint`. v6 of `@typescript-eslint`
|
|
27
|
+
* changed how configurations are defined.
|
|
28
|
+
*
|
|
29
|
+
* TODO(v19): re-evalute these deviations from @typescript-eslint/recommended in v19 of Nx
|
|
30
|
+
*/
|
|
31
|
+
'no-extra-semi': string;
|
|
32
|
+
'@typescript-eslint/no-extra-semi': string;
|
|
33
|
+
'@typescript-eslint/no-non-null-assertion': string;
|
|
34
|
+
'@typescript-eslint/adjacent-overload-signatures': string;
|
|
35
|
+
'@typescript-eslint/prefer-namespace-keyword': string;
|
|
36
|
+
'no-empty-function': string;
|
|
37
|
+
'@typescript-eslint/no-empty-function': string;
|
|
38
|
+
'@typescript-eslint/no-inferrable-types': string;
|
|
39
|
+
'@typescript-eslint/no-unused-vars': string;
|
|
40
|
+
'@typescript-eslint/no-empty-interface': string;
|
|
41
|
+
'@typescript-eslint/no-explicit-any': string;
|
|
22
42
|
};
|
|
23
43
|
};
|
|
24
44
|
export default _default;
|
|
@@ -29,5 +29,25 @@ exports.default = {
|
|
|
29
29
|
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
|
30
30
|
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
31
31
|
'@typescript-eslint/no-parameter-properties': 'off',
|
|
32
|
+
/**
|
|
33
|
+
* From https://typescript-eslint.io/blog/announcing-typescript-eslint-v6/#updated-configuration-rules
|
|
34
|
+
*
|
|
35
|
+
* The following rules were added to preserve the linting rules that were
|
|
36
|
+
* previously defined v5 of `@typescript-eslint`. v6 of `@typescript-eslint`
|
|
37
|
+
* changed how configurations are defined.
|
|
38
|
+
*
|
|
39
|
+
* TODO(v19): re-evalute these deviations from @typescript-eslint/recommended in v19 of Nx
|
|
40
|
+
*/
|
|
41
|
+
'no-extra-semi': 'off',
|
|
42
|
+
'@typescript-eslint/no-extra-semi': 'error',
|
|
43
|
+
'@typescript-eslint/no-non-null-assertion': 'warn',
|
|
44
|
+
'@typescript-eslint/adjacent-overload-signatures': 'error',
|
|
45
|
+
'@typescript-eslint/prefer-namespace-keyword': 'error',
|
|
46
|
+
'no-empty-function': 'off',
|
|
47
|
+
'@typescript-eslint/no-empty-function': 'error',
|
|
48
|
+
'@typescript-eslint/no-inferrable-types': 'error',
|
|
49
|
+
'@typescript-eslint/no-unused-vars': 'warn',
|
|
50
|
+
'@typescript-eslint/no-empty-interface': 'error',
|
|
51
|
+
'@typescript-eslint/no-explicit-any': 'warn',
|
|
32
52
|
},
|
|
33
53
|
};
|
package/src/constants.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export declare const WORKSPACE_RULES_PATH = "tools/eslint-rules";
|
|
1
2
|
export declare const WORKSPACE_PLUGIN_DIR: string;
|
|
2
3
|
/**
|
|
3
4
|
* We add a namespace so that we mitigate the risk of rule name collisions as much as
|
|
@@ -7,6 +8,6 @@ export declare const WORKSPACE_PLUGIN_DIR: string;
|
|
|
7
8
|
* E.g. if a user writes a rule called "foo", then they will include it in their ESLint
|
|
8
9
|
* config files as:
|
|
9
10
|
*
|
|
10
|
-
* "@nx/workspace
|
|
11
|
+
* "@nx/workspace-foo": "error"
|
|
11
12
|
*/
|
|
12
|
-
export declare const
|
|
13
|
+
export declare const WORKSPACE_RULE_PREFIX = "workspace";
|
package/src/constants.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.WORKSPACE_RULE_PREFIX = exports.WORKSPACE_PLUGIN_DIR = exports.WORKSPACE_RULES_PATH = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const path_1 = require("path");
|
|
6
|
-
exports.
|
|
6
|
+
exports.WORKSPACE_RULES_PATH = 'tools/eslint-rules';
|
|
7
|
+
exports.WORKSPACE_PLUGIN_DIR = (0, path_1.join)(devkit_1.workspaceRoot, exports.WORKSPACE_RULES_PATH);
|
|
7
8
|
/**
|
|
8
9
|
* We add a namespace so that we mitigate the risk of rule name collisions as much as
|
|
9
10
|
* possible between what users might create in their workspaces and what we might want
|
|
@@ -12,6 +13,6 @@ exports.WORKSPACE_PLUGIN_DIR = (0, path_1.join)(devkit_1.workspaceRoot, 'tools/e
|
|
|
12
13
|
* E.g. if a user writes a rule called "foo", then they will include it in their ESLint
|
|
13
14
|
* config files as:
|
|
14
15
|
*
|
|
15
|
-
* "@nx/workspace
|
|
16
|
+
* "@nx/workspace-foo": "error"
|
|
16
17
|
*/
|
|
17
|
-
exports.
|
|
18
|
+
exports.WORKSPACE_RULE_PREFIX = 'workspace';
|
package/src/index.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const typescript_1 = tslib_1.__importDefault(require("./configs/typescript"));
|
|
5
|
+
const javascript_1 = tslib_1.__importDefault(require("./configs/javascript"));
|
|
6
|
+
const react_tmp_1 = tslib_1.__importDefault(require("./configs/react-tmp"));
|
|
7
|
+
const react_base_1 = tslib_1.__importDefault(require("./configs/react-base"));
|
|
8
|
+
const react_jsx_1 = tslib_1.__importDefault(require("./configs/react-jsx"));
|
|
9
|
+
const react_typescript_1 = tslib_1.__importDefault(require("./configs/react-typescript"));
|
|
10
|
+
const angular_1 = tslib_1.__importDefault(require("./configs/angular"));
|
|
11
|
+
const angular_template_1 = tslib_1.__importDefault(require("./configs/angular-template"));
|
|
12
|
+
const enforce_module_boundaries_1 = tslib_1.__importStar(require("./rules/enforce-module-boundaries"));
|
|
13
|
+
const nx_plugin_checks_1 = tslib_1.__importStar(require("./rules/nx-plugin-checks"));
|
|
14
|
+
const dependency_checks_1 = tslib_1.__importStar(require("./rules/dependency-checks"));
|
|
14
15
|
// Resolve any custom rules that might exist in the current workspace
|
|
15
16
|
const resolve_workspace_rules_1 = require("./resolve-workspace-rules");
|
|
16
17
|
module.exports = {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const devkit_1 = require("@nx/devkit");
|
|
4
|
+
const binary_extensions_1 = require("@nx/devkit/src/utils/binary-extensions");
|
|
5
|
+
const constants_1 = require("../../constants");
|
|
6
|
+
async function renameWorkspaceRule(tree) {
|
|
7
|
+
if (!tree.exists(constants_1.WORKSPACE_RULES_PATH)) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
let ruleNames = [];
|
|
11
|
+
try {
|
|
12
|
+
ruleNames = Object.keys(require(constants_1.WORKSPACE_PLUGIN_DIR).rules);
|
|
13
|
+
}
|
|
14
|
+
catch (e) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
(0, devkit_1.visitNotIgnoredFiles)(tree, '.', (path) => {
|
|
18
|
+
if ((0, binary_extensions_1.isBinaryPath)(path)) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
let contents = tree.read(path, 'utf-8');
|
|
22
|
+
ruleNames.forEach((ruleName) => {
|
|
23
|
+
contents = contents.replace(new RegExp(`@nx/workspace/${ruleName}`, 'g'), `@nx/workspace-${ruleName}`);
|
|
24
|
+
});
|
|
25
|
+
tree.write(path, contents);
|
|
26
|
+
});
|
|
27
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
28
|
+
}
|
|
29
|
+
exports.default = renameWorkspaceRule;
|
|
@@ -21,7 +21,9 @@ exports.workspaceRules = (() => {
|
|
|
21
21
|
// Apply the namespace to the resolved rules
|
|
22
22
|
const namespacedRules = {};
|
|
23
23
|
for (const [ruleName, ruleConfig] of Object.entries(rules)) {
|
|
24
|
-
namespacedRules[`${constants_1.
|
|
24
|
+
namespacedRules[`${constants_1.WORKSPACE_RULE_PREFIX}-${ruleName}`] = ruleConfig;
|
|
25
|
+
// keep the old namespaced rules for backwards compatibility
|
|
26
|
+
namespacedRules[`${constants_1.WORKSPACE_RULE_PREFIX}/${ruleName}`] = ruleConfig;
|
|
25
27
|
}
|
|
26
28
|
return namespacedRules;
|
|
27
29
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
1
2
|
export type Options = [
|
|
2
3
|
{
|
|
3
4
|
buildTargets?: string[];
|
|
@@ -7,9 +8,10 @@ export type Options = [
|
|
|
7
8
|
ignoredDependencies?: string[];
|
|
8
9
|
ignoredFiles?: string[];
|
|
9
10
|
includeTransitiveDependencies?: boolean;
|
|
11
|
+
useLocalPathsForWorkspaceDependencies?: boolean;
|
|
10
12
|
}
|
|
11
13
|
];
|
|
12
14
|
export type MessageIds = 'missingDependency' | 'obsoleteDependency' | 'versionMismatch' | 'missingDependencySection';
|
|
13
15
|
export declare const RULE_NAME = "dependency-checks";
|
|
14
|
-
declare const _default:
|
|
16
|
+
declare const _default: ESLintUtils.RuleModule<MessageIds, Options, ESLintUtils.RuleListener>;
|
|
15
17
|
export default _default;
|
|
@@ -5,18 +5,18 @@ const path_1 = require("path");
|
|
|
5
5
|
const semver_1 = require("semver");
|
|
6
6
|
const devkit_1 = require("@nx/devkit");
|
|
7
7
|
const find_npm_dependencies_1 = require("@nx/js/src/utils/find-npm-dependencies");
|
|
8
|
-
const create_eslint_rule_1 = require("../utils/create-eslint-rule");
|
|
9
8
|
const project_graph_utils_1 = require("../utils/project-graph-utils");
|
|
10
9
|
const runtime_lint_utils_1 = require("../utils/runtime-lint-utils");
|
|
11
10
|
const package_json_utils_1 = require("../utils/package-json-utils");
|
|
11
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
12
12
|
exports.RULE_NAME = 'dependency-checks';
|
|
13
|
-
exports.default = (
|
|
13
|
+
exports.default = utils_1.ESLintUtils.RuleCreator(() => `https://github.com/nrwl/nx/blob/${devkit_1.NX_VERSION}/docs/generated/packages/eslint-plugin/documents/dependency-checks.md`)({
|
|
14
14
|
name: exports.RULE_NAME,
|
|
15
15
|
meta: {
|
|
16
16
|
type: 'suggestion',
|
|
17
17
|
docs: {
|
|
18
18
|
description: `Checks dependencies in project's package.json for version mismatches`,
|
|
19
|
-
recommended: '
|
|
19
|
+
recommended: 'recommended',
|
|
20
20
|
},
|
|
21
21
|
fixable: 'code',
|
|
22
22
|
schema: [
|
|
@@ -30,6 +30,7 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
|
30
30
|
checkObsoleteDependencies: { type: 'boolean' },
|
|
31
31
|
checkVersionMismatches: { type: 'boolean' },
|
|
32
32
|
includeTransitiveDependencies: { type: 'boolean' },
|
|
33
|
+
useLocalPathsForWorkspaceDependencies: { type: 'boolean' },
|
|
33
34
|
},
|
|
34
35
|
additionalProperties: false,
|
|
35
36
|
},
|
|
@@ -50,9 +51,10 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
|
50
51
|
ignoredDependencies: [],
|
|
51
52
|
ignoredFiles: [],
|
|
52
53
|
includeTransitiveDependencies: false,
|
|
54
|
+
useLocalPathsForWorkspaceDependencies: false,
|
|
53
55
|
},
|
|
54
56
|
],
|
|
55
|
-
create(context, [{ buildTargets, ignoredDependencies, ignoredFiles, checkMissingDependencies, checkObsoleteDependencies, checkVersionMismatches, includeTransitiveDependencies, },]) {
|
|
57
|
+
create(context, [{ buildTargets, ignoredDependencies, ignoredFiles, checkMissingDependencies, checkObsoleteDependencies, checkVersionMismatches, includeTransitiveDependencies, useLocalPathsForWorkspaceDependencies, },]) {
|
|
56
58
|
if (!context.parserServices.isJSON) {
|
|
57
59
|
return {};
|
|
58
60
|
}
|
|
@@ -81,6 +83,7 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
|
81
83
|
{
|
|
82
84
|
includeTransitiveDependencies,
|
|
83
85
|
ignoredFiles,
|
|
86
|
+
useLocalPathsForWorkspaceDependencies,
|
|
84
87
|
});
|
|
85
88
|
const expectedDependencyNames = Object.keys(npmDependencies);
|
|
86
89
|
const projPackageJsonPath = (0, path_1.join)(devkit_1.workspaceRoot, sourceProject.data.root, 'package.json');
|
|
@@ -123,7 +126,9 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
|
123
126
|
if (!checkVersionMismatches) {
|
|
124
127
|
return;
|
|
125
128
|
}
|
|
126
|
-
if (npmDependencies[packageName]
|
|
129
|
+
if (npmDependencies[packageName].startsWith('file:') ||
|
|
130
|
+
packageRange.startsWith('file:') ||
|
|
131
|
+
npmDependencies[packageName] === '*' ||
|
|
127
132
|
packageRange === '*' ||
|
|
128
133
|
(0, semver_1.satisfies)(npmDependencies[packageName], packageRange, {
|
|
129
134
|
includePrerelease: true,
|
|
@@ -194,7 +199,7 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
|
194
199
|
},
|
|
195
200
|
fix: (fixer) => {
|
|
196
201
|
expectedDependencyNames.sort().reduce((acc, d) => {
|
|
197
|
-
acc[d] = rootPackageJsonDeps[d] ||
|
|
202
|
+
acc[d] = rootPackageJsonDeps[d] || npmDependencies[d];
|
|
198
203
|
return acc;
|
|
199
204
|
}, projPackageJsonDeps);
|
|
200
205
|
const dependencies = Object.keys(projPackageJsonDeps)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DepConstraint } from '../utils/runtime-lint-utils';
|
|
2
|
+
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
3
|
type Options = [
|
|
3
4
|
{
|
|
4
5
|
allow: string[];
|
|
@@ -11,7 +12,7 @@ type Options = [
|
|
|
11
12
|
checkNestedExternalImports: boolean;
|
|
12
13
|
}
|
|
13
14
|
];
|
|
14
|
-
export type MessageIds = 'noRelativeOrAbsoluteImportsAcrossLibraries' | 'noSelfCircularDependencies' | 'noCircularDependencies' | 'noImportsOfApps' | 'noImportsOfE2e' | 'noImportOfNonBuildableLibraries' | 'noImportsOfLazyLoadedLibraries' | 'projectWithoutTagsCannotHaveDependencies' | 'bannedExternalImportsViolation' | 'nestedBannedExternalImportsViolation' | 'noTransitiveDependencies' | 'onlyTagsConstraintViolation' | 'emptyOnlyTagsConstraintViolation' | 'notTagsConstraintViolation';
|
|
15
|
+
export type MessageIds = 'noRelativeOrAbsoluteImportsAcrossLibraries' | 'noRelativeOrAbsoluteExternals' | 'noSelfCircularDependencies' | 'noCircularDependencies' | 'noImportsOfApps' | 'noImportsOfE2e' | 'noImportOfNonBuildableLibraries' | 'noImportsOfLazyLoadedLibraries' | 'projectWithoutTagsCannotHaveDependencies' | 'bannedExternalImportsViolation' | 'nestedBannedExternalImportsViolation' | 'noTransitiveDependencies' | 'onlyTagsConstraintViolation' | 'emptyOnlyTagsConstraintViolation' | 'notTagsConstraintViolation';
|
|
15
16
|
export declare const RULE_NAME = "enforce-module-boundaries";
|
|
16
|
-
declare const _default:
|
|
17
|
+
declare const _default: ESLintUtils.RuleModule<MessageIds, Options, ESLintUtils.RuleListener>;
|
|
17
18
|
export default _default;
|
|
@@ -8,16 +8,16 @@ const runtime_lint_utils_1 = require("../utils/runtime-lint-utils");
|
|
|
8
8
|
const utils_1 = require("@typescript-eslint/utils");
|
|
9
9
|
const path_1 = require("path");
|
|
10
10
|
const ast_utils_1 = require("../utils/ast-utils");
|
|
11
|
-
const create_eslint_rule_1 = require("../utils/create-eslint-rule");
|
|
12
11
|
const project_graph_utils_1 = require("../utils/project-graph-utils");
|
|
12
|
+
const utils_2 = require("@typescript-eslint/utils");
|
|
13
13
|
exports.RULE_NAME = 'enforce-module-boundaries';
|
|
14
|
-
exports.default = (
|
|
14
|
+
exports.default = utils_2.ESLintUtils.RuleCreator(() => `https://github.com/nrwl/nx/blob/${devkit_1.NX_VERSION}/docs/generated/packages/eslint-plugin/documents/enforce-module-boundaries.md`)({
|
|
15
15
|
name: exports.RULE_NAME,
|
|
16
16
|
meta: {
|
|
17
17
|
type: 'suggestion',
|
|
18
18
|
docs: {
|
|
19
19
|
description: `Ensure that module boundaries are respected within the monorepo`,
|
|
20
|
-
recommended: '
|
|
20
|
+
recommended: 'recommended',
|
|
21
21
|
},
|
|
22
22
|
fixable: 'code',
|
|
23
23
|
schema: [
|
|
@@ -97,6 +97,7 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
|
97
97
|
],
|
|
98
98
|
messages: {
|
|
99
99
|
noRelativeOrAbsoluteImportsAcrossLibraries: `Projects cannot be imported by a relative or absolute path, and must begin with a npm scope`,
|
|
100
|
+
noRelativeOrAbsoluteExternals: `External resources cannot be imported using a relative or absolute path`,
|
|
100
101
|
noCircularDependencies: `Circular dependency between "{{sourceProjectName}}" and "{{targetProjectName}}" detected: {{path}}\n\nCircular file chain:\n{{filePaths}}`,
|
|
101
102
|
noSelfCircularDependencies: `Projects should use relative imports to import from other files within the same project. Use "./path/to/file" instead of import from "{{imp}}"`,
|
|
102
103
|
noImportsOfApps: 'Imports of apps are forbidden',
|
|
@@ -208,8 +209,15 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
|
208
209
|
targetProject =
|
|
209
210
|
targetProject ||
|
|
210
211
|
(0, runtime_lint_utils_1.findProjectUsingImport)(projectGraph, targetProjectLocator, sourceFilePath, imp);
|
|
211
|
-
// If target is not part of an nx workspace, return.
|
|
212
212
|
if (!targetProject) {
|
|
213
|
+
// non-project imports cannot use relative or absolute paths
|
|
214
|
+
if ((0, fileutils_1.isRelativePath)(imp) || imp.startsWith('/')) {
|
|
215
|
+
context.report({
|
|
216
|
+
node,
|
|
217
|
+
messageId: 'noRelativeOrAbsoluteExternals',
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
// If target is not found (including node internals) we bail early
|
|
213
221
|
return;
|
|
214
222
|
}
|
|
215
223
|
// we only allow relative paths within the same project
|
|
@@ -217,7 +225,7 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
|
217
225
|
if (sourceProject === targetProject) {
|
|
218
226
|
if (!allowCircularSelfDependency &&
|
|
219
227
|
!(0, fileutils_1.isRelativePath)(imp) &&
|
|
220
|
-
!(0, runtime_lint_utils_1.
|
|
228
|
+
!(0, runtime_lint_utils_1.belongsToDifferentNgEntryPoint)(imp, sourceFilePath, sourceProject.data.root)) {
|
|
221
229
|
context.report({
|
|
222
230
|
node,
|
|
223
231
|
messageId: 'noSelfCircularDependencies',
|
|
@@ -351,10 +359,8 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
|
351
359
|
}
|
|
352
360
|
}
|
|
353
361
|
// if we import a library using loadChildren, we should not import it using es6imports
|
|
354
|
-
if (
|
|
355
|
-
node.
|
|
356
|
-
!checkDynamicDependenciesExceptions.some((a) => (0, runtime_lint_utils_1.matchImportWithWildcard)(a, imp)) &&
|
|
357
|
-
(0, runtime_lint_utils_1.onlyLoadChildren)(projectGraph, sourceProject.name, targetProject.name, [])) {
|
|
362
|
+
if (!checkDynamicDependenciesExceptions.some((a) => (0, runtime_lint_utils_1.matchImportWithWildcard)(a, imp)) &&
|
|
363
|
+
(0, runtime_lint_utils_1.hasStaticImportOfDynamicResource)(node, projectGraph, sourceProject.name, targetProject.name)) {
|
|
358
364
|
const filesWithLazyImports = (0, graph_utils_1.findFilesWithDynamicImports)(projectFileMap, sourceProject.name, targetProject.name);
|
|
359
365
|
context.report({
|
|
360
366
|
data: {
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validateVersionJsonExpression = exports.validatePackageGroup = exports.validateImplemenationNode = exports.validateEntry = exports.checkCollectionNode = exports.checkCollectionFileNode = exports.RULE_NAME = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
4
6
|
const devkit_1 = require("@nx/devkit");
|
|
5
7
|
const runtime_lint_utils_1 = require("../utils/runtime-lint-utils");
|
|
6
8
|
const fs_1 = require("fs");
|
|
7
9
|
const internal_1 = require("@nx/js/src/internal");
|
|
8
|
-
const path = require("path");
|
|
9
|
-
const create_eslint_rule_1 = require("../utils/create-eslint-rule");
|
|
10
|
+
const path = tslib_1.__importStar(require("path"));
|
|
10
11
|
const project_graph_utils_1 = require("../utils/project-graph-utils");
|
|
11
12
|
const semver_1 = require("semver");
|
|
12
|
-
const
|
|
13
|
+
const js_1 = require("@nx/js");
|
|
13
14
|
const DEFAULT_OPTIONS = {
|
|
14
15
|
generatorsJson: 'generators.json',
|
|
15
16
|
executorsJson: 'executors.json',
|
|
@@ -18,12 +19,12 @@ const DEFAULT_OPTIONS = {
|
|
|
18
19
|
allowedVersionStrings: ['*', 'latest', 'next'],
|
|
19
20
|
};
|
|
20
21
|
exports.RULE_NAME = 'nx-plugin-checks';
|
|
21
|
-
exports.default = (
|
|
22
|
+
exports.default = utils_1.ESLintUtils.RuleCreator(() => ``)({
|
|
22
23
|
name: exports.RULE_NAME,
|
|
23
24
|
meta: {
|
|
24
25
|
docs: {
|
|
25
26
|
description: 'Checks common nx-plugin configuration files for validity',
|
|
26
|
-
recommended: '
|
|
27
|
+
recommended: 'recommended',
|
|
27
28
|
},
|
|
28
29
|
schema: [
|
|
29
30
|
{
|
|
@@ -89,7 +90,7 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
|
89
90
|
return {};
|
|
90
91
|
}
|
|
91
92
|
if (!global.tsProjectRegistered) {
|
|
92
|
-
(0, internal_1.registerTsProject)((0,
|
|
93
|
+
(0, internal_1.registerTsProject)((0, js_1.getRootTsConfigPath)());
|
|
93
94
|
global.tsProjectRegistered = true;
|
|
94
95
|
}
|
|
95
96
|
return {
|
package/src/utils/ast-utils.js
CHANGED
|
@@ -79,7 +79,17 @@ function hasMemberExport(exportedMember, filePath) {
|
|
|
79
79
|
return ((0, js_1.findNodes)(sourceFile, ts.SyntaxKind.Identifier).filter((identifier) => identifier.text === exportedMember).length > 0);
|
|
80
80
|
}
|
|
81
81
|
function getRelativeImportPath(exportedMember, filePath, basePath) {
|
|
82
|
-
|
|
82
|
+
const status = (0, fs_1.lstatSync)(filePath, {
|
|
83
|
+
throwIfNoEntry: false,
|
|
84
|
+
});
|
|
85
|
+
if (!status /*not existed, but probably not full file with an extension*/) {
|
|
86
|
+
// try to find an extension that exists
|
|
87
|
+
const ext = ['.ts', '.tsx', '.js', '.jsx'].find((ext) => (0, fs_1.lstatSync)(filePath + ext, { throwIfNoEntry: false }));
|
|
88
|
+
if (ext) {
|
|
89
|
+
filePath += ext;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else if (status.isDirectory()) {
|
|
83
93
|
const file = (0, fs_1.readdirSync)(filePath).find((file) => /^index\.[jt]sx?$/.exec(file));
|
|
84
94
|
if (file) {
|
|
85
95
|
filePath = (0, devkit_1.joinPathFragments)(filePath, file);
|
|
@@ -88,15 +98,6 @@ function getRelativeImportPath(exportedMember, filePath, basePath) {
|
|
|
88
98
|
return;
|
|
89
99
|
}
|
|
90
100
|
}
|
|
91
|
-
else if (!(0, fs_1.lstatSync)(filePath, {
|
|
92
|
-
throwIfNoEntry: false,
|
|
93
|
-
}) /*not folder, but probably not full file with an extension either*/) {
|
|
94
|
-
// try to find an extension that exists
|
|
95
|
-
const ext = ['.ts', '.tsx', '.js', '.jsx'].find((ext) => (0, fs_1.lstatSync)(filePath + ext, { throwIfNoEntry: false }));
|
|
96
|
-
if (ext) {
|
|
97
|
-
filePath += ext;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
101
|
const fileContent = (0, fs_1.readFileSync)(filePath, 'utf8');
|
|
101
102
|
// use the TypeScript AST to find the path to the file where exportedMember is defined
|
|
102
103
|
const sourceFile = ts.createSourceFile(filePath, fileContent, ts.ScriptTarget.Latest, true);
|
|
@@ -14,15 +14,18 @@ function getAllDependencies(packageJson) {
|
|
|
14
14
|
}
|
|
15
15
|
exports.getAllDependencies = getAllDependencies;
|
|
16
16
|
function getProductionDependencies(packageJsonPath) {
|
|
17
|
-
if (!globalThis.projPackageJsonDeps ||
|
|
17
|
+
if (!globalThis.projPackageJsonDeps ||
|
|
18
|
+
!globalThis.projPackageJsonDeps[packageJsonPath] ||
|
|
19
|
+
!(0, runtime_lint_utils_1.isTerminalRun)()) {
|
|
18
20
|
const packageJson = getPackageJson(packageJsonPath);
|
|
19
|
-
globalThis.projPackageJsonDeps = {
|
|
21
|
+
globalThis.projPackageJsonDeps = globalThis.projPackageJsonDeps || {};
|
|
22
|
+
globalThis.projPackageJsonDeps[packageJsonPath] = {
|
|
20
23
|
...packageJson.dependencies,
|
|
21
24
|
...packageJson.peerDependencies,
|
|
22
25
|
...packageJson.optionalDependencies,
|
|
23
26
|
};
|
|
24
27
|
}
|
|
25
|
-
return globalThis.projPackageJsonDeps;
|
|
28
|
+
return globalThis.projPackageJsonDeps[packageJsonPath];
|
|
26
29
|
}
|
|
27
30
|
exports.getProductionDependencies = getProductionDependencies;
|
|
28
31
|
function getPackageJson(path) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ProjectGraph, ProjectGraphDependency, ProjectGraphExternalNode, ProjectGraphProjectNode } from '@nx/devkit';
|
|
2
2
|
import { ProjectRootMappings } from 'nx/src/project-graph/utils/find-project-for-path';
|
|
3
3
|
import { TargetProjectLocator } from '@nx/js/src/internal';
|
|
4
|
+
import { TSESTree } from '@typescript-eslint/utils';
|
|
4
5
|
export type Deps = {
|
|
5
6
|
[projectName: string]: ProjectGraphDependency[];
|
|
6
7
|
};
|
|
@@ -39,7 +40,7 @@ export declare function isAbsoluteImportIntoAnotherProject(imp: string, workspac
|
|
|
39
40
|
}): boolean;
|
|
40
41
|
export declare function findProjectUsingImport(projectGraph: ProjectGraph, targetProjectLocator: TargetProjectLocator, filePath: string, imp: string): ProjectGraphProjectNode | ProjectGraphExternalNode;
|
|
41
42
|
export declare function findConstraintsFor(depConstraints: DepConstraint[], sourceProject: ProjectGraphProjectNode): DepConstraint[];
|
|
42
|
-
export declare function
|
|
43
|
+
export declare function hasStaticImportOfDynamicResource(node: TSESTree.ImportDeclaration | TSESTree.ImportExpression | TSESTree.ExportAllDeclaration | TSESTree.ExportNamedDeclaration, graph: ProjectGraph, sourceProjectName: string, targetProjectName: string): boolean;
|
|
43
44
|
export declare function getSourceFilePath(sourceFileName: string, projectPath: string): string;
|
|
44
45
|
export declare function hasBannedImport(source: ProjectGraphProjectNode, target: ProjectGraphExternalNode, depConstraints: DepConstraint[], imp: string): DepConstraint | undefined;
|
|
45
46
|
/**
|
|
@@ -77,12 +78,9 @@ export declare function groupImports(importsToRemap: {
|
|
|
77
78
|
importPath: string;
|
|
78
79
|
}[]): string;
|
|
79
80
|
/**
|
|
80
|
-
* Checks if
|
|
81
|
-
* @param targetProjectLocator
|
|
82
|
-
* @param importExpr
|
|
83
|
-
* @returns
|
|
81
|
+
* Checks if source file belongs to a secondary entry point different than the import one
|
|
84
82
|
*/
|
|
85
|
-
export declare function
|
|
83
|
+
export declare function belongsToDifferentNgEntryPoint(importExpr: string, filePath: string, projectRoot: string): boolean;
|
|
86
84
|
/**
|
|
87
85
|
* Returns true if the given project contains MFE config with "exposes:" section
|
|
88
86
|
*/
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.appIsMFERemote = exports.
|
|
4
|
-
const
|
|
3
|
+
exports.appIsMFERemote = exports.belongsToDifferentNgEntryPoint = exports.groupImports = exports.isTerminalRun = exports.hasBuildExecutor = exports.isDirectDependency = exports.hasBannedDependencies = exports.findTransitiveExternalDependencies = exports.hasBannedImport = exports.getSourceFilePath = exports.hasStaticImportOfDynamicResource = exports.findConstraintsFor = exports.findProjectUsingImport = exports.isAbsoluteImportIntoAnotherProject = exports.findProject = exports.getTargetProjectBasedOnRelativeImport = exports.isRelative = exports.matchImportWithWildcard = exports.findDependenciesWithTags = exports.isComboDepConstraint = exports.hasNoneOfTheseTags = exports.stringifyTags = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const path = tslib_1.__importStar(require("path"));
|
|
5
6
|
const path_1 = require("path");
|
|
6
7
|
const devkit_1 = require("@nx/devkit");
|
|
7
8
|
const graph_utils_1 = require("./graph-utils");
|
|
@@ -9,6 +10,7 @@ const fileutils_1 = require("nx/src/utils/fileutils");
|
|
|
9
10
|
const find_project_for_path_1 = require("nx/src/project-graph/utils/find-project-for-path");
|
|
10
11
|
const js_1 = require("@nx/js");
|
|
11
12
|
const internal_1 = require("@nx/js/src/internal");
|
|
13
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
12
14
|
function stringifyTags(tags) {
|
|
13
15
|
return tags.map((t) => `"${t}"`).join(', ');
|
|
14
16
|
}
|
|
@@ -123,21 +125,31 @@ function findConstraintsFor(depConstraints, sourceProject) {
|
|
|
123
125
|
});
|
|
124
126
|
}
|
|
125
127
|
exports.findConstraintsFor = findConstraintsFor;
|
|
128
|
+
function hasStaticImportOfDynamicResource(node, graph, sourceProjectName, targetProjectName) {
|
|
129
|
+
if (node.type !== utils_1.AST_NODE_TYPES.ImportDeclaration ||
|
|
130
|
+
node.importKind === 'type') {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
return onlyLoadChildren(graph, sourceProjectName, targetProjectName, []);
|
|
134
|
+
}
|
|
135
|
+
exports.hasStaticImportOfDynamicResource = hasStaticImportOfDynamicResource;
|
|
126
136
|
function onlyLoadChildren(graph, sourceProjectName, targetProjectName, visited) {
|
|
127
|
-
if (visited.indexOf(sourceProjectName) > -1)
|
|
137
|
+
if (visited.indexOf(sourceProjectName) > -1) {
|
|
128
138
|
return false;
|
|
139
|
+
}
|
|
129
140
|
return ((graph.dependencies[sourceProjectName] || []).filter((d) => {
|
|
130
|
-
if (d.type !== devkit_1.DependencyType.dynamic)
|
|
141
|
+
if (d.type !== devkit_1.DependencyType.dynamic) {
|
|
131
142
|
return false;
|
|
132
|
-
|
|
143
|
+
}
|
|
144
|
+
if (d.target === targetProjectName) {
|
|
133
145
|
return true;
|
|
146
|
+
}
|
|
134
147
|
return onlyLoadChildren(graph, d.target, targetProjectName, [
|
|
135
148
|
...visited,
|
|
136
149
|
sourceProjectName,
|
|
137
150
|
]);
|
|
138
151
|
}).length > 0);
|
|
139
152
|
}
|
|
140
|
-
exports.onlyLoadChildren = onlyLoadChildren;
|
|
141
153
|
function getSourceFilePath(sourceFileName, projectPath) {
|
|
142
154
|
const normalizedProjectPath = (0, devkit_1.normalizePath)(projectPath);
|
|
143
155
|
const normalizedSourceFileName = (0, devkit_1.normalizePath)(sourceFileName);
|
|
@@ -270,7 +282,7 @@ function hasBuildExecutor(projectGraph, buildTargets = ['build']) {
|
|
|
270
282
|
projectGraph.data.targets[target].executor !== ''));
|
|
271
283
|
}
|
|
272
284
|
exports.hasBuildExecutor = hasBuildExecutor;
|
|
273
|
-
const ESLINT_REGEX = /node_modules.*[\/\\]eslint
|
|
285
|
+
const ESLINT_REGEX = /node_modules.*[\/\\]eslint(?:\.js)?$/;
|
|
274
286
|
const JEST_REGEX = /node_modules\/.bin\/jest$/; // when we run unit tests in jest
|
|
275
287
|
const NRWL_CLI_REGEX = /nx[\/\\]bin[\/\\]run-executor\.js$/;
|
|
276
288
|
function isTerminalRun() {
|
|
@@ -310,17 +322,21 @@ function groupImports(importsToRemap) {
|
|
|
310
322
|
}
|
|
311
323
|
exports.groupImports = groupImports;
|
|
312
324
|
/**
|
|
313
|
-
* Checks if
|
|
314
|
-
* @param targetProjectLocator
|
|
315
|
-
* @param importExpr
|
|
316
|
-
* @returns
|
|
325
|
+
* Checks if source file belongs to a secondary entry point different than the import one
|
|
317
326
|
*/
|
|
318
|
-
function
|
|
319
|
-
const
|
|
320
|
-
|
|
327
|
+
function belongsToDifferentNgEntryPoint(importExpr, filePath, projectRoot) {
|
|
328
|
+
const resolvedImportFile = (0, internal_1.resolveModuleByImport)(importExpr, filePath, // not strictly necessary, but speeds up resolution
|
|
329
|
+
(0, path_1.join)(devkit_1.workspaceRoot, (0, js_1.getRootTsConfigFileName)()));
|
|
330
|
+
if (!resolvedImportFile) {
|
|
331
|
+
return false;
|
|
332
|
+
}
|
|
333
|
+
const importEntryPoint = getAngularEntryPoint(resolvedImportFile, projectRoot);
|
|
334
|
+
const srcEntryPoint = getAngularEntryPoint(filePath, projectRoot);
|
|
335
|
+
// check if the entry point of import expression is different than the source file's entry point
|
|
336
|
+
return importEntryPoint !== srcEntryPoint;
|
|
321
337
|
}
|
|
322
|
-
exports.
|
|
323
|
-
function
|
|
338
|
+
exports.belongsToDifferentNgEntryPoint = belongsToDifferentNgEntryPoint;
|
|
339
|
+
function getAngularEntryPoint(file, projectRoot) {
|
|
324
340
|
let parent = (0, devkit_1.joinPathFragments)(file, '../');
|
|
325
341
|
while (parent !== `${projectRoot}/`) {
|
|
326
342
|
// we need to find closest existing ng-package.json
|
|
@@ -329,11 +345,11 @@ function fileIsSecondaryEntryPoint(file, projectRoot) {
|
|
|
329
345
|
if (ngPackageContent) {
|
|
330
346
|
// https://github.com/ng-packagr/ng-packagr/blob/23c718d04eea85e015b4c261310b7bd0c39e5311/src/ng-package.schema.json#L54
|
|
331
347
|
const entryFile = (0, devkit_1.parseJson)(ngPackageContent)?.lib?.entryFile;
|
|
332
|
-
return
|
|
348
|
+
return (0, devkit_1.joinPathFragments)(parent, entryFile);
|
|
333
349
|
}
|
|
334
350
|
parent = (0, devkit_1.joinPathFragments)(parent, '../');
|
|
335
351
|
}
|
|
336
|
-
return
|
|
352
|
+
return undefined;
|
|
337
353
|
}
|
|
338
354
|
/**
|
|
339
355
|
* Returns true if the given project contains MFE config with "exposes:" section
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
|
-
export declare const createESLintRule: <TOptions extends readonly unknown[], TMessageIds extends string, TRuleListener extends import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener = import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>({ name, meta, ...rule }: Readonly<ESLintUtils.RuleWithMetaAndName<TOptions, TMessageIds, TRuleListener>>) => import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<TMessageIds, TOptions, TRuleListener>;
|