-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge release/11.3 into cascading/11.3.0-11.4.0-rc
- Loading branch information
Showing
6 changed files
with
143 additions
and
37 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
56 changes: 56 additions & 0 deletions
56
.../extractors/src/core/comparator/package-managers-extractors/custom-npm-semver-resolver.ts
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,56 @@ | ||
import { npmHttpUtils, NpmSemverFetcher, NpmSemverResolver } from '@yarnpkg/plugin-npm'; | ||
import { Descriptor, miscUtils, Package, ResolveOptions, structUtils } from '@yarnpkg/core'; | ||
import { Range, SemVer, valid } from 'semver'; | ||
|
||
/** | ||
* Unexposed constant from yarn https://github.com/yarnpkg/berry/blob/master/packages/plugin-npm/sources/constants.ts | ||
*/ | ||
const PROTOCOL = `npm:`; | ||
|
||
/** | ||
* Extends NpmSeverResolver to support prerelease tags | ||
* Check original code from https://github.com/yarnpkg/berry/blob/master/packages/plugin-npm/sources/NpmSemverResolver.ts | ||
*/ | ||
export class CustomNpmSemverResolver extends NpmSemverResolver { | ||
/** @inheritDoc */ | ||
public override async getCandidates(descriptor: Descriptor, _dependencies: Record<string, Package>, opts: ResolveOptions) { | ||
const range = new Range(descriptor.range.slice(PROTOCOL.length), {includePrerelease: true}); | ||
const registryData = await npmHttpUtils.getPackageMetadata(descriptor, { | ||
cache: opts.fetchOptions?.cache, | ||
project: opts.project, | ||
version: valid(range.raw) ? range.raw : undefined | ||
}); | ||
|
||
const candidates = miscUtils.mapAndFilter(Object.keys(registryData.versions), (version) => { | ||
try { | ||
const candidate = new SemVer(version, {includePrerelease: true}); | ||
if (range.test(candidate)) { | ||
return candidate; | ||
} | ||
} catch { } | ||
|
||
return miscUtils.mapAndFilter.skip; | ||
}); | ||
|
||
const noDeprecatedCandidates = candidates.filter((version) => !registryData.versions[version.raw].deprecated); | ||
|
||
// If there are versions that aren't deprecated, use them | ||
const finalCandidates = noDeprecatedCandidates.length > 0 | ||
? noDeprecatedCandidates | ||
: candidates; | ||
|
||
finalCandidates.sort((a, b) => -a.compare(b)); | ||
|
||
return finalCandidates.map(version => { | ||
const versionLocator = structUtils.makeLocator(descriptor, `${PROTOCOL}${version.raw}`); | ||
const archiveUrl = registryData.versions[version.raw].dist.tarball; | ||
|
||
if (NpmSemverFetcher.isConventionalTarballUrl(versionLocator, archiveUrl, {configuration: opts.project.configuration})) { | ||
return versionLocator; | ||
} else { | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
return structUtils.bindLocator(versionLocator, {__archiveUrl: archiveUrl}); | ||
} | ||
}); | ||
} | ||
} |
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
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.