Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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')
)
)
);
}