mirror of
https://github.com/pnpm/pnpm.git
synced 2026-03-30 04:52:04 -04:00
fix: installing two packages with same name in different case (#3417)
This commit is contained in:
5
.changeset/brave-ants-double.md
Normal file
5
.changeset/brave-ants-double.md
Normal 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.
|
||||
@@ -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
|
||||
|
||||
@@ -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')
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user