33
44import * as colors from 'colors' ;
55import * as os from 'os' ;
6+ import * as path from 'path' ;
67import * as fsx from 'fs-extra' ;
78import { CommandLineFlagParameter } from '@microsoft/ts-command-line' ;
89
910import Utilities from '../../utilities/Utilities' ;
1011import { Stopwatch } from '../../utilities/Stopwatch' ;
1112import InstallManager , { InstallType } from '../utilities/InstallManager' ;
12- import LinkManager from '../utilities/LinkManager' ;
13+ import { LinkManagerFactory } from '../utilities/LinkManagerFactory' ;
14+ import { BaseLinkManager } from '../utilities/base/BaseLinkManager' ;
1315import RushCommandLineParser from './RushCommandLineParser' ;
1416import { ApprovedPackagesChecker } from '../utilities/ApprovedPackagesChecker' ;
15- import ShrinkwrapFile from '../utilities/ShrinkwrapFile' ;
17+ import { BaseShrinkwrapFile } from '../utilities/base/BaseShrinkwrapFile' ;
18+ import { ShrinkwrapFileFactory } from '../utilities/ShrinkwrapFileFactory' ;
1619import { BaseRushAction } from './BaseRushAction' ;
1720
1821export default class GenerateAction extends BaseRushAction {
@@ -65,9 +68,13 @@ export default class GenerateAction extends BaseRushAction {
6568
6669 const installManager : InstallManager = new InstallManager ( this . rushConfiguration ) ;
6770
71+ const committedShrinkwrapFilename : string = this . rushConfiguration . committedShrinkwrapFilename ;
72+ const tempShrinkwrapFilename : string = this . rushConfiguration . tempShrinkwrapFilename ;
73+
6874 try {
69- const shrinkwrapFile : ShrinkwrapFile | undefined
70- = ShrinkwrapFile . loadFromFile ( this . rushConfiguration . committedShrinkwrapFilename ) ;
75+ const shrinkwrapFile : BaseShrinkwrapFile | undefined = ShrinkwrapFileFactory . getShrinkwrapFile (
76+ this . rushConfiguration . packageManager ,
77+ this . rushConfiguration . committedShrinkwrapFilename ) ;
7178
7279 if ( shrinkwrapFile
7380 && ! this . _forceParameter . value
@@ -84,17 +91,17 @@ export default class GenerateAction extends BaseRushAction {
8491 console . log ( 'There was a problem reading the shrinkwrap file. Proceeeding with "rush generate".' ) ;
8592 }
8693
87- installManager . ensureLocalNpmTool ( false ) ;
94+ installManager . ensureLocalPackageManager ( false ) ;
8895
8996 installManager . createTempModules ( true ) ;
9097
9198 // Delete both copies of the shrinkwrap file
92- if ( fsx . existsSync ( this . rushConfiguration . committedShrinkwrapFilename ) ) {
93- console . log ( os . EOL + 'Deleting ' + this . rushConfiguration . committedShrinkwrapFilename ) ;
94- fsx . unlinkSync ( this . rushConfiguration . committedShrinkwrapFilename ) ;
99+ if ( fsx . existsSync ( committedShrinkwrapFilename ) ) {
100+ console . log ( os . EOL + 'Deleting ' + committedShrinkwrapFilename ) ;
101+ fsx . unlinkSync ( committedShrinkwrapFilename ) ;
95102 }
96- if ( fsx . existsSync ( this . rushConfiguration . tempShrinkwrapFilename ) ) {
97- fsx . unlinkSync ( this . rushConfiguration . tempShrinkwrapFilename ) ;
103+ if ( fsx . existsSync ( tempShrinkwrapFilename ) ) {
104+ fsx . unlinkSync ( tempShrinkwrapFilename ) ;
98105 }
99106
100107 if ( isLazy ) {
@@ -106,19 +113,25 @@ export default class GenerateAction extends BaseRushAction {
106113 installManager . installCommonModules ( InstallType . Normal ) ;
107114
108115 console . log ( os . EOL + colors . bold ( '(Skipping "npm shrinkwrap")' ) + os . EOL ) ;
116+ const packageLogFilePath : string = path . join ( this . rushConfiguration . commonTempFolder , 'package.lock' ) ;
117+
118+ if ( fsx . existsSync ( packageLogFilePath ) ) {
119+ console . log ( 'Removing NPM5\'s "package.lock" file' ) ;
120+ fsx . removeSync ( packageLogFilePath ) ;
121+ }
109122 } else {
110123 // Do a clean install
111124 installManager . installCommonModules ( InstallType . ForceClean ) ;
112125
113126 console . log ( os . EOL + colors . bold ( 'Running "npm shrinkwrap"...' ) ) ;
114- const npmArgs : string [ ] = [ 'shrinkwrap' ] ;
115- installManager . pushConfigurationNpmArgs ( npmArgs ) ;
116- Utilities . executeCommand ( this . rushConfiguration . npmToolFilename ,
127+ const npmArgs : string [ ] = [ 'shrinkwrap' ] ;
128+ installManager . pushConfigurationArgs ( npmArgs ) ;
129+ Utilities . executeCommand ( this . rushConfiguration . packageManagerToolFilename ,
117130 npmArgs , this . rushConfiguration . commonTempFolder ) ;
118131 console . log ( '"npm shrinkwrap" completed' + os . EOL ) ;
119132
120133 // Copy (or delete) common\temp\npm-shrinkwrap.json --> common\npm-shrinkwrap.json
121- installManager . syncFile ( this . rushConfiguration . tempShrinkwrapFilename ,
134+ installManager . syncFile ( tempShrinkwrapFilename ,
122135 this . rushConfiguration . committedShrinkwrapFilename ) ;
123136
124137 // The flag file is normally created by installCommonModules(), but "rush install" will
@@ -138,7 +151,8 @@ export default class GenerateAction extends BaseRushAction {
138151 console . log ( os . EOL + colors . green ( `Rush generate finished successfully. (${ stopwatch . toString ( ) } )` ) ) ;
139152
140153 if ( ! this . _noLinkParameter . value ) {
141- const linkManager : LinkManager = new LinkManager ( this . rushConfiguration ) ;
154+ const linkManager : BaseLinkManager =
155+ LinkManagerFactory . getLinkManager ( this . rushConfiguration ) ;
142156 // NOTE: Setting force=true here shouldn't be strictly necessary, since installCommonModules()
143157 // above should have already deleted the marker file, but it doesn't hurt to be explicit.
144158 this . _parser . catchSyncErrors ( linkManager . createSymlinksForProjects ( true ) ) ;
0 commit comments