fix: installing two packages with same name in different case (#3417)

This commit is contained in:
Zoltan Kochan
2021-05-03 23:30:36 +03:00
committed by GitHub
parent ec097f4edb
commit 20e2f235da
4 changed files with 34 additions and 3 deletions

View File

@@ -0,0 +1,5 @@
---
"dependency-path": major
---
Add a unique prefix to any directory name inside the virtual store that has non-lowercase characters. This is important to avoid conflicts in case insensitive filesystems.

View File

@@ -132,7 +132,7 @@ export function parse (dependencyPath: string) {
export function depPathToFilename (depPath: string, lockfileDir: string) {
const filename = depPathToFilenameUnescaped(depPath, lockfileDir).replace(/\//g, '+')
if (filename.length > 120) {
if (filename.length > 120 || filename !== filename.toLowerCase() && !filename.startsWith('local+')) {
return `${filename.substring(0, 50)}_${crypto.createHash('md5').update(filename).digest('hex')}`
}
return filename

View File

@@ -128,4 +128,5 @@ test('depPathToFilename()', () => {
expect(filename).not.toContain(':')
expect(depPathToFilename('abcd/'.repeat(200), process.cwd())).toBe('abcd+abcd+abcd+abcd+abcd+abcd+abcd+abcd+abcd+abcd+_27524303f1ddd808db67f175ff83606e')
expect(depPathToFilename('/JSONSteam/1.0.0', process.cwd())).toBe('JSONSteam@1.0.0_4b2567ab922fbdf01171f59fab8f6fef')
})

View File

@@ -1261,7 +1261,32 @@ test('installing dependencies with the same name in different case', async () =>
},
rootDir: path.resolve('project-1'),
},
], await testDefaults({ fastUnpack: false, hoistPattern: '*' }))
], await testDefaults({ fastUnpack: false }))
// if it did not fail, it is fine
})
})
test('two dependencies have the same version and name. The only difference is the casing in the name', async () => {
prepareEmpty()
await mutateModules([
{
buildIndex: 0,
mutation: 'install',
manifest: {
dependencies: {
a: 'npm:JSONStream@1.0.3',
b: 'npm:jsonstream@1.0.3',
},
},
rootDir: process.cwd(),
},
], await testDefaults({
fastUnpack: false,
registries: {
default: 'https://registry.npmjs.org/',
},
}))
expect((await fs.readdir(path.resolve('node_modules/.pnpm'))).length).toBe(5)
})