Skip to content

Commit 8998c8f

Browse files
whxaxesatian25
authored andcommitted
fix: add declarations (#7)
1 parent f618799 commit 8998c8f

File tree

7 files changed

+76
-2
lines changed

7 files changed

+76
-2
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test/fixtures/ts/**/*.js

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ results
1313
node_modules
1414
npm-debug.log
1515
coverage/
16+
test/fixtures/ts/**/*.js

index.d.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { SpawnOptions } from 'child_process';
2+
import { Writable } from 'stream';
3+
4+
declare namespace RunScript {
5+
export interface Options extends SpawnOptions {
6+
stdout?: Writable;
7+
stderr?: Writable;
8+
}
9+
10+
export interface Stdio {
11+
stdout: Buffer | null;
12+
stderr: Buffer | null;
13+
}
14+
15+
export interface StdError extends Error {
16+
stdio: Stdio;
17+
}
18+
}
19+
20+
declare function RunScript(cmd: string, opts?: RunScript.Options): Promise<RunScript.Stdio>;
21+
22+
export = RunScript;

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"description": "Run script easy!",
55
"main": "index.js",
66
"files": [
7-
"index.js"
7+
"index.js",
8+
"index.d.ts"
89
],
910
"scripts": {
1011
"test": "npm run lint && egg-bin test",
@@ -18,11 +19,13 @@
1819
"is-type-of": "^1.1.0"
1920
},
2021
"devDependencies": {
22+
"@types/node": "^12.0.8",
2123
"autod": "*",
2224
"egg-bin": "1",
2325
"egg-ci": "^1.8.0",
2426
"eslint": "3",
25-
"eslint-config-egg": "3"
27+
"eslint-config-egg": "3",
28+
"typescript": "^3.5.1"
2629
},
2730
"homepage": "https://github.com/node-modules/runscript",
2831
"repository": {

test/fixtures/ts/check.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as runscript from '../../../';
2+
import assert = require('assert');
3+
4+
runscript('node -v', { stdio: 'pipe' })
5+
.then(result => {
6+
assert(!result.stderr);
7+
assert(!!result.stdout!.toString());
8+
console.info(result.stdout!.toString());
9+
10+
return runscript('node -h', {
11+
stdio: 'pipe',
12+
stdout: process.stdout,
13+
stderr: process.stderr,
14+
});
15+
})
16+
.catch((err: runscript.StdError) => {
17+
assert(err.stdio);
18+
throw new Error('should not throw');
19+
});

test/fixtures/ts/tsconfig.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"compilerOptions": {
3+
"strict": true,
4+
"target": "es2017",
5+
"module": "commonjs",
6+
"moduleResolution": "node"
7+
}
8+
}

test/runscript.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,26 @@ describe('test/runscript.test.js', () => {
116116
});
117117
});
118118

119+
it('should compile ts without error', () => {
120+
return runScript('tsc -p ./ts/tsconfig.json', {
121+
stdio: 'pipe',
122+
cwd: path.join(__dirname, 'fixtures'),
123+
}).then(stdio => {
124+
assert(!stdio.stderr);
125+
126+
return runScript('node ./ts/check.js', {
127+
stdio: 'pipe',
128+
cwd: path.join(__dirname, 'fixtures'),
129+
}).then(stdio => {
130+
assert(!stdio.stderr);
131+
const stdout = stdio.stdout.toString();
132+
assert(stdout);
133+
assert(stdout.match(/v\d+\.\d+\.\d+/));
134+
assert(stdout.match(/Options:/));
135+
});
136+
});
137+
});
138+
119139
if (process.platform === 'win32') {
120140
it('should run relative path .\\node_modules\\.bin\\autod', () => {
121141
return runScript('.\\node_modules\\.bin\\autod -V', {

0 commit comments

Comments
 (0)