Comparing version 1.0.5 to 1.1.4
24
index.js
@@ -15,10 +15,20 @@ #! /usr/bin/env node | ||
const userModule = require(path.join(process.cwd(), process.argv[2])); | ||
const isEs6 = path.extname(process.argv[2]) === '.mjs'; | ||
if (isEs6) { | ||
import('file://' + path.resolve(path.join(process.cwd(), process.argv[2]))).then((userModule) => { | ||
executeInModule(userModule, process.argv[3], params); | ||
}); | ||
} else { | ||
const userModule = require(path.join(process.cwd(), process.argv[2])); | ||
executeInModule(userModule, process.argv[3], params); | ||
} | ||
if (!userModule) { | ||
throw new Error(`Module ${userModule} does not exists`); | ||
function executeInModule(userMod, fnName, fnParams) { | ||
if (!userMod) { | ||
throw new Error(`Module ${userMod} does not exists`); | ||
} | ||
if (!userMod[fnName]) { | ||
throw new Error(`Function ${fnName} is not present or exported from module ${userMod}`); | ||
} | ||
userMod[fnName](...fnParams); | ||
} | ||
if (!userModule[process.argv[3]]) { | ||
throw new Error(`Function ${process.argv[3]} is not present or exported from module ${userModule}`); | ||
} | ||
userModule[process.argv[3]](...params); |
24
mem.js
@@ -15,10 +15,20 @@ #! /usr/bin/env node --max-old-space-size=4096 | ||
const userModule = require(path.join(process.cwd(), process.argv[2])); | ||
const isEs6 = path.extname(process.argv[2]) === '.mjs'; | ||
if (isEs6) { | ||
import('file://' + path.resolve(path.join(process.cwd(), process.argv[2]))).then((userModule) => { | ||
executeInModule(userModule, process.argv[3], params); | ||
}); | ||
} else { | ||
const userModule = require(path.join(process.cwd(), process.argv[2])); | ||
executeInModule(userModule, process.argv[3], params); | ||
} | ||
if (!userModule) { | ||
throw new Error(`Module ${userModule} does not exists`); | ||
function executeInModule(userMod, fnName, fnParams) { | ||
if (!userMod) { | ||
throw new Error(`Module ${userMod} does not exists`); | ||
} | ||
if (!userMod[fnName]) { | ||
throw new Error(`Function ${fnName} is not present or exported from module ${userMod}`); | ||
} | ||
userMod[fnName](...fnParams); | ||
} | ||
if (!userModule[process.argv[3]]) { | ||
throw new Error(`Function ${process.argv[3]} is not present or exported from module ${userModule}`); | ||
} | ||
userModule[process.argv[3]](...params); |
@@ -25,3 +25,3 @@ { | ||
}, | ||
"version": "1.0.5", | ||
"version": "1.1.4", | ||
"repository": { | ||
@@ -28,0 +28,0 @@ "type": "git", |
@@ -0,0 +0,0 @@ # run-func |
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
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
3116
58