Skip to content

Commit 6f82262

Browse files
authored
test: Bundling (#8)
1 parent 9dc5a77 commit 6f82262

File tree

5 files changed

+575
-37
lines changed

5 files changed

+575
-37
lines changed

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
"test": "node ./test/prepare.js && vitest run --testTimeout 60000"
4444
},
4545
"dependencies": {
46-
"detect-libc": "^2.0.2",
47-
"node-abi": "^3.61.0"
46+
"detect-libc": "^2.0.3",
47+
"node-abi": "^3.73.0"
4848
},
4949
"devDependencies": {
5050
"@sentry-internal/eslint-config-sdk": "^8.51.0",
@@ -55,7 +55,10 @@
5555
"eslint": "^7.0.0",
5656
"node-gyp": "^9.4.1",
5757
"typescript": "^5.7.3",
58-
"vitest": "^3.0.4"
58+
"vitest": "^3.0.4",
59+
"webpack": "^5.97.1",
60+
"node-loader": "^2.1.0",
61+
"esbuild": "^0.24.2"
5962
},
6063
"sideEffects": false,
6164
"volta": {

src/index.ts

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ export function importCppBindingsModule(): PrivateV8CpuProfilerBindings {
4141
// This is for cases where precompiled binaries were not provided, but may have been compiled from source.
4242
if (platform === 'darwin') {
4343
if (arch === 'x64') {
44-
if (abi === '93') {
45-
return require('./sentry_cpu_profiler-darwin-x64-93.node');
46-
}
4744
if (abi === '108') {
4845
return require('./sentry_cpu_profiler-darwin-x64-108.node');
4946
}
@@ -56,9 +53,6 @@ export function importCppBindingsModule(): PrivateV8CpuProfilerBindings {
5653
}
5754

5855
if (arch === 'arm64') {
59-
if (abi === '93') {
60-
return require('./sentry_cpu_profiler-darwin-arm64-93.node');
61-
}
6256
if (abi === '108') {
6357
return require('./sentry_cpu_profiler-darwin-arm64-108.node');
6458
}
@@ -73,9 +67,6 @@ export function importCppBindingsModule(): PrivateV8CpuProfilerBindings {
7367

7468
if (platform === 'win32') {
7569
if (arch === 'x64') {
76-
if (abi === '93') {
77-
return require('./sentry_cpu_profiler-win32-x64-93.node');
78-
}
7970
if (abi === '108') {
8071
return require('./sentry_cpu_profiler-win32-x64-108.node');
8172
}
@@ -91,9 +82,6 @@ export function importCppBindingsModule(): PrivateV8CpuProfilerBindings {
9182
if (platform === 'linux') {
9283
if (arch === 'x64') {
9384
if (stdlib === 'musl') {
94-
if (abi === '93') {
95-
return require('./sentry_cpu_profiler-linux-x64-musl-93.node');
96-
}
9785
if (abi === '108') {
9886
return require('./sentry_cpu_profiler-linux-x64-musl-108.node');
9987
}
@@ -105,9 +93,6 @@ export function importCppBindingsModule(): PrivateV8CpuProfilerBindings {
10593
}
10694
}
10795
if (stdlib === 'glibc') {
108-
if (abi === '93') {
109-
return require('./sentry_cpu_profiler-linux-x64-glibc-93.node');
110-
}
11196
if (abi === '108') {
11297
return require('./sentry_cpu_profiler-linux-x64-glibc-108.node');
11398
}
@@ -121,9 +106,6 @@ export function importCppBindingsModule(): PrivateV8CpuProfilerBindings {
121106
}
122107
if (arch === 'arm64') {
123108
if (stdlib === 'musl') {
124-
if (abi === '93') {
125-
return require('./sentry_cpu_profiler-linux-arm64-musl-93.node');
126-
}
127109
if (abi === '108') {
128110
return require('./sentry_cpu_profiler-linux-arm64-musl-108.node');
129111
}
@@ -136,9 +118,6 @@ export function importCppBindingsModule(): PrivateV8CpuProfilerBindings {
136118
}
137119

138120
if (stdlib === 'glibc') {
139-
if (abi === '93') {
140-
return require('./sentry_cpu_profiler-linux-arm64-glibc-93.node');
141-
}
142121
if (abi === '108') {
143122
return require('./sentry_cpu_profiler-linux-arm64-glibc-108.node');
144123
}
@@ -190,7 +169,7 @@ class Bindings implements V8CpuProfilerBindings {
190169

191170
return PrivateCpuProfilerBindings.stopProfiling(
192171
name,
193-
format as unknown as any,
172+
format as unknown as number,
194173
threadId,
195174
!!global._sentryDebugIds,
196175
);
@@ -199,4 +178,4 @@ class Bindings implements V8CpuProfilerBindings {
199178

200179
export const CpuProfilerBindings = new Bindings();
201180

202-
export * from './types';
181+
export * from './types';

test/bundle.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { inspect } from 'node:util';
2+
3+
import { CpuProfilerBindings, ProfileFormat } from '@sentry-internal/node-cpu-profiler';
4+
5+
CpuProfilerBindings.startProfiling('test');
6+
7+
setTimeout(() => {
8+
const report = CpuProfilerBindings.stopProfiling('test', ProfileFormat.THREAD);
9+
console.log(inspect(report, false, null, true));
10+
}, 5000);

test/bundler.test.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import esbuild from 'esbuild';
2+
import * as path from 'path';
3+
import { describe, expect, test } from "vitest";
4+
import webpack from 'webpack';
5+
6+
const entry = path.resolve(__dirname, 'bundle.mjs');
7+
8+
describe('Bundler tests', () => {
9+
test('webpack', ({ skip }) => {
10+
if (!process.env.CI) {
11+
skip("Modules will be missing unless we're running in CI");
12+
return;
13+
}
14+
15+
return new Promise<void>((resolve, reject) => {
16+
webpack({
17+
mode: 'production',
18+
entry: entry,
19+
target: 'node',
20+
output: {
21+
path: path.resolve(__dirname, 'dist', 'webpack'),
22+
filename: 'index.js',
23+
},
24+
resolve: {
25+
extensions: ['.js', '.node'],
26+
},
27+
module: {
28+
rules: [
29+
{
30+
test: /\.node$/,
31+
loader: 'node-loader',
32+
},
33+
],
34+
},
35+
}).run((err, stats) => {
36+
try {
37+
expect(err).toBeNull();
38+
expect(stats?.compilation.errors.length).toBe(0);
39+
resolve();
40+
} catch (e) {
41+
console.error(stats?.compilation.errors);
42+
reject(e);
43+
}
44+
});
45+
});
46+
});
47+
48+
test('esbuild', ({ skip }) => {
49+
if (!process.env.CI) {
50+
skip("Modules will be missing unless we're running in CI");
51+
return;
52+
}
53+
54+
esbuild.buildSync({
55+
platform: 'node',
56+
entryPoints: [entry],
57+
outfile: './dist/esbuild/esm/index.mjs',
58+
target: 'esnext',
59+
format: 'esm',
60+
bundle: true,
61+
loader: { '.node': 'copy' },
62+
});
63+
});
64+
});

0 commit comments

Comments
 (0)