Comparing version 7.2.3-dev.cafb90d to 7.2.3-dev.d79a638
@@ -30,5 +30,5 @@ #!/usr/bin/env node | ||
--prefix=<command> prefix all commands | ||
--postfix=<command> postfix all commands | ||
--eval=<js>, -e evaluate script | ||
--install, -i install dependencies | ||
--experimental enable experimental features | ||
--version, -v print current zx version | ||
@@ -40,12 +40,4 @@ --help, -h print help | ||
var argv = minimist(process.argv.slice(2), { | ||
string: ["shell", "prefix", "eval"], | ||
boolean: [ | ||
"version", | ||
"help", | ||
"quiet", | ||
"verbose", | ||
"install", | ||
"repl", | ||
"experimental" | ||
], | ||
string: ["shell", "prefix", "postfix", "eval"], | ||
boolean: ["version", "help", "quiet", "verbose", "install", "repl"], | ||
alias: { e: "eval", i: "install", v: "version", h: "help" }, | ||
@@ -65,5 +57,4 @@ stopEarly: true | ||
$.prefix = argv.prefix; | ||
if (argv.experimental) { | ||
Object.assign(global, await import("./experimental.js")); | ||
} | ||
if (argv.postfix) | ||
$.postfix = argv.postfix; | ||
if (argv.version) { | ||
@@ -70,0 +61,0 @@ console.log(getVersion()); |
@@ -28,2 +28,3 @@ import { spawn, spawnSync, StdioNull, StdioPipe } from 'node:child_process'; | ||
prefix: string; | ||
postfix: string; | ||
quote: typeof quote; | ||
@@ -36,3 +37,6 @@ quiet: boolean; | ||
} | ||
export declare function syncProcessCwd(flag?: boolean): void; | ||
export declare const defaults: Options; | ||
export declare function usePowerShell(): void; | ||
export declare function useBash(): void; | ||
export declare const $: Shell & Options; | ||
@@ -39,0 +43,0 @@ type Resolve = (out: ProcessOutput) => void; |
@@ -17,6 +17,9 @@ // src/core.ts | ||
formatCmd, | ||
getCallerLocation, | ||
noop, | ||
normalizeMultilinePieces, | ||
parseDuration, | ||
quote, | ||
quotePowerShell | ||
quotePowerShell, | ||
noquote | ||
} from "./util.js"; | ||
@@ -26,3 +29,3 @@ var processCwd = Symbol("processCwd"); | ||
var storage = new AsyncLocalStorage(); | ||
var hook = createHook({ | ||
var cwdSyncHook = createHook({ | ||
init: syncCwd, | ||
@@ -34,3 +37,8 @@ before: syncCwd, | ||
}); | ||
hook.enable(); | ||
function syncProcessCwd(flag = true) { | ||
if (flag) | ||
cwdSyncHook.enable(); | ||
else | ||
cwdSyncHook.disable(); | ||
} | ||
var defaults = { | ||
@@ -46,5 +54,4 @@ [processCwd]: process.cwd(), | ||
prefix: "", | ||
quote: () => { | ||
throw new Error("No quote function is defined: https://\xEF.at/no-quote-func"); | ||
}, | ||
postfix: "", | ||
quote: noquote, | ||
spawn, | ||
@@ -56,13 +63,16 @@ spawnSync, | ||
var isWin = process.platform == "win32"; | ||
try { | ||
defaults.shell = which.sync("bash"); | ||
defaults.prefix = "set -euo pipefail;"; | ||
defaults.quote = quote; | ||
} catch (err) { | ||
if (isWin) { | ||
try { | ||
defaults.shell = which.sync("powershell.exe"); | ||
defaults.quote = quotePowerShell; | ||
} catch (err2) { | ||
} | ||
function usePowerShell() { | ||
$.shell = which.sync("powershell.exe"); | ||
$.prefix = ""; | ||
$.postfix = "; exit $LastExitCode"; | ||
$.quote = quotePowerShell; | ||
} | ||
function useBash() { | ||
$.shell = which.sync("bash"); | ||
$.prefix = "set -euo pipefail;"; | ||
$.quote = quote; | ||
} | ||
function checkShell() { | ||
if (!$.shell) { | ||
throw new Error(`shell is not available: setup guide goes here`); | ||
} | ||
@@ -75,2 +85,3 @@ } | ||
function(pieces, ...args) { | ||
checkShell(); | ||
if (!Array.isArray(pieces)) { | ||
@@ -84,3 +95,3 @@ return function(...args2) { | ||
} | ||
const from = new Error().stack.split(/^\s*at\s/m)[2].trim(); | ||
const from = getCallerLocation(); | ||
if (pieces.some((p) => p == void 0)) { | ||
@@ -93,3 +104,3 @@ throw new Error(`Malformed command at ${from}`); | ||
$.quote, | ||
pieces, | ||
normalizeMultilinePieces(pieces), | ||
args | ||
@@ -128,2 +139,6 @@ ); | ||
); | ||
try { | ||
useBash(); | ||
} catch (err) { | ||
} | ||
var ProcessPromise = class _ProcessPromise extends Promise { | ||
@@ -170,3 +185,3 @@ constructor() { | ||
input, | ||
cmd: $2.prefix + this._command, | ||
cmd: $2.prefix + this._command + $2.postfix, | ||
cwd: $2.cwd ?? $2[processCwd], | ||
@@ -420,3 +435,3 @@ ac: $2.ac, | ||
if (dir instanceof ProcessOutput) { | ||
dir = dir.toString().replace(/\n+$/, ""); | ||
dir = dir.toString().trim(); | ||
} | ||
@@ -482,3 +497,6 @@ $.log({ kind: "cd", dir }); | ||
log, | ||
syncProcessCwd, | ||
useBash, | ||
usePowerShell, | ||
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) |
@@ -17,2 +17,3 @@ import * as _ from './index.js'; | ||
var globby: typeof _.globby; | ||
var kill: typeof _.kill; | ||
var minimist: typeof _.minimist; | ||
@@ -27,5 +28,6 @@ var nothrow: typeof _.nothrow; | ||
var retry: typeof _.retry; | ||
var usePowerShell: typeof _.usePowerShell; | ||
var useBash: typeof _.useBash; | ||
var sleep: typeof _.sleep; | ||
var spinner: typeof _.spinner; | ||
var ssh: typeof _.ssh; | ||
var stdin: typeof _.stdin; | ||
@@ -32,0 +34,0 @@ var which: typeof _.which; |
@@ -143,3 +143,3 @@ // src/goods.ts | ||
clearInterval(id); | ||
process.stderr.write(" ".repeat(process.stdout.columns - 1) + "\r"); | ||
process.stderr.write(" ".repeat((process.stdout.columns || 1) - 1) + "\r"); | ||
} | ||
@@ -146,0 +146,0 @@ return result; |
import { ProcessPromise } from './core.js'; | ||
export * from './core.js'; | ||
export * from './goods.js'; | ||
export { minimist, chalk, fs, which, YAML, ssh, ps } 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, ps } from "./vendor.js"; | ||
import { minimist, chalk, fs, which, YAML, ps } from "./vendor.js"; | ||
import { quote, quotePowerShell } from "./util.js"; | ||
@@ -22,4 +22,3 @@ function nothrow(promise) { | ||
quotePowerShell, | ||
ssh, | ||
which | ||
}; |
export declare function noop(): void; | ||
export declare function randomId(): string; | ||
export declare function isString(obj: any): boolean; | ||
export declare function normalizeMultilinePieces(pieces: TemplateStringsArray): TemplateStringsArray; | ||
export declare function noquote(): string; | ||
export declare function quote(arg: string): string; | ||
@@ -8,4 +10,6 @@ export declare function quotePowerShell(arg: string): 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 { chalk } from "./vendor.js"; | ||
import { chalk, parseLine } from "./vendor.js"; | ||
function noop() { | ||
@@ -11,2 +11,17 @@ } | ||
} | ||
function normalizeMultilinePieces(pieces) { | ||
return Object.assign( | ||
pieces.map( | ||
(p, i) => p.trim() ? parseLine(p).words.map(({ w, e }) => { | ||
if (w === "\\") | ||
return ""; | ||
return w.trim() + (p[e + 1] === " " ? " " : ""); | ||
}).join(" ") : pieces[i] | ||
), | ||
{ raw: pieces.raw } | ||
); | ||
} | ||
function noquote() { | ||
throw new Error("No quote function is defined: https://\xEF.at/no-quote-func"); | ||
} | ||
function quote(arg) { | ||
@@ -195,2 +210,4 @@ if (/^[a-z0-9/_.\-@:=]+$/i.test(arg) || arg === "") { | ||
return +d.slice(0, -2); | ||
} else if (/\d+m/.test(d)) { | ||
return +d.slice(0, -1) * 1e3 * 60; | ||
} | ||
@@ -323,2 +340,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 { | ||
@@ -328,4 +351,8 @@ errnoMessage, | ||
formatCmd, | ||
getCallerLocation, | ||
getCallerLocationFromString, | ||
isString, | ||
noop, | ||
noquote, | ||
normalizeMultilinePieces, | ||
parseDuration, | ||
@@ -332,0 +359,0 @@ quote, |
@@ -5,2 +5,3 @@ // Generated by dts-bundle-generator v9.3.1 | ||
import { parseLine } from '@webpod/ingrid'; | ||
import * as fs from 'fs'; | ||
@@ -378,2 +379,15 @@ import * as cp from 'node:child_process'; | ||
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; | ||
@@ -711,39 +725,2 @@ export interface ChalkInstance { | ||
}; | ||
type Values = (string | string[] | Promise<string> | Promise<string[]>)[]; | ||
type RemoteShell = { | ||
(pieces: TemplateStringsArray, ...values: Values): Promise<Response$1>; | ||
with(config: Partial<SshConfig>): RemoteShell; | ||
exit(): void; | ||
check(): boolean; | ||
test(pieces: TemplateStringsArray, ...values: Values): Promise<boolean>; | ||
cd(path: string): void; | ||
}; | ||
type SshConfig = { | ||
remoteUser: string; | ||
hostname: string; | ||
port?: number | string; | ||
shell: string; | ||
prefix: string; | ||
cwd?: string; | ||
nothrow: boolean; | ||
multiplexing: boolean; | ||
verbose: boolean; | ||
become?: string; | ||
env: Record<string, string>; | ||
ssh: SshOptions; | ||
}; | ||
export declare function ssh(partial: Partial<SshConfig>): RemoteShell; | ||
declare class Response$1 extends String { | ||
readonly command: string; | ||
readonly location: string; | ||
readonly exitCode: number | null; | ||
readonly stdout: string; | ||
readonly stderr: string; | ||
readonly error?: Error | undefined; | ||
constructor(command: string, location: string, exitCode: number | null, stdout: string, stderr: string, error?: Error | undefined); | ||
} | ||
type SshOptions = { | ||
[key in AvailableOptions]?: string; | ||
}; | ||
type AvailableOptions = "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"; | ||
export type RequestInfo = Parameters<typeof fetch$1>[0]; | ||
@@ -771,6 +748,8 @@ type RequestInit$1 = Parameters<typeof fetch$1>[1]; | ||
_default as ps, | ||
depseekSync as depseek, | ||
fetch$1 as nodeFetch, | ||
fs$1 as fs, | ||
parseLine, | ||
}; | ||
export {}; |
{ | ||
"name": "zx", | ||
"version": "7.2.3-dev.cafb90d", | ||
"version": "7.2.3-dev.d79a638", | ||
"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", | ||
@@ -54,4 +50,5 @@ "./core": "./build/core.js", | ||
"test:types": "tsd", | ||
"test:smoke:bun": "bun test ./test/smoke/bun.test.js", | ||
"test:smoke:win32": "node ./test/smoke/win32.test.js", | ||
"coverage": "c8 -x build/vendor.js -x 'test/**' -x scripts --check-coverage npm test", | ||
"mutation": "stryker run", | ||
"circular": "madge --circular src/*", | ||
@@ -65,3 +62,2 @@ "version": "cat package.json | fx .version" | ||
"devDependencies": { | ||
"@stryker-mutator/core": "^6.4.2", | ||
"@types/fs-extra": "^11.0.4", | ||
@@ -72,4 +68,6 @@ "@types/minimist": "^1.2.5", | ||
"@webpod/ps": "^0.0.0-beta.2", | ||
"@webpod/ingrid": "^0.0.0-beta.3", | ||
"c8": "^9.1.0", | ||
"chalk": "^5.3.0", | ||
"depseek": "^0.4.1", | ||
"dts-bundle-generator": "^9.3.1", | ||
@@ -88,3 +86,2 @@ "esbuild": "^0.20.2", | ||
"typescript": "^5.4.3", | ||
"webpod": "^1", | ||
"which": "^4.0.0", | ||
@@ -91,0 +88,0 @@ "yaml": "^2.4.1", |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
846318
21
23592