-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert @bugsnag/plugin-browser-request to TypeScript (#2236)
* refactor: ♻️ convert plugin-window-onerror to typescript * update rollup configuration * Convert plugin-browser-request to TypeScript * changed tsconfig * fix: 🩹 update main entry from ts to js * fix: 🩹 add missing external dependencies to rollup config * chore: 🏷️ update types and remove ts-expect-error comments * remove unnecessary rollup config * chore: 🏷️ fix types * chore: 🔥 remove IE8 workaround code * fix: 🩹 fix RN init command --------- Co-authored-by: Ben Wilson <[email protected]>
- Loading branch information
1 parent
344a1dc
commit 2b386b5
Showing
12 changed files
with
104 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/request.ts", | ||
external: ['@bugsnag/core/lib/es-utils/assign'] | ||
}); |
6 changes: 4 additions & 2 deletions
6
packages/plugin-browser-request/request.js → ...ges/plugin-browser-request/src/request.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
const assign = require('@bugsnag/core/lib/es-utils/assign') | ||
import { Plugin } from '@bugsnag/core' | ||
import assign from '@bugsnag/core/lib/es-utils/assign' | ||
|
||
/* | ||
* Sets the event request: { url } to be the current href | ||
*/ | ||
module.exports = (win = window) => ({ | ||
export default (win = window): Plugin => ({ | ||
load: (client) => { | ||
client.addOnError(event => { | ||
if (event.request && event.request.url) return | ||
event.request = assign({}, event.request, { url: win.location.href }) | ||
// @ts-expect-error second parameter is private API | ||
}, true) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"include": ["src/**/*.ts"], | ||
"compilerOptions": { | ||
"target": "ES2020" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ | |
"access": "public" | ||
}, | ||
"files": [ | ||
"*.js" | ||
"dist" | ||
], | ||
"author": "Bugsnag", | ||
"license": "MIT", | ||
|
3 changes: 2 additions & 1 deletion
3
packages/plugin-window-unhandled-rejection/rollup.config.npm.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import createRollupConfig from '../../.rollup/index.mjs' | ||
|
||
export default createRollupConfig({ | ||
input: 'src/unhandled-rejection.ts' | ||
input: 'src/unhandled-rejection.ts', | ||
external: ['@bugsnag/core/lib/iserror', '@bugsnag/core/lib/es-utils/map'] | ||
}) |
29 changes: 29 additions & 0 deletions
29
packages/plugin-window-unhandled-rejection/src/fix-bluebird-stacktrace.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Stackframe } from 'packages/core/types' | ||
|
||
// The stack parser on bluebird stacks in FF get a suprious first frame: | ||
// | ||
// Error: derp | ||
// b@http://localhost:5000/bluebird.html:22:24 | ||
// a@http://localhost:5000/bluebird.html:18:9 | ||
// @http://localhost:5000/bluebird.html:14:9 | ||
// | ||
// results in | ||
// […] | ||
// 0: Object { file: "Error: derp", method: undefined, lineNumber: undefined, … } | ||
// 1: Object { file: "http://localhost:5000/bluebird.html", method: "b", lineNumber: 22, … } | ||
// 2: Object { file: "http://localhost:5000/bluebird.html", method: "a", lineNumber: 18, … } | ||
// 3: Object { file: "http://localhost:5000/bluebird.html", lineNumber: 14, columnNumber: 9, … } | ||
// | ||
// so the following reduce/accumulator function removes such frames | ||
// | ||
// Bluebird pads method names with spaces so trim that too… | ||
|
||
// https://github.com/petkaantonov/bluebird/blob/b7f21399816d02f979fe434585334ce901dcaf44/src/debuggability.js#L568-L571 | ||
const fixBluebirdStacktrace = (error: PromiseRejectionEvent['reason']) => (frame: Stackframe) => { | ||
if (frame.file === error.toString()) return | ||
if (frame.method) { | ||
frame.method = frame.method.replace(/^\s+/, '') | ||
} | ||
} | ||
|
||
export default fixBluebirdStacktrace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters