faas-js-runtime
Advanced tools
Comparing version 0.9.6 to 0.9.7
@@ -0,1 +1,2 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
@@ -8,2 +9,6 @@ | ||
if (isESM(filePath)) { | ||
if (process.platform === 'win32') { | ||
// Windows requires the file path to be a URL | ||
filePath = `file:///${filePath}`; | ||
} | ||
code = await dynamicImport(filePath); | ||
@@ -29,12 +34,27 @@ } else { | ||
// find the functions package.json and see if it has a type field | ||
const functionPkg = require(path.join(pathParsed.dir, 'package.json')); | ||
if (functionPkg.type === 'module') { | ||
return true; | ||
// look in the parent directory if the function is in a subdirectory | ||
let dir = pathParsed.dir; | ||
const rootDir = path.parse(process.cwd()).root; | ||
while (!hasPackageJson(dir)) { | ||
if (dir === rootDir) return false; | ||
dir = path.dirname(dir); | ||
} | ||
// Should default to CJS | ||
return false; | ||
// Load the package.json and check the type field | ||
// Put this in a try/catch in case the package.json is invalid | ||
let pkgPath = path.join(dir, 'package.json'); | ||
try { | ||
const functionPkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8')); | ||
return functionPkg.type === 'module'; | ||
} catch(e) { | ||
console.warn(e); | ||
return false; | ||
} | ||
} | ||
function hasPackageJson(dir) { | ||
const pkgPath = path.join(dir, 'package.json'); | ||
return fs.existsSync(pkgPath); | ||
} | ||
module.exports = exports = { loadFunction }; |
{ | ||
"name": "faas-js-runtime", | ||
"version": "0.9.6", | ||
"version": "0.9.7", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "type": "git", |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
42691
684