Skip to content

Commit 7e5ad20

Browse files
author
Gerard Delmàs
committed
use await with promisified node callback
1 parent e2a4769 commit 7e5ad20

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/DtsContent.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import * as os from "os";
33
import * as path from "path";
44
import isThere from "is-there";
55
import * as mkdirp from 'mkdirp';
6+
import * as util from "util";
7+
8+
const writeFile = util.promisify(fs.writeFile);
69

710

811
interface DtsContentOptions {
@@ -65,20 +68,13 @@ export class DtsContent {
6568
return path.join(this.rootDir, this.searchDir, this.rInputPath);
6669
}
6770

68-
public writeFile(): Promise<DtsContent> {
71+
public async writeFile(): Promise<void> {
6972
var outPathDir = path.dirname(this.outputFilePath);
7073
if(!isThere(outPathDir)) {
7174
mkdirp.sync(outPathDir);
7275
}
73-
return new Promise((resolve, reject) => {
74-
fs.writeFile(this.outputFilePath, this.formatted, 'utf8', (err) => {
75-
if(err) {
76-
reject(err);
77-
}else{
78-
resolve(this);
79-
}
80-
});
81-
});
76+
77+
await writeFile(this.outputFilePath, this.formatted, 'utf8');
8278
}
8379
}
8480

0 commit comments

Comments
 (0)