@gasket/utils
Advanced tools
Comparing version 7.2.0-canary.20 to 7.2.0
import type { MaybeAsync } from '@gasket/core'; | ||
import type { SpawnOpts } from 'node:child_process'; | ||
interface PackageManagerOptions { | ||
export { applyConfigOverrides } from './config'; | ||
export interface PackageManagerOptions { | ||
/** Name of manager, either `npm` (default) or `yarn` */ | ||
@@ -13,3 +16,3 @@ packageManager: string; | ||
*/ | ||
export interface PackageManager { | ||
export class PackageManager { | ||
constructor(options: PackageManagerOptions): void; | ||
@@ -25,3 +28,2 @@ | ||
* can be run multiple times. | ||
* | ||
* @param cmd The command that needs to be executed. | ||
@@ -34,3 +36,2 @@ * @param args Additional CLI arguments to pass to `npm`. | ||
* Executes npm link in the application directory `this.dest`. | ||
* | ||
* @param packages Explicit `npm` packages to link locally. | ||
@@ -43,3 +44,2 @@ */ | ||
* installation can be run multiple times. | ||
* | ||
* @param args Additional CLI arguments to pass to `npm`. | ||
@@ -52,3 +52,2 @@ * @public | ||
* Executes yarn or npm info, and returns parsed JSON data results. | ||
* | ||
* @param args Additional CLI arguments to pass to `npm`. | ||
@@ -61,26 +60,2 @@ * @returns stdout and data | ||
interface ConfigContext { | ||
/** Name of environment */ | ||
env: string; | ||
/** Name of command */ | ||
commandId?: string; | ||
/** Project root; required if using localeFile */ | ||
} | ||
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<Def extends ConfigDefinition, Out extends ConfigOutput>( | ||
config: Def, | ||
configContext: ConfigContext | ||
): Out; | ||
export interface Signal { | ||
@@ -91,7 +66,2 @@ aborted?: boolean; | ||
export function getPotentialConfigs( | ||
config: ConfigDefinition, | ||
configContext: ConfigContext | ||
): Generator<any, any, any>; | ||
/** | ||
@@ -104,3 +74,8 @@ * Promise friendly wrapper to running a shell command (eg: git, npm, ls) which | ||
* longer needed. | ||
* | ||
* @param cmd | ||
* @param argv | ||
* @param options | ||
* @param options.signal | ||
* @param options.cwd | ||
* @param debug | ||
* @example | ||
@@ -112,3 +87,2 @@ * const { runShellCommand } = require('@gasket/utils'); | ||
* } | ||
* | ||
* @example | ||
@@ -140,3 +114,3 @@ * // With timeout using AbortController | ||
}, | ||
/** When present pipes std{out,err} to process.* */ | ||
/** When present pipes std{out,err} to process.*/ | ||
debug?: boolean | ||
@@ -171,5 +145,56 @@ ): Promise<{ stdout: string }>; | ||
declare module '@gasket/utils' { | ||
/** | ||
* Executes the appropriate npm binary with the verbatim `argv` and | ||
* `spawnWith` options provided. Passes appropriate debug flag for | ||
* npm based on process.env. | ||
* @param argv | ||
* @param spawnWith | ||
*/ | ||
function PackageManager_spawnNpm( | ||
/** Precise CLI arguments to pass to `npm`. */ | ||
argv: string[], | ||
/** Options for child_process.spawn. */ | ||
spawnWith: SpawnOpts | ||
): Promise<{ stdout: string }>; | ||
export function warnIfOutdated(pkgName: string, currentVersion: string): MaybeAsync<void>; | ||
/** | ||
* Executes the appropriate yarn binary with the verbatim `argv` and | ||
* `spawnWith` options provided. Passes appropriate debug flag for | ||
* npm based on process.env. | ||
* @param argv | ||
* @param spawnWith | ||
*/ | ||
function PackageManager_spawnYarn( | ||
/** Precise CLI arguments to pass to `npm`. */ | ||
argv: string[], | ||
/** Options for child_process.spawn. */ | ||
spawnWith: SpawnOpts | ||
): Promise<{ stdout: string }>; | ||
function PackageManager_exec( | ||
/** The command that needs to be executed. */ | ||
cmd: string, | ||
/** Additional CLI arguments to pass to `npm`. */ | ||
args: string[] | ||
): Promise<{ stdout: string }>; | ||
function PackageManager_link( | ||
/** Explicit `npm` packages to link locally. */ | ||
packages: string[] | ||
): Promise<{ stdout: string }>; | ||
function PackageManager_install( | ||
/** Additional CLI arguments to pass to `npm`. */ | ||
args: string[] | ||
): Promise<{ stdout: string }>; | ||
function PackageManager_info( | ||
/** Additional CLI arguments to pass to `npm`. */ | ||
args: string[] | ||
): Promise<{ data: any; stdout: string }>; | ||
export function warnIfOutdated(pkgName: string, currentVersion: string): MaybeAsync<void>; | ||
} | ||
export function getPackageLatestVersion(pkgName: string, options?: object): Promise<string>; |
@@ -1,2 +0,2 @@ | ||
const applyConfigOverrides = require('./apply-config-overrides'); | ||
const { applyConfigOverrides } = require('./config'); | ||
const runShellCommand = require('./run-shell-command'); | ||
@@ -3,0 +3,0 @@ const PackageManager = require('./package-manager'); |
@@ -18,5 +18,3 @@ /* eslint-disable no-process-env */ | ||
* npm based on process.env. | ||
* @param {string[]} argv Precise CLI arguments to pass to `npm`. | ||
* @param {object} spawnWith Options for child_process.spawn. | ||
* @returns {Promise} promise | ||
* @type {import('@gasket/utils').PackageManager_spawnNpm} | ||
* @public | ||
@@ -38,3 +36,3 @@ */ | ||
/** | ||
* Executes the appropriate yarn binary with the verbatim `argv` and | ||
* Executes the appropriate npm binary with the verbatim `argv` and | ||
* `spawnWith` options provided. Passes appropriate debug flag for | ||
@@ -47,2 +45,21 @@ * npm based on process.env. | ||
*/ | ||
static spawnPnpm(argv, spawnWith) { | ||
// TODO: confirm pnpm binary name on windows | ||
const pnpmBin = process.platform === 'win32' ? 'pnpm.cmd' : 'pnpm'; | ||
return runShellCommand( | ||
pnpmBin, | ||
argv, | ||
spawnWith, | ||
!!process.env.GASKET_DEBUG_NPM | ||
); | ||
} | ||
/** | ||
* Executes the appropriate yarn binary with the verbatim `argv` and | ||
* `spawnWith` options provided. Passes appropriate debug flag for | ||
* npm based on process.env. | ||
* @type {import('@gasket/utils').PackageManager_spawnYarn} | ||
* @public | ||
*/ | ||
static spawnYarn(argv, spawnWith) { | ||
@@ -66,5 +83,3 @@ // Just like the `npm` binary, the `yarn` binary is different on windows | ||
* This installation can be run multiple times. | ||
* @param {string} cmd The command that needs to be executed. | ||
* @param {string[]} args Additional CLI arguments to pass to `npm`. | ||
* @returns {Promise} promise | ||
* @type {import('@gasket/utils').PackageManager_exec} | ||
* @public | ||
@@ -90,2 +105,9 @@ */ | ||
}); | ||
} else if (this.manager === 'pnpm') { | ||
const argv = [cmd].concat(args); | ||
return await PackageManager.spawnPnpm(argv, { | ||
cwd: this.dest, | ||
env | ||
}); | ||
} else if (this.manager === 'yarn') { | ||
@@ -107,4 +129,3 @@ const argv = [cmd].concat(args); | ||
* Executes npm link in the application directory `this.dest`. | ||
* @param {string[]} packages Explicit `npm` packages to link locally. | ||
* @returns {Promise} promise | ||
* @type {import('@gasket/utils').PackageManager_link} | ||
* @public | ||
@@ -119,7 +140,11 @@ */ | ||
* This installation can be run multiple times. | ||
* @param {string[]} args Additional CLI arguments to pass to `npm`. | ||
* @returns {Promise} promise | ||
* @type {import('@gasket/utils').PackageManager_install} | ||
* @public | ||
*/ | ||
async install(args = []) { | ||
// --legacy-peer-deps is not supported by pnpm | ||
if (this.manager === 'pnpm') { | ||
return this.exec('install', args); | ||
} | ||
// Installing with --legacy-peer-deps flag to accommodate npm7, specifically | ||
@@ -132,4 +157,3 @@ // requiring different versions of react | ||
* Executes yarn or npm info, and returns parsed JSON data results. | ||
* @param {string[]} args Additional CLI arguments to pass to `npm`. | ||
* @returns {Promise<object>} stdout and data | ||
* @type {import('@gasket/utils').PackageManager_info} | ||
* @public | ||
@@ -140,3 +164,3 @@ */ | ||
// normalize stdout results of yarn and npm before parsing | ||
let normalized = this.manager === 'npm' ? `{ "data": ${stdout} }` : stdout; | ||
let normalized = this.manager.includes('npm') ? `{ "data": ${stdout} }` : stdout; | ||
normalized = stdout ? normalized : '{}'; | ||
@@ -143,0 +167,0 @@ |
@@ -8,3 +8,5 @@ /* eslint-disable max-params */ | ||
const { signal, ...opts } = options; | ||
/** @type {string} */ | ||
let stderr; | ||
/** @type {string} */ | ||
let stdout; | ||
@@ -11,0 +13,0 @@ |
{ | ||
"name": "@gasket/utils", | ||
"version": "7.2.0-canary.20", | ||
"version": "7.2.0", | ||
"description": "Reusable utilities for Gasket internals", | ||
"main": "lib", | ||
"types": "lib/index.d.ts", | ||
"files": [ | ||
"docs", | ||
"lib" | ||
], | ||
"exports": { | ||
".": { | ||
"types": "./lib/index.d.ts", | ||
"default": "./lib/index.js" | ||
}, | ||
"./config": { | ||
"types": "./lib/config.d.ts", | ||
"default": "./lib/config.js" | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"scripts": { | ||
@@ -18,3 +26,2 @@ "lint": "eslint .", | ||
"posttest": "npm run lint && npm run typecheck", | ||
"disabled_docs": "jsdoc2md --plugin @godaddy/dmd --files lib/*.js > docs/api.md", | ||
"typecheck": "tsc", | ||
@@ -35,5 +42,2 @@ "typecheck:watch": "tsc --watch" | ||
"author": "GoDaddy Operating Company, LLC", | ||
"maintainers": [ | ||
"Andrew Gerard <agerard@godaddy.com>" | ||
], | ||
"license": "MIT", | ||
@@ -47,18 +51,20 @@ "bugs": { | ||
"concat-stream": "^2.0.0", | ||
"deepmerge": "^4.3.1", | ||
"diagnostics": "^2.0.2", | ||
"lodash.defaultsdeep": "^4.6.1", | ||
"semver": "^7.6.0" | ||
"is-plain-object": "^5.0.0", | ||
"semver": "^7.6.3" | ||
}, | ||
"devDependencies": { | ||
"@gasket/core": "^7.2.0-canary.20", | ||
"@godaddy/dmd": "^1.0.4", | ||
"@gasket/core": "^7.2.0", | ||
"@types/concat-stream": "^2.0.3", | ||
"@types/cross-spawn": "^6.0.6", | ||
"abort-controller": "^3.0.0", | ||
"cross-env": "^7.0.3", | ||
"eslint": "^8.56.0", | ||
"eslint-config-godaddy": "^7.1.0", | ||
"eslint-plugin-jest": "^27.6.3", | ||
"eslint-config-godaddy": "^7.1.1", | ||
"eslint-config-godaddy-typescript": "^4.0.3", | ||
"eslint-plugin-jest": "^28.6.0", | ||
"eslint-plugin-json": "^3.1.0", | ||
"eslint-plugin-unicorn": "^44.0.0", | ||
"eslint-plugin-unicorn": "^55.0.0", | ||
"jest": "^29.7.0", | ||
"jsdoc-to-markdown": "^7.1.0", | ||
"typescript": "^5.4.5" | ||
@@ -78,3 +84,29 @@ }, | ||
"unicorn/filename-case": "error" | ||
} | ||
}, | ||
"overrides": [ | ||
{ | ||
"files": [ | ||
"test/**/*.js" | ||
], | ||
"rules": { | ||
"jsdoc/require-jsdoc": "off", | ||
"jsdoc/require-param-type": "off", | ||
"jsdoc/require-returns-description": "off" | ||
} | ||
}, | ||
{ | ||
"files": [ | ||
"*.ts" | ||
], | ||
"extends": [ | ||
"godaddy-typescript" | ||
], | ||
"rules": { | ||
"jsdoc/require-jsdoc": "off", | ||
"jsdoc/require-param-description": "off", | ||
"jsdoc/require-param-type": "off", | ||
"jsdoc/require-returns": "off" | ||
} | ||
} | ||
] | ||
}, | ||
@@ -84,3 +116,3 @@ "eslintIgnore": [ | ||
], | ||
"gitHead": "abdb788c7ff44f4c6db7a5885e96e2dd315273fc" | ||
"gitHead": "8790fd065f4bcb853fc9a2deecf0833999f41443" | ||
} |
@@ -11,8 +11,4 @@ # @gasket/utils | ||
## Usage | ||
See the [API docs](docs/api.md) for details on what is available. | ||
## License | ||
[MIT](./LICENSE.md) |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
590
0
24067
6
13
14
5
+ Addeddeepmerge@^4.3.1
+ Addedis-plain-object@^5.0.0
+ Addeddeepmerge@4.3.1(transitive)
+ Addedis-plain-object@5.0.0(transitive)
- Removedlodash.defaultsdeep@^4.6.1
- Removedlodash.defaultsdeep@4.6.1(transitive)
Updatedsemver@^7.6.3