@sentry/cli 2.58.2 → 2.58.3-alpha0

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,274 +1,260 @@
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 helper = require('../helper');
4
-
5
12
  /**
6
13
  * Default arguments for the `--ignore` option.
7
14
  * @type {string[]}
8
15
  */
9
16
  const DEFAULT_IGNORE = ['node_modules'];
10
-
11
17
  /**
12
18
  * Schema for the `upload-sourcemaps` command.
13
19
  * @type {import('../helper').OptionsSchema}
14
20
  */
15
21
  const SOURCEMAPS_SCHEMA = require('./options/uploadSourcemaps');
16
-
17
22
  /**
18
23
  * Schema for the `deploys new` command.
19
24
  * @type {import('../helper').OptionsSchema}
20
25
  */
21
26
  const DEPLOYS_SCHEMA = require('./options/deploys');
22
-
27
+ /**
28
+ * @typedef {import('../types').SentryCliUploadSourceMapsOptions} SentryCliUploadSourceMapsOptions
29
+ * @typedef {import('../types').SourceMapsPathDescriptor} SourceMapsPathDescriptor
30
+ * @typedef {import('../types').SentryCliNewDeployOptions} SentryCliNewDeployOptions
31
+ * @typedef {import('../types').SentryCliCommitsOptions} SentryCliCommitsOptions
32
+ */
23
33
  /**
24
34
  * Manages releases and release artifacts on Sentry.
25
35
  * @namespace SentryReleases
26
36
  */
