Skip to content

Commit e3d49c4

Browse files
Convert @bugsnag/plugin-strip-project-root to TypeScript (#2520)
* convert plugin strip project root to TypeScript * update import
1 parent aea20e4 commit e3d49c4

File tree

7 files changed

+48
-7
lines changed

7 files changed

+48
-7
lines changed

package-lock.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/plugin-strip-project-root/package.json

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
{
22
"name": "@bugsnag/plugin-strip-project-root",
33
"version": "8.4.0",
4-
"main": "strip-project-root.js",
4+
"main": "dist/strip-project-root.js",
5+
"types": "dist/types/strip-project-root.d.ts",
6+
"exports": {
7+
".": {
8+
"types": "./dist/types/strip-project-root.d.ts",
9+
"default": "./dist/strip-project-root.js",
10+
"import": "./dist/strip-project-root.mjs"
11+
}
12+
},
513
"description": "@bugsnag/js plugin to remove common project root paths from stacktraces",
614
"homepage": "https://www.bugsnag.com/",
715
"repository": {
@@ -12,11 +20,20 @@
1220
"access": "public"
1321
},
1422
"files": [
15-
"*.js"
23+
"dist"
1624
],
1725
"author": "Bugsnag",
1826
"license": "MIT",
1927
"dependencies": {
2028
"@bugsnag/path-normalizer": "^8.4.0"
29+
},
30+
"devDependencies": {
31+
"@bugsnag/core": "^8.4.0"
32+
},
33+
"scripts": {
34+
"build": "npm run build:npm",
35+
"build:npm": "rollup --config rollup.config.npm.mjs",
36+
"clean": "rm -rf dist/*",
37+
"test:types": "tsc -p tsconfig.json"
2138
}
2239
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import createRollupConfig from "../../.rollup/index.mjs";
2+
3+
export default createRollupConfig({
4+
input: "src/strip-project-root.ts",
5+
external: ["@bugsnag/path-normalizer"],
6+
});
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
const normalizePath = require('@bugsnag/path-normalizer')
1+
import type { Config, Plugin, Stackframe } from '@bugsnag/core'
2+
import normalizePath from '@bugsnag/path-normalizer'
23

3-
module.exports = {
4+
interface PluginConfig extends Config {
5+
projectRoot?: string
6+
}
7+
8+
const plugin: Plugin<PluginConfig> = {
49
load: client => client.addOnError(event => {
510
if (!client._config.projectRoot) return
611
const projectRoot = normalizePath(client._config.projectRoot)
7-
const allFrames = event.errors.reduce((accum, er) => accum.concat(er.stacktrace), [])
12+
const allFrames: Stackframe[] = event.errors.reduce((accum: Stackframe[], er) => accum.concat(er.stacktrace), [])
813
allFrames.map(stackframe => {
914
if (typeof stackframe.file === 'string' && stackframe.file.indexOf(projectRoot) === 0) {
1015
stackframe.file = stackframe.file.replace(projectRoot, '')
1116
}
1217
})
1318
})
1419
}
20+
21+
export default plugin

packages/plugin-strip-project-root/test/strip-project-root.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import plugin from '../'
1+
import plugin from '../src/strip-project-root'
22
import { join } from 'path'
33
import { Client, Event, schema } from '@bugsnag/core'
44

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"include": ["src/**/*.ts"],
4+
"compilerOptions": {
5+
"lib": ["es2017"],
6+
"types": ["node"]
7+
}
8+
}

tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"packages/plugin-koa",
2929
"packages/plugin-restify",
3030
"packages/node",
31-
"packages/plugin-strip-project-root",
3231
"packages/plugin-interaction-breadcrumbs",
3332
"packages/plugin-intercept",
3433
"packages/browser"

0 commit comments

Comments
 (0)