Skip to content

test: Bundling #8

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

Merged
merged 4 commits into from
Feb 6, 2025
Merged
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
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
"test": "node ./test/prepare.js && vitest run --testTimeout 60000"
},
"dependencies": {
"detect-libc": "^2.0.2",
"node-abi": "^3.61.0"
"detect-libc": "^2.0.3",
"node-abi": "^3.73.0"
},
"devDependencies": {
"@sentry-internal/eslint-config-sdk": "^8.51.0",
Expand All @@ -55,7 +55,10 @@
"eslint": "^7.0.0",
"node-gyp": "^9.4.1",
"typescript": "^5.7.3",
"vitest": "^3.0.4"
"vitest": "^3.0.4",
"webpack": "^5.97.1",
"node-loader": "^2.1.0",
"esbuild": "^0.24.2"
},
"sideEffects": false,
"volta": {
Expand Down
25 changes: 2 additions & 23 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ export function importCppBindingsModule(): PrivateV8CpuProfilerBindings {
// This is for cases where precompiled binaries were not provided, but may have been compiled from source.
if (platform === 'darwin') {
if (arch === 'x64') {
if (abi === '93') {
return require('./sentry_cpu_profiler-darwin-x64-93.node');
}
Comment on lines -44 to -46
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This PR removes all references to the 93 abi binaries because we no longer build them and they were causing the new tests to fail!

Copy link
Member

Choose a reason for hiding this comment

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

should this be a separate PR, where we stop building those? This does not seem to be a test-only change here? Or is it just not used anymore anywhere?

Copy link
Collaborator Author

@timfish timfish Jan 31, 2025

Choose a reason for hiding this comment

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

should this be a separate PR, where we stop building those?

We haven't been building these binaries for a while. I think they are from Node 16. The new tests simply highlighted that these requires don't point to anything and needed cleaning up.

These are the binaries we build.

if (abi === '108') {
return require('./sentry_cpu_profiler-darwin-x64-108.node');
}
Expand All @@ -56,9 +53,6 @@ export function importCppBindingsModule(): PrivateV8CpuProfilerBindings {
}

if (arch === 'arm64') {
if (abi === '93') {
return require('./sentry_cpu_profiler-darwin-arm64-93.node');
}
if (abi === '108') {
return require('./sentry_cpu_profiler-darwin-arm64-108.node');
}
Expand All @@ -73,9 +67,6 @@ export function importCppBindingsModule(): PrivateV8CpuProfilerBindings {

if (platform === 'win32') {
if (arch === 'x64') {
if (abi === '93') {
return require('./sentry_cpu_profiler-win32-x64-93.node');
}
if (abi === '108') {
return require('./sentry_cpu_profiler-win32-x64-108.node');
}
Expand All @@ -91,9 +82,6 @@ export function importCppBindingsModule(): PrivateV8CpuProfilerBindings {
if (platform === 'linux') {
if (arch === 'x64') {
if (stdlib === 'musl') {
if (abi === '93') {
return require('./sentry_cpu_profiler-linux-x64-musl-93.node');
}
if (abi === '108') {
return require('./sentry_cpu_profiler-linux-x64-musl-108.node');
}
Expand All @@ -105,9 +93,6 @@ export function importCppBindingsModule(): PrivateV8CpuProfilerBindings {
}
}
if (stdlib === 'glibc') {
if (abi === '93') {
return require('./sentry_cpu_profiler-linux-x64-glibc-93.node');
}
if (abi === '108') {
return require('./sentry_cpu_profiler-linux-x64-glibc-108.node');
}
Expand All @@ -121,9 +106,6 @@ export function importCppBindingsModule(): PrivateV8CpuProfilerBindings {
}
if (arch === 'arm64') {
if (stdlib === 'musl') {
if (abi === '93') {
return require('./sentry_cpu_profiler-linux-arm64-musl-93.node');
}
if (abi === '108') {
return require('./sentry_cpu_profiler-linux-arm64-musl-108.node');
}
Expand All @@ -136,9 +118,6 @@ export function importCppBindingsModule(): PrivateV8CpuProfilerBindings {
}

if (stdlib === 'glibc') {
if (abi === '93') {
return require('./sentry_cpu_profiler-linux-arm64-glibc-93.node');
}
if (abi === '108') {
return require('./sentry_cpu_profiler-linux-arm64-glibc-108.node');
}
Expand Down Expand Up @@ -190,7 +169,7 @@ class Bindings implements V8CpuProfilerBindings {

return PrivateCpuProfilerBindings.stopProfiling(
name,
format as unknown as any,
format as unknown as number,
threadId,
!!global._sentryDebugIds,
);
Expand All @@ -199,4 +178,4 @@ class Bindings implements V8CpuProfilerBindings {

export const CpuProfilerBindings = new Bindings();

export * from './types';
export * from './types';
10 changes: 10 additions & 0 deletions test/bundle.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { inspect } from 'node:util';

import { CpuProfilerBindings, ProfileFormat } from '@sentry-internal/node-cpu-profiler';

CpuProfilerBindings.startProfiling('test');

setTimeout(() => {
const report = CpuProfilerBindings.stopProfiling('test', ProfileFormat.THREAD);
console.log(inspect(report, false, null, true));
}, 5000);
64 changes: 64 additions & 0 deletions test/bundler.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import esbuild from 'esbuild';
import * as path from 'path';
import { describe, expect, test } from "vitest";
import webpack from 'webpack';

const entry = path.resolve(__dirname, 'bundle.mjs');

describe('Bundler tests', () => {
test('webpack', ({ skip }) => {
if (!process.env.CI) {
skip("Modules will be missing unless we're running in CI");
return;
}

return new Promise<void>((resolve, reject) => {
webpack({
mode: 'production',
entry: entry,
target: 'node',
output: {
path: path.resolve(__dirname, 'dist', 'webpack'),
filename: 'index.js',
},
resolve: {
extensions: ['.js', '.node'],
},
module: {
rules: [
{
test: /\.node$/,
loader: 'node-loader',
},
],
},
}).run((err, stats) => {
try {
expect(err).toBeNull();
expect(stats?.compilation.errors.length).toBe(0);
resolve();
} catch (e) {
console.error(stats?.compilation.errors);
reject(e);
}
});
});
});

test('esbuild', ({ skip }) => {
if (!process.env.CI) {
skip("Modules will be missing unless we're running in CI");
return;
}

esbuild.buildSync({
platform: 'node',
entryPoints: [entry],
outfile: './dist/esbuild/esm/index.mjs',
target: 'esnext',
format: 'esm',
bundle: true,
loader: { '.node': 'copy' },
});
});
});
Loading