Socket
Socket
Sign inDemoInstall

zx

Package Overview
Dependencies
4
Maintainers
2
Versions
111
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 7.2.3-dev.1d8aa93 to 7.2.3-dev.2026d4a

8

build/cli.js

@@ -32,3 +32,2 @@ #!/usr/bin/env node

--install, -i install dependencies
--experimental enable experimental features
--version, -v print current zx version

@@ -41,3 +40,3 @@ --help, -h print help

string: ["shell", "prefix", "eval"],
boolean: ["version", "help", "quiet", "install", "repl", "experimental"],
boolean: ["version", "help", "quiet", "verbose", "install", "repl"],
alias: { e: "eval", i: "install", v: "version", h: "help" },

@@ -49,2 +48,4 @@ stopEarly: true

await import(globals);
if (argv.verbose)
$.verbose = true;
if (argv.quiet)

@@ -56,5 +57,2 @@ $.verbose = false;

$.prefix = argv.prefix;
if (argv.experimental) {
Object.assign(global, await import("./experimental.js"));
}
if (argv.version) {

@@ -61,0 +59,0 @@ console.log(getVersion());

@@ -33,2 +33,3 @@ import { spawn, spawnSync, StdioNull, StdioPipe } from 'node:child_process';

log: typeof log;
kill: typeof kill;
}

@@ -72,2 +73,3 @@ export declare const defaults: Options;

quiet(): ProcessPromise;
isQuiet(): boolean;
isVerbose(): boolean;

@@ -98,2 +100,3 @@ timeout(d: Duration, signal?: string): ProcessPromise;

export declare function cd(dir: string | ProcessOutput): void;
export declare function kill(pid: number, signal?: string): Promise<void>;
export type LogEntry = {

@@ -100,0 +103,0 @@ kind: 'cmd';

@@ -10,3 +10,4 @@ // src/core.ts

chalk,
which
which,
ps
} from "./vendor.js";

@@ -17,5 +18,5 @@ import {

formatCmd,
getCallerLocation,
noop,
parseDuration,
psTree,
quote,

@@ -38,3 +39,3 @@ quotePowerShell

[syncExec]: false,
verbose: true,
verbose: false,
env: process.env,

@@ -51,3 +52,4 @@ sync: false,

spawnSync,
log
log,
kill
};

