Skip to content

Commit

Permalink
feat: correctly resolve file package paths in root resolutions
Browse files Browse the repository at this point in the history
  • Loading branch information
Emanuel Kluge authored and herschel666 committed Apr 19, 2021
1 parent df8d647 commit 4e6c40f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
19 changes: 19 additions & 0 deletions src/__tests__/workspaces.test.ts
Expand Up @@ -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({
Expand Down
20 changes: 18 additions & 2 deletions src/workspaces.ts
Expand Up @@ -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;
Expand Down Expand Up @@ -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<string, string>);
}, {} as Record<string, string>);

return mergeWith(
{
Expand Down

0 comments on commit 4e6c40f

Please sign in to comment.