Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/cross-spawn/lib/util/readShebang.js')
-rw-r--r--node_modules/cross-spawn/lib/util/readShebang.js32
1 files changed, 9 insertions, 23 deletions
diff --git a/node_modules/cross-spawn/lib/util/readShebang.js b/node_modules/cross-spawn/lib/util/readShebang.js
index 2cf3541c9..5e83733fe 100644
--- a/node_modules/cross-spawn/lib/util/readShebang.js
+++ b/node_modules/cross-spawn/lib/util/readShebang.js
@@ -1,37 +1,23 @@
'use strict';
-var fs = require('fs');
-var LRU = require('lru-cache');
-var shebangCommand = require('shebang-command');
-
-var shebangCache = new LRU({ max: 50, maxAge: 30 * 1000 }); // Cache just for 30sec
+const fs = require('fs');
+const shebangCommand = require('shebang-command');
function readShebang(command) {
- var buffer;
- var fd;
- var shebang;
-
- // Check if it is in the cache first
- if (shebangCache.has(command)) {
- return shebangCache.get(command);
- }
-
// Read the first 150 bytes from the file
- buffer = new Buffer(150);
+ const size = 150;
+ const buffer = Buffer.alloc(size);
+
+ let fd;
try {
fd = fs.openSync(command, 'r');
- fs.readSync(fd, buffer, 0, 150, 0);
+ fs.readSync(fd, buffer, 0, size, 0);
fs.closeSync(fd);
- } catch (e) { /* empty */ }
+ } catch (e) { /* Empty */ }
// Attempt to extract shebang (null is returned if not a shebang)
- shebang = shebangCommand(buffer.toString());
-
- // Store the shebang in the cache
- shebangCache.set(command, shebang);
-
- return shebang;
+ return shebangCommand(buffer.toString());
}
module.exports = readShebang;