Skip to content

Commit 7e2d65d

Browse files
authored
Fix incompatibility with perf_hooks accross nodejs versions (#515)
1 parent 15babd5 commit 7e2d65d

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ project adheres to [Semantic Versioning](http://semver.org/).
1111

1212
### Changed
1313

14+
- Increase compatibility with external build system such as `rollup` by making perf_hooks optional in gc.js
15+
1416
### Added
1517

1618
## [14.1.0] - 2022-08-23

lib/metrics/gc.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ const NODEJS_GC_DURATION_SECONDS = 'nodejs_gc_duration_seconds';
1414
const DEFAULT_GC_DURATION_BUCKETS = [0.001, 0.01, 0.1, 1, 2, 5];
1515

1616
const kinds = [];
17-
kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_MAJOR] = 'major';
18-
kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_MINOR] = 'minor';
19-
kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_INCREMENTAL] = 'incremental';
20-
kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_WEAKCB] = 'weakcb';
17+
18+
if (perf_hooks && perf_hooks.constants) {
19+
kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_MAJOR] = 'major';
20+
kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_MINOR] = 'minor';
21+
kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_INCREMENTAL] = 'incremental';
22+
kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_WEAKCB] = 'weakcb';
23+
}
2124

2225
module.exports = (registry, config = {}) => {
2326
if (!perf_hooks) {

0 commit comments

Comments
 (0)