import normalizePosixPath from 'normalize-path' ; import { transformDependencies } from '@kbn/pm' ; import { findUsedDependencies } from './find_used_dependencies' ; import { read , write , Task } from '../../lib' ; export const CreatePackageJson = { description : 'Creating build-ready version of package.json' , async run ( config , log , build ) { const pkg = config . getKibanaPkg ( ) ; const transformedDeps = transformDependencies ( pkg . dependencies as { [ key ] : string ; } ) ; const foundPkgDeps = await findUsedDependencies ( transformedDeps , normalizePosixPath ( build . resolvePath ( '.' ) ) ) ; const newPkg = { name : pkg . name , private : true , description : pkg . description , keywords : pkg . keywords , version : config . getBuildVersion ( ) , branch : pkg . branch , build : { number : config . getBuildNumber ( ) , sha : config . getBuildSha ( ) , distributable : true , release : config . isRelease , } , repository : pkg . repository , engines : { node : pkg . engines . node , } , resolutions : pkg . resolutions , dependencies : foundPkgDeps , } ; await write ( build . resolvePath ( 'package.json' ) , JSON . stringify ( newPkg , null , '  ' ) ) ; } , } ; export const RemovePackageJsonDeps = { description : 'Removing dependencies from package.json' , async run ( config , log , build ) { const path = build . resolvePath ( 'package.json' ) ; const pkg = JSON . parse ( await read ( path ) ) ; delete pkg . dependencies ; delete pkg . private ; delete pkg . resolutions ; await write ( build . resolvePath ( 'package.json' ) , JSON . stringify ( pkg , null , '  ' ) ) ; } , } ;