🤖 Merge PR #63829 [fs-extra] Update to v11 by @BendingBender

This commit is contained in:
Dimitri B
2023-01-09 00:59:08 +01:00
committed by GitHub
parent dc1784ba8c
commit 5c2ad8fe5d
14 changed files with 2919 additions and 944 deletions

View File

@@ -0,0 +1 @@
esm.d.mts

111
types/fs-extra/esm.d.mts Normal file
View File

@@ -0,0 +1,111 @@
import * as fse from './index';
export {
copy,
copySync,
emptyDirSync,
emptydirSync,
emptyDir,
emptydir,
createFile,
createFileSync,
ensureFile,
ensureFileSync,
createLink,
createLinkSync,
ensureLink,
ensureLinkSync,
createSymlink,
createSymlinkSync,
ensureSymlink,
ensureSymlinkSync,
readJson,
readJSON,
readJsonSync,
readJSONSync,
writeJson,
writeJSON,
writeJsonSync,
writeJSONSync,
outputJson,
outputJSON,
outputJsonSync,
outputJSONSync,
mkdirs,
mkdirsSync,
mkdirp,
mkdirpSync,
ensureDir,
ensureDirSync,
move,
moveSync,
outputFile,
outputFileSync,
pathExists,
pathExistsSync,
remove,
removeSync,
PathLike,
NoParamCallback,
NoParamCallbackWithUndefined,
SymlinkType,
CopyFilterSync,
CopyFilterAsync,
CopyOptions,
CopyOptionsSync,
EnsureDirOptions,
MoveOptions,
WriteFileOptions,
JsonReadOptions,
JsonWriteOptions,
JsonOutputOptions,
} from './index';
declare const fsExtra: {
copy: typeof fse.copy;
copySync: typeof fse.copySync;
emptyDirSync: typeof fse.emptyDirSync;
emptydirSync: typeof fse.emptydirSync;
emptyDir: typeof fse.emptyDir;
emptydir: typeof fse.emptydir;
createFile: typeof fse.createFile;
createFileSync: typeof fse.createFileSync;
ensureFile: typeof fse.ensureFile;
ensureFileSync: typeof fse.ensureFileSync;
createLink: typeof fse.createLink;
createLinkSync: typeof fse.createLinkSync;
ensureLink: typeof fse.ensureLink;
ensureLinkSync: typeof fse.ensureLinkSync;
createSymlink: typeof fse.createSymlink;
createSymlinkSync: typeof fse.createSymlinkSync;
ensureSymlink: typeof fse.ensureSymlink;
ensureSymlinkSync: typeof fse.ensureSymlinkSync;
readJson: typeof fse.readJson;
readJSON: typeof fse.readJSON;
readJsonSync: typeof fse.readJsonSync;
readJSONSync: typeof fse.readJSONSync;
writeJson: typeof fse.writeJson;
writeJSON: typeof fse.writeJSON;
writeJsonSync: typeof fse.writeJsonSync;
writeJSONSync: typeof fse.writeJSONSync;
outputJson: typeof fse.outputJson;
outputJSON: typeof fse.outputJSON;
outputJsonSync: typeof fse.outputJsonSync;
outputJSONSync: typeof fse.outputJSONSync;
mkdirs: typeof fse.mkdirs;
mkdirsSync: typeof fse.mkdirsSync;
mkdirp: typeof fse.mkdirp;
mkdirpSync: typeof fse.mkdirpSync;
ensureDir: typeof fse.ensureDir;
ensureDirSync: typeof fse.ensureDirSync;
move: typeof fse.move;
moveSync: typeof fse.moveSync;
outputFile: typeof fse.outputFile;
outputFileSync: typeof fse.outputFileSync;
pathExists: typeof fse.pathExists;
pathExistsSync: typeof fse.pathExistsSync;
remove: typeof fse.remove;
removeSync: typeof fse.removeSync;
};
export default fsExtra;

View File

