@@ -16,11 +16,16 @@ module.exports = CoreObject.extend({
1616 } ,
1717 useYarnCommand : false ,
1818 yarnLock : 'yarn.lock' ,
19+ yarnLockBackupFileName : 'yarn.lock.ember-try' ,
1920 configKey : 'npm' ,
2021 packageJSON : 'package.json' ,
2122 packageJSONBackupFileName : 'package.json.ember-try' ,
2223 nodeModules : 'node_modules' ,
2324 nodeModulesBackupLocation : '.node_modules.ember-try' ,
25+ npmShrinkWrap : 'npm-shrinkwrap.json' ,
26+ npmShrinkWrapBackupFileName : 'npm-shrinkwrap.json.ember-try' ,
27+ packageLock : 'package-lock.json' ,
28+ packageLockBackupFileName : 'package-lock.json.ember-try' ,
2429 setup ( options ) {
2530 if ( ! options ) {
2631 options = { } ;
@@ -33,7 +38,7 @@ module.exports = CoreObject.extend({
3338
3439 adapter . applyDependencySet ( depSet ) ;
3540
36- return adapter . _install ( ) . then ( ( ) => {
41+ return adapter . _install ( depSet ) . then ( ( ) => {
3742 let deps = extend ( { } , depSet . dependencies || { } , depSet . devDependencies || { } ) ;
3843 let currentDeps = Object . keys ( deps ) . map ( ( dep ) => {
3944 return {
@@ -58,6 +63,18 @@ module.exports = CoreObject.extend({
5863 let cleanupTasks = [ rimraf ( path . join ( adapter . cwd , adapter . packageJSONBackupFileName ) ) ,
5964 rimraf ( path . join ( adapter . cwd , adapter . nodeModulesBackupLocation ) ) ] ;
6065
66+ if ( fs . existsSync ( path . join ( this . cwd , this . yarnLockBackupFileName ) ) ) {
67+ cleanupTasks . push ( rimraf ( path . join ( adapter . cwd , adapter . yarnLockBackupFileName ) ) ) ;
68+ }
69+
70+ if ( fs . existsSync ( path . join ( this . cwd , this . npmShrinkWrapBackupFileName ) ) ) {
71+ cleanupTasks . push ( rimraf ( path . join ( adapter . cwd , adapter . npmShrinkWrapBackupFileName ) ) ) ;
72+ }
73+
74+ if ( fs . existsSync ( path . join ( this . cwd , this . packageLockBackupFileName ) ) ) {
75+ cleanupTasks . push ( rimraf ( path . join ( adapter . cwd , adapter . packageLockBackupFileName ) ) ) ;
76+ }
77+
6178 return RSVP . all ( cleanupTasks ) ;
6279 } ) . catch ( ( e ) => {
6380 console . log ( 'Error cleaning up npm scenario:' , e ) ; // eslint-disable-line no-console
@@ -82,26 +99,35 @@ module.exports = CoreObject.extend({
8299 return null ;
83100 }
84101 } ,
85- _install ( ) {
102+ _install ( depSet ) {
86103 let adapter = this ;
87104 let mgrOptions = this . managerOptions || [ ] ;
105+ let cmd = this . useYarnCommand ? 'yarn' : 'npm' ;
88106
89- debug ( 'Run npm install with options %s' , mgrOptions ) ;
107+ // buildManagerOptions overrides all default
108+ if ( typeof this . buildManagerOptions === 'function' ) {
109+ mgrOptions = this . buildManagerOptions ( depSet ) ;
90110
91- let cmd = this . useYarnCommand ? 'yarn' : 'npm' ;
92- if ( this . useYarnCommand ) {
93- if ( mgrOptions . indexOf ( '--no-lockfile' ) === - 1 ) {
94- mgrOptions = mgrOptions . concat ( [ '--no-lockfile' ] ) ;
111+ if ( ! Array . isArray ( mgrOptions ) ) {
112+ throw new Error ( 'buildManagerOptions must return an array of options' ) ;
95113 }
96- // npm warns on incompatible engines
97- // yarn errors, not a good experience
98- if ( mgrOptions . indexOf ( '--ignore-engines' ) === - 1 ) {
99- mgrOptions = mgrOptions . concat ( [ '--ignore-engines' ] ) ;
114+ } else {
115+ if ( this . useYarnCommand ) {
116+ if ( mgrOptions . indexOf ( '--no-lockfile' ) === - 1 ) {
117+ mgrOptions = mgrOptions . concat ( [ '--no-lockfile' ] ) ;
118+ }
119+ // npm warns on incompatible engines
120+ // yarn errors, not a good experience
121+ if ( mgrOptions . indexOf ( '--ignore-engines' ) === - 1 ) {
122+ mgrOptions = mgrOptions . concat ( [ '--ignore-engines' ] ) ;
123+ }
124+ } else if ( mgrOptions . indexOf ( '--no-shrinkwrap' ) === - 1 ) {
125+ mgrOptions = mgrOptions . concat ( [ '--no-shrinkwrap' ] ) ;
100126 }
101- } else if ( mgrOptions . indexOf ( '--no-shrinkwrap' ) === - 1 ) {
102- mgrOptions = mgrOptions . concat ( [ '--no-shrinkwrap' ] ) ;
103127 }
104128
129+ debug ( 'Run npm/yarn install with options %s' , mgrOptions ) ;
130+
105131 return this . run ( cmd , [ ] . concat ( [ 'install' ] , mgrOptions ) , { cwd : this . cwd } ) . then ( ( ) => {
106132 if ( ! adapter . useYarnCommand ) {
107133 return adapter . run ( 'npm' , [ '--version' ] , { cwd : this . cwd , stdio : 'pipe' } ) . then ( ( res ) => {
@@ -171,6 +197,21 @@ module.exports = CoreObject.extend({
171197 path . join ( this . cwd , this . nodeModules ) , { clobber : true } ) ,
172198 ] ;
173199
200+ if ( fs . existsSync ( path . join ( this . cwd , this . yarnLockBackupFileName ) ) ) {
201+ restoreTasks . push ( copy ( path . join ( this . cwd , this . yarnLockBackupFileName ) ,
202+ path . join ( this . cwd , this . yarnLock ) ) ) ;
203+ }
204+
205+ if ( fs . existsSync ( path . join ( this . cwd , this . npmShrinkWrapBackupFileName ) ) ) {
206+ restoreTasks . push ( copy ( path . join ( this . cwd , this . npmShrinkWrapBackupFileName ) ,
207+ path . join ( this . cwd , this . npmShrinkWrap ) ) ) ;
208+ }
209+
210+ if ( fs . existsSync ( path . join ( this . cwd , this . packageLockBackupFileName ) ) ) {
211+ restoreTasks . push ( copy ( path . join ( this . cwd , this . packageLockBackupFileName ) ,
212+ path . join ( this . cwd , this . packageLock ) ) ) ;
213+ }
214+
174215 return RSVP . all ( restoreTasks ) ;
175216 } ,
176217 _backupOriginalDependencies ( ) {
@@ -184,6 +225,21 @@ module.exports = CoreObject.extend({
184225 copy ( path . join ( this . cwd , this . nodeModules ) ,
185226 path . join ( this . cwd , this . nodeModulesBackupLocation ) , { clobber : true } ) ] ;
186227
228+ if ( fs . existsSync ( path . join ( this . cwd , this . yarnLock ) ) ) {
229+ backupTasks . push ( copy ( path . join ( this . cwd , this . yarnLock ) ,
230+ path . join ( this . cwd , this . yarnLockBackupFileName ) ) ) ;
231+ }
232+
233+ if ( fs . existsSync ( path . join ( this . cwd , this . npmShrinkWrap ) ) ) {
234+ backupTasks . push ( copy ( path . join ( this . cwd , this . npmShrinkWrap ) ,
235+ path . join ( this . cwd , this . npmShrinkWrapBackupFileName ) ) ) ;
236+ }
237+
238+ if ( fs . existsSync ( path . join ( this . cwd , this . packageLock ) ) ) {
239+ backupTasks . push ( copy ( path . join ( this . cwd , this . packageLock ) ,
240+ path . join ( this . cwd , this . packageLockBackupFileName ) ) ) ;
241+ }
242+
187243 return RSVP . all ( backupTasks ) ;
188244 } ,
189245} ) ;
0 commit comments