Skip to content

Commit

Permalink
Merge pull request #2266 from bugsnag/PLAT-13091/plugin-strip-query-s…
Browse files Browse the repository at this point in the history
…tring

Refactor @bugsnag/plugin-strip-query-string
  • Loading branch information
gingerbenw authored Nov 29, 2024
2 parents af49fb0 + b3677d9 commit 9a4591e
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 24 deletions.
17 changes: 15 additions & 2 deletions packages/plugin-strip-query-string/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
{
"name": "@bugsnag/plugin-strip-query-string",
"version": "8.1.1",
"main": "strip-query-string.js",
"main": "dist/strip-query-string.js",
"types": "dist/types/strip-query-string.d.ts",
"exports": {
".": {
"types": "./dist/types/strip-query-string.d.ts",
"default": "./dist/strip-query-string.js",
"import": "./dist/strip-query-string.mjs"
}
},
"description": "@bugsnag/js plugin to strip query string and document fragment from stackframe filenames",
"homepage": "https://www.bugsnag.com/",
"repository": {
Expand All @@ -12,7 +20,7 @@
"access": "public"
},
"files": [
"*.js"
"dist"
],
"author": "Bugsnag",
"license": "MIT",
Expand All @@ -21,5 +29,10 @@
},
"peerDependencies": {
"@bugsnag/core": "^8.0.0"
},
"scripts": {
"build": "npm run build:npm",
"build:npm": "rollup --config rollup.config.npm.mjs",
"clean": "rm -rf dist/*"
}
}
6 changes: 6 additions & 0 deletions packages/plugin-strip-query-string/rollup.config.npm.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import createRollupConfig from "../../.rollup/index.mjs";

export default createRollupConfig({
input: "src/strip-query-string.ts",
external: ["@bugsnag/core/lib/es-utils/map", "@bugsnag/core/lib/es-utils/reduce"]
});
29 changes: 29 additions & 0 deletions packages/plugin-strip-query-string/src/strip-query-string.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Remove query strings (and fragments) from stacktraces
*/
import { Plugin, Stackframe } from '@bugsnag/core'
import map from '@bugsnag/core/lib/es-utils/map'
import reduce from '@bugsnag/core/lib/es-utils/reduce'

const strip = (str: any) =>
typeof str === 'string'
? str.replace(/\?.*$/, '').replace(/#.*$/, '')
: str

interface ExtendedPlugin extends Plugin {
_strip: typeof strip
}

const plugin: ExtendedPlugin = {
load: (client) => {
client.addOnError(event => {
const allFrames: Stackframe[] = reduce(event.errors, (accum, er) => accum.concat(er.stacktrace), [])
map(allFrames, frame => {
frame.file = strip(frame.file)
})
})
},
_strip: strip
}

export default plugin
21 changes: 0 additions & 21 deletions packages/plugin-strip-query-string/strip-query-string.js

This file was deleted.

7 changes: 7 additions & 0 deletions packages/plugin-strip-query-string/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"include": ["src/**/*.ts"],
"compilerOptions": {
"target": "ES2020"
}
}
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
"packages/plugin-koa",
"packages/plugin-restify",
"packages/node",
"packages/plugin-strip-query-string",
"packages/plugin-strip-project-root",
"packages/plugin-interaction-breadcrumbs",
"packages/plugin-intercept",
Expand Down

0 comments on commit 9a4591e

Please sign in to comment.