From d7106294ce213d549f5e11fd1dfaf4e6caa8a578 Mon Sep 17 00:00:00 2001 From: Ian Clester Date: Sun, 19 Sep 2021 19:37:44 -0400 Subject: [PATCH] Fix `IN_NODE`: avoid error with unrelated global. (#1849) --- docs/project/changelog.md | 6 ++++++ src/js/load-pyodide.js | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/project/changelog.md b/docs/project/changelog.md index 0667de80b..d2f3df2a9 100644 --- a/docs/project/changelog.md +++ b/docs/project/changelog.md @@ -19,6 +19,12 @@ substitutions: error, it will return an empty list instead of raising a `SyntaxError`. {pr}`1819` +### Javascript package + +- {{Fix}} {any}`loadPyodide ` no longer fails in the + presence of a user-defined global named `process`. + {pr}`1849` + ### Python / JavaScript type conversions - {{Enhancement}} Updated the calling convention when a Javascript function is diff --git a/src/js/load-pyodide.js b/src/js/load-pyodide.js index 9f997c2fa..c7a38bb60 100644 --- a/src/js/load-pyodide.js +++ b/src/js/load-pyodide.js @@ -1,7 +1,9 @@ import { Module } from "./module.js"; const IN_NODE = - typeof process !== "undefined" && process.release.name !== "undefined"; + typeof process !== "undefined" && + process.release && + process.release.name === "node"; /** @typedef {import('./pyproxy.js').PyProxy} PyProxy */ /** @private */ @@ -68,7 +70,7 @@ if (globalThis.document) { // This is async only for consistency globalThis.importScripts(url); }; -} else if (typeof process !== "undefined" && process.release.name === "node") { +} else if (IN_NODE) { const pathPromise = import("path").then((M) => M.default); const fetchPromise = import("node-fetch").then((M) => M.default); const vmPromise = import("vm").then((M) => M.default);