1
1
'use strict' ;
2
2
3
+ const Debug = require ( 'debug' ) ;
3
4
const Fs = require ( 'fs' ) ;
4
5
const GitUrlParse = require ( 'git-url-parse' ) ;
5
6
const Package = require ( '../package.json' ) ;
@@ -9,7 +10,10 @@ const Wreck = require('@hapi/wreck');
9
10
10
11
const Utils = require ( './utils' ) ;
11
12
12
- const internals = { } ;
13
+ const internals = {
14
+ log : Debug ( 'detect-node-support:loader' ) ,
15
+ error : Debug ( 'detect-node-support:error' )
16
+ } ;
13
17
14
18
15
19
internals . parseRepository = ( packument ) => {
@@ -66,6 +70,10 @@ internals.createPackageLoader = async (packageName) => {
66
70
67
71
internals . createRepositoryLoader = ( repository ) => {
68
72
73
+ if ( repository . split ( '/' ) . length === 2 ) {
74
+ repository = `https://github.com/${ repository } ` ;
75
+ }
76
+
69
77
const parsedRepository = GitUrlParse ( repository ) ;
70
78
71
79
return {
@@ -85,20 +93,24 @@ internals.createRepositoryLoader = (repository) => {
85
93
}
86
94
87
95
const url = `https://raw.githubusercontent.com/${ parsedRepository . full_name } /HEAD/${ filename } ` ;
96
+ internals . log ( 'Loading: %s' , url ) ;
88
97
89
98
try {
90
99
const { payload } = await Wreck . get ( url , options ) ;
91
100
101
+ internals . log ( 'Loaded: %s' , url ) ;
92
102
return payload ;
93
103
}
94
104
catch ( err ) {
95
105
96
- if ( err . output && err . output . statusCode === 404 ) {
106
+ if ( err . data && err . data . res . statusCode === 404 ) {
107
+ internals . log ( 'Not found: %s' , url ) ;
97
108
const error = new Error ( `${ repository } does not contain a ${ filename } ` ) ;
98
109
error . code = 'ENOENT' ;
99
110
throw error ;
100
111
}
101
112
113
+ internals . error ( 'Failed to load: %s' , url ) ;
102
114
throw err ;
103
115
}
104
116
}
0 commit comments