Socket
Socket
Sign inDemoInstall

zx

Package Overview
Dependencies
53
Maintainers
2
Versions
113
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 7.1.0-dev.6f7b331 to 7.1.0-dev.962864d

22

build/cli.js

@@ -38,8 +38,8 @@ #!/usr/bin/env node

--prefix=<command> prefix all commands
--interactive, -i start repl
--eval=<js>, -e evaluate script
--experimental enable new api proposals
--install parse and load script dependencies from the registry
--install, -i install dependencies
--experimental enable experimental features
--version, -v print current zx version
--help, -h print help
--repl start repl
`);

@@ -49,11 +49,4 @@ }

string: ['shell', 'prefix', 'eval'],
boolean: [
'version',
'help',
'quiet',
'install',
'interactive',
'experimental',
],
alias: { e: 'eval', i: 'interactive', v: 'version', h: 'help' },
boolean: ['version', 'help', 'quiet', 'install', 'repl', 'experimental'],
alias: { e: 'eval', i: 'install', v: 'version', h: 'help' },
stopEarly: true,

@@ -81,3 +74,3 @@ });

}
if (argv.interactive) {
if (argv.repl) {
startRepl();

@@ -95,3 +88,3 @@ return;

if (!success)
startRepl();
printUsage();
return;

@@ -169,3 +162,2 @@ }

const deps = parseDeps(await fs.readFile(filepath));
console.log('Installing dependencies...', deps);
await installDeps(deps, dirname(filepath));

@@ -172,0 +164,0 @@ }

@@ -20,3 +20,3 @@ // Copyright 2021 Google LLC

import which from 'which';
import { errnoMessage, exitCodeInfo, formatCmd, noop, parseDuration, psTree, quote, } from './util.js';
import { errnoMessage, exitCodeInfo, formatCmd, noop, parseDuration, psTree, quote, quotePowerShell, } from './util.js';
const processCwd = Symbol('processCwd');

@@ -38,3 +38,5 @@ const storage = new AsyncLocalStorage();

prefix: '',
quote,
quote: () => {
throw new Error('No quote function is defined: https://ï.at/no-quote-func');
},
spawn,

@@ -44,9 +46,11 @@ log,

try {
if (process.platform !== 'win32') {
defaults.shell = which.sync('bash');
defaults.prefix = 'set -euo pipefail;';
}
defaults.shell = which.sync('bash');
defaults.prefix = 'set -euo pipefail;';
defaults.quote = quote;
}
catch (err) {
// ¯\_(ツ)_/¯
if (process.platform == 'win32') {
defaults.shell = which.sync('powershell.exe');
defaults.quote = quotePowerShell;
}
}

@@ -53,0 +57,0 @@ function getStore() {

@@ -15,2 +15,3 @@ // Copyright 2021 Google LLC

import { $ } from './core.js';
import { spinner } from './experimental.js';
export async function installDeps(dependencies, prefix) {

@@ -22,3 +23,3 @@ const packages = Object.entries(dependencies).map(([name, version]) => `${name}@${version}`);

}
await $ `npm install --no-save --no-audit --no-fund ${flags} ${packages}`;
await spinner(`npm i ${packages.join(' ')}`, () => $ `npm install --no-save --no-audit --no-fund ${flags} ${packages}`.nothrow());
}

@@ -94,18 +95,5 @@ const builtins = new Set([

for (let line of lines) {
for (let re of importRe) {
const m1 = re.exec(line);
if (m1 && m1.groups) {
const m2 = nameRe.exec(m1.groups.path);
if (m2 && m2.groups) {
const name = m2.groups.name;
if (!builtins.has(name)) {
let version = 'latest';
const m3 = versionRe.exec(line);
if (m3 && m3.groups) {
version = m3.groups.version;
}
deps[name] = version;
}
}
}
const tuple = parseImports(line);
if (tuple) {
deps[tuple.name] = tuple.version;
}

@@ -115,1 +103,21 @@ }

}
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) {
if (!path)
return;
const name = nameRe.exec(path)?.groups?.name;
if (name && !builtins.has(name)) {
return name;
}
}
function parseVersion(line) {
return versionRe.exec(line)?.groups?.version || 'latest';
}

@@ -7,2 +7,3 @@ import psTreeModule from 'ps-tree';

export declare function quote(arg: string): string;
export declare function quotePowerShell(arg: string): string;
export declare function exitCodeInfo(exitCode: number | null): string | undefined;

@@ -9,0 +10,0 @@ export declare function errnoMessage(errno: number | undefined): string;

@@ -41,2 +41,8 @@ // Copyright 2022 Google LLC

}
export function quotePowerShell(arg) {
if (/^[a-z0-9/_.\-]+$/i.test(arg) || arg === '') {
return arg;
}
return `'` + arg.replace(/'/g, "''") + `'`;
}
export function exitCodeInfo(exitCode) {

@@ -43,0 +49,0 @@ return {

{
"name": "zx",
"version": "7.1.0-dev.6f7b331",
"version": "7.1.0-dev.962864d",
"description": "A tool for writing better scripts.",

@@ -55,3 +55,3 @@ "type": "module",

"@types/minimist": "^1.2.2",
"@types/node": "^18.7.18",
"@types/node": "^18.7.20",
"@types/ps-tree": "^1.1.2",

@@ -86,3 +86,4 @@ "@types/which": "^2.0.1",

"semi": false,
"singleQuote": true
"singleQuote": true,
"endOfLine": "lf"
},

@@ -89,0 +90,0 @@ "repository": "google/zx",

@@ -353,4 +353,19 @@ # 🐚 zx

Specifies a [logging function](src/log.ts).
Specifies a [logging function](src/core.ts).
```ts
import { LogEntry, log } from 'zx/core'
$.log = (entry: LogEntry) => {
switch (entry.kind) {
case 'cmd':
// for example, apply custom data masker for cmd printing
process.stderr.write(masker(entry.cmd))
break
default:
log(entry)
}
}
```
## Polyfills

@@ -411,24 +426,2 @@

## CLI
| Flag | Description | Default |
|-----------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|
| `--quiet` | don't echo commands | `false` |
| `--shell=<path>` | custom shell binary | |
| `--prefix=<command>` | prefix all commands | |
| `--interactive, -i` | start repl | |
| `--eval=<js>, -e` | evaluate script | |
| `--experimental` | enable new api proposals | |
| `--install` | parse and load script dependencies from the registry. You can pass additional [params via env vars](https://docs.npmjs.com/cli/v8/using-npm/config) like `npm_config_registry=<url>` or `npm_config_userconfig=<path>`. | `false` |
| `--version, -v` | print current zx version | |
| `--help, -h` | print help | |
```bash
zx script.js
zx --help
zx --experimental <<'EOF'
await $`pwd`
EOF
```
## FAQ

@@ -521,6 +514,29 @@

### Installing dependencies via --install
```js
// script.mjs:
import sh from 'tinysh'
sh.say('Hello, world!')
```
Add `--install` flag to the `zx` command to install missing dependencies
automatically.
```bash
zx --install script.mjs
```
You can also specify needed version by adding comment with `@` after
the import.
```js
import sh from 'tinysh' // @^1
```
### Attaching a profile
By default `child_process` does not include aliases and bash functions.
But you are still able to do it by hand. Just attach necessary directives to `$.prefix`.
But you are still able to do it by hand. Just attach necessary directives
to the `$.prefix`.

@@ -552,2 +568,9 @@ ```js

### Canary / Beta / RC builds
Impatient early adopters can try the experimental zx versions. But keep in mind: these builds are ⚠️️ __unstable__ in every sense.
```bash
npm i zx@dev
npx zx@dev --install --quiet <<< 'import _ from "lodash" /* 4.17.15 */; console.log(_.VERSION)'
```
## License

@@ -554,0 +577,0 @@

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