Skip to content

Commit

Permalink
fix: should not output warning info with non-top-level directory stru…
Browse files Browse the repository at this point in the history
…cture
  • Loading branch information
Timeless0911 committed Dec 7, 2023
1 parent 1474bfd commit 553f210
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/lovely-wombats-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pnpm/workspace.find-packages": patch
---

fix: should not output warning info when "pnpm" or "resolutions" is configured in a non-root workspace project with non-top-level directory structure
5 changes: 2 additions & 3 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"idempotency",
"imurmurhash",
"ionicons",
"isequal",
"isexe",
"istvan",
"italiano",
Expand Down Expand Up @@ -166,7 +167,6 @@
"postshrinkwrap",
"poststart",
"poststop",
"poststop",
"posttest",
"postuninstall",
"postversion",
Expand All @@ -179,7 +179,6 @@
"prerestart",
"preshrinkwrap",
"prestart",
"prestart",
"prestop",
"preuninstall",
"preversion",
Expand Down Expand Up @@ -254,6 +253,6 @@
"xmarw",
"zkochan",
"zoli",
"zoltan"
"zoltan"
]
}
22 changes: 19 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions workspace/find-packages/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@
"@pnpm/fs.find-packages": "workspace:*",
"@pnpm/types": "workspace:*",
"@pnpm/util.lex-comparator": "1.0.0",
"@pnpm/workspace.read-manifest": "workspace:*"
"@pnpm/workspace.read-manifest": "workspace:*",
"lodash.isequal": "4.5.0"
},
"funding": "https://opencollective.com/pnpm",
"devDependencies": {
"@pnpm/workspace.find-packages": "workspace:*"
"@pnpm/workspace.find-packages": "workspace:*",
"@types/lodash.isequal": "4.5.8"
},
"peerDependencies": {
"@pnpm/logger": "^5.0.0"
Expand Down
11 changes: 7 additions & 4 deletions workspace/find-packages/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { packageIsInstallable } from '@pnpm/cli-utils'
import { packageIsInstallable, readProjectManifest } from '@pnpm/cli-utils'
import { type ProjectManifest, type Project, type SupportedArchitectures } from '@pnpm/types'
import { readWorkspaceManifest } from '@pnpm/workspace.read-manifest'
import { lexCompare } from '@pnpm/util.lex-comparator'
import { findPackages } from '@pnpm/fs.find-packages'
import { logger } from '@pnpm/logger'
import isEqual from 'lodash.isequal'

export type { Project }

Expand All @@ -18,6 +19,7 @@ export async function findWorkspacePackages (
}
): Promise<Project[]> {
const pkgs = await findWorkspacePackagesNoCheck(workspaceRoot, opts)
const { manifest: rootProjectManifest } = await readProjectManifest(workspaceRoot)
for (const pkg of pkgs) {
packageIsInstallable(pkg.dir, pkg.manifest, opts ?? {
supportedArchitectures: {
Expand All @@ -28,7 +30,7 @@ export async function findWorkspacePackages (
})
// When setting shared-workspace-lockfile=false, `pnpm` can be set in sub-project's package.json.
if (opts?.sharedWorkspaceLockfile && pkg.dir !== workspaceRoot) {
checkNonRootProjectManifest(pkg)
checkNonRootProjectManifest(pkg, rootProjectManifest)
}
}

Expand Down Expand Up @@ -68,9 +70,10 @@ export function arrayOfWorkspacePackagesToMap (
}, {} as ArrayOfWorkspacePackagesToMapResult)
}

function checkNonRootProjectManifest ({ manifest, dir }: Project) {
function checkNonRootProjectManifest ({ manifest, dir }: Project, rootProjectManifest: ProjectManifest) {
for (const rootOnlyField of ['pnpm', 'resolutions']) {
if (manifest?.[rootOnlyField as keyof ProjectManifest]) {
const workspaceProjectField = manifest?.[rootOnlyField as keyof ProjectManifest]
if (workspaceProjectField && !isEqual(workspaceProjectField, rootProjectManifest?.[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,
Expand Down

0 comments on commit 553f210

Please sign in to comment.