11'use strict' ;
22
3- const os = require ( 'os' ) ;
4- const path = require ( 'path' ) ;
5- const fs = require ( 'fs' ) ;
6- const childProcess = require ( 'child_process' ) ;
3+ import * as os from 'node:os' ;
4+ import * as path from 'node:path' ;
5+ import * as fs from 'node:fs' ;
6+ import * as childProcess from 'node:child_process' ;
7+ import { SentryCliOptions } from './types' ;
78
89const BINARY_DISTRIBUTIONS = [
910 { packageName : '@sentry/cli-darwin' , subpath : 'bin/sentry-cli' } ,
@@ -23,9 +24,9 @@ const BINARY_DISTRIBUTIONS = [
2324 * Without this, the binary can be detected as an asset and included by bundlers
2425 * that use @vercel/nft.
2526 *
26- * @returns { string } The path to the sentry-cli binary
27+ * @returns The path to the sentry-cli binary
2728 */
28- function getFallbackBinaryPath ( ) {
29+ function getFallbackBinaryPath ( ) : string {
2930 const parts = [ ] ;
3031 parts . push ( __dirname ) ;
3132 parts . push ( '..' ) ;
@@ -93,9 +94,9 @@ function getDistributionForThisPlatform() {
9394/**
9495 * Throws an error with a message stating that Sentry CLI doesn't support the current platform.
9596 *
96- * @returns { never } nothing. It throws.
97+ * @returns nothing. It throws.
9798 */
98- function throwUnsupportedPlatformError ( ) {
99+ function throwUnsupportedPlatformError ( ) : void {
99100 throw new Error (
100101 `Unsupported operating system or architecture! Sentry CLI does not work on this architecture.
101102
@@ -110,9 +111,9 @@ Sentry CLI supports:
110111 * Tries to find the installed Sentry CLI binary - either by looking into the relevant
111112 * optional dependencies or by trying to resolve the fallback binary.
112113 *
113- * @returns { string } The path to the sentry-cli binary
114+ * @returns The path to the sentry-cli binary
114115 */
115- function getBinaryPath ( ) {
116+ function getBinaryPath ( ) : string {
116117 if ( process . env . SENTRY_BINARY_PATH ) {
117118 return process . env . SENTRY_BINARY_PATH ;
118119 }
@@ -161,47 +162,41 @@ It seems like none of the "@sentry/cli" package's optional dependencies got inst
161162
162163/**
163164 * Will be used as the binary path when defined with `mockBinaryPath`.
164- * @type {string | undefined }
165165 */
166- let mockedBinaryPath ;
166+ let mockedBinaryPath : string | undefined ;
167167
168168/**
169169 * Overrides the default binary path with a mock value, useful for testing.
170170 *
171- * @param { string } mockPath The new path to the mock sentry-cli binary
171+ * @param mockPath The new path to the mock sentry-cli binary
172172 * @deprecated This was used in tests internally and will be removed in the next major version.
173173 */
174174// TODO(v3): Remove this function
175- function mockBinaryPath ( mockPath ) {
175+ function mockBinaryPath ( mockPath : string ) {
176176 mockedBinaryPath = mockPath ;
177177}
178178
179- /**
180- * The javascript type of a command line option.
181- * @typedef {'array'|'string'|'boolean'|'inverted-boolean' } OptionType
182- */
183-
184- /**
185- * Schema definition of a command line option.
186- * @typedef {object } OptionSchema
187- * @prop {string } param The flag of the command line option including dashes.
188- * @prop {OptionType } type The value type of the command line option.
189- * @prop {string } [invertedParam] The flag of the command line option including dashes (optional).
190- */
191-
192- /**
193- * Schema definition for a command.
194- * @typedef {Object.<string, OptionSchema> } OptionsSchema
195- */
179+ export type OptionsSchema = Record <
180+ string ,
181+ | {
182+ param : string ;
183+ type : 'array' | 'string' | 'number' | 'boolean' | 'inverted-boolean' ;
184+ invertedParam ?: string ;
185+ }
186+ | {
187+ param ?: never ;
188+ type : 'array' | 'string' | 'number' | 'boolean' | 'inverted-boolean' ;
189+ invertedParam : string ;
190+ }
191+ > ;
196192
197193/**
198194 * Serializes command line options into an arguments array.
199195 *
200- * @param {OptionsSchema } schema An options schema required by the command.
201- * @param {object } options An options object according to the schema.
202- * @returns {string[] } An arguments array that can be passed via command line.
196+ * @param schema An options schema required by the command.
197+ * @param options An options object according to the schema.
203198 */
204- function serializeOptions ( schema , options ) {
199+ function serializeOptions ( schema : OptionsSchema , options : Record < string , unknown > ) : string [ ] {
205200 return Object . keys ( schema ) . reduce ( ( newOptions , option ) => {
206201 const paramValue = options [ option ] ;
207202 if ( paramValue === undefined || paramValue === null ) {
@@ -246,20 +241,23 @@ function serializeOptions(schema, options) {
246241/**
247242 * Serializes the command and its options into an arguments array.
248243 *
249- * @param { string[] } command The literal name of the command.
250- * @param { OptionsSchema } [ schema] An options schema required by the command.
251- * @param { object } [ options] An options object according to the schema.
252- * @returns { string[] } An arguments array that can be passed via command line.
244+ * @param command The literal name of the command.
245+ * @param schema An options schema required by the command.
246+ * @param options An options object according to the schema.
247+ * @returns An arguments array that can be passed via command line.
253248 */
254- function prepareCommand ( command , schema , options ) {
249+ function prepareCommand (
250+ command : string [ ] ,
251+ schema : OptionsSchema ,
252+ options : Record < string , unknown >
253+ ) : string [ ] {
255254 return command . concat ( serializeOptions ( schema || { } , options || { } ) ) ;
256255}
257256
258257/**
259258 * Returns the absolute path to the `sentry-cli` binary.
260- * @returns {string }
261259 */
262- function getPath ( ) {
260+ function getPath ( ) : string {
263261 return mockedBinaryPath !== undefined ? mockedBinaryPath : getBinaryPath ( ) ;
264262}
265263
@@ -280,17 +278,23 @@ function getPath() {
280278 * const output = await execute(['--version']);
281279 * expect(output.trim()).toBe('sentry-cli x.y.z');
282280 *
283- * @param { string[] } args Command line arguments passed to `sentry-cli`.
284- * @param { boolean } live can be set to:
281+ * @param args Command line arguments passed to `sentry-cli`.
282+ * @param live can be set to:
285283 * - `true` to inherit stdio and reject the promise if the command
286284 * exits with a non-zero exit code.
287285 * - `false` to not inherit stdio and return the output as a string.
288- * @param { boolean } silent Disable stdout for silents build (CI/Webpack Stats, ...)
289- * @param { string } [ configFile] Relative or absolute path to the configuration file.
290- * @param { import('./index').SentryCliOptions } [ config] More configuration to pass to the CLI
291- * @returns { Promise<string> } A promise that resolves to the standard output.
286+ * @param silent Disable stdout for silents build (CI/Webpack Stats, ...)
287+ * @param configFile Relative or absolute path to the configuration file.
288+ * @param config More configuration to pass to the CLI
289+ * @returns A promise that resolves to the standard output.
292290 */
293- async function execute ( args , live , silent , configFile , config = { } ) {
291+ async function execute (
292+ args : string [ ] ,
293+ live : boolean ,
294+ silent : boolean ,
295+ configFile : string | undefined ,
296+ config : SentryCliOptions = { }
297+ ) : Promise < string > {
294298 const env = { ...process . env } ;
295299 if ( configFile ) {
296300 env . SENTRY_PROPERTIES = configFile ;
@@ -353,7 +357,7 @@ function getProjectFlagsFromOptions({ projects = [] } = {}) {
353357 return projects . reduce ( ( flags , project ) => flags . concat ( '-p' , project ) , [ ] ) ;
354358}
355359
356- module . exports = {
360+ export {
357361 execute ,
358362 getPath ,
359363 getProjectFlagsFromOptions ,
0 commit comments