emsdk-env 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: emsdk-env
3
- * version: 0.9.0
3
+ * version: 0.10.0
4
4
  * description: Emscripten environment builder
5
5
  * author: Kouji Matsui (@kekyo@mi.kekyo.net)
6
6
  * license: MIT
7
7
  * repository.url: https://github.com/kekyo/emsdk-env
8
- * git.commit.hash: 73d7e217903f020ef22daa9289362dcd19bddac1
8
+ * git.commit.hash: 7ee173408d930a3cc7444806156538a24a617b55
9
9
  */
10
10
 
11
11
  import { mkdir, access, constants, mkdtemp, rename, rm, writeFile, readFile } from "fs/promises";
@@ -866,9 +866,7 @@ const buildGeneratedLoaderContent = (generatedLoaderFile, targets) => {
866
866
  options?: TargetWasmLoadOptions
867
867
  ): Promise<WasmInstance<T>> => {
868
868
  const source = options?.url ?? new URL(${specifier}, import.meta.url);
869
- return await loadWasm<T>(source, {
870
- imports: options?.imports,
871
- });
869
+ return await loadWasm<T>(source, createWasmLoadOptions(options?.imports));
872
870
  };`;
873
871
  }).join("\n\n");
874
872
  return `// Generated by emsdk-env. DO NOT EDIT.
@@ -888,6 +886,13 @@ export interface TargetWasmLoadOptions extends WasmLoadOptions {
888
886
  readonly url?: string | URL;
889
887
  }
890
888
 
889
+ const isResponse = (value: WasmSource): value is Response =>
890
+ typeof Response !== 'undefined' && value instanceof Response;
891
+
892
+ const createWasmLoadOptions = (
893
+ imports: WebAssembly.Imports | undefined
894
+ ): WasmLoadOptions | undefined => (imports ? { imports } : undefined);
895
+
891
896
  export interface WasmInstance<T extends object> {
892
897
  readonly exports: T;
893
898
  readonly memory: WebAssembly.Memory;
@@ -900,7 +905,7 @@ export interface WasmInstance<T extends object> {
900
905
  }
901
906
 
902
907
  const resolveWasmBytes = async (source: WasmSource): Promise<ArrayBuffer> => {
903
- if (typeof Response !== 'undefined' && source instanceof Response) {
908
+ if (isResponse(source)) {
904
909
  return await source.arrayBuffer();
905
910
  }
906
911
  if (source instanceof URL || typeof source === 'string') {
@@ -910,6 +915,9 @@ const resolveWasmBytes = async (source: WasmSource): Promise<ArrayBuffer> => {
910
915
  }
911
916
  return await response.arrayBuffer();
912
917
  }
918
+ if (source instanceof ArrayBuffer) {
919
+ return source;
920
+ }
913
921
  if (ArrayBuffer.isView(source)) {
914
922
  const view = new Uint8Array(
915
923
  source.buffer,
@@ -918,7 +926,7 @@ const resolveWasmBytes = async (source: WasmSource): Promise<ArrayBuffer> => {
918
926
  );
919
927
  return view.slice().buffer;
920
928
  }
921
- return source;
929
+ throw new TypeError('Unsupported wasm source.');
922
930
  };
923
931
 
924
932
  const getImportValue = (
@@ -1657,4 +1665,4 @@ export {
1657
1665
  createConsoleLogger as c,
1658
1666
  prepareEmsdk as p
1659
1667
  };
1660
- //# sourceMappingURL=build-BOZTStIM.js.map
1668
+ //# sourceMappingURL=build-BE9Z95iJ.js.map