@@ -81,3 +83,3 @@ var isWin = process.platform == "win32";

}
const from = new Error().stack.split(/^\s*at\s/m)[2].trim();
const from = getCallerLocation();
if (pieces.some((p) => p == void 0)) {

@@ -192,3 +194,3 @@ throw new Error(`Malformed command at ${from}`);

stderr: (data) => {
$2.log({ kind: "stderr", data, verbose: self.isVerbose() });
$2.log({ kind: "stderr", data, verbose: !self.isQuiet() });
},

@@ -314,13 +316,3 @@ end: ({ error, stdout, stderr, stdall, status, signal }) => {

throw new Error("The process pid is undefined.");
let children = await psTree(this.child.pid);
for (const p of children) {
try {
process.kill(+p.PID, signal);
} catch (e) {
}
}
try {
process.kill(-this.child.pid, signal);
} catch (e) {
}
return $.kill(this.child.pid, signal);
}

@@ -339,5 +331,7 @@ stdio(stdin, stdout = "pipe", stderr = "pipe") {

}
isQuiet() {
return this._quiet ?? this._snapshot.quiet;
}
isVerbose() {
const { verbose, quiet } = this._snapshot;
return verbose && !(this._quiet ?? quiet);
return this._snapshot.verbose && !this.isQuiet();
}

@@ -431,2 +425,15 @@ timeout(d, signal = "SIGTERM") {

}
async function kill(pid, signal) {
let children = await ps.tree({ pid, recursive: true });
for (const p of children) {
try {
process.kill(+p.pid, signal);
} catch (e) {
}
}
try {
process.kill(-pid, signal);
} catch (e) {
}
}
function log(entry) {

@@ -472,4 +479,5 @@ switch (entry.kind) {

defaults,
kill,
log,
within
};
// src/deps.ts
import { $ } from "./core.js";
import { spinner } from "./experimental.js";
import { spinner } from "./goods.js";
import { depseek } from "./vendor.js";
async function installDeps(dependencies, prefix) {

@@ -74,30 +75,16 @@ const packages = Object.entries(dependencies).map(

]);
var importRe = [
/\bimport\s+['"](?<path>[^'"]+)['"]/,
/\bimport\(['"](?<path>[^'"]+)['"]\)/,
/\brequire\(['"](?<path>[^'"]+)['"]\)/,
/\bfrom\s+['"](?<path>[^'"]+)['"]/
];
var nameRe = /^(?<name>(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*)\/?.*$/i;
var versionRe = /(\/\/|\/\*)\s*@(?<version>[~^]?(v?[\dx*]+([-.][\d*a-z-]+)*))/i;
var versionRe = /^@(?<version>[~^]?(v?[\dx*]+([-.][\d*a-z-]+)*))/i;
function parseDeps(content) {
const deps = {};
const lines = content.toString().split("\n");
for (let line of lines) {
const tuple = parseImports(line);
if (tuple) {
deps[tuple.name] = tuple.version;
return depseek(content.toString() + "\n", { comments: true }).reduce((m, { type, value }, i, list) => {
if (type === "dep") {
const meta = list[i + 1];
const name = parsePackageName(value);
const version = meta?.type === "comment" && parseVersion(meta?.value.trim()) || "latest";
if (name)
m[name] = version;
}
}
return deps;
return m;
}, {});
}
function parseImports(line) {
for (let re of importRe) {
const name = parsePackageName(re.exec(line)?.groups?.path);
const version = parseVersion(line);
if (name) {
return { name, version };
}
}
}
function parsePackageName(path) {

@@ -104,0 +91,0 @@ if (!path)

@@ -28,3 +28,2 @@ import * as _ from './index.js';

var spinner: typeof _.spinner;
var ssh: typeof _.ssh;
var stdin: typeof _.stdin;

@@ -31,0 +30,0 @@ var which: typeof _.which;

@@ -19,8 +19,5 @@ // src/goods.ts

}
var globby = Object.assign(
function globby2(patterns, options) {
return globbyModule.globby(patterns, options);
},
globbyModule
);
var globby = Object.assign(function globby2(patterns, options) {
return globbyModule.globby(patterns, options);
}, globbyModule);
var glob = globby;

@@ -27,0 +24,0 @@ function sleep(duration) {

import { ProcessPromise } from './core.js';
export * from './core.js';
export * from './goods.js';
export { minimist, chalk, fs, which, YAML, ssh } from './vendor.js';
export { minimist, chalk, fs, which, YAML, ps } from './vendor.js';
export { type Duration, quote, quotePowerShell } from './util.js';

@@ -6,0 +6,0 @@ /**

// src/index.ts
export * from "./core.js";
export * from "./goods.js";
import { minimist, chalk, fs, which, YAML, ssh } from "./vendor.js";
import { minimist, chalk, fs, which, YAML, ps } from "./vendor.js";
import { quote, quotePowerShell } from "./util.js";

@@ -18,7 +18,7 @@ function nothrow(promise) {

nothrow,
ps,
quiet,
quote,
quotePowerShell,
ssh,
which
};

@@ -1,3 +0,1 @@

import { psTreeModule } from './vendor.js';
export declare const psTree: (arg1: number) => Promise<readonly psTreeModule.PS[]>;
export declare function noop(): void;

@@ -10,4 +8,6 @@ export declare function randomId(): string;

export declare function errnoMessage(errno: number | undefined): string;
export type Duration = number | `${number}s` | `${number}ms`;
export type Duration = number | `${number}m` | `${number}s` | `${number}ms`;
export declare function parseDuration(d: Duration): number;
export declare function formatCmd(cmd?: string): string;
export declare function getCallerLocation(err?: Error): string;
export declare function getCallerLocationFromString(stackString?: string): string;
// src/util.ts
import { promisify } from "node:util";
import { chalk, psTreeModule } from "./vendor.js";
var psTree = promisify(psTreeModule);
import { chalk } from "./vendor.js";
function noop() {

@@ -196,2 +194,4 @@ }

return +d.slice(0, -2);
} else if (/\d+m/.test(d)) {
return +d.slice(0, -1) * 1e3 * 60;
}

@@ -324,2 +324,8 @@ throw new Error(`Unknown duration: "${d}".`);

];
function getCallerLocation(err = new Error()) {
return getCallerLocationFromString(err.stack);
}
function getCallerLocationFromString(stackString = "unknown") {
return stackString.split(/^\s*(at\s)?/m).filter((s) => s?.includes(":"))[2]?.trim() || stackString;
}
export {

@@ -329,6 +335,7 @@ errnoMessage,

formatCmd,
getCallerLocation,
getCallerLocationFromString,
isString,
noop,
parseDuration,
psTree,
quote,

@@ -335,0 +342,0 @@ quotePowerShell,

@@ -377,2 +377,15 @@ // Generated by dts-bundle-generator v9.3.1

export declare const exec: (ctx: TSpawnCtx) => TSpawnCtxNormalized;
type TCodeRef = {
type: string;
value: string;
index: number;
};
type TOptsNormalized = {
comments: boolean;
bufferSize: number;
re: RegExp;
offset: number;
};
type TOpts = Partial<TOptsNormalized>;
declare const depseekSync: (input: string | Buffer, opts?: TOpts) => TCodeRef[];
type ColorSupportLevel = 0 | 1 | 2 | 3;

@@ -682,31 +695,30 @@ export interface ChalkInstance {

}
declare namespace ps_tree$1 {
interface PS {
COMMAND: string;
PPID: string;
PID: string;
STAT: string;
}
const prototype: {};
}
declare function ps_tree$1(pid: number, callback: (error: Error | null, children: readonly ps_tree$1.PS[]) => void): void;
type RemoteShell = ((pieces: TemplateStringsArray, ...values: any[]) => Promise<Result>) & {
exit: () => void;
type TPsLookupCallback = (err: any, processList?: TPsLookupEntry[]) => void;
type TPsLookupEntry = {
pid: string;
ppid?: string;
command: string;
arguments: string[];
};
type Options$2 = {
port?: number | string;
forwardAgent?: boolean;
shell?: string;
options?: (SshOption | `${SshOption}=${string}`)[];
type TPsLookupQuery = {
pid?: number | string | (string | number)[];
command?: string;
arguments?: string;
ppid?: number | string;
psargs?: string | string[];
};
export declare function ssh(host: string, options?: Options$2): RemoteShell;
declare class Result extends String {
readonly source: string;
readonly stdout: string;
readonly stderr: string;
readonly exitCode: number | null;
readonly error?: Error;
constructor(source: string, exitCode: number | null, stdout: string, stderr: string, combined: string, error?: Error);
}
type SshOption = "AddKeysToAgent" | "AddressFamily" | "BatchMode" | "BindAddress" | "CanonicalDomains" | "CanonicalizeFallbackLocal" | "CanonicalizeHostname" | "CanonicalizeMaxDots" | "CanonicalizePermittedCNAMEs" | "CASignatureAlgorithms" | "CertificateFile" | "ChallengeResponseAuthentication" | "CheckHostIP" | "Ciphers" | "ClearAllForwardings" | "Compression" | "ConnectionAttempts" | "ConnectTimeout" | "ControlMaster" | "ControlPath" | "ControlPersist" | "DynamicForward" | "EscapeChar" | "ExitOnForwardFailure" | "FingerprintHash" | "ForwardAgent" | "ForwardX11" | "ForwardX11Timeout" | "ForwardX11Trusted" | "GatewayPorts" | "GlobalKnownHostsFile" | "GSSAPIAuthentication" | "GSSAPIDelegateCredentials" | "HashKnownHosts" | "Host" | "HostbasedAcceptedAlgorithms" | "HostbasedAuthentication" | "HostKeyAlgorithms" | "HostKeyAlias" | "Hostname" | "IdentitiesOnly" | "IdentityAgent" | "IdentityFile" | "IPQoS" | "KbdInteractiveAuthentication" | "KbdInteractiveDevices" | "KexAlgorithms" | "KnownHostsCommand" | "LocalCommand" | "LocalForward" | "LogLevel" | "MACs" | "Match" | "NoHostAuthenticationForLocalhost" | "NumberOfPasswordPrompts" | "PasswordAuthentication" | "PermitLocalCommand" | "PermitRemoteOpen" | "PKCS11Provider" | "Port" | "PreferredAuthentications" | "ProxyCommand" | "ProxyJump" | "ProxyUseFdpass" | "PubkeyAcceptedAlgorithms" | "PubkeyAuthentication" | "RekeyLimit" | "RemoteCommand" | "RemoteForward" | "RequestTTY" | "SendEnv" | "ServerAliveInterval" | "ServerAliveCountMax" | "SetEnv" | "StreamLocalBindMask" | "StreamLocalBindUnlink" | "StrictHostKeyChecking" | "TCPKeepAlive" | "Tunnel" | "TunnelDevice" | "UpdateHostKeys" | "UseKeychain" | "User" | "UserKnownHostsFile" | "VerifyHostKeyDNS" | "VisualHostKey" | "XAuthLocation";
type TPsKillOptions = {
timeout?: number;
signal?: string | number | NodeJS.Signals;
};
type TPsNext = (err?: any, data?: any) => void;
type TPsTreeOpts = {
pid: string | number;
recursive?: boolean;
};
declare const _default: {
lookup: (query?: TPsLookupQuery, cb?: TPsLookupCallback) => Promise<TPsLookupEntry[]>;
kill: (pid: string | number, opts?: string | number | TPsKillOptions | TPsNext | undefined, next?: TPsNext | undefined) => Promise<void>;
tree: (opts: string | number | TPsTreeOpts, cb?: TPsLookupCallback) => Promise<TPsLookupEntry[]>;
};
export type RequestInfo = Parameters<typeof fetch$1>[0];

@@ -733,7 +745,8 @@ type RequestInit$1 = Parameters<typeof fetch$1>[1];

RequestInit$1 as RequestInit,
_default as ps,
depseekSync as depseek,
fetch$1 as nodeFetch,
fs$1 as fs,
ps_tree$1 as psTreeModule,
};
export {};
{
"name": "zx",
"version": "7.2.3-dev.1d8aa93",
"version": "7.2.3-dev.2026d4a",
"description": "A tool for writing better scripts",

@@ -16,5 +16,2 @@ "type": "module",

],
"experimental": [
"./build/experimental.d.ts"
],
"cli": [

@@ -31,3 +28,2 @@ "./build/cli.d.ts"

"./globals": "./build/globals.js",
"./experimental": "./build/experimental.js",
"./cli": "./build/cli.js",

@@ -51,3 +47,4 @@ "./core": "./build/core.js",

"build:dts": "tsc --project tsconfig.prod.json && node scripts/build-dts.mjs",
"test": "npm run build && node ./test/all.test.js",
"test": "npm run build && npm run test:unit && npm run test:types",
"test:unit": "node ./test/all.test.js",
"test:types": "tsd",

@@ -61,3 +58,3 @@ "coverage": "c8 -x build/vendor.js -x 'test/**' -x scripts --check-coverage npm test",

"@types/fs-extra": "^11.0.4",
"@types/node": ">=20.11.28"
"@types/node": ">=20.11.30"
},

@@ -68,7 +65,8 @@ "devDependencies": {

"@types/minimist": "^1.2.5",
"@types/node": ">=20.11.19",
"@types/ps-tree": "^1.1.6",
"@types/node": ">=20.11.30",
"@types/which": "^3.0.3",
"c8": "^7.13.0",
"@webpod/ps": "^0.0.0-beta.2",
"c8": "^9.1.0",
"chalk": "^5.3.0",
"depseek": "^0.4.1",
"dts-bundle-generator": "^9.3.1",

@@ -83,11 +81,9 @@ "esbuild": "^0.20.2",

"minimist": "^1.2.8",
"node-fetch-native": "^1.6.2",
"prettier": "^2.8.8",
"ps-tree": "^1.2.0",
"node-fetch-native": "^1.6.4",
"prettier": "^3.2.5",
"tsd": "^0.30.7",
"typescript": "^5.0.4",
"webpod": "^0",
"which": "^3.0.0",
"typescript": "^5.4.3",
"which": "^4.0.0",
"yaml": "^2.4.1",
"zurk": "^0.0.31"
"zurk": "^0.0.32"
},

@@ -104,3 +100,4 @@ "publishConfig": {

"singleQuote": true,
"endOfLine": "lf"
"endOfLine": "lf",
"trailingComma": "es5"
},

@@ -107,0 +104,0 @@ "repository": "google/zx",

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc