Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion index.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ module.exports.default = module.exports;

// Without this, ts-loader gets annoyed by imports for the pure type. Clear ts-loader bug,
// but this is a quick & easy fix on our end:
module.exports.BrotliWasmType = undefined;
module.exports.BrotliWasmType = undefined;

module.exports.init = (_) => {
return globalThis.Promise.resolve();
}
19 changes: 18 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,21 @@ export * from './pkg.node/brotli_wasm';
declare const promisedValue: Promise<typeof BrotliWasm>;
export default promisedValue;

export type BrotliWasmType = typeof BrotliWasm;
export type BrotliWasmType = typeof BrotliWasm;

import type { InitInput, InitOutput } from './pkg.web/brotli_wasm';

/**
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
* for everything else, calls `WebAssembly.instantiate` directly.
*
* If this project's target is `cloudflare-workers`, you must use this.
* If you use web, this function will return a promise that resolves to the
* `BrotliWasm` module, which you can use directly.
* But if you use other targets, this function will return the void type.
*
* @param {InitInput | Promise<InitInput>} module_or_path
*
* @returns {Promise<InitOutput>}
*/
export function init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput | void>;
6 changes: 5 additions & 1 deletion index.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ const nodePkg = require('./pkg.node/brotli_wasm');
module.exports = nodePkg;

// In addition though, we provide a default export, to match the pure ESM web bundle:
module.exports.default = Promise.resolve(nodePkg);
module.exports.default = Promise.resolve(nodePkg);

module.exports.init = (_) => {
return globalThis.Promise.resolve();
}
4 changes: 3 additions & 1 deletion index.web.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
// For usage with an importmap, it's convenient to add the ".js" extension here, because browsers
// don't try to guess the file extension.
import init, * as brotliWasm from "./pkg.web/brotli_wasm.js";
export default init().then(() => brotliWasm);
export default init().then(() => brotliWasm);

export { init };
18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@
"browser": "./index.browser.js",
"require": "./index.node.js",
"default": "./index.web.js"
},
"./wasm": {
"import": {
"types": "./pkg.web/brotli_wasm_bg.wasm.d.ts",
"default": "./pkg.web/brotli_wasm_bg.wasm"
},
"browser": {
"types": "./pkg.bundler/brotli_wasm_bg.wasm.d.ts",
"default": "./pkg.bundler/brotli_wasm_bg.wasm"
},
"require": {
"types": "./pkg.node/brotli_wasm_bg.wasm.d.ts",
"default": "./pkg.node/brotli_wasm_bg.wasm"
},
"default": {
"types": "./pkg.web/brotli_wasm_bg.wasm.d.ts",
"default": "./pkg.web/brotli_wasm_bg.wasm"
}
}
},
"sideEffects": false,
Expand Down
Loading