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: check if dependency path type is directory with bit flag #1267

Merged
merged 3 commits into from
Apr 8, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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