Skip to content

Commit 5513811

Browse files
ref: Build to ESM for tree shaking (#117)
This PR changes updates our webpack config to use ESM instead of CJS modules so we can actually do tree shaking. The reason for this is our extension failed Chrome's review process due to some third party script loading code from the Sentry SDK. We don't actually use this code and it should be removed from our bundle with tree shaking.
1 parent bcb59cb commit 5513811

File tree

8 files changed

+114
-195
lines changed

8 files changed

+114
-195
lines changed

codecov.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
comment:
2+
require_bundle_changes: True
3+
bundle_change_threshold: "0b"

package-lock.json

Lines changed: 78 additions & 170 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414
"dependencies": {
1515
"@fortawesome/free-solid-svg-icons": "^6.3.0",
1616
"@fortawesome/react-fontawesome": "^0.2.0",
17-
"@sentry/browser": "^8.37.1",
17+
"@sentry/browser": "^9.1.0",
1818
"clsx": "^1.2.1",
1919
"code-tag": "^1.1.0",
20-
"color-alpha": "^1.1.3",
2120
"dom-chef": "^5.1.0",
2221
"lodash": "^4.17.21",
2322
"react": "^18.2.0",
@@ -47,7 +46,7 @@
4746
"tailwindcss": "^3.2.7",
4847
"ts-loader": "^8.0.0",
4948
"tsconfig-paths-webpack-plugin": "^4.0.1",
50-
"typescript": "^4.4.3 ",
49+
"typescript": "^5.7.3",
5150
"webpack": "^5.76.0",
5251
"webpack-cli": "^4.0.0",
5352
"webpack-merge": "^5.0.0"

src/background/main.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import browser from "webextension-polyfill";
2-
import * as Sentry from "@sentry/browser";
2+
import {
3+
init as sentryInit,
4+
browserTracingIntegration,
5+
startSpan,
6+
} from "@sentry/browser";
37

48
import { MessageType } from "src/types";
59
import { Codecov } from "src/service";
@@ -11,12 +15,12 @@ import {
1115
async function main(): Promise<void> {
1216
browser.runtime.onMessage.addListener(handleMessages);
1317

14-
Sentry.init({
18+
sentryInit({
1519
// @ts-ignore SENTRY_DSN is populated by Webpack at build time
1620
dsn: SENTRY_DSN,
1721

1822
integrations: [
19-
Sentry.browserTracingIntegration({
23+
browserTracingIntegration({
2024
// disable automatic span creation
2125
instrumentNavigation: false,
2226
instrumentPageLoad: false,
@@ -33,7 +37,7 @@ async function handleMessages(message: {
3337
referrer?: string;
3438
}) {
3539
const codecov = new Codecov();
36-
return Sentry.startSpan({ name: message.type }, async () => {
40+
return startSpan({ name: message.type }, async () => {
3741
switch (message.type) {
3842
case MessageType.FETCH_COMMIT_REPORT:
3943
return codecov.fetchCommitReport(message.payload, message.referrer!);

src/content/common/sentry.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,35 @@
11
import {
2+
breadcrumbsIntegration,
3+
browserApiErrorsIntegration,
24
BrowserClient,
35
defaultStackParser,
4-
getDefaultIntegrations,
6+
globalHandlersIntegration,
57
makeFetchTransport,
8+
dedupeIntegration,
69
Scope,
7-
} from '@sentry/browser';
10+
} from "@sentry/browser";
811

912
// Sentry config
10-
// Browser extensions must initialize Sentry a bit differently to avoid
13+
// Browser extensions must initialize Sentry a bit differently to avoid
1114
// conflicts between Sentry instances should the site the extension is running
1215
// on also use Sentry. Read more here:
1316
// https://docs.sentry.io/platforms/javascript/best-practices/browser-extensions/
1417

15-
const sentryIntegrations = getDefaultIntegrations({}).filter(defaultIntegration => {
16-
return !['BrowserApiErrors', 'TryCatch', 'Breadcrumbs', 'GlobalHandlers'].includes(
17-
defaultIntegration.name
18-
);
19-
});
20-
2118
const sentryClient = new BrowserClient({
2219
// @ts-ignore SENTRY_DSN is populated by Webpack at build time
2320
dsn: SENTRY_DSN,
2421
transport: makeFetchTransport,
2522
stackParser: defaultStackParser,
26-
integrations: sentryIntegrations,
23+
integrations: [
24+
breadcrumbsIntegration,
25+
browserApiErrorsIntegration,
26+
globalHandlersIntegration,
27+
dedupeIntegration,
28+
],
2729
});
2830

2931
const Sentry = new Scope();
3032
Sentry.setClient(sentryClient);
3133
sentryClient.init();
3234

33-
export default Sentry
35+
export default Sentry;

src/content/github/common/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ export const animationAttachmentId = `${animationName}-attachment`;
77
export const seenClassName = "codecov-seen-mark";
88

99
export const colors = {
10+
redAlpha: "rgba(245,32,32,0.25)",
11+
greenAlpha: "rgba(33,181,119,0.25)",
12+
yellowAlpha: "rgba(244,176,27,0.25)",
1013
red: "rgb(245,32,32)",
1114
green: "rgb(33,181,119)",
1215
yellow: "rgb(244,176,27)",

src/content/github/file/main.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import browser from "webextension-polyfill";
2-
import alpha from "color-alpha";
32
import Drop from "tether-drop";
43
import _ from "lodash";
54
import "tether-drop/dist/css/drop-theme-arrows.css";
@@ -353,11 +352,11 @@ function annotateLine(line: HTMLElement) {
353352
}
354353
const status = globals.coverageReport[lineNumber];
355354
if (status === CoverageStatus.COVERED) {
356-
line.style.backgroundColor = alpha(colors.green, 0.25);
355+
line.style.backgroundColor = colors.greenAlpha;
357356
} else if (status === CoverageStatus.UNCOVERED) {
358-
line.style.backgroundColor = alpha(colors.red, 0.25);
357+
line.style.backgroundColor = colors.redAlpha;
359358
} else if (status === CoverageStatus.PARTIAL) {
360-
line.style.backgroundColor = alpha(colors.yellow, 0.25);
359+
line.style.backgroundColor = colors.yellowAlpha;
361360
} else {
362361
line.style.backgroundColor = "inherit";
363362
}

tsconfig.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"compilerOptions": {
33
"strict": true,
4-
"module": "commonjs",
5-
"target": "es6",
4+
"module": "esnext",
5+
"target": "esnext",
66
"esModuleInterop": true,
77
"sourceMap": false,
88
"baseUrl": "./",
@@ -15,6 +15,7 @@
1515
"outDir": "dist/js",
1616
"noEmitOnError": true,
1717
"jsx": "react",
18-
"typeRoots": ["node_modules/@types"]
18+
"typeRoots": ["node_modules/@types"],
19+
"moduleResolution": "bundler"
1920
}
2021
}

0 commit comments

Comments
 (0)