Skip to content

Commit 9415036

Browse files
committed
fix: remove dependence on bindings COMPASS-10561
1 parent 8b930f3 commit 9415036

5 files changed

Lines changed: 42 additions & 17 deletions

File tree

package.json

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"lint": "eslint {src,test}/**/*.ts",
1515
"test": "npm run lint && npm run build && nyc npm run test-only",
1616
"test-nolint": "npm run build && npm run test-only",
17-
"test-only": "mocha --colors -r ts-node/register test/*.ts",
17+
"test-only": "NODE_OPTIONS=--experimental-strip-types mocha --colors test/*.ts",
1818
"build": "node-gyp rebuild && npm run compile-ts && gen-esm-wrapper . ./.esm-wrapper.mjs",
1919
"prepack": "npm run build",
2020
"compile-ts": "tsc -p tsconfig.json"
@@ -35,8 +35,8 @@
3535
},
3636
"license": "Apache-2.0",
3737
"devDependencies": {
38-
"@types/mocha": "^8.0.3",
39-
"@types/node": "^14.11.1",
38+
"@types/mocha": "^10.0.10",
39+
"@types/node": "^25.5.2",
4040
"@typescript-eslint/eslint-plugin": "^4.2.0",
4141
"@typescript-eslint/parser": "^4.2.0",
4242
"eslint": "^7.9.0",
@@ -47,13 +47,8 @@
4747
"eslint-plugin-promise": "^4.2.1",
4848
"eslint-plugin-standard": "^4.0.1",
4949
"gen-esm-wrapper": "^1.1.0",
50-
"mocha": "^8.1.3",
51-
"node-fetch": "^2.6.1",
50+
"mocha": "^11.7.5",
5251
"nyc": "^15.1.0",
53-
"ts-node": "^9.0.0",
54-
"typescript": "^4.0.3"
55-
},
56-
"dependencies": {
57-
"bindings": "^1.5.0"
52+
"typescript": "^6.0.2"
5853
}
5954
}

src/index.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
1-
import bindings from 'bindings';
2-
const native = bindings('interruptor');
1+
function load() {
2+
try {
3+
return require('../build/Release/interruptor.node');
4+
} catch {
5+
// Webpack will fail when just returning the require, so we need to wrap in a try/catch and rethrow.
6+
/* eslint no-useless-catch: 0 */
7+
try {
8+
return require('../build/Debug/interruptor.node');
9+
} catch (error) {
10+
throw error;
11+
}
12+
}
13+
}
14+
15+
const native = load();
16+
317
export type InterruptHandle = { __id: number };
418

519
export function runInterruptible<Ret>(

test/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import assert from 'assert';
22
import { Worker } from 'worker_threads';
3-
import { runInterruptible, interrupt, InterruptHandle } from '../';
3+
import { createRequire } from 'module';
4+
import { runInterruptible, interrupt, type InterruptHandle } from '../lib/index.js';
5+
6+
const require = createRequire(import.meta.url);
47

58
describe('runInterruptible', () => {
69
it('can interrupt itself', () => {

test/tsconfig.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"rootDir": "../",
5+
"module": "nodenext",
6+
"noEmit": true,
7+
"erasableSyntaxOnly": true,
8+
"types": ["node", "mocha"]
9+
},
10+
"include": [
11+
"./**/*.ts"
12+
]
13+
}

tsconfig.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
22
"compilerOptions": {
33
"esModuleInterop": true,
4-
"downlevelIteration": true,
54
"sourceMap": true,
65
"strictNullChecks": false,
76
"declaration": true,
87
"removeComments": true,
9-
"target": "es2019",
10-
"lib": ["es2019"],
8+
"target": "es2025",
9+
"erasableSyntaxOnly": true,
10+
"types": ["node"],
11+
"rootDir": "./src",
1112
"outDir": "./lib",
12-
"moduleResolution": "node",
1313
"module": "commonjs"
1414
},
1515
"include": [

0 commit comments

Comments
 (0)