11// eslint-disable-next-line filenames/match-exported
22'use strict'
33
4- const { resolve } = require ( 'path' )
5- const { unlink, rename } = require ( 'fs' )
6- const { promisify } = require ( 'util' )
7-
8- const execa = require ( 'execa' )
9- const tar = require ( 'tar' )
10- const { remove } = require ( 'fs-extra' )
11-
12- const pUnlink = promisify ( unlink )
13- const pRename = promisify ( rename )
14-
154const { getPackageRoot } = require ( './root' )
165const { getTempDir, cleanTempDir } = require ( './temp' )
6+ const { unpack } = require ( './unpack' )
177const { addDevChecks } = require ( './dev_checks' )
188
199// Runs `npm pack` then unpack it to `opts.output`
@@ -27,11 +17,13 @@ const localpack = async function({ output } = {}) {
2717
2818 await unpack ( { packageRoot, tempDir, output : outputA } )
2919
30- await addDevChecks ( { output : outputA } )
31-
32- await cleanTempDir ( { tempDir } )
20+ await Promise . all ( [
21+ addDevChecks ( { output : outputA } ) ,
22+ cleanTempDir ( { tempDir } ) ,
23+ ] )
3324}
3425
26+ // Retrieve where package is unpacked
3527const getOutput = function ( {
3628 packageRoot,
3729 output = `${ packageRoot } /${ DEFAULT_OUTPUT } ` ,
@@ -41,28 +33,4 @@ const getOutput = function({
4133
4234const DEFAULT_OUTPUT = 'localpack'
4335
44- // Runs `npm pack` and unpack it to `output`
45- const unpack = async function ( { packageRoot, tempDir, output } ) {
46- // We use `npm pack` instead of `require('./npm/lib/pack')`:
47- // - to use the same `npm` version as the one globally installed,
48- // so it mirrors what will be published
49- // - to make code less likely to change with npm internal changes
50- // However this means this next line is 4 times slower (because it creates
51- // a new process)
52- const { stdout } = await execa . shell (
53- `npm pack --silent --no-update-notifier ${ packageRoot } ` ,
54- { stderr : 'inherit' , cwd : tempDir } ,
55- )
56- const tarball = resolve ( tempDir , stdout )
57-
58- await tar . x ( { file : tarball , cwd : tempDir } )
59-
60- await pUnlink ( tarball )
61-
62- // Is silent when `output` does not exist
63- await remove ( output )
64-
65- await pRename ( `${ tempDir } /package` , output )
66- }
67-
6836module . exports = localpack
0 commit comments