-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: ♻️ refactor browser package to typescript
- Loading branch information
1 parent
c4e1afa
commit 5893f77
Showing
8 changed files
with
416 additions
and
114 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
declare module '@bugsnag/core/config' { | ||
export const schema: any | ||
} | ||
|
||
declare module '@bugsnag/plugin-window-onerror' { | ||
export default function pluginWindowOnerror(): any | ||
} | ||
|
||
declare module '@bugsnag/plugin-window-unhandled-rejection' { | ||
export default function pluginUnhandledRejection(): any | ||
} | ||
|
||
declare module '@bugsnag/plugin-app-duration' { | ||
export default function pluginApp(): any | ||
} | ||
|
||
declare module '@bugsnag/plugin-browser-device' { | ||
export default function pluginDevice(): any | ||
} | ||
|
||
declare module '@bugsnag/plugin-browser-context' { | ||
export default function pluginContext(): any | ||
} | ||
|
||
declare module '@bugsnag/plugin-browser-request' { | ||
export default function pluginRequest(): any | ||
} | ||
|
||
declare module '@bugsnag/plugin-simple-throttle' { | ||
export default function pluginThrottle(): any | ||
} | ||
|
||
declare module '@bugsnag/plugin-console-breadcrumbs' { | ||
export default function pluginConsoleBreadcrumbs(): any | ||
} | ||
|
||
declare module '@bugsnag/plugin-network-breadcrumbs' { | ||
export default function pluginNetworkBreadcrumbs(): any | ||
} | ||
|
||
declare module '@bugsnag/plugin-navigation-breadcrumbs' { | ||
export default function pluginNavigationBreadcrumbs(): any | ||
} | ||
|
||
declare module '@bugsnag/plugin-interaction-breadcrumbs' { | ||
export default function pluginInteractionBreadcrumbs(): any | ||
} | ||
|
||
declare module '@bugsnag/plugin-inline-script-content' { | ||
export default function pluginInlineScriptContent(): any | ||
} | ||
|
||
declare module '@bugsnag/plugin-browser-session' { | ||
export default function pluginSession(): any | ||
} | ||
|
||
declare module '@bugsnag/plugin-client-ip' { | ||
export default function pluginIp(): any | ||
} | ||
|
||
declare module '@bugsnag/plugin-strip-query-string' { | ||
export default function pluginStripQueryString(): any | ||
} |
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,53 @@ | ||
import fs from 'fs' | ||
import terser from '@rollup/plugin-terser' | ||
import replace from '@rollup/plugin-replace' | ||
import commonjs from '@rollup/plugin-commonjs' | ||
import typescript from '@rollup/plugin-typescript' | ||
import nodeResolve from '@rollup/plugin-node-resolve' | ||
|
||
// the built files for the CDN go in the top-level 'build' directory so they | ||
// can't accidentally be uploaded to NPM somehow | ||
const buildDirectory = './dist' | ||
|
||
if (!fs.existsSync(buildDirectory)) { | ||
fs.mkdirSync(buildDirectory) | ||
} | ||
|
||
const packageJson = JSON.parse(fs.readFileSync('./package.json')) | ||
|
||
const sharedOutputOptions = { | ||
format: 'es', | ||
name: 'Bugsnag', | ||
generatedCode: { | ||
preset: 'es2015', | ||
}, | ||
sourcemap: true, | ||
} | ||
|
||
export default { | ||
input: 'src/notifier.ts', | ||
output: [ | ||
{ | ||
...sharedOutputOptions, | ||
file: `${buildDirectory}/bugsnag.js`, | ||
}, | ||
{ | ||
...sharedOutputOptions, | ||
file: `${buildDirectory}/bugsnag.min.js`, | ||
compact: true, | ||
plugins: [terser({ ecma: 2015 })], | ||
}, | ||
], | ||
plugins: [ | ||
replace({ | ||
preventAssignment: true, | ||
values: { __VERSION__: packageJson.version }, | ||
}), | ||
typescript({ | ||
// don't output anything if there's a TS error | ||
noEmitOnError: true, | ||
}), | ||
commonjs(), | ||
nodeResolve({ browser: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import createRollupConfig from '../../.rollup/index.mjs' | ||
|
||
export default createRollupConfig({ | ||
internal: 'src/notifier.ts', | ||
external: [ | ||
"@bugsnag/core/breadcrumb", | ||
"@bugsnag/core/client", | ||
"@bugsnag/core/config", | ||
"@bugsnag/core/event", | ||
"@bugsnag/core/lib/es-utils/map", | ||
"@bugsnag/core/lib/es-utils/keys", | ||
"@bugsnag/core/lib/es-utils/assign", | ||
"@bugsnag/core/session", | ||
"@bugsnag/delivery-x-domain-request", | ||
"@bugsnag/delivery-xml-http-request", | ||
"@bugsnag/plugin-app-duration", | ||
"@bugsnag/plugin-browser-context", | ||
"@bugsnag/plugin-browser-device", | ||
"@bugsnag/plugin-browser-request", | ||
"@bugsnag/plugin-browser-session", | ||
"@bugsnag/plugin-client-ip", | ||
"@bugsnag/plugin-console-breadcrumbs", | ||
"@bugsnag/plugin-inline-script-content", | ||
"@bugsnag/plugin-interaction-breadcrumbs", | ||
"@bugsnag/plugin-navigation-breadcrumbs", | ||
"@bugsnag/plugin-network-breadcrumbs", | ||
"@bugsnag/plugin-simple-throttle", | ||
"@bugsnag/plugin-strip-query-string", | ||
"@bugsnag/plugin-window-onerror", | ||
"@bugsnag/plugin-window-unhandled-rejection" | ||
], | ||
}) |
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,45 @@ | ||
import { Config } from '@bugsnag/core' | ||
import { schema } from '@bugsnag/core/config' | ||
import assign from '@bugsnag/core/lib/es-utils/assign' | ||
import map from '@bugsnag/core/lib/es-utils/map' | ||
|
||
export interface BrowserConfig extends Config { | ||
maxEvents?: number | ||
collectUserIp?: boolean | ||
generateAnonymousId?: boolean | ||
trackInlineScripts?: boolean | ||
} | ||
|
||
export default { | ||
releaseStage: assign({}, schema.releaseStage, { | ||
defaultValue: () => { | ||
if (/^localhost(:\d+)?$/.test(window.location.host)) return 'development' | ||
return 'production' | ||
} | ||
}), | ||
appType: { | ||
...schema.appType, | ||
defaultValue: () => 'browser' | ||
}, | ||
logger: assign({}, schema.logger, { | ||
defaultValue: () => | ||
// set logger based on browser capability | ||
(typeof console !== 'undefined' && typeof console.debug === 'function') | ||
? getPrefixedConsole() | ||
: undefined | ||
}) | ||
} | ||
|
||
type ConsoleMethods = 'debug' | 'info' | 'warn' | 'error' | ||
|
||
const getPrefixedConsole = () => { | ||
const logger: Record<string, () => void> = {} | ||
const consoleLog = console.log | ||
map(['debug', 'info', 'warn', 'error'], (method: ConsoleMethods) => { | ||
const consoleMethod = console[method] | ||
logger[method] = typeof consoleMethod === 'function' | ||
? consoleMethod.bind(console, '[bugsnag]') | ||
: consoleLog.bind(console, '[bugsnag]') | ||
}) | ||
return logger | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.