1
1
var shell = require ( 'shelljs' ) ,
2
2
path = require ( 'path' ) ,
3
3
async = require ( 'async' ) ,
4
- { detect } = require ( 'detect-package-manager' ) ,
4
+ { detect, getNpmVersion } = require ( 'detect-package-manager' ) ,
5
5
pm ,
6
- PRODUCTION_FLAG = '' ,
6
+ ver ,
7
+ command ,
7
8
getSubfolders ,
8
9
fs = require ( 'fs' ) ,
9
10
pwd = shell . pwd ( ) ;
@@ -24,12 +25,34 @@ async.series([
24
25
return next ( ) ;
25
26
} ) ;
26
27
} ,
28
+ function ( next ) {
29
+ getNpmVersion ( pm ) . then ( ( res ) => {
30
+ ver = res ;
31
+ console . log ( 'Detected ' + pm + ' version: ' + ver ) ;
32
+ return next ( ) ;
33
+ } ) ;
34
+ } ,
27
35
function ( next ) {
28
36
if ( args [ 2 ] && args [ 2 ] === 'dev' ) {
29
37
console . log ( 'Dev flag detected running ' + pm + ' install' ) ;
38
+ command = pm + ' install' ;
30
39
}
31
40
else {
32
- PRODUCTION_FLAG = '--no-audit --production' ;
41
+ switch ( pm ) {
42
+ case 'yarn' :
43
+ if ( ver . startsWith ( '1' ) ) {
44
+ command = 'yarn install --production --frozen-lockfile' ;
45
+ }
46
+ else {
47
+ command = 'touch yarn.lock && yarn workspaces focus --all --production'
48
+ }
49
+ break ;
50
+ case 'pnpm' :
51
+ command = 'pnpm install --prod' ;
52
+ break ;
53
+ default :
54
+ command = pm + ' install --no-audit --production' ;
55
+ }
33
56
}
34
57
35
58
console . log ( 'Running pre-package script' ) ;
@@ -51,8 +74,8 @@ async.series([
51
74
52
75
var commandOut ;
53
76
54
- console . log ( codegen . name + ': ' + pm + ' install ' + PRODUCTION_FLAG ) ;
55
- commandOut = shell . exec ( pm + ' install ' + PRODUCTION_FLAG , { silent : true } ) ;
77
+ console . log ( codegen . name + ': ' + command ) ;
78
+ commandOut = shell . exec ( command , { silent : true } ) ;
56
79
57
80
if ( commandOut . code !== 0 ) {
58
81
console . error ( 'Failed to run ' + pm + ' install on codegen ' + codegen . name + ', here is the error:' ) ;
0 commit comments