Socket
Socket
Sign inDemoInstall

@loaders.gl/worker-utils

Package Overview
Dependencies
Maintainers
9
Versions
198
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@loaders.gl/worker-utils - npm Package Compare versions

Comparing version 4.0.0-alpha.17 to 4.0.0-alpha.18

4

dist/es5/lib/env-utils/version.js

@@ -8,7 +8,7 @@ "use strict";

var DEFAULT_VERSION = 'beta';
var VERSION = typeof "4.0.0-alpha.17" !== 'undefined' ? "4.0.0-alpha.17" : DEFAULT_VERSION;
var VERSION = typeof "4.0.0-alpha.18" !== 'undefined' ? "4.0.0-alpha.18" : DEFAULT_VERSION;
exports.VERSION = VERSION;
if (typeof "4.0.0-alpha.17" === 'undefined') {
if (typeof "4.0.0-alpha.18" === 'undefined') {
console.error('loaders.gl: The __VERSION__ variable is not injected using babel plugin. Latest unstable workers would be fetched from the CDN.');
}
//# sourceMappingURL=version.js.map

@@ -19,3 +19,3 @@ "use strict";

var LATEST = 'beta';
var VERSION = typeof "4.0.0-alpha.17" !== 'undefined' ? "4.0.0-alpha.17" : LATEST;
var VERSION = typeof "4.0.0-alpha.18" !== 'undefined' ? "4.0.0-alpha.18" : LATEST;
var loadLibraryPromises = {};

@@ -76,3 +76,3 @@ function loadLibrary(_x) {

_loadLibraryFromFile = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2(libraryUrl) {
var _response, response, scriptSource;
var scriptSource;
return _regenerator.default.wrap(function _callee2$(_context2) {

@@ -82,55 +82,47 @@ while (1) switch (_context2.prev = _context2.next) {

if (!libraryUrl.endsWith('wasm')) {
_context2.next = 7;
_context2.next = 4;
break;
}
_context2.next = 3;
return fetch(libraryUrl);
return loadAsArrayBuffer(libraryUrl);
case 3:
_response = _context2.sent;
_context2.next = 6;
return _response.arrayBuffer();
case 6:
return _context2.abrupt("return", _context2.sent);
case 7:
case 4:
if (_globals.isBrowser) {
_context2.next = 20;
_context2.next = 17;
break;
}
_context2.prev = 8;
_context2.prev = 5;
_context2.t0 = node && node.requireFromFile;
if (!_context2.t0) {
_context2.next = 14;
_context2.next = 11;
break;
}
_context2.next = 13;
_context2.next = 10;
return node.requireFromFile(libraryUrl);
case 13:
case 10:
_context2.t0 = _context2.sent;
case 11:
return _context2.abrupt("return", _context2.t0);
case 14:
return _context2.abrupt("return", _context2.t0);
_context2.prev = 14;
_context2.t1 = _context2["catch"](5);
return _context2.abrupt("return", null);
case 17:
_context2.prev = 17;
_context2.t1 = _context2["catch"](8);
return _context2.abrupt("return", null);
case 20:
if (!_globals.isWorker) {
_context2.next = 22;
_context2.next = 19;
break;
}
return _context2.abrupt("return", importScripts(libraryUrl));
case 22:
_context2.next = 24;
return fetch(libraryUrl);
case 24:
response = _context2.sent;
_context2.next = 27;
return response.text();
case 27:
case 19:
_context2.next = 21;
return loadAsText(libraryUrl);
case 21:
scriptSource = _context2.sent;
return _context2.abrupt("return", loadLibraryFromString(scriptSource, libraryUrl));
case 29:
case 23:
case "end":
return _context2.stop();
}
}, _callee2, null, [[8, 17]]);
}, _callee2, null, [[5, 14]]);
}));

