Skip to content

Commit

Permalink
fix: fs.exists with other fileSystem alternatives (#159)
Browse files Browse the repository at this point in the history
* chore: replace fs.existsSync with fs.accessSync

fs.exists is deprecated starting from node12.

* chore:  replace fs.exists with fs.stat in memory-handler

fs.exists is deprecated starting from node 12

* revert: replacing fs.existsSync as it is not deprecated
  • Loading branch information
shrirambalaji authored and juanpicado committed Oct 5, 2019
1 parent 5282800 commit f94e325
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions plugins/memory/src/memory-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ class MemoryHandler implements IPackageStorageManager {
const temporalName = `/${name}`;

process.nextTick(function() {
fs.exists(temporalName, function(exists) {
if (exists) {
fs.stat(temporalName, function(fileError, stats) {
if (!fileError && stats) {
return uploadStream.emit('error', fSError(fileExist));
}

Expand Down Expand Up @@ -145,13 +145,16 @@ class MemoryHandler implements IPackageStorageManager {
const readTarballStream: IReadTarball = new ReadTarball({});

process.nextTick(function() {
fs.exists(pathName, function(exists) {
if (!exists) {
readTarballStream.emit('error', noPackageFoundError());
} else {
fs.stat(pathName, function(fileError, stats) {
if (fileError && !stats) {
return readTarballStream.emit('error', noPackageFoundError());
}

try {
const readStream = fs.createReadStream(pathName);

readTarballStream.emit('content-length', fs.data[name].length);
const contentLength: number = (fs.data[name] && fs.data[name].length) || 0;
readTarballStream.emit('content-length', contentLength);
readTarballStream.emit('open');
readStream.pipe(readTarballStream);
readStream.on('error', (error: any) => {
Expand All @@ -161,6 +164,8 @@ class MemoryHandler implements IPackageStorageManager {
readTarballStream.abort = function(): void {
readStream.destroy(fSError('read has been aborted', 400));
};
} catch (err) {
readTarballStream.emit('error', err);
}
});
});
Expand Down

0 comments on commit f94e325

Please sign in to comment.