Skip to main content

Classes

NameDescription
PackageManagerWrapper class for executing commands for a given package manager

Functions

NameDescription
applyConfigOverrides(config, context)Normalize the config by applying any overrides for environments, commands, or local-only config file.
applyEnvironmentOverrides(gasketConfig, config, [localFile])Normalize the config by applying any environment or local overrides
installDependency(dependency, gasket)installDependency - install dependency
requireWithInstall(dependency, gasket)requireWithInstall - load devDependency request programmatically when needed
runShellCommand(cmd, [argv], [options], [debug])Promise friendly wrapper to running a shell command (eg: git, npm, ls) which passes back any { stdout, stderr } to the error thrown.
tryRequire(path)Tries to require a module, but ignores if it is not found. If not found, result will be null.
tryResolve(modulePath, options)

PackageManager

Wrapper class for executing commands for a given package manager

Kind: global class

new PackageManager(options)

ParamTypeDescription
optionsobjectOptions
[options.packageManager]stringName of manager, either npm (default) or yarn
options.deststringTarget directory where node_module should exist
[options.npmconfig]stringDEPRECATED Path to userconfig

packageManager.exec(cmd, args)

Executes npm in the application directory this.dest. This installation can be run multiple times.

Kind: instance method of PackageManager
Returns: Promise - promise
Access: public

ParamTypeDescription
cmdstringThe command that needs to be executed.
argsArray.<string>Additional CLI arguments to pass to npm.

packageManager.link(packages)

Executes npm link in the application directory this.dest.

Kind: instance method of PackageManager
Returns: Promise - promise
Access: public

ParamTypeDescription
packagesArray.<string>Explicit npm packages to link locally.

packageManager.install(args)

Executes npm install in the application directory this.dest. This installation can be run multiple times.

Kind: instance method of PackageManager
Returns: Promise - promise
Access: public

ParamTypeDescription
argsArray.<string>Additional CLI arguments to pass to npm.

packageManager.info(args)

Executes yarn or npm info, and returns parsed JSON data results.

Kind: instance method of PackageManager
Returns: Promise.<object> - stdout and data
Access: public

ParamTypeDescription
argsArray.<string>Additional CLI arguments to pass to npm.

PackageManager.spawnNpm(argv, spawnWith)

Executes the appropriate npm binary with the verbatim argv and spawnWith options provided. Passes appropriate debug flag for npm based on process.env.

Kind: static method of PackageManager
Returns: Promise - promise
Access: public

ParamTypeDescription
argvArray.<string>Precise CLI arguments to pass to npm.
spawnWithobjectOptions for child_process.spawn.

PackageManager.spawnYarn(argv, spawnWith)

Executes the appropriate yarn binary with the verbatim argv and spawnWith options provided. Passes appropriate debug flag for npm based on process.env.

Kind: static method of PackageManager
Returns: Promise - promise
Access: public

ParamTypeDescription
argvArray.<string>Precise CLI arguments to pass to npm.
spawnWithobjectOptions for child_process.spawn.

applyConfigOverrides(config, context)

Normalize the config by applying any overrides for environments, commands, or local-only config file.

Kind: global function
Returns: object - config

ParamTypeDescription
configobjectTarget config to be normalized
contextobjectContext for applying overrides
context.envstringName of environment
[context.commandId]stringName of command
[context.root]stringProject root; required if using localeFile
[context.localFile]stringOptional file to load relative to gasket root

applyEnvironmentOverrides(gasketConfig, config, [localFile])

Deprecated

Normalize the config by applying any environment or local overrides

Kind: global function
Returns: object - config

ParamTypeDescription
gasketConfigobjectGasket config
configobjectTarget config to be normalized
[localFile]stringOptional file to load relative to gasket root

installDependency(dependency, gasket)

installDependency - install dependency

Kind: global function

ParamTypeDescription
dependencystringThe dep/s needed
gasketGasketGasket instance

requireWithInstall(dependency, gasket)

requireWithInstall - load devDependency request programmatically when needed

Kind: global function
Returns: objectArray.<object> - module or list of modules

ParamTypeDescription
dependencystring | Array.<string>The require'ed dep/s needed
gasketGasketGasket instance

runShellCommand(cmd, [argv], [options], [debug])

Promise friendly wrapper to running a shell command (eg: git, npm, ls) which passes back any { stdout, stderr } to the error thrown.

Options can be passed to the underlying spawn. An additional signal option can be passed to use AbortController, allowing processes to be killed when no longer needed.

Kind: global function
Returns: Promise - A promise represents if command succeeds or fails.
Access: public

ParamTypeDescription
cmdstringBinary that is run
[argv]Array.<string>Arguments passed to npm binary through spawn.
[options]objectOptions passed to npm binary through spawn
[options.signal]objectAbortControl signal allowing process to be canceled
[debug]booleanWhen present pipes std{out,err} to process.*

Example

const { runShellCommand } = require('@gasket/utils');

async function helloWorld() {
await runShellCommand('echo', ['hello world']);
}

Example

// With timeout using AbortController

const { runShellCommand } = require('@gasket/utils');
const AbortController = require('abort-controller');

async function helloWorld() {
const controller = new AbortController();
// abort the process after 60 seconds
const id = setTimeout(() => controller.abort(), 60000);
await runShellCommand('long-process', ['something'], { signal: controller.signal });
clearTimeout(id);
}

tryRequire(path)

Tries to require a module, but ignores if it is not found. If not found, result will be null.

Kind: global function
Returns: object - module

ParamTypeDescription
pathstringModule to import

Example

const { tryRequire } = require('@gasket/utils');

let someConfig = tryRequire('../might/be/a/path/to/some/file');

if(!someConfig) {
someConfig = require('./default-config')
}

tryResolve(modulePath, options)

Kind: global function
Returns: string - module path

ParamTypeDescription
modulePathstringModule to import
optionsobjectPaths to search for the module