27
37
  class Releases {
28
- /**
29
- * Creates a new `Releases` instance.
30
- *
31
- * @param {Object} [options] More options to pass to the CLI
32
- */
33
- constructor(options) {
34
- this.options = options || {};
35
- if (typeof this.options.configFile === 'string') {
36
- this.configFile = this.options.configFile;
38
+ /**
39
+ * Creates a new `Releases` instance.
40
+ *
41
+ * @param {Object} [options] More options to pass to the CLI
42
+ */
43
+ constructor(options) {
44
+ this.options = options || {};
45
+ if (typeof this.options.configFile === 'string') {
46
+ this.configFile = this.options.configFile;
47
+ }
48
+ delete this.options.configFile;
37
49
  }
38
- delete this.options.configFile;
39
- }
40
-
41
- /**
42
- * Registers a new release with sentry.
43
- *
44
- * The given release name should be unique and deterministic. It can later be used to
45
- * upload artifacts, such as source maps.
46
- *
47
- * @param {string} release Unique name of the new release.
48
- * @param {object} options A set of options when creating a release.
49
- * @param {array} options.projects The list of project slugs for a release.
50
- * @returns {Promise} A promise that resolves when the release has been created.
51
- * @memberof SentryReleases
52
- */
53
- async new(release, options) {
54
- const args = ['releases', 'new', release].concat(helper.getProjectFlagsFromOptions(options));
55
- return this.execute(args, null);
56
- }
57
-
58
- /**
59
- * Specifies the set of commits covered in this release.
60
- *
61
- * @param {string} release Unique name of the release
62
- * @param {object} options A set of options to configure the commits to include
63
- * @param {string} options.repo The full repo name as defined in Sentry
64
- * @param {boolean} options.auto Automatically choose the associated commit (uses
65
- * the current commit). Overrides other options.
66
- * @param {string} options.commit The current (last) commit in the release.
67
- * @param {string} options.previousCommit The commit before the beginning of this
68
- * release (in other words, the last commit of the previous release). If omitted,
69
- * this will default to the last commit of the previous release in Sentry. If there
70
- * was no previous release, the last 10 commits will be used.
71
- * @param {boolean} options.ignoreMissing When the flag is set and the previous release
72
- * commit was not found in the repository, will create a release with the default commits
73
- * count (or the one specified with `--initial-depth`) instead of failing the command.
74
- * @param {boolean} options.ignoreEmpty When the flag is set, command will not fail
75
- * and just exit silently if no new commits for a given release have been found.
76
- * @returns {Promise} A promise that resolves when the commits have been associated
77
- * @memberof SentryReleases
78
- */
79
- async setCommits(release, options) {
80
- if (!options || (!options.auto && (!options.repo || !options.commit))) {
81
- throw new Error('options.auto, or options.repo and options.commit must be specified');
50
+ /**
51
+ * Registers a new release with sentry.
52
+ *
53
+ * The given release name should be unique and deterministic. It can later be used to
54
+ * upload artifacts, such as source maps.
55
+ *
56
+ * @param {string} release Unique name of the new release.
57
+ * @param {{projects?: string[]}} [options] The list of project slugs for a release.
58
+ * @returns {Promise<string>} A promise that resolves when the release has been created.
59
+ * @memberof SentryReleases
60
+ */
61
+ new(release, options) {
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ const args = ['releases', 'new', release].concat(helper.getProjectFlagsFromOptions(options));
64
+ return this.execute(args, null);
65
+ });
82
66
  }
83
-
84
- let commitFlags = [];
85
-
86
- if (options.auto) {
87
- commitFlags = ['--auto'];
88
- } else if (options.previousCommit) {
89
- commitFlags = ['--commit', `${options.repo}@${options.previousCommit}..${options.commit}`];
90
- } else {
91
- commitFlags = ['--commit', `${options.repo}@${options.commit}`];
67
+ /**
68
+ * Specifies the set of commits covered in this release.
69
+ *
70
+ * @param {string} release Unique name of the release
71
+ * @param {SentryCliCommitsOptions} options A set of options to configure the commits to include
72
+ * @returns {Promise<string>} A promise that resolves when the commits have been associated
73
+ * @memberof SentryReleases
74
+ */
75
+ setCommits(release, options) {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ if (!options || (!options.auto && (!options.repo || !options.commit))) {
78
+ throw new Error('options.auto, or options.repo and options.commit must be specified');
79
+ }
80
+ let commitFlags = [];
81
+ if (options.auto) {
82
+ commitFlags = ['--auto'];
83
+ }
84
+ else if (options.previousCommit) {
85
+ commitFlags = ['--commit', `${options.repo}@${options.previousCommit}..${options.commit}`];
86
+ }
87
+ else {
88
+ commitFlags = ['--commit', `${options.repo}@${options.commit}`];
89
+ }
90
+ if (options.ignoreMissing) {
91
+ commitFlags.push('--ignore-missing');
92
+ }
93
+ return this.execute(['releases', 'set-commits', release].concat(commitFlags), false);
94
+ });
92
95
  }
93
-
94
- if (options.ignoreMissing) {
95
- commitFlags.push('--ignore-missing');
96
+ /**
97
+ * Marks this release as complete. This should be called once all artifacts has been
98
+ * uploaded.
99
+ *
100
+ * @param {string} release Unique name of the release.
101
+ * @returns {Promise<string>} A promise that resolves when the release has been finalized.
102
+ * @memberof SentryReleases
103
+ */
104
+ finalize(release) {
105
+ return __awaiter(this, void 0, void 0, function* () {
106
+ return this.execute(['releases', 'finalize', release], null);
107
+ });
96
108
  }
97
-
98
- return this.execute(['releases', 'set-commits', release].concat(commitFlags), false);
99
- }
100
-
101
- /**
102
- * Marks this release as complete. This should be called once all artifacts has been
103
- * uploaded.
104
- *
105
- * @param {string} release Unique name of the release.
106
- * @returns {Promise} A promise that resolves when the release has been finalized.
107
- * @memberof SentryReleases
108
- */
109
- async finalize(release) {
110
- return this.execute(['releases', 'finalize', release], null);
111
- }
112
-
113
- /**
114
- * Creates a unique, deterministic version identifier based on the project type and
115
- * source files. This identifier can be used as release name.
116
- *
117
- * @returns {Promise.<string>} A promise that resolves to the version string.
118
- * @memberof SentryReleases
119
- */
120
- async proposeVersion() {
121
- const version = await this.execute(['releases', 'propose-version'], null);
122
- return version.trim();
123
- }
124
-
125
- /**
126
- * Scans the given include folders for JavaScript source maps and uploads them to the
127
- * specified release for processing.
128
- *
129
- * The options require an `include` array, which is a list of directories to scan.
130
- * Additionally, it supports to ignore certain files, validate and preprocess source
131
- * maps and define a URL prefix.
132
- *
133
- * @example
134
- * await cli.releases.uploadSourceMaps(cli.releases.proposeVersion(), {
135
- * // required options:
136
- * include: ['build'],
137
- *
138
- * // default options:
139
- * ignore: ['node_modules'], // globs for files to ignore
140
- * ignoreFile: null, // path to a file with ignore rules
141
- * rewrite: false, // preprocess sourcemaps before uploading
142
- * sourceMapReference: true, // add a source map reference to source files
143
- * dedupe: true, // deduplicate already uploaded files
144
- * stripPrefix: [], // remove certain prefixes from filenames
145
- * stripCommonPrefix: false, // guess common prefixes to remove from filenames
146
- * validate: false, // validate source maps and cancel the upload on error
147
- * urlPrefix: '', // add a prefix source map urls after stripping them
148
- * urlSuffix: '', // add a suffix source map urls after stripping them
149
- * ext: ['js', 'map', 'jsbundle', 'bundle'], // override file extensions to scan for
150
- * projects: ['node'], // provide a list of projects
151
- * decompress: false // decompress gzip files before uploading
152
- * live: true // whether to inherit stdio to display `sentry-cli` output directly.
153
- * });
154
- *
155
- * @param {string} release Unique name of the release.
156
- * @param {object} options Options to configure the source map upload.
157
- * @returns {Promise} A promise that resolves when the upload has completed successfully.
158
- * @memberof SentryReleases
159
- */
160
- async uploadSourceMaps(release, options) {
161
- if (!options || !options.include || !Array.isArray(options.include)) {
162
- throw new Error(
163
- '`options.include` must be a valid array of paths and/or path descriptor objects.'
164
- );
109
+ /**
110
+ * Creates a unique, deterministic version identifier based on the project type and
111
+ * source files. This identifier can be used as release name.
112
+ *
113
+ * @returns {Promise<string>} A promise that resolves to the version string.
114
+ * @memberof SentryReleases
115
+ */
116
+ proposeVersion() {
117
+ return __awaiter(this, void 0, void 0, function* () {
118
+ const version = yield this.execute(['releases', 'propose-version'], null);
119
+ return version.trim();
120
+ });
165
121
  }
166
-
167
- // Each entry in the `include` array will map to an array of promises, which
168
- // will in turn contain one promise per literal path value. Thus `uploads`
169
- // will be an array of Promise arrays, which we'll flatten later.
170
- const uploads = options.include.map((includeEntry) => {
171
- let pathOptions;
172
- let uploadPaths;
173
-
174
- if (typeof includeEntry === 'object') {
175
- pathOptions = includeEntry;
176
- uploadPaths = includeEntry.paths;
177
-
178
- if (!Array.isArray(uploadPaths)) {
179
- throw new Error(
180
- `Path descriptor objects in \`options.include\` must contain a \`paths\` array. Got ${includeEntry}.`
181
- );
182
- }
183
- }
184
- // `includeEntry` should be a string, which we can wrap in an array to
185
- // match the `paths` property in the descriptor object type
186
- else {
187
- pathOptions = {};
188
- uploadPaths = [includeEntry];
189
- }
190
-
191
- const newOptions = { ...options, ...pathOptions };
192
- if (!newOptions.ignoreFile && !newOptions.ignore) {
193
- newOptions.ignore = DEFAULT_IGNORE;
194
- }
195
-
196
- // args which apply to the entire `include` entry (everything besides the path)
197
- const args = ['sourcemaps', 'upload']
198
- .concat(helper.getProjectFlagsFromOptions(options))
199
- .concat(['--release', release]);
200
-
201
- return uploadPaths.map((path) =>
202
- // `execute()` is async and thus we're returning a promise here
203
- this.execute(
204
- helper.prepareCommand([...args, path], SOURCEMAPS_SCHEMA, newOptions),
205
- options.live != null ? options.live : true
206
- )
207
- );
208
- });
209
-
210
- // `uploads` is an array of Promise arrays, which needs to be flattened
211
- // before being passed to `Promise.all()`. (`Array.flat()` doesn't exist in
212
- // Node < 11; this polyfill takes advantage of the fact that `concat()` is
213
- // willing to accept an arbitrary number of items to add to and/or iterables
214
- // to unpack into the given array.)
215
- return Promise.all([].concat(...uploads));
216
- }
217
-
218
- /**
219
- * List all deploys for a given release.
220
- *
221
- * @param {string} release Unique name of the release.
222
- * @returns {Promise} A promise that resolves when the list comes back from the server.
223
- * @memberof SentryReleases
224
- */
225
- async listDeploys(release) {
226
- return this.execute(['releases', 'deploys', release, 'list'], null);
227
- }
228
-
229
- /**
230
- * Creates a new release deployment. This should be called after the release has been
231
- * finalized, while deploying on a given environment.
232
- *
233
- * @example
234
- * await cli.releases.newDeploy(cli.releases.proposeVersion(), {
235
- * // required options:
236
- * env: 'production', // environment for this release. Values that make sense here would be 'production' or 'staging'
237
- *
238
- * // optional options:
239
- * started: 42, // unix timestamp when the deployment started
240
- * finished: 1337, // unix timestamp when the deployment finished
241
- * time: 1295, // deployment duration in seconds. This can be specified alternatively to `started` and `finished`
242
- * name: 'PickleRick', // human readable name for this deployment
243
- * url: 'https://example.com', // URL that points to the deployment
244
- * });
245
- *
246
- * @param {string} release Unique name of the release.
247
- * @param {object} options Options to configure the new release deploy.
248
- * @returns {Promise} A promise that resolves when the deploy has been created.
249
- * @memberof SentryReleases
250
- */
251
- async newDeploy(release, options) {
252
- if (!options || !options.env) {
253
- throw new Error('options.env must be a valid name');
122
+ /**
123
+ * Scans the given include folders for JavaScript source maps and uploads them to the
124
+ * specified release for processing.
125
+ *
126
+ * The options require an `include` array, which is a list of directories to scan.
127
+ * Additionally, it supports to ignore certain files, validate and preprocess source
128
+ * maps and define a URL prefix.
129
+ *
130
+ * @example
131
+ * await cli.releases.uploadSourceMaps(cli.releases.proposeVersion(), {
132
+ * // required options:
133
+ * include: ['build'],
134
+ *
135
+ * // default options:
136
+ * ignore: ['node_modules'], // globs for files to ignore
137
+ * ignoreFile: null, // path to a file with ignore rules
138
+ * rewrite: false, // preprocess sourcemaps before uploading
139
+ * sourceMapReference: true, // add a source map reference to source files
140
+ * dedupe: true, // deduplicate already uploaded files
141
+ * stripPrefix: [], // remove certain prefixes from filenames
142
+ * stripCommonPrefix: false, // guess common prefixes to remove from filenames
143
+ * validate: false, // validate source maps and cancel the upload on error
144
+ * urlPrefix: '', // add a prefix source map urls after stripping them
145
+ * urlSuffix: '', // add a suffix source map urls after stripping them
146
+ * ext: ['js', 'map', 'jsbundle', 'bundle'], // override file extensions to scan for
147
+ * projects: ['node'], // provide a list of projects
148
+ * decompress: false // decompress gzip files before uploading
149
+ * live: true // whether to inherit stdio to display `sentry-cli` output directly.
150
+ * });
151
+ *
152
+ * @param {string} release Unique name of the release.
153
+ * @param {SentryCliUploadSourceMapsOptions & {live?: boolean | 'rejectOnError'}} options Options to configure the source map upload.
154
+ * @returns {Promise<string[]>} A promise that resolves when the upload has completed successfully.
155
+ * @memberof SentryReleases
156
+ */
157
+ uploadSourceMaps(release, options) {
158
+ return __awaiter(this, void 0, void 0, function* () {
159
+ if (!options || !options.include || !Array.isArray(options.include)) {
160
+ throw new Error('`options.include` must be a valid array of paths and/or path descriptor objects.');
161
+ }
162
+ // Each entry in the `include` array will map to an array of promises, which
163
+ // will in turn contain one promise per literal path value. Thus `uploads`
164
+ // will be an array of Promise arrays, which we'll flatten later.
165
+ const uploads = options.include.map((includeEntry) => {
166
+ let pathOptions;
167
+ let uploadPaths;
168
+ if (typeof includeEntry === 'object') {
169
+ pathOptions = includeEntry;
170
+ uploadPaths = includeEntry.paths;
171
+ if (!Array.isArray(uploadPaths)) {
172
+ throw new Error(`Path descriptor objects in \`options.include\` must contain a \`paths\` array. Got ${includeEntry}.`);
173
+ }
174
+ }
175
+ // `includeEntry` should be a string, which we can wrap in an array to
176
+ // match the `paths` property in the descriptor object type
177
+ else {
178
+ pathOptions = {};
179
+ uploadPaths = [includeEntry];
180
+ }
181
+ const newOptions = Object.assign(Object.assign({}, options), pathOptions);
182
+ if (!newOptions.ignoreFile && !newOptions.ignore) {
183
+ newOptions.ignore = DEFAULT_IGNORE;
184
+ }
185
+ // args which apply to the entire `include` entry (everything besides the path)
186
+ const args = ['sourcemaps', 'upload']
187
+ .concat(helper.getProjectFlagsFromOptions(options))
188
+ .concat(['--release', release]);
189
+ return uploadPaths.map((path) =>
190
+ // `execute()` is async and thus we're returning a promise here
191
+ this.execute(helper.prepareCommand([...args, path], SOURCEMAPS_SCHEMA, newOptions), options.live != null ? options.live : true));
192
+ });
193
+ // `uploads` is an array of Promise arrays, which needs to be flattened
194
+ // before being passed to `Promise.all()`. (`Array.flat()` doesn't exist in
195
+ // Node < 11; this polyfill takes advantage of the fact that `concat()` is
196
+ // willing to accept an arbitrary number of items to add to and/or iterables
197
+ // to unpack into the given array.)
198
+ return Promise.all([].concat(...uploads));
199
+ });
200
+ }
201
+ /**
202
+ * List all deploys for a given release.
203
+ *
204
+ * @param {string} release Unique name of the release.
205
+ * @returns {Promise<string>} A promise that resolves when the list comes back from the server.
206
+ * @memberof SentryReleases
207
+ */
208
+ listDeploys(release) {
209
+ return __awaiter(this, void 0, void 0, function* () {
210
+ return this.execute(['releases', 'deploys', release, 'list'], null);
211
+ });
212
+ }
213
+ /**
214
+ * Creates a new release deployment. This should be called after the release has been
215
+ * finalized, while deploying on a given environment.
216
+ *
217
+ * @example
218
+ * await cli.releases.newDeploy(cli.releases.proposeVersion(), {
219
+ * // required options:
220
+ * env: 'production', // environment for this release. Values that make sense here would be 'production' or 'staging'
221
+ *
222
+ * // optional options:
223
+ * started: 42, // unix timestamp when the deployment started
224
+ * finished: 1337, // unix timestamp when the deployment finished
225
+ * time: 1295, // deployment duration in seconds. This can be specified alternatively to `started` and `finished`
226
+ * name: 'PickleRick', // human readable name for this deployment
227
+ * url: 'https://example.com', // URL that points to the deployment
228
+ * });
229
+ *
230
+ * @param {string} release Unique name of the release.
231
+ * @param {SentryCliNewDeployOptions} options Options to configure the new release deploy.
232
+ * @returns {Promise<string>} A promise that resolves when the deploy has been created.
233
+ * @memberof SentryReleases
234
+ */
235
+ newDeploy(release, options) {
236
+ return __awaiter(this, void 0, void 0, function* () {
237
+ if (!options || !options.env) {
238
+ throw new Error('options.env must be a valid name');
239
+ }
240
+ const args = ['releases', 'deploys', release, 'new'];
241
+ return this.execute(helper.prepareCommand(args, DEPLOYS_SCHEMA, options), null);
242
+ });
243
+ }
244
+ /**
245
+ * See {helper.execute} docs.
246
+ * @param {string[]} args Command line arguments passed to `sentry-cli`.
247
+ * @param {boolean | 'rejectOnError'} live can be set to:
248
+ * - `true` to inherit stdio to display `sentry-cli` output directly.
249
+ * - `false` to not inherit stdio and return the output as a string.
250
+ * - `'rejectOnError'` to inherit stdio and reject the promise if the command
251
+ * exits with a non-zero exit code.
252
+ * @returns {Promise<string>} A promise that resolves to the standard output.
253
+ */
254
+ execute(args, live) {
255
+ return __awaiter(this, void 0, void 0, function* () {
256
+ return helper.execute(args, live, this.options.silent, this.configFile, this.options);
257
+ });
254
258
  }
255
- const args = ['releases', 'deploys', release, 'new'];
256
- return this.execute(helper.prepareCommand(args, DEPLOYS_SCHEMA, options), null);
257
- }
258
-
259
- /**
260
- * See {helper.execute} docs.
261
- * @param {string[]} args Command line arguments passed to `sentry-cli`.
262
- * @param {boolean | 'rejectOnError'} live can be set to:
263
- * - `true` to inherit stdio to display `sentry-cli` output directly.
264
- * - `false` to not inherit stdio and return the output as a string.
265
- * - `'rejectOnError'` to inherit stdio and reject the promise if the command
266
- * exits with a non-zero exit code.
267
- * @returns {Promise.<string>} A promise that resolves to the standard output.
268
- */
269
- async execute(args, live) {
270
- return helper.execute(args, live, this.options.silent, this.configFile, this.options);
271
- }
272
259
  }
273
-
274
260
  module.exports = Releases;
@@ -0,0 +1,2 @@
1
+ declare const _exports: import("../../helper").OptionsSchema;
2
+ export = _exports;
@@ -2,28 +2,28 @@
2
2
  * @type {import('../../helper').OptionsSchema}
3
3
  */
4
4
  module.exports = {
5
- env: {
6
- param: '--env',
7
- type: 'string',
8
- },
9
- started: {
10
- param: '--started',
11
- type: 'number',
12
- },
13
- finished: {
14
- param: '--finished',
15
- type: 'number',
16
- },
17
- time: {
18
- param: '--time',
19
- type: 'number',
20
- },
21
- name: {
22
- param: '--name',
23
- type: 'string',
24
- },
25
- url: {
26
- param: '--url',
27
- type: 'string',
28
- },
5
+ env: {
6
+ param: '--env',
7
+ type: 'string',
8
+ },
9
+ started: {
10
+ param: '--started',
11
+ type: 'number',
12
+ },
13
+ finished: {
14
+ param: '--finished',
15
+ type: 'number',
16
+ },
17
+ time: {
18
+ param: '--time',
19
+ type: 'number',
20
+ },
21
+ name: {
22
+ param: '--name',
23
+ type: 'string',
24
+ },
25
+ url: {
26
+ param: '--url',
27
+ type: 'string',
28
+ },
29
29
  };
@@ -0,0 +1,2 @@
1
+ declare const _exports: import("../../helper").OptionsSchema;
2
+ export = _exports;