@@ -10,6 +10,8 @@ import config from '@socketsecurity/config'
10
10
import chalk from 'chalk'
11
11
import isInteractive from 'is-interactive'
12
12
import ora , { spinners } from 'ora'
13
+ import npmPackageArg from 'npm-package-arg'
14
+ import semver from 'semver'
13
15
14
16
import { API_V0_URL , ENV } from '../constants'
15
17
import { createTTYServer } from './tty-server'
@@ -31,6 +33,7 @@ import type {
31
33
Options as ArboristOptions
32
34
} from '@npmcli/arborist'
33
35
import type { Options as OraOptions } from 'ora'
36
+ import type { AliasResult , RegistryResult } from 'npm-package-arg'
34
37
35
38
type ArboristClass = typeof BaseArborist & {
36
39
new ( ...args : any ) : typeof BaseArborist
@@ -1032,6 +1035,52 @@ class SafeOverrideSet extends OverrideSet {
1032
1035
return true
1033
1036
}
1034
1037
1038
+ override getEdgeRule ( edge : SafeEdge ) : OverrideSetClass {
1039
+ for ( const rule of this . ruleset . values ( ) ) {
1040
+ if ( rule . name !== edge . name ) {
1041
+ continue
1042
+ }
1043
+ // If keySpec is * we found our override.
1044
+ if ( rule . keySpec === '*' ) {
1045
+ return rule
1046
+ }
1047
+ // Patch replacing
1048
+ // let spec = npa(`${edge.name}@${edge.spec}`)
1049
+ // is based on https://github.com/npm/cli/pull/7025.
1050
+ //
1051
+ // We need to use the rawSpec here, because the spec has the overrides
1052
+ // applied to it already.
1053
+ let spec = npmPackageArg ( `${ edge . name } @${ edge . rawSpec } ` )
1054
+ if ( spec . type === 'alias' ) {
1055
+ spec = ( < AliasResult > spec ) . subSpec
1056
+ }
1057
+ if ( spec . type === 'git' ) {
1058
+ if (
1059
+ spec . gitRange &&
1060
+ rule . keySpec &&
1061
+ semver . intersects ( spec . gitRange , rule . keySpec )
1062
+ ) {
1063
+ return rule
1064
+ }
1065
+ continue
1066
+ }
1067
+ if ( spec . type === 'range' || spec . type === 'version' ) {
1068
+ if (
1069
+ rule . keySpec &&
1070
+ semver . intersects ( ( < RegistryResult > spec ) . fetchSpec , rule . keySpec )
1071
+ ) {
1072
+ return rule
1073
+ }
1074
+ continue
1075
+ }
1076
+ // If we got this far, the spec type is one of tag, directory or file
1077
+ // which means we have no real way to make version comparisons, so we
1078
+ // just accept the override.
1079
+ return rule
1080
+ }
1081
+ return this
1082
+ }
1083
+
1035
1084
// Patch adding isEqual is based on
1036
1085
// https://github.com/npm/cli/pull/7025.
1037
1086
override isEqual ( otherOverrideSet : OverrideSetClass | undefined ) {
0 commit comments