Skip to content

Commit

Permalink
Add zx/globals
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmedv committed Aug 31, 2021
1 parent f0b6c21 commit 49d4868
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 5 deletions.
29 changes: 29 additions & 0 deletions globals.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {
$,
argv as _argv,
cd,
chalk as _chalk,
fetch as _fetch,
fs as _fs,
globby as _globby,
nothrow,
os as _os,
question,
sleep,
} from '.'

declare global {
var $: $
var argv: typeof _argv
var cd: cd
var chalk: typeof _chalk
// @ts-ignore
var fetch: typeof _fetch
var fs: typeof _fs
var globby: typeof _globby.globby & typeof _globby
var glob: typeof _globby.globby & typeof _globby
var nothrow: nothrow
var os: typeof _os
var question: question
var sleep: sleep
}
3 changes: 3 additions & 0 deletions globals.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {registerGlobals} from './index.mjs'

registerGlobals()
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface ProcessPromise<T> extends Promise<T> {
readonly exitCode: Promise<number>

pipe(dest: ProcessPromise<ProcessOutput> | Writable): ProcessPromise<ProcessOutput>

kill(signal?: string | number): Promise<void>
}

Expand Down
1 change: 0 additions & 1 deletion test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ import {strict as assert, deepEqual} from 'assert'
assert(typeof globby.isDynamicPattern === 'function')
assert(typeof globby.isGitIgnored === 'function')
assert(typeof globby.isGitIgnoredSync === 'function')
deepEqual(await globby('*.mjs'), ['index.mjs', 'test.mjs', 'zx.mjs'])
console.log(chalk.greenBright('globby available'))
}

Expand Down
9 changes: 5 additions & 4 deletions zx.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ import {tmpdir} from 'os'
import fs from 'fs-extra'
import {createRequire} from 'module'
import url from 'url'
import {$, fetch, ProcessOutput, argv, registerGlobals} from './index.mjs'
import {$, fetch, ProcessOutput, argv} from './index.mjs'

registerGlobals()
import './globals.mjs'

try {
if (argv.version || argv.v || argv.V) {
console.log(`zx version ${createRequire(import.meta.url)('./package.json').version}`)
process.exit(0)
}
let firstArg = process.argv.slice(2).find(a => !a.startsWith('--'));
let firstArg = process.argv.slice(2).find(a => !a.startsWith('--'))
if (typeof firstArg === 'undefined' || firstArg === '-') {
let ok = await scriptFromStdin()
if (!ok) {
Expand Down Expand Up @@ -199,7 +199,8 @@ async function compile(input) {
$.verbose = false
let tsc = $`npm_config_yes=true npx -p typescript tsc --target esnext --lib esnext --module commonjs --moduleResolution node ${input}`
$.verbose = v
let i= 0, spinner = setInterval(() => process.stdout.write(` ${'⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏'[i++ % 10]}\r`), 100)
let i = 0,
spinner = setInterval(() => process.stdout.write(` ${'⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏'[i++ % 10]}\r`), 100)
try {
await tsc
} catch (err) {
Expand Down

0 comments on commit 49d4868

Please sign in to comment.