@sentry/profiling-node 10.70.0 → 11.0.0-alpha.1

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.
@@ -1,204 +0,0 @@
1
- #! /usr/bin/env node
2
-
3
- // This is a build script, so some logging is desirable as it allows
4
- // us to follow the code path that triggered the error.
5
- /* eslint-disable no-console */
6
- const fs = require('fs');
7
-
8
- let SOURCE_DIR, PLATFORM, ARCH, STDLIB, NODE, HELP;
9
-
10
- for (let i = 0; i < process.argv.length; i++) {
11
- const arg = process.argv[i];
12
- if (arg.startsWith('--target_dir_path=')) {
13
- SOURCE_DIR = arg.split('=')[1];
14
- continue;
15
- }
16
-
17
- if (arg.startsWith('--target_platform=')) {
18
- PLATFORM = arg.split('=')[1];
19
- continue;
20
- }
21
-
22
- if (arg.startsWith('--target_arch=')) {
23
- ARCH = arg.split('=')[1];
24
- continue;
25
- }
26
-
27
- if (arg.startsWith('--target_stdlib=')) {
28
- STDLIB = arg.split('=')[1];
29
- continue;
30
- }
31
-
32
- if (arg.startsWith('--target_node=')) {
33
- NODE = arg.split('=')[1];
34
- continue;
35
- }
36
-
37
- if (arg === '--help' || arg === '-h') {
38
- HELP = true;
39
- continue;
40
- }
41
- }
42
-
43
- if (HELP) {
44
- console.log(
45
- `\nSentry: Prune profiler binaries\n
46
- Usage: sentry-prune-profiler-binaries --target_dir_path=... --target_platform=... --target_arch=... --target_stdlib=...\n
47
- Arguments:\n
48
- --target_dir_path: Path to the directory containing the final bundled code. If you are using webpack, this would be the equivalent of output.path option.\n
49
- --target_node: The major node version the code will be running on. Example: 16, 18, 20...\n
50
- --target_platform: The platform the code will be running on. Example: linux, darwin, win32\n
51
- --target_arch: The architecture the code will be running on. Example: x64, arm64\n
52
- --target_stdlib: The standard library the code will be running on. Example: glibc, musl\n
53
- --dry-run: Do not delete any files, just print the files that would be deleted.\n
54
- --help: Print this help message.\n`,
55
- );
56
- process.exit(0);
57
- }
58
-
59
- console.warn(
60
- '[Sentry] Warning: This script will be removed in the next major version. See: https://github.com/getsentry/sentry-javascript/issues/20567',
61
- );
62
-
63
- const ARGV_ERRORS = [];
64
-
65
- const NODE_TO_ABI = {
66
- 16: '93',
67
- 18: '108',
68
- 20: '115',
69
- 22: '127',
70
- 24: '137',
71
- 26: '147',
72
- };
73
-
74
- if (NODE) {
75
- if (NODE_TO_ABI[NODE]) {
76
- NODE = NODE_TO_ABI[NODE];
77
- } else if (NODE.startsWith('16')) {
78
- NODE = NODE_TO_ABI['16'];
79
- } else if (NODE.startsWith('18')) {
80
- NODE = NODE_TO_ABI['18'];
81
- } else if (NODE.startsWith('20')) {
82
- NODE = NODE_TO_ABI['20'];
83
- } else if (NODE.startsWith('22')) {
84
- NODE = NODE_TO_ABI['22'];
85
- } else if (NODE.startsWith('24')) {
86
- NODE = NODE_TO_ABI['24'];
87
- } else if (NODE.startsWith('26')) {
88
- NODE = NODE_TO_ABI['26'];
89
- } else {
90
- ARGV_ERRORS.push(
91
- `❌ Sentry: Invalid node version passed as argument, please make sure --target_node is a valid major node version. Supported versions are ${Object.keys(
92
- NODE_TO_ABI,
93
- ).join(', ')}.`,
94
- );
95
- }
96
- }
97
-
98
- if (!SOURCE_DIR) {
99
- ARGV_ERRORS.push(
100
- '❌ Sentry: Missing target_dir_path argument. target_dir_path should point to the directory containing the final bundled code. If you are using webpack, this would be the equivalent of output.path option.',
101
- );
102
- }
103
-
104
- if (!PLATFORM && !ARCH && !STDLIB) {
105
- ARGV_ERRORS.push(
106
- `❌ Sentry: Missing argument values, pruning requires either --target_platform, --target_arch or --target_stdlib to be passed as argument values.\n Example: sentry-prune-profiler-binaries --target_platform=linux --target_arch=x64 --target_stdlib=glibc\n
107
- If you are unsure about the execution environment, you can opt to skip some values, but at least one value must be passed.`,
108
- );
109
- }
110
-
111
- if (ARGV_ERRORS.length > 0) {
112
- console.log(ARGV_ERRORS.join('\n'));
113
- process.exit(1);
114
- }
115
-
116
- const SENTRY__PROFILER_BIN_REGEXP = /sentry_cpu_profiler-.*\.node$/;
117
-
118
- async function findSentryProfilerBinaries(source_dir) {
119
- const binaries = new Set();
120
- const queue = [source_dir];
121
-
122
- while (queue.length > 0) {
123
- const dir = queue.pop();
124
-
125
- for (const file of fs.readdirSync(dir)) {
126
- if (SENTRY__PROFILER_BIN_REGEXP.test(file)) {
127
- binaries.add(`${dir}/${file}`);
128
- continue;
129
- }
130
-
131
- if (fs.statSync(`${dir}/${file}`).isDirectory()) {
132
- if (file === 'node_modules') {
133
- continue;
134
- }
135
-
136
- queue.push(`${dir}/${file}`);
137
- }
138
- }
139
- }
140
-
141
- return binaries;
142
- }
143
-
144
- function bytesToHumanReadable(bytes) {
145
- if (bytes < 1024) {
146
- return `${bytes} Bytes`;
147
- } else if (bytes < 1048576) {
148
- return `${(bytes / 1024).toFixed(2)} KiB`;
149
- } else {
150
- return `${(bytes / 1048576).toFixed(2)} MiB`;
151
- }
152
- }
153
-
154
- async function prune(binaries) {
155
- let bytesSaved = 0;
156
- let removedBinariesCount = 0;
157
-
158
- const conditions = [PLATFORM, ARCH, STDLIB, NODE].filter(n => !!n);
159
-
160
- for (const binary of binaries) {
161
- if (conditions.every(condition => binary.includes(condition))) {
162
- continue;
163
- }
164
-
165
- const stats = fs.statSync(binary);
166
- bytesSaved += stats.size;
167
- removedBinariesCount++;
168
-
169
- if (process.argv.includes('--dry-run')) {
170
- console.log(`Sentry: would have pruned ${binary} (${bytesToHumanReadable(stats.size)})`);
171
- continue;
172
- }
173
-
174
- console.log(`Sentry: pruned ${binary} (${bytesToHumanReadable(stats.size)})`);
175
- fs.unlinkSync(binary);
176
- }
177
-
178
- if (removedBinariesCount === 0) {
179
- console.log(
180
- '❌ Sentry: no binaries pruned, please make sure target argument values are valid or use --help for more information.',
181
- );
182
- return;
183
- }
184
-
185
- if (process.argv.includes('--dry-run')) {
186
- console.log(
187
- `✅ Sentry: would have pruned ${removedBinariesCount} ${
188
- removedBinariesCount === 1 ? 'binary' : 'binaries'
189
- } and saved ${bytesToHumanReadable(bytesSaved)}.`,
190
- );
191
- return;
192
- }
193
-
194
- console.log(
195
- `✅ Sentry: pruned ${removedBinariesCount} ${
196
- removedBinariesCount === 1 ? 'binary' : 'binaries'
197
- }, saved ${bytesToHumanReadable(bytesSaved)} in total.`,
198
- );
199
- }
200
-
201
- (async () => {
202
- const binaries = await findSentryProfilerBinaries(SOURCE_DIR);
203
- await prune(binaries);
204
- })();