Skip to content

Commit ba51992

Browse files
authored
Make locatefile configurable + missing exported types (emscripten-forge#47)
* Fix wasm import * Provide ability to pass custom locatefile
1 parent d24e59f commit ba51992

File tree

7 files changed

+270
-14
lines changed

7 files changed

+270
-14
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
run: |
4545
micromamba activate untarjs
4646
47-
yarn run build:prod
47+
yarn run build
4848
4949
- name: Run eslint
5050
run: |

RELEASE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ In order to make a new release:
55
- Commit the change with the message "Release x.x.x" on the `main` branch
66
- Create a tag `git tag x.x.x`
77
- Push the new commit and the tag `git push https://github.com/emscripten-forge/untarjs main x.x.x`
8-
- Build and publish `git clean -fdx && yarn && yarn run build:prod && npm publish`
8+
- Build and publish `git clean -fdx && yarn && yarn run build && npm publish`

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",
77
"scripts": {
8+
"build": "yarn run clean && tsc && yarn run build:wasm && copyfiles -u 1 \"src/**/*.d.ts\" lib",
89
"build:wasm": "node build_wasm.js",
910
"clean": "rimraf lib && rimraf tsconfig.tsbuildinfo",
10-
"build": "yarn run clean && tsc && yarn run build:wasm",
11-
"build:prod": "yarn run clean && tsc && yarn run build:wasm",
1211
"prettier": "prettier --list-different --write \"src/**/*.ts\"",
1312
"prettier:check": "prettier --check \"src/**/*.ts\"",
1413
"eslint": "eslint --ext .ts --fix .",
@@ -44,9 +43,11 @@
4443
},
4544
"devDependencies": {
4645
"@eslint/js": "^9.13.0",
46+
"@types/copyfiles": "^2",
4747
"@types/node": "^22.8.1",
4848
"@typescript-eslint/eslint-plugin": "~6.13.2",
4949
"@typescript-eslint/parser": "~6.13.2",
50+
"copyfiles": "^2.4.1",
5051
"eslint": "~8.55.0",
5152
"eslint-config-prettier": "~9.1.0",
5253
"eslint-plugin-prettier": "~5.0.1",

src/helper.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import unpack, { IWasmModule } from './unpack';
22
import unpackWasm from './unpack.wasm';
33

4-
const initializeWasm = async (): Promise<IWasmModule> => {
4+
const initializeWasm = async (locateWasm?: (file: string) => string): Promise<IWasmModule> => {
55
const wasmModule: IWasmModule = await unpack({
66
locateFile(path: string) {
77
if (path.endsWith('.wasm')) {
8+
if (locateWasm) {
9+
return locateWasm(path);
10+
}
811
return unpackWasm;
912
}
1013
return path;

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import initializeWasm from './helper';
22
import { FilesData, IUnpackJSAPI } from './types';
33

4-
const fetchByteArray = async (url: string): Promise<Uint8Array> => {
4+
export const fetchByteArray = async (url: string): Promise<Uint8Array> => {
55
const response = await fetch(url);
66
if (!response.ok) {
77
throw new Error(`HTTP error! status: ${response.status}`);
@@ -10,8 +10,8 @@ const fetchByteArray = async (url: string): Promise<Uint8Array> => {
1010
return new Uint8Array(arrayBuffer);
1111
};
1212

13-
export const initUntarJS = async (): Promise<IUnpackJSAPI> => {
14-
const wasmModule = await initializeWasm();
13+
export const initUntarJS = async (locateWasm?: (file: string) => string): Promise<IUnpackJSAPI> => {
14+
const wasmModule = await initializeWasm(locateWasm);
1515

1616
const extractData = async (
1717
data: Uint8Array,

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export type FilesData = { [filename: string]: Uint8Array };
22

33
export interface IUnpackJSAPI {
4-
extractData: (data: Uint8Array) => Promise<FilesData>;
4+
extractData: (data: Uint8Array, decompressionOnly?: boolean) => Promise<FilesData>;
55
extract: (url: string) => Promise<FilesData>;
66
}

0 commit comments

Comments
 (0)