Skip to content

Commit

Permalink
fix: export runscript function (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 authored Dec 10, 2024
1 parent 651b248 commit 70395b2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ npm install runscript

## Quick start

Commonjs

```js
const { runScript } = require('runscript');

Expand All @@ -38,6 +40,20 @@ runScript('node -v', { stdio: 'pipe' })
});
```

ESM & TypeScript

```js
import { runScript } from 'runscript';

runScript('node -v', { stdio: 'pipe' })
.then(stdio => {
console.log(stdio);
})
.catch(err => {
console.error(err);
});
```

### run with timeout

Run user script for a maximum of 10 seconds.
Expand All @@ -54,6 +70,16 @@ runScript('node user-script.js', { stdio: 'pipe' }, { timeout: 10000 })
});
```

## Upgrade from 1.x to 2.x

```js
// 1.x
// const runscript = require('runscript');

// 2.x
const { runscript } = require('runscript');
```

## License

[MIT](LICENSE.txt)
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,5 @@ export function runScript(script: string, options: Options = {}, extraOptions: E
}
});
}

export const runscript = runScript;
6 changes: 5 additions & 1 deletion test/runscript.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import fs from 'node:fs';
import { strict as assert } from 'node:assert';
import { runScript, RunScriptTimeoutError } from '../src/index.js';
import { runscript, runScript, RunScriptTimeoutError } from '../src/index.js';
import { getFixtures } from './helper.js';

describe('test/runscript.test.ts', () => {
it('should run `$ node -v`', () => {
return runScript('node -v');
});

it('should support alias runscript function', () => {
return runscript('node -v');
});

it('should run `$ npm -v`', () => {
return runScript('npm -v');
});
Expand Down

0 comments on commit 70395b2

Please sign in to comment.