diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 6bb07aa2..18d3ca39 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -50,5 +50,6 @@ module.exports = { curly: ['error', 'all'], 'brace-style': ['error', '1tbs', { allowSingleLine: false }], 'no-else-return': 0, + 'no-return-await': 0, }, }; diff --git a/package-lock.json b/package-lock.json index ac0cc1bd..70193033 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,7 @@ "parse-headers": "^2.0.2", "quick-lru": "^6.1.1", "web-worker": "^1.2.0", - "xml-utils": "^1.0.2", + "xml-utils": "^1.7.2-0", "zstddec": "^0.1.0" }, "devDependencies": { @@ -7576,9 +7576,9 @@ "dev": true }, "node_modules/xml-utils": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/xml-utils/-/xml-utils-1.0.2.tgz", - "integrity": "sha512-rEn0FvKi+YGjv9omf22oAf+0d6Ly/sgJ/CUufU/nOzS7SRLmgwSujrewc03KojXxt+aPaTRpm593TgehtUBMSQ==" + "version": "1.7.2-0", + "resolved": "https://registry.npmjs.org/xml-utils/-/xml-utils-1.7.2-0.tgz", + "integrity": "sha512-+4VGvZo5JVOUNJzGy6HSDJx4c4R8BN6qxa8WGm8a60Gmn/SJB/h0WCpY5NXLNPh49u46jHb7f7bGKWb5m/0I/Q==" }, "node_modules/xmlcreate": { "version": "2.0.3", @@ -13421,9 +13421,9 @@ "dev": true }, "xml-utils": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/xml-utils/-/xml-utils-1.0.2.tgz", - "integrity": "sha512-rEn0FvKi+YGjv9omf22oAf+0d6Ly/sgJ/CUufU/nOzS7SRLmgwSujrewc03KojXxt+aPaTRpm593TgehtUBMSQ==" + "version": "1.7.2-0", + "resolved": "https://registry.npmjs.org/xml-utils/-/xml-utils-1.7.2-0.tgz", + "integrity": "sha512-+4VGvZo5JVOUNJzGy6HSDJx4c4R8BN6qxa8WGm8a60Gmn/SJB/h0WCpY5NXLNPh49u46jHb7f7bGKWb5m/0I/Q==" }, "xmlcreate": { "version": "2.0.3", diff --git a/package.json b/package.json index f1b1becc..6273c27b 100644 --- a/package.json +++ b/package.json @@ -88,7 +88,7 @@ "parse-headers": "^2.0.2", "quick-lru": "^6.1.1", "web-worker": "^1.2.0", - "xml-utils": "^1.0.2", + "xml-utils": "^1.7.2-0", "zstddec": "^0.1.0" }, "devDependencies": { diff --git a/rollup.config.js b/rollup.config.js index a09e3349..be3d0bc3 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -24,6 +24,9 @@ export default { { modules: false, targets: 'last 2 versions, not dead', + exclude: [ + "@babel/plugin-transform-typeof-symbol" + ] }, ], ], diff --git a/src/geotiff.js b/src/geotiff.js index 17349a41..be8c8f6e 100644 --- a/src/geotiff.js +++ b/src/geotiff.js @@ -7,7 +7,6 @@ import Pool from './pool.js'; import { makeRemoteSource, makeCustomSource } from './source/remote.js'; import { makeBufferSource } from './source/arraybuffer.js'; import { makeFileReaderSource } from './source/filereader.js'; -import { makeFileSource } from './source/file.js'; import { BaseClient, BaseResponse } from './source/client/base.js'; import { fieldTypes, fieldTagNames, arrayFields, geoKeyNames } from './globals.js'; @@ -682,7 +681,7 @@ export { MultiGeoTIFF }; * @returns {Promise} The resulting GeoTIFF file. */ export async function fromUrl(url, options = {}, signal) { - return GeoTIFF.fromSource(makeRemoteSource(url, options), signal); + return GeoTIFF.fromSource(await makeRemoteSource(url, options), signal); } /** @@ -723,6 +722,7 @@ export async function fromArrayBuffer(arrayBuffer, signal) { * @returns {Promise} The resulting GeoTIFF file. */ export async function fromFile(path, signal) { + const makeFileSource = await import('./source/file.js'); return GeoTIFF.fromSource(makeFileSource(path), signal); } @@ -752,9 +752,11 @@ export async function fromBlob(blob, signal) { * @returns {Promise} The resulting MultiGeoTIFF file. */ export async function fromUrls(mainUrl, overviewUrls = [], options = {}, signal) { - const mainFile = await GeoTIFF.fromSource(makeRemoteSource(mainUrl, options), signal); + const mainSource = await makeRemoteSource(mainUrl, options); + const mainFile = await GeoTIFF.fromSource(mainSource, signal); const overviewFiles = await Promise.all( - overviewUrls.map((url) => GeoTIFF.fromSource(makeRemoteSource(url, options))), + overviewUrls.map((url) => makeRemoteSource(url, options).then((src) => GeoTIFF.fromSource(src)), + ), ); return new MultiGeoTIFF(mainFile, overviewFiles); diff --git a/src/geotiffimage.js b/src/geotiffimage.js index aff618ca..d29afd1d 100644 --- a/src/geotiffimage.js +++ b/src/geotiffimage.js @@ -1,7 +1,7 @@ /** @module geotiffimage */ import { getFloat16 } from '@petamoriken/float16'; -import getAttribute from 'xml-utils/get-attribute.js'; -import findTagsByName from 'xml-utils/find-tags-by-name.js'; +import getAttribute from 'xml-utils/get-attribute.mjs'; +import findTagsByName from 'xml-utils/find-tags-by-name.mjs'; import { photometricInterpretations, ExtraSamplesValues } from './globals.js'; import { fromWhiteIsZero, fromBlackIsZero, fromPalette, fromCMYK, fromYCbCr, fromCIELab } from './rgb.js'; diff --git a/src/source/remote.js b/src/source/remote.js index be752928..cd18a1e7 100644 --- a/src/source/remote.js +++ b/src/source/remote.js @@ -2,10 +2,6 @@ import { parseByteRanges, parseContentRange, parseContentType } from './httputil import { BaseSource } from './basesource.js'; import { BlockedSource } from './blockedsource.js'; -import { FetchClient } from './client/fetch.js'; -import { XHRClient } from './client/xhr.js'; -import { HttpClient } from './client/http.js'; - class RemoteSource extends BaseSource { /** * @@ -157,19 +153,28 @@ function maybeWrapInBlockedSource(source, { blockSize, cacheSize }) { return new BlockedSource(source, { blockSize, cacheSize }); } -export function makeFetchSource(url, { headers = {}, credentials, maxRanges = 0, allowFullFile = false, ...blockOptions } = {}) { +export async function makeFetchSource(url, { + headers = {}, + credentials, + maxRanges = 0, + allowFullFile = false, + ...blockOptions +} = {}) { + const { FetchClient } = await import('./client/fetch.js'); const client = new FetchClient(url, credentials); const source = new RemoteSource(client, headers, maxRanges, allowFullFile); return maybeWrapInBlockedSource(source, blockOptions); } -export function makeXHRSource(url, { headers = {}, maxRanges = 0, allowFullFile = false, ...blockOptions } = {}) { +export async function makeXHRSource(url, { headers = {}, maxRanges = 0, allowFullFile = false, ...blockOptions } = {}) { + const { XHRClient } = await import('./client/xhr.js'); const client = new XHRClient(url); const source = new RemoteSource(client, headers, maxRanges, allowFullFile); return maybeWrapInBlockedSource(source, blockOptions); } -export function makeHttpSource(url, { headers = {}, maxRanges = 0, allowFullFile = false, ...blockOptions } = {}) { +export async function makeHttpSource(url, { headers = {}, maxRanges = 0, allowFullFile = false, ...blockOptions } = {}) { + const { HttpClient } = await import('./client/http.js'); const client = new HttpClient(url); const source = new RemoteSource(client, headers, maxRanges, allowFullFile); return maybeWrapInBlockedSource(source, blockOptions); @@ -185,12 +190,12 @@ export function makeCustomSource(client, { headers = {}, maxRanges = 0, allowFul * @param {string} url * @param {object} options */ -export function makeRemoteSource(url, { forceXHR = false, ...clientOptions } = {}) { +export async function makeRemoteSource(url, { forceXHR = false, ...clientOptions } = {}) { if (typeof fetch === 'function' && !forceXHR) { - return makeFetchSource(url, clientOptions); + return await makeFetchSource(url, clientOptions); } if (typeof XMLHttpRequest !== 'undefined') { - return makeXHRSource(url, clientOptions); + return await makeXHRSource(url, clientOptions); } - return makeHttpSource(url, clientOptions); + return await makeHttpSource(url, clientOptions); }