mirror of https://github.com/pyodide/pyodide.git
48 lines
1.9 KiB
Diff
48 lines
1.9 KiB
Diff
commit fb4b3c3a955e73fe20f930fb73588c0ad7a446e5
|
|
Author: Sam Clegg <sbc@chromium.org>
|
|
Date: Thu Jun 3 09:42:51 2021 -0700
|
|
|
|
Add support for `--preload-file` in Node.js (#11785)
|
|
|
|
Note: this is included in emscripten 2.O.24
|
|
|
|
diff --git a/emsdk/upstream/emscripten/tools/file_packager.py b/emsdk/upstream/emscripten/tools/file_packager.py
|
|
index cd70b4b7d..ace6d6b2c 100755
|
|
--- a/emsdk/upstream/emscripten/tools/file_packager.py
|
|
+++ b/emsdk/upstream/emscripten/tools/file_packager.py
|
|
@@ -525,14 +525,12 @@ def main():
|
|
remote_package_size = os.path.getsize(package_name)
|
|
remote_package_name = os.path.basename(package_name)
|
|
ret += r'''
|
|
- var PACKAGE_PATH;
|
|
+ var PACKAGE_PATH = '';
|
|
if (typeof window === 'object') {
|
|
PACKAGE_PATH = window['encodeURIComponent'](window.location.pathname.toString().substring(0, window.location.pathname.toString().lastIndexOf('/')) + '/');
|
|
- } else if (typeof location !== 'undefined') {
|
|
- // worker
|
|
+ } else if (typeof process === 'undefined' && typeof location !== 'undefined') {
|
|
+ // web worker
|
|
PACKAGE_PATH = encodeURIComponent(location.pathname.toString().substring(0, location.pathname.toString().lastIndexOf('/')) + '/');
|
|
- } else {
|
|
- throw 'using preloaded data can only be done on a web page or in a web worker';
|
|
}
|
|
var PACKAGE_NAME = '%s';
|
|
var REMOTE_PACKAGE_BASE = '%s';
|
|
@@ -716,6 +714,16 @@ def main():
|
|
|
|
ret += r'''
|
|
function fetchRemotePackage(packageName, packageSize, callback, errback) {
|
|
+ if (typeof process === 'object') {
|
|
+ require('fs').readFile(packageName, function(err, contents) {
|
|
+ if (err) {
|
|
+ errback(err);
|
|
+ } else {
|
|
+ callback(contents.buffer);
|
|
+ }
|
|
+ });
|
|
+ return;
|
|
+ }
|
|
var xhr = new XMLHttpRequest();
|
|
xhr.open('GET', packageName, true);
|
|
xhr.responseType = 'arraybuffer';
|