@@ -5,49 +5,42 @@ var execFileSync = require('child_process').execFileSync
55var fs = require ( 'fs' )
66var tempy = require ( 'tempy' ) // Locked to 0.2.1 for node 6 support
77var cleanEnv = require ( './util/clean-env' )
8-
9- // Old npm (v3?) doesn't support the mechanisms of this test
108var npm = process . platform === 'win32' ? 'npm.cmd' : 'npm'
11- var supported = execFileSync ( npm , [ '-v' ] ) . toString ( ) . match ( / ^ ( \d + ) \. / ) [ 1 ] > 3
129
13- supported && test ( 'skips download in standalone package ' , function ( t ) {
14- run ( t , 'standalone' , '' , function ( code , logs ) {
15- t . is ( code , 1 )
16- t . is ( logs . pop ( ) , 'prebuild-install info install installing standalone , skipping download.' )
10+ test ( 'skips download in git dependency ' , function ( t ) {
11+ // We're not testing this flag. Just that we do hit the code paths before it
12+ run ( t , 'git' , '--build-from-source' , function ( logs ) {
13+ t . is ( logs . pop ( ) , 'prebuild-install info install installing from git repository , skipping download.' )
1714 t . end ( )
1815 } )
1916} )
2017
21- supported && test ( 'skips download in git dependency' , function ( t ) {
22- run ( t , 'git' , '' , function ( code , logs ) {
23- t . is ( code , 1 )
24- t . is ( logs . pop ( ) , 'prebuild-install info install installing from git repository, skipping download.' )
18+ test ( 'does not skip download in normal dependency' , function ( t ) {
19+ // We're not testing this flag. Just that we don't hit the code paths before it
20+ run ( t , 'tarball' , '--build-from-source' , function ( logs ) {
21+ t . is ( logs . pop ( ) , 'prebuild-install info install --build- from-source specified, not attempting download.' )
2522 t . end ( )
2623 } )
2724} )
2825
29- supported && test ( 'does not skip download in normal dependency ' , function ( t ) {
26+ test ( 'does not skip download in standalone package ' , function ( t ) {
3027 // We're not testing this flag. Just that we don't hit the code paths before it
31- run ( t , 'tarball' , '--build-from-source' , function ( code , logs ) {
32- t . is ( code , 1 )
28+ run ( t , 'standalone' , '--build-from-source' , function ( logs ) {
3329 t . is ( logs . pop ( ) , 'prebuild-install info install --build-from-source specified, not attempting download.' )
3430 t . end ( )
3531 } )
3632} )
3733
3834function run ( t , mode , args , cb ) {
3935 var addon = tempy . directory ( )
36+ var logfile = path . join ( addon , 'prebuild-install.log' )
4037 var cwd = addon
4138
4239 writePackage ( addon , {
4340 name : 'addon' ,
4441 version : '1.0.0' ,
45- dependencies : {
46- 'prebuild-install' : 'file:' + path . dirname ( __dirname )
47- } ,
4842 scripts : {
49- // TODO: npm 7 cannot find "prebuild-install" command in tarball mode
50- install : 'prebuild-install ' + args
43+ install : 'node ' + path . resolve ( __dirname , '..' , 'bin.js' ) + ' ' + args + ' || exit 0'
5144 }
5245 } )
5346
@@ -66,11 +59,22 @@ function run (t, mode, args, cb) {
6659 var env = Object . assign ( cleanEnv ( process . env ) , {
6760 // We shouldn't hit npm or github
6861 npm_config_registry : 'http://localhost:1234' ,
69- npm_config_addon_binary_host : 'http://localhost:1234'
62+ npm_config_addon_binary_host : 'http://localhost:1234' ,
63+ npm_config_prefer_offline : 'true' ,
64+ npm_config_audit : 'false' ,
65+
66+ // Temporary workaround for npm 7 which swallows our output
67+ npm_config_prebuild_install_logfile : logfile ,
68+ npm_config_loglevel : 'info'
7069 } )
7170
72- exec ( npm + ' install --loglevel=info' , { cwd, env, encoding : 'utf8' } , function ( err , stdout , stderr ) {
73- cb ( err && err . code , logs ( stderr ) )
71+ exec ( npm + ' install' , { cwd, env } , function ( err ) {
72+ t . ifError ( err , 'no install error' )
73+
74+ fs . readFile ( logfile , 'utf8' , function ( err , data ) {
75+ t . ifError ( err , 'no read error' )
76+ cb ( logs ( data ) )
77+ } )
7478 } )
7579}
7680
@@ -85,9 +89,18 @@ function prepareGit (cwd) {
8589 execFileSync ( 'git' , [ 'add' , 'package.json' ] , { cwd, stdio : 'ignore' } )
8690 execFileSync ( 'git' , [ 'commit' , '-m' , 'test' ] , { cwd, stdio : 'ignore' } )
8791
92+ if ( process . platform === 'win32' && npmVersion ( ) >= 7 ) {
93+ // Otherwise results in invalid url error
94+ return 'git+file:///' + cwd
95+ }
96+
8897 return 'git+file://' + cwd
8998}
9099
100+ function npmVersion ( ) {
101+ return parseInt ( execFileSync ( npm , [ '-v' ] ) . toString ( ) )
102+ }
103+
91104function prepareTarball ( cwd ) {
92105 // Packs to <name>-<version>.tgz
93106 execFileSync ( npm , [ 'pack' ] , { cwd, stdio : 'ignore' } )
@@ -96,9 +109,13 @@ function prepareTarball (cwd) {
96109}
97110
98111function logs ( stderr ) {
99- return ( stderr || '' ) . split ( / \r ? \n / ) . filter ( isOurs )
112+ return ( stderr || '' ) . split ( / \r ? \n / ) . filter ( isOurs ) . map ( stripPrefix )
100113}
101114
102115function isOurs ( line ) {
103- return / ^ p r e b u i l d - i n s t a l l / . test ( line )
116+ return / ^ ( n p m E R R ! ) ? p r e b u i l d - i n s t a l l / . test ( line )
117+ }
118+
119+ function stripPrefix ( line ) {
120+ return line . replace ( / ^ n p m E R R ! / , '' )
104121}
0 commit comments