@sentry/cli 2.58.2 → 2.58.3

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/js/helper.js CHANGED
@@ -1,21 +1,27 @@
1
1
  'use strict';
2
-
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
3
11
  const os = require('os');
4
12
  const path = require('path');
5
13
  const fs = require('fs');
6
14
  const childProcess = require('child_process');
7
-
8
15
  const BINARY_DISTRIBUTIONS = [
9
- { packageName: '@sentry/cli-darwin', subpath: 'bin/sentry-cli' },
10
- { packageName: '@sentry/cli-linux-x64', subpath: 'bin/sentry-cli' },
11
- { packageName: '@sentry/cli-linux-i686', subpath: 'bin/sentry-cli' },
12
- { packageName: '@sentry/cli-linux-arm64', subpath: 'bin/sentry-cli' },
13
- { packageName: '@sentry/cli-linux-arm', subpath: 'bin/sentry-cli' },
14
- { packageName: '@sentry/cli-win32-x64', subpath: 'bin/sentry-cli.exe' },
15
- { packageName: '@sentry/cli-win32-i686', subpath: 'bin/sentry-cli.exe' },
16
- { packageName: '@sentry/cli-win32-arm64', subpath: 'bin/sentry-cli.exe' },
16
+ { packageName: '@sentry/cli-darwin', subpath: 'bin/sentry-cli' },
17
+ { packageName: '@sentry/cli-linux-x64', subpath: 'bin/sentry-cli' },
18
+ { packageName: '@sentry/cli-linux-i686', subpath: 'bin/sentry-cli' },
19
+ { packageName: '@sentry/cli-linux-arm64', subpath: 'bin/sentry-cli' },
20
+ { packageName: '@sentry/cli-linux-arm', subpath: 'bin/sentry-cli' },
21
+ { packageName: '@sentry/cli-win32-x64', subpath: 'bin/sentry-cli.exe' },
22
+ { packageName: '@sentry/cli-win32-i686', subpath: 'bin/sentry-cli.exe' },
23
+ { packageName: '@sentry/cli-win32-arm64', subpath: 'bin/sentry-cli.exe' },
17
24
  ];
18
-
19
25
  /**
20
26
  * This convoluted function resolves the path to the manually downloaded fallback
21
27
  * `sentry-cli` binary in a way that can't be analysed by @vercel/nft.
@@ -26,86 +32,80 @@ const BINARY_DISTRIBUTIONS = [
26
32
  * @returns {string} The path to the sentry-cli binary
27
33
  */
28
34
  function getFallbackBinaryPath() {
29
- const parts = [];
30
- parts.push(__dirname);
31
- parts.push('..');
32
- parts.push(`sentry-cli${process.platform === 'win32' ? '.exe' : ''}`);
33
- return path.resolve(...parts);
35
+ const parts = [];
36
+ parts.push(__dirname);
37
+ parts.push('..');
38
+ parts.push(`sentry-cli${process.platform === 'win32' ? '.exe' : ''}`);
39
+ return path.resolve(...parts);
34
40
  }
