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

visgl / loaders.gl / 25070233425

28 Apr 2026 06:20PM UTC coverage: 59.434% (+0.01%) from 59.423%
25070233425

push

github

web-flow
website: Add tabs for navigating between format docs (#3407)

11310 of 20887 branches covered (54.15%)

Branch coverage included in aggregate %.

89 of 136 new or added lines in 13 files covered. (65.44%)

1742 existing lines in 132 files now uncovered.

23500 of 37682 relevant lines covered (62.36%)

16296.63 hits per line

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

84.78
/modules/polyfills/src/load-library/require-utils.node.ts
1
// Fork of https://github.com/floatdrop/require-from-string/blob/master/index.js
2
// Copyright (c) Vsevolod Strukchinsky <floatdrop@gmail.com> (github.com/floatdrop)
3
// MIT license
4

5
// this file is not visible to webpack (it is excluded in the package.json "browser" field).
6

7
import Module from 'module';
8
import path from 'path';
9
import fs from 'fs';
10
import {ensureArrayBuffer} from '@loaders.gl/loader-utils';
11

12
/**
13
 * Load a file from local file system
14
 * @param filename
15
 * @returns
16
 */
17
export async function readFileAsArrayBuffer(filename: string): Promise<ArrayBuffer> {
18
  if (filename.startsWith('http')) {
8!
UNCOV
19
    const response = await fetch(filename);
UNCOV
20
    return await response.arrayBuffer();
21
  }
22
  const buffer = fs.readFileSync(filename);
8✔
23
  return ensureArrayBuffer(buffer.buffer);
8✔
24
}
25

26
/**
27
 * Load a file from local file system
28
 * @param filename
29
 * @returns
30
 */
31
export async function readFileAsText(filename: string): Promise<string> {
UNCOV
32
  if (filename.startsWith('http')) {
×
UNCOV
33
    const response = await fetch(filename);
UNCOV
34
    return await response.text();
35
  }
UNCOV
36
  const text = fs.readFileSync(filename, 'utf8');
UNCOV
37
  return text;
38
}
39

40
// Node.js Dynamically require from file
41
// Relative names are resolved relative to cwd
42
// This indirect function is provided because webpack will try to bundle `module.require`.
43
// this file is not visible to webpack (it is excluded in the package.json "browser" field).
44
export async function requireFromFile(filename: string): Promise<any> {
45
  if (filename.startsWith('http')) {
18✔
46
    const response = await fetch(filename);
10✔
47
    const code = await response.text();
10✔
48
    return requireFromString(code);
10✔
49
  }
50

51
  if (!filename.startsWith('/')) {
8!
52
    filename = `${process.cwd()}/${filename}`;
8✔
53
  }
54
  const code = fs.readFileSync(filename, 'utf8');
8✔
55
  return requireFromString(code);
8✔
56
}
57

58
// Dynamically require from string
59
// - `code` - Required - Type: string - Module code.
60
// - `filename` - Type: string - Default: '' - Optional filename.
61
// - `options.appendPaths` Type: Array List of paths, that will be appended to module paths.
62
// Useful, when you want to be able require modules from these paths.
63
// - `options.prependPaths` Type: Array Same as appendPaths, but paths will be prepended.
64
export function requireFromString(
65
  code: string,
66
  filename = '',
17✔
67
  options?: {
68
    prependPaths?: string[];
69
    appendPaths?: string[];
70
  }
71
): any {
72
  if (typeof filename === 'object') {
17!
UNCOV
73
    options = filename;
UNCOV
74
    filename = '';
75
  }
76
  filename = filename.replace('file://', '');
17✔
77

78
  if (typeof code !== 'string') {
17✔
79
    throw new Error(`code must be a string, not ${typeof code}`);
1✔
80
  }
81

82
  // @ts-ignore
83
  const paths = Module._nodeModulePaths(path.dirname(filename));
16✔
84

85
  const parent = typeof module !== 'undefined' && module?.parent;
16✔
86

87
  // @ts-ignore
88
  const newModule = new Module(filename, parent);
17✔
89
  newModule.filename = filename;
17✔
90
  newModule.paths = ([] as string[])
17✔
91
    .concat(options?.prependPaths || [])
33✔
92
    .concat(paths)
93
    .concat(options?.appendPaths || []);
33✔
94
  // @ts-ignore
95
  newModule._compile(code, filename);
17✔
96

97
  if (parent && parent.children) {
17!
UNCOV
98
    parent.children.splice(parent.children.indexOf(newModule), 1);
99
  }
100

101
  return newModule.exports;
15✔
102
}
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