Skip to content

Commit d1216f7

Browse files
authored
Merge branch 'main' into timfish/fix/use-renderChunk-for-release-injection
2 parents 303e240 + 8237ac9 commit d1216f7

File tree

23 files changed

+207
-126
lines changed

23 files changed

+207
-126
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,26 @@
44

55
- "You know what they say ‘Fool me once, strike one, but fool me twice… strike three.’" — Michael Scott
66

7+
- fix(core): Make plugin inject ES5-friendly code ([#770](https://github.com/getsentry/sentry-javascript-bundler-plugins/pull/770))
8+
9+
Work in this release was contributed by @grushetsky. Thank you for your contribution!
10+
11+
## 4.0.0
12+
13+
### Breaking Changes
14+
15+
- (Type change) Vite plugin now returns `VitePlugin` type instead of `any`
16+
- Deprecated function `getBuildInformation` has been removed
17+
18+
### List of Changes
19+
20+
- feat(core)!: Remove `getBuildInformation` export ([#765](https://github.com/getsentry/sentry-javascript-bundler-plugins/pull/765))
21+
- feat(vite)!: Update return type of vite plugin ([#728](https://github.com/getsentry/sentry-javascript-bundler-plugins/pull/728))
22+
23+
## 3.6.1
24+
25+
- fix(core): Observe and handle Sentry CLI sourcemap upload failures ([#763](https://github.com/getsentry/sentry-javascript-bundler-plugins/pull/763))
26+
727
## 3.6.0
828

929
- feat(core): Don't add `debugIdUploadPlugin` when sourcemaps option is disabled ([#753](https://github.com/getsentry/sentry-javascript-bundler-plugins/pull/753))

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
3-
"version": "3.6.0",
3+
"version": "4.0.0",
44
"npmClient": "yarn",
55
"useWorkspaces": true
66
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"ts-node": "^10.9.2"
3838
},
3939
"volta": {
40-
"node": "14.21.2",
40+
"node": "18.20.8",
4141
"yarn": "1.22.19"
4242
}
4343
}

packages/babel-plugin-component-annotate/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sentry/babel-plugin-component-annotate",
3-
"version": "3.6.0",
3+
"version": "4.0.0",
44
"description": "A Babel plugin that annotates frontend components with additional data to enrich the experience in Sentry",
55
"repository": "git://github.com/getsentry/sentry-javascript-bundler-plugins.git",
66
"homepage": "https://github.com/getsentry/sentry-javascript-bundler-plugins/tree/main/packages/babel-plugin-component-annotate",
@@ -56,8 +56,8 @@
5656
"@babel/preset-typescript": "7.17.12",
5757
"@rollup/plugin-babel": "5.3.1",
5858
"@rollup/plugin-node-resolve": "13.3.0",
59-
"@sentry-internal/eslint-config": "3.6.0",
60-
"@sentry-internal/sentry-bundler-plugin-tsconfig": "3.6.0",
59+
"@sentry-internal/eslint-config": "4.0.0",
60+
"@sentry-internal/sentry-bundler-plugin-tsconfig": "4.0.0",
6161
"@swc/core": "^1.2.205",
6262
"@swc/jest": "^0.2.21",
6363
"@types/jest": "^28.1.3",

packages/bundler-plugin-core/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sentry/bundler-plugin-core",
3-
"version": "3.6.0",
3+
"version": "4.0.0",
44
"description": "Sentry Bundler Plugin Core",
55
"repository": "git://github.com/getsentry/sentry-javascript-bundler-plugins.git",
66
"homepage": "https://github.com/getsentry/sentry-javascript-bundler-plugins/tree/main/packages/bundler-plugin-core",
@@ -53,8 +53,8 @@
5353
},
5454
"dependencies": {
5555
"@babel/core": "^7.18.5",
56-
"@sentry/babel-plugin-component-annotate": "3.6.0",
57-
"@sentry/cli": "^2.46.0",
56+
"@sentry/babel-plugin-component-annotate": "4.0.0",
57+
"@sentry/cli": "^2.49.0",
5858
"dotenv": "^16.3.1",
5959
"find-up": "^5.0.0",
6060
"glob": "^9.3.2",
@@ -68,8 +68,8 @@
6868
"@rollup/plugin-json": "4.1.0",
6969
"@rollup/plugin-node-resolve": "13.3.0",
7070
"@rollup/plugin-replace": "^4.0.0",
71-
"@sentry-internal/eslint-config": "3.6.0",
72-
"@sentry-internal/sentry-bundler-plugin-tsconfig": "3.6.0",
71+
"@sentry-internal/eslint-config": "4.0.0",
72+
"@sentry-internal/sentry-bundler-plugin-tsconfig": "4.0.0",
7373
"@sentry/core": "8.30.0",
7474
"@sentry/types": "8.30.0",
7575
"@sentry/utils": "8.30.0",

packages/bundler-plugin-core/src/build-plugin-manager.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,9 @@ export function createSentryBuildPluginManager(
455455
await cliInstance.releases.uploadSourceMaps(options.release.name, {
456456
include: normalizedInclude,
457457
dist: options.release.dist,
458+
// We want this promise to throw if the sourcemaps fail to upload so that we know about it.
459+
// see: https://github.com/getsentry/sentry-cli/pull/2605
460+
live: "rejectOnError",
458461
});
459462
}
460463

@@ -642,6 +645,9 @@ export function createSentryBuildPluginManager(
642645
dist: options.release.dist,
643646
},
644647
],
648+
// We want this promise to throw if the sourcemaps fail to upload so that we know about it.
649+
// see: https://github.com/getsentry/sentry-cli/pull/2605
650+
live: "rejectOnError",
645651
}
646652
);
647653
});

packages/bundler-plugin-core/src/index.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { Options, SentrySDKBuildFlags } from "./types";
1414
import {
1515
generateGlobalInjectorCode,
1616
generateModuleMetadataInjectorCode,
17-
getBuildInformation as actualGetBuildInformation,
1817
replaceBooleanFlagsInCode,
1918
stringToUUID,
2019
stripQueryAndHashFromPath,
@@ -174,13 +173,6 @@ export function sentryUnpluginFactory({
174173
});
175174
}
176175

177-
/**
178-
* @deprecated This will be removed in v4
179-
*/
180-
// TODO(v4): Don't export this from the package but keep the utils version
181-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
182-
export const getBuildInformation = actualGetBuildInformation;
183-
184176
/**
185177
* Determines whether the Sentry CLI binary is in its expected location.
186178
* This function is useful since `@sentry/cli` installs the binary via a post-install
@@ -439,7 +431,7 @@ export function createComponentNameAnnotateHooks(ignoredComponents?: string[]):
439431
}
440432

441433
export function getDebugIdSnippet(debugId: string): string {
442-
return `;{try{let e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="${debugId}",e._sentryDebugIdIdentifier="sentry-dbid-${debugId}")}catch(e){}};`;
434+
return `;{try{(function(){var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="${debugId}",e._sentryDebugIdIdentifier="sentry-dbid-${debugId}");})();}catch(e){}};`;
443435
}
444436

445437
export type { Logger } from "./logger";

packages/bundler-plugin-core/src/utils.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,8 @@ export function generateGlobalInjectorCode({
314314
}): string {
315315
// The code below is mostly ternary operators because it saves bundle size.
316316
// The checks are to support as many environments as possible. (Node.js, Browser, webworkers, etc.)
317-
let code = `{
318-
let _global =
317+
let code = `(function(){
318+
var _global =
319319
typeof window !== 'undefined' ?
320320
window :
321321
typeof global !== 'undefined' ?
@@ -332,10 +332,10 @@ export function generateGlobalInjectorCode({
332332
const buildInfo = getBuildInformation();
333333

334334
code += `
335-
_global.SENTRY_BUILD_INFO=${JSON.stringify(buildInfo)};`;
335+
_global.SENTRY_BUILD_INFO=${JSON.stringify(buildInfo)};`;
336336
}
337337

338-
code += "}";
338+
code += "})();";
339339

340340
return code;
341341
}
@@ -345,8 +345,8 @@ export function generateModuleMetadataInjectorCode(metadata: any): string {
345345
// The code below is mostly ternary operators because it saves bundle size.
346346
// The checks are to support as many environments as possible. (Node.js, Browser, webworkers, etc.)
347347
// We are merging the metadata objects in case modules are bundled twice with the plugin
348-
return `{
349-
let _sentryModuleMetadataGlobal =
348+
return `(function(){
349+
var _sentryModuleMetadataGlobal =
350350
typeof window !== "undefined"
351351
? window
352352
: typeof global !== "undefined"
@@ -366,7 +366,7 @@ export function generateModuleMetadataInjectorCode(metadata: any): string {
366366
_sentryModuleMetadataGlobal._sentryModuleMetadata[new _sentryModuleMetadataGlobal.Error().stack],
367367
${JSON.stringify(metadata)}
368368
);
369-
}`;
369+
})();`;
370370
}
371371

372372
export function getBuildInformation(): {

packages/bundler-plugin-core/test/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ describe("getDebugIdSnippet", () => {
44
it("returns the debugId injection snippet for a passed debugId", () => {
55
const snippet = getDebugIdSnippet("1234");
66
expect(snippet).toMatchInlineSnapshot(
7-
`";{try{let e=\\"undefined\\"!=typeof window?window:\\"undefined\\"!=typeof global?global:\\"undefined\\"!=typeof globalThis?globalThis:\\"undefined\\"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]=\\"1234\\",e._sentryDebugIdIdentifier=\\"sentry-dbid-1234\\")}catch(e){}};"`
7+
`";{try{(function(){var e=\\"undefined\\"!=typeof window?window:\\"undefined\\"!=typeof global?global:\\"undefined\\"!=typeof globalThis?globalThis:\\"undefined\\"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]=\\"1234\\",e._sentryDebugIdIdentifier=\\"sentry-dbid-1234\\");})();}catch(e){}};"`
88
);
99
});
1010
});

packages/bundler-plugin-core/test/utils.test.ts

Lines changed: 71 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import {
2+
generateGlobalInjectorCode,
23
generateModuleMetadataInjectorCode,
34
getDependencies,
45
getPackageJson,
56
parseMajorVersion,
67
replaceBooleanFlagsInCode,
78
stringToUUID,
89
} from "../src/utils";
10+
11+
import fs from "fs";
12+
913
import path from "node:path";
1014

1115
type PackageJson = Record<string, unknown>;
@@ -216,12 +220,73 @@ if (false && true) {
216220
});
217221
});
218222

223+
describe("generateGlobalInjectorCode", () => {
224+
it("generates code with release", () => {
225+
const generatedCode = generateGlobalInjectorCode({
226+
release: "1.2.3",
227+
injectBuildInformation: false,
228+
});
229+
230+
expect(generatedCode).toMatchInlineSnapshot(`
231+
"(function(){
232+
var _global =
233+
typeof window !== 'undefined' ?
234+
window :
235+
typeof global !== 'undefined' ?
236+
global :
237+
typeof globalThis !== 'undefined' ?
238+
globalThis :
239+
typeof self !== 'undefined' ?
240+
self :
241+
{};
242+
243+
_global.SENTRY_RELEASE={id:\\"1.2.3\\"};})();"
244+
`);
245+
});
246+
247+
it("generates code with release and build information", () => {
248+
jest.spyOn(fs, "readFileSync").mockReturnValueOnce(
249+
JSON.stringify({
250+
name: "test-app",
251+
dependencies: {
252+
myDep: "^2.1.4",
253+
},
254+
devDependencies: {
255+
rollup: "^3.1.4",
256+
},
257+
})
258+
);
259+
260+
const generatedCode = generateGlobalInjectorCode({
261+
release: "1.2.3",
262+
injectBuildInformation: true,
263+
});
264+
265+
expect(generatedCode).toMatchInlineSnapshot(`
266+
"(function(){
267+
var _global =
268+
typeof window !== 'undefined' ?
269+
window :
270+
typeof global !== 'undefined' ?
271+
global :
272+
typeof globalThis !== 'undefined' ?
273+
globalThis :
274+
typeof self !== 'undefined' ?
275+
self :
276+
{};
277+
278+
_global.SENTRY_RELEASE={id:\\"1.2.3\\"};
279+
_global.SENTRY_BUILD_INFO={\\"deps\\":[\\"myDep\\",\\"rollup\\"],\\"depsVersions\\":{\\"rollup\\":3},\\"nodeVersion\\":18};})();"
280+
`);
281+
});
282+
});
283+
219284
describe("generateModuleMetadataInjectorCode", () => {
220285
it("generates code with empty metadata object", () => {
221286
const generatedCode = generateModuleMetadataInjectorCode({});
222287
expect(generatedCode).toMatchInlineSnapshot(`
223-
"{
224-
let _sentryModuleMetadataGlobal =
288+
"(function(){
289+
var _sentryModuleMetadataGlobal =
225290
typeof window !== \\"undefined\\"
226291
? window
227292
: typeof global !== \\"undefined\\"
@@ -241,7 +306,7 @@ describe("generateModuleMetadataInjectorCode", () => {
241306
_sentryModuleMetadataGlobal._sentryModuleMetadata[new _sentryModuleMetadataGlobal.Error().stack],
242307
{}
243308
);
244-
}"
309+
})();"
245310
`);
246311
});
247312

@@ -255,8 +320,8 @@ describe("generateModuleMetadataInjectorCode", () => {
255320
},
256321
});
257322
expect(generatedCode).toMatchInlineSnapshot(`
258-
"{
259-
let _sentryModuleMetadataGlobal =
323+
"(function(){
324+
var _sentryModuleMetadataGlobal =
260325
typeof window !== \\"undefined\\"
261326
? window
262327
: typeof global !== \\"undefined\\"
@@ -276,7 +341,7 @@ describe("generateModuleMetadataInjectorCode", () => {
276341
_sentryModuleMetadataGlobal._sentryModuleMetadata[new _sentryModuleMetadataGlobal.Error().stack],
277342
{\\"file1.js\\":{\\"foo\\":\\"bar\\"},\\"file2.js\\":{\\"bar\\":\\"baz\\"}}
278343
);
279-
}"
344+
})();"
280345
`);
281346
});
282347
});

0 commit comments

Comments
 (0)