From d28aa3b0a73a0c411695382fbb4e6dc09a5e0126 Mon Sep 17 00:00:00 2001 From: Franck Mourre Date: Wed, 31 Aug 2022 15:35:25 +0200 Subject: [PATCH 1/4] makes perf_hooks actually optionnal --- lib/metrics/gc.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/metrics/gc.js b/lib/metrics/gc.js index 75b8f4bc..a2920583 100644 --- a/lib/metrics/gc.js +++ b/lib/metrics/gc.js @@ -14,10 +14,13 @@ const NODEJS_GC_DURATION_SECONDS = 'nodejs_gc_duration_seconds'; const DEFAULT_GC_DURATION_BUCKETS = [0.001, 0.01, 0.1, 1, 2, 5]; const kinds = []; -kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_MAJOR] = 'major'; -kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_MINOR] = 'minor'; -kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_INCREMENTAL] = 'incremental'; -kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_WEAKCB] = 'weakcb'; + +if (perf_hooks) { + kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_MAJOR] = 'major'; + kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_MINOR] = 'minor'; + kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_INCREMENTAL] = 'incremental'; + kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_WEAKCB] = 'weakcb'; +} module.exports = (registry, config = {}) => { if (!perf_hooks) { From 4810e671a069a92ea2c487d326516671f919267d Mon Sep 17 00:00:00 2001 From: Franck Mourre Date: Wed, 31 Aug 2022 15:37:13 +0200 Subject: [PATCH 2/4] changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a48e0e91..40de2fa5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ project adheres to [Semantic Versioning](http://semver.org/). ### Changed +- Increase compatibility with external build system such as `rollup` by making perf_hooks optional in gc.js + ### Added ## [14.1.0] - 2022-08-23 From 5a90557735f88335220605b9ca20fb25ff9b587d Mon Sep 17 00:00:00 2001 From: Franck Mourre Date: Wed, 31 Aug 2022 15:44:14 +0200 Subject: [PATCH 3/4] check for perf_hooks.constants to exist --- lib/metrics/gc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/metrics/gc.js b/lib/metrics/gc.js index a2920583..8ac77e56 100644 --- a/lib/metrics/gc.js +++ b/lib/metrics/gc.js @@ -15,7 +15,7 @@ const DEFAULT_GC_DURATION_BUCKETS = [0.001, 0.01, 0.1, 1, 2, 5]; const kinds = []; -if (perf_hooks) { +if (perf_hooks && perf_hooks.constants) { kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_MAJOR] = 'major'; kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_MINOR] = 'minor'; kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_INCREMENTAL] = 'incremental'; From 5750124f339f4d3c57d0cc2b6910050eb44b5000 Mon Sep 17 00:00:00 2001 From: Franck Mourre Date: Wed, 31 Aug 2022 15:53:14 +0200 Subject: [PATCH 4/4] fix linting issues --- lib/metrics/gc.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/metrics/gc.js b/lib/metrics/gc.js index 8ac77e56..0d2e2839 100644 --- a/lib/metrics/gc.js +++ b/lib/metrics/gc.js @@ -16,10 +16,10 @@ const DEFAULT_GC_DURATION_BUCKETS = [0.001, 0.01, 0.1, 1, 2, 5]; const kinds = []; if (perf_hooks && perf_hooks.constants) { - kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_MAJOR] = 'major'; - kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_MINOR] = 'minor'; - kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_INCREMENTAL] = 'incremental'; - kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_WEAKCB] = 'weakcb'; + kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_MAJOR] = 'major'; + kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_MINOR] = 'minor'; + kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_INCREMENTAL] = 'incremental'; + kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_WEAKCB] = 'weakcb'; } module.exports = (registry, config = {}) => {