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

feat: allow running in Bun, add to CI #599

Closed
wants to merge 1 commit into from
Closed
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
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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need to close this in some way? i.e. https://nodejs.org/api/perf_hooks.html#performanceobserverdisconnect

} 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
Loading