fix(store-path): throw an error when there's no pnpm home directory

This commit is contained in:
Zoltan Kochan
2024-01-10 12:27:28 +01:00
parent 402fe55af5
commit 37ccff6373
6 changed files with 26 additions and 1 deletions

View 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
View File

@@ -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

View File

@@ -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",

View File

@@ -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)
}

View File

@@ -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.')
})

View File

@@ -8,6 +8,10 @@
"src/**/*.ts",
"../../__typings__/**/*.d.ts"
],
"references": [],
"references": [
{
"path": "../../packages/error"
}
],
"composite": true
}