11'use strict' ;
22
3+ const Debug = require ( 'debug' ) ;
34const Fs = require ( 'fs' ) ;
45const GitUrlParse = require ( 'git-url-parse' ) ;
56const Package = require ( '../package.json' ) ;
@@ -9,7 +10,10 @@ const Wreck = require('@hapi/wreck');
910
1011const Utils = require ( './utils' ) ;
1112
12- const internals = { } ;
13+ const internals = {
14+ log : Debug ( 'detect-node-support:loader' ) ,
15+ error : Debug ( 'detect-node-support:error' )
16+ } ;
1317
1418
1519internals . parseRepository = ( packument ) => {
@@ -66,6 +70,10 @@ internals.createPackageLoader = async (packageName) => {
6670
6771internals . createRepositoryLoader = ( repository ) => {
6872
73+ if ( repository . split ( '/' ) . length === 2 ) {
74+ repository = `https://github.com/${ repository } ` ;
75+ }
76+
6977 const parsedRepository = GitUrlParse ( repository ) ;
7078
7179 return {
@@ -85,20 +93,24 @@ internals.createRepositoryLoader = (repository) => {
8593 }
8694
8795 const url = `https://raw.githubusercontent.com/${ parsedRepository . full_name } /HEAD/${ filename } ` ;
96+ internals . log ( 'Loading: %s' , url ) ;
8897
8998 try {
9099 const { payload } = await Wreck . get ( url , options ) ;
91100
101+ internals . log ( 'Loaded: %s' , url ) ;
92102 return payload ;
93103 }
94104 catch ( err ) {
95105
96- if ( err . output && err . output . statusCode === 404 ) {
106+ if ( err . data && err . data . res . statusCode === 404 ) {
107+ internals . log ( 'Not found: %s' , url ) ;
97108 const error = new Error ( `${ repository } does not contain a ${ filename } ` ) ;
98109 error . code = 'ENOENT' ;
99110 throw error ;
100111 }
101112
113+ internals . error ( 'Failed to load: %s' , url ) ;
102114 throw err ;
103115 }
104116 }
0 commit comments