mirror of
https://github.com/r0adkll/sign-android-release
synced 2026-10-01 09:01:36 +00:00
bump jest and make tests pass
This commit is contained in:
1 parent
d28dc26fa3
commit
4f58d166b7
5769 files changed
+856618
-394571
No files matched your search
+52
-35
@@ -1,14 +1,9 @@
|
||||
'use strict';
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const pify = require('pify');
|
||||
const {promisify} = require('util');
|
||||
const semver = require('semver');
|
||||
|
||||
const defaults = {
|
||||
mode: 0o777 & (~process.umask()),
|
||||
fs
|
||||
};
|
||||
|
||||
const useNativeRecursiveOption = semver.satisfies(process.version, '>=10.12.0');
|
||||
|
||||
// https://github.com/nodejs/node/issues/8987
|
||||
@@ -25,6 +20,19 @@ const checkPath = pth => {
|
||||
}
|
||||
};
|
||||
|
||||
const processOptions = options => {
|
||||
// https://github.com/sindresorhus/make-dir/issues/18
|
||||
const defaults = {
|
||||
mode: 0o777,
|
||||
fs
|
||||
};
|
||||
|
||||
return {
|
||||
...defaults,
|
||||
...options
|
||||
};
|
||||
};
|
||||
|
||||
const permissionError = pth => {
|
||||
// This replicates the exception of `fs.mkdir` with native the
|
||||
// `recusive` option when run on an invalid drive under Windows.
|
||||
@@ -36,60 +44,69 @@ const permissionError = pth => {
|
||||
return error;
|
||||
};
|
||||
|
||||
const makeDir = (input, options) => Promise.resolve().then(() => {
|
||||
const makeDir = async (input, options) => {
|
||||
checkPath(input);
|
||||
options = Object.assign({}, defaults, options);
|
||||
options = processOptions(options);
|
||||
|
||||
// TODO: Use util.promisify when targeting Node.js 8
|
||||
const mkdir = pify(options.fs.mkdir);
|
||||
const stat = pify(options.fs.stat);
|
||||
const mkdir = promisify(options.fs.mkdir);
|
||||
const stat = promisify(options.fs.stat);
|
||||
|
||||
if (useNativeRecursiveOption && options.fs.mkdir === fs.mkdir) {
|
||||
const pth = path.resolve(input);
|
||||
|
||||
return mkdir(pth, {
|
||||
await mkdir(pth, {
|
||||
mode: options.mode,
|
||||
recursive: true
|
||||
}).then(() => pth);
|
||||
});
|
||||
|
||||
return pth;
|
||||
}
|
||||
|
||||
const make = pth => {
|
||||
return mkdir(pth, options.mode)
|
||||
.then(() => pth)
|
||||
.catch(error => {
|
||||
if (error.code === 'EPERM') {
|
||||
const make = async pth => {
|
||||
try {
|
||||
await mkdir(pth, options.mode);
|
||||
|
||||
return pth;
|
||||
} catch (error) {
|
||||
if (error.code === 'EPERM') {
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (error.code === 'ENOENT') {
|
||||
if (path.dirname(pth) === pth) {
|
||||
throw permissionError(pth);
|
||||
}
|
||||
|
||||
if (error.message.includes('null bytes')) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (error.code === 'ENOENT') {
|
||||
if (path.dirname(pth) === pth) {
|
||||
throw permissionError(pth);
|
||||
}
|
||||
await make(path.dirname(pth));
|
||||
|
||||
if (error.message.includes('null bytes')) {
|
||||
throw error;
|
||||
}
|
||||
return make(pth);
|
||||
}
|
||||
|
||||
return make(path.dirname(pth)).then(() => make(pth));
|
||||
try {
|
||||
const stats = await stat(pth);
|
||||
if (!stats.isDirectory()) {
|
||||
throw new Error('The path is not a directory');
|
||||
}
|
||||
} catch (_) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
return stat(pth)
|
||||
.then(stats => stats.isDirectory() ? pth : Promise.reject())
|
||||
.catch(() => {
|
||||
throw error;
|
||||
});
|
||||
});
|
||||
return pth;
|
||||
}
|
||||
};
|
||||
|
||||
return make(path.resolve(input));
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = makeDir;
|
||||
module.exports.default = makeDir;
|
||||
|
||||
module.exports.sync = (input, options) => {
|
||||
checkPath(input);
|
||||
options = Object.assign({}, defaults, options);
|
||||
options = processOptions(options);
|
||||
|
||||
if (useNativeRecursiveOption && options.fs.mkdirSync === fs.mkdirSync) {
|
||||
const pth = path.resolve(input);
|
||||
|
||||
Reference in new issue
Block a user