Skip to content

Commit dadac24

Browse files
filipesilvamichael-ciniawsky
authored andcommitted
fix: replace pify with simpler promise helpers (#221)
1 parent d0e17a1 commit dadac24

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"is-glob": "^4.0.0",
2929
"loader-utils": "^0.2.15",
3030
"minimatch": "^3.0.4",
31-
"pify": "^3.0.0",
3231
"p-limit": "^1.0.0"
3332
},
3433
"devDependencies": {

src/preProcessPattern.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import pify from 'pify';
21
import path from 'path';
32
import isGlob from 'is-glob';
43
import escape from './utils/escape';
54
import isObject from './utils/isObject';
5+
import { stat } from './utils/promisify';
66

77
// https://www.debuggex.com/r/VH2yS2mvJOitiyr3
88
const isTemplateLike = /(\[ext\])|(\[name\])|(\[path\])|(\[folder\])|(\[emoji(:\d+)?\])|(\[(\w+:)?hash(:\w+)?(:\d+)?\])|(\[\d+\])/;
@@ -58,7 +58,7 @@ export default function preProcessPattern(globalRef, pattern) {
5858

5959
debug(`determined '${pattern.from}' to be read from '${pattern.absoluteFrom}'`);
6060

61-
return pify(inputFileSystem).stat(pattern.absoluteFrom)
61+
return stat(inputFileSystem, pattern.absoluteFrom)
6262
.catch(() => {
6363
// If from doesn't appear to be a glob, then log a warning
6464
if (isGlob(pattern.from) || pattern.from.indexOf('*') !== -1) {

src/utils/promisify.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export const stat = (inputFileSystem, path) => {
2+
return new Promise((resolve, reject) => {
3+
inputFileSystem.stat(path, (err, stats) => {
4+
if (err) {
5+
reject(err);
6+
}
7+
resolve(stats);
8+
});
9+
});
10+
}
11+
12+
export const readFile = (inputFileSystem, path) => {
13+
return new Promise((resolve, reject) => {
14+
inputFileSystem.readFile(path, (err, stats) => {
15+
if (err) {
16+
reject(err);
17+
}
18+
resolve(stats);
19+
});
20+
});
21+
}

src/writeFile.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import pify from 'pify';
21
import loaderUtils from 'loader-utils';
32
import path from 'path';
43
import cacache from 'cacache';
54
import serialize from 'serialize-javascript';
65
import { name, version } from '../package.json';
76
import findCacheDir from 'find-cache-dir';
7+
import { stat, readFile } from './utils/promisify';
88

99
export default function writeFile(globalRef, pattern, file) {
1010
const {info, debug, compilation, fileDependencies, written, inputFileSystem, copyUnmodified} = globalRef;
1111

12-
return pify(inputFileSystem).stat(file.absoluteFrom)
12+
return stat(inputFileSystem, file.absoluteFrom)
1313
.then((stat) => {
1414
// We don't write empty directories
1515
if (stat.isDirectory()) {
@@ -22,7 +22,7 @@ export default function writeFile(globalRef, pattern, file) {
2222
}
2323

2424
info(`reading ${file.absoluteFrom} to write to assets`);
25-
return pify(inputFileSystem).readFile(file.absoluteFrom)
25+
return readFile(inputFileSystem, file.absoluteFrom)
2626
.then((content) => {
2727
if (pattern.transform) {
2828
const transform = (content, absoluteFrom) => {

0 commit comments

Comments
 (0)