fix(core): fix lint failures for npm packages (#3827)
This commit is contained in:
parent
6885507567
commit
f057978400
@ -18,6 +18,7 @@ import { createESLintRule } from '../utils/create-eslint-rule';
|
||||
import { normalize } from '@angular-devkit/core';
|
||||
import {
|
||||
createProjectGraph,
|
||||
isNpmProject,
|
||||
ProjectGraph,
|
||||
ProjectType,
|
||||
} from '@nrwl/workspace/src/core/project-graph';
|
||||
@ -169,6 +170,10 @@ export default createESLintRule<Options, MessageIds>({
|
||||
return;
|
||||
}
|
||||
|
||||
// project => npm package
|
||||
if (isNpmProject(targetProject)) {
|
||||
return;
|
||||
}
|
||||
// check constraints between libs and apps
|
||||
// check for circular dependency
|
||||
const circularPath = checkCircularPath(
|
||||
|
||||
@ -248,6 +248,15 @@ describe('Enforce Module Boundaries', () => {
|
||||
files: [createFile(`libs/untagged/src/index.ts`)],
|
||||
},
|
||||
},
|
||||
npmPackage: {
|
||||
name: 'npm:npm-package',
|
||||
type: 'npm',
|
||||
data: {
|
||||
packageName: 'npm-package',
|
||||
version: '0.0.0',
|
||||
files: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
dependencies: {},
|
||||
};
|
||||
@ -280,6 +289,18 @@ describe('Enforce Module Boundaries', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should allow imports to npm packages', () => {
|
||||
const failures = runRule(
|
||||
depConstraints,
|
||||
`${process.cwd()}/proj/libs/api/src/index.ts`,
|
||||
`
|
||||
import 'npm-package';
|
||||
`,
|
||||
graph
|
||||
);
|
||||
expect(failures.length).toEqual(0);
|
||||
});
|
||||
|
||||
it('should error when the target library is untagged', () => {
|
||||
const failures = runRule(
|
||||
depConstraints,
|
||||
|
||||
@ -244,6 +244,18 @@ describe('Enforce Module Boundaries', () => {
|
||||
files: [createFile(`libs/untagged/src/index.ts`)],
|
||||
},
|
||||
},
|
||||
npmPackage: {
|
||||
name: 'npmPackage',
|
||||
type: 'npm',
|
||||
data: {
|
||||
packageName: 'npm-package',
|
||||
version: '0.0.0',
|
||||
tags: [],
|
||||
implicitDependencies: [],
|
||||
architect: {},
|
||||
files: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
dependencies: {},
|
||||
};
|
||||
@ -276,6 +288,19 @@ describe('Enforce Module Boundaries', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should allow imports to npm projects', () => {
|
||||
const failures = runRule(
|
||||
depConstraints,
|
||||
`${process.cwd()}/proj/libs/api/src/index.ts`,
|
||||
`
|
||||
import 'npm-package';
|
||||
`,
|
||||
graph
|
||||
);
|
||||
|
||||
expect(failures.length).toEqual(0);
|
||||
});
|
||||
|
||||
it('should error when the target library is untagged', () => {
|
||||
const failures = runRule(
|
||||
depConstraints,
|
||||
|
||||
@ -3,6 +3,7 @@ import { IOptions } from 'tslint';
|
||||
import * as ts from 'typescript';
|
||||
import {
|
||||
createProjectGraph,
|
||||
isNpmProject,
|
||||
ProjectGraph,
|
||||
ProjectType,
|
||||
} from '../core/project-graph';
|
||||
@ -160,6 +161,12 @@ class EnforceModuleBoundariesWalker extends Lint.RuleWalker {
|
||||
return;
|
||||
}
|
||||
|
||||
// project => npm package
|
||||
if (isNpmProject(targetProject)) {
|
||||
super.visitImportDeclaration(node);
|
||||
return;
|
||||
}
|
||||
|
||||
// check for circular dependency
|
||||
const circularPath = checkCircularPath(
|
||||
this.projectGraph,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user