Skip to content
This repository was archived by the owner on Nov 20, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Also, check the [example](example) directory.

| Option | Type | Required | Description |
| ------------------ | ----------------------------------------------------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| include | `string`/`array` | required | One or more paths that Sentry CLI should scan recursively for sources. It will upload all `.map` files and match associated `.js` files. |
| include | `string`/`array`/`object` | required | One or more paths that Sentry CLI should scan recursively for sources. It will upload all `.map` files and match associated `.js` files. Can be given as an object with path-specific options. See [table below](#include) for details. |
| org | `string` | optional | The slug of the Sentry organization associated with the app. |
| project | `string` | optional | The slug of the Sentry project associated with the app. |
| authToken | `string` | optional | The authentication token to use for all communication with Sentry. Can be obtained from https://sentry.io/settings/account/api/auth-tokens/. Required scopes: `project:releases` (and `org:read` if `setCommits` option is used). |
Expand Down Expand Up @@ -89,6 +89,21 @@ Also, check the [example](example) directory.
| setCommits | `Object` | optional | Adds commits to Sentry. See [table below](#setCommits) for details. |
| deploy | `Object` | optional | Creates a new release deployment in Sentry. See [table below](#deploy) for details. |

#### <a name="include"></a>options.include:

| Option | Type | Required | Description |
| ------------------ | ---------------- | -------- | ---------------------------------------------- |
| paths | `array` | required | One or more paths to scan for files to upload. |
| ignoreFile | `string` | optional | See above. |
| ignore | `string`/`array` | optional | See above. |
| ext | `array` | optional | See above. |
| urlPrefix | `string` | optional | See above. |
| urlSuffix | `string` | optional | See above. |
| stripPrefix | `array` | optional | See above. |
| stripCommonPrefix | `boolean` | optional | See above. |
| sourceMapReference | `boolean` | optional | See above. |
| rewrite | `boolean` | optional | See above. |

#### <a name="setCommits"></a>options.setCommits:

| Option | Type | Required | Description |
Expand Down
20 changes: 20 additions & 0 deletions src/__tests__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,26 @@ describe('constructor', () => {
expect(sentryCliPlugin.options.include).toEqual(['foo']);
expect(sentryCliPlugin.options.ignore).toEqual(['bar']);
});

test('keeps object `ignore` option', () => {
const sentryCliPlugin = new SentryCliPlugin({
include: { paths: ['foo'], urlPrefix: '~/bar/' },
});
expect(sentryCliPlugin.options.include).toEqual({
paths: ['foo'],
urlPrefix: '~/bar/',
});
});

test('sanitizes `ignore` array option in object `ignore` option', () => {
const sentryCliPlugin = new SentryCliPlugin({
include: { paths: ['foo'], ignore: 'bar' },
});
expect(sentryCliPlugin.options.include).toEqual({
paths: ['foo'],
ignore: ['bar'],
});
});
});

describe('CLI configuration', () => {
Expand Down
24 changes: 19 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,18 @@ function getLoaderName(entry) {
}

/**
* Ensures that the passed value is in an array or an array itself.
* Wraps the given value in an array if it is not already an array itself.
* Ignores `undefined` and `null`, returning them as is.
*
* @param {any} value Either an array or a value that should be wrapped
* @returns {array} The array
* @param {any} value Either an array or a value that should be wrapped in an array
* @returns {array} The resulting array, or the original value if it's null/undefined
*/
function toArray(value) {
return !value || Array.isArray(value) ? value : [value];
if (Array.isArray(value) || value === null || value === undefined) {
return value;
}

return [value];
}

/** Backwards compatible version of `compiler.plugin.afterEmit.tapAsync()`. */
Expand All @@ -78,7 +83,16 @@ class SentryCliPlugin {

this.options = Object.assign({}, defaults, options);

if (options.include) this.options.include = toArray(options.include);
// the webpack plugin has looser type requirements than `@sentry/cli` -
// ensure `include` and `ignore` options are in the right format
if (options.include) {
if (typeof options.include === 'string') {
this.options.include = toArray(options.include);
}
if (typeof options.include === 'object') {
this.options.include.ignore = toArray(options.include.ignore);
}
}
if (options.ignore) this.options.ignore = toArray(options.ignore);

this.cli = this.getSentryCli();
Expand Down