Skip to content

feat(core): Write module injections to globalThis #636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ try {
? window
: "undefined" != typeof global
? global
: "undefined" != typeof globalThis
? global
: "undefined" != typeof self
? self
: {};
Expand Down
2 changes: 1 addition & 1 deletion packages/bundler-plugin-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ export function createComponentNameAnnotateHooks() {
}

export function getDebugIdSnippet(debugId: string): string {
return `;!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"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){}}();`;
return `;!function(){try{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){}}();`;
}

export { stringToUUID, replaceBooleanFlagsInCode } from "./utils";
Expand Down
10 changes: 7 additions & 3 deletions packages/bundler-plugin-core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,11 @@ export function generateGlobalInjectorCode({
window :
typeof global !== 'undefined' ?
global :
typeof self !== 'undefined' ?
self :
{};
typeof globalThis !== 'undefined' ?
globalThis :
typeof self !== 'undefined' ?
self :
{};

_global.SENTRY_RELEASE={id:${JSON.stringify(release)}};`;

Expand All @@ -345,6 +347,8 @@ export function generateModuleMetadataInjectorCode(metadata: any) {
? window
: typeof global !== "undefined"
? global
: typeof globalThis !== "undefined"
? globalThis
: typeof self !== "undefined"
? self
: {};
Expand Down
2 changes: 1 addition & 1 deletion packages/bundler-plugin-core/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ describe("getDebugIdSnippet", () => {
it("returns the debugId injection snippet for a passed debugId", () => {
const snippet = getDebugIdSnippet("1234");
expect(snippet).toMatchInlineSnapshot(
`";!function(){try{var e=\\"undefined\\"!=typeof window?window:\\"undefined\\"!=typeof global?global:\\"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){}}();"`
`";!function(){try{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){}}();"`
);
});
});
4 changes: 4 additions & 0 deletions packages/bundler-plugin-core/test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ describe("generateModuleMetadataInjectorCode", () => {
? window
: typeof global !== \\"undefined\\"
? global
: typeof globalThis !== \\"undefined\\"
? globalThis
: typeof self !== \\"undefined\\"
? self
: {};
Expand Down Expand Up @@ -259,6 +261,8 @@ describe("generateModuleMetadataInjectorCode", () => {
? window
: typeof global !== \\"undefined\\"
? global
: typeof globalThis !== \\"undefined\\"
? globalThis
: typeof self !== \\"undefined\\"
? self
: {};
Expand Down
Loading