@nx/eslint-plugin 23.2.0-beta.4 → 23.2.0-beta.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/dist/src/rules/enforce-module-boundaries.js +4 -5
- package/dist/src/utils/graph-utils.js +7 -7
- package/dist/src/utils/package-json-utils.d.ts +1 -1
- package/dist/src/utils/project-graph-utils.d.ts +1 -1
- package/dist/src/utils/project-graph-utils.js +4 -6
- package/dist/src/utils/runtime-lint-utils.d.ts +1 -1
- package/dist/src/utils/runtime-lint-utils.js +7 -8
- package/package.json +4 -4
|
@@ -4,13 +4,12 @@ exports.RULE_NAME = void 0;
|
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const utils_1 = require("@typescript-eslint/utils");
|
|
6
6
|
const internal_1 = require("@nx/js/internal");
|
|
7
|
-
const fileutils_1 = require("nx/src/utils/fileutils");
|
|
8
7
|
const path_1 = require("path");
|
|
9
8
|
const ast_utils_1 = require("../utils/ast-utils");
|
|
10
9
|
const graph_utils_1 = require("../utils/graph-utils");
|
|
11
10
|
const project_graph_utils_1 = require("../utils/project-graph-utils");
|
|
12
11
|
const runtime_lint_utils_1 = require("../utils/runtime-lint-utils");
|
|
13
|
-
const
|
|
12
|
+
const internal_2 = require("@nx/devkit/internal");
|
|
14
13
|
exports.RULE_NAME = 'enforce-module-boundaries';
|
|
15
14
|
exports.default = utils_1.ESLintUtils.RuleCreator(() => `https://github.com/nrwl/nx/blob/${devkit_1.NX_VERSION}/docs/generated/packages/eslint-plugin/documents/enforce-module-boundaries.md`)({
|
|
16
15
|
name: exports.RULE_NAME,
|
|
@@ -236,7 +235,7 @@ exports.default = utils_1.ESLintUtils.RuleCreator(() => `https://github.com/nrwl
|
|
|
236
235
|
(0, runtime_lint_utils_1.findProjectUsingImport)(projectGraph, targetProjectLocator, sourceFilePath, imp);
|
|
237
236
|
if (!targetProject) {
|
|
238
237
|
// non-project imports cannot use relative or absolute paths
|
|
239
|
-
if ((0,
|
|
238
|
+
if ((0, internal_2.isRelativePath)(imp) || imp.startsWith('/')) {
|
|
240
239
|
context.report({
|
|
241
240
|
node,
|
|
242
241
|
messageId: 'noRelativeOrAbsoluteExternals',
|
|
@@ -264,7 +263,7 @@ exports.default = utils_1.ESLintUtils.RuleCreator(() => `https://github.com/nrwl
|
|
|
264
263
|
if (sourceProject === targetProject &&
|
|
265
264
|
!(0, graph_utils_1.circularPathHasPair)([sourceProject, targetProject], expandedIgnoreCircularDependencies)) {
|
|
266
265
|
if (!allowCircularSelfDependency &&
|
|
267
|
-
!(0,
|
|
266
|
+
!(0, internal_2.isRelativePath)(imp) &&
|
|
268
267
|
!(0, runtime_lint_utils_1.belongsToDifferentEntryPoint)(imp, sourceFilePath, sourceProject.data.root)) {
|
|
269
268
|
context.report({
|
|
270
269
|
node,
|
|
@@ -343,7 +342,7 @@ exports.default = utils_1.ESLintUtils.RuleCreator(() => `https://github.com/nrwl
|
|
|
343
342
|
}
|
|
344
343
|
return;
|
|
345
344
|
}
|
|
346
|
-
if (!(0,
|
|
345
|
+
if (!(0, internal_2.isProjectGraphProjectNode)(targetProject)) {
|
|
347
346
|
return;
|
|
348
347
|
}
|
|
349
348
|
targetProject = targetProject;
|
|
@@ -7,8 +7,8 @@ exports.circularPathHasPair = circularPathHasPair;
|
|
|
7
7
|
exports.findFilesInCircularPath = findFilesInCircularPath;
|
|
8
8
|
exports.findFilesWithDynamicImports = findFilesWithDynamicImports;
|
|
9
9
|
exports.expandIgnoredCircularDependencies = expandIgnoredCircularDependencies;
|
|
10
|
-
const
|
|
11
|
-
const
|
|
10
|
+
const devkit_1 = require("@nx/devkit");
|
|
11
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
12
12
|
const reach = {
|
|
13
13
|
graph: null,
|
|
14
14
|
matrix: null,
|
|
@@ -125,7 +125,7 @@ function findFilesInCircularPath(projectFileMap, circularPath) {
|
|
|
125
125
|
const next = circularPath[i + 1].name;
|
|
126
126
|
const files = projectFileMap[circularPath[i].name] || [];
|
|
127
127
|
filePathChain.push(files
|
|
128
|
-
.filter((file) => file.deps && file.deps.find((d) => (0,
|
|
128
|
+
.filter((file) => file.deps && file.deps.find((d) => (0, internal_1.fileDataDepTarget)(d) === next))
|
|
129
129
|
.map((file) => file.file));
|
|
130
130
|
}
|
|
131
131
|
return filePathChain;
|
|
@@ -135,8 +135,8 @@ function findFilesWithDynamicImports(projectFileMap, sourceProjectName, targetPr
|
|
|
135
135
|
projectFileMap[sourceProjectName].forEach((file) => {
|
|
136
136
|
if (!file.deps)
|
|
137
137
|
return;
|
|
138
|
-
if (file.deps.some((d) => (0,
|
|
139
|
-
(0,
|
|
138
|
+
if (file.deps.some((d) => (0, internal_1.fileDataDepTarget)(d) === targetProjectName &&
|
|
139
|
+
(0, internal_1.fileDataDepType)(d) === devkit_1.DependencyType.dynamic)) {
|
|
140
140
|
files.push(file);
|
|
141
141
|
}
|
|
142
142
|
});
|
|
@@ -145,8 +145,8 @@ function findFilesWithDynamicImports(projectFileMap, sourceProjectName, targetPr
|
|
|
145
145
|
function expandIgnoredCircularDependencies(ignoredCircularDependencies, projectGraph) {
|
|
146
146
|
const allowed = new Map();
|
|
147
147
|
for (const [a, b] of ignoredCircularDependencies) {
|
|
148
|
-
const setA = new Set((0,
|
|
149
|
-
const setB = new Set((0,
|
|
148
|
+
const setA = new Set((0, internal_1.findMatchingProjects)([a], projectGraph.nodes));
|
|
149
|
+
const setB = new Set((0, internal_1.findMatchingProjects)([b], projectGraph.nodes));
|
|
150
150
|
for (const projectA of setA) {
|
|
151
151
|
if (!allowed.has(projectA)) {
|
|
152
152
|
allowed.set(projectA, new Set());
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type PackageJson } from '@nx/devkit/internal';
|
|
2
2
|
export declare function getAllDependencies(packageJson: PackageJson): Record<string, string>;
|
|
3
3
|
export declare function getProductionDependencies(packageJson: PackageJson): Record<string, string>;
|
|
4
4
|
export declare function getPackageJson(path: string): PackageJson;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ProjectFileMap, ProjectGraph } from '@nx/devkit';
|
|
2
|
-
import { ProjectRootMappings } from 'nx/src/project-graph/utils/find-project-for-path';
|
|
3
2
|
import { TargetProjectLocator } from '@nx/js/internal';
|
|
3
|
+
import { ProjectRootMappings } from '@nx/devkit/internal';
|
|
4
4
|
export declare function ensureGlobalProjectGraph(ruleName: string): void;
|
|
5
5
|
export declare function readProjectGraph(ruleName: string): {
|
|
6
6
|
projectGraph: ProjectGraph;
|
|
@@ -6,10 +6,8 @@ const tslib_1 = require("tslib");
|
|
|
6
6
|
const devkit_1 = require("@nx/devkit");
|
|
7
7
|
const runtime_lint_utils_1 = require("./runtime-lint-utils");
|
|
8
8
|
const picocolors_1 = tslib_1.__importDefault(require("picocolors"));
|
|
9
|
-
const find_project_for_path_1 = require("nx/src/project-graph/utils/find-project-for-path");
|
|
10
|
-
const configuration_1 = require("nx/src/config/configuration");
|
|
11
9
|
const internal_1 = require("@nx/js/internal");
|
|
12
|
-
const
|
|
10
|
+
const internal_2 = require("@nx/devkit/internal");
|
|
13
11
|
function ensureGlobalProjectGraph(ruleName) {
|
|
14
12
|
/**
|
|
15
13
|
* Only reuse graph when running from terminal
|
|
@@ -19,7 +17,7 @@ function ensureGlobalProjectGraph(ruleName) {
|
|
|
19
17
|
!globalThis.projectRootMappings ||
|
|
20
18
|
!globalThis.projectFileMap ||
|
|
21
19
|
!(0, runtime_lint_utils_1.isTerminalRun)()) {
|
|
22
|
-
const nxJson = (0,
|
|
20
|
+
const nxJson = (0, internal_2.readNxJsonFromDisk)();
|
|
23
21
|
globalThis.workspaceLayout = nxJson.workspaceLayout;
|
|
24
22
|
/**
|
|
25
23
|
* Because there are a number of ways in which the rule can be invoked (executor vs ESLint CLI vs IDE Plugin),
|
|
@@ -28,8 +26,8 @@ function ensureGlobalProjectGraph(ruleName) {
|
|
|
28
26
|
try {
|
|
29
27
|
const projectGraph = (0, devkit_1.readCachedProjectGraph)();
|
|
30
28
|
globalThis.projectGraph = projectGraph;
|
|
31
|
-
globalThis.projectRootMappings = (0,
|
|
32
|
-
globalThis.projectFileMap = (0,
|
|
29
|
+
globalThis.projectRootMappings = (0, internal_2.createProjectRootMappings)(projectGraph.nodes);
|
|
30
|
+
globalThis.projectFileMap = (0, internal_2.readFileMapCache)().fileMap.projectFileMap;
|
|
33
31
|
globalThis.targetProjectLocator = new internal_1.TargetProjectLocator(projectGraph.nodes, projectGraph.externalNodes);
|
|
34
32
|
}
|
|
35
33
|
catch {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ProjectGraph, ProjectGraphDependency, ProjectGraphExternalNode, ProjectGraphProjectNode } from '@nx/devkit';
|
|
2
2
|
import { TargetProjectLocator } from '@nx/js/internal';
|
|
3
3
|
import { TSESLint, TSESTree } from '@typescript-eslint/utils';
|
|
4
|
-
import { ProjectRootMappings } from 'nx/
|
|
4
|
+
import { ProjectRootMappings } from '@nx/devkit/internal';
|
|
5
5
|
export type Deps = {
|
|
6
6
|
[projectName: string]: ProjectGraphDependency[];
|
|
7
7
|
};
|
|
@@ -30,9 +30,8 @@ const devkit_1 = require("@nx/devkit");
|
|
|
30
30
|
const js_1 = require("@nx/js");
|
|
31
31
|
const utils_1 = require("@typescript-eslint/utils");
|
|
32
32
|
const path = tslib_1.__importStar(require("node:path"));
|
|
33
|
-
const find_project_for_path_1 = require("nx/src/project-graph/utils/find-project-for-path");
|
|
34
|
-
const fileutils_1 = require("nx/src/utils/fileutils");
|
|
35
33
|
const graph_utils_1 = require("./graph-utils");
|
|
34
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
36
35
|
function stringifyTags(tags) {
|
|
37
36
|
return tags.map((t) => `"${t}"`).join(', ');
|
|
38
37
|
}
|
|
@@ -114,7 +113,7 @@ function getTargetProjectBasedOnRelativeImport(imp, projectPath, projectGraph, p
|
|
|
114
113
|
return findProject(projectGraph, projectRootMappings, targetFile);
|
|
115
114
|
}
|
|
116
115
|
function findProject(projectGraph, projectRootMappings, sourceFilePath) {
|
|
117
|
-
return projectGraph.nodes[(0,
|
|
116
|
+
return projectGraph.nodes[(0, internal_1.findProjectForPath)(sourceFilePath, projectRootMappings)];
|
|
118
117
|
}
|
|
119
118
|
function isAbsoluteImportIntoAnotherProject(imp, workspaceLayout = { libsDir: 'libs', appsDir: 'apps' }) {
|
|
120
119
|
return (imp.startsWith(`${workspaceLayout.libsDir}/`) ||
|
|
@@ -252,7 +251,7 @@ function isDirectDependency(source, target) {
|
|
|
252
251
|
packageExistsInPackageJson(target.data.packageName, source.data.root));
|
|
253
252
|
}
|
|
254
253
|
function packageExistsInPackageJson(packageName, projectRoot) {
|
|
255
|
-
const content = (0,
|
|
254
|
+
const content = (0, internal_1.readFileIfExisting)(path.join(devkit_1.workspaceRoot, projectRoot, 'package.json'));
|
|
256
255
|
if (content) {
|
|
257
256
|
const { dependencies, devDependencies, peerDependencies } = (0, devkit_1.parseJson)(content);
|
|
258
257
|
if (dependencies && dependencies[packageName]) {
|
|
@@ -356,7 +355,7 @@ function getEntryPoint(file, projectRoot) {
|
|
|
356
355
|
}
|
|
357
356
|
// for Angular we need to find closest existing ng-package.json
|
|
358
357
|
// in order to determine if the file matches the secondary entry point
|
|
359
|
-
const ngPackageContent = (0,
|
|
358
|
+
const ngPackageContent = (0, internal_1.readFileIfExisting)(path.join(devkit_1.workspaceRoot, parent, 'ng-package.json'));
|
|
360
359
|
if (ngPackageContent) {
|
|
361
360
|
// https://github.com/ng-packagr/ng-packagr/blob/23c718d04eea85e015b4c261310b7bd0c39e5311/src/ng-package.schema.json#L54
|
|
362
361
|
const entryFile = (0, devkit_1.parseJson)(ngPackageContent)?.lib?.entryFile ?? 'src/public_api.ts';
|
|
@@ -367,7 +366,7 @@ function getEntryPoint(file, projectRoot) {
|
|
|
367
366
|
return undefined;
|
|
368
367
|
}
|
|
369
368
|
function getPackageEntryPoints(projectRoot) {
|
|
370
|
-
const packageContent = (0,
|
|
369
|
+
const packageContent = (0, internal_1.readFileIfExisting)(path.join(devkit_1.workspaceRoot, projectRoot, 'package.json'));
|
|
371
370
|
if (!packageContent) {
|
|
372
371
|
return [];
|
|
373
372
|
}
|
|
@@ -409,8 +408,8 @@ function parseExports(exports, projectRoot, entryPaths, basePath = '.') {
|
|
|
409
408
|
* Returns true if the given project contains MFE config with "exposes:" section
|
|
410
409
|
*/
|
|
411
410
|
function appIsMFERemote(project) {
|
|
412
|
-
const mfeConfig = (0,
|
|
413
|
-
(0,
|
|
411
|
+
const mfeConfig = (0, internal_1.readFileIfExisting)(path.join(devkit_1.workspaceRoot, project.data.root, 'module-federation.config.js')) ||
|
|
412
|
+
(0, internal_1.readFileIfExisting)(path.join(devkit_1.workspaceRoot, project.data.root, 'module-federation.config.ts'));
|
|
414
413
|
if (mfeConfig) {
|
|
415
414
|
return !!mfeConfig.match(/('|")?exposes('|")?:/);
|
|
416
415
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/eslint-plugin",
|
|
3
|
-
"version": "23.2.0-beta.
|
|
3
|
+
"version": "23.2.0-beta.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"files": [
|
|
@@ -101,11 +101,11 @@
|
|
|
101
101
|
"picocolors": "^1.1.0",
|
|
102
102
|
"semver": "^7.6.3",
|
|
103
103
|
"tslib": "^2.3.0",
|
|
104
|
-
"@nx/
|
|
105
|
-
"@nx/
|
|
104
|
+
"@nx/js": "23.2.0-beta.5",
|
|
105
|
+
"@nx/devkit": "23.2.0-beta.5"
|
|
106
106
|
},
|
|
107
107
|
"devDependencies": {
|
|
108
|
-
"nx": "23.2.0-beta.
|
|
108
|
+
"nx": "23.2.0-beta.5"
|
|
109
109
|
},
|
|
110
110
|
"publishConfig": {
|
|
111
111
|
"access": "public"
|