Skip to content

Commit 743bb1b

Browse files
author
Luca Forstner
authored
fix(esbuild): Don't override user code with proxy module (#322)
1 parent d5dc441 commit 743bb1b

File tree

9 files changed

+72
-1
lines changed

9 files changed

+72
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ export function sentryUnpluginFactory({
203203
);
204204
}
205205

206+
plugins.push(debugIdInjectionPlugin());
207+
206208
if (!options.authToken) {
207209
logger.warn(
208210
"No auth token provided. Will not upload source maps. Please set the `authToken` option. You can find information on how to generate a Sentry auth token here: https://docs.sentry.io/api/auth/"
@@ -216,7 +218,6 @@ export function sentryUnpluginFactory({
216218
"No project provided. Will not upload source maps. Please set the `project` option to your Sentry project slug."
217219
);
218220
} else {
219-
plugins.push(debugIdInjectionPlugin());
220221
plugins.push(
221222
debugIdUploadPlugin(
222223
createDebugIdUploadFunction({

packages/esbuild-plugin/src/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ function esbuildDebugIdInjectionPlugin(): UnpluginOptions {
5858
originalPath: args.path,
5959
originalResolveDir: args.resolveDir,
6060
},
61+
// We need to add a suffix here, otherwise esbuild will mark the entrypoint as resolved and won't traverse
62+
// the module tree any further down past the proxy module because we're essentially creating a dependency
63+
// loop back to the proxy module.
64+
// By setting a suffix we're telling esbuild that the entrypoint and proxy module are two different things,
65+
// making it re-resolve the entrypoint when it is imported from the proxy module.
66+
// Super confusing? Yes. Works? Apparently... Let's see.
67+
suffix: "?sentryProxyModule=true",
6168
};
6269
}
6370
});

packages/integration-tests/fixtures/basic-release-injection/setup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ const entryPointPath = path.resolve(__dirname, "input", "entrypoint.js");
55
const outputDir = path.resolve(__dirname, "out");
66

77
createCjsBundles({ index: entryPointPath }, outputDir, {
8+
telemetry: false,
89
release: { name: "I AM A RELEASE!", create: false },
910
});

packages/integration-tests/fixtures/build-information-injection/setup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ createCjsBundles({ index: entryPointPath }, outputDir, {
88
release: {
99
name: "build-information-injection-test",
1010
},
11+
telemetry: false,
1112
_experiments: { injectBuildInformation: true },
1213
});

packages/integration-tests/fixtures/disabled-release-injection/setup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const entryPointPath = path.resolve(__dirname, "input", "entrypoint.js");
55
const outputDir = path.resolve(__dirname, "out");
66

77
createCjsBundles({ index: entryPointPath }, outputDir, {
8+
telemetry: false,
89
release: { name: "I AM A RELEASE!", inject: false, create: false },
910
project: "releasesProject",
1011
org: "releasesOrg",
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import childProcess from "child_process";
2+
import path from "path";
3+
import { testIfNodeMajorVersionIsLessThan18 } from "../../utils/testIf";
4+
5+
/**
6+
* Runs a node file in a seprate process.
7+
*
8+
* @param bundlePath Path of node file to run
9+
* @returns Stdout of the process
10+
*/
11+
function checkBundle(bundlePath: string): void {
12+
const processOutput = childProcess.execSync(`node ${bundlePath}`, { encoding: "utf-8" });
13+
expect(processOutput).toMatch("I am import!");
14+
expect(processOutput).toMatch("I am index!");
15+
}
16+
17+
test("esbuild bundle", () => {
18+
expect.assertions(2);
19+
checkBundle(path.join(__dirname, "out", "esbuild", "index.js"));
20+
});
21+
22+
test("rollup bundle", () => {
23+
expect.assertions(2);
24+
checkBundle(path.join(__dirname, "out", "rollup", "index.js"));
25+
});
26+
27+
test("vite bundle", () => {
28+
expect.assertions(2);
29+
checkBundle(path.join(__dirname, "out", "vite", "index.js"));
30+
});
31+
32+
testIfNodeMajorVersionIsLessThan18("webpack 4 bundle", () => {
33+
expect.assertions(2);
34+
checkBundle(path.join(__dirname, "out", "webpack4", "index.js"));
35+
});
36+
37+
test("webpack 5 bundle", () => {
38+
expect.assertions(2);
39+
checkBundle(path.join(__dirname, "out", "webpack5", "index.js"));
40+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// eslint-disable-next-line no-console
2+
console.log("I am import!");
3+
4+
export {};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import "./import";
2+
3+
// eslint-disable-next-line no-console
4+
console.log("I am index!");
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import * as path from "path";
2+
import { createCjsBundles } from "../../utils/create-cjs-bundles";
3+
4+
const entryPointPath = path.resolve(__dirname, "input", "index.js");
5+
const outputDir = path.resolve(__dirname, "out");
6+
7+
createCjsBundles({ index: entryPointPath }, outputDir, {
8+
telemetry: false,
9+
release: { name: "I am release!", create: false },
10+
project: "releasesProject",
11+
org: "releasesOrg",
12+
});

0 commit comments

Comments
 (0)