@sentry/bundler-plugins 11.9.0 → 11.11.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 (62) hide show
  1. package/README.md +5 -1
  2. package/build/cjs/bun/index.js +126 -0
  3. package/build/cjs/bun/index.js.map +1 -0
  4. package/build/cjs/core/build-plugin-manager.js +165 -33
  5. package/build/cjs/core/build-plugin-manager.js.map +1 -1
  6. package/build/cjs/core/component-annotation-oxc.js +1 -1
  7. package/build/cjs/core/debug-id-upload.js +64 -55
  8. package/build/cjs/core/debug-id-upload.js.map +1 -1
  9. package/build/cjs/core/index.js +2 -0
  10. package/build/cjs/core/index.js.map +1 -1
  11. package/build/cjs/core/options-mapping.js +6 -0
  12. package/build/cjs/core/options-mapping.js.map +1 -1
  13. package/build/cjs/core/sentry/telemetry.js +4 -0
  14. package/build/cjs/core/sentry/telemetry.js.map +1 -1
  15. package/build/cjs/core/sentry/transports.js +3 -3
  16. package/build/cjs/core/sentry/transports.js.map +1 -1
  17. package/build/cjs/core/sourcemap-settings.js +63 -0
  18. package/build/cjs/core/sourcemap-settings.js.map +1 -0
  19. package/build/cjs/core/utils.js +1 -1
  20. package/build/cjs/core/version.js +1 -1
  21. package/build/cjs/core/version.js.map +1 -1
  22. package/build/cjs/esbuild/index.js +2 -2
  23. package/build/cjs/esbuild/index.js.map +1 -1
  24. package/build/cjs/rollup/index.js +1 -1
  25. package/build/esm/bun/index.js +109 -0
  26. package/build/esm/bun/index.js.map +1 -0
  27. package/build/esm/core/build-plugin-manager.js +166 -34
  28. package/build/esm/core/build-plugin-manager.js.map +1 -1
  29. package/build/esm/core/debug-id-upload.js +62 -56
  30. package/build/esm/core/debug-id-upload.js.map +1 -1
  31. package/build/esm/core/index.js +1 -0
  32. package/build/esm/core/index.js.map +1 -1
  33. package/build/esm/core/options-mapping.js +6 -0
  34. package/build/esm/core/options-mapping.js.map +1 -1
  35. package/build/esm/core/sentry/telemetry.js +4 -0
  36. package/build/esm/core/sentry/telemetry.js.map +1 -1
  37. package/build/esm/core/sourcemap-settings.js +61 -0
  38. package/build/esm/core/sourcemap-settings.js.map +1 -0
  39. package/build/esm/core/version.js +1 -1
  40. package/build/esm/core/version.js.map +1 -1
  41. package/build/esm/esbuild/index.js +2 -2
  42. package/build/esm/esbuild/index.js.map +1 -1
  43. package/build/esm/package.json +1 -1
  44. package/build/types/bun/index.d.ts +25 -0
  45. package/build/types/bun/index.d.ts.map +1 -0
  46. package/build/types/core/build-plugin-manager.d.ts +57 -1
  47. package/build/types/core/build-plugin-manager.d.ts.map +1 -1
  48. package/build/types/core/debug-id-upload.d.ts +38 -2
  49. package/build/types/core/debug-id-upload.d.ts.map +1 -1
  50. package/build/types/core/index.d.ts +3 -0
  51. package/build/types/core/index.d.ts.map +1 -1
  52. package/build/types/core/options-mapping.d.ts +1 -0
  53. package/build/types/core/options-mapping.d.ts.map +1 -1
  54. package/build/types/core/sentry/telemetry.d.ts.map +1 -1
  55. package/build/types/core/sourcemap-settings.d.ts +28 -0
  56. package/build/types/core/sourcemap-settings.d.ts.map +1 -0
  57. package/build/types/core/types.d.ts +11 -0
  58. package/build/types/core/types.d.ts.map +1 -1
  59. package/build/types/core/version.d.ts +1 -1
  60. package/build/types/core/version.d.ts.map +1 -1
  61. package/build/types/esbuild/index.d.ts.map +1 -1
  62. package/package.json +12 -7
