From e2743099a1c01142ce104c8ca1e70ce3b4c30fa4 Mon Sep 17 00:00:00 2001 From: Ib Green Date: Fri, 19 May 2023 16:36:01 -0400 Subject: [PATCH] wip --- modules/compression/package.json | 5 +++-- modules/compression/src/workers/worker.ts | 3 +++ modules/compression/test/compression.spec.js | 12 ++++++++++++ modules/crypto/package.json | 5 +++-- .../test/lib/iterators/make-iterator.spec.ts | 2 +- 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/modules/compression/package.json b/modules/compression/package.json index 4b4e16f4cb..548fbad948 100644 --- a/modules/compression/package.json +++ b/modules/compression/package.json @@ -32,9 +32,10 @@ "util": false }, "scripts": { - "pre-build": "npm run build-bundle && npm run build-worker", + "pre-build": "npm run build-bundle && npm run build-bundle && npm run build-worker", "build-bundle": "esbuild src/bundle.ts --outfile=dist/dist.min.js --bundle --minify --sourcemap --external:{fs,path,crypto}", - "build-worker": "esbuild src/workers/worker.ts --outfile=dist/compression-worker.js --target=esnext,node12 --bundle --minify --sourcemap --external:{fs,path,crypto} --define:__VERSION__=\\\"$npm_package_version\\\"" + "build-worker": "esbuild src/workers/worker.ts --outfile=dist/compression-worker.js --target=esnext,node12 --bundle --minify --sourcemap --external:{fs,path,crypto} --define:__VERSION__=\\\"$npm_package_version\\\"", + "build-worker-node": "esbuild src/workers/worker.ts --outfile=dist/compression-worker-node.js --platform=node --target=esnext,node12 --bundle --minify --sourcemap --external:{fs,path,crypto} --define:__VERSION__=\\\"$npm_package_version\\\"" }, "dependencies": { "@babel/runtime": "^7.3.1", diff --git a/modules/compression/src/workers/worker.ts b/modules/compression/src/workers/worker.ts index ce52494f0a..b827cbe6a7 100644 --- a/modules/compression/src/workers/worker.ts +++ b/modules/compression/src/workers/worker.ts @@ -18,6 +18,9 @@ import lz4js from 'lz4js'; // import lzo from 'lzo'; // import {ZstdCodec} from 'zstd-codec'; +// globalThis.Worker = globalThis.Worker || {}; +// globalThis.Blob = globalThis.Blob || {}; + // Inject large dependencies through Compression constructor options const modules = { // brotli has problems with decompress in browsers diff --git a/modules/compression/test/compression.spec.js b/modules/compression/test/compression.spec.js index fc96b1b206..3a50f83bc8 100644 --- a/modules/compression/test/compression.spec.js +++ b/modules/compression/test/compression.spec.js @@ -164,6 +164,12 @@ test('compression#batched', async (t) => { // WORKER TESTS test('gzip#worker', async (t) => { + if (!isBrowser) { + t.comment('not testing worker under Node.js'); + t.end(); + return; + } + const COMPRESSED_LENGTH_EXPECTED = 12824; // fflate // const COMPRESSED_LENGTH_EXPECTED = 12825; // pako @@ -204,6 +210,12 @@ test('gzip#worker', async (t) => { }); test('lz4#worker', async (t) => { + if (!isBrowser) { + t.comment('not testing worker under Node.js'); + t.end(); + return; + } + const {binaryData} = getData(); t.equal(binaryData.byteLength, 100000, 'Length correct'); diff --git a/modules/crypto/package.json b/modules/crypto/package.json index dbc62ad061..9a133b499a 100644 --- a/modules/crypto/package.json +++ b/modules/crypto/package.json @@ -27,9 +27,10 @@ "README.md" ], "scripts": { - "pre-build": "npm run build-worker && npm run build-bundle", + "pre-build": "npm run build-worker && npm run build-worker-node && npm run build-bundle", "build-bundle": "esbuild src/bundle.ts --outfile=dist/dist.min.js --bundle --minify --sourcemap", - "build-worker": "esbuild src/workers/worker.ts --outfile=dist/crypto-worker.js --target=esnext,node12 --bundle --minify --sourcemap --define:__VERSION__=\\\"$npm_package_version\\\"" + "build-worker": "esbuild src/workers/worker.ts --outfile=dist/crypto-worker.js --target=esnext,node12 --bundle --minify --sourcemap --define:__VERSION__=\\\"$npm_package_version\\\"", + "build-worker-node": "esbuild src/workers/worker.ts --outfile=dist/crypto-worker-node.js --platform=node --target=esnext,node12 --bundle --minify --sourcemap --define:__VERSION__=\\\"$npm_package_version\\\"" }, "dependencies": { "@babel/runtime": "^7.3.1", diff --git a/modules/loader-utils/test/lib/iterators/make-iterator.spec.ts b/modules/loader-utils/test/lib/iterators/make-iterator.spec.ts index 968ba3e9db..3cb105d38c 100644 --- a/modules/loader-utils/test/lib/iterators/make-iterator.spec.ts +++ b/modules/loader-utils/test/lib/iterators/make-iterator.spec.ts @@ -64,7 +64,7 @@ const DATA_URL = '@loaders.gl/draco/test/data/raw-attribute-buffers/lidar-positi test('makeIterator(fetch)#async iterate', async (t) => { const response = await fetchFile(DATA_URL); - const stream = response.body; + const stream = await response.body; t.ok(stream); if (stream) {