diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/esbuild/cjs-directives.config.js b/dev-packages/bundler-plugin-integration-tests/fixtures/esbuild/cjs-directives.config.js new file mode 100644 index 000000000000..30a9bf23f2b1 --- /dev/null +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/esbuild/cjs-directives.config.js @@ -0,0 +1,55 @@ +import * as esbuild from "esbuild"; +import { sentryEsbuildPlugin } from "@sentry/bundler-plugins/esbuild"; + +await esbuild.build({ + entryPoints: { + sloppy: "./src/sloppy-mode.cjs", + }, + bundle: true, + outdir: "./out/cjs-directives/without-plugin", + outExtension: { ".js": ".cjs" }, + minify: false, + format: "cjs", + tsconfigRaw: { compilerOptions: { alwaysStrict: false } }, +}); + +await esbuild.build({ + entryPoints: { + strict: "./src/strict-mode.cjs", + sloppy: "./src/sloppy-mode.cjs", + }, + bundle: true, + outdir: "./out/cjs-directives/static-injection", + outExtension: { ".js": ".cjs" }, + minify: false, + format: "cjs", + tsconfigRaw: { compilerOptions: { alwaysStrict: false } }, + plugins: [ + sentryEsbuildPlugin({ + telemetry: false, + release: { name: "strict-mode-release", create: false }, + sourcemaps: { disable: true }, + }), + ], +}); + +await esbuild.build({ + entryPoints: { + strict: "./src/strict-mode.cjs", + sloppy: "./src/sloppy-mode.cjs", + }, + bundle: true, + outdir: "./out/cjs-directives/debug-id-injection", + outExtension: { ".js": ".cjs" }, + minify: false, + format: "cjs", + sourcemap: true, + tsconfigRaw: { compilerOptions: { alwaysStrict: false } }, + plugins: [ + sentryEsbuildPlugin({ + telemetry: false, + release: { inject: false }, + sourcemaps: { disable: "disable-upload" }, + }), + ], +}); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/esbuild/cjs-directives.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/esbuild/cjs-directives.test.ts new file mode 100644 index 000000000000..cfb43ef05ae8 --- /dev/null +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/esbuild/cjs-directives.test.ts @@ -0,0 +1,32 @@ +import { expect } from "vitest"; +import { test } from "./utils"; + +test(import.meta.url, ({ runBundler, runFileInNode }) => { + runBundler(); + + expect(JSON.parse(runFileInNode("without-plugin/sloppy.cjs"))).toEqual({ + sloppyModePreserved: true, + releaseInjected: false, + debugIdInjected: false, + }); + expect(JSON.parse(runFileInNode("static-injection/strict.cjs"))).toEqual({ + strictModePreserved: true, + releaseInjected: true, + debugIdInjected: false, + }); + expect(JSON.parse(runFileInNode("static-injection/sloppy.cjs"))).toEqual({ + sloppyModePreserved: true, + releaseInjected: true, + debugIdInjected: false, + }); + expect(JSON.parse(runFileInNode("debug-id-injection/strict.cjs"))).toEqual({ + strictModePreserved: true, + releaseInjected: false, + debugIdInjected: true, + }); + expect(JSON.parse(runFileInNode("debug-id-injection/sloppy.cjs"))).toEqual({ + sloppyModePreserved: true, + releaseInjected: false, + debugIdInjected: true, + }); +}); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/esbuild/src/sloppy-mode.cjs b/dev-packages/bundler-plugin-integration-tests/fixtures/esbuild/src/sloppy-mode.cjs new file mode 100644 index 000000000000..ce708c7a27de --- /dev/null +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/esbuild/src/sloppy-mode.cjs @@ -0,0 +1,12 @@ +globalThis.sloppyModePreserved = + (function () { + return this; + })() === globalThis; + +console.log( + JSON.stringify({ + sloppyModePreserved: globalThis.sloppyModePreserved, + releaseInjected: globalThis.SENTRY_RELEASE?.id === "strict-mode-release", + debugIdInjected: Object.keys(globalThis._sentryDebugIds || {}).length === 1, + }) +); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/esbuild/src/strict-mode.cjs b/dev-packages/bundler-plugin-integration-tests/fixtures/esbuild/src/strict-mode.cjs new file mode 100644 index 000000000000..fa2e93dba59b --- /dev/null +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/esbuild/src/strict-mode.cjs @@ -0,0 +1,14 @@ +"use strict"; + +globalThis.strictModePreserved = + (function () { + return this; + })() === undefined; + +console.log( + JSON.stringify({ + strictModePreserved: globalThis.strictModePreserved, + releaseInjected: globalThis.SENTRY_RELEASE?.id === "strict-mode-release", + debugIdInjected: Object.keys(globalThis._sentryDebugIds || {}).length === 1, + }) +); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/after-upload-deletion.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/after-upload-deletion.test.ts index a4305945f767..0bce8d75055b 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/after-upload-deletion.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/after-upload-deletion.test.ts @@ -6,7 +6,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => { expect(readOutputFiles()).toMatchInlineSnapshot(` { "basic.js": "// eslint-disable-next-line no-console - !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();console.log("hello world"); + !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + console.log("hello world"); //# sourceMappingURL=basic.js.map ", } diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/application-key.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/application-key.test.ts index 893eb03cfbb1..9281f822cb81 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/application-key.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/application-key.test.ts @@ -6,7 +6,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles }) => { expect(readOutputFiles()).toMatchInlineSnapshot(` { "basic.js": "// eslint-disable-next-line no-console - !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[(new e.Error).stack]=function(e){for(var n=1;n { expect(readOutputFiles()).toMatchInlineSnapshot(` { "basic.js": "// eslint-disable-next-line no-console - !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();console.log("hello world"); + !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + console.log("hello world"); ", "sentry-cli-mock.json": "["release","create","CURRENT_SHA","--project","fake-project"], ["release","set-commits","CURRENT_SHA","--auto"], diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/basic-release-disabled.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/basic-release-disabled.test.ts index ebf24e57ed36..afb3e329719b 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/basic-release-disabled.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/basic-release-disabled.test.ts @@ -6,7 +6,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles }) => { expect(readOutputFiles()).toMatchInlineSnapshot(` { "basic.js": "// eslint-disable-next-line no-console - !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();console.log("hello world"); + !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + console.log("hello world"); ", } `); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/basic-sourcemaps.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/basic-sourcemaps.test.ts index 1973196d89aa..c4f4c0618a3c 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/basic-sourcemaps.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/basic-sourcemaps.test.ts @@ -6,10 +6,11 @@ test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => { expect(readOutputFiles()).toMatchInlineSnapshot(` { "basic.js": "// eslint-disable-next-line no-console - !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();console.log("hello world"); + !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + console.log("hello world"); //# sourceMappingURL=basic.js.map ", - "basic.js.map": "{"version":3,"file":"basic.js","sources":["../../src/basic.js"],"sourcesContent":["// eslint-disable-next-line no-console\\nconsole.log(\\"hello world\\");\\n"],"names":[],"mappings":"AAAA,CAAA,CAAA,CAAA,MAAA,CAAA,OAAA,CAAA,IAAA,CAAA,IAAA,CAAA,EAAA,CAAA;scACA,OAAO,CAAC,GAAG,CAAC,CAAA,KAAA,CAAA,KAAA,CAAa,CAAC"}", + "basic.js.map": "{"version":3,"file":"basic.js","sources":["../../src/basic.js"],"sourcesContent":["// eslint-disable-next-line no-console\\nconsole.log(\\"hello world\\");\\n"],"names":[],"mappings":"AAAA,CAAA,CAAA,CAAA,MAAA,CAAA,OAAA,CAAA,IAAA,CAAA,IAAA,CAAA,EAAA,CAAA;;AACA,OAAO,CAAC,GAAG,CAAC,CAAA,KAAA,CAAA,KAAA,CAAa,CAAC"}", "sentry-cli-mock.json": "["release","create","CURRENT_SHA","--project","fake-project"], ["release","set-commits","CURRENT_SHA","--auto"], ["release","finalize","CURRENT_SHA"], diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/basic.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/basic.test.ts index b160e72a864c..8877d0a9eb48 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/basic.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/basic.test.ts @@ -6,7 +6,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => { expect(readOutputFiles()).toMatchInlineSnapshot(` { "basic.js": "// eslint-disable-next-line no-console - !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();console.log("hello world"); + !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + console.log("hello world"); ", "sentry-cli-mock.json": "["release","create","CURRENT_SHA","--project","fake-project"], ["release","set-commits","CURRENT_SHA","--auto"], diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/build-info.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/build-info.test.ts index e9b8e53ac2e3..d9dc4b1f6de6 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/build-info.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/build-info.test.ts @@ -6,7 +6,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles }) => { expect(readOutputFiles()).toMatchInlineSnapshot(` { "basic.js": "// eslint-disable-next-line no-console - !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"build-information-injection-test"};e.SENTRY_BUILD_INFO={"deps":["@rollup/plugin-babel","@rollup/plugin-node-resolve","@sentry/bundler-plugins","react","rollup"],"depsVersions":{"react":19,"rollup":3},"nodeVersion":"NODE_VERSION"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();console.log("hello world"); + !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"build-information-injection-test"};e.SENTRY_BUILD_INFO={"deps":["@rollup/plugin-babel","@rollup/plugin-node-resolve","@sentry/bundler-plugins","react","rollup"],"depsVersions":{"react":19,"rollup":3},"nodeVersion":"NODE_VERSION"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + console.log("hello world"); ", } `); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/bundle-size-optimizations.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/bundle-size-optimizations.test.ts index c685a2b794e2..0bf9ac671a0b 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/bundle-size-optimizations.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/bundle-size-optimizations.test.ts @@ -5,7 +5,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => { runBundler(); expect(readOutputFiles()).toMatchInlineSnapshot(` { - "bundle.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();console.log( + "bundle.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + console.log( JSON.stringify({ debug: "b", trace: "b", diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/component-annotation-disabled.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/component-annotation-disabled.test.ts index 054e90c0e827..fe72a52582ca 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/component-annotation-disabled.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/component-annotation-disabled.test.ts @@ -5,7 +5,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles }) => { runBundler(); expect(readOutputFiles()).toMatchInlineSnapshot(` { - "app.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();import { jsx, jsxs } from 'react/jsx-runtime'; + "app.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + import { jsx, jsxs } from 'react/jsx-runtime'; function ComponentA() { return /*#__PURE__*/jsx("span", { diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/component-annotation-next.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/component-annotation-next.test.ts index 62cfe0816cc5..736ee15f00cc 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/component-annotation-next.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/component-annotation-next.test.ts @@ -5,7 +5,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles }) => { runBundler(); expect(readOutputFiles()).toMatchInlineSnapshot(` { - "app.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();import { jsx, jsxs } from 'react/jsx-runtime'; + "app.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + import { jsx, jsxs } from 'react/jsx-runtime'; function ComponentA() { return /*#__PURE__*/jsx("span", { diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/component-annotation.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/component-annotation.test.ts index 387beb7fda07..e26693d043bc 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/component-annotation.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/component-annotation.test.ts @@ -5,7 +5,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles }) => { runBundler(); expect(readOutputFiles()).toMatchInlineSnapshot(` { - "app.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();import { jsx, jsxs } from 'react/jsx-runtime'; + "app.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + import { jsx, jsxs } from 'react/jsx-runtime'; function ComponentA() { return /*#__PURE__*/jsx("span", { diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/dont-mess-up-user-code.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/dont-mess-up-user-code.test.ts index 42d6d3679b9c..87edc97eee9c 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/dont-mess-up-user-code.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/dont-mess-up-user-code.test.ts @@ -6,13 +6,14 @@ test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => { expect(readOutputFiles()).toMatchInlineSnapshot(` { "index.js": "// eslint-disable-next-line no-console - !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"I am release!"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();console.log("I am import!"); + !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"I am release!"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + console.log("I am import!"); // eslint-disable-next-line no-console console.log("I am index!"); //# sourceMappingURL=index.js.map ", - "index.js.map": "{"version":3,"file":"index.js","sources":["../../src/import.js","../../src/index.js"],"sourcesContent":["// eslint-disable-next-line no-console\\nconsole.log(\\"I am import!\\");\\n\\nexport {};\\n","import \\"./import\\";\\n\\n// eslint-disable-next-line no-console\\nconsole.log(\\"I am index!\\");\\n"],"names":[],"mappings":"AAAA,CAAA,CAAA,CAAA,MAAA,CAAA,OAAA,CAAA,IAAA,CAAA,IAAA,CAAA,EAAA,CAAA;2aACA,OAAO,CAAC,GAAG,CAAC,CAAA,CAAA,CAAA,EAAA,CAAA,MAAA,CAAA,CAAc,CAAC;;ACC3B,CAAA,CAAA,CAAA,MAAA,CAAA,OAAA,CAAA,IAAA,CAAA,IAAA,CAAA,EAAA,CAAA;AACA,OAAO,CAAC,GAAG,CAAC,CAAA,CAAA,CAAA,EAAA,CAAA,KAAA,CAAA,CAAa,CAAC"}", + "index.js.map": "{"version":3,"file":"index.js","sources":["../../src/import.js","../../src/index.js"],"sourcesContent":["// eslint-disable-next-line no-console\\nconsole.log(\\"I am import!\\");\\n\\nexport {};\\n","import \\"./import\\";\\n\\n// eslint-disable-next-line no-console\\nconsole.log(\\"I am index!\\");\\n"],"names":[],"mappings":"AAAA,CAAA,CAAA,CAAA,MAAA,CAAA,OAAA,CAAA,IAAA,CAAA,IAAA,CAAA,EAAA,CAAA;;AACA,OAAO,CAAC,GAAG,CAAC,CAAA,CAAA,CAAA,EAAA,CAAA,MAAA,CAAA,CAAc,CAAC;;ACC3B,CAAA,CAAA,CAAA,MAAA,CAAA,OAAA,CAAA,IAAA,CAAA,IAAA,CAAA,EAAA,CAAA;AACA,OAAO,CAAC,GAAG,CAAC,CAAA,CAAA,CAAA,EAAA,CAAA,KAAA,CAAA,CAAa,CAAC"}", } `); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/module-metadata.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/module-metadata.test.ts index b4acc59902a5..cd934b859408 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/module-metadata.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/module-metadata.test.ts @@ -6,7 +6,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => { expect(readOutputFiles()).toMatchInlineSnapshot(` { "basic.js": "// eslint-disable-next-line no-console - !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[(new e.Error).stack]=function(e){for(var n=1;n { runBundler(); expect(readOutputFiles()).toMatchInlineSnapshot(` { - "common.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();function add(a, b) { + "common.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + function add(a, b) { return a + b; } export { add as a }; ", - "entry1.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();import { a as add } from './common.js'; + "entry1.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + import { a as add } from './common.js'; console.log(add(1, 2)); ", - "entry2.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();import { a as add } from './common.js'; + "entry2.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + import { a as add } from './common.js'; console.log(add(2, 4)); ", diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/query-param.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/query-param.test.ts index d65cb2e349da..8200af8ddcf4 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/query-param.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/query-param.test.ts @@ -10,17 +10,20 @@ test(import.meta.url, ({ runBundler, readOutputFiles, ctx }) => { runBundler(); expect(readOutputFiles()).toMatchInlineSnapshot(` { - "common.js?seP58q4g": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();function add(a, b) { + "common.js?seP58q4g": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + function add(a, b) { return a + b; } export { add as a }; ", - "entry1.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();import { a as add } from './common.js?seP58q4g'; + "entry1.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + import { a as add } from './common.js?seP58q4g'; console.log(add(1, 2)); ", - "entry2.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();import { a as add } from './common.js?seP58q4g'; + "entry2.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + import { a as add } from './common.js?seP58q4g'; console.log(add(2, 4)); ", diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/release-disabled.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/release-disabled.test.ts index 39c7da1959d9..c2a17292386d 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/release-disabled.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/release-disabled.test.ts @@ -6,7 +6,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles }) => { expect(readOutputFiles()).toMatchInlineSnapshot(` { "basic.js": "// eslint-disable-next-line no-console - !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();console.log("hello world"); + !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + console.log("hello world"); ", "sentry-cli-mock.json": "["release","set-commits","CURRENT_SHA","--auto"], ["release","finalize","CURRENT_SHA"], diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/telemetry.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/telemetry.test.ts index 970ebdaefd1d..4889fa9c3031 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/telemetry.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup3/telemetry.test.ts @@ -6,7 +6,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => { expect(readOutputFiles()).toMatchInlineSnapshot(` { "basic.js": "// eslint-disable-next-line no-console - !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();console.log("hello world"); + !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + console.log("hello world"); ", "sentry-telemetry.json": "[{"sent_at":"TIMESTAMP","sdk":{"name":"sentry.javascript.node","version":"SDK_VERSION"}},[[{"type":"session"},{"sid":"UUID","init":true,"started":"TIMESTAMP","timestamp":"TIMESTAMP","status":"ok","errors":0,"duration":DURATION,"attrs":{"release":"PLUGIN_VERSION","environment":"production"}}]]], [{"event_id":"UUID","sent_at":"TIMESTAMP","sdk":{"name":"sentry.javascript.node","version":"SDK_VERSION"},"trace":{"environment":"production","release":"PLUGIN_VERSION","public_key":"UUID","trace_id":"UUID","org_id":"1","transaction":"Sentry Bundler Plugin execution","sampled":"true","sample_rand":"SAMPLE_RAND","sample_rate":"1"}},[[{"type":"transaction"},{"contexts":{"trace":{"span_id":"SHORT_UUID","trace_id":"UUID","data":{"sentry.origin":"manual","sentry.segment.name.source":"custom","sentry.sample_rate":1},"status":"ok","origin":"manual"},"runtime":{"name":"node","version":"NODE_VERSION"}},"spans":[],"start_timestamp":START_TIMESTAMP,"timestamp":TIMESTAMP,"transaction":"Sentry Bundler Plugin execution","type":"transaction","transaction_info":{"source":"custom"},"platform":"PLATFORM","event_id":"UUID","environment":"production","release":"PLUGIN_VERSION","tags":{"upload-legacy-sourcemaps":false,"module-metadata":false,"inject-build-information":false,"set-commits":"auto","finalize-release":true,"deploy-options":false,"custom-error-handler":false,"sourcemaps-assets":false,"delete-after-upload":false,"sourcemaps-disabled":false,"react-annotate":false,"node":"NODE_VERSION","platform":"PLATFORM","meta-framework":"none","application-key-set":false,"ci":true,"project":"undefined","bundler":"rollup","bundler-major-version":"3"},"user":{},"sdk":{"name":"sentry.javascript.node","version":"SDK_VERSION","integrations":[],"packages":[{"name":"npm:@sentry/node","version":"SDK_VERSION"}]}}]]], diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/after-upload-deletion.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/after-upload-deletion.test.ts index a4305945f767..0bce8d75055b 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/after-upload-deletion.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/after-upload-deletion.test.ts @@ -6,7 +6,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => { expect(readOutputFiles()).toMatchInlineSnapshot(` { "basic.js": "// eslint-disable-next-line no-console - !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();console.log("hello world"); + !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + console.log("hello world"); //# sourceMappingURL=basic.js.map ", } diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/application-key.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/application-key.test.ts index 893eb03cfbb1..9281f822cb81 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/application-key.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/application-key.test.ts @@ -6,7 +6,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles }) => { expect(readOutputFiles()).toMatchInlineSnapshot(` { "basic.js": "// eslint-disable-next-line no-console - !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[(new e.Error).stack]=function(e){for(var n=1;n { expect(readOutputFiles()).toMatchInlineSnapshot(` { "basic.js": "// eslint-disable-next-line no-console - !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();console.log("hello world"); + !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + console.log("hello world"); ", "sentry-cli-mock.json": "["release","create","CURRENT_SHA","--project","fake-project"], ["release","set-commits","CURRENT_SHA","--auto"], diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/basic-release-disabled.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/basic-release-disabled.test.ts index ebf24e57ed36..afb3e329719b 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/basic-release-disabled.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/basic-release-disabled.test.ts @@ -6,7 +6,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles }) => { expect(readOutputFiles()).toMatchInlineSnapshot(` { "basic.js": "// eslint-disable-next-line no-console - !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();console.log("hello world"); + !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + console.log("hello world"); ", } `); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/basic-sourcemaps.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/basic-sourcemaps.test.ts index 1973196d89aa..c4f4c0618a3c 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/basic-sourcemaps.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/basic-sourcemaps.test.ts @@ -6,10 +6,11 @@ test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => { expect(readOutputFiles()).toMatchInlineSnapshot(` { "basic.js": "// eslint-disable-next-line no-console - !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();console.log("hello world"); + !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + console.log("hello world"); //# sourceMappingURL=basic.js.map ", - "basic.js.map": "{"version":3,"file":"basic.js","sources":["../../src/basic.js"],"sourcesContent":["// eslint-disable-next-line no-console\\nconsole.log(\\"hello world\\");\\n"],"names":[],"mappings":"AAAA,CAAA,CAAA,CAAA,MAAA,CAAA,OAAA,CAAA,IAAA,CAAA,IAAA,CAAA,EAAA,CAAA;scACA,OAAO,CAAC,GAAG,CAAC,CAAA,KAAA,CAAA,KAAA,CAAa,CAAC"}", + "basic.js.map": "{"version":3,"file":"basic.js","sources":["../../src/basic.js"],"sourcesContent":["// eslint-disable-next-line no-console\\nconsole.log(\\"hello world\\");\\n"],"names":[],"mappings":"AAAA,CAAA,CAAA,CAAA,MAAA,CAAA,OAAA,CAAA,IAAA,CAAA,IAAA,CAAA,EAAA,CAAA;;AACA,OAAO,CAAC,GAAG,CAAC,CAAA,KAAA,CAAA,KAAA,CAAa,CAAC"}", "sentry-cli-mock.json": "["release","create","CURRENT_SHA","--project","fake-project"], ["release","set-commits","CURRENT_SHA","--auto"], ["release","finalize","CURRENT_SHA"], diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/basic.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/basic.test.ts index b160e72a864c..8877d0a9eb48 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/basic.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/basic.test.ts @@ -6,7 +6,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => { expect(readOutputFiles()).toMatchInlineSnapshot(` { "basic.js": "// eslint-disable-next-line no-console - !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();console.log("hello world"); + !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + console.log("hello world"); ", "sentry-cli-mock.json": "["release","create","CURRENT_SHA","--project","fake-project"], ["release","set-commits","CURRENT_SHA","--auto"], diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/build-info.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/build-info.test.ts index 3dca9559e716..eab4c35fc0b3 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/build-info.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/build-info.test.ts @@ -6,7 +6,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles }) => { expect(readOutputFiles()).toMatchInlineSnapshot(` { "basic.js": "// eslint-disable-next-line no-console - !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"build-information-injection-test"};e.SENTRY_BUILD_INFO={"deps":["@rollup/plugin-babel","@rollup/plugin-node-resolve","@sentry/bundler-plugins","react","rollup"],"depsVersions":{"react":19,"rollup":4},"nodeVersion":"NODE_VERSION"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();console.log("hello world"); + !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"build-information-injection-test"};e.SENTRY_BUILD_INFO={"deps":["@rollup/plugin-babel","@rollup/plugin-node-resolve","@sentry/bundler-plugins","react","rollup"],"depsVersions":{"react":19,"rollup":4},"nodeVersion":"NODE_VERSION"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + console.log("hello world"); ", } `); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/bundle-size-optimizations.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/bundle-size-optimizations.test.ts index c685a2b794e2..0bf9ac671a0b 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/bundle-size-optimizations.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/bundle-size-optimizations.test.ts @@ -5,7 +5,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => { runBundler(); expect(readOutputFiles()).toMatchInlineSnapshot(` { - "bundle.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();console.log( + "bundle.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + console.log( JSON.stringify({ debug: "b", trace: "b", diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/component-annotation-disabled.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/component-annotation-disabled.test.ts index 054e90c0e827..fe72a52582ca 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/component-annotation-disabled.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/component-annotation-disabled.test.ts @@ -5,7 +5,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles }) => { runBundler(); expect(readOutputFiles()).toMatchInlineSnapshot(` { - "app.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();import { jsx, jsxs } from 'react/jsx-runtime'; + "app.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + import { jsx, jsxs } from 'react/jsx-runtime'; function ComponentA() { return /*#__PURE__*/jsx("span", { diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/component-annotation-next.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/component-annotation-next.test.ts index 62cfe0816cc5..736ee15f00cc 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/component-annotation-next.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/component-annotation-next.test.ts @@ -5,7 +5,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles }) => { runBundler(); expect(readOutputFiles()).toMatchInlineSnapshot(` { - "app.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();import { jsx, jsxs } from 'react/jsx-runtime'; + "app.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + import { jsx, jsxs } from 'react/jsx-runtime'; function ComponentA() { return /*#__PURE__*/jsx("span", { diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/component-annotation.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/component-annotation.test.ts index 387beb7fda07..e26693d043bc 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/component-annotation.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/component-annotation.test.ts @@ -5,7 +5,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles }) => { runBundler(); expect(readOutputFiles()).toMatchInlineSnapshot(` { - "app.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();import { jsx, jsxs } from 'react/jsx-runtime'; + "app.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + import { jsx, jsxs } from 'react/jsx-runtime'; function ComponentA() { return /*#__PURE__*/jsx("span", { diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/debugids-already-injected.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/debugids-already-injected.test.ts index de92ed454402..8242f692f0b7 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/debugids-already-injected.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/debugids-already-injected.test.ts @@ -10,11 +10,12 @@ test(import.meta.url, ({ runBundler, createTempDir }) => { expect(files).toMatchInlineSnapshot(` { "252e0338-8927-4f52-bd57-188131defd0f-0.js": "// eslint-disable-next-line no-console - !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();console.log("hello world"); + !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + console.log("hello world"); //# debugId=00000000-0000-0000-0000-000000000000 //# sourceMappingURL=basic.js.map ", - "252e0338-8927-4f52-bd57-188131defd0f-0.js.map": "{"version":3,"file":"basic.js","sources":["../../src/basic.js"],"sourcesContent":["// eslint-disable-next-line no-console\\nconsole.log(\\"hello world\\");\\n"],"names":[],"mappings":"AAAA,CAAA,CAAA,CAAA,MAAA,CAAA,OAAA,CAAA,IAAA,CAAA,IAAA,CAAA,EAAA,CAAA;scACA,OAAO,CAAC,GAAG,CAAC,CAAA,KAAA,CAAA,KAAA,CAAa,CAAC","debugId":"252e0338-8927-4f52-bd57-188131defd0f","debug_id":"252e0338-8927-4f52-bd57-188131defd0f"}", + "252e0338-8927-4f52-bd57-188131defd0f-0.js.map": "{"version":3,"file":"basic.js","sources":["../../src/basic.js"],"sourcesContent":["// eslint-disable-next-line no-console\\nconsole.log(\\"hello world\\");\\n"],"names":[],"mappings":"AAAA,CAAA,CAAA,CAAA,MAAA,CAAA,OAAA,CAAA,IAAA,CAAA,IAAA,CAAA,EAAA,CAAA;;AACA,OAAO,CAAC,GAAG,CAAC,CAAA,KAAA,CAAA,KAAA,CAAa,CAAC","debugId":"252e0338-8927-4f52-bd57-188131defd0f","debug_id":"252e0338-8927-4f52-bd57-188131defd0f"}", } `); }); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/dont-mess-up-user-code.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/dont-mess-up-user-code.test.ts index 42d6d3679b9c..87edc97eee9c 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/dont-mess-up-user-code.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/dont-mess-up-user-code.test.ts @@ -6,13 +6,14 @@ test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => { expect(readOutputFiles()).toMatchInlineSnapshot(` { "index.js": "// eslint-disable-next-line no-console - !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"I am release!"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();console.log("I am import!"); + !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"I am release!"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + console.log("I am import!"); // eslint-disable-next-line no-console console.log("I am index!"); //# sourceMappingURL=index.js.map ", - "index.js.map": "{"version":3,"file":"index.js","sources":["../../src/import.js","../../src/index.js"],"sourcesContent":["// eslint-disable-next-line no-console\\nconsole.log(\\"I am import!\\");\\n\\nexport {};\\n","import \\"./import\\";\\n\\n// eslint-disable-next-line no-console\\nconsole.log(\\"I am index!\\");\\n"],"names":[],"mappings":"AAAA,CAAA,CAAA,CAAA,MAAA,CAAA,OAAA,CAAA,IAAA,CAAA,IAAA,CAAA,EAAA,CAAA;2aACA,OAAO,CAAC,GAAG,CAAC,CAAA,CAAA,CAAA,EAAA,CAAA,MAAA,CAAA,CAAc,CAAC;;ACC3B,CAAA,CAAA,CAAA,MAAA,CAAA,OAAA,CAAA,IAAA,CAAA,IAAA,CAAA,EAAA,CAAA;AACA,OAAO,CAAC,GAAG,CAAC,CAAA,CAAA,CAAA,EAAA,CAAA,KAAA,CAAA,CAAa,CAAC"}", + "index.js.map": "{"version":3,"file":"index.js","sources":["../../src/import.js","../../src/index.js"],"sourcesContent":["// eslint-disable-next-line no-console\\nconsole.log(\\"I am import!\\");\\n\\nexport {};\\n","import \\"./import\\";\\n\\n// eslint-disable-next-line no-console\\nconsole.log(\\"I am index!\\");\\n"],"names":[],"mappings":"AAAA,CAAA,CAAA,CAAA,MAAA,CAAA,OAAA,CAAA,IAAA,CAAA,IAAA,CAAA,EAAA,CAAA;;AACA,OAAO,CAAC,GAAG,CAAC,CAAA,CAAA,CAAA,EAAA,CAAA,MAAA,CAAA,CAAc,CAAC;;ACC3B,CAAA,CAAA,CAAA,MAAA,CAAA,OAAA,CAAA,IAAA,CAAA,IAAA,CAAA,EAAA,CAAA;AACA,OAAO,CAAC,GAAG,CAAC,CAAA,CAAA,CAAA,EAAA,CAAA,KAAA,CAAA,CAAa,CAAC"}", } `); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/module-metadata.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/module-metadata.test.ts index b4acc59902a5..cd934b859408 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/module-metadata.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/module-metadata.test.ts @@ -6,7 +6,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => { expect(readOutputFiles()).toMatchInlineSnapshot(` { "basic.js": "// eslint-disable-next-line no-console - !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[(new e.Error).stack]=function(e){for(var n=1;n { runBundler(); expect(readOutputFiles()).toMatchInlineSnapshot(` { - "common.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();function add(a, b) { + "common.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + function add(a, b) { return a + b; } export { add as a }; ", - "entry1.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();import { a as add } from './common.js'; + "entry1.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + import { a as add } from './common.js'; console.log(add(1, 2)); ", - "entry2.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();import { a as add } from './common.js'; + "entry2.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + import { a as add } from './common.js'; console.log(add(2, 4)); ", diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/query-param.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/query-param.test.ts index d65cb2e349da..8200af8ddcf4 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/query-param.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/query-param.test.ts @@ -10,17 +10,20 @@ test(import.meta.url, ({ runBundler, readOutputFiles, ctx }) => { runBundler(); expect(readOutputFiles()).toMatchInlineSnapshot(` { - "common.js?seP58q4g": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();function add(a, b) { + "common.js?seP58q4g": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + function add(a, b) { return a + b; } export { add as a }; ", - "entry1.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();import { a as add } from './common.js?seP58q4g'; + "entry1.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + import { a as add } from './common.js?seP58q4g'; console.log(add(1, 2)); ", - "entry2.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();import { a as add } from './common.js?seP58q4g'; + "entry2.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + import { a as add } from './common.js?seP58q4g'; console.log(add(2, 4)); ", diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/release-disabled.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/release-disabled.test.ts index 39c7da1959d9..c2a17292386d 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/release-disabled.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/release-disabled.test.ts @@ -6,7 +6,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles }) => { expect(readOutputFiles()).toMatchInlineSnapshot(` { "basic.js": "// eslint-disable-next-line no-console - !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();console.log("hello world"); + !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + console.log("hello world"); ", "sentry-cli-mock.json": "["release","set-commits","CURRENT_SHA","--auto"], ["release","finalize","CURRENT_SHA"], diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/telemetry.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/telemetry.test.ts index cfb27aee5b5e..6a979c32c9cc 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/telemetry.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/telemetry.test.ts @@ -6,7 +6,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => { expect(readOutputFiles()).toMatchInlineSnapshot(` { "basic.js": "// eslint-disable-next-line no-console - !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();console.log("hello world"); + !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + console.log("hello world"); ", "sentry-telemetry.json": "[{"sent_at":"TIMESTAMP","sdk":{"name":"sentry.javascript.node","version":"SDK_VERSION"}},[[{"type":"session"},{"sid":"UUID","init":true,"started":"TIMESTAMP","timestamp":"TIMESTAMP","status":"ok","errors":0,"duration":DURATION,"attrs":{"release":"PLUGIN_VERSION","environment":"production"}}]]], [{"event_id":"UUID","sent_at":"TIMESTAMP","sdk":{"name":"sentry.javascript.node","version":"SDK_VERSION"},"trace":{"environment":"production","release":"PLUGIN_VERSION","public_key":"UUID","trace_id":"UUID","org_id":"1","transaction":"Sentry Bundler Plugin execution","sampled":"true","sample_rand":"SAMPLE_RAND","sample_rate":"1"}},[[{"type":"transaction"},{"contexts":{"trace":{"span_id":"SHORT_UUID","trace_id":"UUID","data":{"sentry.origin":"manual","sentry.segment.name.source":"custom","sentry.sample_rate":1},"status":"ok","origin":"manual"},"runtime":{"name":"node","version":"NODE_VERSION"}},"spans":[],"start_timestamp":START_TIMESTAMP,"timestamp":TIMESTAMP,"transaction":"Sentry Bundler Plugin execution","type":"transaction","transaction_info":{"source":"custom"},"platform":"PLATFORM","event_id":"UUID","environment":"production","release":"PLUGIN_VERSION","tags":{"upload-legacy-sourcemaps":false,"module-metadata":false,"inject-build-information":false,"set-commits":"auto","finalize-release":true,"deploy-options":false,"custom-error-handler":false,"sourcemaps-assets":false,"delete-after-upload":false,"sourcemaps-disabled":false,"react-annotate":false,"node":"NODE_VERSION","platform":"PLATFORM","meta-framework":"none","application-key-set":false,"ci":true,"project":"undefined","bundler":"rollup","bundler-major-version":"4"},"user":{},"sdk":{"name":"sentry.javascript.node","version":"SDK_VERSION","integrations":[],"packages":[{"name":"npm:@sentry/node","version":"SDK_VERSION"}]}}]]], diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/after-upload-deletion.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/after-upload-deletion.test.ts index a4bcd8a767cb..021d4743e331 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/after-upload-deletion.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/after-upload-deletion.test.ts @@ -5,8 +5,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => { runBundler(); expect(readOutputFiles()).toMatchInlineSnapshot(` { - "basic.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); - /******/ (() => { // webpackBootstrap + "basic.js": "/******/ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + (() => { // webpackBootstrap /******/ "use strict"; // eslint-disable-next-line no-console console.log("hello world"); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/application-key.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/application-key.test.ts index 76b6d9adb0e8..71121ac814cb 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/application-key.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/application-key.test.ts @@ -5,8 +5,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles }) => { runBundler(); expect(readOutputFiles()).toMatchInlineSnapshot(` { - "basic.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[(new e.Error).stack]=function(e){for(var n=1;n { // webpackBootstrap + "basic.js": "/******/ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[(new e.Error).stack]=function(e){for(var n=1;n { // webpackBootstrap /******/ "use strict"; // eslint-disable-next-line no-console console.log("hello world"); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/basic-cjs.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/basic-cjs.test.ts index 8095d1ba0754..f12e4b7fc737 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/basic-cjs.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/basic-cjs.test.ts @@ -5,8 +5,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => { runBundler(); expect(readOutputFiles()).toMatchInlineSnapshot(` { - "basic.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); - /******/ (() => { // webpackBootstrap + "basic.js": "/******/ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + (() => { // webpackBootstrap /******/ "use strict"; // eslint-disable-next-line no-console console.log("hello world"); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/basic-release-disabled.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/basic-release-disabled.test.ts index c7fc5905957a..42134e3f0a58 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/basic-release-disabled.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/basic-release-disabled.test.ts @@ -5,8 +5,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles }) => { runBundler(); expect(readOutputFiles()).toMatchInlineSnapshot(` { - "basic.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); - /******/ (() => { // webpackBootstrap + "basic.js": "/******/ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + (() => { // webpackBootstrap /******/ "use strict"; // eslint-disable-next-line no-console console.log("hello world"); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/basic-sourcemaps.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/basic-sourcemaps.test.ts index fbcababfd029..b7534c90402f 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/basic-sourcemaps.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/basic-sourcemaps.test.ts @@ -5,8 +5,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => { runBundler(); expect(readOutputFiles()).toMatchInlineSnapshot(` { - "basic.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); - /******/ (() => { // webpackBootstrap + "basic.js": "/******/ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + (() => { // webpackBootstrap /******/ "use strict"; // eslint-disable-next-line no-console console.log("hello world"); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/basic.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/basic.test.ts index 8095d1ba0754..f12e4b7fc737 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/basic.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/basic.test.ts @@ -5,8 +5,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => { runBundler(); expect(readOutputFiles()).toMatchInlineSnapshot(` { - "basic.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); - /******/ (() => { // webpackBootstrap + "basic.js": "/******/ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + (() => { // webpackBootstrap /******/ "use strict"; // eslint-disable-next-line no-console console.log("hello world"); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/build-info.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/build-info.test.ts index 4742786c9b76..d29a8157fa40 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/build-info.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/build-info.test.ts @@ -5,8 +5,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles }) => { runBundler(); expect(readOutputFiles()).toMatchInlineSnapshot(` { - "basic.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"build-information-injection-test"};e.SENTRY_BUILD_INFO={"deps":["@babel/preset-react","@sentry/bundler-plugins","babel-loader","webpack","webpack-cli"],"depsVersions":{"webpack":5},"nodeVersion":"NODE_VERSION"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); - /******/ (() => { // webpackBootstrap + "basic.js": "/******/ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"build-information-injection-test"};e.SENTRY_BUILD_INFO={"deps":["@babel/preset-react","@sentry/bundler-plugins","babel-loader","webpack","webpack-cli"],"depsVersions":{"webpack":5},"nodeVersion":"NODE_VERSION"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + (() => { // webpackBootstrap /******/ "use strict"; // eslint-disable-next-line no-console console.log("hello world"); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/bundle-size-optimizations.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/bundle-size-optimizations.test.ts index 7313767b10ad..02079036d9c9 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/bundle-size-optimizations.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/bundle-size-optimizations.test.ts @@ -5,8 +5,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => { runBundler(); expect(readOutputFiles()).toMatchInlineSnapshot(` { - "bundle.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); - /******/ (() => { // webpackBootstrap + "bundle.js": "/******/ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + (() => { // webpackBootstrap /******/ "use strict"; console.log( JSON.stringify({ diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/component-annotation-disabled.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/component-annotation-disabled.test.ts index 39a5b67c4108..78280fc69da0 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/component-annotation-disabled.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/component-annotation-disabled.test.ts @@ -5,8 +5,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles }) => { runBundler(); expect(readOutputFiles()).toMatchInlineSnapshot(` { - "app.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); - /******/ (() => { // webpackBootstrap + "app.js": "/******/ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + (() => { // webpackBootstrap /******/ "use strict"; // UNUSED EXPORTS: default diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/component-annotation-next.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/component-annotation-next.test.ts index 28d9443ae50d..a5556a5624b5 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/component-annotation-next.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/component-annotation-next.test.ts @@ -10,8 +10,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles, ctx }) => { runBundler(); expect(readOutputFiles()).toMatchInlineSnapshot(` { - "app.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); - /******/ (() => { // webpackBootstrap + "app.js": "/******/ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + (() => { // webpackBootstrap /******/ "use strict"; // UNUSED EXPORTS: default diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/component-annotation.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/component-annotation.test.ts index 1c5f9f8cc6ac..495704896f1e 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/component-annotation.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/component-annotation.test.ts @@ -10,8 +10,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles, ctx }) => { runBundler(); expect(readOutputFiles()).toMatchInlineSnapshot(` { - "app.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); - /******/ (() => { // webpackBootstrap + "app.js": "/******/ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + (() => { // webpackBootstrap /******/ "use strict"; // UNUSED EXPORTS: default diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/debugids-already-injected.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/debugids-already-injected.test.ts index 3509e3431c86..096b9c89e43b 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/debugids-already-injected.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/debugids-already-injected.test.ts @@ -9,8 +9,8 @@ test(import.meta.url, ({ runBundler, createTempDir }) => { const files = readAllFiles(tempDir); expect(files).toMatchInlineSnapshot(` { - "33730b8e-5b8d-4795-94b2-666cea28fce6-0.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); - /******/ (() => { // webpackBootstrap + "33730b8e-5b8d-4795-94b2-666cea28fce6-0.js": "/******/ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + (() => { // webpackBootstrap /******/ "use strict"; // eslint-disable-next-line no-console console.log("hello world"); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/module-metadata.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/module-metadata.test.ts index 2672e9edf824..3c3b18580a1d 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/module-metadata.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/module-metadata.test.ts @@ -5,8 +5,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => { runBundler(); expect(readOutputFiles()).toMatchInlineSnapshot(` { - "basic.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[(new e.Error).stack]=function(e){for(var n=1;n { // webpackBootstrap + "basic.js": "/******/ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[(new e.Error).stack]=function(e){for(var n=1;n { // webpackBootstrap /******/ "use strict"; // eslint-disable-next-line no-console console.log("hello world"); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/multiple-entry-points.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/multiple-entry-points.test.ts index 5f054a9ba2da..da52345c24e8 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/multiple-entry-points.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/multiple-entry-points.test.ts @@ -5,8 +5,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => { runBundler(); expect(readOutputFiles()).toMatchInlineSnapshot(` { - "entry1.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); - /******/ (() => { // webpackBootstrap + "entry1.js": "/******/ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + (() => { // webpackBootstrap /******/ "use strict"; ;// ./src/common.js @@ -21,8 +21,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => { /******/ })() ;", - "entry2.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); - /******/ (() => { // webpackBootstrap + "entry2.js": "/******/ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + (() => { // webpackBootstrap /******/ "use strict"; ;// ./src/common.js diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/release-disabled.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/release-disabled.test.ts index 5288fc48bcba..dda6c9ab8889 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/release-disabled.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/release-disabled.test.ts @@ -5,8 +5,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles }) => { runBundler(); expect(readOutputFiles()).toMatchInlineSnapshot(` { - "basic.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); - /******/ (() => { // webpackBootstrap + "basic.js": "/******/ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + (() => { // webpackBootstrap /******/ "use strict"; // eslint-disable-next-line no-console console.log("hello world"); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/telemetry.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/telemetry.test.ts index b26f095092af..d2d6f3d77c7e 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/telemetry.test.ts +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/telemetry.test.ts @@ -5,8 +5,8 @@ test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => { runBundler(); expect(readOutputFiles()).toMatchInlineSnapshot(` { - "basic.js": "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); - /******/ (() => { // webpackBootstrap + "basic.js": "/******/ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}(); + (() => { // webpackBootstrap /******/ "use strict"; // eslint-disable-next-line no-console console.log("hello world"); diff --git a/packages/bundler-plugins/src/core/get-code-injection-position.ts b/packages/bundler-plugins/src/core/get-code-injection-position.ts new file mode 100644 index 000000000000..8ed7ad3cd19e --- /dev/null +++ b/packages/bundler-plugins/src/core/get-code-injection-position.ts @@ -0,0 +1,104 @@ +function isLineTerminator(character: string | undefined): boolean { + return character === '\n' || character === '\r' || character === '\u2028' || character === '\u2029'; +} + +function skipTrivia(code: string, start: number): { end: number; hasLineBreak: boolean } { + let position = start; + let hasLineBreak = false; + + while (position < code.length) { + const character = code[position]; + + if (/\s/.test(character || '')) { + hasLineBreak ||= isLineTerminator(character); + position++; + } else if (code.startsWith('//', position) || (position === 0 && code.startsWith('#!', position))) { + let lineEnd = position + 2; + while (lineEnd < code.length && !isLineTerminator(code[lineEnd])) { + lineEnd++; + } + if (lineEnd === code.length) { + return { end: code.length, hasLineBreak }; + } + position = lineEnd + 1; + hasLineBreak = true; + } else if (code.startsWith('/*', position)) { + const commentEnd = code.indexOf('*/', position + 2); + if (commentEnd === -1) { + return { end: code.length, hasLineBreak }; + } + const comment = code.slice(position, commentEnd + 2); + hasLineBreak ||= /[\n\r\u2028\u2029]/.test(comment); + position = commentEnd + 2; + } else { + break; + } + } + + return { end: position, hasLineBreak }; +} + +function findStringLiteralEnd(code: string, start: number): number | undefined { + const quote = code[start]; + if (quote !== '"' && quote !== "'") { + return undefined; + } + + for (let position = start + 1; position < code.length; position++) { + const character = code[position]; + if (character === '\\') { + position += code[position + 1] === '\r' && code[position + 2] === '\n' ? 2 : 1; + } else if (character === quote) { + return position + 1; + } else if (isLineTerminator(character)) { + return undefined; + } + } + + return undefined; +} + +function startsWithBinaryOperatorKeyword(remainder: string, keyword: string): boolean { + return remainder.startsWith(keyword) && !/^[$_\\\u200C\u200D\p{ID_Continue}]/u.test(remainder.slice(keyword.length)); +} + +function canContinueStringExpression(code: string, position: number): boolean { + const remainder = code.slice(position); + if (/^(?:\+\+|--|!(?!=))/.test(remainder)) { + return false; + } + + return ( + /^!={1,2}/.test(remainder) || + /^[([.`+\-*/%<>=&|^?,:]/.test(remainder) || + ['in', 'instanceof'].some(keyword => startsWithBinaryOperatorKeyword(remainder, keyword)) + ); +} + +export function getCodeInjectionPosition(code: string): number { + let position = skipTrivia(code, 0).end; + let prologueEnd = position; + + while (position < code.length) { + const stringEnd = findStringLiteralEnd(code, position); + if (stringEnd === undefined) { + break; + } + + const trailingTrivia = skipTrivia(code, stringEnd); + if (code[trailingTrivia.end] === ';') { + position = skipTrivia(code, trailingTrivia.end + 1).end; + } else if ( + trailingTrivia.end === code.length || + (trailingTrivia.hasLineBreak && !canContinueStringExpression(code, trailingTrivia.end)) + ) { + position = trailingTrivia.end; + } else { + break; + } + + prologueEnd = position; + } + + return prologueEnd; +} diff --git a/packages/bundler-plugins/src/rollup/index.ts b/packages/bundler-plugins/src/rollup/index.ts index a1ebcb98769d..10482a5e30bf 100644 --- a/packages/bundler-plugins/src/rollup/index.ts +++ b/packages/bundler-plugins/src/rollup/index.ts @@ -7,13 +7,13 @@ import { shouldSkipCodeInjection, getDebugIdSnippet, stringToUUID, - COMMENT_USE_STRICT_REGEX, createDebugIdUploadFunction, globFiles, createComponentNameAnnotateHooks, replaceBooleanFlagsInCode, CodeInjection, } from '../core'; +import { getCodeInjectionPosition } from '../core/get-code-injection-position'; import type { ComponentAnnotationTransformMeta, ComponentAnnotationTransformResult, @@ -259,16 +259,16 @@ export function _rollupPluginInternal( } const ms = meta?.magicString || new MagicString(code, { filename: chunk.fileName }); - const match = code.match(COMMENT_USE_STRICT_REGEX)?.[0]; + const injectionPosition = getCodeInjectionPosition(code); + const codeToInject = injectionPosition === code.length ? `\n${injectCode.code()}` : `${injectCode.code()}\n`; - if (match) { - // Add injected code after any comments or "use strict" at the beginning of the bundle. - ms.appendLeft(match.length, injectCode.code()); + if (injectionPosition > 0) { + ms.appendLeft(injectionPosition, codeToInject); } else { // ms.replace() doesn't work when there is an empty string match (which happens if // there is neither, a comment, nor a "use strict" at the top of the chunk) so we // need this special case here. - ms.prepend(injectCode.code()); + ms.prepend(codeToInject); } // Rolldown can pass a native MagicString instance in meta.magicString diff --git a/packages/bundler-plugins/src/webpack/index.ts b/packages/bundler-plugins/src/webpack/index.ts index 634f2c1e958f..fa602f2af2ef 100644 --- a/packages/bundler-plugins/src/webpack/index.ts +++ b/packages/bundler-plugins/src/webpack/index.ts @@ -5,9 +5,20 @@ import { createRequire } from 'node:module'; // eslint-disable-next-line @typescript-eslint/no-explicit-any type PluginClass = new (options: any) => unknown; +type WebpackSource = { + source: () => string | Uint8Array; +}; + type WebpackModule = { - BannerPlugin?: PluginClass; DefinePlugin?: PluginClass; + Compilation?: { + PROCESS_ASSETS_STAGE_ADDITIONS: number; + }; + sources?: { + ReplaceSource: new (source: WebpackSource) => WebpackSource & { + insert: (position: number, value: string) => void; + }; + }; default?: WebpackModule; }; @@ -25,13 +36,15 @@ function loadWebpack(): WebpackModule { } const webpack = loadWebpack(); -const BannerPlugin = webpack.BannerPlugin ?? webpack.default?.BannerPlugin; const DefinePlugin = webpack.DefinePlugin ?? webpack.default?.DefinePlugin; +const Compilation = webpack.Compilation ?? webpack.default?.Compilation; +const sources = webpack.sources ?? webpack.default?.sources; // eslint-disable-next-line @typescript-eslint/no-explicit-any export const sentryWebpackPlugin: (options?: SentryWebpackPluginOptions) => any = sentryWebpackPluginFactory({ - BannerPlugin, DefinePlugin, + Compilation, + sources, }); export type { SentryWebpackPluginOptions }; diff --git a/packages/bundler-plugins/src/webpack/webpack4and5.ts b/packages/bundler-plugins/src/webpack/webpack4and5.ts index d58f37aefab8..fd2e3d7cf4e5 100644 --- a/packages/bundler-plugins/src/webpack/webpack4and5.ts +++ b/packages/bundler-plugins/src/webpack/webpack4and5.ts @@ -9,6 +9,7 @@ import { getDebugIdSnippet, createDebugIdUploadFunction, } from '../core/index'; +import { getCodeInjectionPosition } from '../core/get-code-injection-position'; import * as path from 'node:path'; import { fileURLToPath } from 'node:url'; import { createRequire } from 'node:module'; @@ -36,23 +37,17 @@ try { // since webpack 5.1 compiler contains webpack module so plugins always use correct webpack version // https://github.com/webpack/webpack/commit/65eca2e529ce1d79b79200d4bdb1ce1b81141459 -interface BannerPluginCallbackArg { - chunk?: { - hash?: string; - contentHash?: { - javascript?: string; - }; - }; -} - -type UnsafeBannerPlugin = { +type UnsafeDefinePlugin = { // eslint-disable-next-line @typescript-eslint/no-explicit-any new (options: any): unknown; }; -type UnsafeDefinePlugin = { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - new (options: any): unknown; +type WebpackCompilationApi = { + PROCESS_ASSETS_STAGE_ADDITIONS: number; +}; + +type WebpackSources = { + ReplaceSource: new (source: WebpackSource) => WebpackReplaceSource; }; type WebpackModule = { @@ -66,6 +61,11 @@ type WebpackLoaderContext = { }; type WebpackCompilationContext = { + chunks: Iterable<{ + files: Iterable; + hash?: string; + contentHash?: { javascript?: string }; + }>; compiler: { webpack?: { NormalModule?: { @@ -81,9 +81,26 @@ type WebpackCompilationContext = { normalModuleLoader?: { tap: (name: string, callback: (loaderContext: WebpackLoaderContext, module: WebpackModule) => void) => void; }; + processAssets: { + tap: ( + options: { name: string; stage: number }, + callback: (assets: Record) => void, + ) => void; + }; }; + updateAsset: (name: string, source: WebpackSource) => void; +}; + +type WebpackSource = { + source: () => string | Uint8Array; +}; + +type WebpackReplaceSource = WebpackSource & { + insert: (position: number, value: string) => void; }; +const WEBPACK_JAVASCRIPT_ASSET_REGEX = /\.(?:js|ts|jsx|tsx|mjs|cjs|mts|cts)(?:\?[^?]*)?(?:#[^#]*)?$/; + type WebpackCompiler = { options: { plugins?: unknown[]; @@ -104,8 +121,9 @@ type WebpackCompiler = { }; }; webpack?: { - BannerPlugin?: UnsafeBannerPlugin; DefinePlugin?: UnsafeDefinePlugin; + Compilation?: WebpackCompilationApi; + sources?: WebpackSources; }; }; @@ -137,19 +155,20 @@ function getWebpackMajorVersion(): string | undefined { } /** - * The factory function accepts BannerPlugin and DefinePlugin classes in - * order to avoid direct dependencies on webpack. + * The factory accepts Webpack APIs to avoid a direct dependency on Webpack. * - * This allow us to export version of the plugin for webpack 5.1+ and compatible environments. + * This allows us to export a version of the plugin for Webpack 5.1+ and compatible environments. * * Since webpack 5.1 compiler contains webpack module so plugins always use correct webpack version. */ export function sentryWebpackPluginFactory({ - BannerPlugin: UnsafeBannerPlugin, DefinePlugin: UnsafeDefinePlugin, + Compilation: UnsafeCompilation, + sources: unsafeSources, }: { - BannerPlugin?: UnsafeBannerPlugin; DefinePlugin?: UnsafeDefinePlugin; + Compilation?: WebpackCompilationApi; + sources?: WebpackSources; } = {}) { return function sentryWebpackPlugin(userOptions: SentryWebpackPluginOptions = {}) { const sentryBuildPluginManager = createSentryBuildPluginManager(userOptions, { @@ -216,32 +235,60 @@ export function sentryWebpackPluginFactory({ }); // Get the correct plugin classes (webpack 5.1+ vs older versions) - const BannerPlugin = compiler?.webpack?.BannerPlugin || UnsafeBannerPlugin; const DefinePlugin = compiler?.webpack?.DefinePlugin || UnsafeDefinePlugin; - // Add BannerPlugin for code injection (release, metadata, debug IDs) + // Injecting through BannerPlugin would place executable code before directive prologues. if (!staticInjectionCode.isEmpty() || sourcemapsEnabled) { - if (!BannerPlugin) { + const ReplaceSource = compiler.webpack?.sources?.ReplaceSource || unsafeSources?.ReplaceSource; + const processAssetsStage = + compiler.webpack?.Compilation?.PROCESS_ASSETS_STAGE_ADDITIONS ?? + UnsafeCompilation?.PROCESS_ASSETS_STAGE_ADDITIONS; + + if (!ReplaceSource || processAssetsStage === undefined) { logger.warn( - 'BannerPlugin is not available. Skipping code injection. This usually means webpack is not properly configured.', + 'Webpack sources are not available. Skipping code injection. This usually means webpack is not properly configured.', ); } else { - compiler.options.plugins = compiler.options.plugins || []; - compiler.options.plugins.push( - new BannerPlugin({ - raw: true, - include: /\.(js|ts|jsx|tsx|mjs|cjs)(\?[^?]*)?(#[^#]*)?$/, - banner: (arg?: BannerPluginCallbackArg) => { - const codeToInject = staticInjectionCode.clone(); - if (sourcemapsEnabled) { - const hash = arg?.chunk?.contentHash?.javascript ?? arg?.chunk?.hash; - const debugId = hash ? stringToUUID(hash) : randomUUID(); - codeToInject.append(getDebugIdSnippet(debugId)); + compiler.hooks.thisCompilation.tap('sentry-webpack-plugin-injection', compilation => { + compilation.hooks.processAssets.tap( + { + name: 'sentry-webpack-plugin-injection', + stage: processAssetsStage, + }, + assets => { + for (const chunk of compilation.chunks) { + for (const assetName of chunk.files) { + if (!WEBPACK_JAVASCRIPT_ASSET_REGEX.test(assetName)) { + continue; + } + + const source = assets[assetName]; + if (!source) { + continue; + } + + const sourceContents = source.source(); + const codeString = + typeof sourceContents === 'string' ? sourceContents : Buffer.from(sourceContents).toString(); + const codeToInject = staticInjectionCode.clone(); + if (sourcemapsEnabled) { + const hash = chunk.contentHash?.javascript ?? chunk.hash; + codeToInject.append(getDebugIdSnippet(hash ? stringToUUID(hash) : randomUUID())); + } + + const injectionPosition = getCodeInjectionPosition(codeString); + const injection = + injectionPosition === codeString.length + ? `\n${codeToInject.code()}` + : `${codeToInject.code()}\n`; + const updatedSource = new ReplaceSource(source); + updatedSource.insert(injectionPosition, injection); + compilation.updateAsset(assetName, updatedSource); + } } - return codeToInject.code(); }, - }), - ); + ); + }); } } diff --git a/packages/bundler-plugins/test/core/get-code-injection-position.test.ts b/packages/bundler-plugins/test/core/get-code-injection-position.test.ts new file mode 100644 index 000000000000..91ea92211d93 --- /dev/null +++ b/packages/bundler-plugins/test/core/get-code-injection-position.test.ts @@ -0,0 +1,36 @@ +import { getCodeInjectionPosition } from '../../src/core/get-code-injection-position'; +import { describe, expect, it } from 'vitest'; + +describe('getCodeInjectionPosition', () => { + it.each([ + [ + 'multiple directives and a block comment', + `/* license */\n"use client";\n'use strict'\nglobalThis.appStarted = true;`, + `/* license */\n"use client";\n'use strict'\n`, + ], + ['a semicolonless directive before a unary IIFE', '"use strict"\n!function () {}();', '"use strict"\n'], + ['a CRLF line comment', '// license\r\n"use strict";\r\nstartApp();', '// license\r\n"use strict";\r\n'], + ['a CR-only line comment', '// license\r"use strict"\rstartApp();', '// license\r"use strict"\r'], + ['a Unicode line separator', '"use strict"\u2028startApp();', '"use strict"\u2028'], + ['a Unicode paragraph separator', '"use strict"\u2029startApp();', '"use strict"\u2029'], + ['a hashbang', '#!/usr/bin/env node\n"use strict";\nstartApp();', '#!/usr/bin/env node\n"use strict";\n'], + ['an escaped string directive', '"use\\x20strict";\nstartApp();', '"use\\x20strict";\n'], + [ + 'an escaped CRLF in a directive string', + '"not strict\\\r\n";\n"use strict";\nstartApp();', + '"not strict\\\r\n";\n"use strict";\n', + ], + ['an unterminated string', '"use strict', ''], + ['an unterminated block comment', '/* license', '/* license'], + ['leading trivia without directives', '/* license */\nstartApp();', '/* license */\n'], + ['a prefix increment statement', '"use strict"\n++value;', '"use strict"\n'], + ['a prefix decrement statement', '"use strict"\n--value;', '"use strict"\n'], + ['an inequality continuation', '"not a directive"\n!= expectedValue;', ''], + ['an addition continuation', '"not a directive"\n+ otherValue;', ''], + ['an identifier prefixed with in', '"use strict"\nin$foo: ;', '"use strict"\n'], + ['a Unicode identifier prefixed with instanceof', '"use strict"\ninstanceofπ: ;', '"use strict"\n'], + ['an escaped identifier prefixed with in', '"use strict"\nin\\u0066oo: ;', '"use strict"\n'], + ])('returns the injection position for %s', (_description, code, expectedPrefix) => { + expect(code.slice(0, getCodeInjectionPosition(code))).toBe(expectedPrefix); + }); +}); diff --git a/packages/bundler-plugins/test/rollup/__snapshots__/public-api.test.ts.snap b/packages/bundler-plugins/test/rollup/__snapshots__/public-api.test.ts.snap index cd0ad570649f..efd140af38e6 100644 --- a/packages/bundler-plugins/test/rollup/__snapshots__/public-api.test.ts.snap +++ b/packages/bundler-plugins/test/rollup/__snapshots__/public-api.test.ts.snap @@ -1,11 +1,26 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`Hooks > renderChunk > should process file 'bundle.cjs' 1`] = `"!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="b80112c0-6818-486d-96f0-185c023439b4",e._sentryDebugIdIdentifier="sentry-dbid-b80112c0-6818-486d-96f0-185c023439b4");}catch(e){}}();console.log("test");"`; +exports[`Hooks > renderChunk > should process file 'bundle.cjs' 1`] = ` +"!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="b80112c0-6818-486d-96f0-185c023439b4",e._sentryDebugIdIdentifier="sentry-dbid-b80112c0-6818-486d-96f0-185c023439b4");}catch(e){}}(); +console.log("test");" +`; -exports[`Hooks > renderChunk > should process file 'bundle.js#hash' 1`] = `"!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="b80112c0-6818-486d-96f0-185c023439b4",e._sentryDebugIdIdentifier="sentry-dbid-b80112c0-6818-486d-96f0-185c023439b4");}catch(e){}}();console.log("test");"`; +exports[`Hooks > renderChunk > should process file 'bundle.js#hash' 1`] = ` +"!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="b80112c0-6818-486d-96f0-185c023439b4",e._sentryDebugIdIdentifier="sentry-dbid-b80112c0-6818-486d-96f0-185c023439b4");}catch(e){}}(); +console.log("test");" +`; -exports[`Hooks > renderChunk > should process file 'bundle.js' 1`] = `"!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="b80112c0-6818-486d-96f0-185c023439b4",e._sentryDebugIdIdentifier="sentry-dbid-b80112c0-6818-486d-96f0-185c023439b4");}catch(e){}}();console.log("test");"`; +exports[`Hooks > renderChunk > should process file 'bundle.js' 1`] = ` +"!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="b80112c0-6818-486d-96f0-185c023439b4",e._sentryDebugIdIdentifier="sentry-dbid-b80112c0-6818-486d-96f0-185c023439b4");}catch(e){}}(); +console.log("test");" +`; -exports[`Hooks > renderChunk > should process file 'bundle.js?foo=bar' 1`] = `"!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="b80112c0-6818-486d-96f0-185c023439b4",e._sentryDebugIdIdentifier="sentry-dbid-b80112c0-6818-486d-96f0-185c023439b4");}catch(e){}}();console.log("test");"`; +exports[`Hooks > renderChunk > should process file 'bundle.js?foo=bar' 1`] = ` +"!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="b80112c0-6818-486d-96f0-185c023439b4",e._sentryDebugIdIdentifier="sentry-dbid-b80112c0-6818-486d-96f0-185c023439b4");}catch(e){}}(); +console.log("test");" +`; -exports[`Hooks > renderChunk > should process file 'bundle.mjs' 1`] = `"!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="b80112c0-6818-486d-96f0-185c023439b4",e._sentryDebugIdIdentifier="sentry-dbid-b80112c0-6818-486d-96f0-185c023439b4");}catch(e){}}();console.log("test");"`; +exports[`Hooks > renderChunk > should process file 'bundle.mjs' 1`] = ` +"!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="b80112c0-6818-486d-96f0-185c023439b4",e._sentryDebugIdIdentifier="sentry-dbid-b80112c0-6818-486d-96f0-185c023439b4");}catch(e){}}(); +console.log("test");" +`; diff --git a/packages/bundler-plugins/test/rollup/public-api.test.ts b/packages/bundler-plugins/test/rollup/public-api.test.ts index b54077fce2bc..296d4416f399 100644 --- a/packages/bundler-plugins/test/rollup/public-api.test.ts +++ b/packages/bundler-plugins/test/rollup/public-api.test.ts @@ -1,6 +1,7 @@ import { _rollupPluginInternal, sentryRollupPlugin } from '../../src/rollup'; import { createComponentNameAnnotateHooks } from '../../src/core'; import type { Plugin, SourceMap } from 'rollup'; +import { runInNewContext } from 'node:vm'; import { describe, it, expect, test, beforeEach, vi } from 'vitest'; const { babelCoreImportMock, transformAsyncMock, viteAnnotationModuleImportMock, viteAnnotationTransformMock } = @@ -137,9 +138,10 @@ describe('Hooks', () => { const result = renderChunk(code, { fileName: 'bundle.js' }); expect(result).not.toBeNull(); - expect(result?.code).toMatchInlineSnapshot( - `"!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="d4309f93-5358-4ae1-bcf0-3813aa590eb5",e._sentryDebugIdIdentifier="sentry-dbid-d4309f93-5358-4ae1-bcf0-3813aa590eb5");}catch(e){}}();console.log("Hello world");"`, - ); + expect(result?.code).toMatchInlineSnapshot(` + "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="d4309f93-5358-4ae1-bcf0-3813aa590eb5",e._sentryDebugIdIdentifier="sentry-dbid-d4309f93-5358-4ae1-bcf0-3813aa590eb5");}catch(e){}}(); + console.log("Hello world");" + `); }); it("should inject debug ID after 'use strict'", () => { @@ -148,11 +150,62 @@ describe('Hooks', () => { expect(result).not.toBeNull(); expect(result?.code).toMatchInlineSnapshot(` - ""use strict";!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="79a86c07-8ecc-4367-82b0-88cf822f2d41",e._sentryDebugIdIdentifier="sentry-dbid-79a86c07-8ecc-4367-82b0-88cf822f2d41");}catch(e){}}(); + ""use strict"; + !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="79a86c07-8ecc-4367-82b0-88cf822f2d41",e._sentryDebugIdIdentifier="sentry-dbid-79a86c07-8ecc-4367-82b0-88cf822f2d41");}catch(e){}}(); console.log("Hello world");" `); }); + it('preserves source mappings when injecting after a directive prologue', () => { + const code = '"use strict";\nglobalThis.applicationStarted = true;'; + const result = renderChunk(code, { fileName: 'bundle.js' }); + + expect(result).not.toBeNull(); + expect(JSON.parse(result?.map.toString() ?? '')).toEqual({ + version: 3, + file: 'bundle.js', + sources: ['bundle.js'], + names: [], + mappings: 'AAAA,CAAC,GAAG,CAAC,MAAM,CAAC;;AACZ,UAAU,CAAC,kBAAkB,CAAC,CAAC,CAAC,IAAI', + }); + }); + + it.each([ + ['when the directive has no semicolon', '"use strict"\n'], + ['when another directive precedes it', '"use client";\n"use strict";\n'], + ['after an escaped CRLF in an earlier directive', '"not strict\\\r\n";\n"use strict";\n'], + ['before an identifier prefixed with an operator keyword', '"use strict"\nin$foo: ;\n'], + ])('preserves strict mode %s', (_description, codePrefix) => { + const code = `${codePrefix}globalThis.strictModePreserved = (function () { return this; })() === undefined;`; + const result = renderChunk(code, { fileName: 'bundle.js' }); + const context: { strictModePreserved?: boolean; _sentryDebugIds?: Record } = {}; + + expect(result).not.toBeNull(); + runInNewContext(result?.code ?? '', context); + + expect(context.strictModePreserved).toBe(true); + expect(Object.keys(context._sentryDebugIds ?? {})).toHaveLength(1); + }); + + it.each([ + ['a semicolonless directive', '"use strict"'], + ['trailing whitespace', '"use strict" '], + ['a trailing block comment', '"use strict"/* trailing */'], + ['a trailing line comment', '"use strict" // trailing'], + ])('preserves a directive at EOF with %s', (_description, code) => { + const result = renderChunk(code, { fileName: 'bundle.js' }); + const context: { strictModePreserved?: boolean; _sentryDebugIds?: Record } = {}; + + expect(result).not.toBeNull(); + runInNewContext( + `${result?.code ?? ''}\nglobalThis.strictModePreserved = (function () { return this; })() === undefined;`, + context, + ); + + expect(context.strictModePreserved).toBe(true); + expect(Object.keys(context._sentryDebugIds ?? {})).toHaveLength(1); + }); + it.each([['bundle.js'], ['bundle.mjs'], ['bundle.cjs'], ['bundle.js?foo=bar'], ['bundle.js#hash']])( "should process file '%s'", fileName => { @@ -235,9 +288,10 @@ export * from './moduleC.js';`, facadeModuleId: '/path/to/index.html', }); expect(result).not.toBeNull(); - expect(result?.code).toMatchInlineSnapshot( - `"!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="c4c89e04-3658-4874-b25b-07e638185091",e._sentryDebugIdIdentifier="sentry-dbid-c4c89e04-3658-4874-b25b-07e638185091");}catch(e){}}();function main() { console.log("hello"); }"`, - ); + expect(result?.code).toMatchInlineSnapshot(` + "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="c4c89e04-3658-4874-b25b-07e638185091",e._sentryDebugIdIdentifier="sentry-dbid-c4c89e04-3658-4874-b25b-07e638185091");}catch(e){}}(); + function main() { console.log("hello"); }" + `); }); it('should inject into HTML facade with variable declarations', () => { @@ -246,9 +300,10 @@ export * from './moduleC.js';`, facadeModuleId: '/path/to/index.html', }); expect(result).not.toBeNull(); - expect(result?.code).toMatchInlineSnapshot( - `"!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="43e69766-1963-49f2-a291-ff8de60cc652",e._sentryDebugIdIdentifier="sentry-dbid-43e69766-1963-49f2-a291-ff8de60cc652");}catch(e){}}();const x = 42;"`, - ); + expect(result?.code).toMatchInlineSnapshot(` + "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="43e69766-1963-49f2-a291-ff8de60cc652",e._sentryDebugIdIdentifier="sentry-dbid-43e69766-1963-49f2-a291-ff8de60cc652");}catch(e){}}(); + const x = 42;" + `); }); it('should inject into HTML facade with substantial code (SPA main bundle)', () => { @@ -267,7 +322,8 @@ bootstrap();`; }); expect(result).not.toBeNull(); expect(result?.code).toMatchInlineSnapshot(` - "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="d0c4524b-496e-45a4-9852-7558d043ba3c",e._sentryDebugIdIdentifier="sentry-dbid-d0c4524b-496e-45a4-9852-7558d043ba3c");}catch(e){}}();import { initApp } from './app.js'; + "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="d0c4524b-496e-45a4-9852-7558d043ba3c",e._sentryDebugIdIdentifier="sentry-dbid-d0c4524b-496e-45a4-9852-7558d043ba3c");}catch(e){}}(); + import { initApp } from './app.js'; const config = { debug: true }; @@ -286,7 +342,8 @@ bootstrap();`; }); expect(result).not.toBeNull(); expect(result?.code).toMatchInlineSnapshot(` - "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="28f0bbaa-9aeb-40c4-98c9-4e44f1d4e175",e._sentryDebugIdIdentifier="sentry-dbid-28f0bbaa-9aeb-40c4-98c9-4e44f1d4e175");}catch(e){}}();import './polyfills.js'; + "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="28f0bbaa-9aeb-40c4-98c9-4e44f1d4e175",e._sentryDebugIdIdentifier="sentry-dbid-28f0bbaa-9aeb-40c4-98c9-4e44f1d4e175");}catch(e){}}(); + import './polyfills.js'; import { init } from './app.js'; init();" @@ -296,9 +353,10 @@ bootstrap();`; it('should inject into regular JS chunks (no HTML facade)', () => { const result = renderChunk(`console.log("Hello");`, { fileName: 'bundle.js' }); expect(result).not.toBeNull(); - expect(result?.code).toMatchInlineSnapshot( - `"!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="79f18a7f-ca16-4168-9797-906c82058367",e._sentryDebugIdIdentifier="sentry-dbid-79f18a7f-ca16-4168-9797-906c82058367");}catch(e){}}();console.log("Hello");"`, - ); + expect(result?.code).toMatchInlineSnapshot(` + "!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="79f18a7f-ca16-4168-9797-906c82058367",e._sentryDebugIdIdentifier="sentry-dbid-79f18a7f-ca16-4168-9797-906c82058367");}catch(e){}}(); + console.log("Hello");" + `); }); }); }); diff --git a/packages/bundler-plugins/test/vite/public-api.test.ts b/packages/bundler-plugins/test/vite/public-api.test.ts index 6f8dd9f84260..cade4da1c67a 100644 --- a/packages/bundler-plugins/test/vite/public-api.test.ts +++ b/packages/bundler-plugins/test/vite/public-api.test.ts @@ -1,4 +1,6 @@ import { sentryVitePlugin } from '../../src/vite'; +import type { Plugin, SourceMap } from 'rollup'; +import { runInNewContext } from 'node:vm'; import { describe, it, expect, test, beforeEach, vi } from 'vitest'; test('Vite plugin should exist', () => { @@ -37,4 +39,27 @@ describe('sentryVitePlugin', () => { expect(plugins.length).toBeGreaterThanOrEqual(1); expect(plugins[0]).toHaveProperty('name'); }); + + it.each([ + ['when the directive has no semicolon', '"use strict"\n'], + ['when another directive precedes it', '"use client";\n"use strict";\n'], + ['after an escaped CRLF in an earlier directive', '"not strict\\\r\n";\n"use strict";\n'], + ['before an identifier prefixed with an operator keyword', '"use strict"\nin$foo: ;\n'], + ])('preserves strict mode %s', (_description, codePrefix) => { + const [plugin] = sentryVitePlugin({ release: { inject: false }, telemetry: false }) as Array; + const renderChunk = plugin?.renderChunk as ( + code: string, + chunkInfo: { fileName: string }, + ) => { code: string; map: SourceMap } | null; + const code = `${codePrefix}globalThis.strictModePreserved = (function () { return this; })() === undefined;`; + + const result = renderChunk(code, { fileName: 'bundle.js' }); + const context: { strictModePreserved?: boolean; _sentryDebugIds?: Record } = {}; + + expect(result).not.toBeNull(); + runInNewContext(result?.code ?? '', context); + + expect(context.strictModePreserved).toBe(true); + expect(Object.keys(context._sentryDebugIds ?? {})).toHaveLength(1); + }); }); diff --git a/packages/bundler-plugins/test/webpack/webpack4and5.test.ts b/packages/bundler-plugins/test/webpack/webpack4and5.test.ts new file mode 100644 index 000000000000..55ed36202f13 --- /dev/null +++ b/packages/bundler-plugins/test/webpack/webpack4and5.test.ts @@ -0,0 +1,137 @@ +import webpack from 'webpack'; +import MagicString from 'magic-string'; +import { runInNewContext } from 'node:vm'; +import { describe, expect, it } from 'vitest'; +import { sentryWebpackPluginFactory } from '../../src/webpack/webpack4and5'; + +function runWebpackSourceInjection( + assetName: string, + source: webpack.sources.Source, + chunkFiles: string[] = [assetName], + chunkHash?: string, +): webpack.sources.Source { + const webpackPlugin = sentryWebpackPluginFactory()({ + release: { inject: false }, + telemetry: false, + }); + let compilationCallback!: (compilation: unknown) => void; + let processAssets!: (assets: Record) => void; + let output = source; + const compiler = { + options: { plugins: [] as unknown[] }, + webpack: { + Compilation: { PROCESS_ASSETS_STAGE_ADDITIONS: -100 }, + sources: { ReplaceSource: webpack.sources.ReplaceSource }, + }, + hooks: { + thisCompilation: { + tap: (_name: string, callback: (compilation: unknown) => void) => { + compilationCallback = callback; + }, + }, + afterEmit: { tapAsync: () => undefined }, + done: { tap: () => undefined }, + }, + }; + const compilation = { + chunks: [{ files: chunkFiles, hash: chunkHash }], + compiler: {}, + hooks: { + processAssets: { + tap: (_options: unknown, callback: (assets: Record) => void) => { + processAssets = callback; + }, + }, + }, + updateAsset: (_name: string, source: webpack.sources.Source) => { + output = source; + }, + }; + + webpackPlugin.apply(compiler as never); + compilationCallback(compilation); + processAssets({ [assetName]: source }); + + return output; +} + +function runWebpackInjection(assetName: string, code: string, chunkFiles: string[] = [assetName]): string { + return runWebpackSourceInjection(assetName, new webpack.sources.RawSource(code), chunkFiles).source().toString(); +} + +describe('sentryWebpackPluginFactory', () => { + it('preserves a top-level strict mode directive', () => { + const code = '"use strict";\nglobalThis.strictModePreserved = (function () { return this; })() === undefined;'; + const output = runWebpackInjection('120.js', code); + const context: { strictModePreserved?: boolean; _sentryDebugIds?: Record } = {}; + + runInNewContext(output, context); + + expect(context.strictModePreserved).toBe(true); + expect(Object.keys(context._sentryDebugIds ?? {})).toHaveLength(1); + }); + + it('preserves source mappings when injecting after a directive prologue', () => { + const code = '"use strict";\nglobalThis.applicationStarted = true;'; + const inputMap = new MagicString(code).generateMap({ + source: 'application.js', + hires: 'boundary' as unknown as undefined, + includeContent: true, + }); + const source = new webpack.sources.SourceMapSource(code, 'bundle.js', inputMap.toString()); + + const output = runWebpackSourceInjection('bundle.js', source); + const outputMap = output.map(); + + expect(outputMap?.sources).toEqual(['application.js']); + expect(outputMap?.sourcesContent).toEqual([code]); + expect(outputMap?.mappings).toBe('AAAA,CAAC,GAAG,CAAC,MAAM,CAAC;AACZ;AAAA,UAAU,CAAC,kBAAkB,CAAC,CAAC,CAAC,IAAI'); + }); + + it('derives the debug ID from the Webpack chunk hash', () => { + const output = runWebpackSourceInjection( + 'bundle.js', + new webpack.sources.RawSource('globalThis.bundleLoaded = true;'), + ['bundle.js'], + 'stable-webpack-chunk-hash', + ) + .source() + .toString(); + + expect(output).toContain('sentry-dbid-1924c426-ebb3-47c2-8293-ea326e499bcc'); + }); + + it.each([ + ['a semicolonless directive', '"use strict"'], + ['trailing whitespace', '"use strict" '], + ['a trailing block comment', '"use strict"/* trailing */'], + ['a trailing line comment', '"use strict" // trailing'], + ])('preserves a directive at EOF with %s', (_description, code) => { + const output = runWebpackInjection('120.js', code); + const context: { strictModePreserved?: boolean; _sentryDebugIds?: Record } = {}; + + runInNewContext( + `${output}\nglobalThis.strictModePreserved = (function () { return this; })() === undefined;`, + context, + ); + + expect(context.strictModePreserved).toBe(true); + expect(Object.keys(context._sentryDebugIds ?? {})).toHaveLength(1); + }); + + it.each(['.ts', '.tsx', '.jsx', '.mts', '.cts'])('injects into a %s asset', extension => { + const output = runWebpackInjection(`bundle${extension}`, 'globalThis.bundleLoaded = true;'); + const context: { _sentryDebugIds?: Record } = {}; + + runInNewContext(output, context); + + expect(Object.keys(context._sentryDebugIds ?? {})).toHaveLength(1); + }); + + it('does not inject into JavaScript assets outside chunks', () => { + const code = 'globalThis.bundleLoaded = true;'; + const output = runWebpackInjection('copied.js', code, []); + + expect(output).toBe(code); + }); +});