@sentry/profiling-node 8.48.0 → 8.49.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -7,9 +7,11 @@ var {
7
7
  Object.defineProperty(exports, '__esModule', { value: true });
8
8
 
9
9
  const core = require('@sentry/core');
10
+ const node_module = require('node:module');
10
11
  const node_os = require('node:os');
11
12
  const node_path = require('node:path');
12
13
  const node_process = require('node:process');
14
+ const node_url = require('node:url');
13
15
  const node_worker_threads = require('node:worker_threads');
14
16
  const detectLibc = require('detect-libc');
15
17
  const nodeAbi = require('node-abi');
@@ -17,6 +19,7 @@ const os = require('os');
17
19
  const process$1 = require('process');
18
20
  const worker_threads = require('worker_threads');
19
21
 
22
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
20
23
  /**
21
24
  * This serves as a build time flag that will be true by default, but false in non-debug builds or if users replace `__SENTRY_DEBUG__` in their generated code.
22
25
  *
@@ -30,23 +33,32 @@ const arch = process.env['BUILD_ARCH'] || node_os.arch();
30
33
  const abi = nodeAbi.getAbi(node_process.versions.node, 'node');
31
34
  const identifier = [platform, arch, stdlib, abi].filter(c => c !== undefined && c !== null).join('-');
32
35
 
33
- const built_from_source_path = node_path.resolve(__dirname, '..', `./sentry_cpu_profiler-${identifier}`);
34
-
35
36
  /**
36
37
  * Imports cpp bindings based on the current platform and architecture.
37
38
  */
38
39
  // eslint-disable-next-line complexity
39
40
  function importCppBindingsModule() {
41
+ // We need to work around using import.meta.url directly with import.meta.url because jest complains about it.
42
+ const importMetaUrl =
43
+ typeof (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)) !== 'undefined'
44
+ ? // This case is always hit when the SDK is built
45
+ (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href))
46
+ : // This case is hit when the tests are run
47
+ node_url.pathToFileURL(__filename).href;
48
+
49
+ const createdRequire = node_module.createRequire(importMetaUrl);
50
+ const esmCompatibleDirname = node_path.dirname(node_url.fileURLToPath(importMetaUrl));
51
+
40
52
  // If a binary path is specified, use that.
41
53
  if (node_process.env['SENTRY_PROFILER_BINARY_PATH']) {
42
54
  const envPath = node_process.env['SENTRY_PROFILER_BINARY_PATH'];
43
- return require(envPath);
55
+ return createdRequire(envPath);
44
56
  }
45
57
 
46
58
  // If a user specifies a different binary dir, they are in control of the binaries being moved there
47
59
  if (node_process.env['SENTRY_PROFILER_BINARY_DIR']) {
48
60
  const binaryPath = node_path.join(node_path.resolve(node_process.env['SENTRY_PROFILER_BINARY_DIR']), `sentry_cpu_profiler-${identifier}`);
49
- return require(`${binaryPath}.node`);
61
+ return createdRequire(`${binaryPath}.node`);
50
62
  }
51
63
 
52
64
  // We need the fallthrough so that in the end, we can fallback to the dynamic require.
