@sentry/bundler-plugins 11.12.0 → 11.14.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.
Files changed (184) hide show
  1. package/build/cjs/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/assertClassBrand.js +6 -0
  2. package/build/cjs/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/checkPrivateRedeclaration.js +5 -0
  3. package/build/cjs/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateFieldGet2.js +6 -0
  4. package/build/cjs/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateFieldInitSpec.js +6 -0
  5. package/build/cjs/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateFieldSet2.js +6 -0
  6. package/build/cjs/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateMethodInitSpec.js +6 -0
  7. package/build/cjs/_virtual/_rolldown/runtime.js +22 -0
  8. package/build/cjs/babel-plugin/component-annotation.js +14 -32
  9. package/build/cjs/babel-plugin/component-annotation.js.map +1 -1
  10. package/build/cjs/babel-plugin/constants.js +140 -122
  11. package/build/cjs/babel-plugin/constants.js.map +1 -1
  12. package/build/cjs/babel-plugin/experimental.js +204 -307
  13. package/build/cjs/babel-plugin/experimental.js.map +1 -1
  14. package/build/cjs/babel-plugin/index.js +315 -437
  15. package/build/cjs/babel-plugin/index.js.map +1 -1
  16. package/build/cjs/bun/index.js +81 -117
  17. package/build/cjs/bun/index.js.map +1 -1
  18. package/build/cjs/core/build-plugin-manager.js +626 -702
  19. package/build/cjs/core/build-plugin-manager.js.map +1 -1
  20. package/build/cjs/core/cli.js +134 -129
  21. package/build/cjs/core/cli.js.map +1 -1
  22. package/build/cjs/core/component-annotate-hooks.js +16 -27
  23. package/build/cjs/core/component-annotate-hooks.js.map +1 -1
  24. package/build/cjs/core/component-annotation-oxc-ast.js +10 -21
  25. package/build/cjs/core/component-annotation-oxc-ast.js.map +1 -1
  26. package/build/cjs/core/component-annotation-oxc-fragments.js +45 -74
  27. package/build/cjs/core/component-annotation-oxc-fragments.js.map +1 -1
  28. package/build/cjs/core/component-annotation-oxc-jsx.js +116 -156
  29. package/build/cjs/core/component-annotation-oxc-jsx.js.map +1 -1
  30. package/build/cjs/core/component-annotation-oxc-walk.js +62 -123
  31. package/build/cjs/core/component-annotation-oxc-walk.js.map +1 -1
  32. package/build/cjs/core/component-annotation-oxc.js +68 -103
  33. package/build/cjs/core/component-annotation-oxc.js.map +1 -1
  34. package/build/cjs/core/debug-id-upload.js +223 -234
  35. package/build/cjs/core/debug-id-upload.js.map +1 -1
  36. package/build/cjs/core/get-code-injection-position.js +59 -74
  37. package/build/cjs/core/get-code-injection-position.js.map +1 -1
  38. package/build/cjs/core/glob.js +9 -7
  39. package/build/cjs/core/glob.js.map +1 -1
  40. package/build/cjs/core/index.js +77 -61
  41. package/build/cjs/core/index.js.map +1 -1
  42. package/build/cjs/core/logger.js +17 -26
  43. package/build/cjs/core/logger.js.map +1 -1
  44. package/build/cjs/core/options-mapping.js +95 -117
  45. package/build/cjs/core/options-mapping.js.map +1 -1
  46. package/build/cjs/core/sentry/telemetry.js +90 -105
  47. package/build/cjs/core/sentry/telemetry.js.map +1 -1
  48. package/build/cjs/core/sentry/transports.js +92 -99
  49. package/build/cjs/core/sentry/transports.js.map +1 -1
  50. package/build/cjs/core/sourcemap-settings.js +98 -61
  51. package/build/cjs/core/sourcemap-settings.js.map +1 -1
  52. package/build/cjs/core/upload-filter.js +41 -46
  53. package/build/cjs/core/upload-filter.js.map +1 -1
  54. package/build/cjs/core/utils.js +228 -221
  55. package/build/cjs/core/utils.js.map +1 -1
  56. package/build/cjs/core/version.js +4 -5
  57. package/build/cjs/core/version.js.map +1 -1
  58. package/build/cjs/esbuild/index.js +183 -213
  59. package/build/cjs/esbuild/index.js.map +1 -1
  60. package/build/cjs/loader-utils/index.js +5 -10
  61. package/build/cjs/rollup/debug-id-injection.js +22 -38
  62. package/build/cjs/rollup/debug-id-injection.js.map +1 -1
  63. package/build/cjs/rollup/debug-id-stamping.js +14 -24
  64. package/build/cjs/rollup/debug-id-stamping.js.map +1 -1
  65. package/build/cjs/rollup/index.js +192 -246
  66. package/build/cjs/rollup/index.js.map +1 -1
  67. package/build/cjs/rollup/source-map-handling.js +151 -175
  68. package/build/cjs/rollup/source-map-handling.js.map +1 -1
  69. package/build/cjs/vite/index.js +19 -21
  70. package/build/cjs/vite/index.js.map +1 -1
  71. package/build/cjs/vite/source-map-hooks.js +112 -89
  72. package/build/cjs/vite/source-map-hooks.js.map +1 -1
  73. package/build/cjs/webpack/component-annotation-transform.js +20 -26
  74. package/build/cjs/webpack/component-annotation-transform.js.map +1 -1
  75. package/build/cjs/webpack/index.js +271 -340
  76. package/build/cjs/webpack/index.js.map +1 -1
  77. package/build/esm/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/assertClassBrand.js +6 -0
  78. package/build/esm/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/checkPrivateRedeclaration.js +5 -0
  79. package/build/esm/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateFieldGet2.js +6 -0
  80. package/build/esm/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateFieldInitSpec.js +6 -0
  81. package/build/esm/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateFieldSet2.js +6 -0
  82. package/build/esm/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateMethodInitSpec.js +6 -0
  83. package/build/esm/_virtual/_rolldown/runtime.js +2 -0
  84. package/build/esm/babel-plugin/component-annotation.js +13 -29
  85. package/build/esm/babel-plugin/component-annotation.js.map +1 -1
  86. package/build/esm/babel-plugin/constants.js +140 -120
  87. package/build/esm/babel-plugin/constants.js.map +1 -1
  88. package/build/esm/babel-plugin/experimental.js +204 -305
  89. package/build/esm/babel-plugin/experimental.js.map +1 -1
  90. package/build/esm/babel-plugin/index.js +311 -434
  91. package/build/esm/babel-plugin/index.js.map +1 -1
  92. package/build/esm/bun/index.js +76 -101
  93. package/build/esm/bun/index.js.map +1 -1
  94. package/build/esm/core/build-plugin-manager.js +621 -683
  95. package/build/esm/core/build-plugin-manager.js.map +1 -1
  96. package/build/esm/core/cli.js +134 -127
  97. package/build/esm/core/cli.js.map +1 -1
  98. package/build/esm/core/component-annotate-hooks.js +16 -25
  99. package/build/esm/core/component-annotate-hooks.js.map +1 -1
  100. package/build/esm/core/component-annotation-oxc-ast.js +9 -19
  101. package/build/esm/core/component-annotation-oxc-ast.js.map +1 -1
  102. package/build/esm/core/component-annotation-oxc-fragments.js +44 -72
  103. package/build/esm/core/component-annotation-oxc-fragments.js.map +1 -1
  104. package/build/esm/core/component-annotation-oxc-jsx.js +115 -154
  105. package/build/esm/core/component-annotation-oxc-jsx.js.map +1 -1
  106. package/build/esm/core/component-annotation-oxc-walk.js +61 -121
  107. package/build/esm/core/component-annotation-oxc-walk.js.map +1 -1
  108. package/build/esm/core/component-annotation-oxc.js +65 -96
  109. package/build/esm/core/component-annotation-oxc.js.map +1 -1
  110. package/build/esm/core/debug-id-upload.js +218 -213
  111. package/build/esm/core/debug-id-upload.js.map +1 -1
  112. package/build/esm/core/get-code-injection-position.js +59 -72
  113. package/build/esm/core/get-code-injection-position.js.map +1 -1
  114. package/build/esm/core/glob.js +9 -5
  115. package/build/esm/core/glob.js.map +1 -1
  116. package/build/esm/core/index.js +62 -47
  117. package/build/esm/core/index.js.map +1 -1
  118. package/build/esm/core/logger.js +17 -24
  119. package/build/esm/core/logger.js.map +1 -1
  120. package/build/esm/core/options-mapping.js +95 -115
  121. package/build/esm/core/options-mapping.js.map +1 -1
  122. package/build/esm/core/sentry/telemetry.js +89 -102
  123. package/build/esm/core/sentry/telemetry.js.map +1 -1
  124. package/build/esm/core/sentry/transports.js +90 -83
  125. package/build/esm/core/sentry/transports.js.map +1 -1
  126. package/build/esm/core/sourcemap-settings.js +96 -59
  127. package/build/esm/core/sourcemap-settings.js.map +1 -1
  128. package/build/esm/core/upload-filter.js +39 -30
  129. package/build/esm/core/upload-filter.js.map +1 -1
  130. package/build/esm/core/utils.js +221 -211
  131. package/build/esm/core/utils.js.map +1 -1
  132. package/build/esm/core/version.js +4 -3
  133. package/build/esm/core/version.js.map +1 -1
  134. package/build/esm/esbuild/index.js +179 -197
  135. package/build/esm/esbuild/index.js.map +1 -1
  136. package/build/esm/loader-utils/index.js +4 -3
  137. package/build/esm/package.json +1 -1
  138. package/build/esm/rollup/debug-id-injection.js +22 -36
  139. package/build/esm/rollup/debug-id-injection.js.map +1 -1
  140. package/build/esm/rollup/debug-id-stamping.js +14 -22
  141. package/build/esm/rollup/debug-id-stamping.js.map +1 -1
  142. package/build/esm/rollup/index.js +189 -226
  143. package/build/esm/rollup/index.js.map +1 -1
  144. package/build/esm/rollup/source-map-handling.js +149 -159
  145. package/build/esm/rollup/source-map-handling.js.map +1 -1
  146. package/build/esm/vite/index.js +19 -18
  147. package/build/esm/vite/index.js.map +1 -1
  148. package/build/esm/vite/source-map-hooks.js +109 -72
  149. package/build/esm/vite/source-map-hooks.js.map +1 -1
  150. package/build/esm/webpack/component-annotation-transform.js +17 -24
  151. package/build/esm/webpack/component-annotation-transform.js.map +1 -1
  152. package/build/esm/webpack/index.js +268 -322
  153. package/build/esm/webpack/index.js.map +1 -1
  154. package/build/types/core/build-plugin-manager.d.ts +16 -5
  155. package/build/types/core/build-plugin-manager.d.ts.map +1 -1
  156. package/build/types/core/cli.d.ts +6 -1
  157. package/build/types/core/cli.d.ts.map +1 -1
  158. package/build/types/core/debug-id-upload.d.ts +7 -4
  159. package/build/types/core/debug-id-upload.d.ts.map +1 -1
  160. package/build/types/core/index.d.ts +3 -3
  161. package/build/types/core/index.d.ts.map +1 -1
  162. package/build/types/core/options-mapping.d.ts +4 -3
  163. package/build/types/core/options-mapping.d.ts.map +1 -1
  164. package/build/types/core/sentry/telemetry.d.ts.map +1 -1
  165. package/build/types/core/sourcemap-settings.d.ts +10 -1
  166. package/build/types/core/sourcemap-settings.d.ts.map +1 -1
  167. package/build/types/core/types.d.ts +25 -1
  168. package/build/types/core/types.d.ts.map +1 -1
  169. package/build/types/core/utils.d.ts +4 -0
  170. package/build/types/core/utils.d.ts.map +1 -1
  171. package/build/types/core/version.d.ts +1 -1
  172. package/build/types/esbuild/index.d.ts +2 -2
  173. package/build/types/esbuild/index.d.ts.map +1 -1
  174. package/build/types/rollup/index.d.ts +2 -2
  175. package/build/types/rollup/index.d.ts.map +1 -1
  176. package/build/types/rollup/source-map-handling.d.ts.map +1 -1
  177. package/build/types/vite/index.d.ts +3 -3
  178. package/build/types/vite/index.d.ts.map +1 -1
  179. package/build/types/vite/source-map-hooks.d.ts.map +1 -1
  180. package/build/types/webpack/index.d.ts +7 -3
  181. package/build/types/webpack/index.d.ts.map +1 -1
  182. package/package.json +8 -15
  183. package/build/cjs/loader-utils/index.js.map +0 -1
  184. package/build/esm/loader-utils/index.js.map +0 -1
