-
-
Notifications
You must be signed in to change notification settings - Fork 936
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: traverse through workspace packages in
why
and list
commands (
#5863) * refactor(dependencies-hierarchy): remove keypath argument from getTree The `keypath` argument is an internal implementation detail of `getTree` used to detect cycles in the package graph. Removing this from the call signature of `getTree` since it exposes an implementation detail. The start of a `getTree` call always passed in the starting node as the initial value anyway. ```ts const getChildrenTree = getTree.bind(null, { ... }) getChildrenTree([relativeId], relativeId) ``` It's simpler for that to happen in the first call to `getTreeHelper` internally and better ensures the keypath is created correctly. A future refactor makes construction of the keypath more involved. * refactor(dependencies-hierarchy): remove refToRelative call in getPkgInfo This removes an extra `refToRelative` call in `getPkgInfo`. The result of this call wasn't used within the function and was simply passed back to the caller. Callers of `getPkgInfo` were checking the result of `refToRelative`, from `getPkgInfo`'s return object only to call `refToRelative` again. Calling `refToRelative` directly simplifies code a bit. We can remove an unnecessary cast and an if statement. * refactor(dependencies-hierarchy): create enum for getTree nodes * feature(dependencies-hierarchy): traverse through workspace packages This updates `pnpm list` and `pnpm why` to traverse through `link:` packages by simply. This is done by simply implementing a new TreeNodeId enum variant. * test(dependencies-hierarchy): test transitive workspace package listing * refactor(dependencies-hierarchy): create interface for GetPkgInfoOpts A future commit adds new fields to `getPkgInfo`'s options. The dedicated interface makes it easier to describe these new options with a JSDoc. * fix(dependencies-hierarchy): fix path for link: deps in projects This was a bug before the changes in this pull request. The bug was not user facing since `pnpm list --json` doesn't print this computed path. * fix(dependencies-hierarchy): print version paths rel to starting project * feat(list): add --only-projects flag * refactor: change description of --only-projects Co-authored-by: Zoltan Kochan <z@kochan.io>
- Loading branch information
Showing
19 changed files
with
424 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@pnpm/reviewing.dependencies-hierarchy": minor | ||
--- | ||
|
||
The `path` field for direct dependencies returned from `buildDependenciesHierarchy` was incorrect if the dependency used the `workspace:` or `link:` protocols. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@pnpm/reviewing.dependencies-hierarchy": minor | ||
pnpm: minor | ||
--- | ||
|
||
The `pnpm list` and `pnpm why` commands will now look through transitive dependencies of `workspace:` packages. A new `--only-projects` flag is available to only print `workspace:` packages. |
7 changes: 7 additions & 0 deletions
7
__fixtures__/workspace-with-nested-workspace-deps/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "root", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"@scope/a": "workspace:*" | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
__fixtures__/workspace-with-nested-workspace-deps/packages/a/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "@scope/a", | ||
"version": "1.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"@scope/b": "workspace:*" | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
__fixtures__/workspace-with-nested-workspace-deps/packages/b/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "@scope/b", | ||
"version": "1.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"@scope/c": "workspace:*", | ||
"is-positive": "1.0.0" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
__fixtures__/workspace-with-nested-workspace-deps/packages/c/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "@scope/c", | ||
"version": "1.0.0", | ||
"private": true, | ||
"dependencies": {} | ||
} |
33 changes: 33 additions & 0 deletions
33
__fixtures__/workspace-with-nested-workspace-deps/pnpm-lock.yaml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 2 additions & 0 deletions
2
__fixtures__/workspace-with-nested-workspace-deps/pnpm-workspace.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
packages: | ||
- 'packages/**' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
export type TreeNodeId = TreeNodeIdImporter | TreeNodeIdPackage | ||
|
||
/** | ||
* A project local to the pnpm workspace. | ||
*/ | ||
interface TreeNodeIdImporter { | ||
readonly type: 'importer' | ||
readonly importerId: string | ||
} | ||
|
||
/** | ||
* An npm package depended on externally. | ||
*/ | ||
interface TreeNodeIdPackage { | ||
readonly type: 'package' | ||
readonly depPath: string | ||
} | ||
|
||
export function serializeTreeNodeId (treeNodeId: TreeNodeId): string { | ||
switch (treeNodeId.type) { | ||
case 'importer': { | ||
// Only serialize known fields from TreeNodeId. TypeScript is duck typed and | ||
// objects can have any number of unknown extra fields. | ||
const { type, importerId } = treeNodeId | ||
return JSON.stringify({ type, importerId }) | ||
} | ||
case 'package': { | ||
const { type, depPath } = treeNodeId | ||
return JSON.stringify({ type, depPath }) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.