From 6d76bf120dd0f77eba6cde9c4d4ca27718244d7b Mon Sep 17 00:00:00 2001 From: Russell Parker <russell@benchling.com> Date: Wed, 8 Mar 2023 11:43:38 -0500 Subject: [PATCH] Change nodejs-shim conditional to avoid checking document (#740) --- CHANGELOG.md | 1 + package.json | 3 ++- src/mol-util/nodejs-shims.ts | 5 +++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d82f6aa8..959388fa2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Note that since we don't clearly distinguish between a public and private interf - Fix issue with outlines and orthographic camera - Reduce over-blurring occlusion at larger view distances - Fix occlusion artefact with non-canvas viewport and pixel-ratio > 1 +- Update nodejs-shims conditionals to handle polyfilled document object in NodeJS environment. ## [v3.31.4] - 2023-02-24 diff --git a/package.json b/package.json index 6755c44df..e6c29447f 100644 --- a/package.json +++ b/package.json @@ -96,7 +96,8 @@ "Ke Ma <mark.ma@rcsb.org>", "Jason Pattle <jpattle@exscientia.co.uk>", "David Williams <dwilliams@nobiastx.com>", - "Zhenyu Zhang <jump2cn@gmail.com>" + "Zhenyu Zhang <jump2cn@gmail.com>", + "Russell Parker <russell@benchling.com>" ], "license": "MIT", "devDependencies": { diff --git a/src/mol-util/nodejs-shims.ts b/src/mol-util/nodejs-shims.ts index fd4304860..0605f3d6b 100644 --- a/src/mol-util/nodejs-shims.ts +++ b/src/mol-util/nodejs-shims.ts @@ -2,6 +2,7 @@ * Copyright (c) 2018-2023 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Adam Midlik <midlik@gmail.com> + * @author Russell Parker <russell@benchling.com> * * Implements some browser-only global variables for Node.js environment. * These workarounds will also work in browsers as usual. @@ -19,7 +20,7 @@ export const File_ = getFile(); function getXMLHttpRequest(): typeof XMLHttpRequest { - if (typeof document === 'undefined') { + if (typeof XMLHttpRequest === 'undefined' || RUNNING_IN_NODEJS) { return require('xhr2'); } else { return XMLHttpRequest; @@ -27,7 +28,7 @@ function getXMLHttpRequest(): typeof XMLHttpRequest { } function getFile(): typeof File { - if (typeof document === 'undefined') { + if (typeof File === 'undefined' || RUNNING_IN_NODEJS) { class File_NodeJs implements File { private readonly blob: Blob; // Blob fields -- GitLab