@gasket/utils
Advanced tools
Comparing version 6.47.0 to 7.0.0-7.0.1-canary.11.0
@@ -13,6 +13,3 @@ | ||
[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. | ||
[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. | ||
@@ -48,3 +45,2 @@ [tryResolve(modulePath, options)] | | ||
| options.dest | `string` | Target directory where `node_module` should exist | | ||
| \[options.npmconfig\] | `string` | DEPRECATED Path to userconfig | | ||
@@ -153,51 +149,8 @@ | ||
| \[context.commandId\] | `string` | Name of command | | ||
| \[context.root\] | `string` | Project root; required if using localeFile | | ||
| \[context.localFile\] | `string` | Optional 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 | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| gasketConfig | `object` | Gasket config | | ||
| config | `object` | Target config to be normalized | | ||
| \[localFile\] | `string` | Optional file to load relative to gasket root | | ||
## installDependency(dependency, gasket) | ||
installDependency - install dependency | ||
**Kind**: global function | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| dependency | `string` | The dep/s needed | | ||
| gasket | `Gasket` | Gasket instance | | ||
## requireWithInstall(dependency, gasket) | ||
requireWithInstall - load devDependency request programmatically when needed | ||
**Kind**: global function | ||
**Returns**: `object` ⎮ `Array.<object>` - module or list of modules | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| dependency | `string` \| `Array.<string>` | The require'ed dep/s needed | | ||
| gasket | `Gasket` | Gasket 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. | ||
which passes back any { stdout, stderr } to the error thrown. | ||
@@ -218,3 +171,3 @@ Options can be passed to the underlying spawn. An additional `signal` option | ||
| \[options.signal\] | `object` | AbortControl signal allowing process to be canceled | | ||
| \[debug\] | `boolean` | When present pipes `std{out,err}` to process.* | | ||
| \[debug\] | `boolean` | When present pipes std{out,err} to process.* | | ||
@@ -283,5 +236,2 @@ **Example** | ||
[applyConfigOverrides(config, context)]:#applyconfigoverridesconfig-context | ||
[applyEnvironmentOverrides(gasketConfig, config, \[localFile\])]:#applyenvironmentoverridesgasketconfig-config-localfile | ||
[installDependency(dependency, gasket)]:#installdependencydependency-gasket | ||
[requireWithInstall(dependency, gasket)]:#requirewithinstalldependency-gasket | ||
[runShellCommand(cmd, \[argv\], \[options\], \[debug\])]:#runshellcommandcmd-argv-options-debug | ||
@@ -288,0 +238,0 @@ [tryRequire(path)]:#tryrequirepath |
@@ -1,4 +0,2 @@ | ||
const path = require('path'); | ||
const defaultsDeep = require('lodash.defaultsdeep'); | ||
const tryRequire = require('./try-require'); | ||
const debug = require('diagnostics')('gasket:utils'); | ||
@@ -13,7 +11,7 @@ | ||
config, | ||
{ env = '', commandId, root, localFile } | ||
{ env = '', commandId } | ||
) { | ||
return defaultsDeep( | ||
{}, | ||
...getPotentialConfigs({ config, env, commandId, root, localFile }) | ||
...getPotentialConfigs(config, { env, commandId }) | ||
); | ||
@@ -26,8 +24,7 @@ } | ||
*/ | ||
function *getPotentialConfigs({ config, env, commandId, root, localFile }) { | ||
// Separate environment-specific config from other config | ||
function *getPotentialConfigs(config, { env, commandId }) { | ||
// Separate environment-specific config from another config | ||
const { environments = {}, commands = {}, ...baseConfig } = config; | ||
const isLocalEnv = env === 'local'; | ||
yield* getLocalOverrides(isLocalEnv, root, localFile); | ||
yield* getCommandOverrides(commands, commandId); | ||
@@ -39,25 +36,2 @@ yield* getSubEnvironmentOverrides(env, environments); | ||
/** | ||
* Generator function to yield local overrides | ||
* @param {boolean} isLocalEnv - Is the environment local | ||
* @param {string} root - Root directory | ||
* @param {string} localFile - Local config file | ||
* @yields {object} - Local overrides | ||
*/ | ||
function *getLocalOverrides(isLocalEnv, root, localFile) { | ||
// For git-ignorable changes, merge in optional `.local` file | ||
const localOverrides = | ||
isLocalEnv && localFile && tryRequire(path.join(root, localFile)); | ||
if (localOverrides) { | ||
debug('Including local config file for overrides', localFile); | ||
yield localOverrides; | ||
} | ||
} | ||
/** | ||
* Generator function to yield command overrides | ||
* @param {object} commands - Commands object | ||
* @param {string} commandId - Command ID | ||
* @yields {object} - Command overrides | ||
*/ | ||
function *getCommandOverrides(commands, commandId) { | ||
@@ -64,0 +38,0 @@ const commandOverrides = commandId && commands[commandId]; |
@@ -1,10 +0,3 @@ | ||
import type { GasketConfig } from '@gasket/engine'; | ||
import type { MaybeAsync } from '@gasket/core'; | ||
declare module '@gasket/engine' { | ||
export interface GasketConfig { | ||
environments?: string; | ||
commands?: string; | ||
} | ||
} | ||
interface PackageManagerOptions { | ||
@@ -15,4 +8,2 @@ /** Name of manager, either `npm` (default) or `yarn` */ | ||
dest: string; | ||
/** @deprecated Path to userconfig */ | ||
npmconfig?: string; | ||
} | ||
@@ -30,4 +21,2 @@ | ||
dest: string; | ||
/** @deprecated Path to userconfig */ | ||
npmconfig: string; | ||
@@ -69,16 +58,2 @@ /** | ||
/** | ||
* Tries to require a module, but ignores if it is not found. If not found, | ||
* result will be null. | ||
* @example | ||
* const { tryRequire } = require('@gasket/utils'); | ||
* | ||
* let someConfig = tryRequire('../might/be/a/path/to/some/file'); | ||
* | ||
* if(!someConfig) { | ||
* someConfig = require('./default-config') | ||
* } | ||
*/ | ||
export function tryRequire(path: string): object | null; | ||
interface ConfigContext { | ||
@@ -90,36 +65,20 @@ /** Name of environment */ | ||
/** Project root; required if using localeFile */ | ||
root?: string; | ||
/** Optional file to load relative to gasket root */ | ||
localFile?: string; | ||
} | ||
interface ConfigDefinition extends Record<string, any> { | ||
environments?: Record<string, Partial<ConfigDefinition>> | ||
commands?: Record<string, Partial<ConfigDefinition>> | ||
[key: string]: any | ||
} | ||
type ConfigOutput = Omit<ConfigDefinition, 'environments' | 'commands'> | ||
/** | ||
* Normalize the config by applying any overrides for environments, commands, or local-only config file. | ||
*/ | ||
export function applyConfigOverrides( | ||
config: GasketConfig, | ||
export function applyConfigOverrides<Def extends ConfigDefinition, Out extends ConfigOutput>( | ||
config: Def, | ||
configContext: ConfigContext | ||
): GasketConfig; | ||
): Out; | ||
export function getPotentialConfigs( | ||
config: ConfigContext & { | ||
config: GasketConfig; | ||
} | ||
): Generator<any, any, any>; | ||
/** | ||
* Normalize the config by applying any environment or local overrides | ||
* | ||
* @param gasketConfig - Gasket config | ||
* @param config - Target config to be normalized | ||
* @param [localFile] - Optional file to load relative to gasket root | ||
* @returns config | ||
* @deprecated use applyConfigOverrides | ||
*/ | ||
declare function applyEnvironmentOverrides( | ||
gasketConfig: GasketConfig, | ||
config: GasketConfig, | ||
localFile?: string | ||
): object; | ||
export interface Signal { | ||
@@ -130,2 +89,7 @@ aborted?: boolean; | ||
export function getPotentialConfigs( | ||
config: ConfigDefinition, | ||
configContext: ConfigContext | ||
): Generator<any, any, any>; | ||
/** | ||
@@ -201,1 +165,6 @@ * Promise friendly wrapper to running a shell command (eg: git, npm, ls) which | ||
} | ||
export function warnIfOutdated(pkgName: string, currentVersion: string): MaybeAsync<void>; | ||
export function getPackageLatestVersion(pkgName: string, options?: object): Promise<string>; |
@@ -1,17 +0,13 @@ | ||
const tryRequire = require('./try-require'); | ||
const { tryResolve } = require('./try-resolve'); | ||
const applyConfigOverrides = require('./apply-config-overrides'); | ||
const applyEnvironmentOverrides = require('./apply-env-overrides'); | ||
const runShellCommand = require('./run-shell-command'); | ||
const PackageManager = require('./package-manager'); | ||
const requireWithInstall = require('./require-with-install'); | ||
const warnIfOutdated = require('./warn-if-outdated'); | ||
const getPackageLatestVersion = require('./get-package-latest-version'); | ||
module.exports = { | ||
tryRequire, | ||
tryResolve, | ||
applyConfigOverrides, | ||
applyEnvironmentOverrides, | ||
runShellCommand, | ||
PackageManager, | ||
requireWithInstall | ||
warnIfOutdated, | ||
getPackageLatestVersion | ||
}; |
@@ -9,6 +9,5 @@ /* eslint-disable no-process-env */ | ||
/** @param {import('./index').PackageManagerOptions} options - Options */ | ||
constructor({ packageManager = 'npm', dest, npmconfig }) { | ||
constructor({ packageManager = 'npm', dest }) { | ||
this.manager = packageManager; | ||
this.dest = dest; | ||
this.npmconfig = npmconfig; | ||
} | ||
@@ -84,6 +83,2 @@ | ||
// Global npmrc configured through gasket flag | ||
// TODO (kinetifex): remove in next major revision | ||
if (this.npmconfig) argv.push('--userconfig', this.npmconfig); | ||
return await PackageManager.spawnNpm(argv, { | ||
@@ -96,9 +91,2 @@ cwd: this.dest, | ||
// Support for the .npmrc configured via --npmconfig flag. | ||
// Yarn does not have a "userconfig" CLI flag, it does however still | ||
// support the npm_config_* environment variables for npm compatibility. | ||
// @see: https://yarnpkg.com/en/docs/envvars#toc-npm-config | ||
// TODO (kinetifex): remove in next major revision | ||
if (this.npmconfig) env.NPM_CONFIG_USERCONFIG = this.npmconfig; | ||
return await PackageManager.spawnYarn(argv, { | ||
@@ -105,0 +93,0 @@ cwd: this.dest, |
@@ -0,3 +1,4 @@ | ||
/* eslint-disable max-params */ | ||
const { spawn } = require('child_process'); | ||
const concat = require('concat-stream'); | ||
const spawn = require('cross-spawn'); | ||
@@ -7,2 +8,4 @@ /** @type {import('./index').runShellCommand} */ | ||
const { signal, ...opts } = options; | ||
let stderr; | ||
let stdout; | ||
@@ -21,5 +24,2 @@ if (signal && signal.aborted) { | ||
let stderr; | ||
let stdout; | ||
child.stderr.pipe( | ||
@@ -26,0 +26,0 @@ concat({ encoding: 'string' }, (lines) => { |
{ | ||
"name": "@gasket/utils", | ||
"version": "6.47.0", | ||
"version": "7.0.0-7.0.1-canary.11.0", | ||
"description": "Reusable utilities for Gasket internals", | ||
@@ -43,9 +43,10 @@ "main": "lib", | ||
"dependencies": { | ||
"chalk": "^4.1.2", | ||
"concat-stream": "^2.0.0", | ||
"cross-spawn": "^7.0.3", | ||
"diagnostics": "^2.0.2", | ||
"lodash.defaultsdeep": "^4.6.1" | ||
"lodash.defaultsdeep": "^4.6.1", | ||
"semver": "^7.6.0" | ||
}, | ||
"devDependencies": { | ||
"@gasket/engine": "^6.46.8", | ||
"@gasket/core": "^7.0.0-7.0.1-canary.11.0", | ||
"@godaddy/dmd": "^1.0.4", | ||
@@ -80,3 +81,3 @@ "abort-controller": "^3.0.0", | ||
], | ||
"gitHead": "9feff1fa92be6b1b6ed2ab6d3028490165395c62" | ||
"gitHead": "ee3641e5f9218418d54690c04456fb24b63dc339" | ||
} |
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
4
27294
5
11
490
1
1
+ Addedchalk@^4.1.2
+ Addedsemver@^7.6.0
+ Addedansi-styles@4.3.0(transitive)
+ Addedchalk@4.1.2(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedsemver@7.7.1(transitive)
+ Addedsupports-color@7.2.0(transitive)
- Removedcross-spawn@^7.0.3
- Removedcross-spawn@7.0.6(transitive)
- Removedisexe@2.0.0(transitive)
- Removedpath-key@3.1.1(transitive)
- Removedshebang-command@2.0.0(transitive)
- Removedshebang-regex@3.0.0(transitive)
- Removedwhich@2.0.2(transitive)