mirror of
https://github.com/pnpm/pnpm.git
synced 2026-03-30 04:52:04 -04:00
fix: should output warning info when "pnpm" or "resolutions" is configured in a non-root workspace project (#6658)
close #6636 --------- Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
5
.changeset/chatty-hounds-hammer.md
Normal file
5
.changeset/chatty-hounds-hammer.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/find-workspace-packages": major
|
||||
---
|
||||
|
||||
`@pnpm/logger` is added as a peer dependency.
|
||||
5
.changeset/nine-eagles-peel.md
Normal file
5
.changeset/nine-eagles-peel.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/find-workspace-packages": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
Output a warning message when "pnpm" or "resolutions" are configured in a non-root workspace project [#6636](https://github.com/pnpm/pnpm/issues/6636)
|
||||
3
pnpm-lock.yaml
generated
3
pnpm-lock.yaml
generated
@@ -5975,6 +5975,9 @@ importers:
|
||||
'@pnpm/fs.find-packages':
|
||||
specifier: workspace:*
|
||||
version: link:../../fs/find-packages
|
||||
'@pnpm/logger':
|
||||
specifier: ^5.0.0
|
||||
version: 5.0.0
|
||||
'@pnpm/types':
|
||||
specifier: workspace:*
|
||||
version: link:../../packages/types
|
||||
|
||||
@@ -40,6 +40,9 @@
|
||||
"devDependencies": {
|
||||
"@pnpm/find-workspace-packages": "workspace:*"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@pnpm/logger": "^5.0.0"
|
||||
},
|
||||
"exports": {
|
||||
".": "./lib/index.js"
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import path from 'path'
|
||||
import { packageIsInstallable } from '@pnpm/cli-utils'
|
||||
import { WORKSPACE_MANIFEST_FILENAME } from '@pnpm/constants'
|
||||
import { type Project } from '@pnpm/types'
|
||||
import { type ProjectManifest, type Project } from '@pnpm/types'
|
||||
import { lexCompare } from '@pnpm/util.lex-comparator'
|
||||
import { findPackages } from '@pnpm/fs.find-packages'
|
||||
import { logger } from '@pnpm/logger'
|
||||
import readYamlFile from 'read-yaml-file'
|
||||
|
||||
export type { Project }
|
||||
@@ -19,6 +20,9 @@ export async function findWorkspacePackages (
|
||||
const pkgs = await findWorkspacePackagesNoCheck(workspaceRoot, opts)
|
||||
for (const pkg of pkgs) {
|
||||
packageIsInstallable(pkg.dir, pkg.manifest, opts ?? {})
|
||||
if (pkg.dir !== workspaceRoot) {
|
||||
checkNonRootProjectManifest(pkg)
|
||||
}
|
||||
}
|
||||
|
||||
return pkgs
|
||||
@@ -67,3 +71,14 @@ export function arrayOfWorkspacePackagesToMap (
|
||||
return acc
|
||||
}, {} as ArrayOfWorkspacePackagesToMapResult)
|
||||
}
|
||||
|
||||
function checkNonRootProjectManifest ({ manifest, dir }: Project) {
|
||||
for (const rootOnlyField of ['pnpm', 'resolutions']) {
|
||||
if (manifest?.[rootOnlyField as keyof ProjectManifest]) {
|
||||
logger.warn({
|
||||
message: `The field "${rootOnlyField}" was found in ${dir}/package.json. This will not take effect. You should configure "${rootOnlyField}" at the root of the workspace instead.`,
|
||||
prefix: dir,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "root",
|
||||
"version": "1.0.0",
|
||||
"pnpm": {
|
||||
"overrides": {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"name": "bar",
|
||||
"version": "1.0.0",
|
||||
"pnpm": {},
|
||||
"resolutions": {}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "foo",
|
||||
"version": "1.0.0",
|
||||
"pnpm": {}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
packages:
|
||||
- packages/*
|
||||
@@ -1,5 +1,14 @@
|
||||
import path from 'path'
|
||||
import { findWorkspacePackagesNoCheck, arrayOfWorkspacePackagesToMap } from '@pnpm/find-workspace-packages'
|
||||
import { findWorkspacePackagesNoCheck, arrayOfWorkspacePackagesToMap, findWorkspacePackages } from '@pnpm/find-workspace-packages'
|
||||
import { logger } from '@pnpm/logger'
|
||||
|
||||
beforeEach(() => {
|
||||
jest.spyOn(logger, 'warn')
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
(logger.warn as jest.Mock).mockRestore()
|
||||
})
|
||||
|
||||
// This is supported for compatibility with Yarn's implementation
|
||||
// see https://github.com/pnpm/pnpm/issues/2648
|
||||
@@ -21,3 +30,16 @@ test('findWorkspacePackagesNoCheck() skips engine checks', async () => {
|
||||
expect(pkgs.length).toBe(1)
|
||||
expect(pkgs[0].manifest.name).toBe('pkg')
|
||||
})
|
||||
|
||||
test('findWorkspacePackages() output warnings for non-root workspace project', async () => {
|
||||
const fixturePath = path.join(__dirname, '__fixtures__/warning-for-non-root-project')
|
||||
|
||||
const pkgs = await findWorkspacePackages(fixturePath)
|
||||
expect(pkgs.length).toBe(3)
|
||||
expect(logger.warn).toBeCalledTimes(3)
|
||||
const fooPath = path.join(fixturePath, 'packages/foo')
|
||||
const barPath = path.join(fixturePath, 'packages/bar')
|
||||
expect(logger.warn).toHaveBeenNthCalledWith(1, { prefix: barPath, message: `The field "pnpm" was found in ${barPath}/package.json. This will not take effect. You should configure "pnpm" at the root of the workspace instead.` })
|
||||
expect(logger.warn).toHaveBeenNthCalledWith(2, { prefix: barPath, message: `The field "resolutions" was found in ${barPath}/package.json. This will not take effect. You should configure "resolutions" at the root of the workspace instead.` })
|
||||
expect(logger.warn).toHaveBeenNthCalledWith(3, { prefix: fooPath, message: `The field "pnpm" was found in ${fooPath}/package.json. This will not take effect. You should configure "pnpm" at the root of the workspace instead.` })
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user