Skip to content

Commit

Permalink
fix: pnpmHomeDir should read PNPM_HOME defined in environment variabl…
Browse files Browse the repository at this point in the history
…es (pnpm#5566)
  • Loading branch information
lvqq committed Oct 29, 2022
1 parent e9cad19 commit a14ad09
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/wise-pugs-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@pnpm/config": patch
"pnpm": patch
---

It should be possible to set a custom home directory for pnpm by changing the PNPM_HOME environment variable.
2 changes: 1 addition & 1 deletion packages/config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ export async function getConfig (
}
return undefined
})()
pnpmConfig.pnpmHomeDir = getDataDir(process)
pnpmConfig.pnpmHomeDir = process.env.PNPM_HOME ?? getDataDir(process)

if (cliOptions['global']) {
let globalDirRoot
Expand Down
20 changes: 20 additions & 0 deletions packages/config/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -971,3 +971,23 @@ test('do not return a warning if a package.json has workspaces field and there i
})
expect(warnings).toStrictEqual([])
})

test('read PNPM_HOME defined in environment variables', async () => {
const oldEnv = process.env
const homeDir = './specified-dir'
process.env = {
...oldEnv,
PNPM_HOME: homeDir,
}

const { config } = await getConfig({
cliOptions: {},
packageManager: {
name: 'pnpm',
version: '1.0.0',
},
})
expect(config.pnpmHomeDir).toBe(homeDir)

process.env = oldEnv
})

0 comments on commit a14ad09

Please sign in to comment.