Skip to content

Commit 479b6b1

Browse files
committed
fix: export function instead of exports
1 parent c89e5bc commit 479b6b1

File tree

1 file changed

+26
-75
lines changed

1 file changed

+26
-75
lines changed

lib/fs.ts

Lines changed: 26 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const fsPromises = fs.promises;
1010

1111
const rEOL = /\r\n/g;
1212

13-
function exists(path: string) {
13+
export function exists(path: string) {
1414
if (!path) throw new TypeError('path is required!');
1515
const promise = fsPromises.access(path).then(() => true, error => {
1616
if (error.code !== 'ENOENT') throw error;
@@ -20,7 +20,7 @@ function exists(path: string) {
2020
return BlueBirdPromise.resolve(promise);
2121
}
2222

23-
function existsSync(path: string) {
23+
export function existsSync(path: string) {
2424
if (!path) throw new TypeError('path is required!');
2525

2626
try {
@@ -33,13 +33,13 @@ function existsSync(path: string) {
3333
return true;
3434
}
3535

36-
function mkdirs(path: string) {
36+
export function mkdirs(path: string) {
3737
if (!path) throw new TypeError('path is required!');
3838

3939
return BlueBirdPromise.resolve(fsPromises.mkdir(path, { recursive: true }));
4040
}
4141

42-
function mkdirsSync(path: string) {
42+
export function mkdirsSync(path: string) {
4343
if (!path) throw new TypeError('path is required!');
4444

4545
fs.mkdirSync(path, { recursive: true });
@@ -49,7 +49,7 @@ function checkParent(path: string) {
4949
return BlueBirdPromise.resolve(fsPromises.mkdir(dirname(path), { recursive: true }));
5050
}
5151

52-
function writeFile(
52+
export function writeFile(
5353
path: string,
5454
data: any,
5555
options?: WriteFileOptions
@@ -63,14 +63,14 @@ function writeFile(
6363
}
6464

6565

66-
function writeFileSync(path: string, data: any, options?: WriteFileOptions) {
66+
export function writeFileSync(path: string, data: any, options?: WriteFileOptions) {
6767
if (!path) throw new TypeError('path is required!');
6868

6969
fs.mkdirSync(dirname(path), { recursive: true });
7070
fs.writeFileSync(path, data, options);
7171
}
7272

73-
function appendFile(
73+
export function appendFile(
7474
path: string,
7575
data: any,
7676
options?: WriteFileOptions) {
@@ -80,14 +80,14 @@ function appendFile(
8080
.then(() => fsPromises.appendFile(path, data, options));
8181
}
8282

83-
function appendFileSync(path: string, data: any, options?: WriteFileOptions) {
83+
export function appendFileSync(path: string, data: any, options?: WriteFileOptions) {
8484
if (!path) throw new TypeError('path is required!');
8585

8686
fs.mkdirSync(dirname(path), { recursive: true });
8787
fs.appendFileSync(path, data, options);
8888
}
8989

90-
function copyFile(
90+
export function copyFile(
9191
src: string, dest: string, flags?: number) {
9292
if (!src) throw new TypeError('src is required!');
9393
if (!dest) throw new TypeError('dest is required!');
@@ -156,7 +156,7 @@ async function _copyDirWalker(
156156
});
157157
}
158158

159-
function copyDir(
159+
export function copyDir(
160160
src: string, dest: string, options: ReadDirOptions = {}) {
161161
if (!src) throw new TypeError('src is required!');
162162
if (!dest) throw new TypeError('dest is required!');
@@ -186,7 +186,7 @@ async function _listDirWalker(
186186
await BlueBirdPromise.all(promises);
187187
}
188188

189-
function listDir(
189+
export function listDir(
190190
path: string, options: ReadDirOptions = {}) {
191191
if (!path) throw new TypeError('path is required!');
192192

@@ -209,7 +209,7 @@ function _listDirSyncWalker(
209209
}
210210
}
211211

212-
function listDirSync(path: string, options: ReadDirOptions = {}) {
212+
export function listDirSync(path: string, options: ReadDirOptions = {}) {
213213
if (!path) throw new TypeError('path is required!');
214214
const results = [];
215215

@@ -218,15 +218,15 @@ function listDirSync(path: string, options: ReadDirOptions = {}) {
218218
return results;
219219
}
220220

221-
function escapeEOL(str: string) {
221+
export function escapeEOL(str: string) {
222222
return str.replace(rEOL, '\n');
223223
}
224224

225-
function escapeBOM(str: string) {
225+
export function escapeBOM(str: string) {
226226
return str.charCodeAt(0) === 0xFEFF ? str.substring(1) : str;
227227
}
228228

229-
function escapeFileContent(content) {
229+
export function escapeFileContent(content) {
230230
return escapeBOM(escapeEOL(content));
231231
}
232232

@@ -245,14 +245,14 @@ async function _readFile(path: string, options: ReadFileOptions | null = {}) {
245245
return content;
246246
}
247247

248-
function readFile(
248+
export function readFile(
249249
path: string, options?: ReadFileOptions | null) {
250250
if (!path) throw new TypeError('path is required!');
251251

252252
return BlueBirdPromise.resolve(_readFile(path, options));
253253
}
254254

255-
function readFileSync(path: string, options: ReadFileOptions = {}) {
255+
export function readFileSync(path: string, options: ReadFileOptions = {}) {
256256
if (!path) throw new TypeError('path is required!');
257257

258258
if (!Object.prototype.hasOwnProperty.call(options,
@@ -293,7 +293,7 @@ async function _emptyDir(
293293
return results;
294294
}
295295

296-
function emptyDir(
296+
export function emptyDir(
297297
path: string, options: ReadDirOptions & { exclude?: any[] } = {}) {
298298
if (!path) throw new TypeError('path is required!');
299299

@@ -329,7 +329,7 @@ function _emptyDirSync(
329329
return results;
330330
}
331331

332-
function emptyDirSync(
332+
export function emptyDirSync(
333333
path: string, options: ReadDirOptions & { exclude?: any[] } = {}) {
334334
if (!path) throw new TypeError('path is required!');
335335

@@ -347,7 +347,7 @@ async function _rmdir(path: string) {
347347
return fsPromises.rmdir(path);
348348
}
349349

350-
function rmdir(path: string) {
350+
export function rmdir(path: string) {
351351
if (!path) throw new TypeError('path is required!');
352352

353353
return BlueBirdPromise.resolve(_rmdir(path));
@@ -370,13 +370,13 @@ function _rmdirSync(path: string) {
370370
fs.rmdirSync(path);
371371
}
372372

373-
function rmdirSync(path: string) {
373+
export function rmdirSync(path: string) {
374374
if (!path) throw new TypeError('path is required!');
375375

376376
_rmdirSync(path);
377377
}
378378

379-
function watch(
379+
export function watch(
380380
path: string | ReadonlyArray<string>, options?: WatchOptions) {
381381
if (!path) throw new TypeError('path is required!');
382382

@@ -416,13 +416,13 @@ async function _ensurePath(path: string): Promise<string> {
416416
return _findUnusedPath(path, files);
417417
}
418418

419-
function ensurePath(path: string) {
419+
export function ensurePath(path: string) {
420420
if (!path) throw new TypeError('path is required!');
421421

422422
return BlueBirdPromise.resolve(_ensurePath(path));
423423
}
424424

425-
function ensurePathSync(path: string) {
425+
export function ensurePathSync(path: string) {
426426
if (!path) throw new TypeError('path is required!');
427427
if (!fs.existsSync(path)) return path;
428428

@@ -431,7 +431,7 @@ function ensurePathSync(path: string) {
431431
return _findUnusedPath(path, files);
432432
}
433433

434-
function ensureWriteStream(path: string, options?: string | {
434+
export function ensureWriteStream(path: string, options?: string | {
435435
flags?: string;
436436
encoding?: string;
437437
fd?: number;
@@ -447,7 +447,7 @@ function ensureWriteStream(path: string, options?: string | {
447447
.then(() => fs.createWriteStream(path, options));
448448
}
449449

450-
function ensureWriteStreamSync(path: string, options?: string | {
450+
export function ensureWriteStreamSync(path: string, options?: string | {
451451
flags?: string;
452452
encoding?: string;
453453
fd?: number;
@@ -475,10 +475,6 @@ function ensureWriteStreamSync(path: string, options?: string | {
475475
exports.access = BlueBirdPromise.promisify(fs.access);
476476
exports.accessSync = fs.accessSync;
477477

478-
// appendFile
479-
exports.appendFile = appendFile;
480-
exports.appendFileSync = appendFileSync;
481-
482478
// chmod
483479
exports.chmod = BlueBirdPromise.promisify(fs.chmod);
484480
exports.chmodSync = fs.chmodSync;
@@ -499,30 +495,10 @@ exports.lchownSync = fs.lchownSync;
499495
exports.close = BlueBirdPromise.promisify(fs.close);
500496
exports.closeSync = fs.closeSync;
501497

502-
// copy
503-
exports.copyDir = copyDir;
504-
exports.copyFile = copyFile;
505-
506498
// createStream
507499
exports.createReadStream = fs.createReadStream;
508500
exports.createWriteStream = fs.createWriteStream;
509501

510-
// emptyDir
511-
exports.emptyDir = emptyDir;
512-
exports.emptyDirSync = emptyDirSync;
513-
514-
// ensurePath
515-
exports.ensurePath = ensurePath;
516-
exports.ensurePathSync = ensurePathSync;
517-
518-
// ensureWriteStream
519-
exports.ensureWriteStream = ensureWriteStream;
520-
exports.ensureWriteStreamSync = ensureWriteStreamSync;
521-
522-
// exists
523-
exports.exists = exists;
524-
exports.existsSync = existsSync;
525-
526502
// fsync
527503
exports.fsync = BlueBirdPromise.promisify(fs.fsync);
528504
exports.fsyncSync = fs.fsyncSync;
@@ -531,18 +507,10 @@ exports.fsyncSync = fs.fsyncSync;
531507
exports.link = BlueBirdPromise.promisify(fs.link);
532508
exports.linkSync = fs.linkSync;
533509

534-
// listDir
535-
exports.listDir = listDir;
536-
exports.listDirSync = listDirSync;
537-
538510
// mkdir
539511
exports.mkdir = BlueBirdPromise.promisify(fs.mkdir);
540512
exports.mkdirSync = fs.mkdirSync;
541513

542-
// mkdirs
543-
exports.mkdirs = mkdirs;
544-
exports.mkdirsSync = mkdirsSync;
545-
546514
// open
547515
exports.open = BlueBirdPromise.promisify(fs.open);
548516
exports.openSync = fs.openSync;
@@ -559,10 +527,6 @@ exports.readSync = fs.readSync;
559527
exports.readdir = BlueBirdPromise.promisify(fs.readdir);
560528
exports.readdirSync = fs.readdirSync;
561529

562-
// readFile
563-
exports.readFile = readFile;
564-
exports.readFileSync = readFileSync;
565-
566530
// readlink
567531
exports.readlink = BlueBirdPromise.promisify(fs.readlink);
568532
exports.readlinkSync = fs.readlinkSync;
@@ -575,10 +539,6 @@ exports.realpathSync = fs.realpathSync;
575539
exports.rename = BlueBirdPromise.promisify(fs.rename);
576540
exports.renameSync = fs.renameSync;
577541

578-
// rmdir
579-
exports.rmdir = rmdir;
580-
exports.rmdirSync = rmdirSync;
581-
582542
// stat
583543
exports.stat = BlueBirdPromise.promisify(fs.stat);
584544
exports.statSync = fs.statSync;
@@ -604,25 +564,16 @@ exports.futimes = BlueBirdPromise.promisify(fs.futimes);
604564
exports.futimesSync = fs.futimesSync;
605565

606566
// watch
607-
exports.watch = watch;
608567
exports.watchFile = fs.watchFile;
609568
exports.unwatchFile = fs.unwatchFile;
610569

611570
// write
612571
exports.write = BlueBirdPromise.promisify(fs.write);
613572
exports.writeSync = fs.writeSync;
614573

615-
// writeFile
616-
exports.writeFile = writeFile;
617-
exports.writeFileSync = writeFileSync;
618-
619574
// Static classes
620575
exports.Stats = fs.Stats;
621576
exports.ReadStream = fs.ReadStream;
622577
exports.WriteStream = fs.WriteStream;
623578
exports.FileReadStream = fs.FileReadStream;
624579
exports.FileWriteStream = fs.FileWriteStream;
625-
626-
// util
627-
exports.escapeBOM = escapeBOM;
628-
exports.escapeEOL = escapeEOL;

0 commit comments

Comments
 (0)