Skip to content

Commit

Permalink
allow emitting .d.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Officeyutong committed Jan 6, 2025
1 parent 16e5786 commit e06168f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 13 deletions.
7 changes: 5 additions & 2 deletions light-client-js/esbuild.config.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import * as esbuild from 'esbuild'
import inlineWorkerPlugin from 'esbuild-plugin-inline-worker';
import { polyfillNode } from "esbuild-plugin-polyfill-node";
import { dtsPlugin } from "esbuild-plugin-d.ts";
import fs from "node:fs/promises";
const tsconfig = JSON.parse(await fs.readFile("./tsconfig.json"));
const profile = process.env.PROFILE;

await esbuild.build({
entryPoints: ["./src/index.ts"],
bundle: true,
outdir: "dist",
plugins: [polyfillNode(), inlineWorkerPlugin({
})],
plugins: [polyfillNode(), inlineWorkerPlugin(), dtsPlugin({ tsconfig })],
target: [
"esnext"
],
Expand Down
1 change: 1 addition & 0 deletions light-client-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@jest/globals": "^29.7.0",
"@types/jest": "^29.5.14",
"esbuild": "0.24.2",
"esbuild-plugin-d.ts": "^1.3.1",
"esbuild-plugin-inline-worker": "^0.1.1",
"esbuild-plugin-polyfill-node": "^0.3.0",
"jest": "^29.7.0",
Expand Down
4 changes: 1 addition & 3 deletions light-client-js/src/db.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ onerror = event => {
}

onmessage = async (evt) => {
// const wasmModule = (await import("light-client-db-worker")).default;

const data = evt.data as DbWorkerInitializeOptions;
wasmModule.set_shared_array(data.inputBuffer, data.outputBuffer);
self.postMessage({});
await wasmModule.main_loop(data.logLevel);
}

export {};
export default {} as typeof Worker & { new(): Worker };
3 changes: 1 addition & 2 deletions light-client-js/src/lightclient.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ onerror = err => {
}
let loaded = false;
onmessage = async (evt) => {
// const wasmModule = (await import("light-client-wasm")).default;
if (!loaded) {
const data = evt.data as LightClientWorkerInitializeOptions;
wasmModule.set_shared_array(data.inputBuffer, data.outputBuffer);
Expand All @@ -31,4 +30,4 @@ onmessage = async (evt) => {
}
};

export { };
export default {} as typeof Worker & { new(): Worker };
15 changes: 11 additions & 4 deletions light-client-js/src/worker.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
declare module "*.worker.ts" {
class WebpackWorker extends Worker {
constructor();
}
export default WebpackWorker;
class WebpackWorker extends Worker {
constructor();
}
export default WebpackWorker;
}

declare module "*.worker" {
class WebpackWorker extends Worker {
constructor();
}
export default WebpackWorker;
}
7 changes: 5 additions & 2 deletions light-client-js/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@
"WebWorker",
"ESNext"
],
"moduleResolution": "bundler"
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"emitDeclarationOnly": true
},
"exclude": [
"webpack.config.js",
"dist/**",
"node_modules/**",
"jest.config.js"
"jest.config.js",
"esbuild.config.*"
]
}

0 comments on commit e06168f

Please sign in to comment.