sentry-cli
sentry-cli copied to clipboard
Improve logic that detects whether sourcemaps are already injected
If sentry-cli sourcemaps inject detects an existing // debugId=... comment, it skips injecting a Debug ID into that file. The underlying assumption is that if there is a // debugId=... comment, then Sentry CLI has already injected this file, and importantly, has stored the Debug ID in a global variable that the SDK can access. However, other tools can also add // debugId comments without also storing the Debug ID in a global variable, which is a problem, since the CLI will skip injection, but the SDK won't know what the Debug ID is since it is not stored in a global variable.
We don't want to set the debug ID global variable twice – this is the reason we need some way to avoid re-injecting the same files twice. However, our current logic produces false positives.
To ensure we only skip files injected by Sentry CLI, we will add another comment which indicates that the file has been injected with debug files by Sentry CLI. In case we ever change injection logic, we may wish to consider adding the version number into this comment, so we know which version of Sentry CLI performed the injection.
Most bundlers now support injecting debug IDs as per the spec (ie. without global variable shim injection). This includes webpack, rollup, vite and rolldown. In those cases the existing debug ID should be used if injecting the shim.
Instead, we should attempt to detect the injection based on whether the code snippet was added