This repository has been archived by the owner on Jul 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[added]
findBinary
function; switched Flow from a global prerequisi…
…te to a local `webcompiler` managed dependency - "flow-bin" (yay!)
- Loading branch information
Showing
13 changed files
with
344 additions
and
347 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
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
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
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
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,52 @@ | ||
/* @flow */ | ||
|
||
import type {ResultOrErrorCallback} from './typedef'; | ||
import {NativeProcess} from './NativeProcess'; | ||
import {stat} from 'fs'; | ||
import {join} from 'path'; | ||
|
||
const npm = new NativeProcess('npm'), | ||
cache = {}; | ||
|
||
/** | ||
* Finds the path to a project level binary, creates a {@link NativeProcess} for that binary, caches it for all | ||
* subsequent invocations, and provides it to the callback. | ||
* | ||
* @function findBinary | ||
* @param {string} name - the binary name | ||
* @param {ResultOrErrorCallback} callback - a callback function | ||
* @return {void} | ||
* @example | ||
* import {findBinary, logError} from 'webcompiler'; | ||
* // or - import {findBinary} from 'webcompiler/lib/findBinary'; | ||
* // or - var findBinary = require('webcompiler').findBinary; | ||
* // or - var findBinary = require('webcompiler/lib/findBinary').findBinary; | ||
* // import logError somehow | ||
* | ||
* findBinary('something', (error, binary) => { | ||
* if (error) { | ||
* return logError(error); | ||
* } | ||
* binary.run(() => { | ||
* // called the `something` binary from the local project level "node_modules/.bin" directory | ||
* }); | ||
* }); | ||
*/ | ||
export function findBinary(name: string, callback: ResultOrErrorCallback) { | ||
if (cache[name]) { | ||
return callback(null, cache[name]); | ||
} | ||
npm.run((stderr, stdout) => { | ||
if (stderr) { | ||
return callback(stderr); | ||
} | ||
const path = join(stdout.trimRight(), name); | ||
|
||
stat(path, statErr => { | ||
if (statErr) { | ||
return callback(statErr); | ||
} | ||
callback(null, cache[name] = new NativeProcess(path)); | ||
}); | ||
}, ['bin']); | ||
} |
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.