[kbn-pm] Use util.promisify instead of Bluebird (#16994) (#17062)

This commit is contained in:
Kim Joar Bekkelund 2018-03-09 16:00:32 +01:00 committed by GitHub
parent 3c646eb842
commit 939222e53a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 854 additions and 6684 deletions

File diff suppressed because one or more lines are too long

View file

@ -9,7 +9,6 @@
"prettier": "prettier --write './src/**/*.ts'"
},
"devDependencies": {
"@types/bluebird": "^3.5.20",
"@types/cmd-shim": "^2.0.0",
"@types/cpy": "^5.1.0",
"@types/dedent": "^0.7.0",
@ -24,7 +23,7 @@
"@types/lodash.clonedeepwith": "^4.5.3",
"@types/log-symbols": "^2.0.0",
"@types/mkdirp": "^0.5.2",
"@types/node": "^6.0.100",
"@types/node": "^8.9.4",
"@types/ora": "^1.3.1",
"@types/read-pkg": "^3.0.0",
"@types/strip-ansi": "^3.0.0",
@ -36,7 +35,6 @@
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.1",
"babel-preset-stage-3": "^6.24.1",
"bluebird": "^3.5.1",
"chalk": "^2.3.1",
"cmd-shim": "^2.0.2",
"cpy": "^6.0.0",

View file

@ -1,6 +1,6 @@
import fs from 'fs';
import { relative, dirname } from 'path';
import { promisify } from 'bluebird';
import { promisify } from 'util';
import cmdShimCb from 'cmd-shim';
import mkdirpCb from 'mkdirp';
@ -9,9 +9,10 @@ const readFile = promisify(fs.readFile);
const unlink = promisify(fs.unlink);
const symlink = promisify(fs.symlink);
const chmod = promisify(fs.chmod);
const cmdShim = promisify(cmdShimCb);
const cmdShim = promisify<string, string>(cmdShimCb);
const mkdirp = promisify(mkdirpCb);
export { chmod, readFile };
export { chmod, readFile, mkdirp };
async function statTest(path: string, block: (stats: fs.Stats) => boolean) {
try {
@ -24,29 +25,6 @@ async function statTest(path: string, block: (stats: fs.Stats) => boolean) {
}
}
/**
* Creates the specified directory including any necessary parent directories that don't yet exist.
* @param dir Directory to create.
* @param mode The mode that will be set for directories that need to be created.
* @return Path to he first directory that had to be created, if any.
*/
export function mkdirp(dir: string, mode?: string | number) {
// Custom wrapper around `mkdirp` to provide Promise-based interface. We don't use `promisify`
// function here since it can't automatically infer the right overload and we don't want to expose
// options format used by `mkdirp` directly.
return new Promise<string | null>((resolve, reject) => {
// If mode is provided we can pass it directly, otherwise we should specify empty `options` object.
const options = mode === undefined ? {} : mode;
mkdirpCb(dir, options, (err, args) => {
if (err) {
reject(err);
} else {
resolve(args);
}
});
});
}
/**
* Test if a path points to a directory.
* @param path

View file

@ -1,13 +1,11 @@
import _glob from 'glob';
import globSync from 'glob';
import path from 'path';
import { promisify } from 'bluebird';
import { promisify } from 'util';
import { CliError } from './errors';
import { Project } from './project';
// Correct overload version of _glob can't be inferred automatically so we
// should explicitly point to the right version with type parameters.
const glob = promisify<string[], string, _glob.IOptions>(_glob);
const glob = promisify(globSync);
export type ProjectMap = Map<string, Project>;
export type ProjectGraph = Map<string, Project[]>;

View file

@ -9,10 +9,6 @@
call-me-maybe "^1.0.1"
glob-to-regexp "^0.3.0"
"@types/bluebird@^3.5.20":
version "3.5.20"
resolved "https://registry.yarnpkg.com/@types/bluebird/-/bluebird-3.5.20.tgz#f6363172add6f4eabb8cada53ca9af2781e8d6a1"
"@types/cmd-shim@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@types/cmd-shim/-/cmd-shim-2.0.0.tgz#c3d81d3c2a51af3c65c19b4f1d493a75abf07a5c"
@ -106,9 +102,9 @@
version "9.4.6"
resolved "https://registry.yarnpkg.com/@types/node/-/node-9.4.6.tgz#d8176d864ee48753d053783e4e463aec86b8d82e"
"@types/node@^6.0.100":
version "6.0.101"
resolved "https://registry.yarnpkg.com/@types/node/-/node-6.0.101.tgz#0c5911cfb434af4a51c0a499931fe6423207d921"
"@types/node@^8.9.4":
version "8.9.4"
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.9.4.tgz#dfd327582a06c114eb6e0441fa3d6fab35edad48"
"@types/normalize-package-data@*":
version "2.4.0"
@ -864,10 +860,6 @@ block-stream@*:
dependencies:
inherits "~2.0.0"
bluebird@^3.5.1:
version "3.5.1"
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.1.tgz#d9551f9de98f1fcda1e683d17ee91a0602ee2eb9"
bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.4.0:
version "4.11.8"
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.8.tgz#2cde09eb5ee341f484746bb0309b3253b1b1442f"