Skip to content

Commit 624c156

Browse files
authored
chore(core): Remove unused dependencies (#110)
Removes a few dependencies we don't need anymore after switching back to Sentry CLI. Makes adjustments to `captureMinimalError` to no longer treat axios errors (axios was one of the removed dependencies)
1 parent a064077 commit 624c156

File tree

7 files changed

+84
-32
lines changed

7 files changed

+84
-32
lines changed

packages/bundler-plugin-core/package.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@
3838
"@sentry/cli": "^1.74.6",
3939
"@sentry/node": "^7.11.1",
4040
"@sentry/tracing": "^7.11.1",
41-
"axios": "^0.27.2",
42-
"form-data": "^4.0.0",
43-
"glob": "8.0.3",
44-
"ignore": "^5.2.0",
4541
"magic-string": "0.26.2",
4642
"unplugin": "0.10.1"
4743
},
@@ -58,7 +54,6 @@
5854
"@sentry-internal/sentry-bundler-plugin-tsconfig": "0.0.1-alpha.0",
5955
"@swc/core": "^1.2.205",
6056
"@swc/jest": "^0.2.21",
61-
"@types/glob": "8.0.0",
6257
"@types/jest": "^28.1.3",
6358
"@types/node": "^18.6.3",
6459
"eslint": "^8.18.0",

packages/bundler-plugin-core/src/sentry/telemetry.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
NodeClient,
88
} from "@sentry/node";
99
import { Span } from "@sentry/tracing";
10-
import { AxiosError } from "axios";
1110
import { BuildContext } from "../types";
1211

1312
export function makeSentryClient(
@@ -57,16 +56,23 @@ export function addSpanToTransaction(
5756
return span;
5857
}
5958

60-
export function captureMinimalError(error: unknown | Error | AxiosError, hub: Hub) {
61-
const isAxiosError = error instanceof AxiosError;
62-
const sentryError =
63-
error instanceof Error
64-
? {
65-
name: `${isAxiosError && error.status ? error.status : ""}: ${error.name}`,
66-
message: error.message,
67-
stack: error.stack,
68-
}
69-
: {};
59+
export function captureMinimalError(error: unknown | Error, hub: Hub) {
60+
let sentryError;
61+
62+
if (error && typeof error === "object") {
63+
const e = error as { name?: string; message?: string; stack?: string };
64+
sentryError = {
65+
name: e.name,
66+
message: e.message,
67+
stack: e.stack,
68+
};
69+
} else {
70+
sentryError = {
71+
name: "Error",
72+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
73+
message: `${error}`,
74+
};
75+
}
7076

7177
hub.captureException(sentryError);
7278
}

packages/bundler-plugin-core/test/cli.test.ts renamed to packages/bundler-plugin-core/test/sentry/cli.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import SentryCli from "@sentry/cli";
2-
import { getSentryCli } from "../src/sentry/cli";
2+
import { getSentryCli } from "../../src/sentry/cli";
33

44
describe("getSentryCLI", () => {
55
it("returns a valid CLI instance if dryRun is not specified", () => {

packages/bundler-plugin-core/test/logger.test.ts renamed to packages/bundler-plugin-core/test/sentry/logger.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Hub } from "@sentry/node";
2-
import { createLogger } from "../src/sentry/logger";
2+
import { createLogger } from "../../src/sentry/logger";
33

44
describe("Logger", () => {
55
const consoleLogSpy = jest.spyOn(console, "log").mockImplementation(() => undefined);

packages/bundler-plugin-core/test/releasePipeline.test.ts renamed to packages/bundler-plugin-core/test/sentry/releasePipeline.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import { InternalOptions } from "../src/options-mapping";
1+
import { InternalOptions } from "../../src/options-mapping";
22
import {
33
addDeploy,
44
cleanArtifacts,
55
createNewRelease,
66
finalizeRelease,
77
setCommits,
88
uploadSourceMaps,
9-
} from "../src/sentry/releasePipeline";
10-
import { BuildContext } from "../src/types";
9+
} from "../../src/sentry/releasePipeline";
10+
import { BuildContext } from "../../src/types";
1111

1212
const mockedAddSpanToTxn = jest.fn();
1313

14-
jest.mock("../src/sentry/telemetry", () => {
14+
jest.mock("../../src/sentry/telemetry", () => {
1515
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
16-
const original = jest.requireActual("../src/sentry/telemetry");
16+
const original = jest.requireActual("../../src/sentry/telemetry");
1717

1818
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
1919
return {
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { Hub } from "@sentry/node";
2+
import { captureMinimalError } from "../../src/sentry/telemetry";
3+
4+
describe("captureMinimalError", () => {
5+
const mockedHub = {
6+
captureException: jest.fn(),
7+
};
8+
9+
beforeEach(() => {
10+
jest.resetAllMocks();
11+
});
12+
13+
it("Should capture a normal error", () => {
14+
captureMinimalError(new Error("test"), mockedHub as unknown as Hub);
15+
expect(mockedHub.captureException).toHaveBeenCalledWith({
16+
name: "Error",
17+
message: "test",
18+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
19+
stack: expect.any(String),
20+
});
21+
});
22+
23+
it("Shouldn't capture an error with additional data", () => {
24+
const error = new Error("test");
25+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
26+
(error as any).additionalContext = { foo: "bar" };
27+
28+
captureMinimalError(error, mockedHub as unknown as Hub);
29+
30+
expect(mockedHub.captureException).toHaveBeenCalledWith({
31+
name: "Error",
32+
message: "test",
33+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
34+
stack: expect.any(String),
35+
});
36+
});
37+
38+
it("Should handle string messages gracefully", () => {
39+
const error = "Property x is missing!";
40+
41+
captureMinimalError(error, mockedHub as unknown as Hub);
42+
43+
expect(mockedHub.captureException).toHaveBeenCalledWith({
44+
name: "Error",
45+
message: error,
46+
});
47+
});
48+
49+
it("Should even handle undefined gracefully", () => {
50+
const error = undefined;
51+
52+
captureMinimalError(error, mockedHub as unknown as Hub);
53+
54+
expect(mockedHub.captureException).toHaveBeenCalledWith({
55+
name: "Error",
56+
message: "undefined",
57+
});
58+
});
59+
});

yarn.lock

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3837,14 +3837,6 @@ axios@*, axios@^1.0.0, axios@^1.1.3:
38373837
form-data "^4.0.0"
38383838
proxy-from-env "^1.1.0"
38393839

3840-
axios@^0.27.2:
3841-
version "0.27.2"
3842-
resolved "https://registry.yarnpkg.com/axios/-/axios-0.27.2.tgz#207658cc8621606e586c85db4b41a750e756d972"
3843-
integrity sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==
3844-
dependencies:
3845-
follow-redirects "^1.14.9"
3846-
form-data "^4.0.0"
3847-
38483840
babel-jest@^27.5.1:
38493841
version "27.5.1"
38503842
resolved "https://registry.yarnpkg.com/babel-jest/-/babel-jest-27.5.1.tgz#a1bf8d61928edfefd21da27eb86a695bfd691444"
@@ -6183,7 +6175,7 @@ flush-write-stream@^1.0.0:
61836175
inherits "^2.0.3"
61846176
readable-stream "^2.3.6"
61856177

6186-
follow-redirects@^1.0.0, follow-redirects@^1.14.9:
6178+
follow-redirects@^1.0.0:
61876179
version "1.15.1"
61886180
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.1.tgz#0ca6a452306c9b276e4d3127483e29575e207ad5"
61896181
integrity sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA==

0 commit comments

Comments
 (0)