Skip to content

Commit f94e325

Browse files
shrirambalajijuanpicado
authored andcommitted
fix: fs.exists with other fileSystem alternatives (#159)
* 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
1 parent 5282800 commit f94e325

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

plugins/memory/src/memory-handler.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ class MemoryHandler implements IPackageStorageManager {
106106
const temporalName = `/${name}`;
107107

108108
process.nextTick(function() {
109-
fs.exists(temporalName, function(exists) {
110-
if (exists) {
109+
fs.stat(temporalName, function(fileError, stats) {
110+
if (!fileError && stats) {
111111
return uploadStream.emit('error', fSError(fileExist));
112112
}
113113

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

147147
process.nextTick(function() {
148-
fs.exists(pathName, function(exists) {
149-
if (!exists) {
150-
readTarballStream.emit('error', noPackageFoundError());
151-
} else {
148+
fs.stat(pathName, function(fileError, stats) {
149+
if (fileError && !stats) {
150+
return readTarballStream.emit('error', noPackageFoundError());
151+
}
152+
153+
try {
152154
const readStream = fs.createReadStream(pathName);
153155

154-
readTarballStream.emit('content-length', fs.data[name].length);
156+
const contentLength: number = (fs.data[name] && fs.data[name].length) || 0;
157+
readTarballStream.emit('content-length', contentLength);
155158
readTarballStream.emit('open');
156159
readStream.pipe(readTarballStream);
157160
readStream.on('error', (error: any) => {
@@ -161,6 +164,8 @@ class MemoryHandler implements IPackageStorageManager {
161164
readTarballStream.abort = function(): void {
162165
readStream.destroy(fSError('read has been aborted', 400));
163166
};
167+
} catch (err) {
168+
readTarballStream.emit('error', err);
164169
}
165170
});
166171
});

0 commit comments

Comments
 (0)