From 4e6c40fe682d68309ab2b1ee91c10861deb4d891 Mon Sep 17 00:00:00 2001 From: Emanuel Kluge Date: Fri, 16 Apr 2021 15:09:54 +0200 Subject: [PATCH] feat: correctly resolve file package paths in root resolutions --- src/__tests__/workspaces.test.ts | 19 +++++++++++++++++++ src/workspaces.ts | 20 ++++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/__tests__/workspaces.test.ts b/src/__tests__/workspaces.test.ts index 1d55bb4..43c2c14 100644 --- a/src/__tests__/workspaces.test.ts +++ b/src/__tests__/workspaces.test.ts @@ -220,6 +220,25 @@ describe('createRootManifest', () => { }); }); + it('should resolve file packages in resolutions', () => { + const manifest = createRootManifest( + partialWorkspacesConfig({ + repositories: [ + partialWorkspacesRepositoryConfig({ + url: 'https://github.com/xing/hops.git', + directory: 'hops', + manifest: { + ...hopsManifest, + resolutions: { stub: 'file:lib/stub' }, + }, + }), + ], + }) + ); + + expect(manifest.resolutions?.stub).toBe('file:hops/lib/stub'); + }); + it('should merge workspaces of root manifests', () => { const manifest = createRootManifest( partialWorkspacesConfig({ diff --git a/src/workspaces.ts b/src/workspaces.ts index 2a5ec80..a84ef09 100644 --- a/src/workspaces.ts +++ b/src/workspaces.ts @@ -22,6 +22,19 @@ const getWorkspacesPackages = ({ workspaces }: PackageJSON): string[] => { return packages; }; +const resolveFilePackagePath = ( + packageValue: string, + repoDirectory: string +): string => { + if (!packageValue.startsWith('file:')) { + return packageValue; + } + + const packagePath = packageValue.replace('file:', ''); + + return `file:${join(repoDirectory, packagePath)}`; +}; + export interface WorkspacesConfig extends Config { repositories: (Config['repositories'][0] & { manifest: PackageJSON; @@ -104,8 +117,11 @@ export function createRootManifest(config: WorkspacesConfig): PackageJSON { } ); } - return resolutions; - }, {}); + return Object.entries(resolutions).reduce((accumulator, [k, v]) => { + accumulator[k] = resolveFilePackagePath(v, repo.directory); + return accumulator; + }, {} as Record); + }, {} as Record); return mergeWith( {