package/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  <p align="center">
2
2
  <a href="https://sentry.io/?utm_source=github&utm_medium=logo" target="_blank">
3
- <img src="https://sentry-brand.storage.googleapis.com/sentry-wordmark-dark-280x84.png" alt="Sentry" width="280" height="84">
3
+ <picture>
4
+ <source srcset="https://sentry-brand.storage.googleapis.com/sentry-logo-white.png" media="(prefers-color-scheme: dark)" />
5
+ <source srcset="https://sentry-brand.storage.googleapis.com/sentry-wordmark-dark-280x84.png" media="(prefers-color-scheme: light), (prefers-color-scheme: no-preference)" />
6
+ <img src="https://sentry-brand.storage.googleapis.com/sentry-wordmark-dark-280x84.png" alt="Sentry" width="280">
7
+ </picture>
4
8
  </a>
5
9
  </p>
6
10
 
@@ -0,0 +1,126 @@
1
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
+
3
+ const index = require('../core/index.js');
4
+ const fs = require('node:fs');
5
+ const buildPluginManager = require('../core/build-plugin-manager.js');
6
+ const utils = require('../core/utils.js');
7
+ const debugIdUpload = require('../core/debug-id-upload.js');
8
+
9
+ function _interopNamespace(e) {
10
+ if (e && e.__esModule) return e;
11
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
12
+ if (e) {
13
+ for (const k in e) {
14
+ n[k] = e[k];
15
+ }
16
+ }
17
+ n.default = e;
18
+ return n;
19
+ }
20
+
21
+ const fs__namespace = /*#__PURE__*/_interopNamespace(fs);
22
+
23
+ const pluginName = "sentry-bun-plugin";
24
+ const DEBUG_ID_PLACEHOLDER = "sentry-bun-debug-id-placeholder-0000";
25
+ const BUN_DEBUG_ID_REGEX = /^\/\/# debugId=([0-9a-fA-F]{32})$(?![\s\S]*^\/\/# debugId=)/m;
26
+ function bunDebugIdToUuid(bunDebugId) {
27
+ const hex = bunDebugId.toLowerCase();
28
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
29
+ }
30
+ function sentryBunPlugin(userOptions = {}) {
31
+ const sentryBuildPluginManager = buildPluginManager.createSentryBuildPluginManager(userOptions, {
32
+ loggerPrefix: userOptions._metaOptions?.loggerPrefixOverride ?? `[${pluginName}]`,
33
+ buildTool: "bun",
34
+ buildToolMajorVersion: process.versions["bun"]?.split(".")[0]
35
+ });
36
+ const {
37
+ logger,
38
+ normalizedOptions: options,
39
+ bundleSizeOptimizationReplacementValues: replacementValues,
40
+ bundleMetadata,
41
+ createDependencyOnBuildArtifacts
42
+ } = sentryBuildPluginManager;
43
+ if (options.disable) {
44
+ return { name: "sentry-bun-noop-plugin", setup: () => void 0 };
45
+ }
46
+ const staticInjectionCode = new utils.CodeInjection();
47
+ if (!options.release.inject) {
48
+ logger.debug("Release injection disabled via `release.inject` option. Will not inject release.");
49
+ } else if (!options.release.name) {
50
+ logger.debug(
51
+ "No release name provided. Will not inject release. Please set the `release.name` option to identify your release."
52
+ );
53
+ } else {
54
+ staticInjectionCode.append(
55
+ utils.generateReleaseInjectorCode({
56
+ release: options.release.name,
57
+ injectBuildInformation: options._experiments.injectBuildInformation || false
58
+ })
59
+ );
60
+ }
61
+ if (Object.keys(bundleMetadata).length > 0) {
62
+ staticInjectionCode.append(utils.generateModuleMetadataInjectorCode(bundleMetadata));
63
+ }
64
+ void sentryBuildPluginManager.telemetry.emitBundlerPluginExecutionSignal().catch(() => {
65
+ });
66
+ async function replaceDebugIdPlaceholder(bundlePath) {
67
+ const source = await fs__namespace.promises.readFile(bundlePath, "utf8");
68
+ const bunDebugId = source.match(BUN_DEBUG_ID_REGEX)?.[1];
69
+ if (!bunDebugId) {
70
+ logger.debug(`Bun wrote no debug ID into the bundle. File will not be source mapped: ${bundlePath}`);
71
+ return;
72
+ }
73
+ await fs__namespace.promises.writeFile(
74
+ bundlePath,
75
+ source.split(DEBUG_ID_PLACEHOLDER).join(bunDebugIdToUuid(bunDebugId)),
76
+ "utf8"
77
+ );
78
+ }
79
+ return {
80
+ name: pluginName,
81
+ setup(build) {
82
+ const config = build.config;
83
+ if (!config) {
84
+ return;
85
+ }
86
+ const injectDebugIds = options.sourcemaps?.disable !== true && !!config.outdir && !!config.sourcemap && config.sourcemap !== "none";
87
+ const injectionCode = new utils.CodeInjection();
88
+ injectionCode.append(staticInjectionCode);
89
+ if (injectDebugIds) {
90
+ injectionCode.append(index.getDebugIdSnippet(DEBUG_ID_PLACEHOLDER));
91
+ }
92
+ if (!injectionCode.isEmpty()) {
93
+ config.banner = config.banner ? `${config.banner}
94
+ ${injectionCode.code()}` : injectionCode.code();
95
+ }
96
+ if (Object.keys(replacementValues).length > 0) {
97
+ const replacementStringValues = {};
98
+ Object.entries(replacementValues).forEach(([key, value]) => {
99
+ replacementStringValues[key] = JSON.stringify(value);
100
+ });
101
+ config.define = { ...config.define, ...replacementStringValues };
102
+ }
103
+ const freeGlobalDependencyOnBuildArtifacts = createDependencyOnBuildArtifacts();
104
+ const upload = debugIdUpload.createDebugIdUploadFunction({ sentryBuildPluginManager });
105
+ build.onEnd(async (result) => {
106
+ try {
107
+ await sentryBuildPluginManager.createRelease();
108
+ if (injectDebugIds) {
109
+ const bundlePaths = result.outputs.filter((output) => output.kind === "entry-point" || output.kind === "chunk").map((output) => output.path);
110
+ await Promise.all(bundlePaths.map(replaceDebugIdPlaceholder));
111
+ if (options.sourcemaps?.disable !== "disable-upload") {
112
+ await upload(bundlePaths);
113
+ }
114
+ }
115
+ } finally {
116
+ freeGlobalDependencyOnBuildArtifacts();
117
+ await sentryBuildPluginManager.deleteArtifacts();
118
+ }
119
+ });
120
+ }
121
+ };
122
+ }
123
+
124
+ exports.default = sentryBunPlugin;
125
+ exports.sentryBunPlugin = sentryBunPlugin;
126
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","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 options.sourcemaps?.disable !== true && !!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 (options.sourcemaps?.disable !== 'disable-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"],"names":["createSentryBuildPluginManager","CodeInjection","generateReleaseInjectorCode","generateModuleMetadataInjectorCode","fs","getDebugIdSnippet","createDebugIdUploadFunction"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAM,UAAA,GAAa,mBAAA;AAKnB,MAAM,oBAAA,GAAuB,sCAAA;AAG7B,MAAM,kBAAA,GAAqB,8DAAA;AAE3B,SAAS,iBAAiB,UAAA,EAA4B;AACpD,EAAA,MAAM,GAAA,GAAM,WAAW,WAAA,EAAY;AACnC,EAAA,OAAO,CAAA,EAAG,GAAA,CAAI,KAAA,CAAM,CAAA,EAAG,CAAC,CAAC,CAAA,CAAA,EAAI,GAAA,CAAI,KAAA,CAAM,CAAA,EAAG,EAAE,CAAC,CAAA,CAAA,EAAI,GAAA,CAAI,KAAA,CAAM,EAAA,EAAI,EAAE,CAAC,CAAA,CAAA,EAAI,GAAA,CAAI,KAAA,CAAM,EAAA,EAAI,EAAE,CAAC,CAAA,CAAA,EAAI,GAAA,CAAI,KAAA,CAAM,EAAE,CAAC,CAAA,CAAA;AAC1G;AAEO,SAAS,eAAA,CAAgB,WAAA,GAAuB,EAAC,EAAc;AACpE,EAAA,MAAM,wBAAA,GAA2BA,kDAA+B,WAAA,EAAa;AAAA,IAC3E,YAAA,EAAc,WAAA,CAAY,YAAA,EAAc,oBAAA,IAAwB,IAAI,UAAU,CAAA,CAAA,CAAA;AAAA,IAC9E,SAAA,EAAW,KAAA;AAAA,IACX,qBAAA,EAAuB,QAAQ,QAAA,CAAS,KAAK,GAAG,KAAA,CAAM,GAAG,EAAE,CAAC;AAAA,GAC7D,CAAA;AAED,EAAA,MAAM;AAAA,IACJ,MAAA;AAAA,IACA,iBAAA,EAAmB,OAAA;AAAA,IACnB,uCAAA,EAAyC,iBAAA;AAAA,IACzC,cAAA;AAAA,IACA;AAAA,GAC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AK,CAAA,KAAM;AAC1D,UAAA,uBAAA,CAAwB,GAAG,CAAA,GAAI,IAAA,CAAK,SAAA,CAAU,KAAK,CAAA;AAAA,QACrD,CAAC,CAAA;AAED,QAAA,MAAA,CAAO,SAAS,EAAE,GAAG,MAAA,CAAO,MAAA,EAAQ,GAAG,uBAAA,EAAwB;AAAA,MACjE;AAEA,MAAA,MAAM,uCAAuC,gCAAA,EAAiC;AAC9E,MAAA,MAAM,MAAA,GAASC,yCAAA,CAA4B,EAAE,wBAAA,EAA0B,CAAA;AAEvE,MAAA,KAAA,CAAM,KAAA,CAAM,OAAM,MAAA,KAAU;AAC1B,QAAA,IAAI;AACF,UAAA,MAAM,yBAAyB,aAAA,EAAc;AAE7C,UAAA,IAAI,cAAA,EAAgB;AAClB,YAAA,MAAM,WAAA,GAAc,MAAA,CAAO,OAAA,CACxB,MAAA,CAAO,YAAU,MAAA,CAAO,IAAA,KAAS,aAAA,IAAiB,MAAA,CAAO,SAAS,OAAO,CAAA,CACzE,GAAA,CAAI,CAAA,MAAA,KAAU,OAAO,IAAI,CAAA;AAE5B,YAAA,MAAM,OAAA,CAAQ,GAAA,CAAI,WAAA,CAAY,GAAA,CAAI,yBAAyB,CAAC,CAAA;AAE5D,YAAA,IAAI,OAAA,CAAQ,UAAA,EAAY,OAAA,KAAY,gBAAA,EAAkB;AACpD,cAAA,MAAM,OAAO,WAAW,CAAA;AAAA,YAC1B;AAAA,UACF;AAAA,QACF,CAAA,SAAE;AACA,UAAA,oCAAA,EAAqC;AACrC,UAAA,MAAM,yBAAyB,eAAA,EAAgB;AAAA,QACjD;AAAA,MACF,CAAC,CAAA;AAAA,IACH;AAAA,GACF;AACF;;;;;"}
@@ -5,6 +5,7 @@ const dotenv = require('dotenv');
5
5
  const fs = require('fs');
6
6
  const os = require('os');
7
7
  const path = require('path');
8
+ const glob$1 = require('glob');
8
9
  const cli = require('./cli.js');
9
10
  const optionsMapping = require('./options-mapping.js');
10
11
  const logger = require('./logger.js');
@@ -12,6 +13,7 @@ const telemetry = require('./sentry/telemetry.js');
12
13
  const utils = require('./utils.js');
13
14
  const debugIdUpload = require('./debug-id-upload.js');
14
15
  const glob = require('./glob.js');
16
+ const sourcemapSettings = require('./sourcemap-settings.js');
15
17
  const version = require('./version.js');
16
18
 
17
19
  function _interopNamespace(e) {
@@ -61,7 +63,20 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
61
63
  bundleMetadata: {},
62
64
  createRelease: async () => {
63
65
  },
64
- uploadSourcemaps: async () => {
66
+ uploadSourcemaps: async () => ({ uploaded: false }),
67
+ createUploadStaging: async () => ({
68
+ dir: "",
69
+ count: 0,
70
+ stagedChunkPaths: /* @__PURE__ */ new Set(),
71
+ stage: async () => "skipped",
72
+ discard: async () => {
73
+ },
74
+ keep: async () => {
75
+ }
76
+ }),
77
+ sourceMaps: {
78
+ uploadPossible: false,
79
+ decide: () => ({ enableHidden: false, deleteAfterUpload: false })
65
80
  },
66
81
  deleteArtifacts: async () => {
67
82
  },
@@ -142,6 +157,8 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
142
157
  notifyBuildArtifactDependencySubscribers();
143
158
  };
144
159
  }
160
+ const sourceMapUploadPossible = getSourceMapUploadBlocker(options, isDevMode) === void 0;
161
+ const loggedSourceMapMessages = /* @__PURE__ */ new Set();
145
162
  function waitUntilBuildArtifactDependenciesAreFreed() {
146
163
  return new Promise((resolve) => {
147
164
  buildArtifactsDependencySubscribers.push(() => {
@@ -354,21 +371,20 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
354
371
  * @param opts - Optional flags to control temp folder usage and preparation
355
372
  */
356
373
  async uploadSourcemaps(buildArtifactPaths, opts) {
374
+ const staging = opts?.staging;
357
375
  if (!canUploadSourceMaps(options, logger$1, isDevMode)) {
358
- return;
376
+ await staging?.discard();
377
+ return { uploaded: false };
359
378
  }
360
379
  const assets = options.sourcemaps?.assets;
361
- if (Array.isArray(assets) && assets.length === 0) {
362
- logger$1.debug("Empty `sourcemaps.assets` option provided. Will not upload sourcemaps with debug ID.");
363
- return;
364
- }
380
+ let uploaded = false;
365
381
  await core.startSpan(
366
382
  // This is `forceTransaction`ed because this span is used in dashboards in the form of indexed transactions.
367
383
  // oxlint-disable-next-line typescript/no-deprecated
368
384
  { name: "debug-id-sourcemap-upload", scope: sentryScope, forceTransaction: true },
369
385
  async () => {
370
386
  const shouldPrepare = opts?.prepareArtifacts ?? true;
371
- let folderToCleanUp;
387
+ let folderToCleanUp = staging?.dir;
372
388
  const freeUploadDependencyOnBuildArtifacts = createDependencyOnBuildArtifacts();
373
389
  try {
374
390
  if (!shouldPrepare) {
@@ -381,6 +397,15 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
381
397
  } else {
382
398
  pathsToUpload = buildArtifactPaths;
383
399
  }
400
+ if (staging && staging.count > 0) {
401
+ pathsToUpload = [...pathsToUpload, staging.dir];
402
+ }
403
+ if (pathsToUpload.length === 0) {
404
+ logger$1.warn(
405
+ "Didn't find any matching sources for debug ID upload. Please check the `sourcemaps.assets` option."
406
+ );
407
+ return;
408
+ }
384
409
  await core.startSpan({ name: "upload", scope: sentryScope }, async () => {
385
410
  const cliInstance = new cli.SentryCliAdapter(options);
386
411
  await cliInstance.uploadSourcemaps(
@@ -392,6 +417,7 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
392
417
  }))
393
418
  );
394
419
  });
420
+ uploaded = true;
395
421
  logger$1.info("Successfully uploaded source maps to Sentry");
396
422
  } else {
397
423
  let globAssets;
@@ -401,31 +427,31 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
401
427
  logger$1.debug(
402
428
  "No `sourcemaps.assets` option provided, falling back to uploading detected build artifacts."
403
429
  );
404
- globAssets = buildArtifactPaths;
430
+ globAssets = buildArtifactPaths.map((asset) => glob$1.escape(asset.split(path__namespace.sep).join("/")));
405
431
  }
406
432
  const globResult = await core.startSpan(
407
433
  { name: "glob", scope: sentryScope },
408
434
  async () => glob.globFiles(globAssets, { ignore: options.sourcemaps?.ignore })
409
435
  );
410
436
  const debugIdChunkFilePaths = globResult.filter((debugIdChunkFilePath) => {
411
- return !!utils.stripQueryAndHashFromPath(debugIdChunkFilePath).match(/\.(js|mjs|cjs)$/);
437
+ const filePath = utils.stripQueryAndHashFromPath(debugIdChunkFilePath);
438
+ return !!filePath.match(/\.(js|mjs|cjs)$/) && !staging?.stagedChunkPaths.has(path__namespace.resolve(filePath));
412
439
  });
413
440
  debugIdChunkFilePaths.sort();
414
- if (debugIdChunkFilePaths.length === 0) {
441
+ const stagedCount = staging?.count ?? 0;
442
+ if (debugIdChunkFilePaths.length === 0 && stagedCount === 0) {
415
443
  logger$1.warn(
416
444
  "Didn't find any matching sources for debug ID upload. Please check the `sourcemaps.assets` option."
417
445
  );
418
446
  } else {
419
- const tmpUploadFolder = await core.startSpan({ name: "mkdtemp", scope: sentryScope }, async () => {
420
- return process.env?.["SENTRY_TEST_OVERRIDE_TEMP_DIR"] || await fs__namespace.promises.mkdtemp(path__namespace.join(os__namespace.tmpdir(), "sentry-bundler-plugin-upload-"));
421
- });
447
+ const tmpUploadFolder = staging?.dir ?? await core.startSpan({ name: "mkdtemp", scope: sentryScope }, () => createTempUploadFolder());
422
448
  folderToCleanUp = tmpUploadFolder;
423
449
  await core.startSpan({ name: "prepare-bundles", scope: sentryScope }, async (prepBundlesSpan) => {
424
450
  const preparationTasks = debugIdChunkFilePaths.map((chunkFilePath, chunkIndex) => async () => {
425
451
  await debugIdUpload.prepareBundleForDebugIdUpload(
426
452
  chunkFilePath,
427
453
  tmpUploadFolder,
428
- chunkIndex,
454
+ stagedCount + chunkIndex,
429
455
  logger$1,
430
456
  options.sourcemaps?.rewriteSources ?? debugIdUpload.defaultRewriteSourcesHook,
431
457
  options.sourcemaps?.resolveSourceMap
@@ -454,7 +480,7 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
454
480
  core.setMeasurement("upload_size", uploadSize, "byte", prepBundlesSpan);
455
481
  if (files.length === 0) {
456
482
  logger$1.warn(
457
- `No source maps found for any of the ${debugIdChunkFilePaths.length} matched build artifacts, so no source maps were uploaded to Sentry. This usually means source map generation is not enabled in your bundler. Enable it so Sentry can un-minify your stack traces.`
483
+ `No source maps found for any of the ${debugIdChunkFilePaths.length + stagedCount} matched build artifacts, so no source maps were uploaded to Sentry. This usually means source map generation is not enabled in your bundler. Enable it so Sentry can un-minify your stack traces.`
458
484
  );
459
485
  return;
460
486
  }
@@ -467,11 +493,16 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
467
493
  }
468
494
  ]);
469
495
  });
496
+ uploaded = true;
470
497
  logger$1.info("Successfully uploaded source maps to Sentry");
471
498
  });
472
499
  }
473
500
  }
474
501
  } catch (e) {
502
+ if (staging && folderToCleanUp) {
503
+ await staging.keep("Source map upload failed.");
504
+ folderToCleanUp = void 0;
505
+ }
475
506
  sentryScope.captureException('Error in "debugIdUploadPlugin" writeBundle hook');
476
507
  handleRecoverableError(e, false);
477
508
  } finally {
@@ -496,6 +527,82 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
496
527
  }
497
528
  }
498
529
  );
530
+ return { uploaded };
531
+ },
532
+ async createUploadStaging() {
533
+ const dir = await createTempUploadFolder();
534
+ const rewriteSourcesHook = options.sourcemaps?.rewriteSources ?? debugIdUpload.defaultRewriteSourcesHook;
535
+ let count = 0;
536
+ let discarded = false;
537
+ const stagedChunkPaths = /* @__PURE__ */ new Set();
538
+ const discard = async () => {
539
+ if (discarded) {
540
+ return;
541
+ }
542
+ discarded = true;
543
+ if (process.env["SENTRY_TEST_OVERRIDE_TEMP_DIR"]) {
544
+ return;
545
+ }
546
+ try {
547
+ await fs__namespace.promises.rm(dir, { recursive: true, force: true });
548
+ } catch (e) {
549
+ logger$1.debug(`Failed to remove staging folder ${dir}:`, e);
550
+ }
551
+ };
552
+ return {
553
+ dir,
554
+ get count() {
555
+ return count;
556
+ },
557
+ stagedChunkPaths,
558
+ async stage(input) {
559
+ const result = debugIdUpload.prepareArtifactForUpload({
560
+ code: input.code,
561
+ mapSource: input.mapSource,
562
+ mapDir: input.mapDir,
563
+ rewriteSourcesHook
564
+ });
565
+ if (!result.ok) {
566
+ logger$1.debug(`Not staging ${input.fileName} for upload: ${result.reason}`);
567
+ return "skipped";
568
+ }
569
+ const index = count++;
570
+ try {
571
+ await debugIdUpload.writePreparedArtifact(dir, `${result.artifact.debugId}-${index}`, result.artifact);
572
+ stagedChunkPaths.add(path__namespace.resolve(input.mapDir, path__namespace.basename(input.fileName)));
573
+ return "staged";
574
+ } catch (e) {
575
+ sentryScope.captureException("Error staging build artifact for upload");
576
+ handleRecoverableError(e, true);
577
+ return "failed";
578
+ }
579
+ },
580
+ discard,
581
+ async keep(reason) {
582
+ if (count === 0) {
583
+ await discard();
584
+ return;
585
+ }
586
+ if (discarded) {
587
+ return;
588
+ }
589
+ discarded = true;
590
+ logger$1.error(
591
+ `${reason} The source maps were kept in ${dir}. Upload them with \`sentry sourcemap upload ${dir}\`.`
592
+ );
593
+ }
594
+ };
595
+ },
596
+ sourceMaps: {
597
+ uploadPossible: sourceMapUploadPossible,
598
+ decide(kind) {
599
+ const decision = sourcemapSettings.decideSourceMapHandling(kind, options, sourceMapUploadPossible);
600
+ if (decision.log && !loggedSourceMapMessages.has(decision.log.message)) {
601
+ loggedSourceMapMessages.add(decision.log.message);
602
+ logger$1[decision.log.level](decision.log.message);
603
+ }
604
+ return decision;
605
+ }
499
606
  },
