Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(polyfills): Consolidate node code #2701

Merged
merged 3 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/benchmarks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@probe.gl/react-bench": "^4.0.2"
},
"devDependencies": {
"@loaders.gl/core": "4.0.0-alpha.23",
"@loaders.gl/core": "4.0.0-beta.3",
"@babel/cli": "^7.0.0",
"@babel/core": "^7.4.0",
"@babel/preset-react": "^7.0.0",
Expand Down
4 changes: 2 additions & 2 deletions examples/experimental/3d-tiles-with-cesium/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"start-local": "webpack-dev-server --env.local --env.esnext --progress --hot --open"
},
"dependencies": {
"@loaders.gl/3d-tiles": "4.0.0-alpha.23",
"@loaders.gl/core": "4.0.0-alpha.23",
"@loaders.gl/3d-tiles": "4.0.0-beta.3",
"@loaders.gl/core": "4.0.0-beta.3",
"@math.gl/culling": "^4.0.0",
"@math.gl/core": "^4.0.0"
},
Expand Down
4 changes: 2 additions & 2 deletions examples/experimental/3d-tiles-with-three.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"start-local": "webpack-dev-server --env.local --progress --hot --open"
},
"dependencies": {
"@loaders.gl/core": "4.0.0-alpha.23",
"@loaders.gl/3d-tiles": "4.0.0-alpha.23",
"@loaders.gl/core": "4.0.0-beta.3",
"@loaders.gl/3d-tiles": "4.0.0-beta.3",
"@math.gl/culling": "^4.0.0",
"mapbox-gl": "^1.1.1",
"three": "^0.106.2"
Expand Down
4 changes: 2 additions & 2 deletions examples/experimental/basis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"start-local": "webpack-dev-server --env.local --progress --hot --open"
},
"dependencies": {
"@loaders.gl/textures": "4.0.0-alpha.23",
"@loaders.gl/core": "^4.0.0-alpha.8"
"@loaders.gl/textures": "4.0.0-beta.3",
"@loaders.gl/core": "4.0.0-beta.3"
},
"devDependencies": {
"babel-plugin-inline-import": "^3.0.0",
Expand Down
4 changes: 2 additions & 2 deletions examples/experimental/gltf-with-deck.gl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"@deck.gl/core": "^8.9.28",
"@deck.gl/mesh-layers": "^8.9.28",
"@deck.gl/react": "^8.9.28",
"@loaders.gl/core": "4.0.0-alpha.23",
"@loaders.gl/gltf": "4.0.0-alpha.23",
"@loaders.gl/core": "4.0.0-beta.3",
"@loaders.gl/gltf": "4.0.0-beta.3",
"@luma.gl/constants": "^8.5.21",
"@luma.gl/experimental": "^8.5.21",
"maplibre-gl": "^2.4.0",
Expand Down
8 changes: 4 additions & 4 deletions examples/experimental/terrain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
"@deck.gl/react": "^8.9.28",
"@deck.gl/mesh-layers": "^8.9.28",
"@deck.gl/layers": "^8.9.28",
"@loaders.gl/core": "4.0.0-alpha.23",
"@loaders.gl/loader-utils": "4.0.0-alpha.23",
"@loaders.gl/mvt": "4.0.0-alpha.23",
"@loaders.gl/terrain": "4.0.0-alpha.23",
"@loaders.gl/core": "4.0.0-beta.3",
"@loaders.gl/loader-utils": "4.0.0-beta.3",
"@loaders.gl/mvt": "4.0.0-beta.3",
"@loaders.gl/terrain": "4.0.0-beta.3",
"maplibre-gl": "^2.4.0",
"react": "^18.0.0",
"react-dom": "^18.0.0",
Expand Down
4 changes: 2 additions & 2 deletions examples/get-started/bundle-with-nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"@deck.gl/geo-layers": "^8.9.28",
"@deck.gl/layers": "^8.9.28",
"@deck.gl/react": "^8.9.28",
"@loaders.gl/core": "4.0.0-alpha.23",
"@loaders.gl/worker-utils": "4.0.0-alpha.23",
"@loaders.gl/core": "4.0.0-beta.3",
"@loaders.gl/worker-utils": "4.0.0-beta.3",
"@next/font": "13.1.6",
"@types/node": "18.11.18",
"@types/react": "18.0.27",
Expand Down
4 changes: 2 additions & 2 deletions examples/get-started/bundle-with-rollup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"serve": "serve public"
},
"dependencies": {
"@loaders.gl/core": "4.0.0-alpha.23",
"@loaders.gl/obj": "^4.0.0-alpha.8"
"@loaders.gl/core": "4.0.0-beta.3",
"@loaders.gl/obj": "4.0.0-beta.3"
},
"devDependencies": {
"@rollup/plugin-alias": "^4.0.3",
Expand Down
4 changes: 2 additions & 2 deletions examples/get-started/bundle-with-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"serve": "vite preview"
},
"dependencies": {
"@loaders.gl/core": "4.0.0-alpha.23",
"@loaders.gl/gltf": "^4.0.0-alpha.8"
"@loaders.gl/core": "4.0.0-beta.3",
"@loaders.gl/gltf": "4.0.0-beta.3"
},
"devDependencies": {
"typescript": "^5.0.4",
Expand Down
4 changes: 2 additions & 2 deletions examples/get-started/bundle-with-webpack-4/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"start": "webpack-dev-server --progress --hot --open -d"
},
"dependencies": {
"@loaders.gl/core": "4.0.0-alpha.23",
"@loaders.gl/obj": "^4.0.0-alpha.8"
"@loaders.gl/core": "4.0.0-beta.3",
"@loaders.gl/obj": "4.0.0-beta.3"
},
"devDependencies": {
"webpack": "^4.42.0",
Expand Down
4 changes: 2 additions & 2 deletions examples/get-started/bundle-with-webpack-5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"build": "webpack build"
},
"dependencies": {
"@loaders.gl/core": "4.0.0-alpha.23",
"@loaders.gl/obj": "^4.0.0-alpha.8"
"@loaders.gl/core": "4.0.0-beta.3",
"@loaders.gl/obj": "4.0.0-beta.3"
},
"devDependencies": {
"html-webpack-plugin": "^5.5.0",
Expand Down
6 changes: 3 additions & 3 deletions examples/website/3d-tiles/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"@deck.gl/layers": "^8.9.28",
"@deck.gl/mesh-layers": "^8.9.28",
"@deck.gl/react": "^8.9.28",
"@loaders.gl/3d-tiles": "4.0.0-alpha.23",
"@loaders.gl/core": "4.0.0-alpha.23",
"@loaders.gl/gltf": "4.0.0-alpha.23",
"@loaders.gl/3d-tiles": "4.0.0-beta.3",
"@loaders.gl/core": "4.0.0-beta.3",
"@loaders.gl/gltf": "4.0.0-beta.3",
"@math.gl/core": "^4.0.0",
"@math.gl/geospatial": "^4.0.0",
"@probe.gl/stats-widget": "^4.0.2",
Expand Down
8 changes: 4 additions & 4 deletions examples/website/geospatial/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
"@deck.gl/core": "^8.9.28",
"@deck.gl/layers": "^8.9.28",
"@deck.gl/react": "^8.9.28",
"@loaders.gl/core": "4.0.0-alpha.23",
"@loaders.gl/flatgeobuf": "4.0.0-alpha.23",
"@loaders.gl/geopackage": "4.0.0-alpha.23",
"@loaders.gl/parquet": "4.0.0-alpha.23",
"@loaders.gl/core": "4.0.0-beta.3",
"@loaders.gl/flatgeobuf": "4.0.0-beta.3",
"@loaders.gl/geopackage": "4.0.0-beta.3",
"@loaders.gl/parquet": "4.0.0-beta.3",
"mapbox-gl": "npm:empty-npm-package@^1.0.0",
"maplibre-gl": "^2.4.0",
"react": "^18.0.0",
Expand Down
4 changes: 2 additions & 2 deletions examples/website/gltf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"serve": "vite preview"
},
"dependencies": {
"@loaders.gl/core": "4.0.0-alpha.23",
"@loaders.gl/gltf": "4.0.0-alpha.23",
"@loaders.gl/core": "4.0.0-beta.3",
"@loaders.gl/gltf": "4.0.0-beta.3",
"@luma.gl/constants": "^8.5.21",
"@luma.gl/core": "^8.5.21",
"@luma.gl/experimental": "^8.5.21",
Expand Down
4 changes: 2 additions & 2 deletions examples/website/i3s-arcgis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"@deck.gl/layers": "^8.9.28",
"@deck.gl/mesh-layers": "^8.9.28",
"@esri/react-arcgis": "^5.2.0",
"@loaders.gl/core": "4.0.0-alpha.23",
"@loaders.gl/i3s": "4.0.0-alpha.23",
"@loaders.gl/core": "4.0.0-beta.3",
"@loaders.gl/i3s": "4.0.0-beta.3",
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
Expand Down
10 changes: 5 additions & 5 deletions examples/website/i3s/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
"@fortawesome/fontawesome-svg-core": "^1.2.34",
"@fortawesome/free-solid-svg-icons": "^5.15.2",
"@fortawesome/react-fontawesome": "^0.1.14",
"@loaders.gl/core": "4.0.0-alpha.23",
"@loaders.gl/draco": "4.0.0-alpha.23",
"@loaders.gl/gltf": "4.0.0-alpha.23",
"@loaders.gl/i3s": "4.0.0-alpha.23",
"@loaders.gl/images": "4.0.0-alpha.23",
"@loaders.gl/core": "4.0.0-beta.3",
"@loaders.gl/draco": "4.0.0-beta.3",
"@loaders.gl/gltf": "4.0.0-beta.3",
"@loaders.gl/i3s": "4.0.0-beta.3",
"@loaders.gl/images": "4.0.0-beta.3",
"@luma.gl/constants": "^8.5.21",
"@luma.gl/core": "^8.5.21",
"@luma.gl/engine": "^8.5.21",
Expand Down
12 changes: 6 additions & 6 deletions examples/website/pointcloud/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
"@deck.gl/react": "^8.9.28",
"@deck.gl/core": "^8.9.28",
"@deck.gl/layers": "^8.9.28",
"@loaders.gl/core": "4.0.0-alpha.23",
"@loaders.gl/draco": "4.0.0-alpha.23",
"@loaders.gl/las": "4.0.0-alpha.23",
"@loaders.gl/obj": "4.0.0-alpha.23",
"@loaders.gl/pcd": "4.0.0-alpha.23",
"@loaders.gl/ply": "4.0.0-alpha.23",
"@loaders.gl/core": "4.0.0-beta.3",
"@loaders.gl/draco": "4.0.0-beta.3",
"@loaders.gl/las": "4.0.0-beta.3",
"@loaders.gl/obj": "4.0.0-beta.3",
"@loaders.gl/pcd": "4.0.0-beta.3",
"@loaders.gl/ply": "4.0.0-beta.3",
"prop-types": "^15.7.2",
"react": "^16.3.0",
"react-dom": "^16.3.0",
Expand Down
6 changes: 3 additions & 3 deletions examples/website/textures/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"serve": "vite preview"
},
"dependencies": {
"@loaders.gl/core": "4.0.0-alpha.23",
"@loaders.gl/images": "4.0.0-alpha.23",
"@loaders.gl/textures": "4.0.0-alpha.23",
"@loaders.gl/core": "4.0.0-beta.3",
"@loaders.gl/images": "4.0.0-beta.3",
"@loaders.gl/textures": "4.0.0-beta.3",
"@luma.gl/core": "^8.5.21",
"prop-types": "^15.7.2",
"react": "^16.3.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/website/tiles/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@deck.gl/mesh-layers": "^8.9.28",
"@deck.gl/extensions": "8.9.28",
"@deck.gl/react": "^8.9.28",
"@loaders.gl/core": "4.0.0-alpha.26",
"@loaders.gl/core": "4.0.0-beta.3",
"@monaco-editor/react": "^4.5.0",
"mapbox-gl": "npm:empty-npm-package@^1.0.0",
"maplibre-gl": "^2.4.0",
Expand Down
4 changes: 2 additions & 2 deletions examples/website/wms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"dependencies": {
"@deck.gl/core": "^8.9.28",
"@deck.gl/geo-layers": "^8.9.28",
"@loaders.gl/core": "4.0.0-alpha.23",
"@loaders.gl/wms": "4.0.0-alpha.23",
"@loaders.gl/core": "4.0.0-beta.3",
"@loaders.gl/wms": "4.0.0-beta.3",
"@monaco-editor/react": "^4.5.0",
"deck.gl": "^8.9.0",
"mapbox-gl": "npm:[email protected]",
Expand Down
2 changes: 1 addition & 1 deletion modules/3d-tiles/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"long": "^5.2.1"
},
"peerDependencies": {
"@loaders.gl/core": "^4.0.0-alpha.8"
"@loaders.gl/core": "4.0.0-beta.3"
},
"gitHead": "c95a4ff72512668a93d9041ce8636bac09333fd5"
}
8 changes: 4 additions & 4 deletions modules/core/src/core-addons/write-file-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ import {isBrowser} from '@loaders.gl/core';

