Socket
Socket
Sign inDemoInstall

faas-js-runtime

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

faas-js-runtime - npm Package Compare versions

Comparing version 0.9.6 to 0.9.7

30

lib/function-loader.js

@@ -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 };

2

package.json
{
"name": "faas-js-runtime",
"version": "0.9.6",
"version": "0.9.7",
"repository": {

@@ -5,0 +5,0 @@ "type": "git",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc