New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@gasket/utils

Package Overview
Dependencies
Maintainers
0
Versions
168
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gasket/utils - npm Package Compare versions

Comparing version

to
7.3.0

lib/config.d.ts

2

lib/get-package-latest-version.js

@@ -5,3 +5,3 @@ const runShellCommand = require('./run-shell-command');

* Get the latest version of a package from npm
* @type {import('./index').getPackageLatestVersion}
* @type {import('@gasket/utils').getPackageLatestVersion}
*/

@@ -8,0 +8,0 @@ module.exports = async function getPackageLatestVersion(pkgName, options = {}) {

import type { MaybeAsync } from '@gasket/core';
import type { SpawnOptions } from 'child_process';
interface PackageManagerOptions {
export { applyConfigOverrides } from './config';
export interface PackageManagerOptions {
/** Name of manager, either `npm` (default) or `yarn` */
packageManager: string;
packageManager?: string;
/** Target directory where `node_module` should exist */
dest: string;
dest?: string;
}

@@ -24,3 +27,2 @@

* can be run multiple times.
*
* @param cmd The command that needs to be executed.

@@ -33,3 +35,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.

@@ -42,3 +43,2 @@ */

* installation can be run multiple times.
*
* @param args Additional CLI arguments to pass to `npm`.

@@ -51,3 +51,2 @@ * @public

* Executes yarn or npm info, and returns parsed JSON data results.
*
* @param args Additional CLI arguments to pass to `npm`.

@@ -60,26 +59,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 {

@@ -90,7 +65,2 @@ aborted?: boolean;

export function getPotentialConfigs(
config: ConfigDefinition,
configContext: ConfigContext
): Generator<any, any, any>;
/**

@@ -103,3 +73,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

@@ -111,3 +86,2 @@ * const { runShellCommand } = require('@gasket/utils');

* }
*
* @example

@@ -133,9 +107,4 @@ * // With timeout using AbortController

/** Options passed to npm binary through spawn */
options?: {
/** AbortControl signal allowing process to be canceled */
signal?: Signal;
/** Path to the target app (Default: cwd/appName) */
cwd?: string;
},
/** When present pipes std{out,err} to process.* */
options?: SpawnOptions,
/** When present pipes std{out,err} to process.*/
debug?: boolean

@@ -170,5 +139,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: SpawnOptions
): 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: SpawnOptions
): 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');

@@ -9,3 +9,3 @@ /* eslint-disable no-process-env */

/** @param {import('./index').PackageManagerOptions} options - Options */
constructor({ packageManager = 'npm', dest }) {
constructor({ packageManager = 'pnpm', dest }) {
this.manager = packageManager;

@@ -19,5 +19,3 @@ this.dest = dest;

* 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

@@ -39,3 +37,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

@@ -48,2 +46,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) {

@@ -67,5 +84,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

@@ -91,2 +106,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') {

@@ -108,4 +130,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

@@ -120,7 +141,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

@@ -133,4 +158,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

@@ -141,3 +165,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 : '{}';

@@ -144,0 +168,0 @@

@@ -5,6 +5,8 @@ /* eslint-disable max-params */

/** @type {import('./index').runShellCommand} */
/** @type {import('@gasket/utils').runShellCommand} */
function runShellCommand(cmd, argv, options = {}, debug = false) {
const { signal, ...opts } = options;
/** @type {string} */
let stderr;
/** @type {string} */
let stdout;

@@ -11,0 +13,0 @@

{
"name": "@gasket/utils",
"version": "7.3.0-canary.4",
"version": "7.3.0",
"description": "Reusable utilities for Gasket internals",
"main": "lib",
"types": "lib/index.d.ts",
"files": [
"docs",
"lib"
],
"scripts": {
"lint": "eslint .",
"lint:fix": "npm run lint -- --fix",
"test": "cross-env NODE_OPTIONS='--unhandled-rejections=strict' jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage",
"posttest": "npm run lint && npm run typecheck",
"disabled_docs": "jsdoc2md --plugin @godaddy/dmd --files lib/*.js > docs/api.md",
"typecheck": "tsc",
"typecheck:watch": "tsc --watch"
"exports": {
".": {
"types": "./lib/index.d.ts",
"default": "./lib/index.js"
},
"./config": {
"types": "./lib/config.d.ts",
"default": "./lib/config.js"
},
"./package.json": "./package.json"
},

@@ -34,5 +31,2 @@ "repository": {

"author": "GoDaddy Operating Company, LLC",
"maintainers": [
"Andrew Gerard <agerard@godaddy.com>"
],
"license": "MIT",

@@ -46,19 +40,22 @@ "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.7.1"
},
"devDependencies": {
"@gasket/core": "^7.3.0-canary.4",
"@godaddy/dmd": "^1.0.4",
"@types/concat-stream": "^2.0.3",
"@types/cross-spawn": "^6.0.6",
"@types/jest": "^29.5.14",
"@types/node": "^20.17.19",
"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-plugin-json": "^3.1.0",
"eslint-plugin-unicorn": "^44.0.0",
"eslint": "^8.57.1",
"eslint-config-godaddy": "^7.1.1",
"eslint-config-godaddy-typescript": "^4.0.3",
"eslint-plugin-jest": "^28.11.0",
"eslint-plugin-unicorn": "^55.0.0",
"jest": "^29.7.0",
"jsdoc-to-markdown": "^7.1.0",
"typescript": "^5.4.5"
"typescript": "^5.7.3",
"@gasket/core": "^7.3.0"
},

@@ -77,3 +74,26 @@ "eslintConfig": {

"unicorn/filename-case": "error"
}
},
"overrides": [
{
"files": [
"test/**/*.js"
],
"rules": {
"jsdoc/require-jsdoc": "off",
"jsdoc/require-param-type": "off",
"jsdoc/require-returns-description": "off"
}
},
{
"files": [
"lib/*.ts"
],
"extends": [
"godaddy-typescript"
],
"rules": {
"jsdoc/*": "off"
}
}
]
},

@@ -83,3 +103,12 @@ "eslintIgnore": [

],
"gitHead": "2abf9afba3b1d1f9a77efe01377a2e12cfeda02c"
}
"scripts": {
"lint": "eslint .",
"lint:fix": "pnpm run lint --fix",
"test": "cross-env NODE_OPTIONS='--unhandled-rejections=strict' jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage",
"posttest": "pnpm run lint && pnpm run typecheck",
"typecheck": "tsc",
"typecheck:watch": "tsc --watch"
}
}

@@ -11,8 +11,4 @@ # @gasket/utils

## Usage
See the [API docs](docs/api.md) for details on what is available.
## License
[MIT](./LICENSE.md)