fix: normalize the value of public-hoist-pattern

close #2783
PR #2786
This commit is contained in:
Zoltan Kochan
2020-08-21 17:33:33 +03:00
committed by GitHub
parent 855f8b00a6
commit 972864e0d8
5 changed files with 56 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/config": patch
---
When public-hoist-pattern is set to an empty string or a list with a single empty string, then it is considered to be undefined.

View File

@@ -0,0 +1,5 @@
---
"@pnpm/get-context": patch
---
publicHoistPattern=undefined should be considered to be the same as publicHoistPattern='' (empty string).

View File

@@ -326,6 +326,18 @@ export default async (
case true:
pnpmConfig.publicHoistPattern = ['*']
break
default:
if (
!pnpmConfig.publicHoistPattern ||
(
Array.isArray(pnpmConfig.publicHoistPattern) &&
pnpmConfig.publicHoistPattern.length === 1 &&
pnpmConfig.publicHoistPattern[0] === ''
)
) {
delete pnpmConfig.publicHoistPattern
}
break
}
if (typeof pnpmConfig['color'] === 'boolean') {
switch (pnpmConfig['color']) {

View File

@@ -422,6 +422,36 @@ test('throw error if --no-hoist is used with --hoist-pattern', async (t) => {
}
})
test('normalizing the value of public-hoist-pattern', async (t) => {
{
const { config } = await getConfig({
cliOptions: {
'public-hoist-pattern': '',
},
packageManager: {
name: 'pnpm',
version: '1.0.0',
},
})
t.equal(config.publicHoistPattern, undefined)
}
{
const { config } = await getConfig({
cliOptions: {
'public-hoist-pattern': [''],
},
packageManager: {
name: 'pnpm',
version: '1.0.0',
},
})
t.equal(config.publicHoistPattern, undefined)
}
t.end()
})
test('rawLocalConfig in a workspace', async (t) => {
const tmp = tempy.directory()
t.comment(`temp dir created: ${tmp}`)

View File

@@ -199,7 +199,10 @@ async function validateModules (
}
): Promise<{ purged: boolean }> {
const rootProject = projects.find(({ id }) => id === '.')
if (opts.forcePublicHoistPattern && !R.equals(modules.publicHoistPattern, opts.publicHoistPattern)) {
if (
opts.forcePublicHoistPattern &&
!R.equals(modules.publicHoistPattern, opts.publicHoistPattern || undefined)
) {
if (opts.forceNewModules && rootProject) {
await purgeModulesDirsOfImporter(rootProject)
return { purged: true }