@loaders.gl/worker-utils 4.0.0-alpha.22 → 4.0.0-alpha.24
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.
- package/dist/es5/lib/env-utils/version.js +2 -2
- package/dist/es5/lib/library-utils/library-utils.js +1 -1
- package/dist/es5/lib/worker-api/get-worker-url.js +1 -1
- package/dist/esm/lib/env-utils/version.js +2 -2
- package/dist/esm/lib/library-utils/library-utils.js +1 -1
- package/dist/esm/lib/worker-api/get-worker-url.js +1 -1
- package/package.json +4 -5
- package/dist/index.js +0 -59
- package/dist/lib/async-queue/async-queue.js +0 -87
- package/dist/lib/env-utils/assert.js +0 -13
- package/dist/lib/env-utils/globals.js +0 -32
- package/dist/lib/env-utils/version.js +0 -12
- package/dist/lib/library-utils/library-utils.js +0 -188
- package/dist/lib/node/require-utils.node.js +0 -89
- package/dist/lib/node/worker_threads-browser.js +0 -15
- package/dist/lib/node/worker_threads.js +0 -33
- package/dist/lib/process-utils/child-process-proxy.js +0 -136
- package/dist/lib/process-utils/process-utils.js +0 -35
- package/dist/lib/worker-api/create-worker.js +0 -91
- package/dist/lib/worker-api/get-worker-url.js +0 -59
- package/dist/lib/worker-api/process-on-worker.js +0 -83
- package/dist/lib/worker-api/validate-worker-version.js +0 -35
- package/dist/lib/worker-farm/worker-body.js +0 -111
- package/dist/lib/worker-farm/worker-farm.js +0 -89
- package/dist/lib/worker-farm/worker-job.js +0 -47
- package/dist/lib/worker-farm/worker-pool.js +0 -164
- package/dist/lib/worker-farm/worker-thread.js +0 -131
- package/dist/lib/worker-utils/get-loadable-worker-url.js +0 -72
- package/dist/lib/worker-utils/get-transfer-list.js +0 -87
- package/dist/lib/worker-utils/remove-nontransferable-options.js +0 -27
- package/dist/types.js +0 -2
- package/dist/workers/null-worker.js +0 -7
|
@@ -5,9 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.VERSION = void 0;
|
|
7
7
|
var DEFAULT_VERSION = 'beta';
|
|
8
|
-
var VERSION = typeof "4.0.0-alpha.
|
|
8
|
+
var VERSION = typeof "4.0.0-alpha.24" !== 'undefined' ? "4.0.0-alpha.24" : DEFAULT_VERSION;
|
|
9
9
|
exports.VERSION = VERSION;
|
|
10
|
-
if (typeof "4.0.0-alpha.
|
|
10
|
+
if (typeof "4.0.0-alpha.24" === 'undefined') {
|
|
11
11
|
console.error('loaders.gl: The __VERSION__ variable is not injected using babel plugin. Latest unstable workers would be fetched from the CDN.');
|
|
12
12
|
}
|
|
13
13
|
//# sourceMappingURL=version.js.map
|
|
@@ -16,7 +16,7 @@ var _version = require("../env-utils/version");
|
|
|
16
16
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
17
17
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
18
18
|
var LATEST = 'beta';
|
|
19
|
-
var VERSION = typeof "4.0.0-alpha.
|
|
19
|
+
var VERSION = typeof "4.0.0-alpha.24" !== 'undefined' ? "4.0.0-alpha.24" : LATEST;
|
|
20
20
|
var loadLibraryPromises = {};
|
|
21
21
|
function loadLibrary(_x) {
|
|
22
22
|
return _loadLibrary.apply(this, arguments);
|
|
@@ -9,7 +9,7 @@ var _assert = require("../env-utils/assert");
|
|
|
9
9
|
var _globals = require("../env-utils/globals");
|
|
10
10
|
var _version = require("../env-utils/version");
|
|
11
11
|
var NPM_TAG = 'beta';
|
|
12
|
-
var VERSION = typeof "4.0.0-alpha.
|
|
12
|
+
var VERSION = typeof "4.0.0-alpha.24" !== 'undefined' ? "4.0.0-alpha.24" : NPM_TAG;
|
|
13
13
|
function getWorkerName(worker) {
|
|
14
14
|
var warning = worker.version !== VERSION ? " (worker-utils@".concat(VERSION, ")") : '';
|
|
15
15
|
return "".concat(worker.name, "@").concat(worker.version).concat(warning);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const DEFAULT_VERSION = 'beta';
|
|
2
|
-
export const VERSION = typeof "4.0.0-alpha.
|
|
3
|
-
if (typeof "4.0.0-alpha.
|
|
2
|
+
export const VERSION = typeof "4.0.0-alpha.24" !== 'undefined' ? "4.0.0-alpha.24" : DEFAULT_VERSION;
|
|
3
|
+
if (typeof "4.0.0-alpha.24" === 'undefined') {
|
|
4
4
|
console.error('loaders.gl: The __VERSION__ variable is not injected using babel plugin. Latest unstable workers would be fetched from the CDN.');
|
|
5
5
|
}
|
|
6
6
|
//# sourceMappingURL=version.js.map
|
|
@@ -3,7 +3,7 @@ import * as node from '../node/require-utils.node';
|
|
|
3
3
|
import { assert } from '../env-utils/assert';
|
|
4
4
|
import { VERSION as __VERSION__ } from '../env-utils/version';
|
|
5
5
|
const LATEST = 'beta';
|
|
6
|
-
const VERSION = typeof "4.0.0-alpha.
|
|
6
|
+
const VERSION = typeof "4.0.0-alpha.24" !== 'undefined' ? "4.0.0-alpha.24" : LATEST;
|
|
7
7
|
const loadLibraryPromises = {};
|
|
8
8
|
export async function loadLibrary(libraryUrl) {
|
|
9
9
|
let moduleName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
@@ -2,7 +2,7 @@ import { assert } from '../env-utils/assert';
|
|
|
2
2
|
import { isBrowser } from '../env-utils/globals';
|
|
3
3
|
import { VERSION as __VERSION__ } from '../env-utils/version';
|
|
4
4
|
const NPM_TAG = 'beta';
|
|
5
|
-
const VERSION = typeof "4.0.0-alpha.
|
|
5
|
+
const VERSION = typeof "4.0.0-alpha.24" !== 'undefined' ? "4.0.0-alpha.24" : NPM_TAG;
|
|
6
6
|
export function getWorkerName(worker) {
|
|
7
7
|
const warning = worker.version !== VERSION ? " (worker-utils@".concat(VERSION, ")") : '';
|
|
8
8
|
return "".concat(worker.name, "@").concat(worker.version).concat(warning);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/worker-utils",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.24",
|
|
4
4
|
"description": "Utilities for running tasks on worker threads",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -26,17 +26,16 @@
|
|
|
26
26
|
],
|
|
27
27
|
"browser": {
|
|
28
28
|
"child_process": false,
|
|
29
|
+
"module": false,
|
|
30
|
+
"path": false,
|
|
29
31
|
"fs": false,
|
|
30
32
|
"./src/lib/node/worker_threads.ts": "./src/lib/node/worker_threads-browser.ts",
|
|
31
|
-
"./dist/lib/node/worker_threads.js": "./dist/lib/node/worker_threads-browser.js",
|
|
32
33
|
"./dist/es5/lib/node/worker_threads.js": "./dist/es5/lib/node/worker_threads-browser.js",
|
|
33
34
|
"./dist/esm/lib/node/worker_threads.js": "./dist/esm/lib/node/worker_threads-browser.js",
|
|
34
35
|
"./src/lib/node/require-utils.node.ts": false,
|
|
35
|
-
"./dist/lib/node/require-utils.node.js": false,
|
|
36
36
|
"./dist/es5/lib/node/require-utils.node.js": false,
|
|
37
37
|
"./dist/esm/lib/node/require-utils.node.js": false,
|
|
38
38
|
"./src/lib/process-utils/child-process-proxy.ts": false,
|
|
39
|
-
"./dist/lib/process-utils/child-process-proxy.js": false,
|
|
40
39
|
"./dist/es5/lib/process-utils/child-process-proxy.js": false,
|
|
41
40
|
"./dist/esm/lib/process-utils/child-process-proxy.js": false
|
|
42
41
|
},
|
|
@@ -50,5 +49,5 @@
|
|
|
50
49
|
"dependencies": {
|
|
51
50
|
"@babel/runtime": "^7.3.1"
|
|
52
51
|
},
|
|
53
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "97a8990595c132fb14e3445a8768d9f4cb98ff05"
|
|
54
53
|
}
|
package/dist/index.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.NullWorker = exports.ChildProcessProxy = exports.AsyncQueue = exports.loadLibrary = exports.getLibraryUrl = exports.getTransferListForWriter = exports.getTransferList = exports.validateWorkerVersion = exports.getWorkerURL = exports.createWorker = exports.canProcessOnWorker = exports.processOnWorker = exports.WorkerBody = exports.WorkerPool = exports.WorkerFarm = exports.WorkerThread = exports.WorkerJob = exports.isWorker = exports.isBrowser = exports.assert = void 0;
|
|
7
|
-
const version_1 = require("./lib/env-utils/version");
|
|
8
|
-
// GENERAL UTILS
|
|
9
|
-
var assert_1 = require("./lib/env-utils/assert");
|
|
10
|
-
Object.defineProperty(exports, "assert", { enumerable: true, get: function () { return assert_1.assert; } });
|
|
11
|
-
var globals_1 = require("./lib/env-utils/globals");
|
|
12
|
-
Object.defineProperty(exports, "isBrowser", { enumerable: true, get: function () { return globals_1.isBrowser; } });
|
|
13
|
-
Object.defineProperty(exports, "isWorker", { enumerable: true, get: function () { return globals_1.isWorker; } });
|
|
14
|
-
// WORKER UTILS - TYPES
|
|
15
|
-
var worker_job_1 = require("./lib/worker-farm/worker-job");
|
|
16
|
-
Object.defineProperty(exports, "WorkerJob", { enumerable: true, get: function () { return __importDefault(worker_job_1).default; } });
|
|
17
|
-
var worker_thread_1 = require("./lib/worker-farm/worker-thread");
|
|
18
|
-
Object.defineProperty(exports, "WorkerThread", { enumerable: true, get: function () { return __importDefault(worker_thread_1).default; } });
|
|
19
|
-
// WORKER FARMS
|
|
20
|
-
var worker_farm_1 = require("./lib/worker-farm/worker-farm");
|
|
21
|
-
Object.defineProperty(exports, "WorkerFarm", { enumerable: true, get: function () { return __importDefault(worker_farm_1).default; } });
|
|
22
|
-
var worker_pool_1 = require("./lib/worker-farm/worker-pool");
|
|
23
|
-
Object.defineProperty(exports, "WorkerPool", { enumerable: true, get: function () { return __importDefault(worker_pool_1).default; } });
|
|
24
|
-
var worker_body_1 = require("./lib/worker-farm/worker-body");
|
|
25
|
-
Object.defineProperty(exports, "WorkerBody", { enumerable: true, get: function () { return __importDefault(worker_body_1).default; } });
|
|
26
|
-
var process_on_worker_1 = require("./lib/worker-api/process-on-worker");
|
|
27
|
-
Object.defineProperty(exports, "processOnWorker", { enumerable: true, get: function () { return process_on_worker_1.processOnWorker; } });
|
|
28
|
-
Object.defineProperty(exports, "canProcessOnWorker", { enumerable: true, get: function () { return process_on_worker_1.canProcessOnWorker; } });
|
|
29
|
-
var create_worker_1 = require("./lib/worker-api/create-worker");
|
|
30
|
-
Object.defineProperty(exports, "createWorker", { enumerable: true, get: function () { return create_worker_1.createWorker; } });
|
|
31
|
-
// WORKER UTILS - EXPORTS
|
|
32
|
-
var get_worker_url_1 = require("./lib/worker-api/get-worker-url");
|
|
33
|
-
Object.defineProperty(exports, "getWorkerURL", { enumerable: true, get: function () { return get_worker_url_1.getWorkerURL; } });
|
|
34
|
-
var validate_worker_version_1 = require("./lib/worker-api/validate-worker-version");
|
|
35
|
-
Object.defineProperty(exports, "validateWorkerVersion", { enumerable: true, get: function () { return validate_worker_version_1.validateWorkerVersion; } });
|
|
36
|
-
var get_transfer_list_1 = require("./lib/worker-utils/get-transfer-list");
|
|
37
|
-
Object.defineProperty(exports, "getTransferList", { enumerable: true, get: function () { return get_transfer_list_1.getTransferList; } });
|
|
38
|
-
Object.defineProperty(exports, "getTransferListForWriter", { enumerable: true, get: function () { return get_transfer_list_1.getTransferListForWriter; } });
|
|
39
|
-
// LIBRARY UTILS
|
|
40
|
-
var library_utils_1 = require("./lib/library-utils/library-utils");
|
|
41
|
-
Object.defineProperty(exports, "getLibraryUrl", { enumerable: true, get: function () { return library_utils_1.getLibraryUrl; } });
|
|
42
|
-
Object.defineProperty(exports, "loadLibrary", { enumerable: true, get: function () { return library_utils_1.loadLibrary; } });
|
|
43
|
-
// PARSER UTILS
|
|
44
|
-
var async_queue_1 = require("./lib/async-queue/async-queue");
|
|
45
|
-
Object.defineProperty(exports, "AsyncQueue", { enumerable: true, get: function () { return __importDefault(async_queue_1).default; } });
|
|
46
|
-
// PROCESS UTILS
|
|
47
|
-
var child_process_proxy_1 = require("./lib/process-utils/child-process-proxy");
|
|
48
|
-
Object.defineProperty(exports, "ChildProcessProxy", { enumerable: true, get: function () { return __importDefault(child_process_proxy_1).default; } });
|
|
49
|
-
// WORKER OBJECTS
|
|
50
|
-
/** A null worker to test that worker processing is functional */
|
|
51
|
-
exports.NullWorker = {
|
|
52
|
-
id: 'null',
|
|
53
|
-
name: 'null',
|
|
54
|
-
module: 'worker-utils',
|
|
55
|
-
version: version_1.VERSION,
|
|
56
|
-
options: {
|
|
57
|
-
null: {}
|
|
58
|
-
}
|
|
59
|
-
};
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// From https://github.com/rauschma/async-iter-demo/tree/master/src under MIT license
|
|
3
|
-
// http://2ality.com/2016/10/asynchronous-iteration.html
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
/**
|
|
6
|
-
* Async Queue
|
|
7
|
-
* - AsyncIterable: An async iterator can be
|
|
8
|
-
* - Values can be pushed onto the queue
|
|
9
|
-
* @example
|
|
10
|
-
* const asyncQueue = new AsyncQueue();
|
|
11
|
-
* setTimeout(() => asyncQueue.enqueue('tick'), 1000);
|
|
12
|
-
* setTimeout(() => asyncQueue.enqueue(new Error('done')), 10000);
|
|
13
|
-
* for await (const value of asyncQueue) {
|
|
14
|
-
* console.log(value); // tick
|
|
15
|
-
* }
|
|
16
|
-
*/
|
|
17
|
-
class AsyncQueue {
|
|
18
|
-
constructor() {
|
|
19
|
-
this._values = []; // enqueues > dequeues
|
|
20
|
-
this._settlers = []; // dequeues > enqueues
|
|
21
|
-
this._closed = false;
|
|
22
|
-
}
|
|
23
|
-
/** Return an async iterator for this queue */
|
|
24
|
-
[Symbol.asyncIterator]() {
|
|
25
|
-
return this;
|
|
26
|
-
}
|
|
27
|
-
/** Push a new value - the async iterator will yield a promise resolved to this value */
|
|
28
|
-
push(value) {
|
|
29
|
-
return this.enqueue(value);
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Push a new value - the async iterator will yield a promise resolved to this value
|
|
33
|
-
* Add an error - the async iterator will yield a promise rejected with this value
|
|
34
|
-
*/
|
|
35
|
-
enqueue(value) {
|
|
36
|
-
if (this._closed) {
|
|
37
|
-
throw new Error('Closed');
|
|
38
|
-
}
|
|
39
|
-
if (this._settlers.length > 0) {
|
|
40
|
-
if (this._values.length > 0) {
|
|
41
|
-
throw new Error('Illegal internal state');
|
|
42
|
-
}
|
|
43
|
-
const settler = this._settlers.shift();
|
|
44
|
-
if (value instanceof Error) {
|
|
45
|
-
settler.reject(value);
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
settler.resolve({ value });
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
this._values.push(value);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
/** Indicate that we not waiting for more values - The async iterator will be done */
|
|
56
|
-
close() {
|
|
57
|
-
while (this._settlers.length > 0) {
|
|
58
|
-
const settler = this._settlers.shift();
|
|
59
|
-
settler.resolve({ done: true });
|
|
60
|
-
}
|
|
61
|
-
this._closed = true;
|
|
62
|
-
}
|
|
63
|
-
// ITERATOR IMPLEMENTATION
|
|
64
|
-
/** @returns a Promise for an IteratorResult */
|
|
65
|
-
next() {
|
|
66
|
-
// If values in queue, yield the first value
|
|
67
|
-
if (this._values.length > 0) {
|
|
68
|
-
const value = this._values.shift();
|
|
69
|
-
if (value instanceof Error) {
|
|
70
|
-
return Promise.reject(value);
|
|
71
|
-
}
|
|
72
|
-
return Promise.resolve({ done: false, value });
|
|
73
|
-
}
|
|
74
|
-
// If queue is closed, the iterator is done
|
|
75
|
-
if (this._closed) {
|
|
76
|
-
if (this._settlers.length > 0) {
|
|
77
|
-
throw new Error('Illegal internal state');
|
|
78
|
-
}
|
|
79
|
-
return Promise.resolve({ done: true, value: undefined });
|
|
80
|
-
}
|
|
81
|
-
// Yield a promise that waits for new values to be enqueued
|
|
82
|
-
return new Promise((resolve, reject) => {
|
|
83
|
-
this._settlers.push({ resolve, reject });
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
exports.default = AsyncQueue;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Replacement for the external assert method to reduce bundle size
|
|
3
|
-
// Note: We don't use the second "message" argument in calling code,
|
|
4
|
-
// so no need to support it here
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.assert = void 0;
|
|
7
|
-
/** Throws an `Error` with the optional `message` if `condition` is falsy */
|
|
8
|
-
function assert(condition, message) {
|
|
9
|
-
if (!condition) {
|
|
10
|
-
throw new Error(message || 'loaders.gl assertion failed.');
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
exports.assert = assert;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Purpose: include this in your module to avoids adding dependencies on
|
|
3
|
-
// micro modules like 'global' and 'is-browser';
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.nodeVersion = exports.isMobile = exports.isWorker = exports.isBrowser = exports.document = exports.global = exports.window = exports.self = void 0;
|
|
6
|
-
/* eslint-disable no-restricted-globals */
|
|
7
|
-
const globals = {
|
|
8
|
-
self: typeof self !== 'undefined' && self,
|
|
9
|
-
window: typeof window !== 'undefined' && window,
|
|
10
|
-
global: typeof global !== 'undefined' && global,
|
|
11
|
-
document: typeof document !== 'undefined' && document
|
|
12
|
-
};
|
|
13
|
-
const self_ = globals.self || globals.window || globals.global || {};
|
|
14
|
-
exports.self = self_;
|
|
15
|
-
const window_ = globals.window || globals.self || globals.global || {};
|
|
16
|
-
exports.window = window_;
|
|
17
|
-
const global_ = globals.global || globals.self || globals.window || {};
|
|
18
|
-
exports.global = global_;
|
|
19
|
-
const document_ = globals.document || {};
|
|
20
|
-
exports.document = document_;
|
|
21
|
-
/** true if running in the browser, false if running in Node.js */
|
|
22
|
-
exports.isBrowser =
|
|
23
|
-
// @ts-ignore process.browser
|
|
24
|
-
typeof process !== 'object' || String(process) !== '[object process]' || process.browser;
|
|
25
|
-
/** true if running on a worker thread */
|
|
26
|
-
exports.isWorker = typeof importScripts === 'function';
|
|
27
|
-
/** true if running on a mobile device */
|
|
28
|
-
exports.isMobile = typeof window !== 'undefined' && typeof window.orientation !== 'undefined';
|
|
29
|
-
// Extract node major version
|
|
30
|
-
const matches = typeof process !== 'undefined' && process.version && /v([0-9]*)/.exec(process.version);
|
|
31
|
-
/** Version of Node.js if running under Node, otherwise 0 */
|
|
32
|
-
exports.nodeVersion = (matches && parseFloat(matches[1])) || 0;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Version constant cannot be imported, it needs to correspond to the build version of **this** module.
|
|
3
|
-
// __VERSION__ is injected by babel-plugin-version-inline
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.VERSION = void 0;
|
|
6
|
-
// Change to `latest` on production branches
|
|
7
|
-
const DEFAULT_VERSION = 'beta';
|
|
8
|
-
exports.VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : DEFAULT_VERSION;
|
|
9
|
-
if (typeof __VERSION__ === 'undefined') {
|
|
10
|
-
// eslint-disable-next-line
|
|
11
|
-
console.error('loaders.gl: The __VERSION__ variable is not injected using babel plugin. Latest unstable workers would be fetched from the CDN.');
|
|
12
|
-
}
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.getLibraryUrl = exports.loadLibrary = void 0;
|
|
27
|
-
/* global importScripts */
|
|
28
|
-
const globals_1 = require("../env-utils/globals");
|
|
29
|
-
const node = __importStar(require("../node/require-utils.node"));
|
|
30
|
-
const assert_1 = require("../env-utils/assert");
|
|
31
|
-
const version_1 = require("../env-utils/version");
|
|
32
|
-
/**
|
|
33
|
-
* TODO - unpkg.com doesn't seem to have a `latest` specifier for alpha releases...
|
|
34
|
-
* 'beta' on beta branch, 'latest' on prod branch
|
|
35
|
-
*/
|
|
36
|
-
const LATEST = 'beta';
|
|
37
|
-
const VERSION = typeof version_1.VERSION !== 'undefined' ? version_1.VERSION : LATEST;
|
|
38
|
-
const loadLibraryPromises = {}; // promises
|
|
39
|
-
/**
|
|
40
|
-
* Dynamically loads a library ("module")
|
|
41
|
-
*
|
|
42
|
-
* - wasm library: Array buffer is returned
|
|
43
|
-
* - js library: Parse JS is returned
|
|
44
|
-
*
|
|
45
|
-
* Method depends on environment
|
|
46
|
-
* - browser - script element is created and installed on document
|
|
47
|
-
* - worker - eval is called on global context
|
|
48
|
-
* - node - file is required
|
|
49
|
-
*
|
|
50
|
-
* @param libraryUrl
|
|
51
|
-
* @param moduleName
|
|
52
|
-
* @param options
|
|
53
|
-
*/
|
|
54
|
-
async function loadLibrary(libraryUrl, moduleName = null, options = {}, libraryName = null) {
|
|
55
|
-
if (moduleName) {
|
|
56
|
-
libraryUrl = getLibraryUrl(libraryUrl, moduleName, options, libraryName);
|
|
57
|
-
}
|
|
58
|
-
// Ensure libraries are only loaded once
|
|
59
|
-
loadLibraryPromises[libraryUrl] =
|
|
60
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
61
|
-
loadLibraryPromises[libraryUrl] || loadLibraryFromFile(libraryUrl);
|
|
62
|
-
return await loadLibraryPromises[libraryUrl];
|
|
63
|
-
}
|
|
64
|
-
exports.loadLibrary = loadLibrary;
|
|
65
|
-
// TODO - sort out how to resolve paths for main/worker and dev/prod
|
|
66
|
-
function getLibraryUrl(library, moduleName, options = {}, libraryName = null) {
|
|
67
|
-
// Check if already a URL
|
|
68
|
-
if (!options.useLocalLibraries && library.startsWith('http')) {
|
|
69
|
-
return library;
|
|
70
|
-
}
|
|
71
|
-
libraryName = libraryName || library;
|
|
72
|
-
// Allow application to import and supply libraries through `options.modules`
|
|
73
|
-
const modules = options.modules || {};
|
|
74
|
-
if (modules[libraryName]) {
|
|
75
|
-
return modules[libraryName];
|
|
76
|
-
}
|
|
77
|
-
// Load from local files, not from CDN scripts in Node.js
|
|
78
|
-
// TODO - needs to locate the modules directory when installed!
|
|
79
|
-
if (!globals_1.isBrowser) {
|
|
80
|
-
return `modules/${moduleName}/dist/libs/${libraryName}`;
|
|
81
|
-
}
|
|
82
|
-
// In browser, load from external scripts
|
|
83
|
-
if (options.CDN) {
|
|
84
|
-
(0, assert_1.assert)(options.CDN.startsWith('http'));
|
|
85
|
-
return `${options.CDN}/${moduleName}@${VERSION}/dist/libs/${libraryName}`;
|
|
86
|
-
}
|
|
87
|
-
// TODO - loading inside workers requires paths relative to worker script location...
|
|
88
|
-
if (globals_1.isWorker) {
|
|
89
|
-
return `../src/libs/${libraryName}`;
|
|
90
|
-
}
|
|
91
|
-
return `modules/${moduleName}/src/libs/${libraryName}`;
|
|
92
|
-
}
|
|
93
|
-
exports.getLibraryUrl = getLibraryUrl;
|
|
94
|
-
async function loadLibraryFromFile(libraryUrl) {
|
|
95
|
-
if (libraryUrl.endsWith('wasm')) {
|
|
96
|
-
return await loadAsArrayBuffer(libraryUrl);
|
|
97
|
-
}
|
|
98
|
-
if (!globals_1.isBrowser) {
|
|
99
|
-
try {
|
|
100
|
-
return node && node.requireFromFile && (await node.requireFromFile(libraryUrl));
|
|
101
|
-
}
|
|
102
|
-
catch {
|
|
103
|
-
return null;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
if (globals_1.isWorker) {
|
|
107
|
-
return importScripts(libraryUrl);
|
|
108
|
-
}
|
|
109
|
-
// TODO - fix - should be more secure than string parsing since observes CORS
|
|
110
|
-
// if (isBrowser) {
|
|
111
|
-
// return await loadScriptFromFile(libraryUrl);
|
|
112
|
-
// }
|
|
113
|
-
const scriptSource = await loadAsText(libraryUrl);
|
|
114
|
-
return loadLibraryFromString(scriptSource, libraryUrl);
|
|
115
|
-
}
|
|
116
|
-
/*
|
|
117
|
-
async function loadScriptFromFile(libraryUrl) {
|
|
118
|
-
const script = document.createElement('script');
|
|
119
|
-
script.src = libraryUrl;
|
|
120
|
-
return await new Promise((resolve, reject) => {
|
|
121
|
-
script.onload = data => {
|
|
122
|
-
resolve(data);
|
|
123
|
-
};
|
|
124
|
-
script.onerror = reject;
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
*/
|
|
128
|
-
// TODO - Needs security audit...
|
|
129
|
-
// - Raw eval call
|
|
130
|
-
// - Potentially bypasses CORS
|
|
131
|
-
// Upside is that this separates fetching and parsing
|
|
132
|
-
// we could create a`LibraryLoader` or`ModuleLoader`
|
|
133
|
-
function loadLibraryFromString(scriptSource, id) {
|
|
134
|
-
if (!globals_1.isBrowser) {
|
|
135
|
-
return node.requireFromString && node.requireFromString(scriptSource, id);
|
|
136
|
-
}
|
|
137
|
-
if (globals_1.isWorker) {
|
|
138
|
-
// Use lvalue trick to make eval run in global scope
|
|
139
|
-
eval.call(globals_1.global, scriptSource); // eslint-disable-line no-eval
|
|
140
|
-
// https://stackoverflow.com/questions/9107240/1-evalthis-vs-evalthis-in-javascript
|
|
141
|
-
// http://perfectionkills.com/global-eval-what-are-the-options/
|
|
142
|
-
return null;
|
|
143
|
-
}
|
|
144
|
-
const script = document.createElement('script');
|
|
145
|
-
script.id = id;
|
|
146
|
-
// most browsers like a separate text node but some throw an error. The second method covers those.
|
|
147
|
-
try {
|
|
148
|
-
script.appendChild(document.createTextNode(scriptSource));
|
|
149
|
-
}
|
|
150
|
-
catch (e) {
|
|
151
|
-
script.text = scriptSource;
|
|
152
|
-
}
|
|
153
|
-
document.body.appendChild(script);
|
|
154
|
-
return null;
|
|
155
|
-
}
|
|
156
|
-
// TODO - technique for module injection into worker, from THREE.DracoLoader...
|
|
157
|
-
/*
|
|
158
|
-
function combineWorkerWithLibrary(worker, jsContent) {
|
|
159
|
-
var fn = wWorker.toString();
|
|
160
|
-
var body = [
|
|
161
|
-
'// injected',
|
|
162
|
-
jsContent,
|
|
163
|
-
'',
|
|
164
|
-
'// worker',
|
|
165
|
-
fn.substring(fn.indexOf('{') + 1, fn.lastIndexOf('}'))
|
|
166
|
-
].join('\n');
|
|
167
|
-
this.workerSourceURL = URL.createObjectURL(new Blob([body]));
|
|
168
|
-
}
|
|
169
|
-
*/
|
|
170
|
-
async function loadAsArrayBuffer(url) {
|
|
171
|
-
if (!node.readFileAsArrayBuffer || url.startsWith('http')) {
|
|
172
|
-
const response = await fetch(url);
|
|
173
|
-
return await response.arrayBuffer();
|
|
174
|
-
}
|
|
175
|
-
return await node.readFileAsArrayBuffer(url);
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Load a file from local file system
|
|
179
|
-
* @param filename
|
|
180
|
-
* @returns
|
|
181
|
-
*/
|
|
182
|
-
async function loadAsText(url) {
|
|
183
|
-
if (!node.readFileAsText || url.startsWith('http')) {
|
|
184
|
-
const response = await fetch(url);
|
|
185
|
-
return await response.text();
|
|
186
|
-
}
|
|
187
|
-
return await node.readFileAsText(url);
|
|
188
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Fork of https://github.com/floatdrop/require-from-string/blob/master/index.js
|
|
3
|
-
// Copyright (c) Vsevolod Strukchinsky <floatdrop@gmail.com> (github.com/floatdrop)
|
|
4
|
-
// MIT license
|
|
5
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.requireFromString = exports.requireFromFile = exports.readFileAsText = exports.readFileAsArrayBuffer = void 0;
|
|
10
|
-
// this file is not visible to webpack (it is excluded in the package.json "browser" field).
|
|
11
|
-
const module_1 = __importDefault(require("module"));
|
|
12
|
-
const path_1 = __importDefault(require("path"));
|
|
13
|
-
const fs_1 = __importDefault(require("fs"));
|
|
14
|
-
/**
|
|
15
|
-
* Load a file from local file system
|
|
16
|
-
* @param filename
|
|
17
|
-
* @returns
|
|
18
|
-
*/
|
|
19
|
-
async function readFileAsArrayBuffer(filename) {
|
|
20
|
-
if (filename.startsWith('http')) {
|
|
21
|
-
const response = await fetch(filename);
|
|
22
|
-
return await response.arrayBuffer();
|
|
23
|
-
}
|
|
24
|
-
const buffer = fs_1.default.readFileSync(filename);
|
|
25
|
-
return buffer.buffer;
|
|
26
|
-
}
|
|
27
|
-
exports.readFileAsArrayBuffer = readFileAsArrayBuffer;
|
|
28
|
-
/**
|
|
29
|
-
* Load a file from local file system
|
|
30
|
-
* @param filename
|
|
31
|
-
* @returns
|
|
32
|
-
*/
|
|
33
|
-
async function readFileAsText(filename) {
|
|
34
|
-
if (filename.startsWith('http')) {
|
|
35
|
-
const response = await fetch(filename);
|
|
36
|
-
return await response.text();
|
|
37
|
-
}
|
|
38
|
-
const text = fs_1.default.readFileSync(filename, 'utf8');
|
|
39
|
-
return text;
|
|
40
|
-
}
|
|
41
|
-
exports.readFileAsText = readFileAsText;
|
|
42
|
-
// Node.js Dynamically require from file
|
|
43
|
-
// Relative names are resolved relative to cwd
|
|
44
|
-
// This indirect function is provided because webpack will try to bundle `module.require`.
|
|
45
|
-
// this file is not visible to webpack (it is excluded in the package.json "browser" field).
|
|
46
|
-
async function requireFromFile(filename) {
|
|
47
|
-
if (filename.startsWith('http')) {
|
|
48
|
-
const response = await fetch(filename);
|
|
49
|
-
const code = await response.text();
|
|
50
|
-
return requireFromString(code);
|
|
51
|
-
}
|
|
52
|
-
if (!filename.startsWith('/')) {
|
|
53
|
-
filename = `${process.cwd()}/${filename}`;
|
|
54
|
-
}
|
|
55
|
-
return require(filename);
|
|
56
|
-
}
|
|
57
|
-
exports.requireFromFile = requireFromFile;
|
|
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
|
-
function requireFromString(code, filename = '', options) {
|
|
65
|
-
if (typeof filename === 'object') {
|
|
66
|
-
options = filename;
|
|
67
|
-
filename = '';
|
|
68
|
-
}
|
|
69
|
-
if (typeof code !== 'string') {
|
|
70
|
-
throw new Error(`code must be a string, not ${typeof code}`);
|
|
71
|
-
}
|
|
72
|
-
// @ts-ignore
|
|
73
|
-
const paths = module_1.default._nodeModulePaths(path_1.default.dirname(filename));
|
|
74
|
-
const parent = module.parent;
|
|
75
|
-
// @ts-ignore
|
|
76
|
-
const newModule = new module_1.default(filename, parent);
|
|
77
|
-
newModule.filename = filename;
|
|
78
|
-
newModule.paths = []
|
|
79
|
-
.concat(options?.prependPaths || [])
|
|
80
|
-
.concat(paths)
|
|
81
|
-
.concat(options?.appendPaths || []);
|
|
82
|
-
// @ts-ignore
|
|
83
|
-
newModule._compile(code, filename);
|
|
84
|
-
if (parent && parent.children) {
|
|
85
|
-
parent.children.splice(parent.children.indexOf(newModule), 1);
|
|
86
|
-
}
|
|
87
|
-
return newModule.exports;
|
|
88
|
-
}
|
|
89
|
-
exports.requireFromString = requireFromString;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parentPort = exports.NodeWorkerType = exports.NodeWorker = exports.Worker = void 0;
|
|
4
|
-
// Browser fills for Node.js built-in `worker_threads` module.
|
|
5
|
-
// These fills are non-functional, and just intended to ensure that
|
|
6
|
-
// `import 'worker_threads` doesn't break browser builds.
|
|
7
|
-
// The replacement is done in package.json browser field
|
|
8
|
-
class Worker {
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
10
|
-
terminate() { }
|
|
11
|
-
}
|
|
12
|
-
exports.Worker = Worker;
|
|
13
|
-
exports.NodeWorker = Worker;
|
|
14
|
-
exports.NodeWorkerType = Worker;
|
|
15
|
-
exports.parentPort = null;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// loaders.gl, MIT license
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
-
}) : function(o, v) {
|
|
17
|
-
o["default"] = v;
|
|
18
|
-
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
-
if (mod && mod.__esModule) return mod;
|
|
21
|
-
var result = {};
|
|
22
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
-
__setModuleDefault(result, mod);
|
|
24
|
-
return result;
|
|
25
|
-
};
|
|
26
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
27
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
28
|
-
};
|
|
29
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.NodeWorker = void 0;
|
|
31
|
-
const WorkerThreads = __importStar(require("worker_threads"));
|
|
32
|
-
__exportStar(require("worker_threads"), exports);
|
|
33
|
-
exports.NodeWorker = WorkerThreads.Worker;
|