@@ -42,6 +42,11 @@ export interface IResultOptions {
42
42
* @default github.com
43
43
*/
44
44
platform ?: string ;
45
+ /**
46
+ * @description Try to resolve the given repository on the NPM registry if its not found on the given platform.
47
+ * @default true
48
+ */
49
+ resolveOnNpmRegistry ?: boolean ;
45
50
}
46
51
47
52
async function getNpmRepository ( repository : string ) : Promise < string > {
@@ -67,7 +72,10 @@ export async function result(
67
72
options : IResultOptions = { }
68
73
) : Promise < ScorecardResult > {
69
74
let formattedRepository = repository ;
70
- const { platform = kDefaultPlatform } = options ;
75
+ const {
76
+ platform = kDefaultPlatform ,
77
+ resolveOnNpmRegistry = true
78
+ } = options ;
71
79
const [ owner , repo ] = repository . replace ( "@" , "" ) . split ( "/" ) ;
72
80
73
81
try {
@@ -83,14 +91,20 @@ export async function result(
83
91
const data = await response . json ( ) as any ;
84
92
formattedRepository = data . full_name ;
85
93
}
86
- catch {
87
- // If the repository is not found, we try to retrieve it from the NPM registry
88
- // i.e: if given repository is "@nodesecure/cli"
94
+ catch ( error ) {
95
+ if ( ! resolveOnNpmRegistry ) {
96
+ throw new Error ( "Invalid repository, cannot find it on GitHub" , {
97
+ cause : error
98
+ } ) ;
99
+ }
100
+
89
101
try {
90
102
formattedRepository = await getNpmRepository ( repository ) ;
91
103
}
92
- catch {
93
- throw new Error ( "Invalid repository, cannot find it on GitHub or NPM registry" ) ;
104
+ catch ( error ) {
105
+ throw new Error ( "Invalid repository, cannot find it on GitHub or NPM registry" , {
106
+ cause : error
107
+ } ) ;
94
108
}
95
109
}
96
110
0 commit comments