From c3db8e60705688e4629ae2116c89a34d4f993a08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Jona=C5=A1?= Date: Wed, 2 Nov 2022 22:08:14 +0100 Subject: [PATCH] fix(linter): ensure fs operations run on full path (#12953) --- .../eslint-plugin-nx/src/rules/enforce-module-boundaries.ts | 4 ++-- packages/eslint-plugin-nx/src/utils/ast-utils.ts | 5 +---- packages/workspace/src/utils/runtime-lint-utils.ts | 4 +++- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/eslint-plugin-nx/src/rules/enforce-module-boundaries.ts b/packages/eslint-plugin-nx/src/rules/enforce-module-boundaries.ts index ea637fef0f..1ac7200d0f 100644 --- a/packages/eslint-plugin-nx/src/rules/enforce-module-boundaries.ts +++ b/packages/eslint-plugin-nx/src/rules/enforce-module-boundaries.ts @@ -248,7 +248,7 @@ export default createESLintRule({ 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({ for (const importMember of imports) { const importPath = getRelativeImportPath( importMember, - entryPointPath, + joinPathFragments(workspaceRoot, entryPointPath), sourceProject.data.sourceRoot ); if (importPath) { diff --git a/packages/eslint-plugin-nx/src/utils/ast-utils.ts b/packages/eslint-plugin-nx/src/utils/ast-utils.ts index d5d5f04c8e..9e4b56e5aa 100644 --- a/packages/eslint-plugin-nx/src/utils/ast-utils.ts +++ b/packages/eslint-plugin-nx/src/utils/ast-utils.ts @@ -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` ); diff --git a/packages/workspace/src/utils/runtime-lint-utils.ts b/packages/workspace/src/utils/runtime-lint-utils.ts index e4fae64f86..475108a6d9 100644 --- a/packages/workspace/src/utils/runtime-lint-utils.ts +++ b/packages/workspace/src/utils/runtime-lint-utils.ts @@ -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') + ) ) ); }