mirror of
https://github.com/pnpm/pnpm.git
synced 2026-03-29 04:21:39 -04:00
6
.changeset/smart-planes-tease.md
Normal file
6
.changeset/smart-planes-tease.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/workspace.find-packages": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
Remove warnings for non-root `pnpm` field, add warnings for non-root `pnpm` subfields that aren't `executionEnv` [#8143](https://github.com/pnpm/pnpm/issues/8413).
|
||||
@@ -61,13 +61,28 @@ export async function findWorkspacePackagesNoCheck (workspaceRoot: string, opts?
|
||||
return pkgs
|
||||
}
|
||||
|
||||
const uselessNonRootManifestFields: Array<keyof ProjectManifest> = ['resolutions']
|
||||
|
||||
type ProjectManifestPnpm = Required<ProjectManifest>['pnpm']
|
||||
const usefulNonRootPnpmFields: Array<keyof ProjectManifestPnpm> = ['executionEnv']
|
||||
|
||||
function checkNonRootProjectManifest ({ manifest, rootDir }: Project): void {
|
||||
for (const rootOnlyField of ['pnpm', 'resolutions']) {
|
||||
if (manifest?.[rootOnlyField as keyof ProjectManifest]) {
|
||||
logger.warn({
|
||||
message: `The field "${rootOnlyField}" was found in ${rootDir}/package.json. This will not take effect. You should configure "${rootOnlyField}" at the root of the workspace instead.`,
|
||||
prefix: rootDir,
|
||||
})
|
||||
const warn = printNonRootFieldWarning.bind(null, rootDir)
|
||||
for (const field of uselessNonRootManifestFields) {
|
||||
if (field in manifest) {
|
||||
warn(field)
|
||||
}
|
||||
}
|
||||
for (const field in manifest.pnpm) {
|
||||
if (!usefulNonRootPnpmFields.includes(field as keyof ProjectManifestPnpm)) {
|
||||
warn(`pnpm.${field}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function printNonRootFieldWarning (prefix: string, propertyPath: string): void {
|
||||
logger.warn({
|
||||
message: `The field "${propertyPath}" was found in ${prefix}/package.json. This will not take effect. You should configure "${propertyPath}" at the root of the workspace instead.`,
|
||||
prefix,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
{
|
||||
"name": "bar",
|
||||
"version": "1.0.0",
|
||||
"pnpm": {},
|
||||
"pnpm": {
|
||||
"overrides": {},
|
||||
"executionEnv": {}
|
||||
},
|
||||
"resolutions": {}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
{
|
||||
"name": "foo",
|
||||
"version": "1.0.0",
|
||||
"pnpm": {}
|
||||
"pnpm": {
|
||||
"overrides": {},
|
||||
"executionEnv": {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,10 +42,14 @@ test('findWorkspacePackages() output warnings for non-root workspace project', a
|
||||
sharedWorkspaceLockfile: true,
|
||||
})
|
||||
expect(pkgs.length).toBe(3)
|
||||
expect(logger.warn).toHaveBeenCalledTimes(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.` })
|
||||
expect(
|
||||
(logger.warn as jest.Mock).mock.calls
|
||||
.sort((a, b) => JSON.stringify(a).localeCompare(JSON.stringify(b)))
|
||||
).toStrictEqual([
|
||||
[{ prefix: barPath, message: `The field "pnpm.overrides" was found in ${barPath}/package.json. This will not take effect. You should configure "pnpm.overrides" at the root of the workspace instead.` }],
|
||||
[{ prefix: fooPath, message: `The field "pnpm.overrides" was found in ${fooPath}/package.json. This will not take effect. You should configure "pnpm.overrides" at the root of the workspace instead.` }],
|
||||
[{ 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.` }],
|
||||
])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user