Skip to content

Commit 7d4049f

Browse files
author
Gerard Delmàs
committed
support node 6
1 parent 48fda1d commit 7d4049f

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

src/DtsContent.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import * as fs from "fs";
21
import * as os from "os";
32
import * as path from "path";
43
import isThere from "is-there";
54
import * as mkdirp from 'mkdirp';
6-
import * as util from "util";
7-
8-
const writeFile = util.promisify(fs.writeFile);
5+
import {writeFile} from "./fs";
96

107

118
interface DtsContentOptions {
@@ -74,7 +71,7 @@ export class DtsContent {
7471
mkdirp.sync(outPathDir);
7572
}
7673

77-
await writeFile(this.outputFilePath, this.formatted, 'utf8');
74+
await writeFile(this.outputFilePath, this.formatted);
7875
}
7976
}
8077

src/FileSystemLoader.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
/* this file is forked from https://raw.githubusercontent.com/css-modules/css-modules-loader-core/master/src/file-system-loader.js */
22

33
import Core from 'css-modules-loader-core'
4-
import * as fs from 'fs'
54
import * as path from 'path'
6-
import * as util from 'util'
75
import { Plugin } from "postcss";
6+
import {readFile} from "./fs";
87

98

109
type Dictionary<T> = {
1110
[key: string]: T | undefined;
1211
};
1312

14-
const readFile = util.promisify(fs.readFile);
15-
1613

1714
export default class FileSystemLoader {
1815
private root: string;
@@ -54,7 +51,7 @@ export default class FileSystemLoader {
5451
}
5552

5653
try {
57-
source = await readFile(fileRelativePath, "utf-8");
54+
source = await readFile(fileRelativePath);
5855
}
5956
catch (error) {
6057
if (relativeTo && relativeTo !== '/') {

src/fs.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import * as fs from 'fs';
2+
3+
4+
export function readFile(path: fs.PathLike): Promise<string> {
5+
return new Promise<string>((resolve, reject) => {
6+
fs.readFile(path, 'utf-8', (err, data) => {
7+
if (err !== null) {
8+
reject(err);
9+
return;
10+
}
11+
12+
resolve(data);
13+
});
14+
});
15+
}
16+
17+
export function writeFile(path: fs.PathLike, data: string): Promise<void> {
18+
return new Promise<void>((resolve, reject) => {
19+
fs.writeFile(path, data, 'utf-8', (err) => {
20+
if (err !== null) {
21+
reject(err);
22+
return;
23+
}
24+
25+
resolve();
26+
});
27+
});
28+
}

0 commit comments

Comments
 (0)