Skip to content

Commit 804fb82

Browse files
jespinoarcanis
authored andcommitted
Fix local mirror invalid file name (#4076) (#4159)
* Fix #4076: Allow git repositories to have only one level on the server * Add test for ensure that the cache file name is generated correctly
1 parent 64b17ae commit 804fb82

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

__tests__/fetchers.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,25 @@ test('GitFetcher.fetch', async () => {
7676
expect(name).toBe('beeper');
7777
});
7878

79+
test('GitFetcher.getTarballMirrorPath without slashes in the repo path', async () => {
80+
const dir = await mkdir('git-fetcher');
81+
const config = await Config.create();
82+
config.registries.yarn.config['yarn-offline-mirror'] = 'test';
83+
84+
const fetcher = new GitFetcher(
85+
dir,
86+
{
87+
type: 'git',
88+
reference: 'ssh://[email protected]:example-without-slash-repo.git',
89+
hash: '8beb0413a8028ca2d52dbb86c75f42069535591b',
90+
registry: 'npm',
91+
},
92+
config,
93+
);
94+
const cachePath = fetcher.getTarballMirrorPath();
95+
expect(cachePath).toBe(path.join('test', 'example-without-slash-repo.git-8beb0413a8028ca2d52dbb86c75f42069535591b'));
96+
});
97+
7998
test('GitFetcher.fetch with prepare script', async () => {
8099
const dir = await mkdir('git-fetcher-with-prepare');
81100
const fetcher = new GitFetcher(

src/fetchers/git-fetcher.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ export default class GitFetcher extends BaseFetcher {
4646

4747
const hash = this.hash;
4848

49-
const packageFilename = withCommit && hash ? `${path.basename(pathname)}-${hash}` : `${path.basename(pathname)}`;
49+
let packageFilename = withCommit && hash ? `${path.basename(pathname)}-${hash}` : `${path.basename(pathname)}`;
50+
51+
if (packageFilename.startsWith(':')) {
52+
packageFilename = packageFilename.substr(1);
53+
}
5054

5155
return this.config.getOfflineMirrorPath(packageFilename);
5256
}

0 commit comments

Comments
 (0)