@zkochan/cmd-shim
Advanced tools
Comparing version 5.3.0 to 5.3.1
67
index.js
@@ -31,8 +31,8 @@ 'use strict'; | ||
opts_.fs_ = { | ||
chmod: fs.chmod ? util_1.promisify(fs.chmod) : (async () => { }), | ||
mkdir: util_1.promisify(fs.mkdir), | ||
readFile: util_1.promisify(fs.readFile), | ||
stat: util_1.promisify(fs.stat), | ||
unlink: util_1.promisify(fs.unlink), | ||
writeFile: util_1.promisify(fs.writeFile) | ||
chmod: fs.chmod ? (0, util_1.promisify)(fs.chmod) : (async () => { }), | ||
mkdir: (0, util_1.promisify)(fs.mkdir), | ||
readFile: (0, util_1.promisify)(fs.readFile), | ||
stat: (0, util_1.promisify)(fs.stat), | ||
unlink: (0, util_1.promisify)(fs.unlink), | ||
writeFile: (0, util_1.promisify)(fs.writeFile) | ||
}; | ||
@@ -52,3 +52,2 @@ return opts_; | ||
const opts_ = ingestOptions(opts); | ||
await opts_.fs_.stat(src); | ||
await cmdShim_(src, to, opts_); | ||
@@ -151,22 +150,44 @@ } | ||
async function searchScriptRuntime(target, opts) { | ||
const data = await opts.fs_.readFile(target, 'utf8'); | ||
// First, check if the bin is a #! of some sort. | ||
const firstLine = data.trim().split(/\r*\n/)[0]; | ||
const shebang = firstLine.match(shebangExpr); | ||
if (!shebang) { | ||
// If not, infer script type from its extension. | ||
// If the inference fails, it's something that'll be compiled, or some other | ||
// sort of script, and just call it directly. | ||
const targetExtension = path.extname(target).toLowerCase(); | ||
try { | ||
const data = await opts.fs_.readFile(target, 'utf8'); | ||
// First, check if the bin is a #! of some sort. | ||
const firstLine = data.trim().split(/\r*\n/)[0]; | ||
const shebang = firstLine.match(shebangExpr); | ||
if (!shebang) { | ||
// If not, infer script type from its extension. | ||
// If the inference fails, it's something that'll be compiled, or some other | ||
// sort of script, and just call it directly. | ||
const targetExtension = path.extname(target).toLowerCase(); | ||
return { | ||
// undefined if extension is unknown but it's converted to null. | ||
program: extensionToProgramMap.get(targetExtension) || null, | ||
additionalArgs: '' | ||
}; | ||
} | ||
return { | ||
// undefined if extension is unknown but it's converted to null. | ||
program: extensionToProgramMap.get(targetExtension) || null, | ||
additionalArgs: '' | ||
program: shebang[1], | ||
additionalArgs: shebang[2] | ||
}; | ||
} | ||
return { | ||
program: shebang[1], | ||
additionalArgs: shebang[2] | ||
}; | ||
catch (err) { | ||
if (!isWindows() || err.code !== 'ENOENT') | ||
throw err; | ||
if (await opts.fs_.stat(`${target}${getExeExtension()}`)) { | ||
return { | ||
program: null, | ||
additionalArgs: '', | ||
}; | ||
} | ||
throw err; | ||
} | ||
} | ||
function getExeExtension() { | ||
let cmdExtension; | ||
if (process.env.PATHEXT) { | ||
cmdExtension = process.env.PATHEXT | ||
.split(path.delimiter) | ||
.find(ext => ext.toLowerCase() === '.exe'); | ||
} | ||
return cmdExtension || '.exe'; | ||
} | ||
/** | ||
@@ -173,0 +194,0 @@ * Write shim to the file system while executing the pre- and post-processes |
{ | ||
"name": "@zkochan/cmd-shim", | ||
"version": "5.3.0", | ||
"version": "5.3.1", | ||
"description": "Used in pnpm for command line application support", | ||
@@ -22,3 +22,3 @@ "author": { | ||
"dependencies": { | ||
"cmd-extension": "^1.0.1", | ||
"cmd-extension": "^1.0.2", | ||
"is-windows": "^1.0.2" | ||
@@ -28,11 +28,12 @@ }, | ||
"@types/is-windows": "^1.0.0", | ||
"@types/jest": "^26.0.20", | ||
"@types/node": "^14.14.20", | ||
"@types/jest": "^26.0.24", | ||
"@types/node": "^14.18.23", | ||
"jest": "^26.6.3", | ||
"memfs": "^3.2.0", | ||
"mock-fs": "^4.13.0", | ||
"memfs": "^3.4.7", | ||
"mock-fs": "^4.14.0", | ||
"mos": "^1.3.1", | ||
"mos-plugin-readme": "^1.0.4", | ||
"standard": "^14.3.4", | ||
"typescript": "^4.1.3" | ||
"tempy": "^1.0.1", | ||
"typescript": "^4.7.4" | ||
}, | ||
@@ -39,0 +40,0 @@ "engines": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
37437
609
11
3
Updatedcmd-extension@^1.0.2