mirror of
https://github.com/nodejs/node.git
synced 2025-05-01 08:42:45 +00:00

PR-URL: https://github.com/nodejs/node/pull/40865 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
35 lines
1.1 KiB
JavaScript
35 lines
1.1 KiB
JavaScript
const { relative } = require('path')
|
|
|
|
const npa = require('npm-package-arg')
|
|
const pkgContents = require('@npmcli/installed-package-contents')
|
|
const pacote = require('pacote')
|
|
const { tarCreateOptions } = pacote.DirFetcher
|
|
const tar = require('tar')
|
|
|
|
// returns a simplified tarball when reading files from node_modules folder,
|
|
// thus avoiding running the prepare scripts and the extra logic from packlist
|
|
const nodeModulesTarball = (manifest, opts) =>
|
|
pkgContents({ path: manifest._resolved, depth: 1 })
|
|
.then(files =>
|
|
files.map(file => relative(manifest._resolved, file))
|
|
)
|
|
.then(files =>
|
|
tar.c(tarCreateOptions(manifest), files).concat()
|
|
)
|
|
|
|
const tarball = (manifest, opts) => {
|
|
const resolved = manifest._resolved
|
|
const where = opts.where || process.cwd()
|
|
|
|
const fromNodeModules = npa(resolved).type === 'directory'
|
|
&& /node_modules[\\/](@[^\\/]+\/)?[^\\/]+[\\/]?$/.test(relative(where, resolved))
|
|
|
|
if (fromNodeModules) {
|
|
return nodeModulesTarball(manifest, opts)
|
|
}
|
|
|
|
return pacote.tarball(manifest._resolved, opts)
|
|
}
|
|
|
|
module.exports = tarball
|