mirror of
https://github.com/acamarata/solar-spa.git
synced 2026-06-30 19:04:28 +00:00
Rebuilt WASM for web and node envs
This commit is contained in:
parent
9fc46f0784
commit
cc8b0299b2
5 changed files with 3 additions and 21 deletions
BIN
.DS_Store
vendored
Normal file
BIN
.DS_Store
vendored
Normal file
Binary file not shown.
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "solar-spa",
|
||||
"version": "1.2.0",
|
||||
"version": "1.2.1",
|
||||
"description": "NREL Solar Position Algorithm (SPA) in WebAssembly",
|
||||
"main": "solar-spa.js",
|
||||
"types": "index.d.ts",
|
||||
|
|
|
|||
|
|
@ -1,12 +1,5 @@
|
|||
// solar-spa.js
|
||||
const spaModule = require('./spa.js');
|
||||
const spaBase64 = require('./spa_base64.js'); // Import the Base64-encoded WASM
|
||||
|
||||
// Convert the Base64-encoded string back to a Uint8Array for use with WebAssembly
|
||||
const wasmBinary = new Uint8Array(Buffer.from(spaBase64, 'base64'));
|
||||
|
||||
// Use the wasmBinary directly instead of loading it from the file system
|
||||
spaModule.wasmBinary = wasmBinary;
|
||||
|
||||
module.exports = function spa(
|
||||
date,
|
||||
|
|
|
|||
13
spa.js
13
spa.js
|
|
@ -326,6 +326,8 @@ var PROXYFS = 'PROXYFS is no longer included by default; build with -lproxyfs.js
|
|||
var WORKERFS = 'WORKERFS is no longer included by default; build with -lworkerfs.js';
|
||||
var NODEFS = 'NODEFS is no longer included by default; build with -lnodefs.js';
|
||||
|
||||
assert(!ENVIRONMENT_IS_WORKER, "worker environment detected but not enabled at build time. Add 'worker' to `-sENVIRONMENT` to enable.");
|
||||
|
||||
assert(!ENVIRONMENT_IS_SHELL, "shell environment detected but not enabled at build time. Add 'shell' to `-sENVIRONMENT` to enable.");
|
||||
|
||||
|
||||
|
|
@ -949,7 +951,6 @@ function getBinaryPromise(binaryFile) {
|
|||
// So use fetch if it is available and the url is not a file, otherwise fall back to XHR.
|
||||
if (!wasmBinary && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER)) {
|
||||
if (typeof fetch == 'function'
|
||||
&& !isFileURI(binaryFile)
|
||||
) {
|
||||
return fetch(binaryFile, { credentials: 'same-origin' }).then(function(response) {
|
||||
if (!response['ok']) {
|
||||
|
|
@ -960,14 +961,6 @@ function getBinaryPromise(binaryFile) {
|
|||
return getBinary(binaryFile);
|
||||
});
|
||||
}
|
||||
else {
|
||||
if (readAsync) {
|
||||
// fetch is not available or url is file => try XHR (readAsync uses XHR internally)
|
||||
return new Promise(function(resolve, reject) {
|
||||
readAsync(binaryFile, function(response) { resolve(new Uint8Array(/** @type{!ArrayBuffer} */(response))) }, reject)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, getBinary should be able to get it synchronously
|
||||
|
|
@ -994,8 +987,6 @@ function instantiateAsync(binary, binaryFile, imports, callback) {
|
|||
if (!binary &&
|
||||
typeof WebAssembly.instantiateStreaming == 'function' &&
|
||||
!isDataURI(binaryFile) &&
|
||||
// Don't use streaming for file:// delivered objects in a webview, fetch them synchronously.
|
||||
!isFileURI(binaryFile) &&
|
||||
// Avoid instantiateStreaming() on Node.js environment for now, as while
|
||||
// Node.js v18.1.0 implements it, it does not have a full fetch()
|
||||
// implementation yet.
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue