-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat(core): add support for pnpm catalogs #32978
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+4,716
−581
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c15a7fe
feat(core): add support for pnpm catalogs
leosvelperez 3b605ee
fix(devkit): fix issue in semver util and add tests
leosvelperez 955dd98
fix(js): handle catalog references in version action
leosvelperez 38d8088
chore(angular): update angular cli migration template
leosvelperez d187f2a
fix(linter): handle pnpm catalogs in dependency-checks eslint rule
leosvelperez a9e7790
cleanup(misc): clean up leftover changes in e2e tests
leosvelperez 3edfe1e
feat(core): support `catalogs.default` definition and `catalog:defaul…
leosvelperez 41fddb4
fix(core): cleanup and simplify solution
leosvelperez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
137 changes: 137 additions & 0 deletions
137
docs/generated/devkit/getDependencyVersionFromPackageJson.md
This file contains hidden or 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,137 @@ | ||
# Function: getDependencyVersionFromPackageJson | ||
|
||
▸ **getDependencyVersionFromPackageJson**(`tree`, `packageName`, `packageJsonPath?`, `dependencyLookup?`): `string` \| `null` | ||
|
||
Get the resolved version of a dependency from package.json. | ||
|
||
Retrieves a package version and automatically resolves PNPM catalog references | ||
(e.g., "catalog:default") to their actual version strings. By default, searches | ||
`dependencies` first, then falls back to `devDependencies`. | ||
|
||
**Tree-based usage** (generators and migrations): | ||
Use when you have a `Tree` object, which is typical in Nx generators and migrations. | ||
|
||
**Filesystem-based usage** (CLI commands and scripts): | ||
Use when reading directly from the filesystem without a `Tree` object. | ||
|
||
#### Parameters | ||
|
||
| Name | Type | Description | | ||
| :------------------ | :-------------------------------------------------- | :---------------------------------------------------------------------------------------------- | | ||
| `tree` | [`Tree`](/reference/core-api/devkit/documents/Tree) | - | | ||
| `packageName` | `string` | - | | ||
| `packageJsonPath?` | `string` | - | | ||
| `dependencyLookup?` | `PackageJsonDependencySection`[] | Array of dependency sections to check in order. Defaults to ['dependencies', 'devDependencies'] | | ||
|
||
#### Returns | ||
|
||
`string` \| `null` | ||
|
||
The resolved version string, or `null` if the package is not found in any of the specified sections | ||
|
||
**`Example`** | ||
|
||
```typescript | ||
// Tree-based - from root package.json (checks dependencies then devDependencies) | ||
const reactVersion = getDependencyVersionFromPackageJson(tree, 'react'); | ||
// Returns: "^18.0.0" (resolves "catalog:default" if present) | ||
|
||
// Tree-based - check only dependencies section | ||
const version = getDependencyVersionFromPackageJson( | ||
tree, | ||
'react', | ||
'package.json', | ||
['dependencies'] | ||
); | ||
|
||
// Tree-based - check only devDependencies section | ||
const version = getDependencyVersionFromPackageJson( | ||
tree, | ||
'jest', | ||
'package.json', | ||
['devDependencies'] | ||
); | ||
|
||
// Tree-based - custom lookup order | ||
const version = getDependencyVersionFromPackageJson( | ||
tree, | ||
'pkg', | ||
'package.json', | ||
['devDependencies', 'dependencies', 'peerDependencies'] | ||
); | ||
|
||
// Tree-based - with pre-loaded package.json | ||
const packageJson = readJson(tree, 'package.json'); | ||
const version = getDependencyVersionFromPackageJson( | ||
tree, | ||
'react', | ||
packageJson, | ||
['dependencies'] | ||
); | ||
``` | ||
|
||
**`Example`** | ||
|
||
```typescript | ||
// Filesystem-based - from current directory | ||
const reactVersion = getDependencyVersionFromPackageJson('react'); | ||
|
||
// Filesystem-based - with workspace root | ||
const version = getDependencyVersionFromPackageJson( | ||
'react', | ||
'/path/to/workspace' | ||
); | ||
|
||
// Filesystem-based - with specific package.json and section | ||
const version = getDependencyVersionFromPackageJson( | ||
'react', | ||
'/path/to/workspace', | ||
'apps/my-app/package.json', | ||
['dependencies'] | ||
); | ||
``` | ||
|
||
▸ **getDependencyVersionFromPackageJson**(`tree`, `packageName`, `packageJson?`, `dependencyLookup?`): `string` \| `null` | ||
|
||
#### Parameters | ||
|
||
| Name | Type | | ||
| :------------------ | :-------------------------------------------------- | | ||
| `tree` | [`Tree`](/reference/core-api/devkit/documents/Tree) | | ||
| `packageName` | `string` | | ||
| `packageJson?` | `PackageJson` | | ||
| `dependencyLookup?` | `PackageJsonDependencySection`[] | | ||
|
||
#### Returns | ||
|
||
`string` \| `null` | ||
|
||
▸ **getDependencyVersionFromPackageJson**(`packageName`, `workspaceRootPath?`, `packageJsonPath?`, `dependencyLookup?`): `string` \| `null` | ||
|
||
#### Parameters | ||
|
||
| Name | Type | | ||
| :------------------- | :------------------------------- | | ||
| `packageName` | `string` | | ||
| `workspaceRootPath?` | `string` | | ||
| `packageJsonPath?` | `string` | | ||
| `dependencyLookup?` | `PackageJsonDependencySection`[] | | ||
|
||
#### Returns | ||
|
||
`string` \| `null` | ||
|
||
▸ **getDependencyVersionFromPackageJson**(`packageName`, `workspaceRootPath?`, `packageJson?`, `dependencyLookup?`): `string` \| `null` | ||
|
||
#### Parameters | ||
|
||
| Name | Type | | ||
| :------------------- | :------------------------------- | | ||
| `packageName` | `string` | | ||
| `workspaceRootPath?` | `string` | | ||
| `packageJson?` | `PackageJson` | | ||
| `dependencyLookup?` | `PackageJsonDependencySection`[] | | ||
|
||
#### Returns | ||
|
||
`string` \| `null` |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.