Skip to content

Commit

Permalink
feat: allowed deprecated versions
Browse files Browse the repository at this point in the history
close #4306
  • Loading branch information
zkochan committed Jun 6, 2022
1 parent 70007c0 commit d75a096
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/core/src/getPeerDependencyIssues.ts
Expand Up @@ -48,6 +48,7 @@ export async function getPeerDependencyIssues (
projectsToResolve,
{
currentLockfile: ctx.currentLockfile,
allowedDeprecatedVersions: {},
defaultUpdateDepth: -1,
dryRun: true,
engineStrict: false,
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/install/extendInstallOptions.ts
Expand Up @@ -7,6 +7,7 @@ import normalizeRegistries, { DEFAULT_REGISTRIES } from '@pnpm/normalize-registr
import { WorkspacePackages } from '@pnpm/resolver-base'
import { StoreController } from '@pnpm/store-controller-types'
import {
AllowedDeprecatedVersions,
PackageExtension,
PeerDependencyRules,
ReadPackageHook,
Expand Down Expand Up @@ -86,6 +87,7 @@ export interface StrictInstallOptions {
enableModulesDir: boolean
modulesCacheMaxAge: number
peerDependencyRules: PeerDependencyRules
allowedDeprecatedVersions: AllowedDeprecatedVersions

publicHoistPattern: string[] | undefined
hoistPattern: string[] | undefined
Expand All @@ -108,6 +110,7 @@ const defaults = async (opts: InstallOptions) => {
version: pnpmPkgJson.version,
}
return {
allowedDeprecatedVersions: {},
autoInstallPeers: false,
childConcurrency: 5,
depth: 0,
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/install/index.ts
Expand Up @@ -740,6 +740,7 @@ const _installInContext: InstallFunction = async (projects, ctx, opts) => {
projects,
{
allowBuild: createAllowBuildFunction(opts),
allowedDeprecatedVersions: opts.allowedDeprecatedVersions,
autoInstallPeers: opts.autoInstallPeers,
currentLockfile: ctx.currentLockfile,
defaultUpdateDepth: (opts.update || (opts.updateMatching != null)) ? opts.depth : -1,
Expand Down
@@ -1,10 +1,12 @@
import {
AllowedDeprecatedVersions,
PackageExtension,
PeerDependencyRules,
ProjectManifest,
} from '@pnpm/types'

export default function getOptionsFromRootManifest (manifest: ProjectManifest): {
allowedDeprecatedVersions?: AllowedDeprecatedVersions
overrides?: Record<string, string>
neverBuiltDependencies?: string[]
onlyBuiltDependencies?: string[]
Expand All @@ -19,7 +21,9 @@ export default function getOptionsFromRootManifest (manifest: ProjectManifest):
const onlyBuiltDependencies = manifest.pnpm?.onlyBuiltDependencies
const packageExtensions = manifest.pnpm?.packageExtensions
const peerDependencyRules = manifest.pnpm?.peerDependencyRules
const allowedDeprecatedVersions = manifest.pnpm?.allowedDeprecatedVersions
return {
allowedDeprecatedVersions,
overrides,
neverBuiltDependencies,
onlyBuiltDependencies,
Expand Down
7 changes: 6 additions & 1 deletion packages/resolve-dependencies/src/resolveDependencies.ts
Expand Up @@ -29,6 +29,7 @@ import {
StoreController,
} from '@pnpm/store-controller-types'
import {
AllowedDeprecatedVersions,
Dependencies,
DependencyManifest,
PackageManifest,
Expand Down Expand Up @@ -119,6 +120,7 @@ export interface ChildrenByParentDepPath {
export interface ResolutionContext {
autoInstallPeers: boolean
allowBuild?: (pkgName: string) => boolean
allowedDeprecatedVersions: AllowedDeprecatedVersions
updatedSet: Set<string>
defaultTag: string
dryRun: boolean
Expand Down Expand Up @@ -889,7 +891,10 @@ async function resolveDependency (
const isNew = !ctx.resolvedPackagesByDepPath[depPath]

if (isNew) {
if (pkg.deprecated) {
if (
pkg.deprecated &&
(!ctx.allowedDeprecatedVersions[pkg.name] || !semver.satisfies(pkg.version, ctx.allowedDeprecatedVersions[pkg.name]))
) {
// Report deprecated packages only on first occurrence.
deprecationLogger.debug({
deprecated: pkg.deprecated,
Expand Down
3 changes: 3 additions & 0 deletions packages/resolve-dependencies/src/resolveDependencyTree.ts
Expand Up @@ -2,6 +2,7 @@ import { Lockfile } from '@pnpm/lockfile-types'
import { PreferredVersions, Resolution, WorkspacePackages } from '@pnpm/resolver-base'
import { StoreController } from '@pnpm/store-controller-types'
import {
AllowedDeprecatedVersions,
ProjectManifest,
ReadPackageHook,
Registries,
Expand Down Expand Up @@ -55,6 +56,7 @@ export interface ImporterToResolveGeneric<T> extends Importer<T> {
export interface ResolveDependenciesOptions {
autoInstallPeers?: boolean
allowBuild?: (pkgName: string) => boolean
allowedDeprecatedVersions: AllowedDeprecatedVersions
currentLockfile: Lockfile
dryRun: boolean
engineStrict: boolean
Expand Down Expand Up @@ -88,6 +90,7 @@ export default async function<T> (
const ctx = {
autoInstallPeers: opts.autoInstallPeers === true,
allowBuild: opts.allowBuild,
allowedDeprecatedVersions: opts.allowedDeprecatedVersions,
childrenByParentDepPath: {} as ChildrenByParentDepPath,
currentLockfile: opts.currentLockfile,
defaultTag: opts.tag,
Expand Down
3 changes: 3 additions & 0 deletions packages/types/src/package.ts
Expand Up @@ -115,13 +115,16 @@ export interface PeerDependencyRules {
allowedVersions?: Record<string, string>
}

export type AllowedDeprecatedVersions = Record<string, string>

export type ProjectManifest = BaseManifest & {
pnpm?: {
neverBuiltDependencies?: string[]
onlyBuiltDependencies?: string[]
overrides?: Record<string, string>
packageExtensions?: Record<string, PackageExtension>
peerDependencyRules?: PeerDependencyRules
allowedDeprecatedVersions?: AllowedDeprecatedVersions
}
private?: boolean
resolutions?: Record<string, string>
Expand Down

0 comments on commit d75a096

Please sign in to comment.