diff --git a/__tests__/fixtures/global/add-with-prefix-env/.yarnrc b/__tests__/fixtures/global/add-with-prefix-env/.yarnrc index 3100b0f46e..b91fc0dfcd 100644 --- a/__tests__/fixtures/global/add-with-prefix-env/.yarnrc +++ b/__tests__/fixtures/global/add-with-prefix-env/.yarnrc @@ -1 +1 @@ -prefix "" +prefix false diff --git a/__tests__/util/path.js b/__tests__/util/path.js index 0abfeac0c8..7ad366426e 100644 --- a/__tests__/util/path.js +++ b/__tests__/util/path.js @@ -12,45 +12,7 @@ jest.mock('path', () => { return path; }); -import {expandPath, resolveWithHome} from '../../src/util/path.js'; - -describe('expandPath', () => { - const realPlatform = process.platform; - - describe('!win32', () => { - beforeAll(() => { - process.platform = 'notWin32'; - }); - - afterAll(() => { - process.platform = realPlatform; - }); - - test('Paths get expanded', () => { - expect(expandPath('~/bar/baz/q')).toEqual('/home/foo/bar/baz/q'); - expect(expandPath(' ~/bar/baz')).toEqual('/home/foo/bar/baz'); - expect(expandPath('./~/bar/baz')).toEqual('./~/bar/baz'); - expect(expandPath('~/~/bar/baz')).toEqual('/home/foo/~/bar/baz'); - }); - }); - - describe('win32', () => { - beforeAll(() => { - process.platform = 'win32'; - }); - - afterAll(() => { - process.platform = realPlatform; - }); - - test('Paths never get expanded', () => { - expect(expandPath('~/bar/baz/q')).toEqual('~/bar/baz/q'); - expect(expandPath(' ~/bar/baz')).toEqual(' ~/bar/baz'); - expect(expandPath('./~/bar/baz')).toEqual('./~/bar/baz'); - expect(expandPath('~/~/bar/baz')).toEqual('~/~/bar/baz'); - }); - }); -}); +import {resolveWithHome} from '../../src/util/path.js'; describe('resolveWithHome', () => { const realPlatform = process.platform; diff --git a/src/config.js b/src/config.js index bc4b7c5d77..3a70831689 100644 --- a/src/config.js +++ b/src/config.js @@ -5,7 +5,7 @@ import type {Reporter} from './reporters/index.js'; import type {Manifest, PackageRemote, WorkspacesManifestMap} from './types.js'; import type PackageReference from './package-reference.js'; import {execFromManifest} from './util/execute-lifecycle-script.js'; -import {expandPath} from './util/path.js'; +import {resolveWithHome} from './util/path.js'; import normalizeManifest from './util/normalize-manifest/index.js'; import {MessageError} from './errors.js'; import * as fs from './util/fs.js'; @@ -192,10 +192,11 @@ export default class Config { * Get a config option from our yarn config. */ - getOption(key: string, expand: boolean = false): mixed { + getOption(key: string, resolve: boolean = false): mixed { const value = this.registries.yarn.getOption(key); - if (expand && typeof value === 'string') { - return expandPath(value); + + if (resolve && typeof value === 'string') { + return resolveWithHome(value); } return value; diff --git a/src/registries/npm-registry.js b/src/registries/npm-registry.js index 90879d9522..124c777290 100644 --- a/src/registries/npm-registry.js +++ b/src/registries/npm-registry.js @@ -53,10 +53,10 @@ function getGlobalPrefix(): string { } } -const PATH_CONFIG_OPTIONS = ['cache', 'cafile', 'prefix', 'userconfig']; +const PATH_CONFIG_OPTIONS = new Set(['cache', 'cafile', 'prefix', 'userconfig']); function isPathConfigOption(key: string): boolean { - return PATH_CONFIG_OPTIONS.indexOf(key) >= 0; + return PATH_CONFIG_OPTIONS.has(key); } function normalizePath(val: mixed): ?string { @@ -65,7 +65,7 @@ function normalizePath(val: mixed): ?string { } if (typeof val !== 'string') { - val = '' + (val: any); + val = String(val); } return resolveWithHome(val); diff --git a/src/util/path.js b/src/util/path.js index 66e53cfb96..277835e334 100644 --- a/src/util/path.js +++ b/src/util/path.js @@ -8,17 +8,9 @@ export function getPosixPath(path: string): string { return path.replace(/\\/g, '/'); } -export function expandPath(path: string): string { - if (process.platform !== 'win32') { - path = path.replace(/^\s*~(?=$|\/|\\)/, userHome); - } - - return path; -} - export function resolveWithHome(path: string): string { const homePattern = process.platform === 'win32' ? /^~(\/|\\)/ : /^~\//; - if (path.match(homePattern)) { + if (homePattern.test(path)) { return resolve(userHome, path.substr(2)); }