// TODO hack - trick filesaver.js to skip loading under node
const savedNavigatorExists = 'navigator' in global;
const savedNavigator = global.navigator;
const savedNavigator = globalThis.navigator;
if (!isBrowser) {
global.navigator = {userAgent: 'MSIE 9.'};
globalThis.navigator = {userAgent: 'MSIE 9.'};
}

// Need to use `require` to ensure our modification of global code above happens first
const saveAs = require('filesaver.js');

if (!isBrowser) {
if (savedNavigatorExists) {
global.navigator = savedNavigator;
globalThis.navigator = savedNavigator;
} else {
delete global.navigator;
delete globalThis.navigator;
}
}
// END hack
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/lib/loader-utils/option-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {probeLog, NullLog} from './loggers';
import {DEFAULT_LOADER_OPTIONS, REMOVED_LOADER_OPTIONS} from './option-defaults';

/**
* Global state for loaders.gl. Stored on `global.loaders._state`
* Global state for loaders.gl. Stored on `globalThis.loaders._state`
*/
type GlobalLoaderState = {
loaderRegistry: Loader[];
Expand Down
1 change: 0 additions & 1 deletion modules/geopackage/test/index.js

This file was deleted.

2 changes: 2 additions & 0 deletions modules/geopackage/test/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// TODO v4.0 restore these tests
// import './geopackage-loader.spec';
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ test('GLTFScenegraph#BufferView indices resolve correctly', async (t) => {
t.end();
});

test('GLTFScenegraph#Typed Arrays sgould be taken by Accessor', async (t) => {
test('GLTFScenegraph#Typed Arrays should be taken by Accessor', async (t) => {
const GLB_ACCESSOR_URL = '@loaders.gl/gltf/test/data/glb/DamagedHelmet.glb';
const testDataSet = [
{
Expand Down
2 changes: 1 addition & 1 deletion modules/i3s/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"@math.gl/geospatial": "^4.0.0"
},
"peerDependencies": {
"@loaders.gl/core": "^4.0.0-alpha.8"
"@loaders.gl/core": "4.0.0-beta.3"
},
"gitHead": "c95a4ff72512668a93d9041ce8636bac09333fd5"
}
6 changes: 3 additions & 3 deletions modules/images/src/lib/category-api/image-format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ export function isImageFormatSupported(mimeType: string): boolean {
function checkNodeImageFormatSupport(mimeType: string): boolean {
/** @deprecated Remove these in 4.0 and rely on polyfills to inject them */
const NODE_FORMAT_SUPPORT = ['image/png', 'image/jpeg', 'image/gif'];
// @ts-ignore
const {_parseImageNode, _imageFormatsNode = NODE_FORMAT_SUPPORT} = globalThis;
return Boolean(_parseImageNode) && _imageFormatsNode.includes(mimeType);
const parseImageNode = globalThis.loaders?.parseImageNode;
const imageFormatsNode = globalThis.loaders?.imageFormatsNode || NODE_FORMAT_SUPPORT;
return Boolean(parseImageNode) && imageFormatsNode.includes(mimeType);
}

/** Checks image format support synchronously.
Expand Down
4 changes: 2 additions & 2 deletions modules/images/src/lib/category-api/image-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import {isBrowser} from '@loaders.gl/loader-utils';
import type {ImageTypeEnum} from '../../types';

// @ts-ignore TS2339: Property does not exist on type
const {_parseImageNode} = globalThis;
const parseImageNode = globalThis.loaders?.parseImageNode;

const IMAGE_SUPPORTED = typeof Image !== 'undefined'; // NOTE: "false" positives if jsdom is installed
const IMAGE_BITMAP_SUPPORTED = typeof ImageBitmap !== 'undefined';
const NODE_IMAGE_SUPPORTED = Boolean(_parseImageNode);
const NODE_IMAGE_SUPPORTED = Boolean(parseImageNode);
const DATA_SUPPORTED = isBrowser ? true : NODE_IMAGE_SUPPORTED;

/**
Expand Down
6 changes: 3 additions & 3 deletions modules/images/src/lib/encoders/encode-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {ImageDataType} from '../../types';
import {getImageSize} from '../category-api/parsed-image-api';

// @ts-ignore TS2339: Property does not exist on type
const {_encodeImageNode} = globalThis;
const encodeImageNode = globalThis.loaders?.encodeImageNode;

/**
* Returns data bytes representing a compressed image in PNG or JPG format,
Expand All @@ -20,8 +20,8 @@ export async function encodeImage(
options = options || {};
options.image = options.image || ({} as {[key: string]: any});

return _encodeImageNode
? _encodeImageNode(image, {type: options.image.mimeType})
return encodeImageNode
? encodeImageNode(image, {type: options.image.mimeType})
: encodeImageInBrowser(image, options);
}

Expand Down
6 changes: 3 additions & 3 deletions modules/images/src/lib/parsers/parse-to-node-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export async function parseToNodeImage(
const {mimeType} = getBinaryImageMetadata(arrayBuffer) || {};

// @ts-ignore
const _parseImageNode: ParseImageNode = globalThis._parseImageNode;
assert(_parseImageNode); // '@loaders.gl/polyfills not installed'
const parseImageNode: ParseImageNode = globalThis.loaders?.parseImageNode;
assert(parseImageNode); // '@loaders.gl/polyfills not installed'

// @ts-expect-error TODO should we throw error in this case?
return await _parseImageNode(arrayBuffer, mimeType);
return await parseImageNode(arrayBuffer, mimeType);
}
Loading
Loading