Skip to content

Commit 1ba55fa

Browse files
OttoAllmendingerllm-git
andcommitted
feat(wasm-utxo): improve ESM compatibility
Configure ESLint to prevent Node.js globals in production code and replace Buffer with Uint8Array in tests. Split tsconfig files to separate test and production code configuration. Issue: BTC-2866 Co-authored-by: llm-git <llm-git@ttll.de>
1 parent 3735b84 commit 1ba55fa

5 files changed

Lines changed: 40 additions & 7 deletions

File tree

packages/wasm-utxo/eslint.config.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default tseslint.config(
77
{
88
languageOptions: {
99
parserOptions: {
10-
projectService: true,
10+
project: ["./tsconfig.json", "./tsconfig.test.json"],
1111
tsconfigRootDir: import.meta.dirname,
1212
},
1313
},
@@ -25,4 +25,29 @@ export default tseslint.config(
2525
"*.config.js",
2626
],
2727
},
28+
// Ban Node.js globals in production code
29+
{
30+
files: ["js/**/*.ts"],
31+
rules: {
32+
"no-restricted-globals": [
33+
"error",
34+
{
35+
name: "Buffer",
36+
message: "Use Uint8Array instead of Buffer for ESM compatibility.",
37+
},
38+
{
39+
name: "process",
40+
message: "Avoid Node.js process global for ESM compatibility.",
41+
},
42+
{
43+
name: "__dirname",
44+
message: "Use import.meta.url instead of __dirname for ESM.",
45+
},
46+
{
47+
name: "__filename",
48+
message: "Use import.meta.url instead of __filename for ESM.",
49+
},
50+
],
51+
},
52+
},
2853
);

packages/wasm-utxo/test/descriptorWallet/address.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe("descriptorWallet/address", () => {
1919
const descriptor = Descriptor.fromStringDetectType(definiteDescriptor);
2020
const script = createScriptPubKeyFromDescriptor(descriptor, undefined);
2121

22-
assert.ok(Buffer.isBuffer(script));
22+
assert.ok(script instanceof Uint8Array);
2323
// P2WPKH scripts are 22 bytes (OP_0 + 20 byte hash)
2424
assert.strictEqual(script.length, 22);
2525
assert.strictEqual(script[0], 0x00); // OP_0
@@ -30,7 +30,7 @@ describe("descriptorWallet/address", () => {
3030
const descriptor = Descriptor.fromStringDetectType(derivableDescriptor);
3131
const script = createScriptPubKeyFromDescriptor(descriptor, 0);
3232

33-
assert.ok(Buffer.isBuffer(script));
33+
assert.ok(script instanceof Uint8Array);
3434
assert.strictEqual(script.length, 22);
3535
});
3636

packages/wasm-utxo/tsconfig.cjs.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@
55
"moduleResolution": "node",
66
"rootDir": ".",
77
"outDir": "./dist/cjs"
8-
},
9-
"exclude": ["test/**/*"]
8+
}
109
}

packages/wasm-utxo/tsconfig.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
"rootDir": ".",
1212
"outDir": "./dist/esm",
1313
"noUnusedLocals": true,
14-
"noUnusedParameters": true
14+
"noUnusedParameters": true,
15+
"types": []
1516
},
16-
"include": ["./js/**/*.ts", "test/**/*.ts"],
17+
"include": ["./js/**/*.ts"],
1718
"exclude": ["node_modules", "./js/wasm/**/*"]
1819
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"types": ["node", "mocha"],
5+
"noEmit": true
6+
},
7+
"include": ["./js/**/*.ts", "test/**/*.ts"]
8+
}

0 commit comments

Comments
 (0)