Skip to content

Commit 8eac0f7

Browse files
committed
Remove pify
1 parent 5691b35 commit 8eac0f7

File tree

3 files changed

+20
-26
lines changed

3 files changed

+20
-26
lines changed

index.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@ import decompressTargz from 'decompress-targz';
77
import decompressUnzip from 'decompress-unzip';
88
import fs from 'graceful-fs';
99
import makeDir from 'make-dir';
10-
import pify from 'pify';
1110
import stripDirs from 'strip-dirs';
1211

13-
const fsP = pify(fs);
14-
1512
const runPlugins = (input, options) => {
1613
if (options.plugins.length === 0) {
1714
return Promise.resolve([]);
@@ -21,7 +18,7 @@ const runPlugins = (input, options) => {
2118
return Promise.all(options.plugins.map(x => x(input, options))).then(files => files.reduce((a, b) => a.concat(b)));
2219
};
2320

24-
const safeMakeDir = (dir, realOutputPath) => fsP.realpath(dir)
21+
const safeMakeDir = (dir, realOutputPath) => fs.promises.realpath(dir)
2522
.catch(_ => {
2623
const parent = path.dirname(dir);
2724
return safeMakeDir(parent, realOutputPath);
@@ -31,10 +28,10 @@ const safeMakeDir = (dir, realOutputPath) => fsP.realpath(dir)
3128
throw new Error('Refusing to create a directory outside the output path.');
3229
}
3330

34-
return makeDir(dir).then(fsP.realpath);
31+
return makeDir(dir).then(fs.promises.realpath);
3532
});
3633

37-
const preventWritingThroughSymlink = (destination, realOutputPath) => fsP.readlink(destination)
34+
const preventWritingThroughSymlink = (destination, realOutputPath) => fs.promises.readlink(destination)
3835
// Either no file exists, or it's not a symlink. In either case, this is
3936
// not an escape we need to worry about in this phase.
4037
.catch(_ => null)
@@ -76,14 +73,14 @@ const extractFile = (input, output, options) => runPlugins(input, options).then(
7673

7774
if (x.type === 'directory') {
7875
return makeDir(output)
79-
.then(outputPath => fsP.realpath(outputPath))
76+
.then(outputPath => fs.promises.realpath(outputPath))
8077
.then(realOutputPath => safeMakeDir(dest, realOutputPath))
81-
.then(() => fsP.utimes(dest, now, x.mtime))
78+
.then(() => fs.promises.utimes(dest, now, x.mtime))
8279
.then(() => x);
8380
}
8481

8582
return makeDir(output)
86-
.then(outputPath => fsP.realpath(outputPath))
83+
.then(outputPath => fs.promises.realpath(outputPath))
8784
.then(realOutputPath =>
8885
// Attempt to ensure parent directory exists (failing if it's outside the output dir)
8986
safeMakeDir(path.dirname(dest), realOutputPath).then(() => realOutputPath),
@@ -95,28 +92,28 @@ const extractFile = (input, output, options) => runPlugins(input, options).then(
9592

9693
return realOutputPath;
9794
})
98-
.then(realOutputPath => fsP.realpath(path.dirname(dest))
95+
.then(realOutputPath => fs.promises.realpath(path.dirname(dest))
9996
.then(realDestinationDir => {
10097
if (realDestinationDir.indexOf(realOutputPath) !== 0) {
10198
throw new Error(`Refusing to write outside output directory: ${realDestinationDir}`);
10299
}
103100
}))
104101
.then(() => {
105102
if (x.type === 'link') {
106-
return fsP.link(x.linkname, dest);
103+
return fs.promises.link(x.linkname, dest);
107104
}
108105

109106
if (x.type === 'symlink' && process.platform === 'win32') {
110-
return fsP.link(x.linkname, dest);
107+
return fs.promises.link(x.linkname, dest);
111108
}
112109

113110
if (x.type === 'symlink') {
114-
return fsP.symlink(x.linkname, dest);
111+
return fs.promises.symlink(x.linkname, dest);
115112
}
116113

117-
return fsP.writeFile(dest, x.data, {mode});
114+
return fs.promises.writeFile(dest, x.data, {mode});
118115
})
119-
.then(() => x.type === 'file' && fsP.utimes(dest, now, x.mtime))
116+
.then(() => x.type === 'file' && fs.promises.utimes(dest, now, x.mtime))
120117
.then(() => x);
121118
}));
122119
});
@@ -141,7 +138,7 @@ const decompress = (input, output, options) => {
141138
...options,
142139
};
143140

