diff --git a/package.json b/package.json index e9b5184b5c..99e520db03 100644 --- a/package.json +++ b/package.json @@ -37,14 +37,13 @@ "@types/cross-spawn": "^6.0.1", "@types/debug": "^4.1.5", "@types/diff": "^4.0.2", - "@types/find-parent-dir": "0.3.0", "@types/from2": "^2.3.0", "@types/fs-extra": "^8.1.0", "@types/fs-readdir-recursive": "1.0.0", "@types/gulp-if": "^0.0.33", "@types/jest": "^25.1.3", - "@types/mem-fs-editor": "^5.1.1", "@types/mem-fs": "^1.1.2", + "@types/mem-fs-editor": "^5.1.1", "@types/merge-stream": "^1.1.2", "@types/node": "^13.7.4", "@types/node-fetch": "^2.5.6", @@ -54,8 +53,8 @@ "@types/react": "16.9.34", "@types/readable-stream": "^2.3.5", "@types/through2": "^2.0.34", - "@types/vinyl-fs": "^2.4.11", "@types/vinyl": "^2.0.4", + "@types/vinyl-fs": "^2.4.11", "@wessberg/cjs-to-esm-transformer": "^0.0.19", "@wessberg/rollup-plugin-ts": "^1.2.24", "cpy-cli": "^3.1.0", @@ -72,12 +71,12 @@ "pretty-quick": "2.0.1", "prompt": "^1.0.0", "rimraf": "3.0.2", + "rollup": "^2.6.1", "rollup-plugin-commonjs": "^10.1.0", "rollup-plugin-json": "^4.0.0", "rollup-plugin-node-polyfills": "^0.2.1", "rollup-plugin-node-resolve": "^5.2.0", "rollup-plugin-peer-deps-external": "^2.2.2", - "rollup": "^2.6.1", "semver": "^7.3.2", "ts-jest": "24.3.0", "tsdx": "^0.13.1", diff --git a/packages/server/package.json b/packages/server/package.json index 7c932354fd..49d901d33e 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -33,7 +33,6 @@ "@types/pump": "^1.1.0", "cross-spawn": "^7.0.2", "fast-glob": "^3.2.2", - "find-parent-dir": "0.3.0", "from2": "^2.3.0", "gulp-if": "^3.0.0", "merge-stream": "^2.0.0", diff --git a/packages/server/src/resolve-bin-async.ts b/packages/server/src/resolve-bin-async.ts index 78d3e3d67d..5bd4f1e991 100644 --- a/packages/server/src/resolve-bin-async.ts +++ b/packages/server/src/resolve-bin-async.ts @@ -1,38 +1,16 @@ import resolveCwd from 'resolve-cwd' -import findParentDir from 'find-parent-dir' +import pkgDir from 'pkg-dir' import path from 'path' -// This code originally from https://github.com/thlorenz/resolve-bin -// It's inlined here because we need to use resolveCwd -function resolveBin(name: string, executable: string, cb: Function) { - var mod - try { - mod = resolveCwd(name) - } catch (err) { - return cb(err) - } +export async function resolveBinAsync(pkg: string, executable = pkg) { + const packageDir = await pkgDir(resolveCwd(pkg)) - findParentDir(mod, 'package.json', function (err, dir) { - if (err) return cb(err) + if (!packageDir) throw new Error(`Could not find package.json for '${pkg}'`) - var pack = require(path.join(dir as string, 'package.json')) - var binfield = pack.bin + const {bin} = require(path.join(packageDir, 'package.json')) + const binPath = typeof bin === 'object' ? bin[executable] : bin - var binpath = typeof binfield === 'object' ? binfield[executable] : binfield - if (!binpath) return cb(new Error('No bin `' + executable + '` in module `' + name + '`')) + if (!binPath) throw new Error(`No bin '${executable}' in module '${pkg}'`) - var bin = path.join(dir as string, binpath) - cb(null, bin) - }) -} - -export function resolveBinAsync(pkg: string, executable = pkg) { - return new Promise((resolve, reject) => { - resolveBin(pkg, executable, (err: any, bin: string) => { - if (err) { - reject(err) - } - resolve(bin) - }) - }) + return path.join(packageDir, binPath) } diff --git a/yarn.lock b/yarn.lock index c1d3667677..ac908c9c1a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2517,11 +2517,6 @@ resolved "https://registry.yarnpkg.com/@types/expect/-/expect-1.20.4.tgz#8288e51737bf7e3ab5d7c77bfa695883745264e5" integrity sha512-Q5Vn3yjTDyCMV50TB6VRIbQNxSE4OmZR86VSbGaNpfUolm0iePBB4KdEEHmxoY5sT2+2DIvXW0rvMDP2nHZ4Mg== -"@types/find-parent-dir@0.3.0": - version "0.3.0" - resolved "https://registry.yarnpkg.com/@types/find-parent-dir/-/find-parent-dir-0.3.0.tgz#0a8e9b1eb4fa77e6761d7a078daaed92ad2868f1" - integrity sha512-jz1cHlySrflg1Xf6fhy8xe/Bc//eO7wkg7OQePQei4vIYHm9IIQs0Ed8pakV6qVuihTnmy+Le+xUYDardq7yNg== - "@types/from2@^2.3.0": version "2.3.0" resolved "https://registry.yarnpkg.com/@types/from2/-/from2-2.3.0.tgz#5a3dd8d9db0363bc1ee6b98e0538fe0ae356ac3a" @@ -6293,11 +6288,6 @@ find-cache-dir@^2.1.0: make-dir "^2.0.0" pkg-dir "^3.0.0" -find-parent-dir@0.3.0: - version "0.3.0" - resolved "https://registry.yarnpkg.com/find-parent-dir/-/find-parent-dir-0.3.0.tgz#33c44b429ab2b2f0646299c5f9f718f376ff8d54" - integrity sha1-M8RLQpqysvBkYpnF+fcY83b/jVQ= - find-up@^1.0.0: version "1.1.2" resolved "https://registry.yarnpkg.com/find-up/-/find-up-1.1.2.tgz#6b2e9822b1a2ce0a60ab64d610eccad53cb24d0f"