mirror of
https://github.com/pnpm/pnpm.git
synced 2026-03-09 10:47:48 -04:00
fix(store-path): throw an error when there's no pnpm home directory
This commit is contained in:
5
.changeset/nice-dolphins-jump.md
Normal file
5
.changeset/nice-dolphins-jump.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/store-path": patch
|
||||
---
|
||||
|
||||
Throw an error when calculating the store directory without the pnpm home directory.
|
||||
3
pnpm-lock.yaml
generated
3
pnpm-lock.yaml
generated
@@ -6123,6 +6123,9 @@ importers:
|
||||
|
||||
store/store-path:
|
||||
dependencies:
|
||||
'@pnpm/error':
|
||||
specifier: workspace:*
|
||||
version: link:../../packages/error
|
||||
'@zkochan/rimraf':
|
||||
specifier: ^2.1.3
|
||||
version: 2.1.3
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/pnpm/pnpm/blob/main/store/store-path#readme",
|
||||
"dependencies": {
|
||||
"@pnpm/error": "workspace:*",
|
||||
"@zkochan/rimraf": "^2.1.3",
|
||||
"can-link": "^2.0.0",
|
||||
"path-absolute": "^1.0.1",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { promises as fs } from 'fs'
|
||||
import { PnpmError } from '@pnpm/error'
|
||||
import rimraf from '@zkochan/rimraf'
|
||||
import canLink from 'can-link'
|
||||
import os from 'os'
|
||||
@@ -22,6 +23,9 @@ export function getStorePath (
|
||||
}
|
||||
) {
|
||||
if (!storePath) {
|
||||
if (!pnpmHomeDir) {
|
||||
throw new PnpmError('NO_PNPM_HOME_DIR', 'The pnpm home directory is unknown. Cannot calculate the store directory location.')
|
||||
}
|
||||
return storePathRelativeToHome(pkgRoot, 'store', pnpmHomeDir)
|
||||
}
|
||||
|
||||
|
||||
@@ -26,3 +26,11 @@ skipOnWindows('a link can be created to the a subdir in the root of the drive',
|
||||
pnpmHomeDir: '/local/share/pnpm',
|
||||
})).toBe('/mnt/.pnpm-store/v3')
|
||||
})
|
||||
|
||||
test('fail when pnpm home directory is not defined', async () => {
|
||||
expect(() => getStorePath({
|
||||
pkgRoot: 'pkgRoot',
|
||||
// @ts-expect-error
|
||||
pnpmHomeDir: undefined,
|
||||
})).toThrow('The pnpm home directory is unknown. Cannot calculate the store directory location.')
|
||||
})
|
||||
|
||||
@@ -8,6 +8,10 @@
|
||||
"src/**/*.ts",
|
||||
"../../__typings__/**/*.d.ts"
|
||||
],
|
||||
"references": [],
|
||||
"references": [
|
||||
{
|
||||
"path": "../../packages/error"
|
||||
}
|
||||
],
|
||||
"composite": true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user