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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- "Would I rather be feared or loved? Easy. Both. I want people to be afraid of how much they love me." — Michael Scott

- fix: Fix types and array normalization for `include` option (#FIXME!!)

## v1.17.0

- feat: Allow `include` option to be an object (#299)
Expand Down
2 changes: 1 addition & 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`/`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. |
| 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. Each path 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
16 changes: 14 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
SentryCliNewDeployOptions,
SentryCliOptions,
SentryCliUploadSourceMapsOptions,
SourceMapsPathDescriptor,
} from '@sentry/cli';

export interface SentryCliPluginOptions
Expand All @@ -13,8 +14,6 @@ export interface SentryCliPluginOptions
>,
Pick<
SentryCliUploadSourceMapsOptions,
| 'include'
| 'ignore'
| 'ignoreFile'
| 'rewrite'
| 'sourceMapReference'
Expand All @@ -25,6 +24,19 @@ export interface SentryCliPluginOptions
| 'urlSuffix'
| 'ext'
> {
/**
* Filepaths to scan recursively for source and source map files
*/
include:
| string
| SourceMapsPathDescriptor
| Array<string | SourceMapsPathDescriptor>;

/**
* Filepaths to ignore when scanning for sources and source maps
*/
ignore?: string | Array<string>;

/**
* Unique name of a release, must be a string, should uniquely identify your release,
* defaults to sentry-cli releases propose-version command which should always return the correct version
Expand Down
64 changes: 47 additions & 17 deletions src/__tests__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,42 +50,72 @@ describe('constructor', () => {
expect(sentryCliPlugin.options.rewrite).toEqual(false);
});

test('sanitizes array options `include` and `ignore`', () => {
const sentryCliPlugin = new SentryCliPlugin({
test('sanitizes non-array options `include` and `ignore`', () => {
const pluginWithStringInclude = new SentryCliPlugin({
include: 'foo',
ignore: 'bar',
});
expect(sentryCliPlugin.options.include).toEqual(['foo']);
expect(sentryCliPlugin.options.ignore).toEqual(['bar']);
expect(pluginWithStringInclude.options.include).toEqual(['foo']);
expect(pluginWithStringInclude.options.ignore).toEqual(['bar']);

const pluginWithObjectInclude = new SentryCliPlugin({
include: { paths: ['foo'], urlPrefix: '~/bar/' },
});
expect(pluginWithObjectInclude.options.include).toEqual([
{ paths: ['foo'], urlPrefix: '~/bar/' },
]);
});

test('keeps array options `include` and `ignore`', () => {
const sentryCliPlugin = new SentryCliPlugin({
const pluginWithStringArrayInclude = new SentryCliPlugin({
include: ['foo'],
ignore: ['bar'],
});
expect(sentryCliPlugin.options.include).toEqual(['foo']);
expect(sentryCliPlugin.options.ignore).toEqual(['bar']);
expect(pluginWithStringArrayInclude.options.include).toEqual(['foo']);
expect(pluginWithStringArrayInclude.options.ignore).toEqual(['bar']);

const pluginWithObjectArrayInclude = new SentryCliPlugin({
include: { paths: ['foo'], urlPrefix: '~/bar/' },
});
expect(pluginWithObjectArrayInclude.options.include).toEqual([
{ paths: ['foo'], urlPrefix: '~/bar/' },
]);
});

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

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

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

Expand Down
17 changes: 11 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,18 @@ class SentryCliPlugin {
// 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);
}
this.options.include = toArray(options.include);
this.options.include.forEach(includeEntry => {
if (
typeof includeEntry === 'object' &&
includeEntry.ignore !== undefined
) {
// eslint-disable-next-line no-param-reassign
includeEntry.ignore = toArray(includeEntry.ignore);
}
});
}

if (options.ignore) this.options.ignore = toArray(options.ignore);

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