diff --git a/.travis.yml b/.travis.yml index 57505cf..f09222f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ sudo: false language: node_js node_js: + - '12' + - '10' - '8' - - '6' - - '4' diff --git a/index.js b/index.js index 9193ebd..213ad06 100644 --- a/index.js +++ b/index.js @@ -54,6 +54,10 @@ const extractFile = (input, output, opts) => runPlugins(input, opts).then(files return makeDir(path.dirname(dest)) .then(() => { + if ((x.type === 'link' || x.type === 'symlink') && opts.symlinks === false) { + return; + } + if (x.type === 'link') { return fsP.link(x.linkname, dest); } @@ -83,12 +87,12 @@ module.exports = (input, output, opts) => { output = null; } - opts = Object.assign({plugins: [ + opts = {plugins: [ decompressTar(), decompressTarbz2(), decompressTargz(), decompressUnzip() - ]}, opts); + ], ...opts}; const read = typeof input === 'string' ? fsP.readFile(input) : Promise.resolve(input); diff --git a/package.json b/package.json index ff67270..4052dd1 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "url": "github.com/kevva" }, "engines": { - "node": ">=4" + "node": ">=7.6.0" }, "scripts": { "test": "xo && ava" @@ -35,15 +35,34 @@ "decompress-targz": "^4.0.0", "decompress-unzip": "^4.0.1", "graceful-fs": "^4.1.10", - "make-dir": "^1.0.0", - "pify": "^2.3.0", - "strip-dirs": "^2.0.0" + "make-dir": "^3.0.0", + "pify": "^4.0.1", + "strip-dirs": "^3.0.0" }, "devDependencies": { "ava": "*", - "is-jpg": "^1.0.0", - "path-exists": "^3.0.0", + "esm": "^3.2.25", + "is-jpg": "^2.0.0", + "path-exists": "^4.0.0", "pify": "^2.3.0", "xo": "*" + }, + "ava": { + "require": [ + "esm" + ] + }, + "xo": { + "rules": { + "promise/prefer-await-to-then": "warn" + }, + "overrides": [ + { + "files": "test.js", + "rules": { + "import/default": "ignore" + } + } + ] } } diff --git a/test.js b/test.js index d145ba0..2f28c62 100644 --- a/test.js +++ b/test.js @@ -50,7 +50,13 @@ test.serial('extract file to directory', async t => { await fsP.unlink(path.join(__dirname, 'test.jpg')); }); -test('extract symlink', async t => { +test.serial('extract without symlink', async t => { + await m(path.join(__dirname, 'fixtures', 'symlink.tar'), __dirname, {strip: 1, symlinks: false}); + t.false(fs.existsSync(path.join(__dirname, 'symlink'))); + await fsP.unlink(path.join(__dirname, 'file.txt')); +}); + +test.serial('extract symlink', async t => { await m(path.join(__dirname, 'fixtures', 'symlink.tar'), __dirname, {strip: 1}); t.is(await fsP.realpath(path.join(__dirname, 'symlink')), path.join(__dirname, 'file.txt')); await fsP.unlink(path.join(__dirname, 'symlink')); @@ -99,7 +105,7 @@ test.serial('set mtime', async t => { await fsP.unlink(path.join(__dirname, 'test.jpg')); }); -test('return emptpy array if no plugins are set', async t => { +test('return empty array if no plugins are set', async t => { const files = await m(path.join(__dirname, 'fixtures', 'file.tar'), {plugins: []}); t.is(files.length, 0); });