@@ -24,46 +24,36 @@ export class PackEnumerator extends PackageEnumerator {
24
24
}
25
25
26
26
protected async processPackage ( packagePath : string , packageJson : any , packages : PackagesType ) : Promise < void > {
27
+ console . log ( "blerf: packing and patching" , packageJson . name ) ;
27
28
childProcess . execSync ( "npm pack" , { stdio : 'inherit' , cwd : packagePath } ) ;
28
29
29
- console . log ( "blerf: patching project references" ) ;
30
-
31
- // NOTE: assuming file name of tarball; can also get it from the output of npm pack
32
30
const sourcePackageTarPath = path . join ( packagePath , packageJson . name + "-" + packageJson . version + ".tgz" ) ;
33
31
const tempPath = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "blerf-" ) ) ;
34
-
35
32
const artifactPackTarPath = path . join ( this . artifactPackPath , packageJson . name + "-" + packageJson . version + ".tgz" ) ;
36
33
37
34
fs . mkdirSync ( this . artifactPackPath , { recursive : true } ) ;
38
35
39
36
try {
40
37
tar . extract ( { file : sourcePackageTarPath , cwd : tempPath , sync : true } ) ;
41
- this . patchPackageJson ( packagePath , path . join ( tempPath , "package" , "package.json" ) , path . resolve ( this . artifactPackPath ) , packages ) ;
38
+
39
+ const packageJsonPath = path . join ( tempPath , "package" , "package.json" ) ;
40
+ const packageJson = this . readPackageJson ( packageJsonPath ) ;
42
41
if ( this . isDeploy ) {
42
+ const artifactPackFullPath = path . resolve ( this . artifactPackPath ) ;
43
+ this . rewriteProjectReferencesFullPathVersion ( artifactPackFullPath , packageJson . dependencies , packages ) ;
44
+ this . rewriteProjectReferencesFullPathVersion ( artifactPackFullPath , packageJson . devDependencies , packages ) ;
43
45
fs . copyFileSync ( path . join ( packagePath , "package-lock.json" ) , path . join ( tempPath , "package" , "package-lock.json" ) ) ;
46
+ } else {
47
+ this . rewriteProjectReferencesVersion ( packageJson . dependencies , packages ) ;
48
+ this . rewriteProjectReferencesVersion ( packageJson . devDependencies , packages ) ;
44
49
}
50
+
51
+ this . trimPackageJson ( packageJson ) ;
52
+ fs . writeFileSync ( packageJsonPath , stringifyPackage ( packageJson ) , 'utf8' ) ;
45
53
tar . create ( { file : artifactPackTarPath , cwd : tempPath , gzip : true , sync : true , } , [ "package" ] ) ;
46
54
} finally {
47
55
fs . unlinkSync ( sourcePackageTarPath ) ;
48
56
this . rimraf ( tempPath ) ;
49
57
}
50
58
}
51
-
52
- private patchPackageJson ( packagePath : string , packageJsonPath : string , artifactPackFullPath : string , packages : PackagesType ) {
53
- // Resolve all file:-based dependencies to explicit versions
54
- const packageJson = this . readPackageJson ( packageJsonPath ) ;
55
- if ( this . isDeploy ) {
56
- this . rewriteProjectReferencesFullPathVersion ( artifactPackFullPath , packageJson . dependencies , packages ) ;
57
- this . rewriteProjectReferencesFullPathVersion ( artifactPackFullPath , packageJson . devDependencies , packages ) ;
58
- } else {
59
- this . rewriteProjectReferencesVersion ( packageJson . dependencies , packages ) ;
60
- this . rewriteProjectReferencesVersion ( packageJson . devDependencies , packages ) ;
61
- }
62
-
63
- // Remove stuff not needed in "binary" packge
64
- delete packageJson . scripts ;
65
- delete packageJson . blerf ;
66
- delete packageJson . devDependencies ;
67
- fs . writeFileSync ( packageJsonPath , stringifyPackage ( packageJson ) , 'utf8' ) ;
68
- }
69
59
}
0 commit comments