-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Refactor library to use smaller modules (#91)
- Loading branch information
1 parent
c3e6239
commit d58a3ed
Showing
15 changed files
with
433 additions
and
311 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
|
||
const util = require('util'); | ||
|
||
/** | ||
* Boolean indicating if debug mode is enabled. | ||
* | ||
* @type {boolean} | ||
*/ | ||
const IS_DEBUG = process.env.SPAWN_WRAP_DEBUG === '1' | ||
|
||
/** | ||
* If debug is enabled, write message to stderr. | ||
* | ||
* If debug is disabled, no message is written. | ||
*/ | ||
function debug(...args) { | ||
if (!IS_DEBUG) { | ||
return; | ||
} | ||
const prefix = 'SW ' + process.pid + ': ' | ||
const data = util.format.apply(util, ...args).trim() | ||
const message = prefix + data.split('\n').join('\n' + prefix) | ||
process.stderr.write(message + '\n') | ||
} | ||
|
||
module.exports = { | ||
IS_DEBUG, | ||
debug, | ||
} |
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,31 @@ | ||
'use strict'; | ||
|
||
const isWindows = require("is-windows") | ||
const path = require("path") | ||
|
||
function isCmd(file) { | ||
const comspec = path.basename(process.env.comspec || '').replace(/\.exe$/i, '') | ||
return isWindows() && (file === comspec || /^cmd(?:\.exe)?$/i.test(file)) | ||
} | ||
|
||
function isNode(file) { | ||
const cmdname = path.basename(process.execPath).replace(/\.exe$/i, '') | ||
return file === 'node' || cmdname === file | ||
} | ||
|
||
function isNpm(file) { | ||
// XXX is this even possible/necessary? | ||
// wouldn't npm just be detected as a node shebang? | ||
return file === 'npm' && !isWindows() | ||
} | ||
|
||
function isSh(file) { | ||
return ['dash', 'sh', 'bash', 'zsh'].includes(file) | ||
} | ||
|
||
module.exports = { | ||
isCmd, | ||
isNode, | ||
isNpm, | ||
isSh, | ||
} |
Oops, something went wrong.