Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config): new global packages location in beta mode #3781

Merged
merged 1 commit into from Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tasty-birds-know.md
@@ -0,0 +1,5 @@
---
"@pnpm/config": minor
---

Use a subfolder of the pnpm homedir as the location of globally installed packages, when use-beta-cli is on.
29 changes: 17 additions & 12 deletions packages/config/src/index.ts
Expand Up @@ -258,22 +258,28 @@ export default async (
pnpmConfig.sharedWorkspaceLockfile = typeof pnpmConfig['sharedWorkspaceLockfile'] === 'undefined'
? pnpmConfig.sharedWorkspaceShrinkwrap
: pnpmConfig['sharedWorkspaceLockfile']
pnpmConfig.pnpmHomeDir = getDataDir(process)

if (cliOptions['global']) {
const knownGlobalBinDirCandidates: string[] = []
let npmGlobalPrefix: string = findBestGlobalPrefix(npmConfig.globalPrefix, process.env)
const globalDirName = `${path.sep}${PNPM_GLOBAL}${path.sep}`
if (npmGlobalPrefix.includes(globalDirName)) {
npmGlobalPrefix = npmGlobalPrefix.substring(0, npmGlobalPrefix.indexOf(globalDirName))
let globalDirRoot
if (pnpmConfig['globalDir']) {
globalDirRoot = pnpmConfig['globalDir']
} else if (pnpmConfig.useBetaCli) {
globalDirRoot = path.join(pnpmConfig.pnpmHomeDir, 'global-packages')
} else {
const npmGlobalBinDir = process.platform === 'win32'
? npmGlobalPrefix
: path.resolve(npmGlobalPrefix, 'bin')
knownGlobalBinDirCandidates.push(npmGlobalBinDir)
let npmGlobalPrefix: string = findBestGlobalPrefix(npmConfig.globalPrefix, process.env)
const globalDirName = `${path.sep}${PNPM_GLOBAL}${path.sep}`
if (npmGlobalPrefix.includes(globalDirName)) {
npmGlobalPrefix = npmGlobalPrefix.substring(0, npmGlobalPrefix.indexOf(globalDirName))
} else {
const npmGlobalBinDir = process.platform === 'win32'
? npmGlobalPrefix
: path.resolve(npmGlobalPrefix, 'bin')
knownGlobalBinDirCandidates.push(npmGlobalBinDir)
}
globalDirRoot = path.join(firstWithWriteAccess([npmGlobalPrefix, os.homedir()]), PNPM_GLOBAL)
}
const globalDirRoot = pnpmConfig['globalDir']
? pnpmConfig['globalDir']
: path.join(firstWithWriteAccess([npmGlobalPrefix, os.homedir()]), PNPM_GLOBAL)
pnpmConfig.dir = path.join(globalDirRoot, LAYOUT_VERSION.toString())

const npmConfigGlobalBinDir = npmConfig.get('global-bin-dir')
Expand Down Expand Up @@ -437,7 +443,6 @@ export default async (
pnpmConfig.noProxy = pnpmConfig['noproxy'] ?? getProcessEnv('no_proxy')
}
pnpmConfig.enablePnp = pnpmConfig['nodeLinker'] === 'pnp'
pnpmConfig.pnpmHomeDir = getDataDir(process)

if (opts.checkUnknownSetting) {
const settingKeys = Object.keys({
Expand Down