diff --git a/README.md b/README.md index 18d1f98..1b50f3c 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ live(command [, options] [, callback]) => statusCode Synchronous usage: ```js -const { live } = require('shelljs-live') +const live = require('shelljs-live') const statusCode = live(['ps', '-ax']) // live('ps -ax') works too. not recommended if (statusCode === 0) { @@ -45,7 +45,7 @@ if (statusCode === 0) { Asynchronous usage: ```js -const { live } = require('shelljs-live') +const live = require('shelljs-live') live(['ps', '-ax'], (statusCode) => { if (statusCode === 0) { @@ -71,7 +71,7 @@ live(command [, options]) => promise Usage: ```js -const { live } = require('shelljs-live/promise') +const live = require('shelljs-live/promise') live(['ps', '-ax']).then(() => { console.log('Success') @@ -83,7 +83,7 @@ live(['ps', '-ax']).then(() => { Or if you want to use `await` and don't care about handling errors: ```js -const { live } = require('shelljs-live/promise') +const live = require('shelljs-live/promise') await live(['ps', '-ax']) console.log('Success') diff --git a/src/index.ts b/src/index.ts index 2900f1f..cd3e96c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,19 +1,16 @@ import { SpawnOptions } from 'child_process' -import * as spawn from 'cross-spawn' +import spawn from 'cross-spawn' import { config } from 'shelljs' -import { parseCommand, buildErrorMessage } from './utils' +import { Options, Callback, parseCommand, buildErrorMessage } from './utils' -export type Options = SpawnOptions & { async?: boolean, fatal?: boolean, silent?: boolean } -export type Callback = (status: number | null) => void - -export function live(command: string | string[], options?: Options): number | null -export function live(command: string | string[], callback: Callback): number | null -export function live( +function live(command: string | string[], options?: Options): number | null +function live(command: string | string[], callback: Callback): number | null +function live( command: string | string[], options: Options | undefined, callback: Callback, ): number | null -export function live( +function live( command: string | string[], optionsOrCallback?: Options | Callback, callback?: Callback, @@ -62,3 +59,5 @@ export function live( return status } } + +export = live diff --git a/src/promise.ts b/src/promise.ts index 517538a..e073c31 100644 --- a/src/promise.ts +++ b/src/promise.ts @@ -1,7 +1,7 @@ -import { live as origLive, Options } from './' -import { parseCommand, buildErrorMessage } from './utils' +import origLive from './' +import { Options, parseCommand, buildErrorMessage } from './utils' -export function live(command: string | string[], options?: Options): Promise { +function live(command: string | string[], options?: Options): Promise { return new Promise((resolve, reject) => { origLive(command, options, (status) => { if (status === 0) { @@ -14,4 +14,4 @@ export function live(command: string | string[], options?: Options): Promise void export function parseCommand(command: string | string[]): [string, string[], boolean] { return Array.isArray(command) diff --git a/test.js b/test.js index 30516c7..0d93071 100644 --- a/test.js +++ b/test.js @@ -1,8 +1,8 @@ const yargs = require('yargs/yargs') const { hideBin } = require('yargs/helpers') const shell = require('shelljs') -const { live } = require('./dist/index') -const { live: promiseLive } = require('./dist/promise') +const live = require('./dist/index') +const promiseLive = require('./dist/promise') const argv = yargs(hideBin(process.argv)).argv shell.config.silent = Boolean(argv.silent) diff --git a/tsconfig.json b/tsconfig.json index a972eed..c4c95c6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,6 +4,7 @@ "target": "ES2019", "module": "CommonJS", "moduleResolution": "Node", + "esModuleInterop": true, "declaration": true, "rootDir": "src", "outDir": "dist"