diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a943038..800a7f76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/README.md b/README.md index c77c649b..302c69cf 100644 --- a/README.md +++ b/README.md @@ -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). | diff --git a/index.d.ts b/index.d.ts index 4758e437..1fbeea1d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -4,6 +4,7 @@ import { SentryCliNewDeployOptions, SentryCliOptions, SentryCliUploadSourceMapsOptions, + SourceMapsPathDescriptor, } from '@sentry/cli'; export interface SentryCliPluginOptions @@ -13,8 +14,6 @@ export interface SentryCliPluginOptions >, Pick< SentryCliUploadSourceMapsOptions, - | 'include' - | 'ignore' | 'ignoreFile' | 'rewrite' | 'sourceMapReference' @@ -25,6 +24,19 @@ export interface SentryCliPluginOptions | 'urlSuffix' | 'ext' > { + /** + * Filepaths to scan recursively for source and source map files + */ + include: + | string + | SourceMapsPathDescriptor + | Array; + + /** + * Filepaths to ignore when scanning for sources and source maps + */ + ignore?: string | Array; + /** * 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 diff --git a/src/__tests__/index.spec.js b/src/__tests__/index.spec.js index 6e4fbc8a..d2616f52 100644 --- a/src/__tests__/index.spec.js +++ b/src/__tests__/index.spec.js @@ -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'], + }, + ]); }); }); diff --git a/src/index.js b/src/index.js index 8ea8312d..bc82e6cd 100644 --- a/src/index.js +++ b/src/index.js @@ -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();