File tree Expand file tree Collapse file tree 3 files changed +32
-10
lines changed Expand file tree Collapse file tree 3 files changed +32
-10
lines changed Original file line number Diff line number Diff line change 1- import * as fs from "fs" ;
21import * as os from "os" ;
32import * as path from "path" ;
43import isThere from "is-there" ;
54import * 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
118interface 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
Original file line number Diff line number Diff line change 11/* this file is forked from https://raw.githubusercontent.com/css-modules/css-modules-loader-core/master/src/file-system-loader.js */
22
33import Core from 'css-modules-loader-core'
4- import * as fs from 'fs'
54import * as path from 'path'
6- import * as util from 'util'
75import { Plugin } from "postcss" ;
6+ import { readFile } from "./fs" ;
87
98
109type Dictionary < T > = {
1110 [ key : string ] : T | undefined ;
1211} ;
1312
14- const readFile = util . promisify ( fs . readFile ) ;
15-
1613
1714export 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 !== '/' ) {
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments