0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-01-13 22:48:31 -05:00
verdaccio/packages/plugins/local-storage/src/fs.ts
Juan Picado ef88da3b47
fix: improve support for fs promises older nodejs (#3570)
* fix: improve support for fs promises older nodejs

* second try with fallback for nodejs18
2023-01-22 09:48:04 +01:00

44 lines
988 B
TypeScript

import fsCallback from 'fs';
import fs from 'fs';
const fsP = fs.promises ? fs.promises : require('fs/promises');
const readFile = fsP.readFile;
const mkdirPromise = fsP.mkdir;
const accessPromise = fsP.access;
const writeFilePromise = fsP.writeFile;
const readdirPromise = fsP.readdir;
const statPromise = fsP.stat;
const unlinkPromise = fsP.unlink;
const rmdirPromise = fsP.rmdir;
const renamePromise = fsP.rename;
const openPromise = fsP.open;
const readFilePromise = async (path) => {
return await readFile(path, 'utf8');
};
function fstatPromise(fd: number): Promise<fsCallback.Stats> {
return new Promise((resolve, reject) => {
fsCallback.fstat(fd, function (err, stats) {
if (err) {
return reject(err);
}
return resolve(stats);
});
});
}
export {
readFilePromise,
renamePromise,
mkdirPromise,
writeFilePromise,
readdirPromise,
statPromise,
accessPromise,
unlinkPromise,
rmdirPromise,
openPromise,
fstatPromise,
};