From 4e2896dba6e93efb16fbfe5629629bc113c32976 Mon Sep 17 00:00:00 2001 From: Viktor Belomestnov Date: Fri, 17 Nov 2023 15:18:24 +0100 Subject: [PATCH 1/2] fix: make node workers cjs --- modules/draco/package.json | 4 ++-- modules/i3s/package.json | 2 +- modules/textures/package.json | 4 ++-- .../src/3d-tiles-converter/3d-tiles-converter.ts | 2 +- .../src/deps-installer/deps-installer.ts | 10 +++++----- .../src/i3s-converter/helpers/geometry-converter.ts | 2 +- .../tile-converter/src/i3s-converter/i3s-converter.ts | 6 +++--- .../worker-utils/src/lib/worker-api/get-worker-url.ts | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/modules/draco/package.json b/modules/draco/package.json index c88e7971b3..a3a4b43afe 100644 --- a/modules/draco/package.json +++ b/modules/draco/package.json @@ -45,9 +45,9 @@ "build-bundle": "ocular-bundle ./src/index.ts", "build-workers": "yarn build-loader-worker && yarn build-loader-worker-node && yarn build-writer-worker && yarn build-writer-worker-node", "build-loader-worker": "esbuild src/workers/draco-worker.ts --outfile=dist/draco-worker.js --target=esnext --bundle --sourcemap --define:__VERSION__=\\\"$npm_package_version\\\"", - "build-loader-worker-node": "esbuild src/workers/draco-worker-node.ts --outfile=dist/draco-worker-node.js --target=node16 --format=esm --platform=node --bundle --sourcemap --define:__VERSION__=\\\"$npm_package_version\\\"", + "build-loader-worker-node": "esbuild src/workers/draco-worker-node.ts --outfile=dist/draco-worker-node.cjs --target=node16 --platform=node --bundle --sourcemap --define:__VERSION__=\\\"$npm_package_version\\\"", "build-writer-worker": "esbuild src/workers/draco-writer-worker.ts --outfile=dist/draco-writer-worker.js --target=esnext --bundle --sourcemap --define:__VERSION__=\\\"$npm_package_version\\\"", - "build-writer-worker-node": "esbuild src/workers/draco-writer-worker-node.ts --outfile=dist/draco-writer-worker-node.js --target=node16 --platform=node --bundle --sourcemap --define:__VERSION__=\\\"$npm_package_version\\\"" + "build-writer-worker-node": "esbuild src/workers/draco-writer-worker-node.ts --outfile=dist/draco-writer-worker-node.cjs --target=node16 --platform=node --bundle --sourcemap --define:__VERSION__=\\\"$npm_package_version\\\"" }, "dependencies": { "@babel/runtime": "^7.3.1", diff --git a/modules/i3s/package.json b/modules/i3s/package.json index 02c2bdd176..5b4bc6097e 100644 --- a/modules/i3s/package.json +++ b/modules/i3s/package.json @@ -38,7 +38,7 @@ "pre-build": "npm run build-bundle && npm run build-bundle -- --env=dev && npm run build-worker && npm run build-worker-node", "build-bundle": "ocular-bundle ./src/index.ts", "build-worker": "esbuild src/workers/i3s-content-worker.ts --outfile=dist/i3s-content-worker.js --target=esnext --bundle --define:__VERSION__=\\\"$npm_package_version\\\"", - "build-worker-node": "esbuild src/workers/i3s-content-worker-node.ts --outfile=dist/i3s-content-worker-node.js --platform=node --target=node16 --minify --bundle --sourcemap --define:__VERSION__=\\\"$npm_package_version\\\"" + "build-worker-node": "esbuild src/workers/i3s-content-worker-node.ts --outfile=dist/i3s-content-worker-node.cjs --platform=node --target=node16 --minify --bundle --sourcemap --define:__VERSION__=\\\"$npm_package_version\\\"" }, "dependencies": { "@loaders.gl/compression": "4.0.3", diff --git a/modules/textures/package.json b/modules/textures/package.json index 2cca3cc8f7..0ab06c9dda 100644 --- a/modules/textures/package.json +++ b/modules/textures/package.json @@ -45,9 +45,9 @@ "build-bundle": "ocular-bundle ./src/index.ts", "build-workers": "npm run build-basis-worker && npm run build-basis-worker-node && npm run build-npy-worker && npm run build-compressed-texture-worker && npm run build-crunch-worker && npm run build-ktx2-basis-writer-worker && npm run build-ktx2-basis-writer-worker-node", "build-basis-worker": "esbuild src/workers/basis-worker.ts --outfile=dist/basis-worker.js --target=esnext --bundle --define:__VERSION__=\\\"$npm_package_version\\\"", - "build-basis-worker-node": "esbuild src/workers/basis-worker-node.ts --outfile=dist/basis-worker-node.js --target=node16 --platform=node --bundle --define:__VERSION__=\\\"$npm_package_version\\\"", + "build-basis-worker-node": "esbuild src/workers/basis-worker-node.ts --outfile=dist/basis-worker-node.cjs --target=node16 --platform=node --bundle --define:__VERSION__=\\\"$npm_package_version\\\"", "build-ktx2-basis-writer-worker": "esbuild src/workers/ktx2-basis-writer-worker.ts --outfile=dist/ktx2-basis-writer-worker.js --target=esnext --bundle --define:__VERSION__=\\\"$npm_package_version\\\"", - "build-ktx2-basis-writer-worker-node": "esbuild src/workers/ktx2-basis-writer-worker-node.ts --outfile=dist/ktx2-basis-writer-worker-node.js --target=node16 --platform=node --bundle --define:__VERSION__=\\\"$npm_package_version\\\"", + "build-ktx2-basis-writer-worker-node": "esbuild src/workers/ktx2-basis-writer-worker-node.ts --outfile=dist/ktx2-basis-writer-worker-node.cjs --target=node16 --platform=node --bundle --define:__VERSION__=\\\"$npm_package_version\\\"", "build-npy-worker": "esbuild src/workers/npy-worker.ts --outfile=dist/npy-worker.js --target=esnext --bundle --define:__VERSION__=\\\"$npm_package_version\\\"", "build-compressed-texture-worker": "esbuild src/workers/compressed-texture-worker.ts --target=esnext --bundle --outfile=dist/compressed-texture-worker.js --define:__VERSION__=\\\"$npm_package_version\\\"", "build-crunch-worker": "esbuild src/workers/crunch-worker.ts --outfile=dist/crunch-worker.js --target=esnext --bundle --define:__VERSION__=\\\"$npm_package_version\\\"" diff --git a/modules/tile-converter/src/3d-tiles-converter/3d-tiles-converter.ts b/modules/tile-converter/src/3d-tiles-converter/3d-tiles-converter.ts index b29fdb0a34..c10518e733 100644 --- a/modules/tile-converter/src/3d-tiles-converter/3d-tiles-converter.ts +++ b/modules/tile-converter/src/3d-tiles-converter/3d-tiles-converter.ts @@ -47,7 +47,7 @@ export default class Tiles3DConverter { i3s: {coordinateSystem: COORDINATE_SYSTEM.LNGLAT_OFFSETS, decodeTextures: false}, // We need to load local fs workers because nodejs can't load workers from the Internet 'i3s-content': { - workerUrl: './modules/i3s/dist/i3s-content-worker-node.js' + workerUrl: './modules/i3s/dist/i3s-content-worker-node.cjs' } }; diff --git a/modules/tile-converter/src/deps-installer/deps-installer.ts b/modules/tile-converter/src/deps-installer/deps-installer.ts index 9abc1d76ff..f01a6114e9 100644 --- a/modules/tile-converter/src/deps-installer/deps-installer.ts +++ b/modules/tile-converter/src/deps-installer/deps-installer.ts @@ -37,19 +37,19 @@ export class DepsInstaller { await writeFile(depsPath, new Uint8Array(fileMap['geoids/egm2008-5.pgm']), 'egm2008-5.pgm'); console.log('Installing "I3S Content Loader" worker'); // eslint-disable-line no-console - await this.installFromNpm('i3s', 'i3s-content-worker-node.js'); + await this.installFromNpm('i3s', 'i3s-content-worker-node.cjs'); console.log('Installing "Draco Loader" worker'); // eslint-disable-line no-console - await this.installFromNpm('draco', 'draco-worker-node.js'); + await this.installFromNpm('draco', 'draco-worker-node.cjs'); console.log('Installing "Draco Writer" worker'); // eslint-disable-line no-console - await this.installFromNpm('draco', 'draco-writer-worker-node.js'); + await this.installFromNpm('draco', 'draco-writer-worker-node.cjs'); console.log('Installing "Basis Loader" worker'); // eslint-disable-line no-console - await this.installFromNpm('textures', 'basis-worker-node.js'); + await this.installFromNpm('textures', 'basis-worker-node.cjs'); console.log('Installing "KTX2 Basis Writer" worker'); // eslint-disable-line no-console - await this.installFromNpm('textures', 'ktx2-basis-writer-worker-node.js'); + await this.installFromNpm('textures', 'ktx2-basis-writer-worker-node.cjs'); console.log('Installing "Draco decoder" library'); // eslint-disable-line no-console await this.installFromUrl( diff --git a/modules/tile-converter/src/i3s-converter/helpers/geometry-converter.ts b/modules/tile-converter/src/i3s-converter/helpers/geometry-converter.ts index 076c9f0aa6..2c22f44b19 100644 --- a/modules/tile-converter/src/i3s-converter/helpers/geometry-converter.ts +++ b/modules/tile-converter/src/i3s-converter/helpers/geometry-converter.ts @@ -1577,7 +1577,7 @@ async function generateCompressedGeometry( }, ['draco-writer']: { // We need to load local fs workers because nodejs can't load workers from the Internet - workerUrl: './modules/draco/dist/draco-writer-worker-node.js' + workerUrl: './modules/draco/dist/draco-writer-worker-node.cjs' } } ); diff --git a/modules/tile-converter/src/i3s-converter/i3s-converter.ts b/modules/tile-converter/src/i3s-converter/i3s-converter.ts index d9eadcdef3..ac5002d6bd 100644 --- a/modules/tile-converter/src/i3s-converter/i3s-converter.ts +++ b/modules/tile-converter/src/i3s-converter/i3s-converter.ts @@ -121,10 +121,10 @@ export default class I3SConverter { basis: { format: 'rgba32', // We need to load local fs workers because nodejs can't load workers from the Internet - workerUrl: './modules/textures/dist/basis-worker-node.js' + workerUrl: './modules/textures/dist/basis-worker-node.cjs' }, // We need to load local fs workers because nodejs can't load workers from the Internet - draco: {workerUrl: './modules/draco/dist/draco-worker-node.js'}, + draco: {workerUrl: './modules/draco/dist/draco-worker-node.cjs'}, fetch: {}, modules: {} }; @@ -1027,7 +1027,7 @@ export default class I3SConverter { ...KTX2BasisWriterWorker.options, ['ktx2-basis-writer']: { // We need to load local fs workers because nodejs can't load workers from the Internet - workerUrl: './modules/textures/dist/ktx2-basis-writer-worker-node.js' + workerUrl: './modules/textures/dist/ktx2-basis-writer-worker-node.cjs' }, reuseWorkers: true, _nodeWorkers: true, diff --git a/modules/worker-utils/src/lib/worker-api/get-worker-url.ts b/modules/worker-utils/src/lib/worker-api/get-worker-url.ts index 1e7cdc27b6..76ad20db9c 100644 --- a/modules/worker-utils/src/lib/worker-api/get-worker-url.ts +++ b/modules/worker-utils/src/lib/worker-api/get-worker-url.ts @@ -27,7 +27,7 @@ export function getWorkerName(worker: WorkerObject): string { export function getWorkerURL(worker: WorkerObject, options: WorkerOptions = {}): string { const workerOptions = options[worker.id] || {}; - const workerFile = isBrowser ? `${worker.id}-worker.js` : `${worker.id}-worker-node.js`; + const workerFile = isBrowser ? `${worker.id}-worker.js` : `${worker.id}-worker-node.cjs`; let url = workerOptions.workerUrl; From 91a2b44e9dbba43c29dafd113f56ced98cbf49ee Mon Sep 17 00:00:00 2001 From: Viktor Belomestnov Date: Fri, 17 Nov 2023 15:29:35 +0100 Subject: [PATCH 2/2] make other workers cjs --- modules/compression/package.json | 2 +- modules/core/package.json | 2 +- modules/crypto/package.json | 2 +- modules/worker-utils/package.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/compression/package.json b/modules/compression/package.json index 49b3fe0c47..8d312c128c 100644 --- a/modules/compression/package.json +++ b/modules/compression/package.json @@ -43,7 +43,7 @@ "pre-build": "npm run build-bundle && npm run build-bundle -- --env=dev && npm run build-worker && npm run build-worker-node", "build-bundle": "ocular-bundle ./src/index.ts", "build-worker": "esbuild src/workers/compression-worker.ts --outfile=dist/compression-worker.js --target=esnext --bundle --minify --sourcemap --external:{fs,path,crypto} --define:__VERSION__=\\\"$npm_package_version\\\"", - "build-worker-node": "esbuild src/workers/compression-worker-node.ts --outfile=dist/compression-worker-node.js --platform=node --target=node16 --bundle --minify --sourcemap --define:__VERSION__=\\\"$npm_package_version\\\"" + "build-worker-node": "esbuild src/workers/compression-worker-node.ts --outfile=dist/compression-worker-node.cjs --platform=node --target=node16 --bundle --minify --sourcemap --define:__VERSION__=\\\"$npm_package_version\\\"" }, "dependencies": { "@babel/runtime": "^7.3.1", diff --git a/modules/core/package.json b/modules/core/package.json index 7ddce74fd9..6f56037a1d 100644 --- a/modules/core/package.json +++ b/modules/core/package.json @@ -45,7 +45,7 @@ "pre-build": "npm run build-bundle && npm run build-bundle -- --env=dev && npm run build-worker && npm run build-worker-node", "build-bundle": "ocular-bundle ./src/index.ts", "build-worker": "esbuild src/workers/null-worker.ts --outfile=dist/null-worker.js --bundle --target=esnext --define:__VERSION__=\\\"$npm_package_version\\\"", - "build-worker-node": "esbuild src/workers/null-worker.ts --outfile=dist/null-worker-node.js --bundle --platform=node --target=node16 --define:__VERSION__=\\\"$npm_package_version\\\"" + "build-worker-node": "esbuild src/workers/null-worker.ts --outfile=dist/null-worker-node.cjs --bundle --platform=node --target=node16 --define:__VERSION__=\\\"$npm_package_version\\\"" }, "dependencies": { "@babel/runtime": "^7.3.1", diff --git a/modules/crypto/package.json b/modules/crypto/package.json index ea39398132..f57d90eb0f 100644 --- a/modules/crypto/package.json +++ b/modules/crypto/package.json @@ -38,7 +38,7 @@ "pre-build": "npm run build-bundle && npm run build-bundle -- --env=dev && npm run build-worker && npm run build-worker-node", "build-bundle": "ocular-bundle ./src/index.ts", "build-worker": "esbuild src/workers/crypto-worker.ts --outfile=dist/crypto-worker.js --target=esnext --bundle --minify --sourcemap --define:__VERSION__=\\\"$npm_package_version\\\"", - "build-worker-node": "esbuild src/workers/crypto-worker-node.ts --outfile=dist/crypto-worker-node.js --platform=node --target=esnext,node16 --bundle --minify --sourcemap --define:__VERSION__=\\\"$npm_package_version\\\"" + "build-worker-node": "esbuild src/workers/crypto-worker-node.ts --outfile=dist/crypto-worker-node.cjs --platform=node --target=esnext,node16 --bundle --minify --sourcemap --define:__VERSION__=\\\"$npm_package_version\\\"" }, "dependencies": { "@babel/runtime": "^7.3.1", diff --git a/modules/worker-utils/package.json b/modules/worker-utils/package.json index 9cd9408628..19f8abe6da 100644 --- a/modules/worker-utils/package.json +++ b/modules/worker-utils/package.json @@ -47,7 +47,7 @@ "scripts": { "pre-build": "npm run build-worker && npm run build-worker-node", "build-worker": "esbuild src/workers/null-worker.ts --outfile=dist/null-worker.js --target=esnext --bundle --sourcemap --define:__VERSION__=\\\"$npm_package_version\\\"", - "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\\\"" + "build-worker-node": "esbuild src/workers/null-worker.ts --outfile=dist/null-worker-node.cjs --platform=node --target=node16 --bundle --sourcemap --define:__VERSION__=\\\"$npm_package_version\\\"" }, "dependencies": { "@babel/runtime": "^7.3.1"