Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove @bugsnag/core/lib/es-utils/map #2336

Draft
wants to merge 2 commits into
base: plat-12947-8
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions packages/browser/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
import { schema } from '@bugsnag/core'
import assign from '@bugsnag/core/lib/es-utils/assign'
import getPrefixedConsole from './get-prefixed-console'

const config = {
releaseStage: assign({}, schema.releaseStage, {
defaultValue: () => {
if (/^localhost(:\d+)?$/.test(window.location.host)) return 'development'
return 'production'
releaseStage: {
...schema.releaseStage, ...{
defaultValue: () => {
if (/^localhost(:\d+)?$/.test(window.location.host)) return 'development'
return 'production'
}
}
}),
appType: assign({}, schema.appType, {
defaultValue: () => 'browser'
}),
logger: assign({}, schema.logger, {
defaultValue: () =>
// set logger based on browser capability
(typeof console !== 'undefined' && typeof console.debug === 'function')
? getPrefixedConsole()
: undefined
})
},
appType: {
...schema.appType, ...{
defaultValue: () => 'browser'
}
},
logger: {
...schema.logger, ...{
defaultValue: () =>
// set logger based on browser capability
(typeof console !== 'undefined' && typeof console.debug === 'function')
? getPrefixedConsole()
: undefined
}
}
}

export default config
5 changes: 2 additions & 3 deletions packages/browser/src/get-prefixed-console.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import map from '@bugsnag/core/lib/es-utils/map'

type LoggerMethod = 'debug' | 'info' | 'warn' | 'error'

const getPrefixedConsole = () => {
const logger: Record<string, unknown> = {}
const consoleLog = console.log
map(['debug', 'info', 'warn', 'error'], (method: LoggerMethod) => {
const loggerMethods = ['debug', 'info', 'warn', 'error'] as const
loggerMethods.map((method: LoggerMethod) => {
const consoleMethod = console[method]
logger[method] = typeof consoleMethod === 'function'
? consoleMethod.bind(console, '[bugsnag]')
Expand Down
1 change: 0 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"./lib/json-payload": "./src/lib/json-payload.js",
"./lib/es-utils/assign": "./src/lib/es-utils/assign.js",
"./lib/validators/int-range": "./src/lib/validators/int-range.js",
"./lib/es-utils/map": "./src/lib/es-utils/map.js",
"./lib/es-utils/includes": "./src/lib/es-utils/includes.js",
"./lib/es-utils/filter": "./src/lib/es-utils/filter.js",
"./lib/iserror": "./src/lib/iserror.js",
Expand Down
4 changes: 1 addition & 3 deletions packages/core/src/lib/feature-flag-delegate.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const map = require('./es-utils/map')
const filter = require('./es-utils/filter')
const isArray = require('./es-utils/is-array')
const jsonStringify = require('@bugsnag/safe-json-stringify')
Expand Down Expand Up @@ -47,8 +46,7 @@ function merge (existingFeatures, newFeatures, existingFeatureKeys) {
// by the Bugsnag Event API:
// [{ featureFlag: 'name', variant: 'variant' }, { featureFlag: 'name 2' }]
function toEventApi (featureFlags) {
return map(
filter(featureFlags, Boolean),
return filter(featureFlags, Boolean).map(
({ name, variant }) => {
const flag = { featureFlag: name }

Expand Down
8 changes: 0 additions & 8 deletions packages/core/test/lib/es-utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import map from '../../src/lib/es-utils/map'
import reduce from '../../src/lib/es-utils/reduce'
import filter from '../../src/lib/es-utils/filter'
import keys from '../../src/lib/es-utils/keys'
Expand All @@ -13,13 +12,6 @@ describe('es-utils', () => {
})
})

describe('map(arr, fn)', () => {
it('works with a variety of examples', () => {
expect(map(['a', 'b', 'c'], x => x)).toEqual(['a', 'b', 'c'])
expect(map(['a', 'b', 'c'], (x) => x.toUpperCase())).toEqual(['A', 'B', 'C'])
})
})

describe('filter(arr, fn)', () => {
it('works with a variety of examples', () => {
const arr = ['a', 0, false, undefined, 1, 'undefined']
Expand Down
5 changes: 2 additions & 3 deletions packages/node/src/get-prefixed-console.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import map from '@bugsnag/core/lib/es-utils/map'

type LoggerMethod = 'debug' | 'info' | 'warn' | 'error'

const getPrefixedConsole = () => {
const logger: Record<string, unknown> = {}
const consoleLog = console.log
map(['debug', 'info', 'warn', 'error'], (method: LoggerMethod) => {
const loggerMethods = ['debug', 'info', 'warn', 'error'] as const
loggerMethods.map((method: LoggerMethod) => {
const consoleMethod = console[method]
logger[method] = typeof consoleMethod === 'function'
? consoleMethod.bind(console, '[bugsnag]')
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-console-breadcrumbs/rollup.config.npm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import createRollupConfig from "../../.rollup/index.mjs";

export default createRollupConfig({
input: "src/console-breadcrumbs.ts",
external: ['@bugsnag/core', "@bugsnag/core/lib/es-utils/filter", "@bugsnag/core/lib/es-utils/map", "@bugsnag/core/lib/es-utils/reduce"]
external: ['@bugsnag/core', "@bugsnag/core/lib/es-utils/filter", "@bugsnag/core/lib/es-utils/reduce"]
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Client, Config, Plugin } from '@bugsnag/core'
import filter from '@bugsnag/core/lib/es-utils/filter'
import map from '@bugsnag/core/lib/es-utils/map'
import reduce from '@bugsnag/core/lib/es-utils/reduce'

type ConsoleMethod = 'log' | 'debug' | 'info' | 'warn' | 'error'
Expand All @@ -23,7 +22,7 @@ const plugin: Plugin = {

if (isDev || !(client as ClientWithInternals)._isBreadcrumbTypeEnabled('log')) return

map(CONSOLE_LOG_METHODS, method => {
CONSOLE_LOG_METHODS.map(method => {
const original = console[method]
console[method] = (...args: any) => {
client.leaveBreadcrumb(
Expand Down
12 changes: 5 additions & 7 deletions packages/plugin-inline-script-content/inline-script-content.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const map = require('@bugsnag/core/lib/es-utils/map')
const reduce = require('@bugsnag/core/lib/es-utils/reduce')
const filter = require('@bugsnag/core/lib/es-utils/filter')

Expand Down Expand Up @@ -91,28 +90,27 @@ module.exports = (doc = document, win = window) => ({

// Proxy all the timer functions whose callback is their 0th argument.
// Keep a reference to the original setTimeout because we need it later
const [_setTimeout] = map([
const [_setTimeout] = [
'setTimeout',
'setInterval',
'setImmediate',
'requestAnimationFrame'
], fn =>
].map(fn =>
__proxy(win, fn, original =>
__traceOriginalScript(original, args => ({
get: () => args[0],
replace: fn => { args[0] = fn }
}))
)
)

;
// Proxy all the host objects whose prototypes have an addEventListener function
map([
'EventTarget', 'Window', 'Node', 'ApplicationCache', 'AudioTrackList', 'ChannelMergerNode',
[ 'EventTarget', 'Window', 'Node', 'ApplicationCache', 'AudioTrackList', 'ChannelMergerNode',
'CryptoOperation', 'EventSource', 'FileReader', 'HTMLUnknownElement', 'IDBDatabase',
'IDBRequest', 'IDBTransaction', 'KeyOperation', 'MediaController', 'MessagePort', 'ModalWindow',
'Notification', 'SVGElementInstance', 'Screen', 'TextTrack', 'TextTrackCue', 'TextTrackList',
'WebSocket', 'WebSocketWorker', 'Worker', 'XMLHttpRequest', 'XMLHttpRequestEventTarget', 'XMLHttpRequestUpload'
], o => {
].map(o => {
if (!win[o] || !win[o].prototype || !Object.prototype.hasOwnProperty.call(win[o].prototype, 'addEventListener')) return
__proxy(win[o].prototype, 'addEventListener', original =>
__traceOriginalScript(original, eventTargetCallbackAccessor)
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-strip-query-string/rollup.config.npm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import createRollupConfig from "../../.rollup/index.mjs";

export default createRollupConfig({
input: "src/strip-query-string.ts",
external: ['@bugsnag/core', "@bugsnag/core/lib/es-utils/map", "@bugsnag/core/lib/es-utils/reduce"]
external: ['@bugsnag/core', "@bugsnag/core/lib/es-utils/reduce"]
});
3 changes: 1 addition & 2 deletions packages/plugin-strip-query-string/src/strip-query-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* 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) =>
Expand All @@ -18,7 +17,7 @@ const plugin: ExtendedPlugin = {
load: (client) => {
client.addOnError(event => {
const allFrames: Stackframe[] = reduce(event.errors, (accum, er) => accum.concat(er.stacktrace), [])
map(allFrames, frame => {
allFrames.map(frame => {
frame.file = strip(frame.file)
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import createRollupConfig from '../../.rollup/index.mjs'

export default createRollupConfig({
input: 'src/unhandled-rejection.ts',
external: ['@bugsnag/core', '@bugsnag/core/lib/iserror', '@bugsnag/core/lib/es-utils/map']
external: ['@bugsnag/core', '@bugsnag/core/lib/iserror']
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Config, Plugin } from '@bugsnag/core'
import map from '@bugsnag/core/lib/es-utils/map'
import isError from '@bugsnag/core/lib/iserror'
import fixBluebirdStacktrace from './fix-bluebird-stacktrace'

Expand Down Expand Up @@ -45,7 +44,7 @@ export default (win = window): Plugin => {
}, 'unhandledrejection handler', 1, client._logger)

if (isBluebird) {
map(event.errors[0].stacktrace, fixBluebirdStacktrace(error))
event.errors[0].stacktrace.map(fixBluebirdStacktrace(error))
}

client._notify(event, (event) => {
Expand Down
5 changes: 2 additions & 3 deletions packages/web-worker/src/get-prefixed-console.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import map from '@bugsnag/core/lib/es-utils/map'

type LoggerMethod = 'debug' | 'info' | 'warn' | 'error'

const getPrefixedConsole = () => {
const logger: Record<string, unknown> = {}
const consoleLog = console.log
map(['debug', 'info', 'warn', 'error'], (method: LoggerMethod) => {
const loggerMethods = ['debug', 'info', 'warn', 'error'] as const
loggerMethods.map((method: LoggerMethod) => {
const consoleMethod = console[method]
logger[method] = typeof consoleMethod === 'function'
? consoleMethod.bind(console, '[bugsnag]')
Expand Down