Skip to content

Commit 643eff2

Browse files
authored
feat(node-profiling): Output ESM and remove Sentry deps from output (#11135)
- Moves Sentry deps to `dependencies` rather than `devDependencies` - Updated `package.json` exports - Updated the rollup config to mirror our other modules with the addition of the commonJs plugin - I couldn't use `createRequire` myself because Jest can't handle `import.meta` so instead I used `@rollup/plugin-esm-shim` which shims both `require` and `__dirname` in `cpu_profiler.ts` in the ESM output!
1 parent 0a54d19 commit 643eff2

File tree

6 files changed

+50
-39
lines changed

6 files changed

+50
-39
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"devDependencies": {
8989
"@biomejs/biome": "^1.4.0",
9090
"@rollup/plugin-commonjs": "^25.0.7",
91+
"@rollup/plugin-esm-shim": "^0.1.5",
9192
"@rollup/plugin-json": "^6.1.0",
9293
"@rollup/plugin-node-resolve": "^15.2.3",
9394
"@rollup/plugin-replace": "^5.0.5",

packages/profiling-node/package.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@
66
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/profiling-node",
77
"author": "Sentry",
88
"license": "MIT",
9-
"main": "lib/index.js",
9+
"main": "lib/cjs/index.js",
1010
"types": "lib/types/index.d.ts",
1111
"exports": {
1212
"./package.json": "./package.json",
1313
".": {
14+
"import": {
15+
"types": "./lib/types/index.d.ts",
16+
"default": "./lib/esm/index.js"
17+
},
1418
"require": {
1519
"types": "./lib/types/index.d.ts",
16-
"default": "./lib/index.js"
20+
"default": "./lib/cjs/index.js"
1721
}
1822
}
1923
},
@@ -73,14 +77,14 @@
7377
"test": "cross-env SENTRY_PROFILER_BINARY_DIR=lib jest --config jest.config.js"
7478
},
7579
"dependencies": {
76-
"detect-libc": "^2.0.2",
77-
"node-abi": "^3.52.0"
78-
},
79-
"devDependencies": {
8080
"@sentry/core": "8.0.0-alpha.2",
8181
"@sentry/node-experimental": "8.0.0-alpha.2",
8282
"@sentry/types": "8.0.0-alpha.2",
8383
"@sentry/utils": "8.0.0-alpha.2",
84+
"detect-libc": "^2.0.2",
85+
"node-abi": "^3.52.0"
86+
},
87+
"devDependencies": {
8488
"@types/node": "16.18.70",
8589
"@types/node-abi": "^3.0.0",
8690
"clang-format": "^1.8.0",
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import commonjs from '@rollup/plugin-commonjs';
2-
import resolve from '@rollup/plugin-node-resolve';
3-
import typescript from '@rollup/plugin-typescript';
4-
import { makeBaseNPMConfig } from '@sentry-internal/rollup-utils';
2+
import esmshim from '@rollup/plugin-esm-shim';
3+
import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollup-utils';
54

6-
export default makeBaseNPMConfig({
7-
packageSpecificConfig: {
8-
input: 'src/index.ts',
9-
output: { file: 'lib/index.js', format: 'cjs', dir: undefined, preserveModules: false },
10-
plugins: [resolve(), commonjs(), typescript({ tsconfig: './tsconfig.json' })],
11-
},
12-
});
5+
export default makeNPMConfigVariants(
6+
makeBaseNPMConfig({
7+
packageSpecificConfig: {
8+
output: { dir: 'lib', preserveModules: false },
9+
plugins: [commonjs(), esmshim()],
10+
},
11+
}),
12+
);

packages/profiling-node/src/cpu_profiler.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const arch = process.env['BUILD_ARCH'] || _arch();
1515
const abi = getAbi(versions.node, 'node');
1616
const identifier = [platform, arch, stdlib, abi].filter(c => c !== undefined && c !== null).join('-');
1717

18-
const built_from_source_path = resolve(__dirname, `./sentry_cpu_profiler-${identifier}`);
18+
const built_from_source_path = resolve(__dirname, '..', `./sentry_cpu_profiler-${identifier}`);
1919

2020
/**
2121
* Imports cpp bindings based on the current platform and architecture.
@@ -39,39 +39,39 @@ export function importCppBindingsModule(): PrivateV8CpuProfilerBindings {
3939
if (platform === 'darwin') {
4040
if (arch === 'x64') {
4141
if (abi === '93') {
42-
return require('./sentry_cpu_profiler-darwin-x64-93.node');
42+
return require('../sentry_cpu_profiler-darwin-x64-93.node');
4343
}
4444
if (abi === '108') {
45-
return require('./sentry_cpu_profiler-darwin-x64-108.node');
45+
return require('../sentry_cpu_profiler-darwin-x64-108.node');
4646
}
4747
if (abi === '115') {
48-
return require('./sentry_cpu_profiler-darwin-x64-115.node');
48+
return require('../sentry_cpu_profiler-darwin-x64-115.node');
4949
}
5050
}
5151

5252
if (arch === 'arm64') {
5353
if (abi === '93') {
54-
return require('./sentry_cpu_profiler-darwin-arm64-93.node');
54+
return require('../sentry_cpu_profiler-darwin-arm64-93.node');
5555
}
5656
if (abi === '108') {
57-
return require('./sentry_cpu_profiler-darwin-arm64-108.node');
57+
return require('../sentry_cpu_profiler-darwin-arm64-108.node');
5858
}
5959
if (abi === '115') {
60-
return require('./sentry_cpu_profiler-darwin-arm64-115.node');
60+
return require('../sentry_cpu_profiler-darwin-arm64-115.node');
6161
}
6262
}
6363
}
6464

6565
if (platform === 'win32') {
6666
if (arch === 'x64') {
6767
if (abi === '93') {
68-
return require('./sentry_cpu_profiler-win32-x64-93.node');
68+
return require('../sentry_cpu_profiler-win32-x64-93.node');
6969
}
7070
if (abi === '108') {
71-
return require('./sentry_cpu_profiler-win32-x64-108.node');
71+
return require('../sentry_cpu_profiler-win32-x64-108.node');
7272
}
7373
if (abi === '115') {
74-
return require('./sentry_cpu_profiler-win32-x64-115.node');
74+
return require('../sentry_cpu_profiler-win32-x64-115.node');
7575
}
7676
}
7777
}
@@ -80,48 +80,48 @@ export function importCppBindingsModule(): PrivateV8CpuProfilerBindings {
8080
if (arch === 'x64') {
8181
if (stdlib === 'musl') {
8282
if (abi === '93') {
83-
return require('./sentry_cpu_profiler-linux-x64-musl-93.node');
83+
return require('../sentry_cpu_profiler-linux-x64-musl-93.node');
8484
}
8585
if (abi === '108') {
86-
return require('./sentry_cpu_profiler-linux-x64-musl-108.node');
86+
return require('../sentry_cpu_profiler-linux-x64-musl-108.node');
8787
}
8888
if (abi === '115') {
89-
return require('./sentry_cpu_profiler-linux-x64-musl-115.node');
89+
return require('../sentry_cpu_profiler-linux-x64-musl-115.node');
9090
}
9191
}
9292
if (stdlib === 'glibc') {
9393
if (abi === '93') {
94-
return require('./sentry_cpu_profiler-linux-x64-glibc-93.node');
94+
return require('../sentry_cpu_profiler-linux-x64-glibc-93.node');
9595
}
9696
if (abi === '108') {
97-
return require('./sentry_cpu_profiler-linux-x64-glibc-108.node');
97+
return require('../sentry_cpu_profiler-linux-x64-glibc-108.node');
9898
}
9999
if (abi === '115') {
100-
return require('./sentry_cpu_profiler-linux-x64-glibc-115.node');
100+
return require('../sentry_cpu_profiler-linux-x64-glibc-115.node');
101101
}
102102
}
103103
}
104104
if (arch === 'arm64') {
105105
if (stdlib === 'musl') {
106106
if (abi === '93') {
107-
return require('./sentry_cpu_profiler-linux-arm64-musl-93.node');
107+
return require('../sentry_cpu_profiler-linux-arm64-musl-93.node');
108108
}
109109
if (abi === '108') {
110-
return require('./sentry_cpu_profiler-linux-arm64-musl-108.node');
110+
return require('../sentry_cpu_profiler-linux-arm64-musl-108.node');
111111
}
112112
if (abi === '115') {
113-
return require('./sentry_cpu_profiler-linux-arm64-musl-115.node');
113+
return require('../sentry_cpu_profiler-linux-arm64-musl-115.node');
114114
}
115115
}
116116
if (stdlib === 'glibc') {
117117
if (abi === '93') {
118-
return require('./sentry_cpu_profiler-linux-arm64-glibc-93.node');
118+
return require('../sentry_cpu_profiler-linux-arm64-glibc-93.node');
119119
}
120120
if (abi === '108') {
121-
return require('./sentry_cpu_profiler-linux-arm64-glibc-108.node');
121+
return require('../sentry_cpu_profiler-linux-arm64-glibc-108.node');
122122
}
123123
if (abi === '115') {
124-
return require('./sentry_cpu_profiler-linux-arm64-glibc-115.node');
124+
return require('../sentry_cpu_profiler-linux-arm64-glibc-115.node');
125125
}
126126
}
127127
}

packages/sveltekit/src/index.types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ export declare const getClient: typeof clientSdk.getClient;
4646
// eslint-disable-next-line deprecation/deprecation
4747
export declare const getCurrentHub: typeof clientSdk.getCurrentHub;
4848
// eslint-disable-next-line deprecation/deprecation
49-
export declare const makeMain: typeof clientSdk.makeMain;
5049
export declare function close(timeout?: number | undefined): PromiseLike<boolean>;
5150
export declare function flush(timeout?: number | undefined): PromiseLike<boolean>;
5251

yarn.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5831,6 +5831,13 @@
58315831
is-reference "1.2.1"
58325832
magic-string "^0.30.3"
58335833

5834+
"@rollup/plugin-esm-shim@^0.1.5":
5835+
version "0.1.5"
5836+
resolved "https://registry.yarnpkg.com/@rollup/plugin-esm-shim/-/plugin-esm-shim-0.1.5.tgz#74464e9a8a7e664557aae65592c8a3e317802220"
5837+
integrity sha512-xnIjDm/0EbqAw0/rR1UE7eAo9db0ftGPqT8RUCFtkFxtCuspbbmj+wutoyxm32jBytyO3SgkxSG17OR893fV7A==
5838+
dependencies:
5839+
magic-string "^0.30.3"
5840+
58345841
"@rollup/plugin-json@^4.0.0", "@rollup/plugin-json@^4.1.0":
58355842
version "4.1.0"
58365843
resolved "https://registry.yarnpkg.com/@rollup/plugin-json/-/plugin-json-4.1.0.tgz#54e09867ae6963c593844d8bd7a9c718294496f3"

0 commit comments

Comments
 (0)