35
-
36
41
  function getDistributionForThisPlatform() {
37
- const arch = os.arch();
38
- const platform = os.platform();
39
-
40
- let packageName = undefined;
41
- if (platform === 'darwin') {
42
- packageName = '@sentry/cli-darwin';
43
- } else if (platform === 'linux' || platform === 'freebsd' || platform === 'android') {
44
- switch (arch) {
45
- case 'x64':
46
- packageName = '@sentry/cli-linux-x64';
47
- break;
48
- case 'x86':
49
- case 'ia32':
50
- packageName = '@sentry/cli-linux-i686';
51
- break;
52
- case 'arm64':
53
- packageName = '@sentry/cli-linux-arm64';
54
- break;
55
- case 'arm':
56
- packageName = '@sentry/cli-linux-arm';
57
- break;
42
+ const arch = os.arch();
43
+ const platform = os.platform();
44
+ let packageName = undefined;
45
+ if (platform === 'darwin') {
46
+ packageName = '@sentry/cli-darwin';
58
47
  }
59
- } else if (platform === 'win32') {
60
- switch (arch) {
61
- case 'x64':
62
- packageName = '@sentry/cli-win32-x64';
63
- break;
64
- case 'x86':
65
- case 'ia32':
66
- packageName = '@sentry/cli-win32-i686';
67
- break;
68
- case 'arm64':
69
- packageName = '@sentry/cli-win32-arm64';
70
- break;
48
+ else if (platform === 'linux' || platform === 'freebsd' || platform === 'android') {
49
+ switch (arch) {
50
+ case 'x64':
51
+ packageName = '@sentry/cli-linux-x64';
52
+ break;
53
+ case 'x86':
54
+ case 'ia32':
55
+ packageName = '@sentry/cli-linux-i686';
56
+ break;
57
+ case 'arm64':
58
+ packageName = '@sentry/cli-linux-arm64';
59
+ break;
60
+ case 'arm':
61
+ packageName = '@sentry/cli-linux-arm';
62
+ break;
63
+ }
71
64
  }
72
- }
73
-
74
- let subpath = undefined;
75
- switch (platform) {
76
- case 'win32':
77
- subpath = 'bin/sentry-cli.exe';
78
- break;
79
- case 'darwin':
80
- case 'linux':
81
- case 'freebsd':
82
- case 'android':
83
- subpath = 'bin/sentry-cli';
84
- break;
85
- default:
86
- subpath = 'bin/sentry-cli';
87
- break;
88
- }
89
-
90
- return { packageName, subpath };
65
+ else if (platform === 'win32') {
66
+ switch (arch) {
67
+ case 'x64':
68
+ packageName = '@sentry/cli-win32-x64';
69
+ break;
70
+ case 'x86':
71
+ case 'ia32':
72
+ packageName = '@sentry/cli-win32-i686';
73
+ break;
74
+ case 'arm64':
75
+ packageName = '@sentry/cli-win32-arm64';
76
+ break;
77
+ }
78
+ }
79
+ let subpath = undefined;
80
+ switch (platform) {
81
+ case 'win32':
82
+ subpath = 'bin/sentry-cli.exe';
83
+ break;
84
+ case 'darwin':
85
+ case 'linux':
86
+ case 'freebsd':
87
+ case 'android':
88
+ subpath = 'bin/sentry-cli';
89
+ break;
90
+ default:
91
+ subpath = 'bin/sentry-cli';
92
+ break;
93
+ }
94
+ return { packageName, subpath };
91
95
  }
92
-
93
96
  /**
94
97
  * Throws an error with a message stating that Sentry CLI doesn't support the current platform.
95
98
  *
96
99
  * @returns {never} nothing. It throws.
97
100
  */
98
101
  function throwUnsupportedPlatformError() {
99
- throw new Error(
100
- `Unsupported operating system or architecture! Sentry CLI does not work on this architecture.
102
+ throw new Error(`Unsupported operating system or architecture! Sentry CLI does not work on this architecture.
101
103
 
102
104
  Sentry CLI supports:
103
105
  - Darwin (macOS)
104
106
  - Linux and FreeBSD on x64, x86, ia32, arm64, and arm architectures
105
- - Windows x64, x86, and ia32 architectures`
106
- );
107
+ - Windows x64, x86, and ia32 architectures`);
107
108
  }
108
-
109
109
  /**
110
110
  * Tries to find the installed Sentry CLI binary - either by looking into the relevant
111
111
  * optional dependencies or by trying to resolve the fallback binary.
@@ -113,58 +113,53 @@ Sentry CLI supports:
113
113
  * @returns {string} The path to the sentry-cli binary
114
114
  */
115
115
  function getBinaryPath() {
116
- if (process.env.SENTRY_BINARY_PATH) {
117
- return process.env.SENTRY_BINARY_PATH;
118
- }
119
-
120
- const { packageName, subpath } = getDistributionForThisPlatform();
121
-
122
- if (packageName === undefined) {
123
- throwUnsupportedPlatformError();
124
- }
125
-
126
- let fallbackBinaryPath = getFallbackBinaryPath();
127
- if (fs.existsSync(fallbackBinaryPath)) {
128
- // Since the fallback got installed, the optional dependencies likely didn't get installed, so we just default to the fallback.
129
- return fallbackBinaryPath;
130
- }
131
-
132
- let compatibleBinaryPath;
133
- try {
134
- compatibleBinaryPath = require.resolve(`${packageName}/${subpath}`);
135
- } catch (e) {
136
- const otherInstalledDistribution = BINARY_DISTRIBUTIONS.find(({ packageName, subpath }) => {
137
- try {
138
- require.resolve(`${packageName}/${subpath}`);
139
- return true;
140
- } catch (e) {
141
- return false;
142
- }
143
- });
144
-
145
- // These error messages are heavily inspired by esbuild's error messages: https://github.com/evanw/esbuild/blob/f3d535262e3998d845d0f102b944ecd5a9efda57/lib/npm/node-platform.ts#L150
146
- if (otherInstalledDistribution) {
147
- throw new Error(`Sentry CLI binary for this platform/architecture not found!
116
+ if (process.env.SENTRY_BINARY_PATH) {
117
+ return process.env.SENTRY_BINARY_PATH;
118
+ }
119
+ const { packageName, subpath } = getDistributionForThisPlatform();
120
+ if (packageName === undefined) {
121
+ throwUnsupportedPlatformError();
122
+ }
123
+ let fallbackBinaryPath = getFallbackBinaryPath();
124
+ if (fs.existsSync(fallbackBinaryPath)) {
125
+ // Since the fallback got installed, the optional dependencies likely didn't get installed, so we just default to the fallback.
126
+ return fallbackBinaryPath;
127
+ }
128
+ let compatibleBinaryPath;
129
+ try {
130
+ compatibleBinaryPath = require.resolve(`${packageName}/${subpath}`);
131
+ }
132
+ catch (e) {
133
+ const otherInstalledDistribution = BINARY_DISTRIBUTIONS.find(({ packageName, subpath }) => {
134
+ try {
135
+ require.resolve(`${packageName}/${subpath}`);
136
+ return true;
137
+ }
138
+ catch (e) {
139
+ return false;
140
+ }
141
+ });
142
+ // These error messages are heavily inspired by esbuild's error messages: https://github.com/evanw/esbuild/blob/f3d535262e3998d845d0f102b944ecd5a9efda57/lib/npm/node-platform.ts#L150
143
+ if (otherInstalledDistribution) {
144
+ throw new Error(`Sentry CLI binary for this platform/architecture not found!
148
145
 
149
146
  The "${otherInstalledDistribution.packageName}" package is installed, but for the current platform, you should have the "${packageName}" package installed instead. This usually happens if the "@sentry/cli" package is installed on one platform (for example Windows or MacOS) and then the "node_modules" folder is reused on another operating system (for example Linux in Docker).
150
147
 
151
148
  To fix this, avoid copying the "node_modules" folder, and instead freshly install your dependencies on the target system. You can also configure your package manager to install the right package. For example, yarn has the "supportedArchitectures" feature: https://yarnpkg.com/configuration/yarnrc/#supportedArchitecture.`);
152
- } else {
153
- throw new Error(`Sentry CLI binary for this platform/architecture not found!
149
+ }
150
+ else {
151
+ throw new Error(`Sentry CLI binary for this platform/architecture not found!
154
152
 
155
153
  It seems like none of the "@sentry/cli" package's optional dependencies got installed. Please make sure your package manager is configured to install optional dependencies. If you are using npm to install your dependencies, please don't set the "--no-optional", "--ignore-optional", or "--omit=optional" flags. Sentry CLI needs the "optionalDependencies" feature in order to install its binary.`);
154
+ }
156
155
  }
157
- }
158
-
159
- return compatibleBinaryPath;
156
+ return compatibleBinaryPath;
160
157
  }
161
-
162
158
  /**
163
159
  * Will be used as the binary path when defined with `mockBinaryPath`.
164
160
  * @type {string | undefined}
165
161
  */
166
162
  let mockedBinaryPath;
167
-
168
163
  /**
169
164
  * Overrides the default binary path with a mock value, useful for testing.
170
165
  *
@@ -173,14 +168,12 @@ let mockedBinaryPath;
173
168
  */
174
169
  // TODO(v3): Remove this function
175
170
  function mockBinaryPath(mockPath) {
176
- mockedBinaryPath = mockPath;
171
+ mockedBinaryPath = mockPath;
177
172
  }
178
-
179
173
  /**
180
174
  * The javascript type of a command line option.
181
175
  * @typedef {'array'|'string'|'boolean'|'inverted-boolean'} OptionType
182
176
  */
183
-
184
177
  /**
185
178
  * Schema definition of a command line option.
186
179
  * @typedef {object} OptionSchema
@@ -188,12 +181,10 @@ function mockBinaryPath(mockPath) {
188
181
  * @prop {OptionType} type The value type of the command line option.
189
182
  * @prop {string} [invertedParam] The flag of the command line option including dashes (optional).
190
183
  */
191
-
192
184
  /**
193
185
  * Schema definition for a command.
194
186
  * @typedef {Object.<string, OptionSchema>} OptionsSchema
195
187
  */
196
-
197
188
  /**
198
189
  * Serializes command line options into an arguments array.
199
190
  *
@@ -202,47 +193,35 @@ function mockBinaryPath(mockPath) {
202
193
  * @returns {string[]} An arguments array that can be passed via command line.
203
194
  */
204
195
  function serializeOptions(schema, options) {
205
- return Object.keys(schema).reduce((newOptions, option) => {
206
- const paramValue = options[option];
207
- if (paramValue === undefined || paramValue === null) {
208
- return newOptions;
209
- }
210
-
211
- const paramType = schema[option].type;
212
- const paramName = schema[option].param;
213
-
214
- if (paramType === 'array') {
215
- if (!Array.isArray(paramValue)) {
216
- throw new Error(`${option} should be an array`);
217
- }
218
-
219
- return newOptions.concat(
220
- paramValue.reduce((acc, value) => acc.concat([paramName, String(value)]), [])
221
- );
222
- }
223
-
224
- if (paramType === 'boolean') {
225
- if (typeof paramValue !== 'boolean') {
226
- throw new Error(`${option} should be a bool`);
227
- }
228
-
229
- const invertedParamName = schema[option].invertedParam;
230
-
231
- if (paramValue && paramName !== undefined) {
232
- return newOptions.concat([paramName]);
233
- }
234
-
235
- if (!paramValue && invertedParamName !== undefined) {
236
- return newOptions.concat([invertedParamName]);
237
- }
238
-
239
- return newOptions;
240
- }
241
-
242
- return newOptions.concat(paramName, paramValue);
243
- }, []);
196
+ return Object.keys(schema).reduce((newOptions, option) => {
197
+ const paramValue = options[option];
198
+ if (paramValue === undefined || paramValue === null) {
199
+ return newOptions;
200
+ }
201
+ const paramType = schema[option].type;
202
+ const paramName = schema[option].param;
203
+ if (paramType === 'array') {
204
+ if (!Array.isArray(paramValue)) {
205
+ throw new Error(`${option} should be an array`);
206
+ }
207
+ return newOptions.concat(paramValue.reduce((acc, value) => acc.concat([paramName, String(value)]), []));
208
+ }
209
+ if (paramType === 'boolean') {
210
+ if (typeof paramValue !== 'boolean') {
211
+ throw new Error(`${option} should be a bool`);
212
+ }
213
+ const invertedParamName = schema[option].invertedParam;
214
+ if (paramValue && paramName !== undefined) {
215
+ return newOptions.concat([paramName]);
216
+ }
217
+ if (!paramValue && invertedParamName !== undefined) {
218
+ return newOptions.concat([invertedParamName]);
219
+ }
220
+ return newOptions;
221
+ }
222
+ return newOptions.concat(paramName, paramValue);
223
+ }, []);
244
224
  }
245
-
246
225
  /**
247
226
  * Serializes the command and its options into an arguments array.
248
227
  *
@@ -252,17 +231,15 @@ function serializeOptions(schema, options) {
252
231
  * @returns {string[]} An arguments array that can be passed via command line.
253
232
  */
254
233
  function prepareCommand(command, schema, options) {
255
- return command.concat(serializeOptions(schema || {}, options || {}));
234
+ return command.concat(serializeOptions(schema || {}, options || {}));
256
235
  }
257
-
258
236
  /**
259
237
  * Returns the absolute path to the `sentry-cli` binary.
260
238
  * @returns {string}
261
239
  */
262
240
  function getPath() {
263
- return mockedBinaryPath !== undefined ? mockedBinaryPath : getBinaryPath();
241
+ return mockedBinaryPath !== undefined ? mockedBinaryPath : getBinaryPath();
264
242
  }
265
-
266
243
  /**
267
244
  * Runs `sentry-cli` with the given command line arguments.
268
245
  *
@@ -288,91 +265,93 @@ function getPath() {
288
265
  * exits with a non-zero exit code.
289
266
  * @param {boolean} silent Disable stdout for silents build (CI/Webpack Stats, ...)
290
267
  * @param {string} [configFile] Relative or absolute path to the configuration file.
291
- * @param {Object} [config] More configuration to pass to the CLI
292
- * @returns {Promise.<string>} A promise that resolves to the standard output.
268
+ * @param {import('./index').SentryCliOptions} [config] More configuration to pass to the CLI
269
+ * @returns {Promise<string>} A promise that resolves to the standard output.
293
270
  */
294
- async function execute(args, live, silent, configFile, config = {}) {
295
- const env = { ...process.env };
296
- if (configFile) {
297
- env.SENTRY_PROPERTIES = configFile;
298
- }
299
- if (config.url) {
300
- env.SENTRY_URL = config.url;
301
- }
302
- if (config.authToken) {
303
- env.SENTRY_AUTH_TOKEN = config.authToken;
304
- }
305
- if (config.apiKey) {
306
- env.SENTRY_API_KEY = config.apiKey;
307
- }
308
- if (config.dsn) {
309
- env.SENTRY_DSN = config.dsn;
310
- }
311
- if (config.org) {
312
- env.SENTRY_ORG = config.org;
313
- }
314
- if (config.project) {
315
- env.SENTRY_PROJECT = config.project;
316
- }
317
- if (config.vcsRemote) {
318
- env.SENTRY_VCS_REMOTE = config.vcsRemote;
319
- }
320
- if (config.customHeader) {
321
- env.CUSTOM_HEADER = config.customHeader;
322
- } else if (config.headers) {
323
- const headers = Object.entries(config.headers).flatMap(([key, value]) => [
324
- '--header',
325
- `${key}:${value}`,
326
- ]);
327
- args = [...headers, ...args];
328
- }
329
-
330
- return new Promise((resolve, reject) => {
331
- if (live === true || live === 'rejectOnError') {
332
- const output = silent ? 'ignore' : 'inherit';
333
- const pid = childProcess.spawn(getPath(), args, {
334
- env,
335
- // stdin, stdout, stderr
336
- stdio: ['ignore', output, output],
337
- });
338
- pid.on('exit', (exitCode) => {
339
- if (live === 'rejectOnError') {
340
- if (exitCode === 0) {
341
- resolve('success (live mode)');
342
- }
343
- reject(new Error(`Command ${args.join(' ')} failed with exit code ${exitCode}`));
271
+ function execute(args_1, live_1, silent_1, configFile_1) {
272
+ return __awaiter(this, arguments, void 0, function* (args, live, silent, configFile, config = {}) {
273
+ const env = Object.assign({}, process.env);
274
+ if (configFile) {
275
+ env.SENTRY_PROPERTIES = configFile;
344
276
  }
345
- // According to the type definition, resolving with void is not allowed.
346
- // However, for backwards compatibility, we resolve void here to
347
- // avoid a behaviour-breaking change.
348
- // TODO (v3): Clean this up and always resolve a string (or change the type definition)
349
- // @ts-expect-error - see comment above
350
- resolve();
351
- });
352
- } else {
353
- childProcess.execFile(getPath(), args, { env }, (err, stdout) => {
354
- if (err) {
355
- reject(err);
356
- } else {
357
- resolve(stdout);
277
+ if (config.url) {
278
+ env.SENTRY_URL = config.url;
358
279
  }
359
- });
360
- }
361
- });
280
+ if (config.authToken) {
281
+ env.SENTRY_AUTH_TOKEN = config.authToken;
282
+ }
283
+ if (config.apiKey) {
284
+ env.SENTRY_API_KEY = config.apiKey;
285
+ }
286
+ if (config.dsn) {
287
+ env.SENTRY_DSN = config.dsn;
288
+ }
289
+ if (config.org) {
290
+ env.SENTRY_ORG = config.org;
291
+ }
292
+ if (config.project) {
293
+ env.SENTRY_PROJECT = config.project;
294
+ }
295
+ if (config.vcsRemote) {
296
+ env.SENTRY_VCS_REMOTE = config.vcsRemote;
297
+ }
298
+ if (config.customHeader) {
299
+ env.CUSTOM_HEADER = config.customHeader;
300
+ }
301
+ else if (config.headers) {
302
+ const headers = Object.entries(config.headers).flatMap(([key, value]) => [
303
+ '--header',
304
+ `${key}:${value}`,
305
+ ]);
306
+ args = [...headers, ...args];
307
+ }
308
+ return new Promise((resolve, reject) => {
309
+ if (live === true || live === 'rejectOnError') {
310
+ const output = silent ? 'ignore' : 'inherit';
311
+ const pid = childProcess.spawn(getPath(), args, {
312
+ env,
313
+ // stdin, stdout, stderr
314
+ stdio: ['ignore', output, output],
315
+ });
316
+ pid.on('exit', (exitCode) => {
317
+ if (live === 'rejectOnError') {
318
+ if (exitCode === 0) {
319
+ resolve('success (live mode)');
320
+ }
321
+ reject(new Error(`Command ${args.join(' ')} failed with exit code ${exitCode}`));
322
+ }
323
+ // According to the type definition, resolving with void is not allowed.
324
+ // However, for backwards compatibility, we resolve void here to
325
+ // avoid a behaviour-breaking change.
326
+ // TODO (v3): Clean this up and always resolve a string (or change the type definition)
327
+ // @ts-expect-error - see comment above
328
+ resolve();
329
+ });
330
+ }
331
+ else {
332
+ childProcess.execFile(getPath(), args, { env }, (err, stdout) => {
333
+ if (err) {
334
+ reject(err);
335
+ }
336
+ else {
337
+ resolve(stdout);
338
+ }
339
+ });
340
+ }
341
+ });
342
+ });
362
343
  }
363
-
364
344
  function getProjectFlagsFromOptions({ projects = [] } = {}) {
365
- return projects.reduce((flags, project) => flags.concat('-p', project), []);
345
+ return projects.reduce((flags, project) => flags.concat('-p', project), []);
366
346
  }
367
-
368
347
  module.exports = {
369
- execute,
370
- getPath,
371
- getProjectFlagsFromOptions,
372
- mockBinaryPath,
373
- prepareCommand,
374
- serializeOptions,
375
- getDistributionForThisPlatform,
376
- throwUnsupportedPlatformError,
377
- getFallbackBinaryPath,
348
+ execute,
349
+ getPath,
350
+ getProjectFlagsFromOptions,
351
+ mockBinaryPath,
352
+ prepareCommand,
353
+ serializeOptions,
354
+ getDistributionForThisPlatform,
355
+ throwUnsupportedPlatformError,
356
+ getFallbackBinaryPath,
378
357
  };