Skip to content

Commit

Permalink
fix(linter): ensure fs operations run on full path (#12953)
Browse files Browse the repository at this point in the history
  • Loading branch information
meeroslav committed Nov 2, 2022
1 parent 4ca743e commit c3db8e6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 1 addition & 4 deletions packages/eslint-plugin-nx/src/utils/ast-utils.ts
Expand Up @@ -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 {
Expand Down Expand Up @@ -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`
);
Expand Down
4 changes: 3 additions & 1 deletion packages/workspace/src/utils/runtime-lint-utils.ts
Expand Up @@ -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')
)
)
);
}

1 comment on commit c3db8e6

@vercel
Copy link

@vercel vercel bot commented on c3db8e6 Nov 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-five.vercel.app
nx.dev
nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app

Please sign in to comment.