@@ -8,16 +8,13 @@ const { sync: spawnSync } = require('cross-spawn');
88const fs = require ( 'fs-extra' ) ;
99const path = require ( 'path' ) ;
1010const Paths = require ( './paths' ) ;
11+ const { satisfies } = require ( 'semver' ) ;
1112
12- const NodeVersion = ( versions => {
13- return { major : versions [ 0 ] , minor : versions [ 1 ] , patch : versions [ 2 ] } ;
14- } ) (
15- process . versions . node
16- . split ( '-' )
17- . shift ( )
18- . split ( '.' )
19- . map ( s => parseInt ( s , 10 ) )
20- ) ;
13+ const npmVersion = spawnSync ( 'npm' , [ '-s' , '--version' ] )
14+ . stdout . toString ( )
15+ . trim ( ) ;
16+ const npmHasCiCommand = satisfies ( npmVersion , '>=5.7.0' ) ;
17+ const npmHasPrepare = satisfies ( npmVersion , '>=4.0.0' ) ;
2118
2219function getDirectories ( rootDir ) {
2320 return fs . readdirSync ( rootDir ) . filter ( function ( file ) {
@@ -28,6 +25,13 @@ function getDirectories(rootDir) {
2825function setupE2e ( ) {
2926 // this will trigger the build as well (not using yarn since yarn pack is bugy)
3027 // keep on to so that the build is triggered beforehand (pack => prepublish => clean-build => build)
28+ // Except that on npm < 4.0.0 the prepare doesn't exists
29+ if ( ! npmHasPrepare ) {
30+ spawnSync ( 'npm' , [ '-s' , 'run' , 'build' ] , {
31+ cwd : Paths . rootDir ,
32+ stdio : 'inherit' ,
33+ } ) ;
34+ }
3135 const res = spawnSync ( 'npm' , [ '-s' , 'pack' ] , { cwd : Paths . rootDir } ) ;
3236 const bundle = path . join ( Paths . rootDir , res . stdout . toString ( ) . trim ( ) ) ;
3337
@@ -53,10 +57,9 @@ function setupE2e() {
5357 // template dir, to know if we should re-install or not
5458 if ( fs . existsSync ( path . join ( dir , 'node_modules' ) ) ) return ;
5559
56- if ( NodeVersion . major >= 8 ) {
60+ if ( npmHasCiCommand ) {
5761 spawnSync ( 'npm' , [ 'ci' ] , { cwd : dir , stdio : 'inherit' } ) ;
5862 } else {
59- // npm coming with node < 8 does not have the `ci` command
6063 spawnSync ( 'npm' , [ 'i' ] , { cwd : dir , stdio : 'inherit' } ) ;
6164 }
6265 spawnSync ( 'npm' , [ 'i' , '-D' , bundle ] , { cwd : dir , stdio : 'inherit' } ) ;
0 commit comments