@@ -1,359 +1,290 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
-
3
- const index = require('../core/index.js');
4
- const path = require('node:path');
5
- const node_url = require('node:url');
6
- const node_module = require('node:module');
7
- const node_crypto = require('node:crypto');
8
- const buildPluginManager = require('../core/build-plugin-manager.js');
9
- const utils = require('../core/utils.js');
10
- const componentAnnotateHooks = require('../core/component-annotate-hooks.js');
11
- const getCodeInjectionPosition = require('../core/get-code-injection-position.js');
12
- const debugIdUpload = require('../core/debug-id-upload.js');
13
-
14
- var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
15
- function _interopNamespace(e) {
16
- if (e && e.__esModule) return e;
17
- const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
18
- if (e) {
19
- for (const k in e) {
20
- n[k] = e[k];
21
- }
22
- }
23
- n.default = e;
24
- return n;
25
- }
26
-
27
- const path__namespace = /*#__PURE__*/_interopNamespace(path);
28
-
29
- const _req = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('webpack/index.js', document.baseURI).href)));
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_runtime = require("../_virtual/_rolldown/runtime.js");
3
+ const require_utils = require("../core/utils.js");
4
+ const require_get_code_injection_position = require("../core/get-code-injection-position.js");
5
+ const require_component_annotate_hooks = require("../core/component-annotate-hooks.js");
6
+ const require_debug_id_upload = require("../core/debug-id-upload.js");
7
+ const require_build_plugin_manager = require("../core/build-plugin-manager.js");
8
+ const require_index = require("../core/index.js");
9
+ let node_path = require("node:path");
10
+ node_path = require_runtime.__toESM(node_path);
11
+ let node_module = require("node:module");
12
+ let node_crypto = require("node:crypto");
13
+ let node_url = require("node:url");
14
+ // src/webpack/index.ts
15
+ const _req = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
30
16
  let COMPONENT_ANNOTATION_LOADER;
