Files
pnpm/config/reader/test/globalBinDir.test.ts
Zoltan Kochan 8bba5c3858 refactor(config): only read auth/registry from .npmrc, add registries to pnpm-workspace.yaml (#11189)
Replace the unmaintained @pnpm/npm-conf package with a purpose-built
module that reads only auth/registry-related settings from .npmrc files
using read-ini-file + @pnpm/config.env-replace (both already deps).

All non-registry settings (hoist-pattern, node-linker, etc.) are now
only read from pnpm-workspace.yaml, CLI options, or environment
variables. Registry-related settings (auth tokens, registry URLs,
SSL certs, proxy settings) continue to be read from .npmrc for
migration compatibility, and can also be set in pnpm-workspace.yaml.

New modules:
- loadNpmrcFiles.ts: reads .npmrc from standard locations, filters to
  auth/registry keys, returns structured layers
- npmConfigTypes.ts: inlined npm config type definitions
- npmDefaults.ts: inlined npm defaults (registry, unsafe-perm, etc.)
2026-04-04 02:44:12 +02:00

92 lines
2.4 KiB
TypeScript

/// <reference path="../../../__typings__/index.d.ts"/>
import fs from 'node:fs'
import { homedir } from 'node:os'
import path from 'node:path'
import { getConfig } from '@pnpm/config.reader'
import { tempDir } from '@pnpm/prepare'
import pathName from 'path-name'
import { symlinkDir } from 'symlink-dir'
const globalBinDir = path.join(homedir(), '.local', 'pnpm')
test('respects global-bin-dir from CLI', async () => {
const { config } = await getConfig({
cliOptions: {
global: true,
'global-bin-dir': globalBinDir,
},
env: {
[pathName]: `${globalBinDir}${path.delimiter}${process.env[pathName]!}`,
},
packageManager: {
name: 'pnpm',
version: '1.0.0',
},
})
expect(config.bin).toBe(globalBinDir)
})
test('respects global-bin-dir rather than dir', async () => {
const { config } = await getConfig({
cliOptions: {
global: true,
'global-bin-dir': globalBinDir,
dir: import.meta.dirname,
},
env: {
[pathName]: `${globalBinDir}${path.delimiter}${process.env[pathName]!}`,
},
packageManager: {
name: 'pnpm',
version: '1.0.0',
},
})
expect(config.bin).toBe(globalBinDir)
})
test('an exception is thrown when the global dir is not in PATH', async () => {
const tmp = tempDir()
const binDir = path.join(tmp, 'not-in-path-bin')
fs.mkdirSync(binDir, { recursive: true })
await expect(
getConfig({
cliOptions: {
global: true,
'global-bin-dir': binDir,
dir: import.meta.dirname,
},
env: {
[pathName]: process.env[pathName],
},
packageManager: {
name: 'pnpm',
version: '1.0.0',
},
})
).rejects.toThrow(/is not in PATH/)
})
test('the global directory may be a symlink to a directory that is in PATH', async () => {
const tmp = tempDir()
const globalBinDirTarget = path.join(tmp, 'global-target')
fs.mkdirSync(globalBinDirTarget)
const globalBinDirSymlink = path.join(tmp, 'global-symlink')
await symlinkDir(globalBinDirTarget, globalBinDirSymlink)
const { config } = await getConfig({
cliOptions: {
global: true,
'global-bin-dir': globalBinDirSymlink,
dir: import.meta.dirname,
},
env: {
[pathName]: `${globalBinDirTarget}${path.delimiter}${process.env[pathName]!}`,
},
packageManager: {
name: 'pnpm',
version: '1.0.0',
},
})
expect(config.bin).toBe(globalBinDirSymlink)
})