diff --git a/libs/npm/src/lib/workspace-dependencies.spec.ts b/libs/npm/src/lib/workspace-dependencies.spec.ts index 7b4a28e499..766723fb98 100644 --- a/libs/npm/src/lib/workspace-dependencies.spec.ts +++ b/libs/npm/src/lib/workspace-dependencies.spec.ts @@ -1,4 +1,5 @@ import { PartialDeep } from 'type-fest'; +import { mocked } from 'ts-jest/utils'; import { workspaceDependencyPath } from './workspace-dependencies'; @@ -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 => { 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 () => { @@ -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"` + ); + }); }); diff --git a/libs/npm/src/lib/workspace-dependencies.ts b/libs/npm/src/lib/workspace-dependencies.ts index 6902979779..718260d2c7 100644 --- a/libs/npm/src/lib/workspace-dependencies.ts +++ b/libs/npm/src/lib/workspace-dependencies.ts @@ -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 {