@@ -2,16 +2,18 @@ const fs = require('fs');
22const path = require ( 'path' ) ;
33
44const root = path . resolve ( __dirname , '..' ) ;
5+ const packageDistPath = path . join ( root , 'package.json.dist' ) ;
56const packagePath = path . join ( root , 'package.json' ) ;
67const pluginRoot = path . resolve ( root , '../../..' ) ;
78const pluginPackagePath = path . join ( pluginRoot , 'tests' , 'TestApplication' , 'package.json' ) ;
89
9- if ( ! fs . existsSync ( pluginPackagePath ) ) {
10- process . exit ( 0 ) ;
11- }
10+ const pluginPackageExists = fs . existsSync ( pluginPackagePath ) ;
11+ const pluginPackage = pluginPackageExists
12+ ? JSON . parse ( fs . readFileSync ( pluginPackagePath , 'utf-8' ) )
13+ : { dependencies : { } , devDependencies : { } }
14+ ;
1215
13- const pluginPackage = JSON . parse ( fs . readFileSync ( pluginPackagePath , 'utf-8' ) ) ;
14- const rootPackage = JSON . parse ( fs . readFileSync ( packagePath , 'utf-8' ) ) ;
16+ const basePackage = JSON . parse ( fs . readFileSync ( packageDistPath , 'utf-8' ) ) ;
1517
1618function mergeDependencies ( target = { } , source = { } ) {
1719 const result = { ...target } ;
@@ -22,7 +24,10 @@ function mergeDependencies(target = {}, source = {}) {
2224 return result ;
2325}
2426
25- rootPackage . dependencies = mergeDependencies ( rootPackage . dependencies , pluginPackage . dependencies ) ;
26- rootPackage . devDependencies = mergeDependencies ( rootPackage . devDependencies , pluginPackage . devDependencies ) ;
27+ const finalPackage = {
28+ ...basePackage ,
29+ dependencies : mergeDependencies ( basePackage . dependencies , pluginPackage . dependencies ) ,
30+ devDependencies : mergeDependencies ( basePackage . devDependencies , pluginPackage . devDependencies ) ,
31+ } ;
2732
28- fs . writeFileSync ( packagePath , JSON . stringify ( rootPackage , null , 4 ) ) ;
33+ fs . writeFileSync ( packagePath , JSON . stringify ( finalPackage , null , 4 ) ) ;
0 commit comments