Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ibgreen committed Oct 8, 2023
1 parent 2f991d3 commit 0286f2a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
10 changes: 5 additions & 5 deletions modules/core/src/lib/fetch/fetch-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ export async function fetchFile(

// Support fetching from local file system
if (isNodePath(url)) {
if (!globalThis.loaders?.fetchNode) {
throw new Error(
'fetchFile: globalThis.loaders.fetchNode not defined. Install @loaders.gl/polyfills'
);
if (globalThis.loaders?.fetchNode) {
return globalThis.loaders?.fetchNode(url, fetchOptions);
}
return globalThis.loaders?.fetchNode(url, fetchOptions);
// throw new Error(
// 'fetchFile: globalThis.loaders.fetchNode not defined. Install @loaders.gl/polyfills'
// );
}

// Call global fetch
Expand Down
4 changes: 4 additions & 0 deletions modules/polyfills/src/index.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ export function installFilePolyfills() {}

// Dummy export to avoid import errors in browser tests
export const NodeFileSystem = null;

export function fetchNode(path: string, options: RequestInit): Promise<Response> {
throw new Error('fetchNode not available in browser');
}
18 changes: 10 additions & 8 deletions modules/polyfills/test/filesystems/fetch-node.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,18 @@ test('polyfills#fetchNode() error handling (NODE)', async (t) => {
});

test('polyfills#fetchNode() able to decompress .gz extension (NODE)', async (t) => {
let response = await fetchNode(TEXT_URL);
t.ok(response.ok, response.statusText);
let data = await response.text();
t.equal(data, '123456', 'fetchNode polyfill correctly read text file');

if (!isBrowser) {
response = await fetchNode(TEXT_URL_GZIPPED);
let response = await fetchNode(TEXT_URL);
t.ok(response.ok, response.statusText);
data = await response.text();
t.equal(data, '123456', 'fetchNode polyfill correctly decompressed gzipped ".gz" file');
let data = await response.text();
t.equal(data, '123456', 'fetchNode polyfill correctly read text file');

if (!isBrowser) {
response = await fetchNode(TEXT_URL_GZIPPED);
t.ok(response.ok, response.statusText);
data = await response.text();
t.equal(data, '123456', 'fetchNode polyfill correctly decompressed gzipped ".gz" file');
}
}
t.end();
});

0 comments on commit 0286f2a

Please sign in to comment.