Created
November 11, 2024 19:32
-
-
Save Dari4sho/71d5ea6eae4d50352d4244e61ebe4c6e to your computer and use it in GitHub Desktop.
Patch for `@codesandbox/sandpack-react` using patch-package to not use `eval()`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/node_modules/@codesandbox/sandpack-react/dist/index.js b/node_modules/@codesandbox/sandpack-react/dist/index.js | |
| index a419147..59f82ef 100644 | |
| --- a/node_modules/@codesandbox/sandpack-react/dist/index.js | |
| +++ b/node_modules/@codesandbox/sandpack-react/dist/index.js | |
| @@ -5037,8 +5037,20 @@ var MAX_MESSAGE_COUNT = MAX_KEYS * 2; | |
| // Const | |
| var GLOBAL = (function getGlobal() { | |
| // NOTE: see http://www.ecma-international.org/ecma-262/6.0/index.html#sec-performeval step 10 | |
| - var savedEval = eval; | |
| - return savedEval("this"); | |
| + if (typeof globalThis !== "undefined") { | |
| + // Modern standard | |
| + return globalThis; | |
| + } else if (typeof window !== "undefined") { | |
| + // Browsers | |
| + return window; | |
| + } else if (typeof global !== "undefined") { | |
| + // Node.js | |
| + return global; | |
| + } else if (typeof self !== "undefined") { | |
| + // Web Workers | |
| + return self; | |
| + } | |
| + throw new Error("Unable to locate global object."); | |
| })(); | |
| var ARRAY_BUFFER_SUPPORTED = typeof ArrayBuffer === "function"; | |
| var MAP_SUPPORTED = typeof Map === "function"; | |
| diff --git a/node_modules/@codesandbox/sandpack-react/dist/index.mjs b/node_modules/@codesandbox/sandpack-react/dist/index.mjs | |
| index fb56146..bcec85a 100644 | |
| --- a/node_modules/@codesandbox/sandpack-react/dist/index.mjs | |
| +++ b/node_modules/@codesandbox/sandpack-react/dist/index.mjs | |
| @@ -5010,8 +5010,20 @@ var MAX_MESSAGE_COUNT = MAX_KEYS * 2; | |
| // Const | |
| var GLOBAL = (function getGlobal() { | |
| // NOTE: see http://www.ecma-international.org/ecma-262/6.0/index.html#sec-performeval step 10 | |
| - var savedEval = eval; | |
| - return savedEval("this"); | |
| + if (typeof globalThis !== "undefined") { | |
| + // Modern standard | |
| + return globalThis; | |
| + } else if (typeof window !== "undefined") { | |
| + // Browsers | |
| + return window; | |
| + } else if (typeof global !== "undefined") { | |
| + // Node.js | |
| + return global; | |
| + } else if (typeof self !== "undefined") { | |
| + // Web Workers | |
| + return self; | |
| + } | |
| + throw new Error("Unable to locate global object."); | |
| })(); | |
| var ARRAY_BUFFER_SUPPORTED = typeof ArrayBuffer === "function"; | |
| var MAP_SUPPORTED = typeof Map === "function"; | |
| diff --git a/node_modules/@codesandbox/sandpack-react/dist/unstyled/index.js b/node_modules/@codesandbox/sandpack-react/dist/unstyled/index.js | |
| index b74ba42..dc6ed9d 100644 | |
| --- a/node_modules/@codesandbox/sandpack-react/dist/unstyled/index.js | |
| +++ b/node_modules/@codesandbox/sandpack-react/dist/unstyled/index.js | |
| @@ -5170,8 +5170,20 @@ var MAX_KEYS = 400; | |
| var MAX_MESSAGE_COUNT = MAX_KEYS * 2; | |
| var GLOBAL = (function getGlobal() { | |
| - var savedEval = eval; | |
| - return savedEval("this"); | |
| + if (typeof globalThis !== "undefined") { | |
| + // Modern standard | |
| + return globalThis; | |
| + } else if (typeof window !== "undefined") { | |
| + // Browsers | |
| + return window; | |
| + } else if (typeof global !== "undefined") { | |
| + // Node.js | |
| + return global; | |
| + } else if (typeof self !== "undefined") { | |
| + // Web Workers | |
| + return self; | |
| + } | |
| + throw new Error("Unable to locate global object."); | |
| })(); | |
| var ARRAY_BUFFER_SUPPORTED = typeof ArrayBuffer === "function"; | |
| var MAP_SUPPORTED = typeof Map === "function"; | |
| diff --git a/node_modules/@codesandbox/sandpack-react/dist/unstyled/index.mjs b/node_modules/@codesandbox/sandpack-react/dist/unstyled/index.mjs | |
| index 71a2a3c..5382845 100644 | |
| --- a/node_modules/@codesandbox/sandpack-react/dist/unstyled/index.mjs | |
| +++ b/node_modules/@codesandbox/sandpack-react/dist/unstyled/index.mjs | |
| @@ -5143,8 +5143,20 @@ var MAX_KEYS = 400; | |
| var MAX_MESSAGE_COUNT = MAX_KEYS * 2; | |
| var GLOBAL = (function getGlobal() { | |
| - var savedEval = eval; | |
| - return savedEval("this"); | |
| + if (typeof globalThis !== "undefined") { | |
| + // Modern standard | |
| + return globalThis; | |
| + } else if (typeof window !== "undefined") { | |
| + // Browsers | |
| + return window; | |
| + } else if (typeof global !== "undefined") { | |
| + // Node.js | |
| + return global; | |
| + } else if (typeof self !== "undefined") { | |
| + // Web Workers | |
| + return self; | |
| + } | |
| + throw new Error("Unable to locate global object."); | |
| })(); | |
| var ARRAY_BUFFER_SUPPORTED = typeof ArrayBuffer === "function"; | |
| var MAP_SUPPORTED = typeof Map === "function"; |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
According issue in the library's repository:
codesandbox/sandpack#1221
Put the patch file to a
patchesdirectory in the root of your project (usingnpm- might differ slightly for other package managers)Apply patch using:
npx patch-packageDon't forget to add
"postinstall": "npx patch-package"to
package.json