@loaders.gl/worker-utils
Advanced tools
Comparing version 4.0.0-beta.2 to 4.0.0-beta.3
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
// src/lib/async-queue/async-queue.ts | ||
@@ -8,8 +10,14 @@ var AsyncQueue = class { | ||
} | ||
/** Return an async iterator for this queue */ | ||
[Symbol.asyncIterator]() { | ||
return this; | ||
} | ||
/** Push a new value - the async iterator will yield a promise resolved to this value */ | ||
push(value) { | ||
return this.enqueue(value); | ||
} | ||
/** | ||
* Push a new value - the async iterator will yield a promise resolved to this value | ||
* Add an error - the async iterator will yield a promise rejected with this value | ||
*/ | ||
enqueue(value) { | ||
@@ -33,2 +41,3 @@ if (this._closed) { | ||
} | ||
/** Indicate that we not waiting for more values - The async iterator will be done */ | ||
close() { | ||
@@ -41,2 +50,4 @@ while (this._settlers.length > 0) { | ||
} | ||
// ITERATOR IMPLEMENTATION | ||
/** @returns a Promise for an IteratorResult */ | ||
next() { | ||
@@ -64,3 +75,3 @@ if (this._values.length > 0) { | ||
function getTransferList(object, recursive = true, transfers) { | ||
const transfersSet = transfers || new Set(); | ||
const transfersSet = transfers || /* @__PURE__ */ new Set(); | ||
if (!object) { | ||
@@ -108,7 +119,11 @@ } else if (isTransferable(object)) { | ||
} | ||
var onMessageWrapperMap = new Map(); | ||
var onMessageWrapperMap = /* @__PURE__ */ new Map(); | ||
var WorkerBody = class { | ||
/** Check that we are actually in a worker thread */ | ||
static inWorkerThread() { | ||
return typeof self !== "undefined" || Boolean(getParentPort()); | ||
} | ||
/* | ||
* (type: WorkerMessageType, payload: WorkerMessagePayload) => any | ||
*/ | ||
static set onmessage(onMessage) { | ||
@@ -157,2 +172,7 @@ function handleMessage(message) { | ||
} | ||
/** | ||
* Send a message from a worker to creating thread (main thread) | ||
* @param type | ||
* @param payload | ||
*/ | ||
static postMessage(type, payload) { | ||
@@ -159,0 +179,0 @@ const data = { source: "loaders.gl", type, payload }; |
@@ -0,4 +1,8 @@ | ||
"use strict"; | ||
(() => { | ||
// src/lib/async-queue/async-queue.ts | ||
var AsyncQueue = class { | ||
_values; | ||
_settlers; | ||
_closed; | ||
constructor() { | ||
@@ -9,8 +13,14 @@ this._values = []; | ||
} | ||
/** Return an async iterator for this queue */ | ||
[Symbol.asyncIterator]() { | ||
return this; | ||
} | ||
/** Push a new value - the async iterator will yield a promise resolved to this value */ | ||
push(value) { | ||
return this.enqueue(value); | ||
} | ||
/** | ||
* Push a new value - the async iterator will yield a promise resolved to this value | ||
* Add an error - the async iterator will yield a promise rejected with this value | ||
*/ | ||
enqueue(value) { | ||
@@ -34,2 +44,3 @@ if (this._closed) { | ||
} | ||
/** Indicate that we not waiting for more values - The async iterator will be done */ | ||
close() { | ||
@@ -42,2 +53,4 @@ while (this._settlers.length > 0) { | ||
} | ||
// ITERATOR IMPLEMENTATION | ||
/** @returns a Promise for an IteratorResult */ | ||
next() { | ||
@@ -65,3 +78,3 @@ if (this._values.length > 0) { | ||
function getTransferList(object, recursive = true, transfers) { | ||
const transfersSet = transfers || new Set(); | ||
const transfersSet = transfers || /* @__PURE__ */ new Set(); | ||
if (!object) { | ||
@@ -109,7 +122,11 @@ } else if (isTransferable(object)) { | ||
} | ||
var onMessageWrapperMap = new Map(); | ||
var onMessageWrapperMap = /* @__PURE__ */ new Map(); | ||
var WorkerBody = class { | ||
/** Check that we are actually in a worker thread */ | ||
static inWorkerThread() { | ||
return typeof self !== "undefined" || Boolean(getParentPort()); | ||
} | ||
/* | ||
* (type: WorkerMessageType, payload: WorkerMessagePayload) => any | ||
*/ | ||
static set onmessage(onMessage) { | ||
@@ -158,2 +175,7 @@ function handleMessage(message) { | ||
} | ||
/** | ||
* Send a message from a worker to creating thread (main thread) | ||
* @param type | ||
* @param payload | ||
*/ | ||
static postMessage(type, payload) { | ||
@@ -160,0 +182,0 @@ const data = { source: "loaders.gl", type, payload }; |
{ | ||
"name": "@loaders.gl/worker-utils", | ||
"version": "4.0.0-beta.2", | ||
"version": "4.0.0-beta.3", | ||
"description": "Utilities for running tasks on worker threads", | ||
"license": "MIT", | ||
"type": "module", | ||
"publishConfig": { | ||
@@ -19,4 +20,11 @@ "access": "public" | ||
"types": "dist/index.d.ts", | ||
"main": "dist/es5/index.js", | ||
"module": "dist/esm/index.js", | ||
"main": "dist/index.cjs", | ||
"module": "dist/index.js", | ||
"exports": { | ||
".": { | ||
"import": "./dist/index.js", | ||
"require": "./dist/index.cjs", | ||
"types": "./dist/index.d.ts" | ||
} | ||
}, | ||
"sideEffects": false, | ||
@@ -45,4 +53,2 @@ "files": [ | ||
"pre-build": "npm run build-worker && npm run build-worker-node", | ||
"pre-build-disabled": "npm run build-bundle && npm run build-workers", | ||
"build-bundle": "esbuild src/bundle.ts --outfile=dist/dist.min.js", | ||
"build-worker": "esbuild src/workers/null-worker.ts --outfile=dist/null-worker.js --target=esnext --bundle --sourcemap --define:__VERSION__=\\\"$npm_package_version\\\"", | ||
@@ -54,3 +60,3 @@ "build-worker-node": "esbuild src/workers/null-worker.ts --outfile=dist/null-worker-node.js --platform=node --target=node16 --bundle --sourcemap --define:__VERSION__=\\\"$npm_package_version\\\"" | ||
}, | ||
"gitHead": "79c2033f755e88e11bc30a04428e3666b177b8fc" | ||
"gitHead": "7ba9621cc51c7a26c407086ac86171f35b8712af" | ||
} |
@@ -87,5 +87,12 @@ /* global importScripts */ | ||
if (!isBrowser) { | ||
// TODO - Node doesn't yet support dynamic import from https URLs | ||
// try { | ||
// return await import(libraryUrl); | ||
// } catch (error) { | ||
// console.error(error); | ||
// } | ||
try { | ||
return node && node.requireFromFile && (await node.requireFromFile(libraryUrl)); | ||
} catch { | ||
} catch (error) { | ||
console.error(error); // eslint-disable-line no-console | ||
return null; | ||
@@ -92,0 +99,0 @@ } |
@@ -53,3 +53,4 @@ // Fork of https://github.com/floatdrop/require-from-string/blob/master/index.js | ||
} | ||
return require(filename); | ||
const code = await fs.readFileSync(filename, 'utf8'); | ||
return requireFromString(code); | ||
} | ||
@@ -83,3 +84,4 @@ | ||
const parent = module.parent; | ||
const parent = typeof module !== 'undefined' && module?.parent; | ||
// @ts-ignore | ||
@@ -86,0 +88,0 @@ const newModule = new Module(filename, parent); |
@@ -6,3 +6,2 @@ // Browser fills for Node.js built-in `worker_threads` module. | ||
export class Worker { | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
terminate() {} | ||
@@ -9,0 +8,0 @@ } |
@@ -157,2 +157,5 @@ import type {WorkerMessageType, WorkerMessagePayload} from '../../types'; | ||
await job.result; | ||
} catch (error) { | ||
// eslint-disable-next-line no-console | ||
console.error(`Worker exception: ${error}`); | ||
} finally { | ||
@@ -159,0 +162,0 @@ this.returnWorkerToQueue(workerThread); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
2
11
Yes
206
6
10
1
49
327015
231313
133
4916