500
607
  /**
501
608
  * Will delete artifacts based on the passed `sourcemaps.filesToDeleteAfterUpload` option.
@@ -527,34 +634,59 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
527
634
  createDependencyOnBuildArtifacts
528
635
  };
529
636
  }
530
- function canUploadSourceMaps(options, logger, isDevMode) {
637
+ async function createTempUploadFolder() {
638
+ return process.env["SENTRY_TEST_OVERRIDE_TEMP_DIR"] || await fs__namespace.promises.mkdtemp(path__namespace.join(os__namespace.tmpdir(), "sentry-bundler-plugin-upload-"));
639
+ }
640
+ function getSourceMapUploadBlocker(options, isDevMode) {
531
641
  if (options.sourcemaps?.disable) {
532
- logger.debug("Source map upload was disabled. Will not upload sourcemaps using debug ID process.");
533
- return false;
642
+ return "disabled";
643
+ }
644
+ if (Array.isArray(options.sourcemaps?.assets) && options.sourcemaps.assets.length === 0) {
645
+ return "no-assets";
534
646
  }
535
647
  if (isDevMode) {
536
- logger.debug("Running in development mode. Will not upload sourcemaps.");
537
- return false;
648
+ return "dev-mode";
538
649
  }
539
650
  if (!options.authToken) {
540
- logger.warn(
541
- `No auth token provided. Will not upload source maps. Please set the \`authToken\` option. You can find information on how to generate a Sentry auth token here: https://docs.sentry.io/api/auth/${utils.getTurborepoEnvPassthroughWarning("SENTRY_AUTH_TOKEN")}`
542
- );
543
- return false;
651
+ return "no-auth-token";
544
652
  }
545
653
  if (!options.org && !options.authToken.startsWith("sntrys_")) {
546
- logger.warn(
547
- `No org provided. Will not upload source maps. Please set the \`org\` option to your Sentry organization slug.${utils.getTurborepoEnvPassthroughWarning("SENTRY_ORG")}`
548
- );
549
- return false;
654
+ return "no-org";
550
655
  }
551
656
  if (!utils.getProjects(options.project)?.[0]) {
552
- logger.warn(
553
- `No project provided. Will not upload source maps. Please set the \`project\` option to your Sentry project slug.${utils.getTurborepoEnvPassthroughWarning("SENTRY_PROJECT")}`
554
- );
555
- return false;
657
+ return "no-project";
658
+ }
659
+ return void 0;
660
+ }
661
+ function canUploadSourceMaps(options, logger, isDevMode) {
662
+ switch (getSourceMapUploadBlocker(options, isDevMode)) {
663
+ case "disabled":
664
+ logger.debug("Source map upload was disabled. Will not upload sourcemaps using debug ID process.");
665
+ return false;
666
+ case "no-assets":
667
+ logger.debug("Empty `sourcemaps.assets` option provided. Will not upload sourcemaps with debug ID.");
668
+ return false;
669
+ case "dev-mode":
670
+ logger.debug("Running in development mode. Will not upload sourcemaps.");
671
+ return false;
672
+ case "no-auth-token":
673
+ logger.warn(
674
+ `No auth token provided. Will not upload source maps. Please set the \`authToken\` option. You can find information on how to generate a Sentry auth token here: https://docs.sentry.io/api/auth/${utils.getTurborepoEnvPassthroughWarning("SENTRY_AUTH_TOKEN")}`
675
+ );
676
+ return false;
677
+ case "no-org":
678
+ logger.warn(
679
+ `No org provided. Will not upload source maps. Please set the \`org\` option to your Sentry organization slug.${utils.getTurborepoEnvPassthroughWarning("SENTRY_ORG")}`
680
+ );
681
+ return false;
682
+ case "no-project":
683
+ logger.warn(
684
+ `No project provided. Will not upload source maps. Please set the \`project\` option to your Sentry project slug.${utils.getTurborepoEnvPassthroughWarning("SENTRY_PROJECT")}`
685
+ );
686
+ return false;
687
+ default:
688
+ return true;
556
689
  }
557
- return true;
558
690
  }
559
691
 
560
692
  exports.createSentryBuildPluginManager = createSentryBuildPluginManager;