-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove `readable-stream` (only needed for `v0.10`) * Remove `mkdirp` `'EEXIST'` checks * Remove `rewire` in favor of `clear-require` and `require-uncached` Closes: #13
- Loading branch information
1 parent
2ec76c4
commit 36349c8
Showing
9 changed files
with
387 additions
and
333 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict'; | ||
const NestedError = require('nested-error-stacks'); | ||
|
||
class CpFileError extends NestedError { | ||
constructor(message, nested) { | ||
super(message, nested); | ||
Object.assign(this, nested); | ||
this.name = 'CpFileError'; | ||
} | ||
} | ||
|
||
module.exports = CpFileError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
'use strict'; | ||
const fs = require('graceful-fs'); | ||
const mkdirp = require('mkdirp'); | ||
const pify = require('pify'); | ||
const CpFileError = require('./cp-file-error'); | ||
|
||
const fsP = pify(fs); | ||
const mkdirpP = pify(mkdirp); | ||
|
||
exports.closeSync = fs.closeSync.bind(fs); | ||
exports.createWriteStream = fs.createWriteStream.bind(fs); | ||
|
||
exports.createReadStream = (path, options) => new Promise((resolve, reject) => { | ||
const read = fs.createReadStream(path, options); | ||
|
||
read.on('error', err => { | ||
reject(new CpFileError(`cannot read from \`${path}\`: ${err.message}`, err)); | ||
}); | ||
|
||
read.on('readable', () => { | ||
resolve(read); | ||
}); | ||
|
||
read.on('end', () => { | ||
resolve(read); | ||
}); | ||
}); | ||
|
||
exports.stat = path => fsP.stat(path).catch(err => { | ||
throw new CpFileError(`cannot stat path \`${path}\`: ${err.message}`, err); | ||
}); | ||
|
||
exports.lstat = path => fsP.lstat(path).catch(err => { | ||
throw new CpFileError(`lstat \`${path}\` failed: ${err.message}`, err); | ||
}); | ||
|
||
exports.utimes = (path, atime, mtime) => fsP.utimes(path, atime, mtime).catch(err => { | ||
throw new CpFileError(`utimes \`${path}\` failed: ${err.message}`, err); | ||
}); | ||
|
||
exports.openSync = (path, flags, mode) => { | ||
try { | ||
return fs.openSync(path, flags, mode); | ||
} catch (err) { | ||
if (flags.includes('w')) { | ||
throw new CpFileError(`cannot write to \`${path}\`: ${err.message}`, err); | ||
} | ||
|
||
throw new CpFileError(`cannot open \`${path}\`: ${err.message}`, err); | ||
} | ||
}; | ||
|
||
// eslint-disable-next-line max-params | ||
exports.readSync = (fd, buffer, offset, length, position, path) => { | ||
try { | ||
return fs.readSync(fd, buffer, offset, length, position); | ||
} catch (err) { | ||
throw new CpFileError(`cannot read from \`${path}\`: ${err.message}`, err); | ||
} | ||
}; | ||
|
||
// eslint-disable-next-line max-params | ||
exports.writeSync = (fd, buffer, offset, length, position, path) => { | ||
try { | ||
return fs.writeSync(fd, buffer, offset, length, position); | ||
} catch (err) { | ||
throw new CpFileError(`cannot write to \`${path}\`: ${err.message}`, err); | ||
} | ||
}; | ||
|
||
exports.fstatSync = (fd, path) => { | ||
try { | ||
return fs.fstatSync(fd); | ||
} catch (err) { | ||
throw new CpFileError(`stat \`${path}\` failed: ${err.message}`, err); | ||
} | ||
}; | ||
|
||
exports.futimesSync = (fd, atime, mtime, path) => { | ||
try { | ||
return fs.futimesSync(fd, atime, mtime, path); | ||
} catch (err) { | ||
throw new CpFileError(`utimes \`${path}\` failed: ${err.message}`, err); | ||
} | ||
}; | ||
|
||
exports.mkdirp = path => mkdirpP(path, {fs}).catch(err => { | ||
throw new CpFileError(`cannot create directory \`${path}\`: ${err.message}`, err); | ||
}); | ||
|
||
exports.mkdirpSync = path => { | ||
try { | ||
mkdirp.sync(path, {fs}); | ||
} catch (err) { | ||
throw new CpFileError(`cannot create directory \`${path}\`: ${err.message}`, err); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.