@@ -157,2 +149,70 @@ return _loadLibraryFromFile.apply(this, arguments);

}
function loadAsArrayBuffer(_x3) {
return _loadAsArrayBuffer.apply(this, arguments);
}
function _loadAsArrayBuffer() {
_loadAsArrayBuffer = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee3(url) {
var response;
return _regenerator.default.wrap(function _callee3$(_context3) {
while (1) switch (_context3.prev = _context3.next) {
case 0:
if (!(!node.readFileAsArrayBuffer || url.startsWith('http'))) {
_context3.next = 7;
break;
}
_context3.next = 3;
return fetch(url);
case 3:
response = _context3.sent;
_context3.next = 6;
return response.arrayBuffer();
case 6:
return _context3.abrupt("return", _context3.sent);
case 7:
_context3.next = 9;
return node.readFileAsArrayBuffer(url);
case 9:
return _context3.abrupt("return", _context3.sent);
case 10:
case "end":
return _context3.stop();
}
}, _callee3);
}));
return _loadAsArrayBuffer.apply(this, arguments);
}
function loadAsText(_x4) {
return _loadAsText.apply(this, arguments);
}
function _loadAsText() {
_loadAsText = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee4(url) {
var response;
return _regenerator.default.wrap(function _callee4$(_context4) {
while (1) switch (_context4.prev = _context4.next) {
case 0:
if (!(!node.readFileAsText || url.startsWith('http'))) {
_context4.next = 7;
break;
}
_context4.next = 3;
return fetch(url);
case 3:
response = _context4.sent;
_context4.next = 6;
return response.text();
case 6:
return _context4.abrupt("return", _context4.sent);
case 7:
_context4.next = 9;
return node.readFileAsText(url);
case 9:
return _context4.abrupt("return", _context4.sent);
case 10:
case "end":
return _context4.stop();
}
}, _callee4);
}));
return _loadAsText.apply(this, arguments);
}
//# sourceMappingURL=library-utils.js.map

@@ -7,2 +7,4 @@ "use strict";

});
exports.readFileAsArrayBuffer = readFileAsArrayBuffer;
exports.readFileAsText = readFileAsText;
exports.requireFromFile = requireFromFile;

@@ -15,8 +17,9 @@ exports.requireFromString = requireFromString;

var _path = _interopRequireDefault(require("path"));
function requireFromFile(_x) {
return _requireFromFile.apply(this, arguments);
var _fs = _interopRequireDefault(require("fs"));
function readFileAsArrayBuffer(_x) {
return _readFileAsArrayBuffer.apply(this, arguments);
}
function _requireFromFile() {
_requireFromFile = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(filename) {
var response, code;
function _readFileAsArrayBuffer() {
_readFileAsArrayBuffer = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(filename) {
var response, buffer;
return _regenerator.default.wrap(function _callee$(_context) {

@@ -26,3 +29,3 @@ while (1) switch (_context.prev = _context.next) {

if (!filename.startsWith('http')) {
_context.next = 8;
_context.next = 7;
break;

@@ -35,6 +38,70 @@ }

_context.next = 6;
return response.arrayBuffer();
case 6:
return _context.abrupt("return", _context.sent);
case 7:
buffer = _fs.default.readFileSync(filename);
return _context.abrupt("return", buffer.buffer);
case 9:
case "end":
return _context.stop();
}
}, _callee);
}));
return _readFileAsArrayBuffer.apply(this, arguments);
}
function readFileAsText(_x2) {
return _readFileAsText.apply(this, arguments);
}
function _readFileAsText() {
_readFileAsText = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2(filename) {
var response, text;
return _regenerator.default.wrap(function _callee2$(_context2) {
while (1) switch (_context2.prev = _context2.next) {
case 0:
if (!filename.startsWith('http')) {
_context2.next = 7;
break;
}
_context2.next = 3;
return fetch(filename);
case 3:
response = _context2.sent;
_context2.next = 6;
return response.text();
case 6:
code = _context.sent;
return _context.abrupt("return", requireFromString(code));
return _context2.abrupt("return", _context2.sent);
case 7:
text = _fs.default.readFileSync(filename, 'utf8');
return _context2.abrupt("return", text);
case 9:
case "end":
return _context2.stop();
}
}, _callee2);
}));
return _readFileAsText.apply(this, arguments);
}
function requireFromFile(_x3) {
return _requireFromFile.apply(this, arguments);
}
function _requireFromFile() {
_requireFromFile = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee3(filename) {
var response, code;
return _regenerator.default.wrap(function _callee3$(_context3) {
while (1) switch (_context3.prev = _context3.next) {
case 0:
if (!filename.startsWith('http')) {
_context3.next = 8;
break;
}
_context3.next = 3;
return fetch(filename);
case 3:
response = _context3.sent;
_context3.next = 6;
return response.text();
case 6:
code = _context3.sent;
return _context3.abrupt("return", requireFromString(code));
case 8:

@@ -44,8 +111,8 @@ if (!filename.startsWith('/')) {

}
return _context.abrupt("return", require(filename));
return _context3.abrupt("return", require(filename));
case 10:
case "end":
return _context.stop();
return _context3.stop();
}
}, _callee);
}, _callee3);
}));

@@ -52,0 +119,0 @@ return _requireFromFile.apply(this, arguments);

