From 24582089cc48f671c591d09594b01b5069c9bc37 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sun, 17 Jul 2022 21:18:44 +0200 Subject: [PATCH 1/2] chore: remove weak-napi support --- CHANGELOG.md | 1 + packages/jest-leak-detector/package.json | 4 -- packages/jest-leak-detector/src/index.ts | 34 ++---------- yarn.lock | 69 ------------------------ 4 files changed, 6 insertions(+), 102 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 683a94544110..58abf56842a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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` ([#13034](https://github.com/facebook/jest/pull/13034)) ### Performance diff --git a/packages/jest-leak-detector/package.json b/packages/jest-leak-detector/package.json index 21748ff3895d..6c93a4cb5936 100644 --- a/packages/jest-leak-detector/package.json +++ b/packages/jest-leak-detector/package.json @@ -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" }, diff --git a/packages/jest-leak-detector/src/index.ts b/packages/jest-leak-detector/src/index.ts index 2473ec271ad4..ff61ae78a246 100644 --- a/packages/jest-leak-detector/src/index.ts +++ b/packages/jest-leak-detector/src/index.ts @@ -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; diff --git a/yarn.lock b/yarn.lock index 8db66fee7ef6..c17af1b7ad1f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -11193,13 +11184,6 @@ __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" @@ -11207,15 +11191,6 @@ __metadata: 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" @@ -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 @@ -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" @@ -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" @@ -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" @@ -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" From 037c9a17f20ef70698f2abe1fa437f5ae3d88adf Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sun, 17 Jul 2022 21:22:44 +0200 Subject: [PATCH 2/2] correct link --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58abf56842a5..9ae2a9be3ef0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +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` ([#13034](https://github.com/facebook/jest/pull/13034)) +- `[jest-leak-detector]` Remove support for `weak-napi` ([#13035](https://github.com/facebook/jest/pull/13035)) ### Performance