@sentry/bundler-plugins 11.14.0 → 11.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/bun/index.js +6 -2
- package/build/cjs/bun/index.js.map +1 -1
- package/build/cjs/core/build-plugin-manager.js +5 -1
- package/build/cjs/core/build-plugin-manager.js.map +1 -1
- package/build/cjs/core/debug-id-upload.js +1 -1
- package/build/cjs/core/debug-id-upload.js.map +1 -1
- package/build/cjs/core/index.js +3 -0
- package/build/cjs/core/index.js.map +1 -1
- package/build/cjs/core/options-mapping.js +6 -1
- package/build/cjs/core/options-mapping.js.map +1 -1
- package/build/cjs/core/sentry/telemetry.js +3 -0
- package/build/cjs/core/sentry/telemetry.js.map +1 -1
- package/build/cjs/core/sourcemap-settings.js +85 -5
- package/build/cjs/core/sourcemap-settings.js.map +1 -1
- package/build/cjs/core/utils.js +10 -0
- package/build/cjs/core/utils.js.map +1 -1
- package/build/cjs/core/version.js +1 -1
- package/build/cjs/core/version.js.map +1 -1
- package/build/cjs/esbuild/index.js +14 -9
- package/build/cjs/esbuild/index.js.map +1 -1
- package/build/cjs/rollup/index.js +20 -12
- package/build/cjs/rollup/index.js.map +1 -1
- package/build/cjs/rollup/source-map-handling.js +19 -1
- package/build/cjs/rollup/source-map-handling.js.map +1 -1
- package/build/cjs/vite/release-html-injection.js +33 -0
- package/build/cjs/vite/release-html-injection.js.map +1 -0
- package/build/cjs/vite/source-map-hooks.js +8 -6
- package/build/cjs/vite/source-map-hooks.js.map +1 -1
- package/build/cjs/webpack/index.js +40 -8
- package/build/cjs/webpack/index.js.map +1 -1
- package/build/esm/bun/index.js +6 -2
- package/build/esm/bun/index.js.map +1 -1
- package/build/esm/core/build-plugin-manager.js +6 -2
- package/build/esm/core/build-plugin-manager.js.map +1 -1
- package/build/esm/core/debug-id-upload.js +1 -1
- package/build/esm/core/debug-id-upload.js.map +1 -1
- package/build/esm/core/index.js +3 -3
- package/build/esm/core/index.js.map +1 -1
- package/build/esm/core/options-mapping.js +7 -2
- package/build/esm/core/options-mapping.js.map +1 -1
- package/build/esm/core/sentry/telemetry.js +3 -0
- package/build/esm/core/sentry/telemetry.js.map +1 -1
- package/build/esm/core/sourcemap-settings.js +84 -6
- package/build/esm/core/sourcemap-settings.js.map +1 -1
- package/build/esm/core/utils.js +10 -1
- package/build/esm/core/utils.js.map +1 -1
- package/build/esm/core/version.js +1 -1
- package/build/esm/core/version.js.map +1 -1
- package/build/esm/esbuild/index.js +14 -9
- package/build/esm/esbuild/index.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/rollup/index.js +20 -12
- package/build/esm/rollup/index.js.map +1 -1
- package/build/esm/rollup/source-map-handling.js +19 -1
- package/build/esm/rollup/source-map-handling.js.map +1 -1
- package/build/esm/vite/release-html-injection.js +33 -0
- package/build/esm/vite/release-html-injection.js.map +1 -0
- package/build/esm/vite/source-map-hooks.js +9 -7
- package/build/esm/vite/source-map-hooks.js.map +1 -1
- package/build/esm/webpack/index.js +40 -8
- package/build/esm/webpack/index.js.map +1 -1
- package/build/types/bun/index.d.ts.map +1 -1
- package/build/types/core/build-plugin-manager.d.ts.map +1 -1
- package/build/types/core/debug-id-upload.d.ts +1 -1
- package/build/types/core/index.d.ts +2 -2
- package/build/types/core/index.d.ts.map +1 -1
- package/build/types/core/options-mapping.d.ts +4 -1
- package/build/types/core/options-mapping.d.ts.map +1 -1
- package/build/types/core/sentry/telemetry.d.ts.map +1 -1
- package/build/types/core/sourcemap-settings.d.ts +19 -0
- package/build/types/core/sourcemap-settings.d.ts.map +1 -1
- package/build/types/core/types.d.ts +54 -1
- package/build/types/core/types.d.ts.map +1 -1
- package/build/types/core/utils.d.ts +7 -0
- package/build/types/core/utils.d.ts.map +1 -1
- package/build/types/core/version.d.ts +1 -1
- package/build/types/esbuild/index.d.ts.map +1 -1
- package/build/types/rollup/index.d.ts +36 -5
- package/build/types/rollup/index.d.ts.map +1 -1
- package/build/types/rollup/source-map-handling.d.ts +5 -0
- package/build/types/rollup/source-map-handling.d.ts.map +1 -1
- package/build/types/vite/release-html-injection.d.ts +31 -0
- package/build/types/vite/release-html-injection.d.ts.map +1 -0
- package/build/types/vite/source-map-hooks.d.ts +1 -0
- package/build/types/vite/source-map-hooks.d.ts.map +1 -1
- package/build/types/webpack/index.d.ts.map +1 -1
- package/package.json +4 -4
|
@@ -4,6 +4,7 @@ const require_utils = require("../core/utils.js");
|
|
|
4
4
|
const require_get_code_injection_position = require("../core/get-code-injection-position.js");
|
|
5
5
|
const require_component_annotate_hooks = require("../core/component-annotate-hooks.js");
|
|
6
6
|
const require_debug_id_upload = require("../core/debug-id-upload.js");
|
|
7
|
+
const require_sourcemap_settings = require("../core/sourcemap-settings.js");
|
|
7
8
|
const require_build_plugin_manager = require("../core/build-plugin-manager.js");
|
|
8
9
|
const require_index = require("../core/index.js");
|
|
9
10
|
let node_path = require("node:path");
|
|
@@ -21,6 +22,12 @@ try {
|
|
|
21
22
|
COMPONENT_ANNOTATION_LOADER = node_path.resolve(dirname, "component-annotation-transform.js");
|
|
22
23
|
}
|
|
23
24
|
const WEBPACK_JAVASCRIPT_ASSET_REGEX = /\.(?:js|ts|jsx|tsx|mjs|cjs|mts|cts)(?:\?[^?]*)?(?:#[^#]*)?$/;
|
|
25
|
+
function findHtmlWebpackPlugin(compiler) {
|
|
26
|
+
for (const plugin of compiler.options.plugins ?? []) {
|
|
27
|
+
const pluginClass = plugin?.constructor;
|
|
28
|
+
if (pluginClass?.name === "HtmlWebpackPlugin" && typeof pluginClass.getHooks === "function") return pluginClass;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
24
31
|
/**
|
|
25
32
|
* Maps webpack's `devtool` onto the plugin's source map kinds. A user who sets `devtool: false`
|
|
26
33
|
* and adds a `SourceMapDevToolPlugin` manages source maps themselves.
|
|
@@ -116,7 +123,7 @@ function createSentryWebpackPlugin(userOptions = {}) {
|
|
|
116
123
|
const { logger, normalizedOptions: options, bundleSizeOptimizationReplacementValues: replacementValues, bundleMetadata, createDependencyOnBuildArtifacts } = sentryBuildPluginManager;
|
|
117
124
|
if (options.disable) return { apply() {} };
|
|
118
125
|
if (process.cwd().match(/\\node_modules\\|\/node_modules\//)) logger.warn("Running Sentry plugin from within a `node_modules` folder. Some features may not work.");
|
|
119
|
-
const
|
|
126
|
+
const { injectDebugIds, upload: uploadEnabled, stampEmittedFiles } = require_sourcemap_settings.getSourceMapFeatures(options);
|
|
120
127
|
const releaseInjectionCode = new require_utils.CodeInjection();
|
|
121
128
|
const chunkInjectionCode = new require_utils.CodeInjection();
|
|
122
129
|
if (!options.release.inject) logger.debug("Release injection disabled via `release.inject` option. Will not inject release.");
|
|
@@ -141,8 +148,33 @@ function createSentryWebpackPlugin(userOptions = {}) {
|
|
|
141
148
|
decision
|
|
142
149
|
};
|
|
143
150
|
}
|
|
144
|
-
|
|
145
|
-
|
|
151
|
+
/**
|
|
152
|
+
* Adds the release snippet to the `<head>` of every page that `html-webpack-plugin` generates.
|
|
153
|
+
* Returns `false` when the build has no `html-webpack-plugin`.
|
|
154
|
+
*/
|
|
155
|
+
function addReleaseToHtml(compiler) {
|
|
156
|
+
const HtmlWebpackPlugin = findHtmlWebpackPlugin(compiler);
|
|
157
|
+
if (!HtmlWebpackPlugin) {
|
|
158
|
+
logger.warn("`release.inject: 'html'` needs `html-webpack-plugin` to generate the HTML, and this build does not use it. Injecting the release into the startup chunks instead.");
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
const tag = {
|
|
162
|
+
tagName: "script",
|
|
163
|
+
voidTag: false,
|
|
164
|
+
attributes: {},
|
|
165
|
+
meta: { plugin: "sentry-webpack-plugin" },
|
|
166
|
+
innerHTML: releaseInjectionCode.code()
|
|
167
|
+
};
|
|
168
|
+
compiler.hooks.thisCompilation.tap("sentry-webpack-plugin", (compilation) => {
|
|
169
|
+
HtmlWebpackPlugin.getHooks(compilation).alterAssetTagGroups.tap("sentry-webpack-plugin", (data) => {
|
|
170
|
+
data.headTags.unshift(tag);
|
|
171
|
+
return data;
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
function addCodeInjection(compiler, injectRelease) {
|
|
177
|
+
if ((!injectRelease || releaseInjectionCode.isEmpty()) && chunkInjectionCode.isEmpty() && !injectDebugIds) return;
|
|
146
178
|
const ReplaceSource = compiler.webpack?.sources?.ReplaceSource;
|
|
147
179
|
const processAssetsStage = compiler.webpack?.Compilation?.PROCESS_ASSETS_STAGE_ADDITIONS;
|
|
148
180
|
if (!ReplaceSource || processAssetsStage === void 0) {
|
|
@@ -163,9 +195,9 @@ function createSentryWebpackPlugin(userOptions = {}) {
|
|
|
163
195
|
const sourceContents = source.source();
|
|
164
196
|
const code = typeof sourceContents === "string" ? sourceContents : Buffer.from(sourceContents).toString();
|
|
165
197
|
const codeToInject = new require_utils.CodeInjection();
|
|
166
|
-
if (chunk.canBeInitial?.() ?? true) codeToInject.append(releaseInjectionCode);
|
|
198
|
+
if (injectRelease && (chunk.canBeInitial?.() ?? true)) codeToInject.append(releaseInjectionCode);
|
|
167
199
|
codeToInject.append(chunkInjectionCode);
|
|
168
|
-
if (
|
|
200
|
+
if (injectDebugIds) {
|
|
169
201
|
const hash = chunk.contentHash?.javascript ?? chunk.hash;
|
|
170
202
|
codeToInject.append(require_index.getDebugIdSnippet(hash ? require_utils.stringToUUID(hash) : (0, node_crypto.randomUUID)()));
|
|
171
203
|
}
|
|
@@ -217,8 +249,8 @@ function createSentryWebpackPlugin(userOptions = {}) {
|
|
|
217
249
|
compiler.hooks.done.tap("sentry-webpack-plugin", settlePendingStagings);
|
|
218
250
|
compiler.hooks.failed?.tap("sentry-webpack-plugin", settlePendingStagings);
|
|
219
251
|
}
|
|
220
|
-
addCodeInjection(compiler);
|
|
221
|
-
if (
|
|
252
|
+
addCodeInjection(compiler, !(options.release.inject === "html" && !releaseInjectionCode.isEmpty() && addReleaseToHtml(compiler)));
|
|
253
|
+
if (stampEmittedFiles) {
|
|
222
254
|
const RawSource = compiler.webpack?.sources?.RawSource;
|
|
223
255
|
const stage = (compiler.webpack?.Compilation?.PROCESS_ASSETS_STAGE_DEV_TOOLING ?? 500) + 1;
|
|
224
256
|
if (!RawSource) logger.warn("Webpack sources are not available. Skipping debug ID injection into emitted source maps. This usually means webpack is not properly configured.");
|
|
@@ -257,7 +289,7 @@ function createSentryWebpackPlugin(userOptions = {}) {
|
|
|
257
289
|
const run = async () => {
|
|
258
290
|
try {
|
|
259
291
|
await sentryBuildPluginManager.createRelease();
|
|
260
|
-
if (
|
|
292
|
+
if (uploadEnabled) {
|
|
261
293
|
const outputPath = compilation.outputOptions.path ?? node_path.resolve();
|
|
262
294
|
const buildArtifacts = Object.keys(compilation.assets).map((asset) => node_path.join(outputPath, asset));
|
|
263
295
|
stagingHandedOver = true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["createRequire","path","fileURLToPath","isJsFile","stampDebugId","createSentryBuildPluginManager","CodeInjection","generateReleaseInjectorCode","generateModuleMetadataInjectorCode","createComponentNameAnnotateHooks","getDebugIdSnippet","stringToUUID","randomUUID","getCodeInjectionPosition","createDebugIdUploadFunction"],"sources":["../../../src/webpack/index.ts"],"sourcesContent":["/* oxlint-disable max-lines */\n\nimport type {\n InternalOptions,\n Options,\n SourceMapDecision,\n SourceMapKind,\n UploadFilter,\n UploadStaging,\n} from '../core/index';\nimport {\n createSentryBuildPluginManager,\n generateReleaseInjectorCode,\n generateModuleMetadataInjectorCode,\n stringToUUID,\n createComponentNameAnnotateHooks,\n CodeInjection,\n getDebugIdSnippet,\n createDebugIdUploadFunction,\n getCodeInjectionPosition,\n isJsFile,\n stampDebugId,\n} from '../core/index';\nimport * as path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { createRequire } from 'node:module';\nimport { randomUUID } from 'node:crypto';\n\nconst _req = createRequire(import.meta.url);\n\n// Resolve the loader path via the package's own exports.\n// This module may end up in a shared chunk (_chunks/) whose import.meta.url\n// does not point to the webpack/ directory where the transform file lives, so\n// a path-relative lookup would fail. Using require.resolve on the package export\n// always finds the correct installed file regardless of chunk placement.\nlet COMPONENT_ANNOTATION_LOADER: string;\ntry {\n COMPONENT_ANNOTATION_LOADER = _req.resolve('@sentry/bundler-plugins/webpack-loader');\n} catch {\n // Fallback for non-packaged environments (e.g., monorepo source runs without dist)\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore Rollup transpiles import.meta for us for CJS\n const dirname = path.dirname(fileURLToPath(import.meta.url));\n // The Rollup build emits `.js` for both CJS and ESM, so the extension is the same in both.\n COMPONENT_ANNOTATION_LOADER = path.resolve(dirname, 'component-annotation-transform.js');\n}\n\ntype PluginClass = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (options: any): unknown;\n};\n\ntype WebpackSource = {\n source: () => string | Buffer;\n};\n\ntype WebpackRawSource = {\n new (source: string): WebpackSource;\n};\n\ntype WebpackReplaceSource = WebpackSource & {\n insert: (position: number, value: string) => void;\n};\n\nconst WEBPACK_JAVASCRIPT_ASSET_REGEX = /\\.(?:js|ts|jsx|tsx|mjs|cjs|mts|cts)(?:\\?[^?]*)?(?:#[^#]*)?$/;\n\ntype WebpackAsset = {\n name: string;\n source: WebpackSource;\n info: {\n related?: {\n sourceMap?: string | string[];\n };\n };\n};\n\ntype WebpackCompiler = {\n options: {\n plugins?: unknown[];\n mode?: string;\n devtool?: string | false;\n module?: {\n rules?: unknown[];\n };\n };\n hooks: {\n compilation: {\n tap: (name: string, callback: (compilation: WebpackCompilation) => void) => void;\n };\n thisCompilation: {\n tap: (name: string, callback: (compilation: WebpackCompilation) => void) => void;\n };\n emit: {\n tap: (name: string, callback: (compilation: WebpackCompilation) => void) => void;\n };\n afterEmit: {\n tapAsync: (name: string, callback: (compilation: WebpackCompilation, cb: () => void) => void) => void;\n };\n done: {\n tap: (name: string, callback: () => void) => void;\n };\n failed?: {\n tap: (name: string, callback: () => void) => void;\n };\n };\n webpack?: {\n DefinePlugin?: PluginClass;\n Compilation?: {\n PROCESS_ASSETS_STAGE_ADDITIONS?: number;\n PROCESS_ASSETS_STAGE_DEV_TOOLING?: number;\n PROCESS_ASSETS_STAGE_REPORT?: number;\n };\n sources?: {\n RawSource?: WebpackRawSource;\n ReplaceSource?: new (source: WebpackSource) => WebpackReplaceSource;\n };\n };\n};\n\ntype WebpackCompilation = {\n chunks: Iterable<{\n files: Iterable<string>;\n hash?: string;\n contentHash?: { javascript?: string };\n canBeInitial?: () => boolean;\n }>;\n outputOptions: {\n path?: string;\n };\n assets: Record<string, unknown>;\n getAssets: () => WebpackAsset[];\n getAsset: (name: string) => WebpackAsset | undefined;\n updateAsset: (name: string, source: WebpackSource) => void;\n deleteAsset: (name: string) => void;\n hooks: {\n processAssets: {\n tap: (\n options: { name: string; stage: number },\n callback: (assets: Record<string, WebpackSource>) => void,\n ) => void;\n tapPromise: (options: { name: string; stage: number }, callback: () => Promise<void>) => void;\n };\n };\n};\n\n/**\n * Maps webpack's `devtool` onto the plugin's source map kinds. A user who sets `devtool: false`\n * and adds a `SourceMapDevToolPlugin` manages source maps themselves.\n */\nfunction sourceMapKindFromDevtool(compiler: WebpackCompiler): SourceMapKind | undefined {\n const devtool = compiler.options.devtool;\n\n if (devtool === undefined) {\n return 'unset';\n }\n if (devtool === false) {\n const hasSourceMapPlugin = compiler.options.plugins?.some(\n plugin =>\n (plugin as { constructor?: { name?: string } } | undefined)?.constructor?.name === 'SourceMapDevToolPlugin',\n );\n return hasSourceMapPlugin ? undefined : 'off';\n }\n // Plain `eval` has no source maps at all.\n if (!devtool.includes('source-map')) {\n return 'off';\n }\n if (devtool.includes('inline') || devtool.includes('eval')) {\n return 'inline';\n }\n if (devtool.includes('hidden')) {\n return 'hidden';\n }\n return 'visible';\n}\n\ntype WebpackModule = {\n version?: string;\n default?: { version?: string };\n};\n\n// Only used for telemetry; `webpack` is an optional peer dependency and may be absent (e.g. rspack).\nfunction getWebpackMajorVersion(): string | undefined {\n try {\n const webpack = _req('webpack') as WebpackModule;\n const version = webpack.version ?? webpack.default?.version;\n return version?.split('.')[0];\n } catch {\n return undefined;\n }\n}\n\n/**\n * Stamps each JS asset's debug ID into the asset itself and its source map asset.\n *\n * Runs after source maps have been generated, so the JS asset no longer needs to carry\n * source map information and can be replaced with a plain `RawSource`.\n */\nfunction addDebugIdsToAssets(compilation: WebpackCompilation, RawSource: WebpackRawSource): void {\n for (const asset of compilation.getAssets()) {\n if (!isJsFile(asset.name)) {\n continue;\n }\n\n const bundleSource = asset.source.source().toString();\n const relatedSourceMap = asset.info.related?.sourceMap;\n const sourceMapName = typeof relatedSourceMap === 'string' ? relatedSourceMap : `${asset.name}.map`;\n const sourceMapAsset = compilation.getAsset(sourceMapName);\n\n const stamped = stampDebugId(bundleSource, sourceMapAsset?.source.source().toString());\n if (!stamped) {\n continue;\n }\n\n compilation.updateAsset(asset.name, new RawSource(stamped.bundleSource));\n if (stamped.sourceMapSource !== undefined) {\n compilation.updateAsset(sourceMapName, new RawSource(stamped.sourceMapSource));\n }\n }\n}\n\n/** Drops a source map asset and its compressed variants from the compilation. */\nfunction deleteSourceMapAssets(compilation: WebpackCompilation, sourceMapName: string): void {\n for (const candidate of compilation.getAssets()) {\n if (candidate.name === sourceMapName || candidate.name.startsWith(`${sourceMapName}.`)) {\n compilation.deleteAsset(candidate.name);\n }\n }\n}\n\n/**\n * Drops the source maps of the JS assets that an upload would include. With `removeAll` it drops\n * the source maps of all assets, CSS included.\n */\nfunction dropSourceMaps(compilation: WebpackCompilation, shouldUpload: UploadFilter, removeAll: boolean): void {\n const outputPath = compilation.outputOptions.path ?? path.resolve();\n\n for (const asset of compilation.getAssets()) {\n if (!removeAll && (!isJsFile(asset.name) || !shouldUpload(path.join(outputPath, asset.name)))) {\n continue;\n }\n const relatedSourceMap = asset.info.related?.sourceMap;\n const sourceMapName = typeof relatedSourceMap === 'string' ? relatedSourceMap : `${asset.name}.map`;\n if (compilation.getAsset(sourceMapName)) {\n deleteSourceMapAssets(compilation, sourceMapName);\n }\n }\n}\n\n/**\n * Copies each JS asset and its source map into the upload staging folder and drops the source map\n * assets (and their compressed variants) from the compilation, so webpack never emits them.\n *\n * A map the plugin or the SDK turned on (`pluginEnabledMaps`) never reaches the output, whether or\n * not its asset is uploaded. That covers CSS maps, which `devtool` turns on along with the JS ones.\n * A map the user enabled stays unless it was staged.\n */\nasync function stageSourceMaps(\n compilation: WebpackCompilation,\n staging: UploadStaging,\n logger: { warn: (message: string) => void },\n pluginEnabledMaps: boolean,\n): Promise<void> {\n const outputPath = compilation.outputOptions.path ?? path.resolve();\n\n for (const asset of compilation.getAssets()) {\n const relatedSourceMap = asset.info.related?.sourceMap;\n const sourceMapName = typeof relatedSourceMap === 'string' ? relatedSourceMap : `${asset.name}.map`;\n const sourceMapAsset = compilation.getAsset(sourceMapName);\n if (!sourceMapAsset) {\n continue;\n }\n\n if (!isJsFile(asset.name)) {\n if (pluginEnabledMaps) {\n deleteSourceMapAssets(compilation, sourceMapName);\n }\n continue;\n }\n\n const result = await staging.stage({\n code: asset.source.source().toString(),\n mapSource: sourceMapAsset.source.source().toString(),\n mapDir: path.join(outputPath, path.dirname(sourceMapName)),\n chunkPath: path.join(outputPath, asset.name),\n });\n\n if (result === 'skipped' || result === 'failed') {\n logger.warn(\n pluginEnabledMaps\n ? `Could not prepare ${asset.name} for upload, so it is not uploaded and its source map ${sourceMapName} was removed from the build output.`\n : `Could not prepare ${asset.name} for upload, so its source map ${sourceMapName} stays in the build output.`,\n );\n }\n if (result === 'staged' || pluginEnabledMaps) {\n deleteSourceMapAssets(compilation, sourceMapName);\n }\n }\n}\n\nfunction createSentryWebpackPlugin(userOptions: SentryWebpackPluginInternalOptions = {}) {\n const sentryBuildPluginManager = createSentryBuildPluginManager(userOptions, {\n loggerPrefix: userOptions._metaOptions?.loggerPrefixOverride ?? '[sentry-webpack-plugin]',\n buildTool: 'webpack',\n buildToolMajorVersion: getWebpackMajorVersion(),\n });\n\n const {\n logger,\n normalizedOptions: options,\n bundleSizeOptimizationReplacementValues: replacementValues,\n bundleMetadata,\n createDependencyOnBuildArtifacts,\n } = sentryBuildPluginManager;\n\n if (options.disable) {\n return {\n apply() {\n // noop plugin\n },\n };\n }\n\n if (process.cwd().match(/\\\\node_modules\\\\|\\/node_modules\\//)) {\n logger.warn('Running Sentry plugin from within a `node_modules` folder. Some features may not work.');\n }\n\n const sourcemapsEnabled = options.sourcemaps?.disable !== true;\n const releaseInjectionCode = new CodeInjection();\n const chunkInjectionCode = new CodeInjection();\n\n if (!options.release.inject) {\n logger.debug('Release injection disabled via `release.inject` option. Will not inject release.');\n } else if (!options.release.name) {\n logger.debug(\n 'No release name provided. Will not inject release. Please set the `release.name` option to identify your release.',\n );\n } else {\n releaseInjectionCode.append(\n generateReleaseInjectorCode({\n release: options.release.name,\n injectBuildInformation: options._experiments.injectBuildInformation || false,\n }),\n );\n }\n\n if (Object.keys(bundleMetadata).length > 0) {\n chunkInjectionCode.append(generateModuleMetadataInjectorCode(bundleMetadata));\n }\n\n const transformAnnotations = options.reactComponentAnnotation?.enabled\n ? createComponentNameAnnotateHooks(\n options.reactComponentAnnotation?.ignoredComponents || [],\n !!options.reactComponentAnnotation?._experimentalInjectIntoHtml,\n { logger },\n )\n : undefined;\n\n const transformReplace = Object.keys(replacementValues).length > 0;\n\n function decideSourceMaps(compiler: WebpackCompiler): { kind?: SourceMapKind; decision: SourceMapDecision } {\n const kind = compiler.options.mode === 'development' ? undefined : sourceMapKindFromDevtool(compiler);\n if (kind === undefined) {\n return { decision: { enableHidden: false, deleteAfterUpload: false } };\n }\n\n const decision = sentryBuildPluginManager.sourceMaps.decide(kind);\n\n if (decision.enableHidden) {\n compiler.options.devtool = kind === 'visible' ? `hidden-${compiler.options.devtool}` : 'hidden-source-map';\n }\n\n return { kind, decision };\n }\n\n function addCodeInjection(compiler: WebpackCompiler): void {\n if (releaseInjectionCode.isEmpty() && chunkInjectionCode.isEmpty() && !sourcemapsEnabled) {\n return;\n }\n\n const ReplaceSource = compiler.webpack?.sources?.ReplaceSource;\n const processAssetsStage = compiler.webpack?.Compilation?.PROCESS_ASSETS_STAGE_ADDITIONS;\n\n if (!ReplaceSource || processAssetsStage === undefined) {\n logger.warn(\n 'Webpack sources are not available. Skipping code injection. This usually means webpack is not properly configured.',\n );\n return;\n }\n\n compiler.hooks.compilation.tap('sentry-webpack-plugin-injection', compilation => {\n compilation.hooks.processAssets.tap(\n {\n name: 'sentry-webpack-plugin-injection',\n stage: processAssetsStage,\n },\n assets => {\n const injectedAssets = new Set<string>();\n\n for (const chunk of compilation.chunks) {\n for (const assetName of chunk.files) {\n if (injectedAssets.has(assetName) || !WEBPACK_JAVASCRIPT_ASSET_REGEX.test(assetName)) {\n continue;\n }\n\n const source = assets[assetName];\n if (!source) {\n continue;\n }\n injectedAssets.add(assetName);\n\n const sourceContents = source.source();\n const code = typeof sourceContents === 'string' ? sourceContents : Buffer.from(sourceContents).toString();\n const codeToInject = new CodeInjection();\n if (chunk.canBeInitial?.() ?? true) {\n codeToInject.append(releaseInjectionCode);\n }\n codeToInject.append(chunkInjectionCode);\n if (sourcemapsEnabled) {\n const hash = chunk.contentHash?.javascript ?? chunk.hash;\n codeToInject.append(getDebugIdSnippet(hash ? stringToUUID(hash) : randomUUID()));\n }\n\n const injectionPosition = getCodeInjectionPosition(code);\n const injection = injectionPosition === code.length ? `\\n${codeToInject.code()}` : codeToInject.code();\n const updatedSource = new ReplaceSource(source);\n updatedSource.insert(injectionPosition, injection);\n compilation.updateAsset(assetName, updatedSource);\n }\n }\n },\n );\n });\n }\n\n return {\n apply(compiler: WebpackCompiler) {\n void sentryBuildPluginManager.telemetry.emitBundlerPluginExecutionSignal().catch(() => {\n // Telemetry failures are acceptable\n });\n\n const { DefinePlugin } = compiler.webpack ?? {};\n\n // One plugin instance can serve several compilers (`MultiCompiler`) and\n // a compiler several compilations (watch mode), so nothing is shared.\n const { decision: sourceMapDecision } = decideSourceMaps(compiler);\n const removeAllSourceMaps = sourceMapDecision.removeAllSourceMaps === true;\n const pendingStagings = new Map<WebpackCompilation, UploadStaging>();\n\n // After `RealContentHashPlugin` rewrote the hash placeholders, so the staged\n // JS equals the emitted file and `[contenthash]` names are final.\n const deleteStage = (compiler.webpack?.Compilation?.PROCESS_ASSETS_STAGE_REPORT ?? 5000) + 1;\n\n if (sourceMapDecision.deleteAfterUpload && !sentryBuildPluginManager.sourceMaps.uploadPossible) {\n compiler.hooks.thisCompilation.tap('sentry-webpack-plugin', compilation => {\n compilation.hooks.processAssets.tap({ name: 'sentry-webpack-plugin', stage: deleteStage }, () => {\n dropSourceMaps(compilation, sentryBuildPluginManager.sourceMaps.shouldUpload, removeAllSourceMaps);\n });\n });\n } else if (sourceMapDecision.deleteAfterUpload) {\n compiler.hooks.thisCompilation.tap('sentry-webpack-plugin', compilation => {\n compilation.hooks.processAssets.tapPromise(\n { name: 'sentry-webpack-plugin', stage: deleteStage },\n async () => {\n const staging = await sentryBuildPluginManager.createUploadStaging();\n pendingStagings.set(compilation, staging);\n await stageSourceMaps(compilation, staging, logger, removeAllSourceMaps);\n },\n );\n });\n\n // A staging that `afterEmit` never took belongs to a compilation that\n // failed before emitting, or to one whose assets were emitted without\n // their maps because an earlier `afterEmit` tap failed. Only the\n // second kind has no other copy of the maps.\n const emittedCompilations = new Set<WebpackCompilation>();\n compiler.hooks.emit.tap('sentry-webpack-plugin', compilation => {\n emittedCompilations.add(compilation);\n });\n const settlePendingStagings = (): void => {\n for (const [compilation, staging] of pendingStagings) {\n if (emittedCompilations.has(compilation)) {\n void staging.keep('The source map upload did not run.');\n } else {\n void staging.discard();\n }\n }\n pendingStagings.clear();\n emittedCompilations.clear();\n };\n compiler.hooks.done.tap('sentry-webpack-plugin', settlePendingStagings);\n compiler.hooks.failed?.tap('sentry-webpack-plugin', settlePendingStagings);\n }\n\n // BannerPlugin prepends executable code before directive prologues.\n addCodeInjection(compiler);\n\n // The upload routine (which stamps debug IDs into temp copies of the artifacts) is skipped\n // with `disable-upload`, so the emitted artifacts get stamped in the asset pipeline instead.\n if (sourcemapsEnabled && options.sourcemaps?.disable === 'disable-upload') {\n const RawSource = compiler.webpack?.sources?.RawSource;\n // Right after source map generation (and thus after minification, which would strip the comment),\n // so later stages (real content hashing, subresource integrity) see the final assets.\n const stage = (compiler.webpack?.Compilation?.PROCESS_ASSETS_STAGE_DEV_TOOLING ?? 500) + 1;\n\n if (!RawSource) {\n logger.warn(\n 'Webpack sources are not available. Skipping debug ID injection into emitted source maps. This usually means webpack is not properly configured.',\n );\n } else {\n compiler.hooks.thisCompilation.tap('sentry-webpack-plugin', compilation => {\n compilation.hooks.processAssets.tap({ name: 'sentry-webpack-plugin', stage }, () => {\n addDebugIdsToAssets(compilation, RawSource);\n });\n });\n }\n }\n\n // Add DefinePlugin for bundle size optimizations\n if (transformReplace && DefinePlugin) {\n compiler.options.plugins = compiler.options.plugins || [];\n compiler.options.plugins.push(new DefinePlugin(replacementValues));\n }\n\n // Add component name annotation transform\n if (transformAnnotations?.transform) {\n compiler.options.module = compiler.options.module || {};\n compiler.options.module.rules = compiler.options.module.rules || [];\n compiler.options.module.rules.unshift({\n test: /\\.[jt]sx$/,\n exclude: /node_modules/,\n enforce: 'pre',\n use: [\n {\n loader: COMPONENT_ANNOTATION_LOADER,\n options: {\n transform: transformAnnotations.transform,\n },\n },\n ],\n });\n }\n\n compiler.hooks.afterEmit.tapAsync(\n 'sentry-webpack-plugin',\n (compilation: WebpackCompilation, callback: (err?: Error) => void) => {\n const freeGlobalDependencyOnBuildArtifacts = createDependencyOnBuildArtifacts();\n const upload = createDebugIdUploadFunction({ sentryBuildPluginManager });\n\n const staging = pendingStagings.get(compilation);\n pendingStagings.delete(compilation);\n let stagingHandedOver = false;\n\n const run = async (): Promise<void> => {\n try {\n await sentryBuildPluginManager.createRelease();\n if (sourcemapsEnabled && options.sourcemaps?.disable !== 'disable-upload') {\n const outputPath = compilation.outputOptions.path ?? path.resolve();\n const buildArtifacts = Object.keys(compilation.assets).map(asset => path.join(outputPath, asset));\n stagingHandedOver = true;\n await upload(buildArtifacts, { staging });\n } else {\n stagingHandedOver = true;\n await staging?.discard();\n }\n } catch (e) {\n if (!stagingHandedOver) {\n await staging?.keep('The source map upload did not run.');\n }\n throw e;\n } finally {\n freeGlobalDependencyOnBuildArtifacts();\n await sentryBuildPluginManager.deleteArtifacts();\n }\n };\n\n run().then(\n () => callback(),\n (err: Error) => callback(err),\n );\n },\n );\n\n if (userOptions._experiments?.forceExitOnBuildCompletion && compiler.options.mode === 'production') {\n compiler.hooks.done.tap('sentry-webpack-plugin', () => {\n setTimeout(() => {\n logger.debug('Exiting process after debug file upload');\n process.exit(0);\n });\n });\n }\n },\n };\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const sentryWebpackPlugin: (options?: SentryWebpackPluginInternalOptions) => any = createSentryWebpackPlugin;\n\n/** @internal For Sentry SDK packages only. See `InternalOptions`. */\nexport type SentryWebpackPluginInternalOptions = InternalOptions & WebpackExperiments;\n\nexport type SentryWebpackPluginOptions = Options & WebpackExperiments;\n\ntype WebpackExperiments = {\n _experiments?: Options['_experiments'] & {\n /**\n * If enabled, the webpack plugin will exit the build process after the build completes.\n * Use this with caution, as it will terminate the process.\n *\n * More information: https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/345\n *\n * @default false\n */\n forceExitOnBuildCompletion?: boolean;\n };\n};\n"],"mappings":";;;;;;;;;;;;;;AA4BA,MAAM,QAAA,GAAOA,YAAAA,cAAAA,CAAAA,QAAAA,KAAAA,CAAAA,CAAAA,cAAAA,UAAAA,CAAAA,CAAAA,IAA6B;AAO1C,IAAI;AACJ,IAAI;CACF,8BAA8B,KAAK,QAAQ,wCAAwC;AACrF,QAAQ;CAIN,MAAM,UAAUC,UAAK,SAAA,GAAQC,SAAAA,cAAAA,CAAAA,QAAAA,KAAAA,CAAAA,CAAAA,cAAAA,UAAAA,CAAAA,CAAAA,IAA6B,CAAC;CAE3D,8BAA8BD,UAAK,QAAQ,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,CAAC;EACH;EAEA,SAAS,MAAM,UAAU,SACvB,0BACC,aAAiC,aAAoC;GACpE,MAAM,uCAAuC,iCAAiC;GAC9E,MAAM,SAASC,wBAAAA,4BAA4B,EAAE,yBAAyB,CAAC;GAEvE,MAAM,UAAU,gBAAgB,IAAI,WAAW;GAC/C,gBAAgB,OAAO,WAAW;GAClC,IAAI,oBAAoB;GAExB,MAAM,MAAM,YAA2B;IACrC,IAAI;KACF,MAAM,yBAAyB,cAAc;KAC7C,IAAI,qBAAqB,QAAQ,YAAY,YAAY,kBAAkB;MACzE,MAAM,aAAa,YAAY,cAAc,QAAQb,UAAK,QAAQ;MAClE,MAAM,iBAAiB,OAAO,KAAK,YAAY,MAAM,CAAC,CAAC,KAAI,UAASA,UAAK,KAAK,YAAY,KAAK,CAAC;MAChG,oBAAoB;MACpB,MAAM,OAAO,gBAAgB,EAAE,QAAQ,CAAC;KAC1C,OAAO;MACL,oBAAoB;MACpB,MAAM,SAAS,QAAQ;KACzB;IACF,SAAS,GAAG;KACV,IAAI,CAAC,mBACH,MAAM,SAAS,KAAK,oCAAoC;KAE1D,MAAM;IACR,UAAU;KACR,qCAAqC;KACrC,MAAM,yBAAyB,gBAAgB;IACjD;GACF;GAEA,IAAI,CAAC,CAAC,WACE,SAAS,IACd,QAAe,SAAS,GAAG,CAC9B;EACF,CACF;EAEA,IAAI,YAAY,cAAc,8BAA8B,SAAS,QAAQ,SAAS,cACpF,SAAS,MAAM,KAAK,IAAI,+BAA+B;GACrD,iBAAiB;IACf,OAAO,MAAM,yCAAyC;IACtD,QAAQ,KAAK,CAAC;GAChB,CAAC;EACH,CAAC;CAEL,EACF;AACF;AAGA,MAAa,sBAA6E"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["createRequire","path","fileURLToPath","isJsFile","stampDebugId","createSentryBuildPluginManager","getSourceMapFeatures","CodeInjection","generateReleaseInjectorCode","generateModuleMetadataInjectorCode","createComponentNameAnnotateHooks","getDebugIdSnippet","stringToUUID","randomUUID","getCodeInjectionPosition","createDebugIdUploadFunction"],"sources":["../../../src/webpack/index.ts"],"sourcesContent":["/* oxlint-disable max-lines */\n\nimport type {\n InternalOptions,\n Options,\n SourceMapDecision,\n SourceMapKind,\n UploadFilter,\n UploadStaging,\n} from '../core/index';\nimport {\n createSentryBuildPluginManager,\n generateReleaseInjectorCode,\n generateModuleMetadataInjectorCode,\n stringToUUID,\n createComponentNameAnnotateHooks,\n CodeInjection,\n getDebugIdSnippet,\n createDebugIdUploadFunction,\n getCodeInjectionPosition,\n isJsFile,\n stampDebugId,\n getSourceMapFeatures,\n} from '../core/index';\nimport * as path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { createRequire } from 'node:module';\nimport { randomUUID } from 'node:crypto';\n\nconst _req = createRequire(import.meta.url);\n\n// Resolve the loader path via the package's own exports.\n// This module may end up in a shared chunk (_chunks/) whose import.meta.url\n// does not point to the webpack/ directory where the transform file lives, so\n// a path-relative lookup would fail. Using require.resolve on the package export\n// always finds the correct installed file regardless of chunk placement.\nlet COMPONENT_ANNOTATION_LOADER: string;\ntry {\n COMPONENT_ANNOTATION_LOADER = _req.resolve('@sentry/bundler-plugins/webpack-loader');\n} catch {\n // Fallback for non-packaged environments (e.g., monorepo source runs without dist)\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore Rollup transpiles import.meta for us for CJS\n const dirname = path.dirname(fileURLToPath(import.meta.url));\n // The Rollup build emits `.js` for both CJS and ESM, so the extension is the same in both.\n COMPONENT_ANNOTATION_LOADER = path.resolve(dirname, 'component-annotation-transform.js');\n}\n\ntype PluginClass = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (options: any): unknown;\n};\n\ntype WebpackSource = {\n source: () => string | Buffer;\n};\n\ntype WebpackRawSource = {\n new (source: string): WebpackSource;\n};\n\ntype WebpackReplaceSource = WebpackSource & {\n insert: (position: number, value: string) => void;\n};\n\nconst WEBPACK_JAVASCRIPT_ASSET_REGEX = /\\.(?:js|ts|jsx|tsx|mjs|cjs|mts|cts)(?:\\?[^?]*)?(?:#[^#]*)?$/;\n\ntype WebpackAsset = {\n name: string;\n source: WebpackSource;\n info: {\n related?: {\n sourceMap?: string | string[];\n };\n };\n};\n\ntype WebpackCompiler = {\n options: {\n plugins?: unknown[];\n mode?: string;\n devtool?: string | false;\n module?: {\n rules?: unknown[];\n };\n };\n hooks: {\n compilation: {\n tap: (name: string, callback: (compilation: WebpackCompilation) => void) => void;\n };\n thisCompilation: {\n tap: (name: string, callback: (compilation: WebpackCompilation) => void) => void;\n };\n emit: {\n tap: (name: string, callback: (compilation: WebpackCompilation) => void) => void;\n };\n afterEmit: {\n tapAsync: (name: string, callback: (compilation: WebpackCompilation, cb: () => void) => void) => void;\n };\n done: {\n tap: (name: string, callback: () => void) => void;\n };\n failed?: {\n tap: (name: string, callback: () => void) => void;\n };\n };\n webpack?: {\n DefinePlugin?: PluginClass;\n Compilation?: {\n PROCESS_ASSETS_STAGE_ADDITIONS?: number;\n PROCESS_ASSETS_STAGE_DEV_TOOLING?: number;\n PROCESS_ASSETS_STAGE_REPORT?: number;\n };\n sources?: {\n RawSource?: WebpackRawSource;\n ReplaceSource?: new (source: WebpackSource) => WebpackReplaceSource;\n };\n };\n};\n\ntype WebpackCompilation = {\n chunks: Iterable<{\n files: Iterable<string>;\n hash?: string;\n contentHash?: { javascript?: string };\n canBeInitial?: () => boolean;\n }>;\n outputOptions: {\n path?: string;\n };\n assets: Record<string, unknown>;\n getAssets: () => WebpackAsset[];\n getAsset: (name: string) => WebpackAsset | undefined;\n updateAsset: (name: string, source: WebpackSource) => void;\n deleteAsset: (name: string) => void;\n hooks: {\n processAssets: {\n tap: (\n options: { name: string; stage: number },\n callback: (assets: Record<string, WebpackSource>) => void,\n ) => void;\n tapPromise: (options: { name: string; stage: number }, callback: () => Promise<void>) => void;\n };\n };\n};\n\ntype HtmlTagObject = {\n tagName: string;\n voidTag: boolean;\n attributes: Record<string, string | boolean>;\n meta: Record<string, unknown>;\n innerHTML?: string;\n};\n\n// The part of `html-webpack-plugin`'s API (v4 and later) that the plugin uses. Found among the\n// configured plugins instead of imported, because it is an optional dependency of the user.\ntype HtmlWebpackPluginClass = {\n getHooks: (compilation: WebpackCompilation) => {\n alterAssetTagGroups: {\n tap: (name: string, callback: <T extends { headTags: HtmlTagObject[] }>(data: T) => T) => void;\n };\n };\n};\n\nfunction findHtmlWebpackPlugin(compiler: WebpackCompiler): HtmlWebpackPluginClass | undefined {\n for (const plugin of compiler.options.plugins ?? []) {\n const pluginClass = (plugin as { constructor?: { name?: string; getHooks?: unknown } } | undefined)?.constructor;\n if (pluginClass?.name === 'HtmlWebpackPlugin' && typeof pluginClass.getHooks === 'function') {\n return pluginClass as HtmlWebpackPluginClass;\n }\n }\n return undefined;\n}\n\n/**\n * Maps webpack's `devtool` onto the plugin's source map kinds. A user who sets `devtool: false`\n * and adds a `SourceMapDevToolPlugin` manages source maps themselves.\n */\nfunction sourceMapKindFromDevtool(compiler: WebpackCompiler): SourceMapKind | undefined {\n const devtool = compiler.options.devtool;\n\n if (devtool === undefined) {\n return 'unset';\n }\n if (devtool === false) {\n const hasSourceMapPlugin = compiler.options.plugins?.some(\n plugin =>\n (plugin as { constructor?: { name?: string } } | undefined)?.constructor?.name === 'SourceMapDevToolPlugin',\n );\n return hasSourceMapPlugin ? undefined : 'off';\n }\n // Plain `eval` has no source maps at all.\n if (!devtool.includes('source-map')) {\n return 'off';\n }\n if (devtool.includes('inline') || devtool.includes('eval')) {\n return 'inline';\n }\n if (devtool.includes('hidden')) {\n return 'hidden';\n }\n return 'visible';\n}\n\ntype WebpackModule = {\n version?: string;\n default?: { version?: string };\n};\n\n// Only used for telemetry; `webpack` is an optional peer dependency and may be absent (e.g. rspack).\nfunction getWebpackMajorVersion(): string | undefined {\n try {\n const webpack = _req('webpack') as WebpackModule;\n const version = webpack.version ?? webpack.default?.version;\n return version?.split('.')[0];\n } catch {\n return undefined;\n }\n}\n\n/**\n * Stamps each JS asset's debug ID into the asset itself and its source map asset.\n *\n * Runs after source maps have been generated, so the JS asset no longer needs to carry\n * source map information and can be replaced with a plain `RawSource`.\n */\nfunction addDebugIdsToAssets(compilation: WebpackCompilation, RawSource: WebpackRawSource): void {\n for (const asset of compilation.getAssets()) {\n if (!isJsFile(asset.name)) {\n continue;\n }\n\n const bundleSource = asset.source.source().toString();\n const relatedSourceMap = asset.info.related?.sourceMap;\n const sourceMapName = typeof relatedSourceMap === 'string' ? relatedSourceMap : `${asset.name}.map`;\n const sourceMapAsset = compilation.getAsset(sourceMapName);\n\n const stamped = stampDebugId(bundleSource, sourceMapAsset?.source.source().toString());\n if (!stamped) {\n continue;\n }\n\n compilation.updateAsset(asset.name, new RawSource(stamped.bundleSource));\n if (stamped.sourceMapSource !== undefined) {\n compilation.updateAsset(sourceMapName, new RawSource(stamped.sourceMapSource));\n }\n }\n}\n\n/** Drops a source map asset and its compressed variants from the compilation. */\nfunction deleteSourceMapAssets(compilation: WebpackCompilation, sourceMapName: string): void {\n for (const candidate of compilation.getAssets()) {\n if (candidate.name === sourceMapName || candidate.name.startsWith(`${sourceMapName}.`)) {\n compilation.deleteAsset(candidate.name);\n }\n }\n}\n\n/**\n * Drops the source maps of the JS assets that an upload would include. With `removeAll` it drops\n * the source maps of all assets, CSS included.\n */\nfunction dropSourceMaps(compilation: WebpackCompilation, shouldUpload: UploadFilter, removeAll: boolean): void {\n const outputPath = compilation.outputOptions.path ?? path.resolve();\n\n for (const asset of compilation.getAssets()) {\n if (!removeAll && (!isJsFile(asset.name) || !shouldUpload(path.join(outputPath, asset.name)))) {\n continue;\n }\n const relatedSourceMap = asset.info.related?.sourceMap;\n const sourceMapName = typeof relatedSourceMap === 'string' ? relatedSourceMap : `${asset.name}.map`;\n if (compilation.getAsset(sourceMapName)) {\n deleteSourceMapAssets(compilation, sourceMapName);\n }\n }\n}\n\n/**\n * Copies each JS asset and its source map into the upload staging folder and drops the source map\n * assets (and their compressed variants) from the compilation, so webpack never emits them.\n *\n * A map the plugin or the SDK turned on (`pluginEnabledMaps`) never reaches the output, whether or\n * not its asset is uploaded. That covers CSS maps, which `devtool` turns on along with the JS ones.\n * A map the user enabled stays unless it was staged.\n */\nasync function stageSourceMaps(\n compilation: WebpackCompilation,\n staging: UploadStaging,\n logger: { warn: (message: string) => void },\n pluginEnabledMaps: boolean,\n): Promise<void> {\n const outputPath = compilation.outputOptions.path ?? path.resolve();\n\n for (const asset of compilation.getAssets()) {\n const relatedSourceMap = asset.info.related?.sourceMap;\n const sourceMapName = typeof relatedSourceMap === 'string' ? relatedSourceMap : `${asset.name}.map`;\n const sourceMapAsset = compilation.getAsset(sourceMapName);\n if (!sourceMapAsset) {\n continue;\n }\n\n if (!isJsFile(asset.name)) {\n if (pluginEnabledMaps) {\n deleteSourceMapAssets(compilation, sourceMapName);\n }\n continue;\n }\n\n const result = await staging.stage({\n code: asset.source.source().toString(),\n mapSource: sourceMapAsset.source.source().toString(),\n mapDir: path.join(outputPath, path.dirname(sourceMapName)),\n chunkPath: path.join(outputPath, asset.name),\n });\n\n if (result === 'skipped' || result === 'failed') {\n logger.warn(\n pluginEnabledMaps\n ? `Could not prepare ${asset.name} for upload, so it is not uploaded and its source map ${sourceMapName} was removed from the build output.`\n : `Could not prepare ${asset.name} for upload, so its source map ${sourceMapName} stays in the build output.`,\n );\n }\n if (result === 'staged' || pluginEnabledMaps) {\n deleteSourceMapAssets(compilation, sourceMapName);\n }\n }\n}\n\nfunction createSentryWebpackPlugin(userOptions: SentryWebpackPluginInternalOptions = {}) {\n const sentryBuildPluginManager = createSentryBuildPluginManager(userOptions, {\n loggerPrefix: userOptions._metaOptions?.loggerPrefixOverride ?? '[sentry-webpack-plugin]',\n buildTool: 'webpack',\n buildToolMajorVersion: getWebpackMajorVersion(),\n });\n\n const {\n logger,\n normalizedOptions: options,\n bundleSizeOptimizationReplacementValues: replacementValues,\n bundleMetadata,\n createDependencyOnBuildArtifacts,\n } = sentryBuildPluginManager;\n\n if (options.disable) {\n return {\n apply() {\n // noop plugin\n },\n };\n }\n\n if (process.cwd().match(/\\\\node_modules\\\\|\\/node_modules\\//)) {\n logger.warn('Running Sentry plugin from within a `node_modules` folder. Some features may not work.');\n }\n\n const { injectDebugIds, upload: uploadEnabled, stampEmittedFiles } = getSourceMapFeatures(options);\n const releaseInjectionCode = new CodeInjection();\n const chunkInjectionCode = new CodeInjection();\n\n if (!options.release.inject) {\n logger.debug('Release injection disabled via `release.inject` option. Will not inject release.');\n } else if (!options.release.name) {\n logger.debug(\n 'No release name provided. Will not inject release. Please set the `release.name` option to identify your release.',\n );\n } else {\n releaseInjectionCode.append(\n generateReleaseInjectorCode({\n release: options.release.name,\n injectBuildInformation: options._experiments.injectBuildInformation || false,\n }),\n );\n }\n\n if (Object.keys(bundleMetadata).length > 0) {\n chunkInjectionCode.append(generateModuleMetadataInjectorCode(bundleMetadata));\n }\n\n const transformAnnotations = options.reactComponentAnnotation?.enabled\n ? createComponentNameAnnotateHooks(\n options.reactComponentAnnotation?.ignoredComponents || [],\n !!options.reactComponentAnnotation?._experimentalInjectIntoHtml,\n { logger },\n )\n : undefined;\n\n const transformReplace = Object.keys(replacementValues).length > 0;\n\n function decideSourceMaps(compiler: WebpackCompiler): { kind?: SourceMapKind; decision: SourceMapDecision } {\n const kind = compiler.options.mode === 'development' ? undefined : sourceMapKindFromDevtool(compiler);\n if (kind === undefined) {\n return { decision: { enableHidden: false, deleteAfterUpload: false } };\n }\n\n const decision = sentryBuildPluginManager.sourceMaps.decide(kind);\n\n if (decision.enableHidden) {\n compiler.options.devtool = kind === 'visible' ? `hidden-${compiler.options.devtool}` : 'hidden-source-map';\n }\n\n return { kind, decision };\n }\n\n /**\n * Adds the release snippet to the `<head>` of every page that `html-webpack-plugin` generates.\n * Returns `false` when the build has no `html-webpack-plugin`.\n */\n function addReleaseToHtml(compiler: WebpackCompiler): boolean {\n const HtmlWebpackPlugin = findHtmlWebpackPlugin(compiler);\n if (!HtmlWebpackPlugin) {\n logger.warn(\n \"`release.inject: 'html'` needs `html-webpack-plugin` to generate the HTML, and this build does not use it. Injecting the release into the startup chunks instead.\",\n );\n return false;\n }\n\n const tag: HtmlTagObject = {\n tagName: 'script',\n voidTag: false,\n attributes: {},\n meta: { plugin: 'sentry-webpack-plugin' },\n innerHTML: releaseInjectionCode.code(),\n };\n\n // All instances of the plugin share the hooks of a compilation, so one tap covers every page.\n compiler.hooks.thisCompilation.tap('sentry-webpack-plugin', compilation => {\n HtmlWebpackPlugin.getHooks(compilation).alterAssetTagGroups.tap('sentry-webpack-plugin', data => {\n data.headTags.unshift(tag);\n return data;\n });\n });\n return true;\n }\n\n function addCodeInjection(compiler: WebpackCompiler, injectRelease: boolean): void {\n if ((!injectRelease || releaseInjectionCode.isEmpty()) && chunkInjectionCode.isEmpty() && !injectDebugIds) {\n return;\n }\n\n const ReplaceSource = compiler.webpack?.sources?.ReplaceSource;\n const processAssetsStage = compiler.webpack?.Compilation?.PROCESS_ASSETS_STAGE_ADDITIONS;\n\n if (!ReplaceSource || processAssetsStage === undefined) {\n logger.warn(\n 'Webpack sources are not available. Skipping code injection. This usually means webpack is not properly configured.',\n );\n return;\n }\n\n compiler.hooks.compilation.tap('sentry-webpack-plugin-injection', compilation => {\n compilation.hooks.processAssets.tap(\n {\n name: 'sentry-webpack-plugin-injection',\n stage: processAssetsStage,\n },\n assets => {\n const injectedAssets = new Set<string>();\n\n for (const chunk of compilation.chunks) {\n for (const assetName of chunk.files) {\n if (injectedAssets.has(assetName) || !WEBPACK_JAVASCRIPT_ASSET_REGEX.test(assetName)) {\n continue;\n }\n\n const source = assets[assetName];\n if (!source) {\n continue;\n }\n injectedAssets.add(assetName);\n\n const sourceContents = source.source();\n const code = typeof sourceContents === 'string' ? sourceContents : Buffer.from(sourceContents).toString();\n const codeToInject = new CodeInjection();\n if (injectRelease && (chunk.canBeInitial?.() ?? true)) {\n codeToInject.append(releaseInjectionCode);\n }\n codeToInject.append(chunkInjectionCode);\n if (injectDebugIds) {\n const hash = chunk.contentHash?.javascript ?? chunk.hash;\n codeToInject.append(getDebugIdSnippet(hash ? stringToUUID(hash) : randomUUID()));\n }\n\n const injectionPosition = getCodeInjectionPosition(code);\n const injection = injectionPosition === code.length ? `\\n${codeToInject.code()}` : codeToInject.code();\n const updatedSource = new ReplaceSource(source);\n updatedSource.insert(injectionPosition, injection);\n compilation.updateAsset(assetName, updatedSource);\n }\n }\n },\n );\n });\n }\n\n return {\n apply(compiler: WebpackCompiler) {\n void sentryBuildPluginManager.telemetry.emitBundlerPluginExecutionSignal().catch(() => {\n // Telemetry failures are acceptable\n });\n\n const { DefinePlugin } = compiler.webpack ?? {};\n\n // One plugin instance can serve several compilers (`MultiCompiler`) and\n // a compiler several compilations (watch mode), so nothing is shared.\n const { decision: sourceMapDecision } = decideSourceMaps(compiler);\n const removeAllSourceMaps = sourceMapDecision.removeAllSourceMaps === true;\n const pendingStagings = new Map<WebpackCompilation, UploadStaging>();\n\n // After `RealContentHashPlugin` rewrote the hash placeholders, so the staged\n // JS equals the emitted file and `[contenthash]` names are final.\n const deleteStage = (compiler.webpack?.Compilation?.PROCESS_ASSETS_STAGE_REPORT ?? 5000) + 1;\n\n if (sourceMapDecision.deleteAfterUpload && !sentryBuildPluginManager.sourceMaps.uploadPossible) {\n compiler.hooks.thisCompilation.tap('sentry-webpack-plugin', compilation => {\n compilation.hooks.processAssets.tap({ name: 'sentry-webpack-plugin', stage: deleteStage }, () => {\n dropSourceMaps(compilation, sentryBuildPluginManager.sourceMaps.shouldUpload, removeAllSourceMaps);\n });\n });\n } else if (sourceMapDecision.deleteAfterUpload) {\n compiler.hooks.thisCompilation.tap('sentry-webpack-plugin', compilation => {\n compilation.hooks.processAssets.tapPromise(\n { name: 'sentry-webpack-plugin', stage: deleteStage },\n async () => {\n const staging = await sentryBuildPluginManager.createUploadStaging();\n pendingStagings.set(compilation, staging);\n await stageSourceMaps(compilation, staging, logger, removeAllSourceMaps);\n },\n );\n });\n\n // A staging that `afterEmit` never took belongs to a compilation that\n // failed before emitting, or to one whose assets were emitted without\n // their maps because an earlier `afterEmit` tap failed. Only the\n // second kind has no other copy of the maps.\n const emittedCompilations = new Set<WebpackCompilation>();\n compiler.hooks.emit.tap('sentry-webpack-plugin', compilation => {\n emittedCompilations.add(compilation);\n });\n const settlePendingStagings = (): void => {\n for (const [compilation, staging] of pendingStagings) {\n if (emittedCompilations.has(compilation)) {\n void staging.keep('The source map upload did not run.');\n } else {\n void staging.discard();\n }\n }\n pendingStagings.clear();\n emittedCompilations.clear();\n };\n compiler.hooks.done.tap('sentry-webpack-plugin', settlePendingStagings);\n compiler.hooks.failed?.tap('sentry-webpack-plugin', settlePendingStagings);\n }\n\n const releaseInHtml =\n options.release.inject === 'html' && !releaseInjectionCode.isEmpty() && addReleaseToHtml(compiler);\n\n // BannerPlugin prepends executable code before directive prologues.\n addCodeInjection(compiler, !releaseInHtml);\n\n if (stampEmittedFiles) {\n const RawSource = compiler.webpack?.sources?.RawSource;\n // Right after source map generation (and thus after minification, which would strip the comment),\n // so later stages (real content hashing, subresource integrity) see the final assets.\n const stage = (compiler.webpack?.Compilation?.PROCESS_ASSETS_STAGE_DEV_TOOLING ?? 500) + 1;\n\n if (!RawSource) {\n logger.warn(\n 'Webpack sources are not available. Skipping debug ID injection into emitted source maps. This usually means webpack is not properly configured.',\n );\n } else {\n compiler.hooks.thisCompilation.tap('sentry-webpack-plugin', compilation => {\n compilation.hooks.processAssets.tap({ name: 'sentry-webpack-plugin', stage }, () => {\n addDebugIdsToAssets(compilation, RawSource);\n });\n });\n }\n }\n\n // Add DefinePlugin for bundle size optimizations\n if (transformReplace && DefinePlugin) {\n compiler.options.plugins = compiler.options.plugins || [];\n compiler.options.plugins.push(new DefinePlugin(replacementValues));\n }\n\n // Add component name annotation transform\n if (transformAnnotations?.transform) {\n compiler.options.module = compiler.options.module || {};\n compiler.options.module.rules = compiler.options.module.rules || [];\n compiler.options.module.rules.unshift({\n test: /\\.[jt]sx$/,\n exclude: /node_modules/,\n enforce: 'pre',\n use: [\n {\n loader: COMPONENT_ANNOTATION_LOADER,\n options: {\n transform: transformAnnotations.transform,\n },\n },\n ],\n });\n }\n\n compiler.hooks.afterEmit.tapAsync(\n 'sentry-webpack-plugin',\n (compilation: WebpackCompilation, callback: (err?: Error) => void) => {\n const freeGlobalDependencyOnBuildArtifacts = createDependencyOnBuildArtifacts();\n const upload = createDebugIdUploadFunction({ sentryBuildPluginManager });\n\n const staging = pendingStagings.get(compilation);\n pendingStagings.delete(compilation);\n let stagingHandedOver = false;\n\n const run = async (): Promise<void> => {\n try {\n await sentryBuildPluginManager.createRelease();\n if (uploadEnabled) {\n const outputPath = compilation.outputOptions.path ?? path.resolve();\n const buildArtifacts = Object.keys(compilation.assets).map(asset => path.join(outputPath, asset));\n stagingHandedOver = true;\n await upload(buildArtifacts, { staging });\n } else {\n stagingHandedOver = true;\n await staging?.discard();\n }\n } catch (e) {\n if (!stagingHandedOver) {\n await staging?.keep('The source map upload did not run.');\n }\n throw e;\n } finally {\n freeGlobalDependencyOnBuildArtifacts();\n await sentryBuildPluginManager.deleteArtifacts();\n }\n };\n\n run().then(\n () => callback(),\n (err: Error) => callback(err),\n );\n },\n );\n\n if (userOptions._experiments?.forceExitOnBuildCompletion && compiler.options.mode === 'production') {\n compiler.hooks.done.tap('sentry-webpack-plugin', () => {\n setTimeout(() => {\n logger.debug('Exiting process after debug file upload');\n process.exit(0);\n });\n });\n }\n },\n };\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const sentryWebpackPlugin: (options?: SentryWebpackPluginInternalOptions) => any = createSentryWebpackPlugin;\n\n/** @internal For Sentry SDK packages only. See `InternalOptions`. */\nexport type SentryWebpackPluginInternalOptions = InternalOptions & WebpackExperiments;\n\nexport type SentryWebpackPluginOptions = Options & WebpackExperiments;\n\ntype WebpackExperiments = {\n _experiments?: Options['_experiments'] & {\n /**\n * If enabled, the webpack plugin will exit the build process after the build completes.\n * Use this with caution, as it will terminate the process.\n *\n * More information: https://github.com/getsentry/sentry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,UAAU,SACvB,0BACC,aAAiC,aAAoC;GACpE,MAAM,uCAAuC,iCAAiC;GAC9E,MAAM,SAASC,wBAAAA,4BAA4B,EAAE,yBAAyB,CAAC;GAEvE,MAAM,UAAU,gBAAgB,IAAI,WAAW;GAC/C,gBAAgB,OAAO,WAAW;GAClC,IAAI,oBAAoB;GAExB,MAAM,MAAM,YAA2B;IACrC,IAAI;KACF,MAAM,yBAAyB,cAAc;KAC7C,IAAI,eAAe;MACjB,MAAM,aAAa,YAAY,cAAc,QAAQd,UAAK,QAAQ;MAClE,MAAM,iBAAiB,OAAO,KAAK,YAAY,MAAM,CAAC,CAAC,KAAI,UAASA,UAAK,KAAK,YAAY,KAAK,CAAC;MAChG,oBAAoB;MACpB,MAAM,OAAO,gBAAgB,EAAE,QAAQ,CAAC;KAC1C,OAAO;MACL,oBAAoB;MACpB,MAAM,SAAS,QAAQ;KACzB;IACF,SAAS,GAAG;KACV,IAAI,CAAC,mBACH,MAAM,SAAS,KAAK,oCAAoC;KAE1D,MAAM;IACR,UAAU;KACR,qCAAqC;KACrC,MAAM,yBAAyB,gBAAgB;IACjD;GACF;GAEA,IAAI,CAAC,CAAC,WACE,SAAS,IACd,QAAe,SAAS,GAAG,CAC9B;EACF,CACF;EAEA,IAAI,YAAY,cAAc,8BAA8B,SAAS,QAAQ,SAAS,cACpF,SAAS,MAAM,KAAK,IAAI,+BAA+B;GACrD,iBAAiB;IACf,OAAO,MAAM,yCAAyC;IACtD,QAAQ,KAAK,CAAC;GAChB,CAAC;EACH,CAAC;CAEL,EACF;AACF;AAGA,MAAa,sBAA6E"}
|
package/build/esm/bun/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import "../_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { CodeInjection, generateModuleMetadataInjectorCode, generateReleaseInjectorCode } from "../core/utils.js";
|
|
3
3
|
import { createDebugIdUploadFunction } from "../core/debug-id-upload.js";
|
|
4
|
+
import { getSourceMapFeatures } from "../core/sourcemap-settings.js";
|
|
4
5
|
import { createSentryBuildPluginManager } from "../core/build-plugin-manager.js";
|
|
5
6
|
import { getDebugIdSnippet } from "../core/index.js";
|
|
6
7
|
import * as fs from "node:fs";
|
|
@@ -23,7 +24,10 @@ function sentryBunPlugin(userOptions = {}) {
|
|
|
23
24
|
name: "sentry-bun-noop-plugin",
|
|
24
25
|
setup: () => void 0
|
|
25
26
|
};
|
|
27
|
+
const sourceMapFeatures = getSourceMapFeatures(options);
|
|
28
|
+
if (options.sourcemaps?.delete !== void 0) logger.warn("The Sentry Bun plugin does not support `sourcemaps.delete`. It removes no source maps.");
|
|
26
29
|
const staticInjectionCode = new CodeInjection();
|
|
30
|
+
if (options.release.inject === "html") logger.warn("`release.inject: 'html'` is not supported by the Bun plugin. Injecting the release into the startup chunks instead.");
|
|
27
31
|
if (!options.release.inject) logger.debug("Release injection disabled via `release.inject` option. Will not inject release.");
|
|
28
32
|
else if (!options.release.name) logger.debug("No release name provided. Will not inject release. Please set the `release.name` option to identify your release.");
|
|
29
33
|
else staticInjectionCode.append(generateReleaseInjectorCode({
|
|
@@ -46,7 +50,7 @@ function sentryBunPlugin(userOptions = {}) {
|
|
|
46
50
|
setup(build) {
|
|
47
51
|
const config = build.config;
|
|
48
52
|
if (!config) return;
|
|
49
|
-
const injectDebugIds =
|
|
53
|
+
const injectDebugIds = sourceMapFeatures.injectDebugIds && !!config.outdir && !!config.sourcemap && config.sourcemap !== "none";
|
|
50
54
|
const injectionCode = new CodeInjection();
|
|
51
55
|
injectionCode.append(staticInjectionCode);
|
|
52
56
|
if (injectDebugIds) injectionCode.append(getDebugIdSnippet(DEBUG_ID_PLACEHOLDER));
|
|
@@ -69,7 +73,7 @@ function sentryBunPlugin(userOptions = {}) {
|
|
|
69
73
|
if (injectDebugIds) {
|
|
70
74
|
const bundlePaths = result.outputs.filter((output) => output.kind === "entry-point" || output.kind === "chunk").map((output) => output.path);
|
|
71
75
|
await Promise.all(bundlePaths.map(replaceDebugIdPlaceholder));
|
|
72
|
-
if (
|
|
76
|
+
if (sourceMapFeatures.upload) await upload(bundlePaths);
|
|
73
77
|
}
|
|
74
78
|
} finally {
|
|
75
79
|
freeGlobalDependencyOnBuildArtifacts();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/bun/index.ts"],"sourcesContent":["import type { Options } from '../core';\nimport {\n createSentryBuildPluginManager,\n generateReleaseInjectorCode,\n generateModuleMetadataInjectorCode,\n getDebugIdSnippet,\n createDebugIdUploadFunction,\n CodeInjection,\n} from '../core';\nimport * as fs from 'node:fs';\n\ninterface BunBuildArtifact {\n path: string;\n kind: string;\n}\n\ninterface BunBuildConfig {\n banner?: string;\n sourcemap?: 'none' | 'linked' | 'inline' | 'external' | boolean;\n outdir?: string;\n define?: Record<string, string>;\n}\n\ninterface BunPluginBuilder {\n // Bun passes no `config` when the plugin runs as a runtime plugin (`Bun.plugin()`)\n config?: BunBuildConfig;\n onEnd: (callback: (result: { outputs: BunBuildArtifact[] }) => void | Promise<void>) => void;\n}\n\ninterface BunPlugin {\n name: string;\n setup: (build: BunPluginBuilder) => void;\n}\n\nconst pluginName = 'sentry-bun-plugin';\n\n// Bun computes the debug ID of an output after it adds the banner, so the\n// banner holds this placeholder. It has the length of a debug ID, so the\n// swap does not move any code that the source map points to.\nconst DEBUG_ID_PLACEHOLDER = 'sentry-bun-debug-id-placeholder-0000';\n// Bun writes `//# sourceMappingURL=` after this comment for linked and\n// inline source maps, so match the last debug ID line, not the file end.\nconst BUN_DEBUG_ID_REGEX = /^\\/\\/# debugId=([0-9a-fA-F]{32})$(?![\\s\\S]*^\\/\\/# debugId=)/m;\n\nfunction bunDebugIdToUuid(bunDebugId: string): string {\n const hex = bunDebugId.toLowerCase();\n return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;\n}\n\nexport function sentryBunPlugin(userOptions: Options = {}): BunPlugin {\n const sentryBuildPluginManager = createSentryBuildPluginManager(userOptions, {\n loggerPrefix: userOptions._metaOptions?.loggerPrefixOverride ?? `[${pluginName}]`,\n buildTool: 'bun',\n buildToolMajorVersion: process.versions['bun']?.split('.')[0],\n });\n\n const {\n logger,\n normalizedOptions: options,\n bundleSizeOptimizationReplacementValues: replacementValues,\n bundleMetadata,\n createDependencyOnBuildArtifacts,\n } = sentryBuildPluginManager;\n\n if (options.disable) {\n return { name: 'sentry-bun-noop-plugin', setup: () => undefined };\n }\n\n const staticInjectionCode = new CodeInjection();\n\n if (!options.release.inject) {\n logger.debug('Release injection disabled via `release.inject` option. Will not inject release.');\n } else if (!options.release.name) {\n logger.debug(\n 'No release name provided. Will not inject release. Please set the `release.name` option to identify your release.',\n );\n } else {\n staticInjectionCode.append(\n generateReleaseInjectorCode({\n release: options.release.name,\n injectBuildInformation: options._experiments.injectBuildInformation || false,\n }),\n );\n }\n\n if (Object.keys(bundleMetadata).length > 0) {\n staticInjectionCode.append(generateModuleMetadataInjectorCode(bundleMetadata));\n }\n\n void sentryBuildPluginManager.telemetry.emitBundlerPluginExecutionSignal().catch(() => {\n // Telemetry failures are acceptable\n });\n\n async function replaceDebugIdPlaceholder(bundlePath: string): Promise<void> {\n const source = await fs.promises.readFile(bundlePath, 'utf8');\n const bunDebugId = source.match(BUN_DEBUG_ID_REGEX)?.[1];\n if (!bunDebugId) {\n logger.debug(`Bun wrote no debug ID into the bundle. File will not be source mapped: ${bundlePath}`);\n return;\n }\n\n await fs.promises.writeFile(\n bundlePath,\n source.split(DEBUG_ID_PLACEHOLDER).join(bunDebugIdToUuid(bunDebugId)),\n 'utf8',\n );\n }\n\n return {\n name: pluginName,\n setup(build: BunPluginBuilder): void {\n const config = build.config;\n if (!config) {\n return;\n }\n\n // Without `outdir`, Bun writes no files that the placeholder can be\n // replaced in.\n const injectDebugIds =\n
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/bun/index.ts"],"sourcesContent":["import type { Options } from '../core';\nimport {\n createSentryBuildPluginManager,\n generateReleaseInjectorCode,\n generateModuleMetadataInjectorCode,\n getDebugIdSnippet,\n createDebugIdUploadFunction,\n CodeInjection,\n getSourceMapFeatures,\n} from '../core';\nimport * as fs from 'node:fs';\n\ninterface BunBuildArtifact {\n path: string;\n kind: string;\n}\n\ninterface BunBuildConfig {\n banner?: string;\n sourcemap?: 'none' | 'linked' | 'inline' | 'external' | boolean;\n outdir?: string;\n define?: Record<string, string>;\n}\n\ninterface BunPluginBuilder {\n // Bun passes no `config` when the plugin runs as a runtime plugin (`Bun.plugin()`)\n config?: BunBuildConfig;\n onEnd: (callback: (result: { outputs: BunBuildArtifact[] }) => void | Promise<void>) => void;\n}\n\ninterface BunPlugin {\n name: string;\n setup: (build: BunPluginBuilder) => void;\n}\n\nconst pluginName = 'sentry-bun-plugin';\n\n// Bun computes the debug ID of an output after it adds the banner, so the\n// banner holds this placeholder. It has the length of a debug ID, so the\n// swap does not move any code that the source map points to.\nconst DEBUG_ID_PLACEHOLDER = 'sentry-bun-debug-id-placeholder-0000';\n// Bun writes `//# sourceMappingURL=` after this comment for linked and\n// inline source maps, so match the last debug ID line, not the file end.\nconst BUN_DEBUG_ID_REGEX = /^\\/\\/# debugId=([0-9a-fA-F]{32})$(?![\\s\\S]*^\\/\\/# debugId=)/m;\n\nfunction bunDebugIdToUuid(bunDebugId: string): string {\n const hex = bunDebugId.toLowerCase();\n return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;\n}\n\nexport function sentryBunPlugin(userOptions: Options = {}): BunPlugin {\n const sentryBuildPluginManager = createSentryBuildPluginManager(userOptions, {\n loggerPrefix: userOptions._metaOptions?.loggerPrefixOverride ?? `[${pluginName}]`,\n buildTool: 'bun',\n buildToolMajorVersion: process.versions['bun']?.split('.')[0],\n });\n\n const {\n logger,\n normalizedOptions: options,\n bundleSizeOptimizationReplacementValues: replacementValues,\n bundleMetadata,\n createDependencyOnBuildArtifacts,\n } = sentryBuildPluginManager;\n\n if (options.disable) {\n return { name: 'sentry-bun-noop-plugin', setup: () => undefined };\n }\n\n const sourceMapFeatures = getSourceMapFeatures(options);\n if (options.sourcemaps?.delete !== undefined) {\n logger.warn('The Sentry Bun plugin does not support `sourcemaps.delete`. It removes no source maps.');\n }\n\n const staticInjectionCode = new CodeInjection();\n\n if (options.release.inject === 'html') {\n logger.warn(\n \"`release.inject: 'html'` is not supported by the Bun plugin. Injecting the release into the startup chunks instead.\",\n );\n }\n\n if (!options.release.inject) {\n logger.debug('Release injection disabled via `release.inject` option. Will not inject release.');\n } else if (!options.release.name) {\n logger.debug(\n 'No release name provided. Will not inject release. Please set the `release.name` option to identify your release.',\n );\n } else {\n staticInjectionCode.append(\n generateReleaseInjectorCode({\n release: options.release.name,\n injectBuildInformation: options._experiments.injectBuildInformation || false,\n }),\n );\n }\n\n if (Object.keys(bundleMetadata).length > 0) {\n staticInjectionCode.append(generateModuleMetadataInjectorCode(bundleMetadata));\n }\n\n void sentryBuildPluginManager.telemetry.emitBundlerPluginExecutionSignal().catch(() => {\n // Telemetry failures are acceptable\n });\n\n async function replaceDebugIdPlaceholder(bundlePath: string): Promise<void> {\n const source = await fs.promises.readFile(bundlePath, 'utf8');\n const bunDebugId = source.match(BUN_DEBUG_ID_REGEX)?.[1];\n if (!bunDebugId) {\n logger.debug(`Bun wrote no debug ID into the bundle. File will not be source mapped: ${bundlePath}`);\n return;\n }\n\n await fs.promises.writeFile(\n bundlePath,\n source.split(DEBUG_ID_PLACEHOLDER).join(bunDebugIdToUuid(bunDebugId)),\n 'utf8',\n );\n }\n\n return {\n name: pluginName,\n setup(build: BunPluginBuilder): void {\n const config = build.config;\n if (!config) {\n return;\n }\n\n // Without `outdir`, Bun writes no files that the placeholder can be\n // replaced in.\n const injectDebugIds =\n sourceMapFeatures.injectDebugIds && !!config.outdir && !!config.sourcemap && config.sourcemap !== 'none';\n\n const injectionCode = new CodeInjection();\n injectionCode.append(staticInjectionCode);\n if (injectDebugIds) {\n injectionCode.append(getDebugIdSnippet(DEBUG_ID_PLACEHOLDER));\n }\n\n if (!injectionCode.isEmpty()) {\n config.banner = config.banner ? `${config.banner}\\n${injectionCode.code()}` : injectionCode.code();\n }\n\n if (Object.keys(replacementValues).length > 0) {\n const replacementStringValues: Record<string, string> = {};\n Object.entries(replacementValues).forEach(([key, value]) => {\n replacementStringValues[key] = JSON.stringify(value);\n });\n\n config.define = { ...config.define, ...replacementStringValues };\n }\n\n const freeGlobalDependencyOnBuildArtifacts = createDependencyOnBuildArtifacts();\n const upload = createDebugIdUploadFunction({ sentryBuildPluginManager });\n\n build.onEnd(async result => {\n try {\n await sentryBuildPluginManager.createRelease();\n\n if (injectDebugIds) {\n const bundlePaths = result.outputs\n .filter(output => output.kind === 'entry-point' || output.kind === 'chunk')\n .map(output => output.path);\n\n await Promise.all(bundlePaths.map(replaceDebugIdPlaceholder));\n\n if (sourceMapFeatures.upload) {\n await upload(bundlePaths);\n }\n }\n } finally {\n freeGlobalDependencyOnBuildArtifacts();\n await sentryBuildPluginManager.deleteArtifacts();\n }\n });\n },\n };\n}\n\nexport default sentryBunPlugin;\nexport type { Options as SentryBunPluginOptions } from '../core';\n"],"mappings":";;;;;;;;AAmCA,MAAM,aAAa;AAKnB,MAAM,uBAAuB;AAG7B,MAAM,qBAAqB;AAE3B,SAAS,iBAAiB,YAA4B;CACpD,MAAM,MAAM,WAAW,YAAY;CACnC,OAAO,GAAG,IAAI,MAAM,GAAG,CAAC,EAAE,GAAG,IAAI,MAAM,GAAG,EAAE,EAAE,GAAG,IAAI,MAAM,IAAI,EAAE,EAAE,GAAG,IAAI,MAAM,IAAI,EAAE,EAAE,GAAG,IAAI,MAAM,EAAE;AACzG;AAEA,SAAgB,gBAAgB,cAAuB,CAAC,GAAc;CACpE,MAAM,2BAA2B,+BAA+B,aAAa;EAC3E,cAAc,YAAY,cAAc,wBAAwB,IAAI,WAAW;EAC/E,WAAW;EACX,uBAAu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C,OAAO,aAAa,OAAO,cAAc;GAEpG,MAAM,gBAAgB,IAAI,cAAc;GACxC,cAAc,OAAO,mBAAmB;GACxC,IAAI,gBACF,cAAc,OAAO,kBAAkB,oBAAoB,CAAC;GAG9D,IAAI,CAAC,cAAc,QAAQ,GACzB,OAAO,SAAS,OAAO,SAAS,GAAG,OAAO,OAAO,IAAI,cAAc,KAAK,MAAM,cAAc,KAAK;GAGnG,IAAI,OAAO,KAAK,iBAAiB,CAAC,CAAC,SAAS,GAAG;IAC7C,MAAM,0BAAkD,CAAC;IACzD,OAAO,QAAQ,iBAAiB,CAAC,CAAC,SAAS,CAAC,KAAK,WAAW;KAC1D,wBAAwB,OAAO,KAAK,UAAU,KAAK;IACrD,CAAC;IAED,OAAO,SAAS;KAAE,GAAG,OAAO;KAAQ,GAAG;IAAwB;GACjE;GAEA,MAAM,uCAAuC,iCAAiC;GAC9E,MAAM,SAAS,4BAA4B,EAAE,yBAAyB,CAAC;GAEvE,MAAM,MAAM,OAAM,WAAU;IAC1B,IAAI;KACF,MAAM,yBAAyB,cAAc;KAE7C,IAAI,gBAAgB;MAClB,MAAM,cAAc,OAAO,QACxB,QAAO,WAAU,OAAO,SAAS,iBAAiB,OAAO,SAAS,OAAO,CAAC,CAC1E,KAAI,WAAU,OAAO,IAAI;MAE5B,MAAM,QAAQ,IAAI,YAAY,IAAI,yBAAyB,CAAC;MAE5D,IAAI,kBAAkB,QACpB,MAAM,OAAO,WAAW;KAE5B;IACF,UAAU;KACR,qCAAqC;KACrC,MAAM,yBAAyB,gBAAgB;IACjD;GACF,CAAC;EACH;CACF;AACF"}
|
|
@@ -5,7 +5,7 @@ import { allowedToSendTelemetry, createSentryInstance, safeFlushTelemetry } from
|
|
|
5
5
|
import { arrayify, getProjects, getTurborepoEnvPassthroughWarning, stripQueryAndHashFromPath } from "./utils.js";
|
|
6
6
|
import { defaultRewriteSourcesHook, prepareArtifactForUpload, prepareBundleForDebugIdUpload, writePreparedArtifact } from "./debug-id-upload.js";
|
|
7
7
|
import { globFiles } from "./glob.js";
|
|
8
|
-
import { decideSourceMapHandling } from "./sourcemap-settings.js";
|
|
8
|
+
import { decideSourceMapHandling, getSourceMapFeatures } from "./sourcemap-settings.js";
|
|
9
9
|
import { createUploadFilter } from "./upload-filter.js";
|
|
10
10
|
import { LIB_VERSION } from "./version.js";
|
|
11
11
|
import * as path from "path";
|
|
@@ -293,6 +293,10 @@ async emitBundlerPluginExecutionSignal() {
|
|
|
293
293
|
}
|
|
294
294
|
},
|
|
295
295
|
async injectDebugIds(buildArtifactPaths) {
|
|
296
|
+
if (!getSourceMapFeatures(options).injectDebugIds) {
|
|
297
|
+
logger.debug("Debug ID injection was disabled. Will not inject debug IDs.");
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
296
300
|
await startSpan({
|
|
297
301
|
name: "inject-debug-ids",
|
|
298
302
|
scope: sentryScope,
|
|
@@ -591,7 +595,7 @@ async function createTempUploadFolder() {
|
|
|
591
595
|
return process.env["SENTRY_TEST_OVERRIDE_TEMP_DIR"] || await fs.promises.mkdtemp(path.join(os.tmpdir(), "sentry-bundler-plugin-upload-"));
|
|
592
596
|
}
|
|
593
597
|
function getSourceMapUploadBlocker(options, isDevMode) {
|
|
594
|
-
if (options.
|
|
598
|
+
if (!getSourceMapFeatures(options).upload) return "disabled";
|
|
595
599
|
if (Array.isArray(options.sourcemaps?.assets) && options.sourcemaps.assets.length === 0) return "no-assets";
|
|
596
600
|
if (isDevMode) return "dev-mode";
|
|
597
601
|
if (!options.authToken) return "no-auth-token";
|