@@ -12,3 +12,3 @@ "use strict";

var NPM_TAG = 'beta';
var VERSION = typeof "4.0.0-alpha.17" !== 'undefined' ? "4.0.0-alpha.17" : NPM_TAG;
var VERSION = typeof "4.0.0-alpha.18" !== 'undefined' ? "4.0.0-alpha.18" : NPM_TAG;
function getWorkerName(worker) {

@@ -15,0 +15,0 @@ var warning = worker.version !== VERSION ? " (worker-utils@".concat(VERSION, ")") : '';

const DEFAULT_VERSION = 'beta';
export const VERSION = typeof "4.0.0-alpha.17" !== 'undefined' ? "4.0.0-alpha.17" : DEFAULT_VERSION;
if (typeof "4.0.0-alpha.17" === 'undefined') {
export const VERSION = typeof "4.0.0-alpha.18" !== 'undefined' ? "4.0.0-alpha.18" : DEFAULT_VERSION;
if (typeof "4.0.0-alpha.18" === 'undefined') {
console.error('loaders.gl: The __VERSION__ variable is not injected using babel plugin. Latest unstable workers would be fetched from the CDN.');
}
//# sourceMappingURL=version.js.map

@@ -6,3 +6,3 @@ import { global, isBrowser, isWorker } from '../env-utils/globals';

const LATEST = 'beta';
const VERSION = typeof "4.0.0-alpha.17" !== 'undefined' ? "4.0.0-alpha.17" : LATEST;
const VERSION = typeof "4.0.0-alpha.18" !== 'undefined' ? "4.0.0-alpha.18" : LATEST;
const loadLibraryPromises = {};

@@ -40,4 +40,3 @@ export async function loadLibrary(libraryUrl) {

if (libraryUrl.endsWith('wasm')) {
const response = await fetch(libraryUrl);
return await response.arrayBuffer();
return await loadAsArrayBuffer(libraryUrl);
}

@@ -54,4 +53,3 @@ if (!isBrowser) {

}
const response = await fetch(libraryUrl);
const scriptSource = await response.text();
const scriptSource = await loadAsText(libraryUrl);
return loadLibraryFromString(scriptSource, libraryUrl);

@@ -77,2 +75,16 @@ }

}
async function loadAsArrayBuffer(url) {
if (!node.readFileAsArrayBuffer || url.startsWith('http')) {
const response = await fetch(url);
return await response.arrayBuffer();
}
return await node.readFileAsArrayBuffer(url);
}
async function loadAsText(url) {
if (!node.readFileAsText || url.startsWith('http')) {
const response = await fetch(url);
return await response.text();
}
return await node.readFileAsText(url);
}
//# sourceMappingURL=library-utils.js.map
import Module from 'module';
import path from 'path';
import fs from 'fs';
export async function readFileAsArrayBuffer(filename) {
if (filename.startsWith('http')) {
const response = await fetch(filename);
return await response.arrayBuffer();
}
const buffer = fs.readFileSync(filename);
return buffer.buffer;
}
export async function readFileAsText(filename) {
if (filename.startsWith('http')) {
const response = await fetch(filename);
return await response.text();
}
const text = fs.readFileSync(filename, 'utf8');
return text;
}
export async function requireFromFile(filename) {

@@ -4,0 +21,0 @@ if (filename.startsWith('http')) {

@@ -5,3 +5,3 @@ import { assert } from '../env-utils/assert';

const NPM_TAG = 'beta';
const VERSION = typeof "4.0.0-alpha.17" !== 'undefined' ? "4.0.0-alpha.17" : NPM_TAG;
const VERSION = typeof "4.0.0-alpha.18" !== 'undefined' ? "4.0.0-alpha.18" : NPM_TAG;
export function getWorkerName(worker) {

@@ -8,0 +8,0 @@ const warning = worker.version !== VERSION ? " (worker-utils@".concat(VERSION, ")") : '';

@@ -95,4 +95,3 @@ "use strict";

if (libraryUrl.endsWith('wasm')) {
const response = await fetch(libraryUrl);
return await response.arrayBuffer();
return await loadAsArrayBuffer(libraryUrl);
}

@@ -114,4 +113,3 @@ if (!globals_1.isBrowser) {

// }
const response = await fetch(libraryUrl);
const scriptSource = await response.text();
const scriptSource = await loadAsText(libraryUrl);
return loadLibraryFromString(scriptSource, libraryUrl);

@@ -173,1 +171,20 @@ }

*/
async function loadAsArrayBuffer(url) {
if (!node.readFileAsArrayBuffer || url.startsWith('http')) {
const response = await fetch(url);
return await response.arrayBuffer();
}
return await node.readFileAsArrayBuffer(url);
}
/**
* Load a file from local file system
* @param filename
* @returns
*/
async function loadAsText(url) {
if (!node.readFileAsText || url.startsWith('http')) {
const response = await fetch(url);
return await response.text();
}
return await node.readFileAsText(url);
}

@@ -0,1 +1,13 @@

/**
* Load a file from local file system
* @param filename
* @returns
*/
export declare function readFileAsArrayBuffer(filename: string): Promise<ArrayBuffer>;
/**
* Load a file from local file system
* @param filename
* @returns
*/
export declare function readFileAsText(filename: string): Promise<string>;
export declare function requireFromFile(filename: string): Promise<any>;

@@ -2,0 +14,0 @@ export declare function requireFromString(code: string, filename?: string, options?: {

@@ -9,6 +9,35 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.requireFromString = exports.requireFromFile = void 0;
exports.requireFromString = exports.requireFromFile = exports.readFileAsText = exports.readFileAsArrayBuffer = void 0;
// this file is not visible to webpack (it is excluded in the package.json "browser" field).
const module_1 = __importDefault(require("module"));
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
/**
* Load a file from local file system
* @param filename
* @returns
*/
async function readFileAsArrayBuffer(filename) {
if (filename.startsWith('http')) {
const response = await fetch(filename);
return await response.arrayBuffer();
}
const buffer = fs_1.default.readFileSync(filename);
return buffer.buffer;
}
exports.readFileAsArrayBuffer = readFileAsArrayBuffer;
/**
* Load a file from local file system
* @param filename
* @returns
*/
async function readFileAsText(filename) {
if (filename.startsWith('http')) {
const response = await fetch(filename);
return await response.text();
}
const text = fs_1.default.readFileSync(filename, 'utf8');
return text;
}
exports.readFileAsText = readFileAsText;
// Node.js Dynamically require from file

@@ -15,0 +44,0 @@ // Relative names are resolved relative to cwd

{
"name": "@loaders.gl/worker-utils",
"version": "4.0.0-alpha.17",
"version": "4.0.0-alpha.18",
"description": "Utilities for running tasks on worker threads",

@@ -53,3 +53,3 @@ "license": "MIT",

},
"gitHead": "68a743e2460cc89bf89edabfd08b395380d7d10c"
"gitHead": "7bc633f46560f661bdd46cf1015ea27b3694ebce"
}

@@ -39,3 +39,2 @@ /* global importScripts */

}
// Ensure libraries are only loaded once

@@ -84,4 +83,3 @@

if (libraryUrl.endsWith('wasm')) {
const response = await fetch(libraryUrl);
return await response.arrayBuffer();
return await loadAsArrayBuffer(libraryUrl);
}

@@ -104,4 +102,3 @@

const response = await fetch(libraryUrl);
const scriptSource = await response.text();
const scriptSource = await loadAsText(libraryUrl);
return loadLibraryFromString(scriptSource, libraryUrl);

@@ -167,1 +164,22 @@ }

*/
async function loadAsArrayBuffer(url: string): Promise<ArrayBuffer> {
if (!node.readFileAsArrayBuffer || url.startsWith('http')) {
const response = await fetch(url);
return await response.arrayBuffer();
}
return await node.readFileAsArrayBuffer(url);
}
/**
* Load a file from local file system
* @param filename
* @returns
*/
async function loadAsText(url: string): Promise<string> {
if (!node.readFileAsText || url.startsWith('http')) {
const response = await fetch(url);
return await response.text();
}
return await node.readFileAsText(url);
}

@@ -9,3 +9,32 @@ // Fork of https://github.com/floatdrop/require-from-string/blob/master/index.js

import path from 'path';
import fs from 'fs';
/**
* Load a file from local file system
* @param filename
* @returns
*/
export async function readFileAsArrayBuffer(filename: string): Promise<ArrayBuffer> {
if (filename.startsWith('http')) {
const response = await fetch(filename);
return await response.arrayBuffer();
}
const buffer = fs.readFileSync(filename);
return buffer.buffer;
}
/**
* Load a file from local file system
* @param filename
* @returns
*/
export async function readFileAsText(filename: string): Promise<string> {
if (filename.startsWith('http')) {
const response = await fetch(filename);
return await response.text();
}
const text = fs.readFileSync(filename, 'utf8');
return text;
}
// Node.js Dynamically require from file

@@ -12,0 +41,0 @@ // Relative names are resolved relative to cwd

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc