Skip to content

Commit

Permalink
refactor: ♻️ refactor plugin-app-duration to typescript es module
Browse files Browse the repository at this point in the history
  • Loading branch information
gingerbenw committed Oct 16, 2024
1 parent 483e30a commit c95a023
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 6 deletions.
15 changes: 14 additions & 1 deletion packages/plugin-app-duration/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
{
"name": "@bugsnag/plugin-app-duration",
"version": "8.0.0",
"main": "app.js",
"main": "dist/app-duration.js",
"types": "dist/types/app-duration.d.ts",
"exports": {
".": {
"types": "./dist/types/app-duration.d.ts",
"default": "./dist/app-duration.js",
"import": "./dist/app-duration.mjs"
}
},
"description": "@bugsnag/js plugin to set app duration in browsers and node",
"homepage": "https://www.bugsnag.com/",
"repository": {
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/*"
}
}
25 changes: 25 additions & 0 deletions packages/plugin-app-duration/rollup.config.npm.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import createRollupConfig from '../../.rollup/index.mjs'

export default createRollupConfig({
input: 'src/app-duration.ts',
output: [
{
dir: `dist`,
entryFileNames: '[name].js',
format: 'cjs',
preserveModules: true,
generatedCode: {
preset: 'es2015',
}
},
{
dir: `dist`,
entryFileNames: '[name].mjs',
format: 'esm',
preserveModules: true,
generatedCode: {
preset: 'es2015',
}
}
]
})
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import { Plugin } from 'packages/core/types'

let appStart = new Date()
const reset = () => { appStart = new Date() }

module.exports = {
const plugin: Plugin = {
name: 'appDuration',
load: client => {
client.addOnError(event => {
const now = new Date()

event.app.duration = now - appStart
event.app.duration = Number(now) - Number(appStart)
// @ts-expect-error second argument is private API
}, true)

return { reset }
}
}

export default plugin
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import plugin from '../app'
import plugin from '../src/app-duration'
import Client from '@bugsnag/core/client'
import Event from '@bugsnag/core/event'

Expand Down Expand Up @@ -39,7 +39,7 @@ describe('plugin-app-duration', () => {
}
}

const result = plugin.load(client)
const result = plugin.load(client as unknown as Client)

const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))

Expand Down
8 changes: 8 additions & 0 deletions packages/plugin-app-duration/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"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 @@ -66,7 +66,6 @@
"packages/delivery-x-domain-request",
"packages/delivery-xml-http-request",
"packages/in-flight",
"packages/plugin-app-duration",
"packages/plugin-aws-lambda",
"packages/plugin-browser-context",
"packages/plugin-browser-device",
Expand Down

0 comments on commit c95a023

Please sign in to comment.