Skip to content

Commit

Permalink
chore: use picomatch to match against glob patterns
Browse files Browse the repository at this point in the history
Refs: #1053
  • Loading branch information
subzero10 committed Apr 26, 2023
1 parent 4bb32eb commit e5b7b36
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/rollup-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ These plugin parameters correspond to the Honeybadger [Source Map Upload API](ht
</dd>

<dt><code>ignorePaths</code> (optional &mdash; default: [])</dt>
<dd>An array of paths to ignore when uploading sourcemaps. Regex is also supported.
<dd>An array of paths (glob patterns) to ignore when uploading sourcemaps. Uses <a href="https://github.com/micromatch/picomatch">picomatch</a> to match against paths.
</dd>

<dt><code>deployEndpoint</code> (optional &mdash; default: "https://api.honeybadger.io/v1/deploys")</dt>
Expand Down
3 changes: 2 additions & 1 deletion packages/rollup-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
"dependencies": {
"fetch-retry": "^5.0.3",
"form-data": "^4.0.0",
"node-fetch": "^2.6.9"
"node-fetch": "^2.6.9",
"picomatch": "^2.3.1"
},
"main": "dist/cjs/index.js",
"module": "dist/es/index.js",
Expand Down
9 changes: 3 additions & 6 deletions packages/rollup-plugin/src/rollupUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from 'node:path'
import picomatch from 'picomatch'

import type { OutputBundle, OutputAsset, OutputChunk, NormalizedOutputOptions } from 'rollup'
import type { SourcemapInfo } from './types'
Expand Down Expand Up @@ -31,12 +32,8 @@ function isSourcemap(file: OutputAsset | OutputChunk): file is OutputAsset {

function isNotIgnored(sourceMapInfo: SourcemapInfo, ignorePaths: Array<string | RegExp>) {
for (const ignorePath of ignorePaths) {
let regex = ignorePath
if (!(regex instanceof RegExp)) {
regex = new RegExp(regex)
}

if (regex.test(sourceMapInfo.jsFilePath)) {
const isMatch = picomatch.isMatch(sourceMapInfo.jsFilePath, ignorePath, { basename: true })
if (isMatch) {
return false
}
}
Expand Down
31 changes: 30 additions & 1 deletion packages/rollup-plugin/test/fixtures/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,35 @@ const chunks = {
'module.exports = bar;\n',
map: null
},
'empty.sass': {
exports: [ 'default' ],
facadeModuleId: '/Users/bethanyberkowitz/projects/honeybadger/honeybadger-js/packages/rollup-plugin/examples/rollup/src/empty.sass',
isDynamicEntry: false,
isEntry: false,
isImplicitEntry: false,
moduleIds: [
'/Users/bethanyberkowitz/projects/honeybadger/honeybadger-js/packages/rollup-plugin/examples/rollup/src/empty.sass'
],
name: 'empty',
type: 'chunk' as const,
dynamicImports: [],
fileName: 'empty.sass',
implicitlyLoadedBefore: [],
importedBindings: {},
imports: [],
modules: {
'/Users/bethanyberkowitz/projects/honeybadger/honeybadger-js/packages/rollup-plugin/examples/rollup/src/empty.sass': {
'code': 'color: blue;',
'originalLength': 12,
'removedExports': [],
'renderedExports': ['default'],
'renderedLength': 12
}
},
referencedFiles: [],
code: 'color: blue;',
map: null
},
}

const assets = {
Expand Down Expand Up @@ -130,7 +159,7 @@ const assets = {
'empty.js.map': {
fileName: 'empty.js.map',
name: undefined,
source: '{"version":3,"file":"empty.js","sources":[], "sourcesContent": [], "names":[],"mappings":""}',
source: '{"version":3,"file":"empty.sass","sources":[], "sourcesContent": [], "names":[],"mappings":""}',
type: 'asset' as const,
needsCodeReference: false
}
Expand Down
6 changes: 3 additions & 3 deletions packages/rollup-plugin/test/rollupUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ describe('extractSourcemapDataFromBundle', () => {
])
})

const itEach = ['foo.js', /foo.js/, 'foo.*', /foo.*/]
const itEach = ['foo.js', '**/foo.js', 'foo.*', '**/foo.*', 'foo.js*', '**/foo.js*']
for (const ignorePath of itEach) {
it(`should ignore files that match the ignorePaths ${ignorePath}`, () => {
it(`should ignore files that match the ignorePath ${ignorePath}`, () => {
const data = extractSourcemapDataFromBundle(outputOptions, bundle, [ignorePath])
expect(data).to.be.an('array').lengthOf(2)
expect(data).to.have.deep.members([
Expand All @@ -61,7 +61,7 @@ describe('extractSourcemapDataFromBundle', () => {
expect(bundle['empty.js.map']).to.deep.equal({
fileName: 'empty.js.map',
name: undefined,
source: '{"version":3,"file":"empty.js","sources":[], "sourcesContent": [], "names":[],"mappings":""}',
source: '{"version":3,"file":"empty.sass","sources":[], "sourcesContent": [], "names":[],"mappings":""}',
type: 'asset' as const,
needsCodeReference: false,
})
Expand Down

0 comments on commit e5b7b36

Please sign in to comment.