@@ -1,424 +0,0 @@
import * as fs from 'fs-extra';
const len = 2;
const src = '';
const dest = '';
const file = '';
const dir = '';
const path = '';
const data = '';
const uid = 0;
const gid = 0;
const fd = 0;
const modeNum = 0;
const modeStr = '';
const object = {};
const errorCallback = (err: Error) => {};
const noParamCallback: fs.NoParamCallback = err => {};
const ensureNum = 0o700;
const ensureObj: fs.EnsureOptions = {
mode: 0o700,
};
const readOptions: fs.ReadOptions = {
reviver: {},
};
const writeOptions: fs.WriteOptions = {
replacer: {},
};
fs.moveSync(src, dest, {});
fs.move(src, dest, {}).then(() => {
// stub
});
fs.move(src, dest).then(() => {
// stub
});
fs.move(src, dest, {}, () => {
// stub
});
fs.move(src, dest, () => {
// stub
});
fs.copy(src, dest).then(() => {
// stub
});
fs.copy(src, dest, { overwrite: true }).then(() => {
// stub
});
fs.copy(src, dest, errorCallback);
fs.copy(src, dest, { filter: (src: string, dest: string) => false }, errorCallback);
fs.copy(
src,
dest,
{
overwrite: true,
preserveTimestamps: true,
filter: (src: string, dest: string) => Promise.resolve(false),
},
errorCallback,
);
fs.copySync(src, dest);
fs.copySync(src, dest, { filter: (src: string, dest: string) => false });
fs.copySync(src, dest, {
overwrite: true,
preserveTimestamps: true,
filter: (src: string, dest: string) => false,
});
fs.createFile(file).then(() => {
// stub
});
fs.createFile(file, errorCallback);
fs.createFileSync(file);
fs.mkdir(dir).then(() => {
// stub
});
fs.mkdir(dir, errorCallback);
fs.mkdirSync(dir);
fs.mkdir(dir, modeNum).then(() => {
// stub
});
fs.mkdir(dir, modeNum, errorCallback);
fs.mkdirSync(dir, modeNum);
fs.mkdir(dir, { mode: modeNum }).then(() => {
// stub
});
fs.mkdir(dir, { mode: modeNum }, errorCallback);
fs.mkdirSync(dir, { mode: modeNum });
fs.mkdirs(dir).then(() => {
// stub
});
fs.mkdirp(dir).then(() => {
// stub
});
fs.mkdirs(dir, errorCallback);
fs.mkdirsSync(dir);
fs.mkdirp(dir, errorCallback);
fs.mkdirpSync(dir);
fs.outputFile(file, data).then(() => {
// stub
});
fs.outputFile(file, data, 'utf-8').then(() => {
// stub
});
fs.outputFile(file, data, { encoding: 'utf-8' }).then(() => {
// stub
});
fs.outputFile(file, data, 'foo').then(() => {
// stub
});
fs.outputFile(file, data, { encoding: 'foo' }).then(() => {
// stub
});
fs.outputFile(file, data, errorCallback);
fs.outputFile(file, data, 'utf-8', errorCallback);
fs.outputFile(file, data, 'foo', errorCallback);
fs.outputFile(file, data, { encoding: 'utf-8' }, errorCallback);
fs.outputFile(file, data, { encoding: 'foo' }, errorCallback);
fs.outputFileSync(file, data);
fs.outputFileSync(file, data, 'utf-8');
fs.outputFileSync(file, data, 'foo');
fs.outputFileSync(file, data, { encoding: 'utf-8' });
fs.outputFileSync(file, data, { encoding: 'foo' });
fs.outputJson(file, data, {
spaces: 2,
}).then(() => {
// stub
});
fs.outputJson(file, data, {
encoding: 'utf-8',
spaces: 2,
}).then(() => {
// stub
});
fs.outputJson(file, data, 'utf-8').then(() => {
// stub
});
fs.outputJson(
file,
data,
{
spaces: 2,
},
errorCallback,
);
fs.outputJson(
file,
data,
{
encoding: 'utf-8',
spaces: 2,
},
errorCallback,
);
fs.outputJson(file, data, 'utf-8', errorCallback);
fs.outputJSON(file, data, errorCallback);
fs.outputJSON(file, data).then(() => {
// stub
});
fs.outputJsonSync(file, data);
fs.outputJSONSync(file, data);
fs.outputJsonSync(file, data, 'utf-8');
fs.outputJSONSync(file, data, 'utf-8');
fs.outputJsonSync(file, data, { encoding: 'utf-8' });
fs.outputJSONSync(file, data, { encoding: 'utf-8' });
fs.readJson(file).then(() => {
// stub
});
fs.readJson(file, 'utf-8').then(() => {
// stub
});
fs.readJson(file, readOptions).then(() => {
// stub
});
fs.readJson(file, { encoding: 'utf-8' }).then(() => {
// stub
});
fs.readJson(file, (error: Error, jsonObject: any) => {});
fs.readJson(file, readOptions, (error: Error, jsonObject: any) => {});
fs.readJson(file, 'utf-8', (error: Error, jsonObject: any) => {});
fs.readJson(file, { encoding: 'utf-8' }, (error: Error, jsonObject: any) => {});
fs.readJSON(file, (error: Error, jsonObject: any) => {});
fs.readJSON(file, readOptions, (error: Error, jsonObject: any) => {});
fs.readJSON(file, 'utf-8', (error: Error, jsonObject: any) => {});
fs.readJSON(file, { encoding: 'utf-8' }, (error: Error, jsonObject: any) => {});
fs.readJsonSync(file, readOptions);
fs.readJSONSync(file, readOptions);
fs.readJsonSync(file, 'utf-8');
fs.readJSONSync(file, 'utf-8');
fs.readJsonSync(file, { encoding: 'utf-8' });
fs.readJSONSync(file, { encoding: 'utf-8' });
fs.remove(dir, errorCallback);
fs.remove(dir).then(() => {
// stub
});
// @ts-expect-error map can't be called as it passes a number for the second argument instead of a callback.
['file/to/remove'].map(fs.remove);
// @ts-expect-error promise should not be returned when callback is provided.
// tslint:disable-next-line:no-void-expression
fs.remove(dir, errorCallback).then(() => {
// stub
});
fs.removeSync(dir);
fs.writeJson(file, object).then(() => {
// stub
});
fs.writeJSON(file, object).then(() => {
// stub
});
fs.writeJson(file, object, errorCallback);
fs.writeJson(file, object, writeOptions, errorCallback);
fs.writeJson(file, object, 'utf-8', errorCallback);
fs.writeJson(file, object, { encoding: 'utf-8' }, errorCallback);
fs.writeJSON(file, object, errorCallback);
fs.writeJSON(file, object, writeOptions, errorCallback);
fs.writeJSON(file, object, 'utf-8', errorCallback);
fs.writeJSON(file, object, { encoding: 'utf-8' }, errorCallback);
fs.writeJson(file, object, writeOptions).then(() => {
// stub
});
fs.writeJson(file, object, writeOptions).then(() => {
// stub
});
fs.writeJson(file, object, 'utf-8').then(() => {
// stub
});
fs.writeJson(file, object, { encoding: 'utf-8' }).then(() => {
// stub
});
fs.writeJSON(file, object, writeOptions).then(() => {
// stub
});
fs.writeJSON(file, object, 'utf-8').then(() => {
// stub
});
fs.writeJSON(file, object, { encoding: 'utf-8' }).then(() => {
// stub
});
fs.writeJsonSync(file, object, writeOptions);
fs.writeJsonSync(file, object, 'utf-8');
fs.writeJsonSync(file, object, { encoding: 'utf-8' });
fs.writeJSONSync(file, object, writeOptions);
fs.writeJSONSync(file, object, 'utf-8');
fs.writeJSONSync(file, object, { encoding: 'utf-8' });
fs.ensureDir(path).then(() => {
// stub
});
fs.ensureDir(path, ensureObj).then(() => {
// stub
});
fs.ensureDir(path, ensureNum).then(() => {
// stub
});
fs.ensureDir(path, ensureObj, errorCallback);
fs.ensureDir(path, ensureNum, errorCallback);
fs.ensureDir(path, errorCallback);
fs.ensureDirSync(path);
fs.ensureDirSync(path, ensureObj);
fs.ensureDirSync(path, ensureNum);
fs.ensureFile(path).then(() => {
// stub
});
fs.ensureFile(path, errorCallback);
fs.ensureFileSync(path);
fs.ensureLink(path, path).then(() => {
// stub
});
fs.ensureLink(path, path, errorCallback);
fs.createLink(path, path).then(() => {
// stub
});
fs.createLink(path, path, errorCallback);
fs.ensureLinkSync(path, path);
fs.createLinkSync(path, path);
fs.ensureSymlink(path, path, 'file').then(() => {
// stub
});
fs.ensureSymlink(path, path, 'junction').then(() => {
// stub
});
fs.ensureSymlink(path, path, errorCallback);
fs.ensureSymlinkSync(path, path);
fs.emptyDir(path).then(() => {
// stub
});
fs.emptyDir(path, errorCallback);
fs.emptydir(path, errorCallback);
fs.emptydir(path).then(() => {});
fs.emptyDirSync(path);
fs.emptydirSync(path);
fs.pathExists(path).then((_exist: boolean) => {
// stub
});
fs.pathExists(path, (_err: Error, _exists: boolean) => {});
const x: boolean = fs.pathExistsSync(path);
fs.rename(src, dest, errorCallback);
fs.renameSync(src, dest);
fs.truncate(path, len, errorCallback);
fs.truncateSync(path, len);
fs.chown(path, uid, gid, errorCallback);
fs.chownSync(path, uid, gid);
fs.fchown(fd, uid, gid, errorCallback);
fs.fchownSync(fd, uid, gid);
fs.lchown(path, uid, gid, errorCallback);
fs.lchownSync(path, uid, gid);
fs.chmod(path, modeNum, errorCallback);
fs.chmod(path, modeStr, errorCallback);
fs.chmodSync(path, modeNum);
fs.chmodSync(path, modeStr);
fs.fchmod(fd, modeNum, errorCallback);
fs.fchmod(fd, modeStr, errorCallback);
fs.fchmodSync(fd, modeNum);
fs.fchmodSync(fd, modeStr);
fs.lchmod(path, modeStr, noParamCallback);
fs.lchmod(path, modeNum, noParamCallback);
fs.lchmodSync(path, modeNum);
fs.lchmodSync(path, modeStr);
fs.statSync(path);
fs.lstatSync(path);
fs.read(0, Buffer.from(''), 0, 0, null).then(x => {
const a = x.buffer;
const b = x.bytesRead;
});
fs.write(0, Buffer.from(''), 0, 0, null).then(x => {
const a = x.buffer;
const b = x.bytesWritten;
});
fs.write(0, Buffer.from('')).then(x => {
const a = x.buffer;
const b = x.bytesWritten;
});
const writevTest = async (buffs: NodeJS.ArrayBufferView[], position: number) => {
await fs.writev(fd, buffs); // $ExpectType WritevResult
await fs.writev(fd, buffs, position); // $ExpectType WritevResult
};
// $ExpectType Promise<void>
fs.writeFile('foo.txt', 'i am foo', 'utf-8');
// $ExpectType Promise<void>
fs.writeFile('foo.txt', 'i am foo', { encoding: 'utf-8' });
// $ExpectType Promise<string>
fs.mkdtemp('foo');
fs.copyFile('src', 'dest').then();
fs.copyFile('src', 'dest', fs.constants.COPYFILE_EXCL).then();
fs.copyFile('src', 'dest', errorCallback);
fs.createSymlink('src', 'dest', 'dir').then();
fs.createSymlink('src', 'dest', 'file').then();
fs.createSymlink('src', 'dest', 'junction', errorCallback);
const openDirTest = async (path: string, opts: fs.OpenDirOptions) => {
await fs.opendir(path); // $ExpectType Dir
await fs.opendir(path, opts); // $ExpectType Dir
};
fs.readdir('src').then((files: string[]) => {});
fs.readdir('src', 'buffer').then((files: Buffer[]) => {});
fs.readdir('src', { encoding: 'buffer' }).then((files: Buffer[]) => {});
fs.readdir('src', { withFileTypes: true }).then((files: fs.Dirent[]) => {});
fs.readdir('src', 'utf-8').then((files: string[]) => {});
fs.readdir('src', { encoding: 'utf-8' }).then((files: string[]) => {});
fs.readdir('src', 'foo').then((files: string[]) => {});
fs.readdir('src', { encoding: 'foo' }).then((files: string[]) => {});
// $ExpectType void
fs.realpath('src', (err, resolved) => {
// $ExpectType string
resolved;
});
// $ExpectType Promise<string>
fs.realpath.native('src');
// $ExpectType Promise<string>
fs.realpath.native('src', 'utf-8');
// $ExpectType Promise<Buffer>
fs.realpath.native('src', 'buffer');
// $ExpectType Promise<string>
fs.realpath.native('src', 'foo');
// $ExpectType Promise<string>
fs.realpath.native('src', { encoding: 'utf-8' });
// $ExpectType Promise<Buffer>
fs.realpath.native('src', { encoding: 'buffer' });
// $ExpectType Promise<string>
fs.realpath.native('src', { encoding: 'foo' });
// $ExpectType Promise<string>
fs.realpath.native('src', { encoding: null });
async function rmTest() {
// $ExpectType void
await fs.rm('path');
// $ExpectType void
await fs.rm('path', {
force: true,
maxRetries: 1,
recursive: true,
retryDelay: 200,
});
}
async function rmDirTest() {
// $ExpectType void
await fs.rmdir('dir');
// $ExpectType void
await fs.rmdir('dir', { maxRetries: 1, retryDelay: 200 });
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,13 @@
{
"private": true,
"exports": {
".": {
"types": "./index.d.ts"
},
"./esm": {
"types": {
"import": "./esm.d.mts"
}
}
}
}

View File

@@ -0,0 +1,529 @@
import * as fs from 'fs-extra/esm.mjs';
// test type exports
type Types =
| fs.PathLike
| fs.NoParamCallback
| fs.NoParamCallbackWithUndefined
| fs.SymlinkType
| fs.CopyFilterSync
| fs.CopyFilterAsync
| fs.CopyOptions
| fs.CopyOptionsSync
| fs.EnsureDirOptions
| fs.MoveOptions
| fs.JsonReadOptions
| fs.JsonWriteOptions
| fs.JsonOutputOptions;
const src = '';
const dest = '';
const file = '';
const dir = '';
const path = '';
const data = '';
const object = {};
fs.move(src, dest); // $ExpectType Promise<void>
fs.move(src, dest, { overwrite: true }); // $ExpectType Promise<void>
fs.move(src, dest, { dereference: true }); // $ExpectType Promise<void>
// $ExpectType void
fs.move(src, dest, err => {
err; // $ExpectType ErrnoException | null | undefined
});
// $ExpectType void
fs.move(src, dest, { overwrite: true }, err => {
err; // $ExpectType ErrnoException | null | undefined
});
// $ExpectType void
fs.move(src, dest, { dereference: true }, err => {
err; // $ExpectType ErrnoException | null | undefined
});
fs.moveSync(src, dest); // $ExpectType void
fs.moveSync(src, dest, { overwrite: true }); // $ExpectType void
fs.moveSync(src, dest, { dereference: true }); // $ExpectType void
fs.copy(src, dest); // $ExpectType Promise<void>
fs.copy(src, dest, { overwrite: true }); // $ExpectType Promise<void>
// $ExpectType void
fs.copy(src, dest, err => {
err; // $ExpectType ErrnoException | null | undefined
});
// $ExpectType void
fs.copy(
src,
dest,
{
filter(src, dest) {
src; // $ExpectType string
dest; // $ExpectType string
return false;
},
},
err => {
err; // $ExpectType ErrnoException | null | undefined
},
);
// $ExpectType void
fs.copy(
src,
dest,
{
overwrite: true,
preserveTimestamps: true,
filter(src, dest) {
src; // $ExpectType string
dest; // $ExpectType string
return Promise.resolve(false);
},
},
err => {
err; // $ExpectType ErrnoException | null | undefined
},
);
fs.copySync(src, dest); // $ExpectType void
// $ExpectType void
fs.copySync(src, dest, {
filter(src, dest) {
src; // $ExpectType string
dest; // $ExpectType string
return false;
},
});
// $ExpectType void
fs.copySync(src, dest, {
overwrite: true,
preserveTimestamps: true,
filter(src, dest) {
src; // $ExpectType string
dest; // $ExpectType string
return false;
},
});
fs.createFile(file); // $ExpectType Promise<void>
// $ExpectType void
fs.createFile(file, err => {
err; // $ExpectType ErrnoException | null | undefined
});
fs.createFileSync(file); // $ExpectType void
fs.ensureFile(path); // $ExpectType Promise<void>
// $ExpectType void
fs.ensureFile(path, err => {
err; // $ExpectType ErrnoException | null | undefined
});
fs.ensureFileSync(path); // $ExpectType void
fs.createLink(path, path); // $ExpectType Promise<void>
// $ExpectType void
fs.createLink(path, path, err => {
err; // $ExpectType ErrnoException | null
});
fs.ensureLink(path, path); // $ExpectType Promise<void>
// $ExpectType void
fs.ensureLink(path, path, err => {
err; // $ExpectType ErrnoException | null
});
fs.createLinkSync(path, path); // $ExpectType void
fs.ensureLinkSync(path, path); // $ExpectType void
fs.createSymlink(path, path); // $ExpectType Promise<void>
fs.createSymlink(path, path, 'dir'); // $ExpectType Promise<void>
fs.createSymlink(path, path, 'file'); // $ExpectType Promise<void>
fs.ensureSymlink(path, path); // $ExpectType Promise<void>
fs.ensureSymlink(path, path, 'dir'); // $ExpectType Promise<void>
fs.ensureSymlink(path, path, 'file'); // $ExpectType Promise<void>
// $ExpectType void
fs.createSymlink(path, path, err => {
err; // $ExpectType ErrnoException | null
});
// $ExpectType void
fs.ensureSymlink(path, path, err => {
err; // $ExpectType ErrnoException | null
});
// $ExpectType void
fs.createSymlink(path, path, 'junction', err => {
err; // $ExpectType ErrnoException | null
});
// $ExpectType void
fs.ensureSymlink(path, path, 'junction', err => {
err; // $ExpectType ErrnoException | null
});
fs.createSymlinkSync(path, path); // $ExpectType void
fs.ensureSymlinkSync(path, path); // $ExpectType void
fs.mkdirs(dir); // $ExpectType Promise<void>
fs.mkdirs(dir, 0o777); // $ExpectType Promise<void>
fs.mkdirs(dir, { mode: 0o700 }); // $ExpectType Promise<void>
fs.mkdirp(dir); // $ExpectType Promise<void>
fs.mkdirp(dir, 0o777); // $ExpectType Promise<void>
fs.mkdirp(dir, { mode: 0o700 }); // $ExpectType Promise<void>
fs.ensureDir(dir); // $ExpectType Promise<void>
fs.ensureDir(dir, 0o777); // $ExpectType Promise<void>
fs.ensureDir(dir, { mode: 0o700 }); // $ExpectType Promise<void>
// $ExpectType void
fs.mkdirs(dir, err => {
err; // $ExpectType ErrnoException | null
});
// $ExpectType void
fs.mkdirs(dir, 0o777, err => {
err; // $ExpectType ErrnoException | null
});
// $ExpectType void
fs.mkdirs(dir, { mode: 0o700 }, err => {
err; // $ExpectType ErrnoException | null
});
// $ExpectType void
fs.mkdirp(dir, err => {
err; // $ExpectType ErrnoException | null
});
// $ExpectType void
fs.mkdirp(dir, 0o777, err => {
err; // $ExpectType ErrnoException | null
});
// $ExpectType void
fs.mkdirp(dir, { mode: 0o700 }, err => {
err; // $ExpectType ErrnoException | null
});
// $ExpectType void
fs.ensureDir(dir, err => {
err; // $ExpectType ErrnoException | null
});
// $ExpectType void
fs.ensureDir(dir, 0o777, err => {
err; // $ExpectType ErrnoException | null
});
// $ExpectType void
fs.ensureDir(dir, { mode: 0o700 }, err => {
err; // $ExpectType ErrnoException | null
});
fs.mkdirsSync(dir); // $ExpectType void
fs.mkdirsSync(dir, 0o777); // $ExpectType void
fs.mkdirsSync(dir, { mode: 0o700 }); // $ExpectType void
fs.mkdirpSync(dir); // $ExpectType void
fs.mkdirpSync(dir, 0o777); // $ExpectType void
fs.mkdirpSync(dir, { mode: 0o700 }); // $ExpectType void
fs.ensureDirSync(dir); // $ExpectType void
fs.ensureDirSync(dir, 0o777); // $ExpectType void
fs.ensureDirSync(dir, { mode: 0o700 }); // $ExpectType void
fs.outputFile(file, data); // $ExpectType Promise<void>
fs.outputFile(file, data, 'utf-8'); // $ExpectType Promise<void>
fs.outputFile(file, data, { encoding: 'utf-8' }); // $ExpectType Promise<void>
// @ts-expect-error
fs.outputFile(file, data, { encoding: 'foo' });
// $ExpectType void
fs.outputFile(file, data, err => {
err; // $ExpectType ErrnoException | null
});
// $ExpectType void
fs.outputFile(file, data, 'utf-8', err => {
err; // $ExpectType ErrnoException | null
});
// @ts-expect-error
fs.outputFile(file, data, 'foo', errorCallback);
// $ExpectType void
fs.outputFile(file, data, { encoding: 'utf-8' }, err => {
err; // $ExpectType ErrnoException | null
});
// @ts-expect-error
fs.outputFile(file, data, { encoding: 'foo' }, errorCallback);
fs.outputFileSync(file, data); // $ExpectType void
fs.outputFileSync(file, data, 'utf-8'); // $ExpectType void
// @ts-expect-error
fs.outputFileSync(file, data, 'foo');
fs.outputFileSync(file, data, { encoding: 'utf-8' }); // $ExpectType void
// @ts-expect-error
fs.outputFileSync(file, data, { encoding: 'foo' });
fs.outputJson(file, data); // $ExpectType Promise<void>
fs.outputJson(file, data, { spaces: 2 }); // $ExpectType Promise<void>
fs.outputJson(file, data, { encoding: 'utf-8', spaces: 2 }); // $ExpectType Promise<void>
fs.outputJson(file, data, 'utf-8'); // $ExpectType Promise<void>
// $ExpectType void
fs.outputJson(
file,
data,
{
spaces: 2,
},
err => {
err; // $ExpectType ErrnoException | null
},
);
// $ExpectType void
fs.outputJson(
file,
data,
{
encoding: 'utf-8',
spaces: 2,
},
err => {
err; // $ExpectType ErrnoException | null
},
);
// $ExpectType void
fs.outputJson(file, data, 'utf-8', err => {
err; // $ExpectType ErrnoException | null
});
fs.outputJSON(file, data); // $ExpectType Promise<void>
fs.outputJSON(file, data, { spaces: 2 }); // $ExpectType Promise<void>
fs.outputJSON(file, data, { encoding: 'utf-8', spaces: 2 }); // $ExpectType Promise<void>
fs.outputJSON(file, data, 'utf-8'); // $ExpectType Promise<void>
// $ExpectType void
fs.outputJSON(
file,
data,
{
spaces: 2,
},
err => {
err; // $ExpectType ErrnoException | null
},
);
// $ExpectType void
fs.outputJSON(
file,
data,
{
encoding: 'utf-8',
spaces: 2,
},
err => {
err; // $ExpectType ErrnoException | null
},
);
// $ExpectType void
fs.outputJSON(file, data, err => {
err; // $ExpectType ErrnoException | null
});
fs.outputJsonSync(file, data); // $ExpectType void
fs.outputJSONSync(file, data); // $ExpectType void
fs.outputJsonSync(file, data, 'utf-8'); // $ExpectType void
fs.outputJSONSync(file, data, 'utf-8'); // $ExpectType void
fs.outputJsonSync(file, data, { encoding: 'utf-8' }); // $ExpectType void
fs.outputJSONSync(file, data, { encoding: 'utf-8' }); // $ExpectType void
fs.readJson(file); // $ExpectType Promise<any>
fs.readJson(file, 'utf-8'); // $ExpectType Promise<any>
// $ExpectType Promise<any>
fs.readJson(file, {
reviver(key, value) {
key; // $ExpectType any
value; // $ExpectType any
},
});
fs.readJson(file, { encoding: 'utf-8' }); // $ExpectType Promise<any>
fs.readJSON(file); // $ExpectType Promise<any>
fs.readJSON(file, 'utf-8'); // $ExpectType Promise<any>
// $ExpectType Promise<any>
fs.readJSON(file, {
reviver(key, value) {
key; // $ExpectType any
value; // $ExpectType any
},
});
fs.readJSON(file, { encoding: 'utf-8' }); // $ExpectType Promise<any>
// $ExpectType void
fs.readJson(file, (error, jsonObject) => {
error; // $ExpectType ErrnoException | null
jsonObject; // $ExpectType any
});
// $ExpectType void
fs.readJson(
file,
{
reviver(key, value) {
key; // $ExpectType any
value; // $ExpectType any
},
},
(error, jsonObject) => {
error; // $ExpectType ErrnoException | null
jsonObject; // $ExpectType any
},
);
// $ExpectType void
fs.readJson(file, 'utf-8', (error, jsonObject) => {
error; // $ExpectType ErrnoException | null
jsonObject; // $ExpectType any
});
// $ExpectType void
fs.readJson(file, { encoding: 'utf-8' }, (error, jsonObject) => {
error; // $ExpectType ErrnoException | null
jsonObject; // $ExpectType any
});
// $ExpectType void
fs.readJSON(file, (error, jsonObject) => {
error; // $ExpectType ErrnoException | null
jsonObject; // $ExpectType any
});
// $ExpectType void
fs.readJSON(
file,
{
reviver(key, value) {
key; // $ExpectType any
value; // $ExpectType any
},
},
(error, jsonObject) => {
error; // $ExpectType ErrnoException | null
jsonObject; // $ExpectType any
},
);
// $ExpectType void
fs.readJSON(file, 'utf-8', (error, jsonObject) => {
error; // $ExpectType ErrnoException | null
jsonObject; // $ExpectType any
});
// $ExpectType void
fs.readJSON(file, { encoding: 'utf-8' }, (error, jsonObject) => {
error; // $ExpectType ErrnoException | null
jsonObject; // $ExpectType any
});
// $ExpectType any
fs.readJsonSync(file, {
reviver(key, value) {
key; // $ExpectType any
value; // $ExpectType any
},
});
// $ExpectType any
fs.readJSONSync(file, {
reviver(key, value) {
key; // $ExpectType any
value; // $ExpectType any
},
});
fs.readJsonSync(file, 'utf-8'); // $ExpectType any
fs.readJSONSync(file, 'utf-8'); // $ExpectType any
fs.readJsonSync(file, { encoding: 'utf-8' }); // $ExpectType any
fs.readJSONSync(file, { encoding: 'utf-8' }); // $ExpectType any
fs.writeJson(file, object); // $ExpectType Promise<void>
fs.writeJSON(file, object); // $ExpectType Promise<void>
// $ExpectType void
fs.writeJson(file, object, error => {
error; // $ExpectType ErrnoException | null
});
// $ExpectType void
fs.writeJson(
file,
object,
{
replacer(key, value) {
key; // $ExpectType string
value; // $ExpectType any
},
},
error => {
error; // $ExpectType ErrnoException | null
},
);
// $ExpectType void
fs.writeJson(file, object, 'utf-8', error => {
error; // $ExpectType ErrnoException | null
});
// $ExpectType void
fs.writeJson(file, object, { encoding: 'utf-8' }, error => {
error; // $ExpectType ErrnoException | null
});
// $ExpectType void
fs.writeJSON(file, object, error => {
error; // $ExpectType ErrnoException | null
});
// $ExpectType void
fs.writeJSON(
file,
object,
{
replacer(key, value) {
key; // $ExpectType string
value; // $ExpectType any
},
},
error => {
error; // $ExpectType ErrnoException | null
},
);
// $ExpectType void
fs.writeJSON(file, object, 'utf-8', error => {
error; // $ExpectType ErrnoException | null
});
// $ExpectType void
fs.writeJSON(file, object, { encoding: 'utf-8' }, error => {
error; // $ExpectType ErrnoException | null
});
// $ExpectType Promise<void>
fs.writeJson(file, object, {
replacer(key, value) {
key; // $ExpectType string
value; // $ExpectType any
},
});
fs.writeJson(file, object, 'utf-8'); // $ExpectType Promise<void>
fs.writeJson(file, object, { encoding: 'utf-8' }); // $ExpectType Promise<void>
// $ExpectType Promise<void>
fs.writeJSON(file, object, {
replacer(key, value) {
key; // $ExpectType string
value; // $ExpectType any
},
});
fs.writeJSON(file, object, 'utf-8'); // $ExpectType Promise<void>
fs.writeJSON(file, object, { encoding: 'utf-8' }); // $ExpectType Promise<void>
// $ExpectType void
fs.writeJsonSync(file, object, {
replacer(key, value) {
key; // $ExpectType string
value; // $ExpectType any
},
});
fs.writeJsonSync(file, object, 'utf-8'); // $ExpectType void
fs.writeJsonSync(file, object, { encoding: 'utf-8' }); // $ExpectType void
// $ExpectType void
fs.writeJSONSync(file, object, {
replacer(key, value) {
key; // $ExpectType string
value; // $ExpectType any
},
});
fs.writeJSONSync(file, object, 'utf-8'); // $ExpectType void
fs.writeJSONSync(file, object, { encoding: 'utf-8' }); // $ExpectType void
// $ExpectType void
fs.remove(dir, error => {
error; // $ExpectType ErrnoException | null
});
fs.remove(dir); // $ExpectType Promise<void>
['file/to/remove'].map(file => fs.remove(file));
fs.removeSync(dir); // $ExpectType void
fs.emptyDir(path); // $ExpectType Promise<void>
fs.emptydir(path); // $ExpectType Promise<void>
// $ExpectType void
fs.emptyDir(path, error => {
error; // $ExpectType ErrnoException | null
});
// $ExpectType void
fs.emptydir(path, error => {
error; // $ExpectType ErrnoException | null
});
fs.emptyDirSync(path); // $ExpectType void
fs.emptydirSync(path); // $ExpectType void
fs.pathExists(path); // $ExpectType Promise<boolean>
// $ExpectType void
fs.pathExists(path, (err, exists) => {
err; // $ExpectType ErrnoException | null
exists; // $ExpectType boolean
});
fs.pathExistsSync(path); // $ExpectType boolean

File diff suppressed because it is too large Load Diff

View File

@@ -18,6 +18,7 @@
},
"files": [
"index.d.ts",
"fs-extra-tests.ts"
"test/fs-extra-tests.ts",
"test/fs-extra-tests-module.ts"
]
}

