@@ -5,6 +5,14 @@ import fs from 'fs-extra';
55
66const LOCAL_PACKAGE_PREFIX = 'file:' ;
77
8+ export async function npmPack ( pkgPath , workingDir ) {
9+ const { stdout } = await execa ( 'npm' , [ 'pack' , '--json' , pkgPath ] , {
10+ cwd : workingDir
11+ } ) ;
12+ const [ output ] = JSON . parse ( stdout ) ;
13+ return resolve ( workingDir , output . filename ) ;
14+ }
15+
816export function getPackageManagerCommand ( { cwd, options } ) {
917 if ( options . packageManager ) {
1018 const { packageManager } = options ;
@@ -34,12 +42,16 @@ export function getPackageManagerCommand ({ cwd, options }) {
3442
3543export async function createManifest ( tempdir , { cwd, manifest } ) {
3644 const updatedManifest = { ...manifest } ;
45+ const originalDeps = manifest . dependencies || { } ;
46+ updatedManifest . dependencies = { ...originalDeps } ;
3747
38- Object . keys ( manifest . dependencies ) . forEach ( ( pkgName ) => {
39- const pkgVersion = manifest . dependencies [ pkgName ] ;
48+ await Promise . all ( Object . keys ( originalDeps ) . map ( async ( pkgName ) => {
49+ const pkgVersion = originalDeps [ pkgName ] ;
4050 if ( ! pkgVersion . startsWith ( LOCAL_PACKAGE_PREFIX ) ) return ;
41- updatedManifest . dependencies [ pkgName ] = `${ LOCAL_PACKAGE_PREFIX } ${ resolve ( cwd , pkgVersion . slice ( LOCAL_PACKAGE_PREFIX . length ) ) } ` ;
42- } ) ;
51+ const absolutePath = resolve ( cwd , pkgVersion . slice ( LOCAL_PACKAGE_PREFIX . length ) ) ;
52+ const bundledAbsolutePath = await npmPack ( absolutePath , cwd ) ;
53+ updatedManifest . dependencies [ pkgName ] = `${ LOCAL_PACKAGE_PREFIX } ${ bundledAbsolutePath } ` ;
54+ } ) ) ;
4355
4456 await fs . writeFile ( resolve ( tempdir , 'package.json' ) , JSON . stringify ( updatedManifest , null , 2 ) ) ;
4557}
0 commit comments