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

visgl / loaders.gl / 20382848403

19 Dec 2025 09:20PM UTC coverage: 35.219% (+0.1%) from 35.095%
20382848403

push

github

web-flow
feat: Upgrade to handle ArrayBufferLike (#3271)

1190 of 2002 branches covered (59.44%)

Branch coverage included in aggregate %.

157 of 269 new or added lines in 41 files covered. (58.36%)

3 existing lines in 3 files now uncovered.

37536 of 107957 relevant lines covered (34.77%)

0.79 hits per line

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

0.0
/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';
×
NEW
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')) {
×
19
    const response = await fetch(filename);
×
20
    return await response.arrayBuffer();
×
21
  }
×
22
  const buffer = fs.readFileSync(filename);
×
NEW
23
  return ensureArrayBuffer(buffer.buffer);
×
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> {
×
32
  if (filename.startsWith('http')) {
×
33
    const response = await fetch(filename);
×
34
    return await response.text();
×
35
  }
×
36
  const text = fs.readFileSync(filename, 'utf8');
×
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')) {
×
46
    const response = await fetch(filename);
×
47
    const code = await response.text();
×
48
    return requireFromString(code);
×
49
  }
×
50

×
51
  if (!filename.startsWith('/')) {
×
52
    filename = `${process.cwd()}/${filename}`;
×
53
  }
×
54
  const code = fs.readFileSync(filename, 'utf8');
×
55
  return requireFromString(code);
×
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 = '',
×
67
  options?: {
×
68
    prependPaths?: string[];
×
69
    appendPaths?: string[];
×
70
  }
×
71
): any {
×
72
  if (typeof filename === 'object') {
×
73
    options = filename;
×
74
    filename = '';
×
75
  }
×
76
  filename = filename.replace('file://', '');
×
77

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

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

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

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

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

×
101
  return newModule.exports;
×
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