Skip to content

Commit

Permalink
fix: replace pify with simpler promise helpers (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
filipesilva authored and michael-ciniawsky committed Feb 8, 2018
1 parent d0e17a1 commit dadac24
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"is-glob": "^4.0.0",
"loader-utils": "^0.2.15",
"minimatch": "^3.0.4",
"pify": "^3.0.0",
"p-limit": "^1.0.0"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions src/preProcessPattern.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pify from 'pify';
import path from 'path';
import isGlob from 'is-glob';
import escape from './utils/escape';
import isObject from './utils/isObject';
import { stat } from './utils/promisify';

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

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

return pify(inputFileSystem).stat(pattern.absoluteFrom)
return stat(inputFileSystem, pattern.absoluteFrom)
.catch(() => {
// If from doesn't appear to be a glob, then log a warning
if (isGlob(pattern.from) || pattern.from.indexOf('*') !== -1) {
Expand Down
21 changes: 21 additions & 0 deletions src/utils/promisify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export const stat = (inputFileSystem, path) => {
return new Promise((resolve, reject) => {
inputFileSystem.stat(path, (err, stats) => {
if (err) {
reject(err);
}
resolve(stats);
});
});
}

export const readFile = (inputFileSystem, path) => {
return new Promise((resolve, reject) => {
inputFileSystem.readFile(path, (err, stats) => {
if (err) {
reject(err);
}
resolve(stats);
});
});
}
6 changes: 3 additions & 3 deletions src/writeFile.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import pify from 'pify';
import loaderUtils from 'loader-utils';
import path from 'path';
import cacache from 'cacache';
import serialize from 'serialize-javascript';
import { name, version } from '../package.json';
import findCacheDir from 'find-cache-dir';
import { stat, readFile } from './utils/promisify';

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

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

info(`reading ${file.absoluteFrom} to write to assets`);
return pify(inputFileSystem).readFile(file.absoluteFrom)
return readFile(inputFileSystem, file.absoluteFrom)
.then((content) => {
if (pattern.transform) {
const transform = (content, absoluteFrom) => {
Expand Down

0 comments on commit dadac24

Please sign in to comment.