-
Notifications
You must be signed in to change notification settings - Fork 664
[npm-check-fork] - Replace package-json and throat dependencies #5565
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
+863
−315
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
105b340
feat(npm-check-fork): add npm registry type definitions
TheLarkInn e439bc3
feat(npm-check-fork): add NpmRegistryClient for fetching package meta…
TheLarkInn 7fa09ce
refactor(npm-check-fork): use NpmRegistryClient in GetLatestFromRegistry
TheLarkInn 864462f
feat(npm-check-fork): add getNpmInfoBatch for concurrent package fetc…
TheLarkInn d3378f5
refactor(npm-check-fork): remove package-json and throat dependencies
TheLarkInn 3b73c38
test(npm-check-fork): add unit tests for NpmRegistryClient
TheLarkInn a28a131
docs(npm-check-fork): update CHANGELOG for dependency replacement
TheLarkInn 8d40f92
cleanup from code review
TheLarkInn d216e0d
remove ai outputs
TheLarkInn 3e4f852
rush change
TheLarkInn a948130
restore CHANGELOG.md
TheLarkInn 6a6e724
docs(npm-check-fork): fix JSDoc claiming interface extends when it do…
Copilot d264e90
Add comprehensive unit tests for NpmRegistryClient with http mocking …
Copilot a4fa3bf
DROP: rush update
TheLarkInn 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
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
common/changes/@rushstack/npm-check-fork/atomic-style-claude_2026-01-24-18-36.json
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,10 @@ | ||
| { | ||
| "changes": [ | ||
| { | ||
| "packageName": "@rushstack/npm-check-fork", | ||
| "comment": "Remove dependencies on throat and package-json", | ||
| "type": "patch" | ||
| } | ||
| ], | ||
| "packageName": "@rushstack/npm-check-fork" | ||
| } |
256 changes: 5 additions & 251 deletions
256
common/config/subspaces/build-tests-subspace/pnpm-lock.yaml
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| // DO NOT MODIFY THIS FILE MANUALLY BUT DO COMMIT IT. It is generated and used by Rush. | ||
| { | ||
| "pnpmShrinkwrapHash": "da80c128380df78244e113861884b5e6a38ad7c5", | ||
| "pnpmShrinkwrapHash": "5d9bc6eee5c9d99eb1d47a58664f6c7488199d42", | ||
| "preferredVersionsHash": "550b4cee0bef4e97db6c6aad726df5149d20e7d9", | ||
| "packageJsonInjectedDependenciesHash": "1c312688ef85bfdb64079cc271a46b18d816d411" | ||
| "packageJsonInjectedDependenciesHash": "88585d29209a34b4908b0928fd68566f978c2bca" | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| // DO NOT MODIFY THIS FILE MANUALLY BUT DO COMMIT IT. It is generated and used by Rush. | ||
| { | ||
| "pnpmShrinkwrapHash": "aebea9e28d4e012d8a37fc57c92bd28eb386df5b", | ||
| "pnpmShrinkwrapHash": "b0dbc9dd6df6e790055edb199b9d85eb3a0f200f", | ||
| "preferredVersionsHash": "a9b67c38568259823f9cfb8270b31bf6d8470b27" | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,45 +1,97 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. | ||
| // See LICENSE in the project root for license information. | ||
|
|
||
| import os from 'node:os'; | ||
|
|
||
| import _ from 'lodash'; | ||
| import semver from 'semver'; | ||
| import packageJson from 'package-json'; | ||
| import throat from 'throat'; | ||
|
|
||
| import { Async } from '@rushstack/node-core-library'; | ||
|
|
||
| import bestGuessHomepage from './BestGuessHomepage'; | ||
| import type { INpmRegistryInfo } from './interfaces/INpmCheckRegistry'; | ||
| import { NpmRegistryClient, type INpmRegistryClientResult } from './NpmRegistryClient'; | ||
| import type { | ||
| INpmRegistryInfo, | ||
| INpmCheckRegistryData, | ||
| INpmRegistryPackageResponse | ||
| } from './interfaces/INpmCheckRegistry'; | ||
|
|
||
| const cpuCount: number = os.cpus().length; | ||
| // Module-level registry client instance (lazy initialized) | ||
| let _registryClient: NpmRegistryClient | undefined; | ||
|
|
||
| /** | ||
| * Gets or creates the shared registry client instance. | ||
| */ | ||
| function getRegistryClient(): NpmRegistryClient { | ||
| if (!_registryClient) { | ||
| _registryClient = new NpmRegistryClient(); | ||
| } | ||
| return _registryClient; | ||
| } | ||
|
|
||
| /** | ||
| * Fetches package information from the npm registry. | ||
| * | ||
| * @param packageName - The name of the package to fetch | ||
| * @returns A promise that resolves to the package registry info | ||
| */ | ||
| export default async function getNpmInfo(packageName: string): Promise<INpmRegistryInfo> { | ||
| const limit: () => Promise<packageJson.FullMetadata> = throat(cpuCount, () => | ||
| packageJson(packageName, { fullMetadata: true, allVersions: true }) | ||
| const client: NpmRegistryClient = getRegistryClient(); | ||
| const result: INpmRegistryClientResult = await client.fetchPackageMetadataAsync(packageName); | ||
|
|
||
| if (result.error) { | ||
| return { | ||
| error: `Registry error ${result.error}` | ||
| }; | ||
| } | ||
|
|
||
| const rawData: INpmRegistryPackageResponse = result.data!; | ||
| const CRAZY_HIGH_SEMVER: string = '8000.0.0'; | ||
| const sortedVersions: string[] = _(rawData.versions) | ||
| .keys() | ||
| .remove(_.partial(semver.gt, CRAZY_HIGH_SEMVER)) | ||
| .sort(semver.compare) | ||
| .valueOf(); | ||
|
|
||
| const latest: string = rawData['dist-tags'].latest; | ||
| const next: string = rawData['dist-tags'].next; | ||
| const latestStableRelease: string | undefined = semver.satisfies(latest, '*') | ||
| ? latest | ||
| : semver.maxSatisfying(sortedVersions, '*') || ''; | ||
|
|
||
| // Cast to INpmCheckRegistryData for bestGuessHomepage compatibility | ||
| // INpmRegistryPackageResponse is a superset of INpmCheckRegistryData | ||
| const registryData: INpmCheckRegistryData = rawData as unknown as INpmCheckRegistryData; | ||
|
|
||
| return { | ||
| latest: latestStableRelease, | ||
| next: next, | ||
| versions: sortedVersions, | ||
| homepage: bestGuessHomepage(registryData) || '' | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Fetches package information for multiple packages concurrently. | ||
| * | ||
| * @param packageNames - Array of package names to fetch | ||
| * @param concurrency - Maximum number of concurrent requests (defaults to CPU count) | ||
| * @returns A promise that resolves to a Map of package name to registry info | ||
| */ | ||
| export async function getNpmInfoBatch( | ||
TheLarkInn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| packageNames: string[], | ||
| concurrency: number = os.cpus().length | ||
| ): Promise<Map<string, INpmRegistryInfo>> { | ||
| const results: Map<string, INpmRegistryInfo> = new Map(); | ||
|
|
||
| // TODO: Refactor createPackageSummary to use this batch function to reduce registry requests | ||
| await Async.forEachAsync( | ||
| packageNames, | ||
| async (packageName: string) => { | ||
| results.set(packageName, await getNpmInfo(packageName)); | ||
| }, | ||
| { concurrency } | ||
TheLarkInn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ); | ||
| return limit() | ||
| .then((rawData: packageJson.FullMetadata) => { | ||
| const CRAZY_HIGH_SEMVER: string = '8000.0.0'; | ||
| const sortedVersions: string[] = _(rawData.versions) | ||
| .keys() | ||
| .remove(_.partial(semver.gt, CRAZY_HIGH_SEMVER)) | ||
| .sort(semver.compare) | ||
| .valueOf(); | ||
|
|
||
| const latest: string = rawData['dist-tags'].latest; | ||
| const next: string = rawData['dist-tags'].next; | ||
| const latestStableRelease: string | undefined = semver.satisfies(latest, '*') | ||
| ? latest | ||
| : semver.maxSatisfying(sortedVersions, '*') || ''; | ||
|
|
||
| return { | ||
| latest: latestStableRelease, | ||
| next: next, | ||
| versions: sortedVersions, | ||
| homepage: bestGuessHomepage(rawData) || '' | ||
| }; | ||
| }) | ||
| .catch((error) => { | ||
| const errorMessage: string = `Registry error ${error.message}`; | ||
| return { | ||
| error: errorMessage | ||
| }; | ||
| }); | ||
|
|
||
| return results; | ||
| } | ||
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.