Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions workspaces/libnpmpack/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const npa = require('npm-package-arg')
const runScript = require('@npmcli/run-script')
const path = require('node:path')
const Arborist = require('@npmcli/arborist')
const { writeFile } = require('node:fs/promises')

module.exports = pack
async function pack (spec = 'file:.', opts = {}) {
Expand All @@ -28,18 +27,24 @@ async function pack (spec = 'file:.', opts = {}) {
}

// packs tarball
const tarball = await pacote.tarball(manifest._resolved, {
...opts,
Arborist,
integrity: manifest._integrity,
})
let tarball

// check for explicit `false` so the default behavior is to skip writing to disk
if (opts.dryRun === false) {
const filename = `${manifest.name}-${manifest.version}.tgz`
.replace(/^@/, '').replace(/\//, '-')
const destination = path.resolve(opts.packDestination, filename)
await writeFile(destination, tarball)
tarball = await pacote.tarball.file(manifest._resolved, destination, {
...opts,
Arborist,
integrity: manifest._integrity,
})
} else {
tarball = await pacote.tarball(manifest._resolved, {
...opts,
Arborist,
integrity: manifest._integrity,
})
}

if (spec.type === 'directory' && !opts.ignoreScripts) {
Expand Down
1 change: 0 additions & 1 deletion workspaces/libnpmpack/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ t.test('writes tarball to file when dryRun === false', async t => {
t.ok(tarball)
const expectedTarball = path.join(testDir, 'my-cool-pkg-1.0.0.tgz')
t.ok(fs.existsSync(expectedTarball), 'file was written')
t.same(fs.readFileSync(expectedTarball), tarball, 'wrote same data that was returned')

const prepackTimestamp = (await fs.promises.stat(path.join(testDir, 'prepack'))).mtime
const tarballTimestamp = (await fs.promises.stat(expectedTarball)).mtime
Expand Down