Skip to content

Commit

Permalink
remove 'fs.promises' experimental feature call.
Browse files Browse the repository at this point in the history
  • Loading branch information
shellyln committed Sep 12, 2018
1 parent eb9984f commit 795c62d
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions packages/red-agate/src/red-agate/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const requireDynamic = isNode ? eval("require") : void 0;
export class HtmlRenderer {
private static async writeToTempFile(html: string, tmpPath: string) {
const path = requireDynamic('path');
const fs = requireDynamic('fs');
const fs = requireDynamic('fs');
const util = requireDynamic('util');

for (let i = 0; i < 3; i++) {
let tmp = tmpPath;
Expand All @@ -35,18 +36,18 @@ export class HtmlRenderer {
let url = '';
const tmpFullPath = path.resolve(tmp);

const fd = await fs.promises.open(tmpFullPath, 'ax');
const fd = await util.promisify(fs.open)(tmpFullPath, 'ax');

try {
await fs.promises.writeFile(fd, html, 'utf8');
await util.promisify(fs.writeFile)(fd, html, 'utf8');
let p = encodeURI(tmpFullPath.replace(/\\/g, '/'));
if (! p.startsWith('/')) {
// Windows absolute paths except UNC paths.
p = '/' + p;
}
url = 'file://' + p;
} finally {
await fd.close();
await util.promisify(fs.close)(fd);
}

return { tmpFullPath, url };
Expand Down Expand Up @@ -90,8 +91,9 @@ export class HtmlRenderer {
} catch (e) {}
try {
if (tmpPath && tmpFullPath) {
const fs = requireDynamic('fs');
await fs.promises.unlink(tmpFullPath);
const fs = requireDynamic('fs');
const util = requireDynamic('util');
await util.promisify(fs.unlink)(tmpFullPath);
}
} catch (e) {}
}
Expand Down Expand Up @@ -151,8 +153,9 @@ export class HtmlRenderer {
} catch (e) {}
try {
if (tmpPath && tmpFullPath) {
const fs = requireDynamic('fs');
await fs.promises.unlink(tmpFullPath);
const fs = requireDynamic('fs');
const util = requireDynamic('util');
await util.promisify(fs.unlink)(tmpFullPath);
}
} catch (e) {}
}
Expand Down

0 comments on commit 795c62d

Please sign in to comment.