Comparing version 7.0.0 to 7.0.1
@@ -21,2 +21,3 @@ #!/usr/bin/env node | ||
import './globals.js'; | ||
import { updateArgv } from './goods.js'; | ||
import { $, argv, chalk, fetch, ProcessOutput } from './index.js'; | ||
@@ -77,2 +78,3 @@ import { startRepl } from './repl.js'; | ||
} | ||
updateArgv({ sliceAt: 3 }); | ||
await importPath(filepath); | ||
@@ -79,0 +81,0 @@ } |
@@ -23,2 +23,3 @@ /// <reference types="node" resolution-mode="require"/> | ||
}; | ||
export declare const defaults: Options; | ||
export declare const $: Shell & Options; | ||
@@ -25,0 +26,0 @@ declare type Resolve = (out: ProcessOutput) => void; |
@@ -31,25 +31,21 @@ // Copyright 2021 Google LLC | ||
hook.enable(); | ||
function initStore() { | ||
const context = { | ||
[processCwd]: process.cwd(), | ||
verbose: global.ZX_VERBOSE ?? true, | ||
env: process.env, | ||
shell: true, | ||
prefix: '', | ||
quote, | ||
spawn, | ||
log, | ||
}; | ||
storage.enterWith(context); | ||
try { | ||
$.shell = which.sync('bash'); | ||
$.prefix = 'set -euo pipefail;'; | ||
} | ||
catch (err) { | ||
// ¯\_(ツ)_/¯ | ||
} | ||
return context; | ||
export const defaults = { | ||
[processCwd]: process.cwd(), | ||
verbose: true, | ||
env: process.env, | ||
shell: true, | ||
prefix: '', | ||
quote, | ||
spawn, | ||
log, | ||
}; | ||
try { | ||
defaults.shell = which.sync('bash'); | ||
defaults.prefix = 'set -euo pipefail;'; | ||
} | ||
catch (err) { | ||
// ¯\_(ツ)_/¯ | ||
} | ||
function getStore() { | ||
return storage.getStore() || initStore(); | ||
return storage.getStore() || defaults; | ||
} | ||
@@ -285,5 +281,3 @@ export const $ = new Proxy(function (pieces, ...args) { | ||
export function within(callback) { | ||
const result = storage.run({ ...getStore() }, callback); | ||
syncCwd(); | ||
return result; | ||
return storage.run({ ...getStore() }, callback); | ||
} | ||
@@ -290,0 +284,0 @@ function syncCwd() { |
@@ -6,2 +6,5 @@ /// <reference types="node" resolution-mode="require"/> | ||
declare global { | ||
var ProcessPromise: typeof _.ProcessPromise; | ||
var ProcessOutput: typeof _.ProcessOutput; | ||
var log: typeof _.log; | ||
var $: typeof _.$; | ||
@@ -8,0 +11,0 @@ var argv: typeof _.argv; |
@@ -11,3 +11,6 @@ import * as globbyModule from 'globby'; | ||
export { default as os } from 'node:os'; | ||
export declare const argv: minimist.ParsedArgs; | ||
export declare let argv: minimist.ParsedArgs; | ||
export declare function updateArgv(params: { | ||
sliceAt: number; | ||
}): void; | ||
export declare const globby: ((patterns: string | readonly string[], options?: globbyModule.Options) => Promise<string[]>) & typeof globbyModule; | ||
@@ -14,0 +17,0 @@ export declare const glob: ((patterns: string | readonly string[], options?: globbyModule.Options) => Promise<string[]>) & typeof globbyModule; |
@@ -26,3 +26,7 @@ // Copyright 2022 Google LLC | ||
export { default as os } from 'node:os'; | ||
export const argv = minimist(process.argv.slice(2)); | ||
export let argv = minimist(process.argv.slice(2)); | ||
export function updateArgv(params) { | ||
argv = minimist(process.argv.slice(params.sliceAt)); | ||
global.argv = argv; | ||
} | ||
export const globby = Object.assign(function globby(patterns, options) { | ||
@@ -29,0 +33,0 @@ return globbyModule.globby(patterns, options); |
@@ -19,6 +19,5 @@ // Copyright 2022 Google LLC | ||
import { inspect } from 'node:util'; | ||
import { ProcessOutput } from './core.js'; | ||
import { ProcessOutput, defaults } from './core.js'; | ||
export function startRepl() { | ||
; | ||
global.ZX_VERBOSE = false; | ||
defaults.verbose = false; | ||
const r = repl.start({ | ||
@@ -25,0 +24,0 @@ prompt: chalk.greenBright.bold('❯ '), |
{ | ||
"name": "zx", | ||
"version": "7.0.0", | ||
"version": "7.0.1", | ||
"description": "A tool for writing better scripts.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -21,5 +21,5 @@ # 🐚 zx | ||
Bash is great, but when it comes to writing scripts, | ||
people usually choose a more convenient programming language. | ||
JavaScript is a perfect choice, but standard Node.js library | ||
Bash is great, but when it comes to writing more complex scripts, | ||
many people prefer a more convenient programming language. | ||
JavaScript is a perfect choice, but the Node.js standard library | ||
requires additional hassle before using. The `zx` package provides | ||
@@ -45,4 +45,4 @@ useful wrappers around `child_process`, escapes arguments and | ||
Write your scripts in a file with `.mjs` extension in order to | ||
be able to use `await` on top level. If you prefer the `.js` extension, | ||
Write your scripts in a file with an `.mjs` extension in order to | ||
use `await` at the top level. If you prefer the `.js` extension, | ||
wrap your scripts in something like `void async function () {...}()`. | ||
@@ -67,4 +67,4 @@ | ||
All functions (`$`, `cd`, `fetch`, etc) are available straight away | ||
without any imports. | ||
All functions (`$`, `cd`, `fetch`, etc) are available straight away | ||
without any imports. | ||
@@ -79,3 +79,3 @@ Or import globals explicitly (for better autocomplete in VS Code). | ||
Executes a given command using the `spawn` func | ||
Executes a given command using the `spawn` func | ||
and returns [`ProcessPromise`](#processpromise). | ||
@@ -90,3 +90,3 @@ | ||
**There is no need to add extra quotes.** Read more about it in | ||
**There is no need to add extra quotes.** Read more about it in | ||
[quotes](docs/quotes.md). | ||
@@ -146,3 +146,3 @@ | ||
The output of the process is captured as is. Usually, programs print a new line `\n` at the end. | ||
The output of the process is captured as-is. Usually, programs print a new line `\n` at the end. | ||
If `ProcessOutput` is used as an argument to some other `$` process, | ||
@@ -220,3 +220,3 @@ **zx** will use stdout and trim the new line. | ||
cd('/tmp') | ||
setTimeout(async () => { | ||
@@ -230,3 +230,3 @@ await $`pwd` // => /tmp | ||
```js | ||
```js | ||
let version = await within(async () => { | ||
@@ -237,7 +237,7 @@ $.prefix += 'export NVM_DIR=$HOME/.nvm; source $NVM_DIR/nvm.sh; ' | ||
}) | ||
```` | ||
``` | ||
## Packages | ||
Following packages are available without importing inside scripts. | ||
The following packages are available without importing inside scripts. | ||
@@ -335,3 +335,3 @@ ### `chalk` package | ||
Specifies a function for escaping special characters during | ||
Specifies a function for escaping special characters during | ||
command substitution. | ||
@@ -343,6 +343,6 @@ | ||
In verbose mode, the `zx` prints all executed commands alongside with their | ||
In verbose mode, `zx` prints all executed commands alongside with their | ||
outputs. | ||
Or use a CLI argument `--quiet` to set `$.verbose = false`. | ||
Or use the CLI argument `--quiet` to set `$.verbose = false`. | ||
@@ -366,3 +366,3 @@ ### `$.env` | ||
## Polyfills | ||
## Polyfills | ||
@@ -388,3 +388,3 @@ ### `__filename` & `__dirname` | ||
The zx also provides a few experimental functions. Please leave a feedback about | ||
The zx provides a few experimental functions. Please leave feedback about | ||
those features in [the discussion](https://github.com/google/zx/discussions/299). | ||
@@ -434,3 +434,3 @@ To enable new features via CLI pass `--experimental` flag. | ||
If array of values passed as argument to `$`, items of the array will be escaped | ||
When passing an array of values as an argument to `$`, items of the array will be escaped | ||
individually and concatenated via space. | ||
@@ -444,3 +444,3 @@ | ||
### Importing from other scripts | ||
### Importing into other scripts | ||
@@ -463,4 +463,3 @@ It is possible to make use of `$` and other functions via explicit imports: | ||
The `zx` can execute scripts written in markdown | ||
([docs/markdown.md](docs/markdown.md)): | ||
The `zx` can execute [scripts written as markdown](docs/markdown.md): | ||
@@ -472,6 +471,6 @@ ```bash | ||
### TypeScript scripts | ||
```ts | ||
import {$} from 'zx' | ||
// Or | ||
// Or | ||
import 'zx/globals' | ||
@@ -484,4 +483,4 @@ | ||
Set [`"type": "module"`](https://nodejs.org/api/packages.html#packages_type) | ||
in **package.json** and [`"module": "ESNext"`](https://www.typescriptlang.org/tsconfig/#module) | ||
Set [`"type": "module"`](https://nodejs.org/api/packages.html#packages_type) | ||
in **package.json** and [`"module": "ESNext"`](https://www.typescriptlang.org/tsconfig/#module) | ||
in **tsconfig.json**. | ||
@@ -518,3 +517,3 @@ | ||
By default `child_process` does not include aliases and bash functions. | ||
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`. | ||
@@ -529,3 +528,3 @@ | ||
Default GitHub Action runner comes with npx installed. | ||
The default GitHub Action runner comes with `npx` installed. | ||
@@ -532,0 +531,0 @@ ```yaml |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
65434
1237
1
532