View File

@@ -1,10 +1,6 @@
import gfs = require('graceful-fs');
import * as gfs2 from 'graceful-fs';
// test const { gracefuifly } = require('graceful-fs');
// tslint:disable-next-line:no-duplicate-imports
import { gracefulify } from 'graceful-fs';
import * as fs from 'fs';
import * as fse from 'fs-extra';
import { promisify } from 'util';
const str = '';
@@ -21,9 +17,6 @@ const _fs: typeof fs = gracefulified;
gracefulified.lutimes; // $ExpectType typeof lutimes
promisify(gracefulified.lutimes); // $ExpectType (path: PathLike, atime: TimeLike, mtime: TimeLike) => Promise<void>
const fseGrace = gracefulify(fse);
fseGrace.lutimes; // $ExpectType typeof lutimes
fs.lutimes(buf, str, str, err => {
err; // $ExpectType ErrnoException | null
});

View File

@@ -3,7 +3,6 @@
// Definitions by: Bart van der Schoor <https://github.com/Bartvds>
// BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// Minimum TypeScript Version: 3.9
/// <reference types="node" />

View File

@@ -51,7 +51,7 @@ export type JFWriteOptions =
| null;
export type ReadCallback = (err: NodeJS.ErrnoException | null, data: any) => void;
export type WriteCallback = (err: NodeJS.ErrnoException) => void;
export type WriteCallback = (err: NodeJS.ErrnoException | null) => void;
/**
* @see {@link https://github.com/jprichardson/node-jsonfile#readfilefilename-options-callback}

View File

@@ -35,25 +35,25 @@ jsonfile.readFileSync(file, { encoding: 'utf8', throws: true });
// $ExpectType void
jsonfile.writeFile(file, obj, err => {
// $ExpectType ErrnoException
// $ExpectType ErrnoException | null
err;
});
// $ExpectType void
jsonfile.writeFile(file, obj, { spaces: 2 }, err => {
// $ExpectType ErrnoException
// $ExpectType ErrnoException | null
err;
});
// $ExpectType void
jsonfile.writeFile(file, obj, { spaces: 2, EOL: '\r\n' }, err => {
// $ExpectType ErrnoException
// $ExpectType ErrnoException | null
err;
});
// $ExpectType void
jsonfile.writeFile(file, obj, { flag: 'a' }, err => {
// $ExpectType ErrnoException
// $ExpectType ErrnoException | null
err;
});

9
types/jsonfile/utils.d.ts vendored Normal file
View File

@@ -0,0 +1,9 @@
export function stringify(obj: any, options?: StringifyOptions): string;
export function stripBom(content: string): string;
export interface StringifyOptions {
EOL?: string | undefined;
finalEOL?: boolean | undefined;
replacer?: ((key: string, value: any) => any) | undefined;
spaces?: string | number | undefined;
}

View File

@@ -1,10 +0,0 @@
export function stringify(
obj: any,
options?: {
EOL?: string | undefined;
finalEOL?: boolean | undefined;
replacer?: ((key: string, value: any) => any) | undefined;
spaces?: string | number | undefined;
},
): string;
export function stripBom(content: string): string;