fix(linter): ensure fs operations run on full path (#12953)

This commit is contained in:
Miroslav Jonaš 2022-11-02 22:08:14 +01:00 committed by GitHub
parent 4ca743ea54
commit c3db8e6070
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 7 deletions

View File

@ -248,7 +248,7 @@ export default createESLintRule<Options, MessageIds>({
for (const importMember of imports) {
const importPath = getRelativeImportPath(
importMember,
entryPointPath.path,
joinPathFragments(workspaceRoot, entryPointPath.path),
sourceProject.data.sourceRoot
);
// we cannot remap, so leave it as is
@ -322,7 +322,7 @@ export default createESLintRule<Options, MessageIds>({
for (const importMember of imports) {
const importPath = getRelativeImportPath(
importMember,
entryPointPath,
joinPathFragments(workspaceRoot, entryPointPath),
sourceProject.data.sourceRoot
);
if (importPath) {

View File

@ -7,8 +7,7 @@ import { findNodes } from '@nrwl/workspace/src/utilities/typescript';
import { existsSync, readFileSync } from 'fs';
import { dirname } from 'path';
import ts = require('typescript');
import { logger } from '@nrwl/devkit';
import { workspaceRoot } from '@nrwl/devkit';
import { logger, workspaceRoot } from '@nrwl/devkit';
function tryReadBaseJson() {
try {
@ -200,14 +199,12 @@ export function getRelativeImportPath(exportedMember, filePath, basePath) {
const modulePath = (exportDeclaration as any).moduleSpecifier.text;
let moduleFilePath = joinPathFragments(
'./',
dirname(filePath),
`${modulePath}.ts`
);
if (!existsSync(moduleFilePath)) {
// might be a index.ts
moduleFilePath = joinPathFragments(
'./',
dirname(filePath),
`${modulePath}/index.ts`
);

View File

@ -437,7 +437,9 @@ export function isAngularSecondaryEntrypoint(
// The `ng-packagr` defaults to the `src/public_api.ts` entry file to
// the public API if the `lib.entryFile` is not specified explicitly.
(file.endsWith('src/public_api.ts') || file.endsWith('src/index.ts')) &&
existsSync(joinPathFragments(file, '../../', 'ng-package.json'))
existsSync(
joinPathFragments(workspaceRoot, file, '../../', 'ng-package.json')
)
)
);
}