pyodide
Version:
The Pyodide JavaScript package
4 lines • 69.7 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../src/js/vendor/stackframe/stackframe.ts", "../src/js/vendor/stackframe/error-stack-parser.ts", "../src/js/environments.ts", "../src/js/compat.ts", "../src/js/nativefs.ts", "../src/js/emscripten-settings.ts", "../src/js/version.ts", "../src/js/pyodide.ts"],
"sourcesContent": ["// @ts-nocheck\n// Port of https://github.com/stacktracejs/stackframe/blob/master/stackframe.js.\n// Rewritten to ES6 and removed UMD and CommonJS support.\n\nfunction _isNumber(n) {\n return !isNaN(parseFloat(n)) && isFinite(n);\n}\n\nfunction _capitalize(str) {\n return str.charAt(0).toUpperCase() + str.substring(1);\n}\n\nfunction _getter(p) {\n return function () {\n return this[p];\n };\n}\n\nvar booleanProps = [\"isConstructor\", \"isEval\", \"isNative\", \"isToplevel\"];\nvar numericProps = [\"columnNumber\", \"lineNumber\"];\nvar stringProps = [\"fileName\", \"functionName\", \"source\"];\nvar arrayProps = [\"args\"];\nvar objectProps = [\"evalOrigin\"];\n\nvar props = booleanProps.concat(\n numericProps,\n stringProps,\n arrayProps,\n objectProps,\n);\n\ndeclare namespace StackFrame {\n export interface StackFrameOptions {\n isConstructor?: boolean;\n isEval?: boolean;\n isNative?: boolean;\n isToplevel?: boolean;\n columnNumber?: number;\n lineNumber?: number;\n fileName?: string;\n functionName?: string;\n source?: string;\n args?: any[];\n evalOrigin?: StackFrame;\n }\n}\n\ndeclare class StackFrame {\n constructor(obj: StackFrame.StackFrameOptions);\n\n args?: any[];\n getArgs(): any[] | undefined;\n setArgs(args: any[]): void;\n\n evalOrigin?: StackFrame;\n getEvalOrigin(): StackFrame | undefined;\n setEvalOrigin(stackframe: StackFrame): void;\n\n isConstructor?: boolean;\n getIsConstructor(): boolean | undefined;\n setIsConstructor(isConstructor: boolean): void;\n\n isEval?: boolean;\n getIsEval(): boolean | undefined;\n setIsEval(isEval: boolean): void;\n\n isNative?: boolean;\n getIsNative(): boolean | undefined;\n setIsNative(isNative: boolean): void;\n\n isToplevel?: boolean;\n getIsToplevel(): boolean | undefined;\n setIsToplevel(isToplevel: boolean): void;\n\n columnNumber?: number;\n getColumnNumber(): number | undefined;\n setColumnNumber(columnNumber: number): void;\n\n lineNumber?: number;\n getLineNumber(): number | undefined;\n setLineNumber(lineNumber: number): void;\n\n fileName?: string;\n getFileName(): string | undefined;\n setFileName(fileName: string): void;\n\n functionName?: string;\n getFunctionName(): string | undefined;\n setFunctionName(functionName: string): void;\n\n source?: string;\n getSource(): string | undefined;\n setSource(source: string): void;\n\n toString(): string;\n}\n\nfunction StackFrame(obj) {\n if (!obj) return;\n for (var i = 0; i < props.length; i++) {\n if (obj[props[i]] !== undefined) {\n this[\"set\" + _capitalize(props[i])](obj[props[i]]);\n }\n }\n}\n\nStackFrame.prototype = {\n getArgs: function () {\n return this.args;\n },\n setArgs: function (v) {\n if (Object.prototype.toString.call(v) !== \"[object Array]\") {\n throw new TypeError(\"Args must be an Array\");\n }\n this.args = v;\n },\n\n getEvalOrigin: function () {\n return this.evalOrigin;\n },\n setEvalOrigin: function (v) {\n if (v instanceof StackFrame) {\n this.evalOrigin = v;\n } else if (v instanceof Object) {\n this.evalOrigin = new StackFrame(v);\n } else {\n throw new TypeError(\"Eval Origin must be an Object or StackFrame\");\n }\n },\n\n toString: function () {\n var fileName = this.getFileName() || \"\";\n var lineNumber = this.getLineNumber() || \"\";\n var columnNumber = this.getColumnNumber() || \"\";\n var functionName = this.getFunctionName() || \"\";\n if (this.getIsEval()) {\n if (fileName) {\n return (\n \"[eval] (\" + fileName + \":\" + lineNumber + \":\" + columnNumber + \")\"\n );\n }\n return \"[eval]:\" + lineNumber + \":\" + columnNumber;\n }\n if (functionName) {\n return (\n functionName +\n \" (\" +\n fileName +\n \":\" +\n lineNumber +\n \":\" +\n columnNumber +\n \")\"\n );\n }\n return fileName + \":\" + lineNumber + \":\" + columnNumber;\n },\n};\n\nStackFrame.fromString = function StackFrame$$fromString(str) {\n var argsStartIndex = str.indexOf(\"(\");\n var argsEndIndex = str.lastIndexOf(\")\");\n\n var functionName = str.substring(0, argsStartIndex);\n var args = str.substring(argsStartIndex + 1, argsEndIndex).split(\",\");\n var locationString = str.substring(argsEndIndex + 1);\n\n if (locationString.indexOf(\"@\") === 0) {\n var parts = /@(.+?)(?::(\\d+))?(?::(\\d+))?$/.exec(locationString, \"\");\n var fileName = parts[1];\n var lineNumber = parts[2];\n var columnNumber = parts[3];\n }\n\n return new StackFrame({\n functionName: functionName,\n args: args || undefined,\n fileName: fileName,\n lineNumber: lineNumber || undefined,\n columnNumber: columnNumber || undefined,\n });\n};\n\nfor (var i = 0; i < booleanProps.length; i++) {\n StackFrame.prototype[\"get\" + _capitalize(booleanProps[i])] = _getter(\n booleanProps[i],\n );\n StackFrame.prototype[\"set\" + _capitalize(booleanProps[i])] = (function (p) {\n return function (v) {\n this[p] = Boolean(v);\n };\n })(booleanProps[i]);\n}\n\nfor (var j = 0; j < numericProps.length; j++) {\n StackFrame.prototype[\"get\" + _capitalize(numericProps[j])] = _getter(\n numericProps[j],\n );\n StackFrame.prototype[\"set\" + _capitalize(numericProps[j])] = (function (p) {\n return function (v) {\n if (!_isNumber(v)) {\n throw new TypeError(p + \" must be a Number\");\n }\n this[p] = Number(v);\n };\n })(numericProps[j]);\n}\n\nfor (var k = 0; k < stringProps.length; k++) {\n StackFrame.prototype[\"get\" + _capitalize(stringProps[k])] = _getter(\n stringProps[k],\n );\n StackFrame.prototype[\"set\" + _capitalize(stringProps[k])] = (function (p) {\n return function (v) {\n this[p] = String(v);\n };\n })(stringProps[k]);\n}\n\nexport default StackFrame;\n", "// @ts-nocheck\n// Port of https://github.com/stacktracejs/error-stack-parser\n// Rewritten to ES6 and removed UMD and CommonJS support.\n// Removed old opera support.\n\nimport StackFrame from \"./stackframe\";\n\ndeclare namespace ErrorStackParser {\n export type { StackFrame };\n /**\n * Given an Error object, extract the most information from it.\n *\n * @param {Error} error object\n * @return {Array} of StackFrames\n */\n export function parse(error: Error): StackFrame[];\n}\n\nfunction ErrorStackParser() {\n var CHROME_IE_STACK_REGEXP = /^\\s*at .*(\\S+:\\d+|\\(native\\))/m;\n var SAFARI_NATIVE_CODE_REGEXP = /^(eval@)?(\\[native code])?$/;\n\n return {\n /**\n * Given an Error object, extract the most information from it.\n *\n * @param {Error} error object\n * @return {Array} of StackFrames\n */\n parse: function ErrorStackParser$$parse(error: Error): StackFrame[] {\n if (error.stack && error.stack.match(CHROME_IE_STACK_REGEXP)) {\n return this.parseV8OrIE(error);\n } else if (error.stack) {\n return this.parseFFOrSafari(error);\n } else {\n throw new Error(\"Cannot parse given Error object\");\n }\n },\n\n // Separate line and column numbers from a string of the form: (URI:Line:Column)\n extractLocation: function ErrorStackParser$$extractLocation(urlLike) {\n // Fail-fast but return locations like \"(native)\"\n if (urlLike.indexOf(\":\") === -1) {\n return [urlLike];\n }\n\n var regExp = /(.+?)(?::(\\d+))?(?::(\\d+))?$/;\n var parts = regExp.exec(urlLike.replace(/[()]/g, \"\"));\n return [parts[1], parts[2] || undefined, parts[3] || undefined];\n },\n\n parseV8OrIE: function ErrorStackParser$$parseV8OrIE(error) {\n var filtered = error.stack.split(\"\\n\").filter(function (line) {\n return !!line.match(CHROME_IE_STACK_REGEXP);\n }, this);\n\n return filtered.map(function (line) {\n if (line.indexOf(\"(eval \") > -1) {\n // Throw away eval information until we implement stacktrace.js/stackframe#8\n line = line\n .replace(/eval code/g, \"eval\")\n .replace(/(\\(eval at [^()]*)|(,.*$)/g, \"\");\n }\n var sanitizedLine = line\n .replace(/^\\s+/, \"\")\n .replace(/\\(eval code/g, \"(\")\n .replace(/^.*?\\s+/, \"\");\n\n // capture and preserve the parenthesized location \"(/foo/my bar.js:12:87)\" in\n // case it has spaces in it, as the string is split on \\s+ later on\n var location = sanitizedLine.match(/ (\\(.+\\)$)/);\n\n // remove the parenthesized location from the line, if it was matched\n sanitizedLine = location\n ? sanitizedLine.replace(location[0], \"\")\n : sanitizedLine;\n\n // if a location was matched, pass it to extractLocation() otherwise pass all sanitizedLine\n // because this line doesn't have function name\n var locationParts = this.extractLocation(\n location ? location[1] : sanitizedLine,\n );\n var functionName = (location && sanitizedLine) || undefined;\n var fileName =\n [\"eval\", \"<anonymous>\"].indexOf(locationParts[0]) > -1\n ? undefined\n : locationParts[0];\n\n return new StackFrame({\n functionName: functionName,\n fileName: fileName,\n lineNumber: locationParts[1],\n columnNumber: locationParts[2],\n source: line,\n });\n }, this);\n },\n\n parseFFOrSafari: function ErrorStackParser$$parseFFOrSafari(error) {\n var filtered = error.stack.split(\"\\n\").filter(function (line) {\n return !line.match(SAFARI_NATIVE_CODE_REGEXP);\n }, this);\n\n return filtered.map(function (line) {\n // Throw away eval information until we implement stacktrace.js/stackframe#8\n if (line.indexOf(\" > eval\") > -1) {\n line = line.replace(\n / line (\\d+)(?: > eval line \\d+)* > eval:\\d+:\\d+/g,\n \":$1\",\n );\n }\n\n if (line.indexOf(\"@\") === -1 && line.indexOf(\":\") === -1) {\n // Safari eval frames only have function names and nothing else\n return new StackFrame({\n functionName: line,\n });\n } else {\n var functionNameRegex = /((.*\".+\"[^@]*)?[^@]*)(?:@)/;\n var matches = line.match(functionNameRegex);\n var functionName = matches && matches[1] ? matches[1] : undefined;\n var locationParts = this.extractLocation(\n line.replace(functionNameRegex, \"\"),\n );\n\n return new StackFrame({\n functionName: functionName,\n fileName: locationParts[0],\n lineNumber: locationParts[1],\n columnNumber: locationParts[2],\n source: line,\n });\n }\n }, this);\n },\n };\n}\n\nconst errorStackParser = new ErrorStackParser();\n\nexport { StackFrame };\nexport default errorStackParser;\n", "// @ts-nocheck\n\n/** @private */\nexport const IN_NODE =\n typeof process === \"object\" &&\n typeof process.versions === \"object\" &&\n typeof process.versions.node === \"string\" &&\n !process.browser; /* This last condition checks if we run the browser shim of process */\n\n/** @private */\nexport const IN_NODE_COMMONJS =\n IN_NODE &&\n typeof module !== \"undefined\" &&\n typeof module.exports !== \"undefined\" &&\n typeof require !== \"undefined\" &&\n typeof __dirname !== \"undefined\";\n\n/** @private */\nexport const IN_NODE_ESM = IN_NODE && !IN_NODE_COMMONJS;\n\n/** @private */\nexport const IN_BUN = typeof globalThis.Bun !== \"undefined\";\n\n/** @private */\nexport const IN_DENO = typeof Deno !== \"undefined\"; // just in case...\n\n/** @private */\nexport const IN_BROWSER = !IN_NODE && !IN_DENO;\n\n/** @private */\nexport const IN_BROWSER_MAIN_THREAD =\n IN_BROWSER &&\n typeof window === \"object\" &&\n typeof document === \"object\" &&\n typeof document.createElement === \"function\" &&\n \"sessionStorage\" in window &&\n typeof importScripts !== \"function\";\n\n/** @private */\nexport const IN_BROWSER_WEB_WORKER =\n IN_BROWSER && typeof importScripts === \"function\" && typeof self === \"object\";\n\n/** @private */\nexport const IN_SAFARI =\n typeof navigator === \"object\" &&\n typeof navigator.userAgent === \"string\" &&\n navigator.userAgent.indexOf(\"Chrome\") == -1 &&\n navigator.userAgent.indexOf(\"Safari\") > -1;\n\n/**\n * Detects the current environment and returns a record with the results.\n * This function is useful for debugging and testing purposes.\n * @private\n */\nexport function detectEnvironment(): Record<string, boolean> {\n return {\n IN_NODE: IN_NODE,\n IN_NODE_COMMONJS: IN_NODE_COMMONJS,\n IN_NODE_ESM: IN_NODE_ESM,\n IN_BUN: IN_BUN,\n IN_DENO: IN_DENO,\n IN_BROWSER: IN_BROWSER,\n IN_BROWSER_MAIN_THREAD: IN_BROWSER_MAIN_THREAD,\n IN_BROWSER_WEB_WORKER: IN_BROWSER_WEB_WORKER,\n IN_SAFARI: IN_SAFARI,\n };\n}\n", "import ErrorStackParser from \"./vendor/stackframe/error-stack-parser\";\nimport {\n IN_NODE,\n IN_NODE_ESM,\n IN_BROWSER_MAIN_THREAD,\n IN_BROWSER_WEB_WORKER,\n IN_NODE_COMMONJS,\n} from \"./environments\";\nimport { Lockfile } from \"./types\";\n\nlet nodeUrlMod: typeof import(\"node:url\");\nlet nodePath: typeof import(\"node:path\");\nlet nodeVmMod: typeof import(\"node:vm\");\n/** @private */\nexport let nodeFSMod: typeof import(\"node:fs\");\n/** @private */\nexport let nodeFsPromisesMod: typeof import(\"node:fs/promises\");\n\ndeclare var globalThis: {\n importScripts: (url: string) => void;\n document?: typeof document;\n fetch?: typeof fetch;\n};\n\n/**\n * If we're in node, it's most convenient to import various node modules on\n * initialization. Otherwise, this does nothing.\n * @private\n */\nexport async function initNodeModules() {\n if (!IN_NODE) {\n return;\n }\n // @ts-ignore\n nodeUrlMod = (await import(\"node:url\")).default;\n nodeFSMod = await import(\"node:fs\");\n nodeFsPromisesMod = await import(\"node:fs/promises\");\n\n // @ts-ignore\n nodeVmMod = (await import(\"node:vm\")).default;\n nodePath = await import(\"node:path\");\n pathSep = nodePath.sep;\n\n // Emscripten uses `require`, so if it's missing (because we were imported as\n // an ES6 module) we need to polyfill `require` with `import`. `import` is\n // async and `require` is synchronous, so we import all packages that might be\n // required up front and define require to look them up in this table.\n\n if (typeof require !== \"undefined\") {\n return;\n }\n // These are all the packages required in pyodide.asm.js. You can get this\n // list with:\n // $ grep -o 'require(\"[a-z]*\")' pyodide.asm.js | sort -u\n const fs = nodeFSMod;\n const crypto = await import(\"node:crypto\");\n const ws = await import(\"ws\");\n const child_process = await import(\"node:child_process\");\n const node_modules: { [mode: string]: any } = {\n fs,\n crypto,\n ws,\n child_process,\n };\n // Since we're in an ES6 module, this is only modifying the module namespace,\n // it's still private to Pyodide.\n (globalThis as any).require = function (mod: string): any {\n return node_modules[mod];\n };\n}\n\nfunction node_resolvePath(path: string, base?: string): string {\n return nodePath.resolve(base || \".\", path);\n}\n\nfunction browser_resolvePath(path: string, base?: string): string {\n if (base === undefined) {\n // @ts-ignore\n base = location;\n }\n return new URL(path, base).toString();\n}\n\nexport let resolvePath: (rest: string, base?: string) => string;\nif (IN_NODE) {\n resolvePath = node_resolvePath;\n} else {\n resolvePath = browser_resolvePath;\n}\n\n/**\n * Get the path separator. If we are on Linux or in the browser, it's /.\n * In Windows, it's \\.\n * @private\n */\nexport let pathSep: string;\n\nif (!IN_NODE) {\n pathSep = \"/\";\n}\n\n/**\n * Load a binary file, only for use in Node. If the path explicitly is a URL,\n * then fetch from a URL, else load from the file system.\n * @param indexURL base path to resolve relative paths\n * @param path the path to load\n * @param checksum sha-256 checksum of the package\n * @returns An ArrayBuffer containing the binary data\n * @private\n */\nfunction node_getBinaryResponse(\n path: string,\n _file_sub_resource_hash?: string | undefined, // Ignoring sub resource hash. See issue-2431.\n):\n | { response: Promise<Response>; binary?: undefined }\n | { binary: Promise<Uint8Array> } {\n if (path.startsWith(\"file://\")) {\n // handle file:// with filesystem operations rather than with fetch.\n path = path.slice(\"file://\".length);\n }\n if (path.includes(\"://\")) {\n // If it has a protocol, make a fetch request\n return { response: fetch(path) };\n } else {\n // Otherwise get it from the file system\n return {\n binary: nodeFsPromisesMod\n .readFile(path)\n .then(\n (data: Buffer) =>\n new Uint8Array(data.buffer, data.byteOffset, data.byteLength),\n ),\n };\n }\n}\n\n/**\n * Load a binary file, only for use in browser. Resolves relative paths against\n * indexURL.\n *\n * @param path the path to load\n * @param subResourceHash the sub resource hash for fetch() integrity check\n * @returns A Uint8Array containing the binary data\n * @private\n */\nfunction browser_getBinaryResponse(\n path: string,\n subResourceHash: string | undefined,\n): { response: Promise<Response>; binary?: undefined } {\n const url = new URL(path, location as unknown as URL);\n let options = subResourceHash ? { integrity: subResourceHash } : {};\n return { response: fetch(url, options) };\n}\n\n/** @private */\nexport let getBinaryResponse: (\n path: string,\n file_sub_resource_hash?: string | undefined,\n) =>\n | { response: Promise<Response>; binary?: undefined }\n | { response?: undefined; binary: Promise<Uint8Array> };\nif (IN_NODE) {\n getBinaryResponse = node_getBinaryResponse;\n} else {\n getBinaryResponse = browser_getBinaryResponse;\n}\n\nexport async function loadBinaryFile(\n path: string,\n file_sub_resource_hash?: string | undefined,\n): Promise<Uint8Array> {\n const { response, binary } = getBinaryResponse(path, file_sub_resource_hash);\n if (binary) {\n return binary;\n }\n const r = await response;\n if (!r.ok) {\n throw new Error(`Failed to load '${path}': request failed.`);\n }\n return new Uint8Array(await r.arrayBuffer());\n}\n\n/**\n * Currently loadScript is only used once to load `pyodide.asm.js`.\n * @param url\n * @private\n */\nexport let loadScript: (url: string) => Promise<void>;\n\nif (IN_BROWSER_MAIN_THREAD) {\n // browser\n loadScript = async (url) => await import(/* webpackIgnore: true */ url);\n} else if (IN_BROWSER_WEB_WORKER) {\n // webworker\n loadScript = async (url) => {\n try {\n // use importScripts in classic web worker\n globalThis.importScripts(url);\n } catch (e) {\n // importScripts throws TypeError in a module type web worker, use import instead\n if (e instanceof TypeError) {\n await import(/* webpackIgnore: true */ url);\n } else {\n throw e;\n }\n }\n };\n} else if (IN_NODE) {\n loadScript = nodeLoadScript;\n} else {\n throw new Error(\"Cannot determine runtime environment\");\n}\n\n/**\n * Load a text file and executes it as Javascript\n * @param url The path to load. May be a url or a relative file system path.\n * @private\n */\nasync function nodeLoadScript(url: string) {\n if (url.startsWith(\"file://\")) {\n // handle file:// with filesystem operations rather than with fetch.\n url = url.slice(\"file://\".length);\n }\n if (url.includes(\"://\")) {\n // If it's a url, load it with fetch then eval it.\n nodeVmMod.runInThisContext(await (await fetch(url)).text());\n } else {\n // Otherwise, hopefully it is a relative path we can load from the file\n // system.\n await import(/* webpackIgnore: true */ nodeUrlMod.pathToFileURL(url).href);\n }\n}\n\nexport async function loadLockFile(lockFileURL: string): Promise<Lockfile> {\n if (IN_NODE) {\n await initNodeModules();\n const package_string = await nodeFsPromisesMod.readFile(lockFileURL, {\n encoding: \"utf8\",\n });\n return JSON.parse(package_string);\n } else {\n let response = await fetch(lockFileURL);\n return await response.json();\n }\n}\n\n/**\n * Calculate the directory name of the current module.\n * This is used to guess the indexURL when it is not provided.\n */\nexport async function calculateDirname(): Promise<string> {\n if (IN_NODE_COMMONJS) {\n return __dirname;\n }\n\n let err: Error;\n try {\n throw new Error();\n } catch (e) {\n err = e as Error;\n }\n let fileName = ErrorStackParser.parse(err)[0].fileName!;\n\n if (IN_NODE && !fileName.startsWith(\"file://\")) {\n fileName = `file://${fileName}`; // Error stack filenames are not starting with `file://` in `Bun`\n }\n\n if (IN_NODE_ESM) {\n const nodePath = await import(\"node:path\");\n const nodeUrl = await import(\"node:url\");\n\n // FIXME: We would like to use import.meta.url here,\n // but mocha seems to mess with compiling typescript files to ES6.\n return nodeUrl.fileURLToPath(nodePath.dirname(fileName));\n }\n\n const indexOfLastSlash = fileName.lastIndexOf(pathSep);\n if (indexOfLastSlash === -1) {\n throw new Error(\n \"Could not extract indexURL path from pyodide module location\",\n );\n }\n return fileName.slice(0, indexOfLastSlash);\n}\n\n/**\n * Ensure that the directory exists before trying to download files into it (Node.js only).\n * @param dir The directory to ensure exists\n */\nexport async function ensureDirNode(dir: string) {\n if (!IN_NODE) {\n return;\n }\n\n try {\n // Check if the `installBaseUrl` directory exists\n await nodeFsPromisesMod.stat(dir); // Use `.stat()` which works even on ASAR archives of Electron apps, while `.access` doesn't.\n } catch {\n // If it doesn't exist, make it. Call mkdir() here only when necessary after checking the existence to avoid an error on read-only file systems. See https://github.com/pyodide/pyodide/issues/4736\n await nodeFsPromisesMod.mkdir(dir, {\n recursive: true,\n });\n }\n}\n", "import { Module } from \"./types\";\n\n/**\n * @private\n */\nasync function syncfs(m: Module, direction: boolean): Promise<void> {\n return new Promise((resolve, reject) => {\n m.FS.syncfs(direction, (err: any) => {\n if (err) {\n reject(err);\n } else {\n resolve();\n }\n });\n });\n}\n\n/**\n * @private\n */\nexport async function syncLocalToRemote(m: Module): Promise<void> {\n return await syncfs(m, false);\n}\n\n/**\n * @private\n */\nexport async function syncRemoteToLocal(m: Module): Promise<void> {\n return await syncfs(m, true);\n}\n\n/**\n * @private\n */\nexport function initializeNativeFS(module: Module) {\n const FS = module.FS;\n const MEMFS = module.FS.filesystems.MEMFS;\n const PATH = module.PATH;\n\n const nativeFSAsync = {\n // DIR_MODE: {{{ cDefine('S_IFDIR') }}} | 511 /* 0777 */,\n // FILE_MODE: {{{ cDefine('S_IFREG') }}} | 511 /* 0777 */,\n DIR_MODE: 16384 | 511,\n FILE_MODE: 32768 | 511,\n mount: function (mount: any) {\n if (!mount.opts.fileSystemHandle) {\n throw new Error(\"opts.fileSystemHandle is required\");\n }\n\n // reuse all of the core MEMFS functionality\n return MEMFS.mount.apply(null, arguments);\n },\n syncfs: async (mount: any, populate: Boolean, callback: Function) => {\n try {\n const local = nativeFSAsync.getLocalSet(mount);\n const remote = await nativeFSAsync.getRemoteSet(mount);\n const src = populate ? remote : local;\n const dst = populate ? local : remote;\n await nativeFSAsync.reconcile(mount, src, dst);\n callback(null);\n } catch (e) {\n callback(e);\n }\n },\n // Returns file set of emscripten's filesystem at the mountpoint.\n getLocalSet: (mount: any) => {\n let entries = Object.create(null);\n\n function isRealDir(p: string) {\n return p !== \".\" && p !== \"..\";\n }\n\n function toAbsolute(root: string) {\n return (p: string) => {\n return PATH.join2(root, p);\n };\n }\n\n let check = FS.readdir(mount.mountpoint)\n .filter(isRealDir)\n .map(toAbsolute(mount.mountpoint));\n\n while (check.length) {\n let path = check.pop();\n let stat = FS.stat(path);\n\n if (FS.isDir(stat.mode)) {\n check.push.apply(\n check,\n FS.readdir(path).filter(isRealDir).map(toAbsolute(path)),\n );\n }\n\n entries[path] = { timestamp: stat.mtime, mode: stat.mode };\n }\n\n return { type: \"local\", entries: entries };\n },\n // Returns file set of the real, on-disk filesystem at the mountpoint.\n getRemoteSet: async (mount: any) => {\n // TODO: this should be a map.\n const entries = Object.create(null);\n\n const handles = await getFsHandles(mount.opts.fileSystemHandle);\n for (const [path, handle] of handles) {\n if (path === \".\") continue;\n\n entries[PATH.join2(mount.mountpoint, path)] = {\n timestamp:\n handle.kind === \"file\"\n ? new Date((await handle.getFile()).lastModified)\n : new Date(),\n mode:\n handle.kind === \"file\"\n ? nativeFSAsync.FILE_MODE\n : nativeFSAsync.DIR_MODE,\n };\n }\n\n return { type: \"remote\", entries, handles };\n },\n loadLocalEntry: (path: string) => {\n const lookup = FS.lookupPath(path);\n const node = lookup.node;\n const stat = FS.stat(path);\n\n if (FS.isDir(stat.mode)) {\n return { timestamp: stat.mtime, mode: stat.mode };\n } else if (FS.isFile(stat.mode)) {\n node.contents = MEMFS.getFileDataAsTypedArray(node);\n return {\n timestamp: stat.mtime,\n mode: stat.mode,\n contents: node.contents,\n };\n } else {\n throw new Error(\"node type not supported\");\n }\n },\n storeLocalEntry: (path: string, entry: any) => {\n if (FS.isDir(entry[\"mode\"])) {\n FS.mkdirTree(path, entry[\"mode\"]);\n } else if (FS.isFile(entry[\"mode\"])) {\n FS.writeFile(path, entry[\"contents\"], { canOwn: true });\n } else {\n throw new Error(\"node type not supported\");\n }\n\n FS.chmod(path, entry[\"mode\"]);\n FS.utime(path, entry[\"timestamp\"], entry[\"timestamp\"]);\n },\n removeLocalEntry: (path: string) => {\n var stat = FS.stat(path);\n\n if (FS.isDir(stat.mode)) {\n FS.rmdir(path);\n } else if (FS.isFile(stat.mode)) {\n FS.unlink(path);\n }\n },\n loadRemoteEntry: async (handle: any) => {\n if (handle.kind === \"file\") {\n const file = await handle.getFile();\n return {\n contents: new Uint8Array(await file.arrayBuffer()),\n mode: nativeFSAsync.FILE_MODE,\n timestamp: new Date(file.lastModified),\n };\n } else if (handle.kind === \"directory\") {\n return {\n mode: nativeFSAsync.DIR_MODE,\n timestamp: new Date(),\n };\n } else {\n throw new Error(\"unknown kind: \" + handle.kind);\n }\n },\n storeRemoteEntry: async (handles: any, path: string, entry: any) => {\n const parentDirHandle = handles.get(PATH.dirname(path));\n const handle = FS.isFile(entry.mode)\n ? await parentDirHandle.getFileHandle(PATH.basename(path), {\n create: true,\n })\n : await parentDirHandle.getDirectoryHandle(PATH.basename(path), {\n create: true,\n });\n if (handle.kind === \"file\") {\n const writable = await handle.createWritable();\n await writable.write(entry.contents);\n await writable.close();\n }\n handles.set(path, handle);\n },\n removeRemoteEntry: async (handles: any, path: string) => {\n const parentDirHandle = handles.get(PATH.dirname(path));\n await parentDirHandle.removeEntry(PATH.basename(path));\n handles.delete(path);\n },\n reconcile: async (mount: any, src: any, dst: any) => {\n let total = 0;\n\n const create: Array<string> = [];\n Object.keys(src.entries).forEach(function (key) {\n const e = src.entries[key];\n const e2 = dst.entries[key];\n if (\n !e2 ||\n (FS.isFile(e.mode) &&\n e[\"timestamp\"].getTime() > e2[\"timestamp\"].getTime())\n ) {\n create.push(key);\n total++;\n }\n });\n // sort paths in ascending order so directory entries are created\n // before the files inside them\n create.sort();\n\n const remove: Array<string> = [];\n Object.keys(dst.entries).forEach(function (key) {\n if (!src.entries[key]) {\n remove.push(key);\n total++;\n }\n });\n // sort paths in descending order so files are deleted before their\n // parent directories\n remove.sort().reverse();\n\n if (!total) {\n return;\n }\n\n const handles = src.type === \"remote\" ? src.handles : dst.handles;\n\n for (const path of create) {\n const relPath = PATH.normalize(\n path.replace(mount.mountpoint, \"/\"),\n ).substring(1);\n if (dst.type === \"local\") {\n const handle = handles.get(relPath);\n const entry = await nativeFSAsync.loadRemoteEntry(handle);\n nativeFSAsync.storeLocalEntry(path, entry);\n } else {\n const entry = nativeFSAsync.loadLocalEntry(path);\n await nativeFSAsync.storeRemoteEntry(handles, relPath, entry);\n }\n }\n\n for (const path of remove) {\n if (dst.type === \"local\") {\n nativeFSAsync.removeLocalEntry(path);\n } else {\n const relPath = PATH.normalize(\n path.replace(mount.mountpoint, \"/\"),\n ).substring(1);\n await nativeFSAsync.removeRemoteEntry(handles, relPath);\n }\n }\n },\n };\n\n module.FS.filesystems.NATIVEFS_ASYNC = nativeFSAsync;\n}\n\nconst getFsHandles = async (dirHandle: any) => {\n const handles: any = [];\n\n async function collect(curDirHandle: any) {\n for await (const entry of curDirHandle.values()) {\n handles.push(entry);\n if (entry.kind === \"directory\") {\n await collect(entry);\n }\n }\n }\n\n await collect(dirHandle);\n\n const result = new Map();\n result.set(\".\", dirHandle);\n for (const handle of handles) {\n const relativePath = (await dirHandle.resolve(handle)).join(\"/\");\n result.set(relativePath, handle);\n }\n return result;\n};\n", "/** @private */\n\nimport { ConfigType } from \"./pyodide\";\nimport { initializeNativeFS } from \"./nativefs\";\nimport { loadBinaryFile, getBinaryResponse } from \"./compat\";\nimport { API, PreRunFunc } from \"./types\";\n\n/**\n * @private\n * @hidden\n */\nexport interface EmscriptenSettings {\n readonly noImageDecoding?: boolean;\n readonly noAudioDecoding?: boolean;\n readonly noWasmDecoding?: boolean;\n readonly preRun: readonly PreRunFunc[];\n readonly quit: (status: number, toThrow: Error) => void;\n readonly print?: (a: string) => void;\n readonly printErr?: (a: string) => void;\n readonly onExit?: (code: number) => void;\n readonly thisProgram?: string;\n readonly arguments: readonly string[];\n readonly instantiateWasm?: (\n imports: { [key: string]: any },\n successCallback: (\n instance: WebAssembly.Instance,\n module: WebAssembly.Module,\n ) => void,\n ) => void;\n readonly API: API;\n readonly locateFile: (file: string) => string;\n\n exited?: { readonly status: number; readonly toThrow: Error };\n noInitialRun?: boolean;\n INITIAL_MEMORY?: number;\n}\n\n/**\n * Get the base settings to use to load Pyodide.\n *\n * @private\n */\nexport function createSettings(config: ConfigType): EmscriptenSettings {\n const settings: EmscriptenSettings = {\n noImageDecoding: true,\n noAudioDecoding: true,\n noWasmDecoding: false,\n preRun: getFileSystemInitializationFuncs(config),\n quit(status: number, toThrow: Error) {\n // It's a little bit hacky that we set this on the settings object but\n // it's not that easy to get access to the Module object from here.\n settings.exited = { status, toThrow };\n throw toThrow;\n },\n print: config.stdout,\n printErr: config.stderr,\n thisProgram: config._sysExecutable,\n arguments: config.args,\n API: { config } as API,\n // Emscripten calls locateFile exactly one time with argument\n // pyodide.asm.wasm to get the URL it should download it from.\n //\n // If we set instantiateWasm the return value of locateFile actually is\n // unused, but Emscripten calls it anyways. We set instantiateWasm except\n // when compiling with source maps, see comment in getInstantiateWasmFunc().\n //\n // It also is called when Emscripten tries to find a dependency of a shared\n // library but it failed to find it in the file system. But for us that\n // means dependency resolution has already failed and we want to throw an\n // error anyways.\n locateFile: (path: string) => config.indexURL + path,\n instantiateWasm: getInstantiateWasmFunc(config.indexURL),\n };\n return settings;\n}\n\n/**\n * Make the home directory inside the virtual file system,\n * then change the working directory to it.\n *\n * @param Module The Emscripten Module.\n * @param path The path to the home directory.\n * @private\n */\nfunction createHomeDirectory(path: string): PreRunFunc {\n return function (Module) {\n const fallbackPath = \"/\";\n try {\n Module.FS.mkdirTree(path);\n } catch (e) {\n console.error(`Error occurred while making a home directory '${path}':`);\n console.error(e);\n console.error(`Using '${fallbackPath}' for a home directory instead`);\n path = fallbackPath;\n }\n Module.FS.chdir(path);\n };\n}\n\nfunction setEnvironment(env: { [key: string]: string }): PreRunFunc {\n return function (Module) {\n Object.assign(Module.ENV, env);\n };\n}\n\n/**\n * Mount local directories to the virtual file system. Only for Node.js.\n * @param mounts The list of paths to mount.\n */\nfunction callFsInitHook(\n fsInit: undefined | ((fs: typeof FS, info: { sitePackages: string }) => void),\n): PreRunFunc[] {\n if (!fsInit) {\n return [];\n }\n return [\n async (Module) => {\n Module.addRunDependency(\"fsInitHook\");\n try {\n await fsInit(Module.FS, { sitePackages: Module.API.sitePackages });\n } finally {\n Module.removeRunDependency(\"fsInitHook\");\n }\n },\n ];\n}\n\n/**\n * Install the Python standard library to the virtual file system.\n *\n * Previously, this was handled by Emscripten's file packager (pyodide.asm.data).\n * However, using the file packager means that we have only one version\n * of the standard library available. We want to be able to use different\n * versions of the standard library, for example:\n *\n * - Use compiled(.pyc) or uncompiled(.py) standard library.\n * - Remove unused modules or add additional modules using bundlers like pyodide-pack.\n *\n * @param stdlibURL The URL for the Python standard library\n */\nfunction installStdlib(stdlibURL: string): PreRunFunc {\n const stdlibPromise: Promise<Uint8Array> = loadBinaryFile(stdlibURL);\n return async (Module) => {\n /* @ts-ignore */\n const pymajor = Module._py_version_major();\n /* @ts-ignore */\n const pyminor = Module._py_version_minor();\n Module.FS.mkdirTree(\"/lib\");\n Module.API.sitePackages = `/lib/python${pymajor}.${pyminor}/site-packages`;\n Module.FS.mkdirTree(Module.API.sitePackages);\n Module.addRunDependency(\"install-stdlib\");\n\n try {\n const stdlib = await stdlibPromise;\n Module.FS.writeFile(`/lib/python${pymajor}${pyminor}.zip`, stdlib);\n } catch (e) {\n console.error(\"Error occurred while installing the standard library:\");\n console.error(e);\n } finally {\n Module.removeRunDependency(\"install-stdlib\");\n }\n };\n}\n\n/**\n * Initialize the virtual file system, before loading Python interpreter.\n * @private\n */\nfunction getFileSystemInitializationFuncs(config: ConfigType): PreRunFunc[] {\n let stdLibURL;\n if (config.stdLibURL != undefined) {\n stdLibURL = config.stdLibURL;\n } else {\n stdLibURL = config.indexURL + \"python_stdlib.zip\";\n }\n\n // Note: Hooks are called in **reverse** order of appearance.\n return [\n ...callFsInitHook(config.fsInit),\n installStdlib(stdLibURL),\n createHomeDirectory(config.env.HOME),\n setEnvironment(config.env),\n initializeNativeFS,\n ];\n}\n\nfunction getInstantiateWasmFunc(\n indexURL: string,\n): EmscriptenSettings[\"instantiateWasm\"] {\n // @ts-ignore\n if (SOURCEMAP || typeof WasmOffsetConverter !== \"undefined\") {\n // According to the docs:\n //\n // \"Sanitizers or source map is currently not supported if overriding\n // WebAssembly instantiation with Module.instantiateWasm.\"\n // https://emscripten.org/docs/api_reference/module.html?highlight=instantiatewasm#Module.instantiateWasm\n //\n // typeof WasmOffsetConverter !== \"undefined\" checks for asan.\n return;\n }\n const { binary, response } = getBinaryResponse(indexURL + \"pyodide.asm.wasm\");\n return function (\n imports: { [key: string]: any },\n successCallback: (\n instance: WebAssembly.Instance,\n module: WebAssembly.Module,\n ) => void,\n ) {\n (async function () {\n try {\n let res: WebAssembly.WebAssemblyInstantiatedSource;\n if (response) {\n res = await WebAssembly.instantiateStreaming(response, imports);\n } else {\n res = await WebAssembly.instantiate(await binary, imports);\n }\n const { instance, module } = res;\n successCallback(instance, module);\n } catch (e) {\n console.warn(\"wasm instantiation failed!\");\n console.warn(e);\n }\n })();\n\n return {}; // Compiling asynchronously, no exports.\n };\n}\n", "/**\n *\n * The Pyodide version.\n *\n * The version here is a Python version, following :pep:`440`. This is different\n * from the version in ``package.json`` which follows the node package manager\n * version convention.\n */\nexport const version: string = \"0.27.5\";\n", "/**\n * The main bootstrap code for loading pyodide.\n */\nimport {\n calculateDirname,\n loadScript,\n initNodeModules,\n resolvePath,\n loadLockFile,\n} from \"./compat\";\n\nimport { createSettings } from \"./emscripten-settings\";\nimport { version } from \"./version\";\n\nimport type { PyodideInterface } from \"./api.js\";\nimport type { TypedArray, Module, PackageData, FSType } from \"./types\";\nimport type { EmscriptenSettings } from \"./emscripten-settings\";\nimport type { SnapshotConfig } from \"./snapshot\";\nexport type { PyodideInterface, TypedArray };\n\nexport { version, type PackageData };\n\ndeclare function _createPyodideModule(\n settings: EmscriptenSettings,\n): Promise<Module>;\n\n// BUILD_ID is generated from hashing together pyodide.asm.js and\n// pyodide.asm.wasm in esbuild.config.outer.mjs\n//\n// It is used to check that memory snapshots were generated by the same build of\n// the runtime that is trying to use them. Attempting to use a snapshot from a\n// different build will fail badly. See logic in snapshot.ts.\ndeclare const BUILD_ID: string;\n\n/**\n * See documentation for loadPyodide.\n * @hidden\n */\nexport type ConfigType = {\n indexURL: string;\n packageCacheDir: string;\n lockFileURL: string;\n fullStdLib?: boolean;\n stdLibURL?: string;\n stdin?: () => string;\n stdout?: (msg: string) => void;\n stderr?: (msg: string) => void;\n jsglobals?: object;\n _sysExecutable?: string;\n args: string[];\n fsInit?: (FS: FSType, info: { sitePackages: string }) => Promise<void>;\n env: { [key: string]: string };\n packages: string[];\n _makeSnapshot: boolean;\n enableRunUntilComplete: boolean;\n checkAPIVersion: boolean;\n BUILD_ID: string;\n};\n\n/**\n * Load the main Pyodide wasm module and initialize it.\n *\n * @returns The :ref:`js-api-pyodide` module.\n * @example\n * async function main() {\n * const pyodide = await loadPyodide({\n * fullStdLib: true,\n * stdout: (msg) => console.log(`Pyodide: ${msg}`),\n * });\n * console.log(\"Loaded Pyodide\");\n * }\n * main();\n */\nexport async function loadPyodide(\n options: {\n /**\n * The URL from which Pyodide will load the main Pyodide runtime and\n * packages. It is recommended that you leave this unchanged, providing an\n * incorrect value can cause broken behavior.\n *\n * Default: The url that Pyodide is loaded from with the file name\n * (``pyodide.js`` or ``pyodide.mjs``) removed.\n */\n indexURL?: string;\n\n /**\n * The file path where packages will be cached in node. If a package\n * exists in ``packageCacheDir`` it is loaded from there, otherwise it is\n * downloaded from the JsDelivr CDN and then cached into ``packageCacheDir``.\n * Only applies when running in node; ignored in browsers.\n *\n * Default: same as indexURL\n */\n packageCacheDir?: string;\n\n /**\n * The URL from which Pyodide will load the Pyodide ``pyodide-lock.json`` lock\n * file. You can produce custom lock files with :py:func:`micropip.freeze`.\n * Default: ```${indexURL}/pyodide-lock.json```\n */\n lockFileURL?: string;\n /**\n * Load the full Python standard library. Setting this to false excludes\n * unvendored modules from the standard library.\n * Default: ``false``\n */\n fullStdLib?: boolean;\n /**\n * The URL from which to load the standard library ``python_stdlib.zip``\n * file. This URL includes the most of the Python standard library. Some\n * stdlib modules were unvendored, and can be loaded separately\n * with ``fullStdLib: true`` option or by their package name.\n * Default: ```${indexURL}/python_stdlib.zip```\n */\n stdLibURL?: string;\n /**\n * Override the standard input callback. Should ask the user for one line of\n * input. The :js:func:`pyodide.setStdin` function is more flexible and\n * should be preferred.\n */\n stdin?: () => string;\n /**\n * Override the standard output callback. The :js:func:`pyodide.setStdout`\n * function is more flexible and should be preferred in most cases, but\n * depending on the ``args`` passed to ``loadPyodide``, Pyodide may write to\n * stdout on startup, which can only be controlled by passing a custom\n * ``stdout`` function.\n */\n stdout?: (msg: string) => void;\n /**\n * Override the standard error output callback. The\n * :js:func:`pyodide.setStderr` function is more flexible and should be\n * preferred in most cases, but depending on the ``args`` passed to\n * ``loadPyodide``, Pyodide may write to stdout on startup, which can only\n * be controlled by passing a custom ``stdout`` function.\n */\n stderr?: (msg: string) => void;\n /**\n * The object that Pyodide will use for the ``js`` module.\n * Default: ``globalThis``\n */\n jsglobals?: object;\n /**\n * Determine the value of ``sys.executable``.\n * @ignore\n */\n _sysExecutable?: string;\n /**\n * Command line arguments to pass to Python on startup. See `Python command\n * line interface options\n * <https://docs.python.org/3.10/using/cmdline.html#interface-options>`_ for\n * more details. Default: ``[]``\n */\n args?: string[];\n /**\n * Environment variables to pass to Python. This can be accessed inside of\n * Python at runtime via :py:data:`os.environ`. Certain environment variables change\n * the way that Python loads:\n * https://docs.python.org/3.10/using/cmdline.html#environment-variables\n * Default: ``{}``.\n * If ``env.HOME`` is undefined, it will be set to a default value of\n * ``\"/home/pyodide\"``\n */\n env?: { [key: string]: string };\n /**\n * A list of packages to load as Pyodide is initializing.\n *\n * This is the same as loading the packages with\n * :js:func:`pyodide.loadPackage` after Pyodide is loaded except using the\n * ``packages`` option is more efficient because the packages are downloaded\n * while Pyodide bootstraps itself.\n */\n packages?: string[];\n /**\n * Opt into the old behavior where :js:func:`PyProxy.toString() <pyodide.ffi.PyProxy.toString>`\n * calls :py:func:`repr` and not :py:class:`str() <str>`.\n * @deprecated\n */\n pyproxyToStringRepr?: boolean;\n /**\n * Make loop.run_until_complete() function correctly using stack switching\n */\n enableRunUntilComplete?: boolean;\n /**\n * If true (default), throw an error if the version of Pyodide core does not\n * match the version of the Pyodide js package.\n */\n checkAPIVersion?: boolean;\n /**\n * This is a hook that allows modification of the file system before the\n * main() function is called and the intereter is started. When this is\n * called, it is guaranteed that there is an empty site-packages directory.\n * @experimental\n */\n fsInit?: (FS: FSType, info: { sitePackages: string }) => Promise<void>;\n /** @ignore */\n _makeSnapshot?: boolean;\n /** @ignore */\n _loadSnapshot?:\n | Uint8Array\n | ArrayBuffer\n | PromiseLike<Uint8Array | ArrayBuffer>;\n /** @ignore */\n _snapshotDeserializer?: (obj: any) => any;\n } = {},\n): Promise<PyodideInterface> {\n await initNodeModules();\n let indexURL = options.indexURL || (await calculateDirname());\n indexURL = resolvePath(indexURL); // A relative indexURL causes havoc.\n if (!indexURL.endsWith(\"/\")) {\n indexURL += \"/\";\n }\n options.indexURL = indexURL;\n\n const default_config = {\n fullStdLib: false,\n jsglobals: globalThis,\n stdin: globalThis.prompt ? globalThis.prompt : undefined,\n lockFileURL: indexURL + \"pyodide-lock.json\",\n args: [],\n env: {},\n packageCacheDir: indexURL,\n packages: [],\n enableRunUntilComplete: false,\n checkAPIVersion: true,\n BUILD_ID,\n };\n const config = Object.assign(default_config, options) as ConfigType;\n config.env.HOME ??= \"/home/pyodide\";\n /**\n * `PyErr_Print()` will call `exit()` if the exception is a `SystemError`.\n * This shuts down the Python interpreter, which is a change in behavior from\n * what happened before. In order to avoid this, we set the `inspect` config\n * parameter which prevents `PyErr_Print()` from calling `exit()`. Except in\n * the cli runner, we actually do want to exit. So set default to true and in\n * cli runner we explicitly set it to false.\n */\n config.env.PYTHONINSPECT ??= \"1\";\n const emscriptenSettings = createSettings(config);\n const API = emscriptenSettings.API;\n API.lockFilePromise = loadLockFile(config.lockFileURL);\n\n // If the pyodide.asm.js script has been imported, we can skip the dynamic import\n // Users can then do a static import of the script in environments where\n // dynamic importing is not allowed or not desirable, like module-type service workers\n if (typeof _createPyodideModule !== \"function\") {\n const scriptSrc = `${config.indexURL}pyodide.asm.js`;\n await loadScript(scriptSrc);\n }\n\n let snapshot: Uint8Array | undefined = undefined;\n if (options._loadSnapshot) {\n const snp = await options._loadSnapshot;\n if (ArrayBuffer.isView(snp)) {\n snapshot = snp;\n } else {\n snapshot = new Uint8Array(snp);\n }\n emscriptenSettings.noInitialRun = true;\n // @ts-ignore\n emscriptenSettings.INITIAL_MEMORY = snapshot.length;\n }\n\n // _createPyodideModule is specified in the Makefile by the linker flag:\n // `-s EXPORT_NAME=\"'_createPyodideModule'\"`\n const Module = await _createPyodideModule(emscriptenSettings);\n // Handle early exit\n if (emscriptenSettings.exited) {\n throw emscriptenSettings.exited.toThrow;\n }\n if (options.pyproxyToStringRepr) {\n API.setPyProxyToStringMethod(true);\n }\n\n if (API.version !== version && config.checkAPIVersion) {\n throw new Error(`\\\nPyodide version does not match: '${version}' <==> '${API.version}'. \\\nIf you updated the Pyodide version, make sure you also updated the 'indexURL' parameter passed to loadPyodide.\\\n`);\n }\n // Disable further loading of Emscripten file_packager stuff.\n Module.locateFile = (path: string) => {\n throw new Error(\"Didn't expect to load any more file_packager files!\");\n };\n\n let snapshotConfig: SnapshotConfig | undefined = undefined;\n if (snapshot) {\n snapshotConfig = API.restoreSnapshot(snapshot);\n }\n // runPython works starting after the call to finalizeBootstrap.\n const pyodide = API.finalizeBootstrap(\n snapshotConfig,\n options._sn