Skip to content

Commit

Permalink
feat: allow running in Bun
Browse files Browse the repository at this point in the history
Adds feature testing to more default metrics so that Bun (and possibly Deno) work.

Ref #570
  • Loading branch information
zbjornson committed Nov 25, 2023
1 parent 68ae662 commit 33fb051
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.yml]
indent_style = space
indent_size = 2
17 changes: 15 additions & 2 deletions .github/workflows/nodejs.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Node.js CI
name: CI

on:
push:
Expand All @@ -11,7 +11,7 @@ on:
- '**'

jobs:
build:
nodejs:
name: Test on Node.js v${{ matrix.node-version }} and OS ${{ matrix.os }}
strategy:
fail-fast: false
Expand Down Expand Up @@ -40,3 +40,16 @@ jobs:
run: npm i
- name: Test
run: npm run test

bun:
name: Test on Bun
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- name: Install Dependencies
run: bun install
- name: Test
run: bun test-unit
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ project adheres to [Semantic Versioning](http://semver.org/).
- remove unnecessary loop from `osMemoryHeapLinux`
- Improve performance of `hashObject` by using pre-sorted array of label names
- Fix type of `collectDefaultMetrics.metricsList`
- Allow running in Bun by skipping incompatible default metrics.

### Added

Expand Down
4 changes: 3 additions & 1 deletion lib/metrics/gc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ let perf_hooks;
try {
// eslint-disable-next-line
perf_hooks = require('perf_hooks');
new perf_hooks.PerformanceObserver();
} catch {
// node version is too old
// node version is too old, or Bun
perf_hooks = false;
}

const NODEJS_GC_DURATION_SECONDS = 'nodejs_gc_duration_seconds';
Expand Down
6 changes: 6 additions & 0 deletions lib/metrics/heapSpacesSizeAndUsed.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ METRICS.forEach(metricType => {
});

module.exports = (registry, config = {}) => {
try {
v8.getHeapSpaceStatistics();
} catch {
return; // Bun
}

const registers = registry ? [registry] : undefined;
const namePrefix = config.prefix ? config.prefix : '';

Expand Down
4 changes: 3 additions & 1 deletion test/metrics/gcTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ describe.each([
try {
// eslint-disable-next-line
perf_hooks = require('perf_hooks');
new perf_hooks.PerformanceObserver();
} catch {
// node version is too old
// node version is too old, or Bun
perf_hooks = false;
}

if (perf_hooks) {
Expand Down

0 comments on commit 33fb051

Please sign in to comment.