Skip to content

Commit

Permalink
fix(esbuild): Don't inject debug IDs into injected modules
Browse files Browse the repository at this point in the history
  • Loading branch information
lforst committed Oct 5, 2023
1 parent 8a74c87 commit 864dfea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/esbuild-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,17 @@ function esbuildDebugIdInjectionPlugin(): UnpluginOptions {
name: pluginName,

esbuild: {
setup({ onLoad, onResolve }) {
setup({ initialOptions, onLoad, onResolve }) {
onResolve({ filter: /.*/ }, (args) => {
if (args.kind !== "entry-point") {
return;
} else {
// Injected modules via the esbuild `inject` option do also have `kind == "entry-point"`.
// We do not want to inject debug IDs into those files because they are already bundled into the entrypoints
if (initialOptions.inject?.includes(args.path)) {
return;
}

return {
pluginName,
// needs to be an abs path, otherwise esbuild will complain
Expand Down Expand Up @@ -123,11 +129,17 @@ function esbuildModuleMetadataInjectionPlugin(injectionCode: string): UnpluginOp
name: pluginName,

esbuild: {
setup({ onLoad, onResolve }) {
setup({ initialOptions, onLoad, onResolve }) {
onResolve({ filter: /.*/ }, (args) => {
if (args.kind !== "entry-point") {
return;
} else {
// Injected modules via the esbuild `inject` option do also have `kind == "entry-point"`.
// We do not want to inject debug IDs into those files because they are already bundled into the entrypoints
if (initialOptions.inject?.includes(args.path)) {
return;
}

return {
pluginName,
// needs to be an abs path, otherwise esbuild will complain
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import childProcess from "child_process";
import path from "path";
import fs from "fs";

const outputBundlePath = path.join(__dirname, "out", "index.js");

test("check functionality", () => {
const processOutput = childProcess.execSync(`node ${outputBundlePath}`, { encoding: "utf-8" });
expect(processOutput).toMatch(/injected fallback/);
});

test("check that output only contains one debug ID reference", async () => {
const bundleContent = await fs.promises.readFile(outputBundlePath, "utf-8");
const debugIdReferences = bundleContent.match(/sentry-dbid-/g) ?? [];
expect(debugIdReferences).toHaveLength(1);
});

0 comments on commit 864dfea

Please sign in to comment.