@@ -54,31 +66,31 @@ function importCppBindingsModule() {
54
66
  if (platform === 'darwin') {
55
67
  if (arch === 'x64') {
56
68
  if (abi === '93') {
57
- return require('../sentry_cpu_profiler-darwin-x64-93.node');
69
+ return createdRequire('../sentry_cpu_profiler-darwin-x64-93.node');
58
70
  }
59
71
  if (abi === '108') {
60
- return require('../sentry_cpu_profiler-darwin-x64-108.node');
72
+ return createdRequire('../sentry_cpu_profiler-darwin-x64-108.node');
61
73
  }
62
74
  if (abi === '115') {
63
- return require('../sentry_cpu_profiler-darwin-x64-115.node');
75
+ return createdRequire('../sentry_cpu_profiler-darwin-x64-115.node');
64
76
  }
65
77
  if (abi === '127') {
66
- return require('../sentry_cpu_profiler-darwin-x64-127.node');
78
+ return createdRequire('../sentry_cpu_profiler-darwin-x64-127.node');
67
79
  }
68
80
  }
69
81
 
70
82
  if (arch === 'arm64') {
71
83
  if (abi === '93') {
72
- return require('../sentry_cpu_profiler-darwin-arm64-93.node');
84
+ return createdRequire('../sentry_cpu_profiler-darwin-arm64-93.node');
73
85
  }
74
86
  if (abi === '108') {
75
- return require('../sentry_cpu_profiler-darwin-arm64-108.node');
87
+ return createdRequire('../sentry_cpu_profiler-darwin-arm64-108.node');
76
88
  }
77
89
  if (abi === '115') {
78
- return require('../sentry_cpu_profiler-darwin-arm64-115.node');
90
+ return createdRequire('../sentry_cpu_profiler-darwin-arm64-115.node');
79
91
  }
80
92
  if (abi === '127') {
81
- return require('../sentry_cpu_profiler-darwin-arm64-127.node');
93
+ return createdRequire('../sentry_cpu_profiler-darwin-arm64-127.node');
82
94
  }
83
95
  }
84
96
  }
@@ -86,16 +98,16 @@ function importCppBindingsModule() {
86
98
  if (platform === 'win32') {
87
99
  if (arch === 'x64') {
88
100
  if (abi === '93') {
89
- return require('../sentry_cpu_profiler-win32-x64-93.node');
101
+ return createdRequire('../sentry_cpu_profiler-win32-x64-93.node');
90
102
  }
91
103
  if (abi === '108') {
92
- return require('../sentry_cpu_profiler-win32-x64-108.node');
104
+ return createdRequire('../sentry_cpu_profiler-win32-x64-108.node');
93
105
  }
94
106
  if (abi === '115') {
95
- return require('../sentry_cpu_profiler-win32-x64-115.node');
107
+ return createdRequire('../sentry_cpu_profiler-win32-x64-115.node');
96
108
  }
97
109
  if (abi === '127') {
98
- return require('../sentry_cpu_profiler-win32-x64-127.node');
110
+ return createdRequire('../sentry_cpu_profiler-win32-x64-127.node');
99
111
  }
100
112
  }
101
113
  }
@@ -104,66 +116,68 @@ function importCppBindingsModule() {
104
116
  if (arch === 'x64') {
105
117
  if (stdlib === 'musl') {
106
118
  if (abi === '93') {
107
- return require('../sentry_cpu_profiler-linux-x64-musl-93.node');
119
+ return createdRequire('../sentry_cpu_profiler-linux-x64-musl-93.node');
108
120
  }
109
121
  if (abi === '108') {
110
- return require('../sentry_cpu_profiler-linux-x64-musl-108.node');
122
+ return createdRequire('../sentry_cpu_profiler-linux-x64-musl-108.node');
111
123
  }
112
124
  if (abi === '115') {
113
- return require('../sentry_cpu_profiler-linux-x64-musl-115.node');
125
+ return createdRequire('../sentry_cpu_profiler-linux-x64-musl-115.node');
114
126
  }
115
127
  if (abi === '127') {
116
- return require('../sentry_cpu_profiler-linux-x64-musl-127.node');
128
+ return createdRequire('../sentry_cpu_profiler-linux-x64-musl-127.node');
117
129
  }
118
130
  }
119
131
  if (stdlib === 'glibc') {
120
132
  if (abi === '93') {
121
- return require('../sentry_cpu_profiler-linux-x64-glibc-93.node');
133
+ return createdRequire('../sentry_cpu_profiler-linux-x64-glibc-93.node');
122
134
  }
123
135
  if (abi === '108') {
124
- return require('../sentry_cpu_profiler-linux-x64-glibc-108.node');
136
+ return createdRequire('../sentry_cpu_profiler-linux-x64-glibc-108.node');
125
137
  }
126
138
  if (abi === '115') {
127
- return require('../sentry_cpu_profiler-linux-x64-glibc-115.node');
139
+ return createdRequire('../sentry_cpu_profiler-linux-x64-glibc-115.node');
128
140
  }
129
141
  if (abi === '127') {
130
- return require('../sentry_cpu_profiler-linux-x64-glibc-127.node');
142
+ return createdRequire('../sentry_cpu_profiler-linux-x64-glibc-127.node');
131
143
  }
132
144
  }
133
145
  }
134
146
  if (arch === 'arm64') {
135
147
  if (stdlib === 'musl') {
136
148
  if (abi === '93') {
137
- return require('../sentry_cpu_profiler-linux-arm64-musl-93.node');
149
+ return createdRequire('../sentry_cpu_profiler-linux-arm64-musl-93.node');
138
150
  }
139
151
  if (abi === '108') {
140
- return require('../sentry_cpu_profiler-linux-arm64-musl-108.node');
152
+ return createdRequire('../sentry_cpu_profiler-linux-arm64-musl-108.node');
141
153
  }
142
154
  if (abi === '115') {
143
- return require('../sentry_cpu_profiler-linux-arm64-musl-115.node');
155
+ return createdRequire('../sentry_cpu_profiler-linux-arm64-musl-115.node');
144
156
  }
145
157
  if (abi === '127') {
146
- return require('../sentry_cpu_profiler-linux-arm64-musl-127.node');
158
+ return createdRequire('../sentry_cpu_profiler-linux-arm64-musl-127.node');
147
159
  }
148
160
  }
149
161
 
150
162
  if (stdlib === 'glibc') {
151
163
  if (abi === '93') {
152
- return require('../sentry_cpu_profiler-linux-arm64-glibc-93.node');
164
+ return createdRequire('../sentry_cpu_profiler-linux-arm64-glibc-93.node');
153
165
  }
154
166
  if (abi === '108') {
155
- return require('../sentry_cpu_profiler-linux-arm64-glibc-108.node');
167
+ return createdRequire('../sentry_cpu_profiler-linux-arm64-glibc-108.node');
156
168
  }
157
169
  if (abi === '115') {
158
- return require('../sentry_cpu_profiler-linux-arm64-glibc-115.node');
170
+ return createdRequire('../sentry_cpu_profiler-linux-arm64-glibc-115.node');
159
171
  }
160
172
  if (abi === '127') {
161
- return require('../sentry_cpu_profiler-linux-arm64-glibc-127.node');
173
+ return createdRequire('../sentry_cpu_profiler-linux-arm64-glibc-127.node');
162
174
  }
163
175
  }
164
176
  }
165
177
  }
166
- return require(`${built_from_source_path}.node`);
178
+
179
+ const built_from_source_path = node_path.resolve(esmCompatibleDirname, '..', `sentry_cpu_profiler-${identifier}`);
180
+ return createdRequire(`${built_from_source_path}.node`);
167
181
  }
168
182
 
169
183
  const PrivateCpuProfilerBindings = importCppBindingsModule();