Skip to content

Commit

Permalink
fix: use export function instead of exports
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshinorin committed Sep 11, 2022
1 parent c89e5bc commit 1fb8f7a
Showing 1 changed file with 26 additions and 75 deletions.
101 changes: 26 additions & 75 deletions lib/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const fsPromises = fs.promises;

const rEOL = /\r\n/g;

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

function existsSync(path: string) {
export function existsSync(path: string) {
if (!path) throw new TypeError('path is required!');

try {
Expand All @@ -33,13 +33,13 @@ function existsSync(path: string) {
return true;
}

function mkdirs(path: string) {
export function mkdirs(path: string) {
if (!path) throw new TypeError('path is required!');

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

function mkdirsSync(path: string) {
export function mkdirsSync(path: string) {
if (!path) throw new TypeError('path is required!');

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

function writeFile(
export function writeFile(
path: string,
data: any,
options?: WriteFileOptions
Expand All @@ -63,14 +63,14 @@ function writeFile(
}


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

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

function appendFile(
export function appendFile(
path: string,
data: any,
options?: WriteFileOptions) {
Expand All @@ -80,14 +80,14 @@ function appendFile(
.then(() => fsPromises.appendFile(path, data, options));
}

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

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

function copyFile(
export function copyFile(
src: string, dest: string, flags?: number) {
if (!src) throw new TypeError('src is required!');
if (!dest) throw new TypeError('dest is required!');
Expand Down Expand Up @@ -156,7 +156,7 @@ async function _copyDirWalker(
});
}

function copyDir(
export function copyDir(
src: string, dest: string, options: ReadDirOptions = {}) {
if (!src) throw new TypeError('src is required!');
if (!dest) throw new TypeError('dest is required!');
Expand Down Expand Up @@ -186,7 +186,7 @@ async function _listDirWalker(
await BlueBirdPromise.all(promises);
}

function listDir(
export function listDir(
path: string, options: ReadDirOptions = {}) {
if (!path) throw new TypeError('path is required!');

Expand All @@ -209,7 +209,7 @@ function _listDirSyncWalker(
}
}

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

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

function escapeEOL(str: string) {
export function escapeEOL(str: string) {
return str.replace(rEOL, '\n');
}

function escapeBOM(str: string) {
export function escapeBOM(str: string) {
return str.charCodeAt(0) === 0xFEFF ? str.substring(1) : str;
}

function escapeFileContent(content) {
export function escapeFileContent(content) {
return escapeBOM(escapeEOL(content));
}

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

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

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

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

if (!Object.prototype.hasOwnProperty.call(options,
Expand Down Expand Up @@ -293,7 +293,7 @@ async function _emptyDir(
return results;
}

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

Expand Down Expand Up @@ -329,7 +329,7 @@ function _emptyDirSync(
return results;
}

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

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

function rmdir(path: string) {
export function rmdir(path: string) {
if (!path) throw new TypeError('path is required!');

return BlueBirdPromise.resolve(_rmdir(path));
Expand All @@ -370,13 +370,13 @@ function _rmdirSync(path: string) {
fs.rmdirSync(path);
}

function rmdirSync(path: string) {
export function rmdirSync(path: string) {
if (!path) throw new TypeError('path is required!');

_rmdirSync(path);
}

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

Expand Down Expand Up @@ -416,13 +416,13 @@ async function _ensurePath(path: string): Promise<string> {
return _findUnusedPath(path, files);
}

function ensurePath(path: string) {
export function ensurePath(path: string) {
if (!path) throw new TypeError('path is required!');

return BlueBirdPromise.resolve(_ensurePath(path));
}

function ensurePathSync(path: string) {
export function ensurePathSync(path: string) {
if (!path) throw new TypeError('path is required!');
if (!fs.existsSync(path)) return path;

Expand All @@ -431,7 +431,7 @@ function ensurePathSync(path: string) {
return _findUnusedPath(path, files);
}

function ensureWriteStream(path: string, options?: string | {
export function ensureWriteStream(path: string, options?: string | {
flags?: string;
encoding?: string;
fd?: number;
Expand All @@ -447,7 +447,7 @@ function ensureWriteStream(path: string, options?: string | {
.then(() => fs.createWriteStream(path, options));
}

function ensureWriteStreamSync(path: string, options?: string | {
export function ensureWriteStreamSync(path: string, options?: string | {
flags?: string;
encoding?: string;
fd?: number;
Expand Down Expand Up @@ -475,10 +475,6 @@ function ensureWriteStreamSync(path: string, options?: string | {
exports.access = BlueBirdPromise.promisify(fs.access);
exports.accessSync = fs.accessSync;

// appendFile
exports.appendFile = appendFile;
exports.appendFileSync = appendFileSync;

// chmod
exports.chmod = BlueBirdPromise.promisify(fs.chmod);
exports.chmodSync = fs.chmodSync;
Expand All @@ -499,30 +495,10 @@ exports.lchownSync = fs.lchownSync;
exports.close = BlueBirdPromise.promisify(fs.close);
exports.closeSync = fs.closeSync;

// copy
exports.copyDir = copyDir;
exports.copyFile = copyFile;

// createStream
exports.createReadStream = fs.createReadStream;
exports.createWriteStream = fs.createWriteStream;

// emptyDir
exports.emptyDir = emptyDir;
exports.emptyDirSync = emptyDirSync;

// ensurePath
exports.ensurePath = ensurePath;
exports.ensurePathSync = ensurePathSync;

// ensureWriteStream
exports.ensureWriteStream = ensureWriteStream;
exports.ensureWriteStreamSync = ensureWriteStreamSync;

// exists
exports.exists = exists;
exports.existsSync = existsSync;

// fsync
exports.fsync = BlueBirdPromise.promisify(fs.fsync);
exports.fsyncSync = fs.fsyncSync;
Expand All @@ -531,18 +507,10 @@ exports.fsyncSync = fs.fsyncSync;
exports.link = BlueBirdPromise.promisify(fs.link);
exports.linkSync = fs.linkSync;

// listDir
exports.listDir = listDir;
exports.listDirSync = listDirSync;

// mkdir
exports.mkdir = BlueBirdPromise.promisify(fs.mkdir);
exports.mkdirSync = fs.mkdirSync;

// mkdirs
exports.mkdirs = mkdirs;
exports.mkdirsSync = mkdirsSync;

// open
exports.open = BlueBirdPromise.promisify(fs.open);
exports.openSync = fs.openSync;
Expand All @@ -559,10 +527,6 @@ exports.readSync = fs.readSync;
exports.readdir = BlueBirdPromise.promisify(fs.readdir);
exports.readdirSync = fs.readdirSync;

// readFile
exports.readFile = readFile;
exports.readFileSync = readFileSync;

// readlink
exports.readlink = BlueBirdPromise.promisify(fs.readlink);
exports.readlinkSync = fs.readlinkSync;
Expand All @@ -575,10 +539,6 @@ exports.realpathSync = fs.realpathSync;
exports.rename = BlueBirdPromise.promisify(fs.rename);
exports.renameSync = fs.renameSync;

// rmdir
exports.rmdir = rmdir;
exports.rmdirSync = rmdirSync;

// stat
exports.stat = BlueBirdPromise.promisify(fs.stat);
exports.statSync = fs.statSync;
Expand All @@ -604,25 +564,16 @@ exports.futimes = BlueBirdPromise.promisify(fs.futimes);
exports.futimesSync = fs.futimesSync;

// watch
exports.watch = watch;
exports.watchFile = fs.watchFile;
exports.unwatchFile = fs.unwatchFile;

// write
exports.write = BlueBirdPromise.promisify(fs.write);
exports.writeSync = fs.writeSync;

// writeFile
exports.writeFile = writeFile;
exports.writeFileSync = writeFileSync;

// Static classes
exports.Stats = fs.Stats;
exports.ReadStream = fs.ReadStream;
exports.WriteStream = fs.WriteStream;
exports.FileReadStream = fs.FileReadStream;
exports.FileWriteStream = fs.FileWriteStream;

// util
exports.escapeBOM = escapeBOM;
exports.escapeEOL = escapeEOL;

0 comments on commit 1fb8f7a

Please sign in to comment.