diff --git a/index.browser.js b/index.browser.js index d24f973..882a97a 100644 --- a/index.browser.js +++ b/index.browser.js @@ -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; \ No newline at end of file +module.exports.BrotliWasmType = undefined; + +module.exports.init = (_) => { + return globalThis.Promise.resolve(); +} diff --git a/index.d.ts b/index.d.ts index b7f946d..ab60b92 100644 --- a/index.d.ts +++ b/index.d.ts @@ -6,4 +6,21 @@ export * from './pkg.node/brotli_wasm'; declare const promisedValue: Promise; export default promisedValue; -export type BrotliWasmType = typeof BrotliWasm; \ No newline at end of file +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} module_or_path +* +* @returns {Promise} +*/ +export function init (module_or_path?: InitInput | Promise): Promise; diff --git a/index.node.js b/index.node.js index cede0e8..2117a4d 100644 --- a/index.node.js +++ b/index.node.js @@ -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); \ No newline at end of file +module.exports.default = Promise.resolve(nodePkg); + +module.exports.init = (_) => { + return globalThis.Promise.resolve(); +} diff --git a/index.web.js b/index.web.js index e9ec741..f0fe5ad 100644 --- a/index.web.js +++ b/index.web.js @@ -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); \ No newline at end of file +export default init().then(() => brotliWasm); + +export { init }; diff --git a/package.json b/package.json index 5b23435..3d8377c 100644 --- a/package.json +++ b/package.json @@ -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,