31
17
  try {
32
- COMPONENT_ANNOTATION_LOADER = _req.resolve("@sentry/bundler-plugins/webpack-loader");
18
+ COMPONENT_ANNOTATION_LOADER = _req.resolve("@sentry/bundler-plugins/webpack-loader");
33
19
  } catch {
34
- const dirname = path__namespace.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('webpack/index.js', document.baseURI).href))));
35
- COMPONENT_ANNOTATION_LOADER = path__namespace.resolve(dirname, "component-annotation-transform.js");
20
+ const dirname = node_path.dirname((0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href));
21
+ COMPONENT_ANNOTATION_LOADER = node_path.resolve(dirname, "component-annotation-transform.js");
36
22
  }
37
23
  const WEBPACK_JAVASCRIPT_ASSET_REGEX = /\.(?:js|ts|jsx|tsx|mjs|cjs|mts|cts)(?:\?[^?]*)?(?:#[^#]*)?$/;
24
+ /**
25
+ * Maps webpack's `devtool` onto the plugin's source map kinds. A user who sets `devtool: false`
26
+ * and adds a `SourceMapDevToolPlugin` manages source maps themselves.
27
+ */
38
28
  function sourceMapKindFromDevtool(compiler) {
39
- const devtool = compiler.options.devtool;
40
- if (devtool === void 0) {
41
- return "unset";
42
- }
43
- if (devtool === false) {
44
- const hasSourceMapPlugin = compiler.options.plugins?.some(
45
- (plugin) => plugin?.constructor?.name === "SourceMapDevToolPlugin"
46
- );
47
- return hasSourceMapPlugin ? void 0 : "off";
48
- }
49
- if (!devtool.includes("source-map")) {
50
- return "off";
51
- }
52
- if (devtool.includes("inline") || devtool.includes("eval")) {
53
- return "inline";
54
- }
55
- if (devtool.includes("hidden")) {
56
- return "hidden";
57
- }
58
- return "visible";
29
+ const devtool = compiler.options.devtool;
30
+ if (devtool === void 0) return "unset";
31
+ if (devtool === false) return compiler.options.plugins?.some((plugin) => plugin?.constructor?.name === "SourceMapDevToolPlugin") ? void 0 : "off";
32
+ if (!devtool.includes("source-map")) return "off";
33
+ if (devtool.includes("inline") || devtool.includes("eval")) return "inline";
34
+ if (devtool.includes("hidden")) return "hidden";
35
+ return "visible";
59
36
  }
60
37
  function getWebpackMajorVersion() {
61
- try {
62
- const webpack = _req("webpack");
63
- const version = webpack.version ?? webpack.default?.version;
64
- return version?.split(".")[0];
65
- } catch {
66
- return void 0;
67
- }
38
+ try {
39
+ const webpack = _req("webpack");
40
+ return (webpack.version ?? webpack.default?.version)?.split(".")[0];
41
+ } catch {
42
+ return;
43
+ }
68
44
  }
45
+ /**
46
+ * Stamps each JS asset's debug ID into the asset itself and its source map asset.
47
+ *
48
+ * Runs after source maps have been generated, so the JS asset no longer needs to carry
49
+ * source map information and can be replaced with a plain `RawSource`.
50
+ */
69
51
  function addDebugIdsToAssets(compilation, RawSource) {
70
- for (const asset of compilation.getAssets()) {
71
- if (!index.isJsFile(asset.name)) {
72
- continue;
73
- }
74
- const bundleSource = asset.source.source().toString();
75
- const relatedSourceMap = asset.info.related?.sourceMap;
76
- const sourceMapName = typeof relatedSourceMap === "string" ? relatedSourceMap : `${asset.name}.map`;
77
- const sourceMapAsset = compilation.getAsset(sourceMapName);
78
- const stamped = debugIdUpload.stampDebugId(bundleSource, sourceMapAsset?.source.source().toString());
79
- if (!stamped) {
80
- continue;
81
- }
82
- compilation.updateAsset(asset.name, new RawSource(stamped.bundleSource));
83
- if (stamped.sourceMapSource !== void 0) {
84
- compilation.updateAsset(sourceMapName, new RawSource(stamped.sourceMapSource));
85
- }
86
- }
52
+ for (const asset of compilation.getAssets()) {
53
+ if (!require_index.isJsFile(asset.name)) continue;
54
+ const bundleSource = asset.source.source().toString();
55
+ const relatedSourceMap = asset.info.related?.sourceMap;
56
+ const sourceMapName = typeof relatedSourceMap === "string" ? relatedSourceMap : `${asset.name}.map`;
57
+ const sourceMapAsset = compilation.getAsset(sourceMapName);
58
+ const stamped = require_debug_id_upload.stampDebugId(bundleSource, sourceMapAsset?.source.source().toString());
59
+ if (!stamped) continue;
60
+ compilation.updateAsset(asset.name, new RawSource(stamped.bundleSource));
61
+ if (stamped.sourceMapSource !== void 0) compilation.updateAsset(sourceMapName, new RawSource(stamped.sourceMapSource));
62
+ }
87
63
  }
64
+ /** Drops a source map asset and its compressed variants from the compilation. */
88
65
  function deleteSourceMapAssets(compilation, sourceMapName) {
89
- for (const candidate of compilation.getAssets()) {
90
- if (candidate.name === sourceMapName || candidate.name.startsWith(`${sourceMapName}.`)) {
91
- compilation.deleteAsset(candidate.name);
92
- }
93
- }
66
+ for (const candidate of compilation.getAssets()) if (candidate.name === sourceMapName || candidate.name.startsWith(`${sourceMapName}.`)) compilation.deleteAsset(candidate.name);
67
+ }
68
+ /**
69
+ * Drops the source maps of the JS assets that an upload would include. With `removeAll` it drops
70
+ * the source maps of all assets, CSS included.
71
+ */
72
+ function dropSourceMaps(compilation, shouldUpload, removeAll) {
73
+ const outputPath = compilation.outputOptions.path ?? node_path.resolve();
74
+ for (const asset of compilation.getAssets()) {
75
+ if (!removeAll && (!require_index.isJsFile(asset.name) || !shouldUpload(node_path.join(outputPath, asset.name)))) continue;
76
+ const relatedSourceMap = asset.info.related?.sourceMap;
77
+ const sourceMapName = typeof relatedSourceMap === "string" ? relatedSourceMap : `${asset.name}.map`;
78
+ if (compilation.getAsset(sourceMapName)) deleteSourceMapAssets(compilation, sourceMapName);
79
+ }
94
80
  }
81
+ /**
82
+ * Copies each JS asset and its source map into the upload staging folder and drops the source map
83
+ * assets (and their compressed variants) from the compilation, so webpack never emits them.
84
+ *
85
+ * A map the plugin or the SDK turned on (`pluginEnabledMaps`) never reaches the output, whether or
86
+ * not its asset is uploaded. That covers CSS maps, which `devtool` turns on along with the JS ones.
87
+ * A map the user enabled stays unless it was staged.
88
+ */
95
89
  async function stageSourceMaps(compilation, staging, logger, pluginEnabledMaps) {
96
- const outputPath = compilation.outputOptions.path ?? path__namespace.resolve();
97
- for (const asset of compilation.getAssets()) {
98
- const relatedSourceMap = asset.info.related?.sourceMap;
99
- const sourceMapName = typeof relatedSourceMap === "string" ? relatedSourceMap : `${asset.name}.map`;
100
- const sourceMapAsset = compilation.getAsset(sourceMapName);
101
- if (!sourceMapAsset) {
102
- continue;
103
- }
104
- if (!index.isJsFile(asset.name)) {
105
- if (pluginEnabledMaps) {
106
- deleteSourceMapAssets(compilation, sourceMapName);
107
- }
108
- continue;
109
- }
110
- const result = await staging.stage({
111
- code: asset.source.source().toString(),
112
- mapSource: sourceMapAsset.source.source().toString(),
113
- mapDir: path__namespace.join(outputPath, path__namespace.dirname(sourceMapName)),
114
- chunkPath: path__namespace.join(outputPath, asset.name)
115
- });
116
- if (result === "skipped" || result === "failed") {
117
- logger.warn(
118
- pluginEnabledMaps ? `Could not prepare ${asset.name} for upload, so it is not uploaded and its source map ${sourceMapName} was removed from the build output.` : `Could not prepare ${asset.name} for upload, so its source map ${sourceMapName} stays in the build output.`
119
- );
120
- }
121
- if (result === "staged" || pluginEnabledMaps) {
122
- deleteSourceMapAssets(compilation, sourceMapName);
123
- }
124
- }
90
+ const outputPath = compilation.outputOptions.path ?? node_path.resolve();
91
+ for (const asset of compilation.getAssets()) {
92
+ const relatedSourceMap = asset.info.related?.sourceMap;
93
+ const sourceMapName = typeof relatedSourceMap === "string" ? relatedSourceMap : `${asset.name}.map`;
94
+ const sourceMapAsset = compilation.getAsset(sourceMapName);
95
+ if (!sourceMapAsset) continue;
96
+ if (!require_index.isJsFile(asset.name)) {
97
+ if (pluginEnabledMaps) deleteSourceMapAssets(compilation, sourceMapName);
98
+ continue;
99
+ }
100
+ const result = await staging.stage({
101
+ code: asset.source.source().toString(),
102
+ mapSource: sourceMapAsset.source.source().toString(),
103
+ mapDir: node_path.join(outputPath, node_path.dirname(sourceMapName)),
104
+ chunkPath: node_path.join(outputPath, asset.name)
105
+ });
106
+ if (result === "skipped" || result === "failed") logger.warn(pluginEnabledMaps ? `Could not prepare ${asset.name} for upload, so it is not uploaded and its source map ${sourceMapName} was removed from the build output.` : `Could not prepare ${asset.name} for upload, so its source map ${sourceMapName} stays in the build output.`);
107
+ if (result === "staged" || pluginEnabledMaps) deleteSourceMapAssets(compilation, sourceMapName);
108
+ }
125
109
  }
126
110
  function createSentryWebpackPlugin(userOptions = {}) {
127
- const sentryBuildPluginManager = buildPluginManager.createSentryBuildPluginManager(userOptions, {
128
- loggerPrefix: userOptions._metaOptions?.loggerPrefixOverride ?? "[sentry-webpack-plugin]",
129
- buildTool: "webpack",
130
- buildToolMajorVersion: getWebpackMajorVersion()
131
- });
132
- const {
133
- logger,
134
- normalizedOptions: options,
135
- bundleSizeOptimizationReplacementValues: replacementValues,
136
- bundleMetadata,
137
- createDependencyOnBuildArtifacts
138
- } = sentryBuildPluginManager;
139
- if (options.disable) {
140
- return {
141
- apply() {
142
- }
143
- };
144
- }
145
- if (process.cwd().match(/\\node_modules\\|\/node_modules\//)) {
146
- logger.warn("Running Sentry plugin from within a `node_modules` folder. Some features may not work.");
147
- }
148
- const sourcemapsEnabled = options.sourcemaps?.disable !== true;
149
- const releaseInjectionCode = new utils.CodeInjection();
150
- const chunkInjectionCode = new utils.CodeInjection();
151
- if (!options.release.inject) {
152
- logger.debug("Release injection disabled via `release.inject` option. Will not inject release.");
153
- } else if (!options.release.name) {
154
- logger.debug(
155
- "No release name provided. Will not inject release. Please set the `release.name` option to identify your release."
156
- );
157
- } else {
158
- releaseInjectionCode.append(
159
- utils.generateReleaseInjectorCode({
160
- release: options.release.name,
161
- injectBuildInformation: options._experiments.injectBuildInformation || false
162
- })
163
- );
164
- }
165
- if (Object.keys(bundleMetadata).length > 0) {
166
- chunkInjectionCode.append(utils.generateModuleMetadataInjectorCode(bundleMetadata));
167
- }
168
- const transformAnnotations = options.reactComponentAnnotation?.enabled ? componentAnnotateHooks.createComponentNameAnnotateHooks(
169
- options.reactComponentAnnotation?.ignoredComponents || [],
170
- !!options.reactComponentAnnotation?._experimentalInjectIntoHtml,
171
- { logger }
172
- ) : void 0;
173
- const transformReplace = Object.keys(replacementValues).length > 0;
174
- function decideSourceMaps(compiler) {
175
- const kind = compiler.options.mode === "development" ? void 0 : sourceMapKindFromDevtool(compiler);
176
- if (kind === void 0) {
177
- return { decision: { enableHidden: false, deleteAfterUpload: false } };
178
- }
179
- const decision = sentryBuildPluginManager.sourceMaps.decide(kind);
180
- if (decision.enableHidden) {
181
- compiler.options.devtool = kind === "visible" ? `hidden-${compiler.options.devtool}` : "hidden-source-map";
182
- }
183
- return { kind, decision };
184
- }
185
- function addCodeInjection(compiler) {
186
- if (releaseInjectionCode.isEmpty() && chunkInjectionCode.isEmpty() && !sourcemapsEnabled) {
187
- return;
188
- }
189
- const ReplaceSource = compiler.webpack?.sources?.ReplaceSource;
190
- const processAssetsStage = compiler.webpack?.Compilation?.PROCESS_ASSETS_STAGE_ADDITIONS;
191
- if (!ReplaceSource || processAssetsStage === void 0) {
192
- logger.warn(
193
- "Webpack sources are not available. Skipping code injection. This usually means webpack is not properly configured."
194
- );
195
- return;
196
- }
197
- compiler.hooks.compilation.tap("sentry-webpack-plugin-injection", (compilation) => {
198
- compilation.hooks.processAssets.tap(
199
- {
200
- name: "sentry-webpack-plugin-injection",
201
- stage: processAssetsStage
202
- },
203
- (assets) => {
204
- const injectedAssets = /* @__PURE__ */ new Set();
205
- for (const chunk of compilation.chunks) {
206
- for (const assetName of chunk.files) {
207
- if (injectedAssets.has(assetName) || !WEBPACK_JAVASCRIPT_ASSET_REGEX.test(assetName)) {
208
- continue;
209
- }
210
- const source = assets[assetName];
211
- if (!source) {
212
- continue;
213
- }
214
- injectedAssets.add(assetName);
215
- const sourceContents = source.source();
216
- const code = typeof sourceContents === "string" ? sourceContents : Buffer.from(sourceContents).toString();
217
- const codeToInject = new utils.CodeInjection();
218
- if (chunk.canBeInitial?.() ?? true) {
219
- codeToInject.append(releaseInjectionCode);
220
- }
221
- codeToInject.append(chunkInjectionCode);
222
- if (sourcemapsEnabled) {
223
- const hash = chunk.contentHash?.javascript ?? chunk.hash;
224
- codeToInject.append(index.getDebugIdSnippet(hash ? utils.stringToUUID(hash) : node_crypto.randomUUID()));
225
- }
226
- const injectionPosition = getCodeInjectionPosition.getCodeInjectionPosition(code);
227
- const injection = injectionPosition === code.length ? `
228
- ${codeToInject.code()}` : codeToInject.code();
229
- const updatedSource = new ReplaceSource(source);
230
- updatedSource.insert(injectionPosition, injection);
231
- compilation.updateAsset(assetName, updatedSource);
232
- }
233
- }
234
- }
235
- );
236
- });
237
- }
238
- return {
239
- apply(compiler) {
240
- void sentryBuildPluginManager.telemetry.emitBundlerPluginExecutionSignal().catch(() => {
241
- });
242
- const { DefinePlugin } = compiler.webpack ?? {};
243
- const { kind: sourceMapKind, decision: sourceMapDecision } = decideSourceMaps(compiler);
244
- const pendingStagings = /* @__PURE__ */ new Map();
245
- if (sourceMapDecision.deleteAfterUpload) {
246
- const stage = (compiler.webpack?.Compilation?.PROCESS_ASSETS_STAGE_REPORT ?? 5e3) + 1;
247
- compiler.hooks.thisCompilation.tap("sentry-webpack-plugin", (compilation) => {
248
- compilation.hooks.processAssets.tapPromise({ name: "sentry-webpack-plugin", stage }, async () => {
249
- const staging = await sentryBuildPluginManager.createUploadStaging();
250
- pendingStagings.set(compilation, staging);
251
- await stageSourceMaps(compilation, staging, logger, sourceMapKind === "unset");
252
- });
253
- });
254
- const emittedCompilations = /* @__PURE__ */ new Set();
255
- compiler.hooks.emit.tap("sentry-webpack-plugin", (compilation) => {
256
- emittedCompilations.add(compilation);
257
- });
258
- const settlePendingStagings = () => {
259
- for (const [compilation, staging] of pendingStagings) {
260
- if (emittedCompilations.has(compilation)) {
261
- void staging.keep("The source map upload did not run.");
262
- } else {
263
- void staging.discard();
264
- }
265
- }
266
- pendingStagings.clear();
267
- emittedCompilations.clear();
268
- };
269
- compiler.hooks.done.tap("sentry-webpack-plugin", settlePendingStagings);
270
- compiler.hooks.failed?.tap("sentry-webpack-plugin", settlePendingStagings);
271
- }
272
- addCodeInjection(compiler);
273
- if (sourcemapsEnabled && options.sourcemaps?.disable === "disable-upload") {
274
- const RawSource = compiler.webpack?.sources?.RawSource;
275
- const stage = (compiler.webpack?.Compilation?.PROCESS_ASSETS_STAGE_DEV_TOOLING ?? 500) + 1;
276
- if (!RawSource) {
277
- logger.warn(
278
- "Webpack sources are not available. Skipping debug ID injection into emitted source maps. This usually means webpack is not properly configured."
279
- );
280
- } else {
281
- compiler.hooks.thisCompilation.tap("sentry-webpack-plugin", (compilation) => {
282
- compilation.hooks.processAssets.tap({ name: "sentry-webpack-plugin", stage }, () => {
283
- addDebugIdsToAssets(compilation, RawSource);
284
- });
285
- });
286
- }
287
- }
288
- if (transformReplace && DefinePlugin) {
289
- compiler.options.plugins = compiler.options.plugins || [];
290
- compiler.options.plugins.push(new DefinePlugin(replacementValues));
291
- }
292
- if (transformAnnotations?.transform) {
293
- compiler.options.module = compiler.options.module || {};
294
- compiler.options.module.rules = compiler.options.module.rules || [];
295
- compiler.options.module.rules.unshift({
296
- test: /\.[jt]sx$/,
297
- exclude: /node_modules/,
298
- enforce: "pre",
299
- use: [
300
- {
301
- loader: COMPONENT_ANNOTATION_LOADER,
302
- options: {
303
- transform: transformAnnotations.transform
304
- }
305
- }
306
- ]
307
- });
308
- }
309
- compiler.hooks.afterEmit.tapAsync(
310
- "sentry-webpack-plugin",
311
- (compilation, callback) => {
312
- const freeGlobalDependencyOnBuildArtifacts = createDependencyOnBuildArtifacts();
313
- const upload = debugIdUpload.createDebugIdUploadFunction({ sentryBuildPluginManager });
314
- const staging = pendingStagings.get(compilation);
315
- pendingStagings.delete(compilation);
316
- let stagingHandedOver = false;
317
- const run = async () => {
318
- try {
319
- await sentryBuildPluginManager.createRelease();
320
- if (sourcemapsEnabled && options.sourcemaps?.disable !== "disable-upload") {
321
- const outputPath = compilation.outputOptions.path ?? path__namespace.resolve();
322
- const buildArtifacts = Object.keys(compilation.assets).map((asset) => path__namespace.join(outputPath, asset));
323
- stagingHandedOver = true;
324
- await upload(buildArtifacts, { staging });
325
- } else {
326
- stagingHandedOver = true;
327
- await staging?.discard();
328
- }
329
- } catch (e) {
330
- if (!stagingHandedOver) {
331
- await staging?.keep("The source map upload did not run.");
332
- }
333
- throw e;
334
- } finally {
335
- freeGlobalDependencyOnBuildArtifacts();
336
- await sentryBuildPluginManager.deleteArtifacts();
337
- }
338
- };
339
- run().then(
340
- () => callback(),
341
- (err) => callback(err)
342
- );
343
- }
344
- );
345
- if (userOptions._experiments?.forceExitOnBuildCompletion && compiler.options.mode === "production") {
346
- compiler.hooks.done.tap("sentry-webpack-plugin", () => {
347
- setTimeout(() => {
348
- logger.debug("Exiting process after debug file upload");
349
- process.exit(0);
350
- });
351
- });
352
- }
353
- }
354
- };
111
+ const sentryBuildPluginManager = require_build_plugin_manager.createSentryBuildPluginManager(userOptions, {
112
+ loggerPrefix: userOptions._metaOptions?.loggerPrefixOverride ?? "[sentry-webpack-plugin]",
113
+ buildTool: "webpack",
114
+ buildToolMajorVersion: getWebpackMajorVersion()
115
+ });
116
+ const { logger, normalizedOptions: options, bundleSizeOptimizationReplacementValues: replacementValues, bundleMetadata, createDependencyOnBuildArtifacts } = sentryBuildPluginManager;
117
+ if (options.disable) return { apply() {} };
118
+ 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 sourcemapsEnabled = options.sourcemaps?.disable !== true;
120
+ const releaseInjectionCode = new require_utils.CodeInjection();
121
+ const chunkInjectionCode = new require_utils.CodeInjection();
122
+ if (!options.release.inject) logger.debug("Release injection disabled via `release.inject` option. Will not inject release.");
123
+ 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.");
124
+ else releaseInjectionCode.append(require_utils.generateReleaseInjectorCode({
125
+ release: options.release.name,
126
+ injectBuildInformation: options._experiments.injectBuildInformation || false
127
+ }));
128
+ if (Object.keys(bundleMetadata).length > 0) chunkInjectionCode.append(require_utils.generateModuleMetadataInjectorCode(bundleMetadata));
129
+ const transformAnnotations = options.reactComponentAnnotation?.enabled ? require_component_annotate_hooks.createComponentNameAnnotateHooks(options.reactComponentAnnotation?.ignoredComponents || [], !!options.reactComponentAnnotation?._experimentalInjectIntoHtml, { logger }) : void 0;
130
+ const transformReplace = Object.keys(replacementValues).length > 0;
131
+ function decideSourceMaps(compiler) {
132
+ const kind = compiler.options.mode === "development" ? void 0 : sourceMapKindFromDevtool(compiler);
133
+ if (kind === void 0) return { decision: {
134
+ enableHidden: false,
135
+ deleteAfterUpload: false
136
+ } };
137
+ const decision = sentryBuildPluginManager.sourceMaps.decide(kind);
138
+ if (decision.enableHidden) compiler.options.devtool = kind === "visible" ? `hidden-${compiler.options.devtool}` : "hidden-source-map";
139
+ return {
140
+ kind,
141
+ decision
142
+ };
143
+ }
144
+ function addCodeInjection(compiler) {
145
+ if (releaseInjectionCode.isEmpty() && chunkInjectionCode.isEmpty() && !sourcemapsEnabled) return;
146
+ const ReplaceSource = compiler.webpack?.sources?.ReplaceSource;
147
+ const processAssetsStage = compiler.webpack?.Compilation?.PROCESS_ASSETS_STAGE_ADDITIONS;
148
+ if (!ReplaceSource || processAssetsStage === void 0) {
149
+ logger.warn("Webpack sources are not available. Skipping code injection. This usually means webpack is not properly configured.");
150
+ return;
151
+ }
152
+ compiler.hooks.compilation.tap("sentry-webpack-plugin-injection", (compilation) => {
153
+ compilation.hooks.processAssets.tap({
154
+ name: "sentry-webpack-plugin-injection",
155
+ stage: processAssetsStage
156
+ }, (assets) => {
157
+ const injectedAssets = /* @__PURE__ */ new Set();
158
+ for (const chunk of compilation.chunks) for (const assetName of chunk.files) {
159
+ if (injectedAssets.has(assetName) || !WEBPACK_JAVASCRIPT_ASSET_REGEX.test(assetName)) continue;
160
+ const source = assets[assetName];
161
+ if (!source) continue;
162
+ injectedAssets.add(assetName);
163
+ const sourceContents = source.source();
164
+ const code = typeof sourceContents === "string" ? sourceContents : Buffer.from(sourceContents).toString();
165
+ const codeToInject = new require_utils.CodeInjection();
166
+ if (chunk.canBeInitial?.() ?? true) codeToInject.append(releaseInjectionCode);
167
+ codeToInject.append(chunkInjectionCode);
168
+ if (sourcemapsEnabled) {
169
+ const hash = chunk.contentHash?.javascript ?? chunk.hash;
170
+ codeToInject.append(require_index.getDebugIdSnippet(hash ? require_utils.stringToUUID(hash) : (0, node_crypto.randomUUID)()));
171
+ }
172
+ const injectionPosition = require_get_code_injection_position.getCodeInjectionPosition(code);
173
+ const injection = injectionPosition === code.length ? `\n${codeToInject.code()}` : codeToInject.code();
174
+ const updatedSource = new ReplaceSource(source);
175
+ updatedSource.insert(injectionPosition, injection);
176
+ compilation.updateAsset(assetName, updatedSource);
177
+ }
178
+ });
179
+ });
180
+ }
181
+ return { apply(compiler) {
182
+ sentryBuildPluginManager.telemetry.emitBundlerPluginExecutionSignal().catch(() => {});
183
+ const { DefinePlugin } = compiler.webpack ?? {};
184
+ const { decision: sourceMapDecision } = decideSourceMaps(compiler);
185
+ const removeAllSourceMaps = sourceMapDecision.removeAllSourceMaps === true;
186
+ const pendingStagings = /* @__PURE__ */ new Map();
187
+ const deleteStage = (compiler.webpack?.Compilation?.PROCESS_ASSETS_STAGE_REPORT ?? 5e3) + 1;
188
+ if (sourceMapDecision.deleteAfterUpload && !sentryBuildPluginManager.sourceMaps.uploadPossible) compiler.hooks.thisCompilation.tap("sentry-webpack-plugin", (compilation) => {
189
+ compilation.hooks.processAssets.tap({
190
+ name: "sentry-webpack-plugin",
191
+ stage: deleteStage
192
+ }, () => {
193
+ dropSourceMaps(compilation, sentryBuildPluginManager.sourceMaps.shouldUpload, removeAllSourceMaps);
194
+ });
195
+ });
196
+ else if (sourceMapDecision.deleteAfterUpload) {
197
+ compiler.hooks.thisCompilation.tap("sentry-webpack-plugin", (compilation) => {
198
+ compilation.hooks.processAssets.tapPromise({
199
+ name: "sentry-webpack-plugin",
200
+ stage: deleteStage
201
+ }, async () => {
202
+ const staging = await sentryBuildPluginManager.createUploadStaging();
203
+ pendingStagings.set(compilation, staging);
204
+ await stageSourceMaps(compilation, staging, logger, removeAllSourceMaps);
205
+ });
206
+ });
207
+ const emittedCompilations = /* @__PURE__ */ new Set();
208
+ compiler.hooks.emit.tap("sentry-webpack-plugin", (compilation) => {
209
+ emittedCompilations.add(compilation);
210
+ });
211
+ const settlePendingStagings = () => {
212
+ for (const [compilation, staging] of pendingStagings) if (emittedCompilations.has(compilation)) staging.keep("The source map upload did not run.");
213
+ else staging.discard();
214
+ pendingStagings.clear();
215
+ emittedCompilations.clear();
216
+ };
217
+ compiler.hooks.done.tap("sentry-webpack-plugin", settlePendingStagings);
218
+ compiler.hooks.failed?.tap("sentry-webpack-plugin", settlePendingStagings);
219
+ }
220
+ addCodeInjection(compiler);
221
+ if (sourcemapsEnabled && options.sourcemaps?.disable === "disable-upload") {
222
+ const RawSource = compiler.webpack?.sources?.RawSource;
223
+ const stage = (compiler.webpack?.Compilation?.PROCESS_ASSETS_STAGE_DEV_TOOLING ?? 500) + 1;
224
+ 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.");
225
+ else compiler.hooks.thisCompilation.tap("sentry-webpack-plugin", (compilation) => {
226
+ compilation.hooks.processAssets.tap({
227
+ name: "sentry-webpack-plugin",
228
+ stage
229
+ }, () => {
230
+ addDebugIdsToAssets(compilation, RawSource);
231
+ });
232
+ });
233
+ }
234
+ if (transformReplace && DefinePlugin) {
235
+ compiler.options.plugins = compiler.options.plugins || [];
236
+ compiler.options.plugins.push(new DefinePlugin(replacementValues));
237
+ }
238
+ if (transformAnnotations?.transform) {
239
+ compiler.options.module = compiler.options.module || {};
240
+ compiler.options.module.rules = compiler.options.module.rules || [];
241
+ compiler.options.module.rules.unshift({
242
+ test: /\.[jt]sx$/,
243
+ exclude: /node_modules/,
244
+ enforce: "pre",
245
+ use: [{
246
+ loader: COMPONENT_ANNOTATION_LOADER,
247
+ options: { transform: transformAnnotations.transform }
248
+ }]
249
+ });
250
+ }
251
+ compiler.hooks.afterEmit.tapAsync("sentry-webpack-plugin", (compilation, callback) => {
252
+ const freeGlobalDependencyOnBuildArtifacts = createDependencyOnBuildArtifacts();
253
+ const upload = require_debug_id_upload.createDebugIdUploadFunction({ sentryBuildPluginManager });
254
+ const staging = pendingStagings.get(compilation);
255
+ pendingStagings.delete(compilation);
256
+ let stagingHandedOver = false;
257
+ const run = async () => {
258
+ try {
259
+ await sentryBuildPluginManager.createRelease();
260
+ if (sourcemapsEnabled && options.sourcemaps?.disable !== "disable-upload") {
261
+ const outputPath = compilation.outputOptions.path ?? node_path.resolve();
262
+ const buildArtifacts = Object.keys(compilation.assets).map((asset) => node_path.join(outputPath, asset));
263
+ stagingHandedOver = true;
264
+ await upload(buildArtifacts, { staging });
265
+ } else {
266
+ stagingHandedOver = true;
267
+ await staging?.discard();
268
+ }
269
+ } catch (e) {
270
+ if (!stagingHandedOver) await staging?.keep("The source map upload did not run.");
271
+ throw e;
272
+ } finally {
273
+ freeGlobalDependencyOnBuildArtifacts();
274
+ await sentryBuildPluginManager.deleteArtifacts();
275
+ }
276
+ };
277
+ run().then(() => callback(), (err) => callback(err));
278
+ });
279
+ if (userOptions._experiments?.forceExitOnBuildCompletion && compiler.options.mode === "production") compiler.hooks.done.tap("sentry-webpack-plugin", () => {
280
+ setTimeout(() => {
281
+ logger.debug("Exiting process after debug file upload");
282
+ process.exit(0);
283
+ });
284
+ });
285
+ } };
355
286
  }
356
287
  const sentryWebpackPlugin = createSentryWebpackPlugin;
357
-
358
288
  exports.sentryWebpackPlugin = sentryWebpackPlugin;
359
- //# sourceMappingURL=index.js.map
289
+
290
+ //# sourceMappingURL=index.js.map