Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2017-05-27 10:35:39 +0300
committerRebecca Turner <me@re-becca.org>2017-08-23 02:17:29 +0300
commit0195c0a8cdf816834c2f737372194ddc576c451d (patch)
tree056a49dd32d7e2ae12dada7690082253fd116f86
parent7ef0d282018cb82c8d4ebd5eeafd2a2be289d6f7 (diff)
pack: Use new tar
Credit: @isaacs Reviewed-By: @iarna PR-URL: https://github.com/npm/npm/pull/16804
-rw-r--r--lib/pack.js22
-rw-r--r--test/tap/bundled-dependencies.js11
-rw-r--r--test/tap/bundled-transitive-deps.js15
-rw-r--r--test/tap/files-and-ignores.js14
4 files changed, 36 insertions, 26 deletions
diff --git a/lib/pack.js b/lib/pack.js
index ae3bb260b..c42848203 100644
--- a/lib/pack.js
+++ b/lib/pack.js
@@ -26,8 +26,9 @@ const pipe = BB.promisify(require('mississippi').pipe)
const prepublishWarning = require('./utils/warn-deprecated')('prepublish-on-install')
const pinflight = require('promise-inflight')
const readJson = BB.promisify(require('read-package-json'))
-const tarPack = BB.promisify(require('./utils/tar').pack)
const writeStreamAtomic = require('fs-write-stream-atomic')
+const tar = require('tar')
+const packlist = require('npm-packlist')
pack.usage = 'npm pack [[<@scope>/]<pkg>...]'
@@ -118,11 +119,20 @@ function packDirectory (mani, dir, target) {
}).then((pkg) => {
return cacache.tmp.withTmp(npm.tmp, {tmpPrefix: 'packing'}, (tmp) => {
const tmpTarget = path.join(tmp, path.basename(target))
- return tarPack(tmpTarget, dir, pkg).then(() => {
- return move(tmpTarget, target, {Promise: BB, fs})
- }).then(() => {
- return lifecycle(pkg, 'postpack', dir)
- }).then(() => target)
+
+ const tarOpt = {
+ file: tmpTarget,
+ cwd: dir,
+ prefix: 'package/',
+ portable: true,
+ gzip: true
+ }
+
+ return packlist({ path: dir })
+ .then((files) => tar.create(tarOpt, files))
+ .then(() => move(tmpTarget, target, {Promise: BB, fs}))
+ .then(() => lifecycle(pkg, 'postpack', dir))
+ .then(() => target)
})
})
}
diff --git a/test/tap/bundled-dependencies.js b/test/tap/bundled-dependencies.js
index a49610e66..c6d67e3c5 100644
--- a/test/tap/bundled-dependencies.js
+++ b/test/tap/bundled-dependencies.js
@@ -6,7 +6,6 @@ var rimraf = require('rimraf')
var mkdirp = require('mkdirp')
var fs = require('graceful-fs')
var tar = require('tar')
-var zlib = require('zlib')
var basepath = path.resolve(__dirname, path.basename(__filename, '.js'))
var fixturepath = path.resolve(basepath, 'npm-test-bundled-deps')
var targetpath = path.resolve(basepath, 'target')
@@ -103,10 +102,8 @@ function withFixture (t, fixture, tester) {
function extractTarball (cb) {
// Unpack to disk so case-insensitive filesystems are consistent
- fs.createReadStream(path.join(basepath, 'npm-test-files-1.2.5.tgz'))
- .pipe(zlib.Unzip())
- .on('error', cb)
- .pipe(tar.Extract(targetpath))
- .on('error', cb)
- .on('end', function () { cb() })
+ tar.extract({
+ file: path.join(basepath, 'npm-test-files-1.2.5.tgz'),
+ cwd: targetpath
+ }).then(cb, cb)
}
diff --git a/test/tap/bundled-transitive-deps.js b/test/tap/bundled-transitive-deps.js
index 9af12337d..fe5914906 100644
--- a/test/tap/bundled-transitive-deps.js
+++ b/test/tap/bundled-transitive-deps.js
@@ -7,8 +7,8 @@ var File = Tacks.File
var Dir = Tacks.Dir
var common = require('../common-tap.js')
var npm = require('../../lib/npm.js')
-var tar = require('../../lib/utils/tar.js')
-
+var tar = require('tar')
+var mkdirp = require('mkdirp')
var testdir = path.join(__dirname, path.basename(__filename, '.js'))
var packed = path.join(testdir, 'packed')
@@ -87,10 +87,13 @@ test('bundled-transitive-deps', function (t) {
var tarball = stdout.trim()
t.comment(stderr.trim())
t.is(code, 0, 'pack successful')
- tar.unpack(path.join(testdir, tarball), packed, thenCheckContents)
- }
- function thenCheckContents (err) {
- t.ifError(err, 'unpack successful')
+ mkdirp.sync(packed)
+ tar.extract({
+ file: path.join(testdir, tarball),
+ cwd: packed,
+ strip: 1,
+ sync: true
+ })
var transitivePackedDep = path.join(packed, 'node_modules', 'b')
exists(t, transitivePackedDep)
var nestedScopedDep = path.join(packed, 'node_modules', '@c', 'd', 'node_modules', 'e')
diff --git a/test/tap/files-and-ignores.js b/test/tap/files-and-ignores.js
index 204d60e85..543120bac 100644
--- a/test/tap/files-and-ignores.js
+++ b/test/tap/files-and-ignores.js
@@ -6,7 +6,6 @@ var rimraf = require('rimraf')
var mkdirp = require('mkdirp')
var fs = require('graceful-fs')
var tar = require('tar')
-var zlib = require('zlib')
var basepath = path.resolve(__dirname, path.basename(__filename, '.js'))
var fixturepath = path.resolve(basepath, 'npm-test-files')
var targetpath = path.resolve(basepath, 'target')
@@ -609,10 +608,11 @@ function withFixture (t, fixture, tester) {
function extractTarball (cb) {
// Unpack to disk so case-insensitive filesystems are consistent
- fs.createReadStream(path.join(basepath, 'npm-test-files-1.2.5.tgz'))
- .pipe(zlib.Unzip())
- .on('error', cb)
- .pipe(tar.Extract(targetpath))
- .on('error', cb)
- .on('end', function () { cb() })
+ tar.extract({
+ file: basepath + '/npm-test-files-1.2.5.tgz',
+ cwd: targetpath,
+ sync: true
+ })
+
+ cb()
}