From df26a121dd0d5a6a19bbb083e9ab878b5a7890c7 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Fri, 9 Jun 2023 20:54:36 +0200 Subject: [PATCH 1/4] fix(esbuild): Don't use namespace for esbuild proxy resolving Potentially fixes https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/310 --- packages/esbuild-plugin/src/index.ts | 18 +++++++++++++----- packages/playground/build-esbuild.js | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/esbuild-plugin/src/index.ts b/packages/esbuild-plugin/src/index.ts index da7dd4da..a160e1ac 100644 --- a/packages/esbuild-plugin/src/index.ts +++ b/packages/esbuild-plugin/src/index.ts @@ -38,7 +38,6 @@ function esbuildReleaseInjectionPlugin(injectionCode: string): UnpluginOptions { function esbuildDebugIdInjectionPlugin(): UnpluginOptions { const pluginName = "sentry-esbuild-debug-id-injection-plugin"; - const proxyNamespace = "sentry-debug-id-proxy"; const stubNamespace = "sentry-debug-id-stub"; return { @@ -46,26 +45,35 @@ function esbuildDebugIdInjectionPlugin(): UnpluginOptions { esbuild: { setup({ onLoad, onResolve }) { - onResolve({ filter: /.*/ }, (args) => { + onResolve({ filter: /.*/, namespace: "file" }, (args) => { if (args.kind !== "entry-point") { return; } + return { pluginName, - path: args.path, - namespace: proxyNamespace, + // needs to be an abs path, otherwise esbuild will complain + path: path.isAbsolute(args.path) ? args.path : path.join(args.resolveDir, args.path), + namespace: "file", // passthrough pluginData: { + isProxyResolver: true, originalPath: args.path, originalResolveDir: args.resolveDir, }, }; }); - onLoad({ filter: /.*/, namespace: proxyNamespace }, (args) => { + onLoad({ filter: /.*/, namespace: "file" }, (args) => { + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + if (!(args.pluginData.isProxyResolver as undefined | boolean)) { + return null; + } + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access const originalPath = args.pluginData.originalPath as string; // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access const originalResolveDir = args.pluginData.originalResolveDir as string; + return { loader: "js", pluginName, diff --git a/packages/playground/build-esbuild.js b/packages/playground/build-esbuild.js index dabb9fea..447c11bf 100644 --- a/packages/playground/build-esbuild.js +++ b/packages/playground/build-esbuild.js @@ -2,7 +2,7 @@ const { sentryEsbuildPlugin } = require("@sentry/esbuild-plugin"); const { build } = require("esbuild"); build({ - entryPoints: ["./src/entrypoint1.js"], + entryPoints: ["./src/get-global.js", "./src/hello-world.js"], outdir: "./out/esbuild", plugins: [ sentryEsbuildPlugin({ From 507cc75450dac632e2755593f32a65cc6ef9bab3 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Sat, 10 Jun 2023 10:37:27 +0200 Subject: [PATCH 2/4] Discard changes to packages/playground/build-esbuild.js --- packages/playground/build-esbuild.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/playground/build-esbuild.js b/packages/playground/build-esbuild.js index 447c11bf..dabb9fea 100644 --- a/packages/playground/build-esbuild.js +++ b/packages/playground/build-esbuild.js @@ -2,7 +2,7 @@ const { sentryEsbuildPlugin } = require("@sentry/esbuild-plugin"); const { build } = require("esbuild"); build({ - entryPoints: ["./src/get-global.js", "./src/hello-world.js"], + entryPoints: ["./src/entrypoint1.js"], outdir: "./out/esbuild", plugins: [ sentryEsbuildPlugin({ From 5c24b303061dcfb5ab5e73db1eba518b81f948fd Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Mon, 12 Jun 2023 10:23:14 +0200 Subject: [PATCH 3/4] Remove unnecessary namespace filter and definition --- packages/esbuild-plugin/src/index.ts | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/packages/esbuild-plugin/src/index.ts b/packages/esbuild-plugin/src/index.ts index a160e1ac..11fbcda8 100644 --- a/packages/esbuild-plugin/src/index.ts +++ b/packages/esbuild-plugin/src/index.ts @@ -45,22 +45,21 @@ function esbuildDebugIdInjectionPlugin(): UnpluginOptions { esbuild: { setup({ onLoad, onResolve }) { - onResolve({ filter: /.*/, namespace: "file" }, (args) => { + onResolve({ filter: /.*/ }, (args) => { if (args.kind !== "entry-point") { return; + } else { + return { + pluginName, + // needs to be an abs path, otherwise esbuild will complain + path: path.isAbsolute(args.path) ? args.path : path.join(args.resolveDir, args.path), + pluginData: { + isProxyResolver: true, + originalPath: args.path, + originalResolveDir: args.resolveDir, + }, + }; } - - return { - pluginName, - // needs to be an abs path, otherwise esbuild will complain - path: path.isAbsolute(args.path) ? args.path : path.join(args.resolveDir, args.path), - namespace: "file", // passthrough - pluginData: { - isProxyResolver: true, - originalPath: args.path, - originalResolveDir: args.resolveDir, - }, - }; }); onLoad({ filter: /.*/, namespace: "file" }, (args) => { From 29f39f630cdb3de6865a6c627a1ec629e2b53b5f Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Mon, 12 Jun 2023 10:30:27 +0200 Subject: [PATCH 4/4] Remove unnecessary namespace filter --- packages/esbuild-plugin/src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/esbuild-plugin/src/index.ts b/packages/esbuild-plugin/src/index.ts index 11fbcda8..3f401936 100644 --- a/packages/esbuild-plugin/src/index.ts +++ b/packages/esbuild-plugin/src/index.ts @@ -62,9 +62,9 @@ function esbuildDebugIdInjectionPlugin(): UnpluginOptions { } }); - onLoad({ filter: /.*/, namespace: "file" }, (args) => { + onLoad({ filter: /.*/ }, (args) => { // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - if (!(args.pluginData.isProxyResolver as undefined | boolean)) { + if (!(args.pluginData?.isProxyResolver as undefined | boolean)) { return null; }