@loaders.gl/worker-utils 4.2.0-alpha.5 → 4.2.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,7 +22,7 @@ export type ChildProcessProxyProps = {
22
22
  /** wait: 0 - infinity */
23
23
  wait?: number;
24
24
  /** Options passed on to Node'.js `spawn` */
25
- spawn?: ChildProcess.SpawnOptionsWithoutStdio;
25
+ spawn?: any; // ChildProcess.SpawnOptionsWithoutStdio;
26
26
  /** Should proceed if stderr stream recieved data */
27
27
  ignoreStderr?: boolean;
28
28
  /** Callback when the */
@@ -4,7 +4,10 @@
4
4
 
5
5
  import type {WorkerMessageData, WorkerMessageType, WorkerMessagePayload} from '../../types';
6
6
  import {getTransferList} from '../worker-utils/get-transfer-list';
7
- import {TransferListItem, parentPort} from '../node/worker_threads';
7
+ // import type {TransferListItem} from '../node/worker_threads';
8
+ import {parentPort} from '../node/worker_threads';
9
+
10
+ type TransferListItem = any;
8
11
 
9
12
  /** Vile hack to defeat over-zealous bundlers from stripping out the require */
10
13
  async function getParentPort() {
@@ -54,7 +57,9 @@ export default class WorkerBody {
54
57
 
55
58
  getParentPort().then((parentPort) => {
56
59
  if (parentPort) {
57
- parentPort.on('message', handleMessage);
60
+ parentPort.on('message', (message) => {
61
+ handleMessage(message);
62
+ });
58
63
  // if (message == 'exit') { parentPort.unref(); }
59
64
  // eslint-disable-next-line
60
65
  parentPort.on('exit', () => console.debug('Node worker closing'));
@@ -1,18 +0,0 @@
1
- /**
2
- * Load a file from local file system
3
- * @param filename
4
- * @returns
5
- */
6
- export declare function readFileAsArrayBuffer(filename: string): Promise<ArrayBuffer>;
7
- /**
8
- * Load a file from local file system
9
- * @param filename
10
- * @returns
11
- */
12
- export declare function readFileAsText(filename: string): Promise<string>;
13
- export declare function requireFromFile(filename: string): Promise<any>;
14
- export declare function requireFromString(code: string, filename?: string, options?: {
15
- prependPaths?: string[];
16
- appendPaths?: string[];
17
- }): any;
18
- //# sourceMappingURL=require-utils.node.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"require-utils.node.d.ts","sourceRoot":"","sources":["../../../src/lib/node/require-utils.node.ts"],"names":[],"mappings":"AAcA;;;;GAIG;AACH,wBAAsB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAOlF;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAOtE;AAMD,wBAAsB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAYpE;AAQD,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,QAAQ,SAAK,EACb,OAAO,CAAC,EAAE;IACR,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB,GACA,GAAG,CA8BL"}
@@ -1,83 +0,0 @@
1
- // loaders.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
- // Fork of https://github.com/floatdrop/require-from-string/blob/master/index.js
5
- // Copyright (c) Vsevolod Strukchinsky <floatdrop@gmail.com> (github.com/floatdrop)
6
- // MIT license
7
- // this file is not visible to webpack (it is excluded in the package.json "browser" field).
8
- import Module from 'module';
9
- import * as path from 'path';
10
- import * as fs from 'fs';
11
- /**
12
- * Load a file from local file system
13
- * @param filename
14
- * @returns
15
- */
16
- export async function readFileAsArrayBuffer(filename) {
17
- if (filename.startsWith('http')) {
18
- const response = await fetch(filename);
19
- return await response.arrayBuffer();
20
- }
21
- const buffer = fs.readFileSync(filename);
22
- return buffer.buffer;
23
- }
24
- /**
25
- * Load a file from local file system
26
- * @param filename
27
- * @returns
28
- */
29
- export async function readFileAsText(filename) {
30
- if (filename.startsWith('http')) {
31
- const response = await fetch(filename);
32
- return await response.text();
33
- }
34
- const text = fs.readFileSync(filename, 'utf8');
35
- return text;
36
- }
37
- // Node.js Dynamically require from file
38
- // Relative names are resolved relative to cwd
39
- // This indirect function is provided because webpack will try to bundle `module.require`.
40
- // this file is not visible to webpack (it is excluded in the package.json "browser" field).
41
- export async function requireFromFile(filename) {
42
- if (filename.startsWith('http')) {
43
- const response = await fetch(filename);
44
- const code = await response.text();
45
- return requireFromString(code);
46
- }
47
- if (!filename.startsWith('/')) {
48
- filename = `${process.cwd()}/${filename}`;
49
- }
50
- const code = await fs.promises.readFile(filename, 'utf8');
51
- return requireFromString(code);
52
- }
53
- // Dynamically require from string
54
- // - `code` - Required - Type: string - Module code.
55
- // - `filename` - Type: string - Default: '' - Optional filename.
56
- // - `options.appendPaths` Type: Array List of paths, that will be appended to module paths.
57
- // Useful, when you want to be able require modules from these paths.
58
- // - `options.prependPaths` Type: Array Same as appendPaths, but paths will be prepended.
59
- export function requireFromString(code, filename = '', options) {
60
- if (typeof filename === 'object') {
61
- options = filename;
62
- filename = '';
63
- }
64
- if (typeof code !== 'string') {
65
- throw new Error(`code must be a string, not ${typeof code}`);
66
- }
67
- // @ts-ignore
68
- const paths = Module._nodeModulePaths(path.dirname(filename));
69
- const parent = typeof module !== 'undefined' && module?.parent;
70
- // @ts-ignore
71
- const newModule = new Module(filename, parent);
72
- newModule.filename = filename;
73
- newModule.paths = []
74
- .concat(options?.prependPaths || [])
75
- .concat(paths)
76
- .concat(options?.appendPaths || []);
77
- // @ts-ignore
78
- newModule._compile(code, filename);
79
- if (parent && parent.children) {
80
- parent.children.splice(parent.children.indexOf(newModule), 1);
81
- }
82
- return newModule.exports;
83
- }
@@ -1,104 +0,0 @@
1
- // loaders.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
-
5
- // Fork of https://github.com/floatdrop/require-from-string/blob/master/index.js
6
- // Copyright (c) Vsevolod Strukchinsky <floatdrop@gmail.com> (github.com/floatdrop)
7
- // MIT license
8
-
9
- // this file is not visible to webpack (it is excluded in the package.json "browser" field).
10
-
11
- import Module from 'module';
12
- import * as path from 'path';
13
- import * as fs from 'fs';
14
-
15
- /**
16
- * Load a file from local file system
17
- * @param filename
18
- * @returns
19
- */
20
- export async function readFileAsArrayBuffer(filename: string): Promise<ArrayBuffer> {
21
- if (filename.startsWith('http')) {
22
- const response = await fetch(filename);
23
- return await response.arrayBuffer();
24
- }
25
- const buffer = fs.readFileSync(filename);
26
- return buffer.buffer;
27
- }
28
-
29
- /**
30
- * Load a file from local file system
31
- * @param filename
32
- * @returns
33
- */
34
- export async function readFileAsText(filename: string): Promise<string> {
35
- if (filename.startsWith('http')) {
36
- const response = await fetch(filename);
37
- return await response.text();
38
- }
39
- const text = fs.readFileSync(filename, 'utf8');
40
- return text;
41
- }
42
-
43
- // Node.js Dynamically require from file
44
- // Relative names are resolved relative to cwd
45
- // This indirect function is provided because webpack will try to bundle `module.require`.
46
- // this file is not visible to webpack (it is excluded in the package.json "browser" field).
47
- export async function requireFromFile(filename: string): Promise<any> {
48
- if (filename.startsWith('http')) {
49
- const response = await fetch(filename);
50
- const code = await response.text();
51
- return requireFromString(code);
52
- }
53
-
54
- if (!filename.startsWith('/')) {
55
- filename = `${process.cwd()}/${filename}`;
56
- }
57
- const code = await fs.promises.readFile(filename, 'utf8');
58
- return requireFromString(code);
59
- }
60
-
61
- // Dynamically require from string
62
- // - `code` - Required - Type: string - Module code.
63
- // - `filename` - Type: string - Default: '' - Optional filename.
64
- // - `options.appendPaths` Type: Array List of paths, that will be appended to module paths.
65
- // Useful, when you want to be able require modules from these paths.
66
- // - `options.prependPaths` Type: Array Same as appendPaths, but paths will be prepended.
67
- export function requireFromString(
68
- code: string,
69
- filename = '',
70
- options?: {
71
- prependPaths?: string[];
72
- appendPaths?: string[];
73
- }
74
- ): any {
75
- if (typeof filename === 'object') {
76
- options = filename;
77
- filename = '';
78
- }
79
-
80
- if (typeof code !== 'string') {
81
- throw new Error(`code must be a string, not ${typeof code}`);
82
- }
83
-
84
- // @ts-ignore
85
- const paths = Module._nodeModulePaths(path.dirname(filename));
86
-
87
- const parent = typeof module !== 'undefined' && module?.parent;
88
-
89
- // @ts-ignore
90
- const newModule = new Module(filename, parent);
91
- newModule.filename = filename;
92
- newModule.paths = ([] as string[])
93
- .concat(options?.prependPaths || [])
94
- .concat(paths)
95
- .concat(options?.appendPaths || []);
96
- // @ts-ignore
97
- newModule._compile(code, filename);
98
-
99
- if (parent && parent.children) {
100
- parent.children.splice(parent.children.indexOf(newModule), 1);
101
- }
102
-
103
- return newModule.exports;
104
- }