Skip to content

Commit

Permalink
fix: check if dependency path type is directory with bit flag (#1267)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cammisuli authored Apr 8, 2022
1 parent d10ae62 commit e75daac
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
31 changes: 26 additions & 5 deletions libs/npm/src/lib/workspace-dependencies.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PartialDeep } from 'type-fest';
import { mocked } from 'ts-jest/utils';

import { workspaceDependencyPath } from './workspace-dependencies';

Expand All @@ -12,32 +13,33 @@ jest.mock(
),
})
);
const mockedPnpDependencies = pnpDependencies as jest.Mocked<
typeof pnpDependencies
>;
const mockedPnpDependencies = mocked(pnpDependencies);

import * as vscode from 'vscode';
jest.mock('vscode', (): PartialDeep<typeof vscode> => {
return {
FileType: {
Directory: 2,
SymbolicLink: 64,
},
Uri: {
file: jest.fn((path) => path as any),
},
workspace: {
fs: {
stat: () =>
stat: jest.fn(() =>
Promise.resolve({
ctime: 0,
mtime: 0,
size: 0,
type: 2,
}),
})
),
},
},
};
});
const mockedVsCode = mocked(vscode, true);

describe('workspace-dependencies path', () => {
it('should return a path to a workspace dependency when using node_modules', async () => {
Expand Down Expand Up @@ -72,4 +74,23 @@ describe('workspace-dependencies path', () => {
`"/workspace/tools/local/executor"`
);
});

it('should support symbolic directory links', async () => {
mockedVsCode.workspace.fs.stat.mockImplementationOnce(() => {
return Promise.resolve({
ctime: 0,
mtime: 0,
size: 0,
type: 66,
});
});

const dependencyPath = await workspaceDependencyPath(
'/workspace',
'@nrwl/nx'
);
expect(dependencyPath).toMatchInlineSnapshot(
`"/workspace/node_modules/@nrwl/nx"`
);
});
});
3 changes: 2 additions & 1 deletion libs/npm/src/lib/workspace-dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export async function workspaceDependencyPath(

const path = join(workspacePath, 'node_modules', workspaceDependencyName);
try {
return (await workspace.fs.stat(Uri.file(path))).type === FileType.Directory
const directoryType = (await workspace.fs.stat(Uri.file(path))).type;
return (directoryType & FileType.Directory) === FileType.Directory
? path
: undefined;
} catch {
Expand Down

0 comments on commit e75daac

Please sign in to comment.