From a04fe2cfe12084f5a7118dfd8fe8f5d089c0f1b7 Mon Sep 17 00:00:00 2001 From: Ben Wilson Date: Mon, 11 Nov 2024 09:54:24 +0000 Subject: [PATCH] refactor: :recycle: refactor plugin-interaction-breadcrumbs --- .../plugin-interaction-breadcrumbs/package.json | 14 +++++++++++++- .../rollup.config.npm.mjs | 5 +++++ .../interaction-breadcrumbs.ts} | 11 ++++++++--- .../test/interaction-breadcrumbs.test.ts | 2 +- .../plugin-interaction-breadcrumbs/tsconfig.json | 5 +++++ 5 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 packages/plugin-interaction-breadcrumbs/rollup.config.npm.mjs rename packages/plugin-interaction-breadcrumbs/{interaction-breadcrumbs.js => src/interaction-breadcrumbs.ts} (87%) create mode 100644 packages/plugin-interaction-breadcrumbs/tsconfig.json diff --git a/packages/plugin-interaction-breadcrumbs/package.json b/packages/plugin-interaction-breadcrumbs/package.json index 3d11035d01..48b40f7613 100644 --- a/packages/plugin-interaction-breadcrumbs/package.json +++ b/packages/plugin-interaction-breadcrumbs/package.json @@ -2,6 +2,14 @@ "name": "@bugsnag/plugin-interaction-breadcrumbs", "version": "8.1.1", "main": "interaction-breadcrumbs.js", + "types": "dist/types/interaction-breadcrumbs.d.ts", + "exports": { + ".": { + "types": "./dist/types/interaction-breadcrumbs.d.ts", + "default": "./dist/interaction-breadcrumbs.js", + "import": "./dist/interaction-breadcrumbs.mjs" + } + }, "description": "@bugsnag/js plugin to record UI click events as breadcrumbs", "homepage": "https://www.bugsnag.com/", "repository": { @@ -14,7 +22,11 @@ "files": [ "*.js" ], - "scripts": {}, + "scripts": { + "build": "npm run build:npm", + "build:npm": "rollup --config rollup.config.npm.mjs", + "clean": "rm -rf dist/*" + }, "author": "Bugsnag", "license": "MIT", "devDependencies": { diff --git a/packages/plugin-interaction-breadcrumbs/rollup.config.npm.mjs b/packages/plugin-interaction-breadcrumbs/rollup.config.npm.mjs new file mode 100644 index 0000000000..5683a04647 --- /dev/null +++ b/packages/plugin-interaction-breadcrumbs/rollup.config.npm.mjs @@ -0,0 +1,5 @@ +import createRollupConfig from '../../.rollup/index.mjs' + +export default createRollupConfig({ + input: 'src/interaction-breadcrumbs.ts' +}) diff --git a/packages/plugin-interaction-breadcrumbs/interaction-breadcrumbs.js b/packages/plugin-interaction-breadcrumbs/src/interaction-breadcrumbs.ts similarity index 87% rename from packages/plugin-interaction-breadcrumbs/interaction-breadcrumbs.js rename to packages/plugin-interaction-breadcrumbs/src/interaction-breadcrumbs.ts index 86c7b03086..ba1b65c961 100644 --- a/packages/plugin-interaction-breadcrumbs/interaction-breadcrumbs.js +++ b/packages/plugin-interaction-breadcrumbs/src/interaction-breadcrumbs.ts @@ -1,7 +1,10 @@ +import { Plugin } from '@bugsnag/core' +import type ClientWithInternals from 'packages/core/client' + /* * Leaves breadcrumbs when the user interacts with the DOM */ -module.exports = (win = window) => ({ +export default (win = window): Plugin => ({ load: (client) => { if (!('addEventListener' in win)) return if (!client._isBreadcrumbTypeEnabled('user')) return @@ -23,7 +26,8 @@ module.exports = (win = window) => ({ const trim = /^\s*([^\s][\s\S]{0,139}[^\s])?\s*/ -function getNodeText (el) { +// TODO: Fix Type +function getNodeText (el: any) { let text = el.textContent || el.innerText || '' if (!text && (el.type === 'submit' || el.type === 'button')) { @@ -40,7 +44,8 @@ function getNodeText (el) { } // Create a label from tagname, id and css class of the element -function getNodeSelector (el, win) { +// TODO: Fix Type +function getNodeSelector (el: any, win: Window): string { const parts = [el.tagName] if (el.id) parts.push('#' + el.id) if (el.className && el.className.length) parts.push(`.${el.className.split(' ').join('.')}`) diff --git a/packages/plugin-interaction-breadcrumbs/test/interaction-breadcrumbs.test.ts b/packages/plugin-interaction-breadcrumbs/test/interaction-breadcrumbs.test.ts index e2c198dec5..8ce1f00285 100644 --- a/packages/plugin-interaction-breadcrumbs/test/interaction-breadcrumbs.test.ts +++ b/packages/plugin-interaction-breadcrumbs/test/interaction-breadcrumbs.test.ts @@ -1,4 +1,4 @@ -import plugin from '../' +import plugin from '../src/interaction-breadcrumbs' import Client from '@bugsnag/core/client' import Breadcrumb from '@bugsnag/core/breadcrumb' diff --git a/packages/plugin-interaction-breadcrumbs/tsconfig.json b/packages/plugin-interaction-breadcrumbs/tsconfig.json new file mode 100644 index 0000000000..09758ceb4c --- /dev/null +++ b/packages/plugin-interaction-breadcrumbs/tsconfig.json @@ -0,0 +1,5 @@ +{ + "extends": "../../tsconfig.json", + "include": ["src/**/*.ts"] +} + \ No newline at end of file