Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove weak-napi support #13035

Merged
merged 2 commits into from
Jul 17, 2022
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Chore & Maintenance

- `[*]` [**BREAKING**] Drop support for Node v12 and v17 ([#13033](https://github.com/facebook/jest/pull/13033))
- `[jest-leak-detector]` Remove support for `weak-napi` ([#13035](https://github.com/facebook/jest/pull/13035))

### Performance

Expand Down
4 changes: 0 additions & 4 deletions packages/jest-leak-detector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
"jest-get-type": "^28.0.2",
"pretty-format": "^28.1.3"
},
"devDependencies": {
"@types/weak-napi": "^2.0.0",
"weak-napi": "^2.0.1"
},
"engines": {
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
},
Expand Down
34 changes: 5 additions & 29 deletions packages/jest-leak-detector/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,11 @@ export default class LeakDetector {
);
}

// TODO: Remove the `if` and `weak-napi` when we drop node 12, as v14 supports FinalizationRegistry
if (globalThis.FinalizationRegistry) {
// When `_finalizationRegistry` is GCed the callback we set will no longer be called,
// so we need to assign it to `this` to keep it referenced
this._finalizationRegistry = new FinalizationRegistry(() => {
this._isReferenceBeingHeld = false;
});

this._finalizationRegistry.register(value as object, undefined);
} else {
let weak: typeof import('weak-napi');

try {
// eslint-disable-next-line import/no-extraneous-dependencies
weak = require('weak-napi');
} catch (err: any) {
if (!err || err.code !== 'MODULE_NOT_FOUND') {
throw err;
}

throw new Error(
'The leaking detection mechanism requires newer version of node that supports ' +
'FinalizationRegistry, update your node or install the "weak-napi" package ' +
'which support current node version as a dependency on your main project.',
);
}

weak(value as object, () => (this._isReferenceBeingHeld = false));
}
// When `_finalizationRegistry` is GCed the callback we set will no longer be called,
this._finalizationRegistry = new FinalizationRegistry(() => {
this._isReferenceBeingHeld = false;
});
this._finalizationRegistry.register(value as object, undefined);

this._isReferenceBeingHeld = true;

Expand Down
69 changes: 0 additions & 69 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5591,15 +5591,6 @@ __metadata:
languageName: node
linkType: hard

"@types/weak-napi@npm:^2.0.0":
version: 2.0.0
resolution: "@types/weak-napi@npm:2.0.0"
dependencies:
"@types/node": "*"
checksum: 148b14ace8702cc1e639cfbaa5f17eaf98d571821e30e0c1ddb15c6d9f2a646d2677eabf6d0dd924b89e8c87aac4bc795f1d52a29abc170cb1cbfb4022ce4f48
languageName: node
linkType: hard

"@types/webidl-conversions@npm:*":
version: 6.1.1
resolution: "@types/webidl-conversions@npm:6.1.1"
Expand Down Expand Up @@ -11193,29 +11184,13 @@ __metadata:
languageName: node
linkType: hard

"get-symbol-from-current-process-h@npm:^1.0.1":
version: 1.0.2
resolution: "get-symbol-from-current-process-h@npm:1.0.2"
checksum: d47cc1b9e0be27469e2af0555b21aaa5ebd114e8aa25bb0e2616c8abaebb7933e7b5bedcc31c6cad06e4df232e0fe280118001fec78da488f5f630b65cc1cae5
languageName: node
linkType: hard

"get-tsconfig@npm:@unts/get-tsconfig@^4.1.1":
version: 4.1.1
resolution: "@unts/get-tsconfig@npm:4.1.1"
checksum: dff677518c6bb9452aeb96a8d5935d0a93da1671ec17f92a8b1dfedc957447b12a4a1e8cade4b8dbacfef97a7b1761de40787f315ec62eebe65aa20675fc4944
languageName: node
linkType: hard

"get-uv-event-loop-napi-h@npm:^1.0.5":
version: 1.0.6
resolution: "get-uv-event-loop-napi-h@npm:1.0.6"
dependencies:
get-symbol-from-current-process-h: ^1.0.1
checksum: 3a2a9f9fc18196113d94496c79d5208c7e750cee6f65625fa34df195cab6bf9f122981c923e10cadd81d7f8da1ff92fe4020a7414d3ec16c820dee18e45bb29c
languageName: node
linkType: hard

"get-value@npm:^2.0.3, get-value@npm:^2.0.6":
version: 2.0.6
resolution: "get-value@npm:2.0.6"
Expand Down Expand Up @@ -13383,10 +13358,8 @@ __metadata:
version: 0.0.0-use.local
resolution: "jest-leak-detector@workspace:packages/jest-leak-detector"
dependencies:
"@types/weak-napi": ^2.0.0
jest-get-type: ^28.0.2
pretty-format: ^28.1.3
weak-napi: ^2.0.1
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -16128,15 +16101,6 @@ __metadata:
languageName: node
linkType: hard

"node-addon-api@npm:^3.0.0":
version: 3.2.1
resolution: "node-addon-api@npm:3.2.1"
dependencies:
node-gyp: latest
checksum: 2369986bb0881ccd9ef6bacdf39550e07e089a9c8ede1cbc5fc7712d8e2faa4d50da0e487e333d4125f8c7a616c730131d1091676c9d499af1d74560756b4a18
languageName: node
linkType: hard

"node-dir@npm:^0.1.17":
version: 0.1.17
resolution: "node-dir@npm:0.1.17"
Expand Down Expand Up @@ -16176,17 +16140,6 @@ __metadata:
languageName: node
linkType: hard

"node-gyp-build@npm:^4.2.1":
version: 4.4.0
resolution: "node-gyp-build@npm:4.4.0"
bin:
node-gyp-build: bin.js
node-gyp-build-optional: optional.js
node-gyp-build-test: build-test.js
checksum: 972a059f960253d254e0b23ce10f54c8982236fc0edcab85166d0b7f87443b2ce98391c877cfb2f6eeafcf03c538c5f4dd3e0bfff03828eb48634f58f4c64343
languageName: node
linkType: hard

"node-gyp@npm:^5.0.2":
version: 5.1.1
resolution: "node-gyp@npm:5.1.1"
Expand Down Expand Up @@ -19903,16 +19856,6 @@ __metadata:
languageName: node
linkType: hard

"setimmediate-napi@npm:^1.0.3":
version: 1.0.6
resolution: "setimmediate-napi@npm:1.0.6"
dependencies:
get-symbol-from-current-process-h: ^1.0.1
get-uv-event-loop-napi-h: ^1.0.5
checksum: c2bd48c6f7131e1aa9d7e076d6778a56047ec509b5edfedcc4c98c917d912abed9a60c70f4cf6a841393abe2352ef9cff44e3fe9a1000010180f3ad9522d625a
languageName: node
linkType: hard

"setimmediate@npm:^1.0.5":
version: 1.0.5
resolution: "setimmediate@npm:1.0.5"
Expand Down Expand Up @@ -22372,18 +22315,6 @@ __metadata:
languageName: node
linkType: hard

"weak-napi@npm:^2.0.1":
version: 2.0.2
resolution: "weak-napi@npm:2.0.2"
dependencies:
node-addon-api: ^3.0.0
node-gyp: latest
node-gyp-build: ^4.2.1
setimmediate-napi: ^1.0.3
checksum: 4c3ebac3250c179c789bbef0514a53d35143da41706c716d4b8d2d8921aa8acb3eb4a1c1ccc7d5dc4dead6eae8602c69bae36250e15d967fda39c363dadf02af
languageName: node
linkType: hard

"web-namespaces@npm:^1.0.0":
version: 1.1.4
resolution: "web-namespaces@npm:1.1.4"
Expand Down