Skip to content

Commit

Permalink
Convert plugin-browser-context to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
AnastasiiaSvietlova committed Oct 24, 2024
1 parent 0b18a5e commit 8aaaf95
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 6 deletions.
17 changes: 15 additions & 2 deletions packages/plugin-browser-context/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
{
"name": "@bugsnag/plugin-browser-context",
"version": "8.0.0",
"main": "context.js",
"main": "dist/context.ts",
"types": "dist/types/context.d.ts",
"exports": {
".": {
"types": "./dist/types/context.d.ts",
"default": "./dist/context.js",
"import": "./dist/context.mjs"
}
},
"description": "@bugsnag/js plugin to set event context in browsers",
"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/*"
}
}
5 changes: 5 additions & 0 deletions packages/plugin-browser-context/rollup.config.npm.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import createRollupConfig from "../../.rollup/index.mjs";

export default createRollupConfig({
input: "src/context.ts"
});
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { Plugin } from '@bugsnag/core'

/*
* Sets the default context to be the current URL
*/
module.exports = (win = window) => ({
load: (client) => {
export default (win = window): Plugin => ({
load: client => {
client.addOnError(event => {
if (event.context !== undefined) return
event.context = win.location.pathname
// @ts-expect-error second parameter is private API
}, true)
}
})
2 changes: 1 addition & 1 deletion packages/plugin-browser-context/test/context.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import plugin from '../'
import plugin from '../src/context'

import Client, { EventDeliveryPayload } from '@bugsnag/core/client'

Expand Down
7 changes: 7 additions & 0 deletions packages/plugin-browser-context/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 @@ -67,7 +67,6 @@
"packages/delivery-xml-http-request",
"packages/in-flight",
"packages/plugin-aws-lambda",
"packages/plugin-browser-context",
"packages/plugin-contextualize",
"packages/plugin-navigation-breadcrumbs",
"packages/plugin-network-breadcrumbs",
Expand Down

0 comments on commit 8aaaf95

Please sign in to comment.