144-
const read = typeof input === 'string' ? fsP.readFile(input) : Promise.resolve(input);
141+
const read = typeof input === 'string' ? fs.promises.readFile(input) : Promise.resolve(input);
145142

146143
return read.then(buf => extractFile(buf, output, options));
147144
};

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
"decompress-unzip": "^4.0.1",
4545
"graceful-fs": "^4.2.9",
4646
"make-dir": "^3.1.0",
47-
"pify": "^5.0.0",
4847
"strip-dirs": "^3.0.0"
4948
},
5049
"devDependencies": {

test.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
import fs from 'node:fs';
1+
import {promises as fs} from 'node:fs';
22
import path from 'node:path';
33
import {fileURLToPath} from 'node:url';
44
import {promisify} from 'node:util';
55
import isJpg from 'is-jpg';
66
import {pathExists} from 'path-exists';
7-
import pify from 'pify';
87
import rimraf from 'rimraf';
98
import test from 'ava';
109
import decompress from './index.js';
1110

12-
const fsP = pify(fs);
1311
const rimrafP = promisify(rimraf);
1412
const __dirname = path.dirname(fileURLToPath(import.meta.url));
1513

@@ -40,13 +38,13 @@ test('extract file', async t => {
4038
});
4139

4240
test('extract file using buffer', async t => {
43-
const tarBuf = await fsP.readFile(path.join(__dirname, 'fixtures', 'file.tar'));
41+
const tarBuf = await fs.readFile(path.join(__dirname, 'fixtures', 'file.tar'));
4442
const tarFiles = await decompress(tarBuf);
45-
const tarbzBuf = await fsP.readFile(path.join(__dirname, 'fixtures', 'file.tar.bz2'));
43+
const tarbzBuf = await fs.readFile(path.join(__dirname, 'fixtures', 'file.tar.bz2'));
4644
const tarbzFiles = await decompress(tarbzBuf);
47-
const targzBuf = await fsP.readFile(path.join(__dirname, 'fixtures', 'file.tar.gz'));
45+
const targzBuf = await fs.readFile(path.join(__dirname, 'fixtures', 'file.tar.gz'));
4846
const targzFiles = await decompress(targzBuf);
49-
const zipBuf = await fsP.readFile(path.join(__dirname, 'fixtures', 'file.zip'));
47+
const zipBuf = await fs.readFile(path.join(__dirname, 'fixtures', 'file.zip'));
5048
const zipFiles = await decompress(zipBuf);
5149

5250
t.is(tarFiles[0].path, 'test.jpg');
@@ -65,7 +63,7 @@ test.serial('extract file to directory', async t => {
6563

6664
test.serial('extract symlink', async t => {
6765
await decompress(path.join(__dirname, 'fixtures', 'symlink.tar'), __dirname, {strip: 1});
68-
t.is(await fsP.realpath(path.join(__dirname, 'symlink')), path.join(__dirname, 'file.txt'));
66+
t.is(await fs.realpath(path.join(__dirname, 'symlink')), path.join(__dirname, 'file.txt'));
6967
});
7068

7169
test.serial('extract directory', async t => {
@@ -104,7 +102,7 @@ test('map option', async t => {
104102

105103
test.serial('set mtime', async t => {
106104
const files = await decompress(path.join(__dirname, 'fixtures', 'file.tar'), __dirname);
107-
const stat = await fsP.stat(path.join(__dirname, 'test.jpg'));
105+
const stat = await fs.stat(path.join(__dirname, 'test.jpg'));
108106
t.deepEqual(files[0].mtime, stat.mtime);
109107
});
110108

0 commit comments

Comments
 (0)