• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nodeshift / faas-js-runtime / 28096121195

24 Jun 2026 11:45AM UTC coverage: 86.882% (-0.6%) from 87.527%
28096121195

Pull #445

github

web-flow
Merge 07e9452fa into 3bb3df089
Pull Request #445: feat!: remove Node 20 support

117 of 146 branches covered (80.14%)

Branch coverage included in aggregate %.

287 of 319 relevant lines covered (89.97%)

83.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.29
/lib/function-loader.js
1
const fs = require('fs');
3✔
2
const path = require('path');
3✔
3

4
// This is the way to import es modules inside a CJS module
5
const dynamicImport = new Function('modulePath', 'return import(modulePath)');
3✔
6

7
async function loadFunction(filePath) {
8
  if (isESM(filePath)) {
12✔
9
    if (process.platform === 'win32') {
9!
10
      // Windows requires the file path to be a URL
11
      filePath = `file:///${filePath}`;
×
12
    }
13
    code = await dynamicImport(filePath);
9✔
14
  } else {
15
    code = require(filePath);
3✔
16
  }
17

18
  return code;
12✔
19
}
20

21
// https://nodejs.org/dist/latest-v18.x/docs/api/packages.html#determining-module-system
22
// An ESM module can be determined 2 ways
23
// 1. has the mjs file extention
24
// 2. type=module in the package.json
25
function isESM(filePath) {
26
  const pathParsed = path.parse(filePath);
12✔
27

28
  if (pathParsed.ext === '.mjs') {
12✔
29
    return true;
3✔
30
  }
31

32
  // find the functions package.json and see if it has a type field
33
  // look in the parent directory if the function is in a subdirectory
34
  let dir = pathParsed.dir;
9✔
35
  const rootDir = path.parse(process.cwd()).root;
9✔
36
  while (!hasPackageJson(dir)) {
9✔
37
    if (dir === rootDir) return false;
3!
38
    dir = path.dirname(dir);
3✔
39
  }
40

41
  // Load the package.json and check the type field
42
  // Put this in a try/catch in case the package.json is invalid
43
  let pkgPath = path.join(dir, 'package.json');
9✔
44
  try {
9✔
45
    const functionPkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
9✔
46
    return functionPkg.type === 'module';
9✔
47
  } catch(e) {
48
    console.warn(e);
×
49
    return false;
×
50
  }
51
}
52

53
function hasPackageJson(dir) {
54
  const pkgPath = path.join(dir, 'package.json');
12✔
55
  return fs.existsSync(pkgPath);
12✔
56
}
57

58
module.exports = exports = { loadFunction };
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc