11var shell = require ( 'shelljs' ) ,
22 path = require ( 'path' ) ,
33 async = require ( 'async' ) ,
4- { detect } = require ( 'detect-package-manager' ) ,
4+ { detect, getNpmVersion } = require ( 'detect-package-manager' ) ,
55 pm ,
6- PRODUCTION_FLAG = '' ,
6+ ver ,
7+ command ,
78 getSubfolders ,
89 fs = require ( 'fs' ) ,
910 pwd = shell . pwd ( ) ;
@@ -24,12 +25,34 @@ async.series([
2425 return next ( ) ;
2526 } ) ;
2627 } ,
28+ function ( next ) {
29+ getNpmVersion ( pm ) . then ( ( res ) => {
30+ ver = res ;
31+ console . log ( 'Detected ' + pm + ' version: ' + ver ) ;
32+ return next ( ) ;
33+ } ) ;
34+ } ,
2735 function ( next ) {
2836 if ( args [ 2 ] && args [ 2 ] === 'dev' ) {
2937 console . log ( 'Dev flag detected running ' + pm + ' install' ) ;
38+ command = pm + ' install' ;
3039 }
3140 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+ }
3356 }
3457
3558 console . log ( 'Running pre-package script' ) ;
@@ -51,8 +74,8 @@ async.series([
5174
5275 var commandOut ;
5376
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 } ) ;
5679
5780 if ( commandOut . code !== 0 ) {
5881 console . error ( 'Failed to run ' + pm + ' install on codegen ' + codegen . name + ', here is the error:' ) ;
0 commit comments