@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 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/rollup/index.ts"],"sourcesContent":["import type { ChunkGraphNode, Options } from '../core';\nimport {\n createSentryBuildPluginManager,\n generateReleaseInjectorCode,\n generateModuleMetadataInjectorCode,\n isJsFile,\n isInitialChunk,\n shouldSkipCodeInjection,\n getDebugIdSnippet,\n createDebugIdUploadFunction,\n globFiles,\n createComponentNameAnnotateHooks,\n replaceBooleanFlagsInCode,\n CodeInjection,\n getCodeInjectionPosition,\n} from '../core';\nimport type { ComponentAnnotationTransformMeta } from '../core/component-annotation-oxc';\nimport type { SourceMap } from 'magic-string';\nimport MagicString from 'magic-string';\nimport * as path from 'node:path';\nimport { createRequire } from 'node:module';\nimport { finalizeRolldownDebugIds, getDebugIdForChunk, hasExistingDebugID } from './debug-id-injection';\nimport { stampDebugIds, type OutputBundle } from './debug-id-stamping';\nimport { createSourceMapHandling, type OutputDestinationOptions } from './source-map-handling';\nimport { createViteSourceMapHooks } from '../vite/source-map-hooks';\n\n// The subset of Rollup's `TransformResult` that this plugin's `transform`\n// hook actually returns. Defined locally instead of imported from `rollup`\n// because `rollup` is an optional dependency.\ntype TransformResult = { code: string; map?: SourceMap | string | { mappings: string } | null } | null | undefined;\n\ntype ViteModule = {\n parseAstAsync?: (code: string, options: { lang: 'jsx' | 'tsx' }) => Promise<unknown>;\n};\n\ntype ViteParseAstAsync = NonNullable<ViteModule['parseAstAsync']>;\n\nlet viteParseAstAsyncPromise: Promise<ViteParseAstAsync | null> | undefined;\n\n// Rolldown sets `meta.rolldownVersion` on the plugin context.\ntype PluginContext = { meta?: { rolldownVersion?: string } };\n\nconst JS_MODULE_ID_FILTER = /\\.[cm]?[jt]sx?(?:[?#].*)?$/;\n\nfunction getRollupMajorVersion(): string | undefined {\n try {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore - Rollup already transpiles this for us\n const req = createRequire(import.meta.url);\n const rollup = req('rollup') as { VERSION?: string };\n return rollup.VERSION?.split('.')[0];\n } catch {\n // do nothing, we'll just not report a version\n }\n\n return undefined;\n}\n\nfunction getViteParseAstAsync(): Promise<ViteParseAstAsync | null> {\n if (!viteParseAstAsyncPromise) {\n viteParseAstAsyncPromise = Promise.resolve()\n .then(async () => {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore - Vite is an optional runtime peer for this package\n const viteModule = createRequire(import.meta.url)('vite') as ViteModule;\n\n if (typeof viteModule.parseAstAsync !== 'function') {\n return null;\n }\n\n try {\n await viteModule.parseAstAsync('const x = <div />;', { lang: 'tsx' });\n } catch {\n return null;\n }\n\n return viteModule.parseAstAsync;\n })\n .catch(() => null);\n }\n\n return viteParseAstAsyncPromise;\n}\n\n/**\n * @ignore - internal plugin factory shared by the Rollup and Vite plugins.\n *\n * `main` carries injection, release creation and the upload. `post` runs last in `generateBundle`,\n * copies chunks and their source maps into the upload staging folder and drops the map assets\n * from the bundle, so the bundler never writes them.\n */\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function _createRollupPluginInternals(\n userOptions: Options = {},\n buildTool: 'rollup' | 'vite',\n buildToolMajorVersion?: string,\n) {\n const sentryBuildPluginManager = createSentryBuildPluginManager(userOptions, {\n loggerPrefix: userOptions._metaOptions?.loggerPrefixOverride ?? `[sentry-${buildTool}-plugin]`,\n buildTool,\n buildToolMajorVersion: buildToolMajorVersion || getRollupMajorVersion(),\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 main: {\n name: 'sentry-noop-plugin',\n },\n post: undefined,\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 freeGlobalDependencyOnBuildArtifacts = createDependencyOnBuildArtifacts();\n const upload = createDebugIdUploadFunction({ sentryBuildPluginManager });\n const sourcemapsEnabled = options.sourcemaps?.disable !== true;\n const sourceMapHandling = createSourceMapHandling(sentryBuildPluginManager);\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 {\n // Vite 8 already loads an oxc-based parser, so reuse it.\n getParseAstAsync: buildTool === 'vite' && buildToolMajorVersion === '8' ? getViteParseAstAsync : undefined,\n logger,\n },\n )\n : undefined;\n\n const transformReplace = Object.keys(replacementValues).length > 0;\n const shouldTransform = transformAnnotations || transformReplace;\n\n function buildStart(): void {\n void sentryBuildPluginManager.telemetry.emitBundlerPluginExecutionSignal().catch(() => {\n // Telemetry failures are acceptable\n });\n }\n\n async function transform(\n code: string,\n id: string,\n meta?: ComponentAnnotationTransformMeta,\n ): Promise<TransformResult> {\n // Component annotations are only in user code and boolean flag replacements are\n // only in Sentry code. If we successfully add annotations, we can return early.\n if (transformAnnotations) {\n const result = await transformAnnotations.transform(code, id, meta);\n if (result) {\n return result;\n }\n }\n\n if (transformReplace) {\n return replaceBooleanFlagsInCode(code, replacementValues);\n }\n\n return null;\n }\n\n function renderChunk(\n this: PluginContext | undefined,\n code: string,\n chunk: { fileName: string; facadeModuleId?: string | null; isEntry?: boolean },\n _?: unknown,\n meta?: { magicString?: MagicString; chunks?: Record<string, ChunkGraphNode> },\n ): {\n code: string;\n map?: SourceMap;\n } | null {\n if (!isJsFile(chunk.fileName)) {\n return null; // returning null means not modifying the chunk at all\n }\n\n // Skip empty chunks and HTML facade chunks (Vite MPA)\n if (shouldSkipCodeInjection(code, chunk.facadeModuleId)) {\n return null;\n }\n\n const injectCode = new CodeInjection();\n\n if (isInitialChunk(chunk, meta?.chunks)) {\n injectCode.append(releaseInjectionCode);\n }\n\n injectCode.append(chunkInjectionCode);\n\n if (sourcemapsEnabled && !hasExistingDebugID(code)) {\n const debugId = getDebugIdForChunk(code, !!this?.meta?.rolldownVersion);\n injectCode.append(getDebugIdSnippet(debugId));\n }\n\n if (injectCode.isEmpty()) {\n return null;\n }\n\n const ms = meta?.magicString || new MagicString(code, { filename: chunk.fileName });\n const injectionPosition = getCodeInjectionPosition(code);\n const codeToInject = injectionPosition === code.length ? `\\n${injectCode.code()}` : injectCode.code();\n ms.appendLeft(injectionPosition, codeToInject);\n\n // Rolldown can pass a native MagicString instance in meta.magicString\n // https://rolldown.rs/in-depth/native-magic-string#usage-examples\n if (ms?.constructor?.name === 'BindingMagicString') {\n // Rolldown docs say to return the magic string instance directly in this case\n return { code: ms as unknown as string };\n }\n\n return {\n code: ms.toString(),\n map: ms.generateMap({ file: chunk.fileName, hires: 'boundary' }),\n };\n }\n\n /**\n * Resolves Rolldown's placeholder debug IDs, then stamps debug IDs into the emitted chunks and\n * source maps.\n *\n * `disable-upload` skips the upload routine (which stamps debug IDs into temp copies), so the emitted\n * artifacts get stamped here instead. Not in `renderChunk`: minifiers running after it would strip the\n * comment. Rollup computes `[hash]` file names before this hook, so only plugins that hash the final\n * assets afterwards (e.g. subresource integrity) see the stamped content.\n */\n function generateBundle(this: PluginContext | undefined, _outputOptions: unknown, bundle: OutputBundle): void {\n if (this?.meta?.rolldownVersion) {\n finalizeRolldownDebugIds(bundle);\n }\n\n if (options.sourcemaps?.disable !== 'disable-upload') {\n return;\n }\n\n stampDebugIds(bundle, true);\n }\n\n async function writeBundle(outputOptions: OutputDestinationOptions, bundle: OutputBundle | undefined): Promise<void> {\n const staging = await sourceMapHandling.takeStaging(outputOptions, bundle);\n let stagingHandedOver = false;\n\n try {\n await sentryBuildPluginManager.createRelease();\n\n if (sourcemapsEnabled && options.sourcemaps?.disable !== 'disable-upload') {\n let buildArtifacts: string[];\n if (outputOptions.dir) {\n const outputDir = outputOptions.dir;\n const JS_AND_MAP_PATTERNS = [\n '/**/*.js',\n '/**/*.mjs',\n '/**/*.cjs',\n '/**/*.js.map',\n '/**/*.mjs.map',\n '/**/*.cjs.map',\n ].map(q => `${q}?(\\\\?*)?(#*)`); // We want to allow query and hash strings at the end of files\n buildArtifacts = await globFiles(JS_AND_MAP_PATTERNS, { root: outputDir });\n } else if (outputOptions.file) {\n buildArtifacts = [outputOptions.file];\n } else {\n buildArtifacts = Object.keys(bundle ?? {}).map(asset => path.join(path.resolve(), asset));\n }\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 const name = `sentry-${buildTool}-plugin`;\n const transformHook =\n buildTool === 'vite'\n ? {\n filter: { id: JS_MODULE_ID_FILTER },\n handler: transform,\n }\n : transform;\n\n // Vite warns about `rollupOptions.output.sourcemap`, so the Vite plugin\n // decides in a `config` hook instead.\n const viteSourceMapHooks =\n buildTool === 'vite' ? createViteSourceMapHooks(sentryBuildPluginManager, sourceMapHandling) : undefined;\n\n const main = {\n name,\n buildStart,\n ...(shouldTransform ? { transform: transformHook } : {}),\n ...(viteSourceMapHooks\n ? { configResolved: viteSourceMapHooks.configResolved }\n : { outputOptions: sourceMapHandling.outputOptions }),\n renderChunk,\n generateBundle: { order: 'pre' as const, handler: generateBundle },\n writeBundle,\n };\n\n const post = {\n name: buildTool === 'vite' ? 'sentry-vite-upload-staging' : 'sentry-rollup-upload-staging',\n // On the post plugin, so framework plugins that set `build.sourcemap`\n // themselves run first and the decision sees the merged setting.\n ...(viteSourceMapHooks ? { config: viteSourceMapHooks.config } : {}),\n generateBundle: {\n order: 'post' as const,\n async handler(outputOptions: OutputDestinationOptions, bundle: OutputBundle, isWrite?: boolean): Promise<void> {\n if (buildTool === 'vite' && options.sourcemaps?.disable === 'disable-upload') {\n // Vite's module preload rewrite in `generateBundle` regenerates the source map of every\n // chunk with a dynamic import, which drops the debug ID the main plugin stamped in its\n // `pre` hook. Restore it without touching the chunk code, so file hashes stay valid.\n stampDebugIds(bundle, false);\n }\n\n await sourceMapHandling.stageSourceMaps(outputOptions, bundle, isWrite);\n },\n },\n };\n\n return { main, post };\n}\n\n/**\n * @ignore - this is the internal plugin factory function only used for the Vite plugin!\n */\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function _rollupPluginInternal(\n userOptions: Options = {},\n buildTool: 'rollup' | 'vite',\n buildToolMajorVersion?: string,\n) {\n return _createRollupPluginInternals(userOptions, buildTool, buildToolMajorVersion).main;\n}\n\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/no-explicit-any\nexport function sentryRollupPlugin(userOptions: Options = {}): any {\n const { main, post } = _createRollupPluginInternals(userOptions, 'rollup');\n // We return an array here so we don't break backwards compatibility with what\n // unplugin used to return\n return post ? [main, post] : [main];\n}\n\nexport type { Options as SentryRollupPluginOptions } from '../core';\n"],"names":["createRequire","createSentryBuildPluginManager","createDebugIdUploadFunction","sourceMapHandling","createSourceMapHandling","CodeInjection","generateReleaseInjectorCode","generateModuleMetadataInjectorCode","createComponentNameAnnotateHooks","replaceBooleanFlagsInCode","isJsFile","shouldSkipCodeInjection","isInitialChunk","hasExistingDebugID","getDebugIdForChunk","getDebugIdSnippet","MagicString","getCodeInjectionPosition","finalizeRolldownDebugIds","stampDebugIds","globFiles","path","createViteSourceMapHooks"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,IAAI,wBAAA;AAKJ,MAAM,mBAAA,GAAsB,4BAAA;AAE5B,SAAS,qBAAA,GAA4C;AACnD,EAAA,IAAI;AAGF,IAAA,MAAM,GAAA,GAAMA,yBAAA,CAAc,iQAAe,CAAA;AACzC,IAAA,MAAM,MAAA,GAAS,IAAI,QAAQ,CAAA;AAC3B,IAAA,OAAO,MAAA,CAAO,OAAA,EAAS,KAAA,CAAM,GAAG,EAAE,CAAC,CAAA;AAAA,EACrC,CAAA,CAAA,MAAQ;AAAA,EAER;AAEA,EAAA,OAAO,MAAA;AACT;AAEA,SAAS,oBAAA,GAA0D;AACjE,EAAA,IAAI,CAAC,wBAAA,EAA0B;AAC7B,IAAA,wBAAA,GAA2B,OAAA,CAAQ,OAAA,EAAQ,CACxC,IAAA,CAAK,YAAY;AAGhB,MAAA,MAAM,UAAA,GAAaA,yBAAA,CAAc,iQAAe,EAAE,MAAM,CAAA;AAExD,MAAA,IAAI,OAAO,UAAA,CAAW,aAA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,MAAA;AAAA,MACP,MAAM,OAAA,CAAQ,aAAA,EAAyC,MAAA,EAAsB,OAAA,EAAkC;AAC7G,QAAA,IAAI,SAAA,KAAc,MAAA,IAAU,OAAA,CAAQ,UAAA,EAAY,YAAY,gBAAA,EAAkB;AAI5E,UAAAgB,6BAAA,CAAc,QAAQ,KAAK,CAAA;AAAA,QAC7B;AAEA,QAAA,MAAMhB,mBAAA,CAAkB,eAAA,CAAgB,aAAA,EAAe,MAAA,EAAQ,OAAO,CAAA;AAAA,MACxE;AAAA;AACF,GACF;AAEA,EAAA,OAAO,EAAE,MAAM,IAAA,EAAK;AACtB;AAMO,SAAS,qBAAA,CACd,WAAA,GAAuB,EAAC,EACxB,WACA,qBAAA,EACA;AACA,EAAA,OAAO,4BAAA,CAA6B,WAAA,EAAa,SAAA,EAAW,qBAAqB,CAAA,CAAE,IAAA;AACrF;AAGO,SAAS,kBAAA,CAAmB,WAAA,GAAuB,EAAC,EAAQ;AACjE,EAAA,MAAM,EAAE,IAAA,EAAM,IAAA,EAAK,GAAI,4BAAA,CAA6B,aAAa,QAAQ,CAAA;AAGzE,EAAA,OAAO,OAAO,CAAC,IAAA,EAAM,IAAI,CAAA,GAAI,CAAC,IAAI,CAAA;AACpC;;;;;;"}
1
+ {"version":3,"file":"index.js","names":["createRequire","createSentryBuildPluginManager","createDebugIdUploadFunction","createSourceMapHandling","CodeInjection","generateReleaseInjectorCode","generateModuleMetadataInjectorCode","createComponentNameAnnotateHooks","replaceBooleanFlagsInCode","isJsFile","shouldSkipCodeInjection","isInitialChunk","hasExistingDebugID","getDebugIdForChunk","getDebugIdSnippet","MagicString","getCodeInjectionPosition","finalizeRolldownDebugIds","stampDebugIds","globFiles","path","createViteSourceMapHooks"],"sources":["../../../src/rollup/index.ts"],"sourcesContent":["import type { ChunkGraphNode, InternalOptions, Options } from '../core';\nimport {\n createSentryBuildPluginManager,\n generateReleaseInjectorCode,\n generateModuleMetadataInjectorCode,\n isJsFile,\n isInitialChunk,\n shouldSkipCodeInjection,\n getDebugIdSnippet,\n createDebugIdUploadFunction,\n globFiles,\n createComponentNameAnnotateHooks,\n replaceBooleanFlagsInCode,\n CodeInjection,\n getCodeInjectionPosition,\n} from '../core';\nimport type { ComponentAnnotationTransformMeta } from '../core/component-annotation-oxc';\nimport type { SourceMap } from 'magic-string';\nimport MagicString from 'magic-string';\nimport * as path from 'node:path';\nimport { createRequire } from 'node:module';\nimport { finalizeRolldownDebugIds, getDebugIdForChunk, hasExistingDebugID } from './debug-id-injection';\nimport { stampDebugIds, type OutputBundle } from './debug-id-stamping';\nimport { createSourceMapHandling, type OutputDestinationOptions } from './source-map-handling';\nimport { createViteSourceMapHooks } from '../vite/source-map-hooks';\n\n// The subset of Rollup's `TransformResult` that this plugin's `transform`\n// hook actually returns. Defined locally instead of imported from `rollup`\n// because `rollup` is an optional dependency.\ntype TransformResult = { code: string; map?: SourceMap | string | { mappings: string } | null } | null | undefined;\n\ntype ViteModule = {\n parseAstAsync?: (code: string, options: { lang: 'jsx' | 'tsx' }) => Promise<unknown>;\n};\n\ntype ViteParseAstAsync = NonNullable<ViteModule['parseAstAsync']>;\n\nlet viteParseAstAsyncPromise: Promise<ViteParseAstAsync | null> | undefined;\n\n// Rolldown sets `meta.rolldownVersion` on the plugin context.\ntype PluginContext = { meta?: { rolldownVersion?: string } };\n\nconst JS_MODULE_ID_FILTER = /\\.[cm]?[jt]sx?(?:[?#].*)?$/;\n\nfunction getRollupMajorVersion(): string | undefined {\n try {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore - Rollup already transpiles this for us\n const req = createRequire(import.meta.url);\n const rollup = req('rollup') as { VERSION?: string };\n return rollup.VERSION?.split('.')[0];\n } catch {\n // do nothing, we'll just not report a version\n }\n\n return undefined;\n}\n\nfunction getViteParseAstAsync(): Promise<ViteParseAstAsync | null> {\n if (!viteParseAstAsyncPromise) {\n viteParseAstAsyncPromise = Promise.resolve()\n .then(async () => {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore - Vite is an optional runtime peer for this package\n const viteModule = createRequire(import.meta.url)('vite') as ViteModule;\n\n if (typeof viteModule.parseAstAsync !== 'function') {\n return null;\n }\n\n try {\n await viteModule.parseAstAsync('const x = <div />;', { lang: 'tsx' });\n } catch {\n return null;\n }\n\n return viteModule.parseAstAsync;\n })\n .catch(() => null);\n }\n\n return viteParseAstAsyncPromise;\n}\n\n/**\n * @ignore - internal plugin factory shared by the Rollup and Vite plugins.\n *\n * `main` carries injection, release creation and the upload. `post` runs last in `generateBundle`,\n * copies chunks and their source maps into the upload staging folder and drops the map assets\n * from the bundle, so the bundler never writes them.\n */\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function _createRollupPluginInternals(\n userOptions: InternalOptions = {},\n buildTool: 'rollup' | 'vite',\n buildToolMajorVersion?: string,\n) {\n const sentryBuildPluginManager = createSentryBuildPluginManager(userOptions, {\n loggerPrefix: userOptions._metaOptions?.loggerPrefixOverride ?? `[sentry-${buildTool}-plugin]`,\n buildTool,\n buildToolMajorVersion: buildToolMajorVersion || getRollupMajorVersion(),\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 main: {\n name: 'sentry-noop-plugin',\n },\n post: undefined,\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 freeGlobalDependencyOnBuildArtifacts = createDependencyOnBuildArtifacts();\n const upload = createDebugIdUploadFunction({ sentryBuildPluginManager });\n const sourcemapsEnabled = options.sourcemaps?.disable !== true;\n const sourceMapHandling = createSourceMapHandling(sentryBuildPluginManager);\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 {\n // Vite 8 already loads an oxc-based parser, so reuse it.\n getParseAstAsync: buildTool === 'vite' && buildToolMajorVersion === '8' ? getViteParseAstAsync : undefined,\n logger,\n },\n )\n : undefined;\n\n const transformReplace = Object.keys(replacementValues).length > 0;\n const shouldTransform = transformAnnotations || transformReplace;\n\n function buildStart(): void {\n void sentryBuildPluginManager.telemetry.emitBundlerPluginExecutionSignal().catch(() => {\n // Telemetry failures are acceptable\n });\n }\n\n async function transform(\n code: string,\n id: string,\n meta?: ComponentAnnotationTransformMeta,\n ): Promise<TransformResult> {\n // Component annotations are only in user code and boolean flag replacements are\n // only in Sentry code. If we successfully add annotations, we can return early.\n if (transformAnnotations) {\n const result = await transformAnnotations.transform(code, id, meta);\n if (result) {\n return result;\n }\n }\n\n if (transformReplace) {\n return replaceBooleanFlagsInCode(code, replacementValues);\n }\n\n return null;\n }\n\n function renderChunk(\n this: PluginContext | undefined,\n code: string,\n chunk: { fileName: string; facadeModuleId?: string | null; isEntry?: boolean },\n _?: unknown,\n meta?: { magicString?: MagicString; chunks?: Record<string, ChunkGraphNode> },\n ): {\n code: string;\n map?: SourceMap;\n } | null {\n if (!isJsFile(chunk.fileName)) {\n return null; // returning null means not modifying the chunk at all\n }\n\n // Skip empty chunks and HTML facade chunks (Vite MPA)\n if (shouldSkipCodeInjection(code, chunk.facadeModuleId)) {\n return null;\n }\n\n const injectCode = new CodeInjection();\n\n if (isInitialChunk(chunk, meta?.chunks)) {\n injectCode.append(releaseInjectionCode);\n }\n\n injectCode.append(chunkInjectionCode);\n\n if (sourcemapsEnabled && !hasExistingDebugID(code)) {\n const debugId = getDebugIdForChunk(code, !!this?.meta?.rolldownVersion);\n injectCode.append(getDebugIdSnippet(debugId));\n }\n\n if (injectCode.isEmpty()) {\n return null;\n }\n\n const ms = meta?.magicString || new MagicString(code, { filename: chunk.fileName });\n const injectionPosition = getCodeInjectionPosition(code);\n const codeToInject = injectionPosition === code.length ? `\\n${injectCode.code()}` : injectCode.code();\n ms.appendLeft(injectionPosition, codeToInject);\n\n // Rolldown can pass a native MagicString instance in meta.magicString\n // https://rolldown.rs/in-depth/native-magic-string#usage-examples\n if (ms?.constructor?.name === 'BindingMagicString') {\n // Rolldown docs say to return the magic string instance directly in this case\n return { code: ms as unknown as string };\n }\n\n return {\n code: ms.toString(),\n map: ms.generateMap({ file: chunk.fileName, hires: 'boundary' }),\n };\n }\n\n /**\n * Resolves Rolldown's placeholder debug IDs, then stamps debug IDs into the emitted chunks and\n * source maps.\n *\n * `disable-upload` skips the upload routine (which stamps debug IDs into temp copies), so the emitted\n * artifacts get stamped here instead. Not in `renderChunk`: minifiers running after it would strip the\n * comment. Rollup computes `[hash]` file names before this hook, so only plugins that hash the final\n * assets afterwards (e.g. subresource integrity) see the stamped content.\n */\n function generateBundle(this: PluginContext | undefined, _outputOptions: unknown, bundle: OutputBundle): void {\n if (this?.meta?.rolldownVersion) {\n finalizeRolldownDebugIds(bundle);\n }\n\n if (options.sourcemaps?.disable !== 'disable-upload') {\n return;\n }\n\n stampDebugIds(bundle, true);\n }\n\n async function writeBundle(outputOptions: OutputDestinationOptions, bundle: OutputBundle | undefined): Promise<void> {\n const staging = await sourceMapHandling.takeStaging(outputOptions, bundle);\n let stagingHandedOver = false;\n\n try {\n await sentryBuildPluginManager.createRelease();\n\n if (sourcemapsEnabled && options.sourcemaps?.disable !== 'disable-upload') {\n let buildArtifacts: string[];\n if (outputOptions.dir) {\n const outputDir = outputOptions.dir;\n const JS_AND_MAP_PATTERNS = [\n '/**/*.js',\n '/**/*.mjs',\n '/**/*.cjs',\n '/**/*.js.map',\n '/**/*.mjs.map',\n '/**/*.cjs.map',\n ].map(q => `${q}?(\\\\?*)?(#*)`); // We want to allow query and hash strings at the end of files\n buildArtifacts = await globFiles(JS_AND_MAP_PATTERNS, { root: outputDir });\n } else if (outputOptions.file) {\n buildArtifacts = [outputOptions.file];\n } else {\n buildArtifacts = Object.keys(bundle ?? {}).map(asset => path.join(path.resolve(), asset));\n }\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 const name = `sentry-${buildTool}-plugin`;\n const transformHook =\n buildTool === 'vite'\n ? {\n filter: { id: JS_MODULE_ID_FILTER },\n handler: transform,\n }\n : transform;\n\n // Vite warns about `rollupOptions.output.sourcemap`, so the Vite plugin\n // decides in a `config` hook instead.\n const viteSourceMapHooks =\n buildTool === 'vite' ? createViteSourceMapHooks(sentryBuildPluginManager, sourceMapHandling) : undefined;\n\n const main = {\n name,\n buildStart,\n ...(shouldTransform ? { transform: transformHook } : {}),\n ...(viteSourceMapHooks\n ? { configResolved: viteSourceMapHooks.configResolved }\n : { outputOptions: sourceMapHandling.outputOptions }),\n renderChunk,\n generateBundle: { order: 'pre' as const, handler: generateBundle },\n writeBundle,\n };\n\n const post = {\n name: buildTool === 'vite' ? 'sentry-vite-upload-staging' : 'sentry-rollup-upload-staging',\n // On the post plugin, so framework plugins that set `build.sourcemap`\n // themselves run first and the decision sees the merged setting.\n ...(viteSourceMapHooks ? { config: viteSourceMapHooks.config } : {}),\n generateBundle: {\n order: 'post' as const,\n async handler(outputOptions: OutputDestinationOptions, bundle: OutputBundle, isWrite?: boolean): Promise<void> {\n if (buildTool === 'vite' && options.sourcemaps?.disable === 'disable-upload') {\n // Vite's module preload rewrite in `generateBundle` regenerates the source map of every\n // chunk with a dynamic import, which drops the debug ID the main plugin stamped in its\n // `pre` hook. Restore it without touching the chunk code, so file hashes stay valid.\n stampDebugIds(bundle, false);\n }\n\n await sourceMapHandling.stageSourceMaps(outputOptions, bundle, isWrite);\n },\n },\n };\n\n return { main, post };\n}\n\n/**\n * @ignore - this is the internal plugin factory function only used for the Vite plugin!\n */\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function _rollupPluginInternal(\n userOptions: Options = {},\n buildTool: 'rollup' | 'vite',\n buildToolMajorVersion?: string,\n) {\n return _createRollupPluginInternals(userOptions, buildTool, buildToolMajorVersion).main;\n}\n\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/no-explicit-any\nexport function sentryRollupPlugin(userOptions: Options = {}): any {\n const { main, post } = _createRollupPluginInternals(userOptions, 'rollup');\n // We return an array here so we don't break backwards compatibility with what\n // unplugin used to return\n return post ? [main, post] : [main];\n}\n\nexport type { Options as SentryRollupPluginOptions } from '../core';\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAqCA,IAAI;AAKJ,MAAM,sBAAsB;AAE5B,SAAS,wBAA4C;CACnD,IAAI;EAKF,QAAA,GAFYA,YAAAA,cAAAA,CAAAA,QAAAA,KAAAA,CAAAA,CAAAA,cAAAA,UAAAA,CAAAA,CAAAA,IACK,CAAC,CAAC,QACP,CAAC,CAAC,SAAS,MAAM,GAAG,CAAC,CAAC;CACpC,QAAQ,CAER;AAGF;AAEA,SAAS,uBAA0D;CACjE,IAAI,CAAC,0BACH,2BAA2B,QAAQ,QAAQ,CAAC,CACzC,KAAK,YAAY;EAGhB,MAAM,cAAA,GAAaA,YAAAA,cAAAA,CAAAA,QAAAA,KAAAA,CAAAA,CAAAA,cAAAA,UAAAA,CAAAA,CAA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AI,CAAC,mBACH,MAAM,SAAS,KAAK,oCAAoC;GAE1D,MAAM;EACR,UAAU;GACR,qCAAqC;GACrC,MAAM,yBAAyB,gBAAgB;EACjD;CACF;CAEA,MAAM,OAAO,UAAU,UAAU;CACjC,MAAM,gBACJ,cAAc,SACV;EACE,QAAQ,EAAE,IAAI,oBAAoB;EAClC,SAAS;CACX,IACA;CAIN,MAAM,qBACJ,cAAc,SAASC,yBAAAA,yBAAyB,0BAA0B,iBAAiB,IAAI,KAAA;CAkCjG,OAAO;EAAE,MAAA;GA/BP;GACA;GACA,GAAI,kBAAkB,EAAE,WAAW,cAAc,IAAI,CAAC;GACtD,GAAI,qBACA,EAAE,gBAAgB,mBAAmB,eAAe,IACpD,EAAE,eAAe,kBAAkB,cAAc;GACrD;GACA,gBAAgB;IAAE,OAAO;IAAgB,SAAS;GAAe;GACjE;EAuBU;EAAG,MAAA;GAnBb,MAAM,cAAc,SAAS,+BAA+B;GAG5D,GAAI,qBAAqB,EAAE,QAAQ,mBAAmB,OAAO,IAAI,CAAC;GAClE,gBAAgB;IACd,OAAO;IACP,MAAM,QAAQ,eAAyC,QAAsB,SAAkC;KAC7G,IAAI,cAAc,UAAU,QAAQ,YAAY,YAAY,kBAI1DH,0BAAAA,cAAc,QAAQ,KAAK;KAG7B,MAAM,kBAAkB,gBAAgB,eAAe,QAAQ,OAAO;IACxE;GACF;EAGgB;CAAE;AACtB;;;;AAMA,SAAgB,sBACd,cAAuB,CAAC,GACxB,WACA,uBACA;CACA,OAAO,6BAA6B,aAAa,WAAW,qBAAqB,CAAC,CAAC;AACrF;AAGA,SAAgB,mBAAmB,cAAuB,CAAC,GAAQ;CACjE,MAAM,EAAE,MAAM,SAAS,6BAA6B,aAAa,QAAQ;CAGzE,OAAO,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,IAAI;AACpC"}
@@ -1,202 +1,178 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
-
3
- const path = require('node:path');
4
- const index = require('../core/index.js');
5
-
6
- function _interopNamespace(e) {
7
- if (e && e.__esModule) return e;
8
- const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
9
- if (e) {
10
- for (const k in e) {
11
- n[k] = e[k];
12
- }
13
- }
14
- n.default = e;
15
- return n;
16
- }
17
-
18
- const path__namespace = /*#__PURE__*/_interopNamespace(path);
19
-
1
+ const require_runtime = require("../_virtual/_rolldown/runtime.js");
2
+ const require_index = require("../core/index.js");
3
+ let node_path = require("node:path");
4
+ node_path = require_runtime.__toESM(node_path);
5
+ // src/rollup/source-map-handling.ts
6
+ /** Maps Rollup's (and Vite's) `sourcemap` setting onto the plugin's source map kinds. */
20
7
  function sourceMapKindFromRollupSetting(setting) {
21
- switch (setting) {
22
- case void 0:
23
- return "unset";
24
- case false:
25
- return "off";
26
- case true:
27
- return "visible";
28
- default:
29
- return setting;
30
- }
8
+ switch (setting) {
9
+ case void 0: return "unset";
10
+ case false: return "off";
11
+ case true: return "visible";
12
+ default: return setting;
13
+ }
31
14
  }
15
+ /** The directory an output writes to. Decisions and stagings are keyed by it. */
32
16
  function getOutputDestination(outputOptions) {
33
- return path__namespace.resolve(outputOptions.dir ?? path__namespace.dirname(outputOptions.file ?? "."));
17
+ return node_path.resolve(outputOptions.dir ?? node_path.dirname(outputOptions.file ?? "."));
34
18
  }
35
19
  const MATCH_KEYS = [
36
- "dir",
37
- "file",
38
- "format",
39
- "entryFileNames",
40
- "chunkFileNames",
41
- "preserveModules",
42
- "sourcemap"
20
+ "dir",
21
+ "file",
22
+ "format",
23
+ "entryFileNames",
24
+ "chunkFileNames",
25
+ "preserveModules",
26
+ "sourcemap"
43
27
  ];
28
+ /** The raw options accept aliases that the normalized options do not carry. */
44
29
  function normalizeFormat(format) {
45
- switch (format) {
46
- case "esm":
47
- case "module":
48
- return "es";
49
- case "commonjs":
50
- return "cjs";
51
- case "systemjs":
52
- return "system";
53
- default:
54
- return format;
55
- }
30
+ switch (format) {
31
+ case "esm":
32
+ case "module": return "es";
33
+ case "commonjs": return "cjs";
34
+ case "systemjs": return "system";
35
+ default: return format;
36
+ }
56
37
  }
38
+ /** The fields of `OutputMatch` an output sets, in the form the normalized options carry them. */
57
39
  function getOutputMatch(outputOptions) {
58
- const match = {};
59
- for (const key of MATCH_KEYS) {
60
- const value = outputOptions[key];
61
- if (value === void 0) {
62
- continue;
63
- }
64
- match[key] = key === "format" ? normalizeFormat(value) : key === "dir" || key === "file" ? path__namespace.resolve(String(value)) : value;
65
- }
66
- return match;
40
+ const match = {};
41
+ for (const key of MATCH_KEYS) {
42
+ const value = outputOptions[key];
43
+ if (value === void 0) continue;
44
+ match[key] = key === "format" ? normalizeFormat(value) : key === "dir" || key === "file" ? node_path.resolve(String(value)) : value;
45
+ }
46
+ return match;
67
47
  }
68
48
  function matchesOutput(match, outputOptions) {
69
- const actual = getOutputMatch(outputOptions);
70
- return MATCH_KEYS.every((key) => match[key] === void 0 || match[key] === actual[key]);
49
+ const actual = getOutputMatch(outputOptions);
50
+ return MATCH_KEYS.every((key) => match[key] === void 0 || match[key] === actual[key]);
71
51
  }
72
52
  function isSameMatch(a, b) {
73
- return MATCH_KEYS.every((key) => a[key] === b[key]);
53
+ return MATCH_KEYS.every((key) => a[key] === b[key]);
74
54
  }
75
55
  function countMatchFields(match) {
76
- return MATCH_KEYS.filter((key) => match[key] !== void 0).length;
56
+ return MATCH_KEYS.filter((key) => match[key] !== void 0).length;
77
57
  }
78
58
  const DEBUG_ID_PATTERN = /sentry-dbid-([0-9a-f-]{36})|\/\/# debugId=([0-9a-f-]{36})/i;
59
+ /** Identifies the chunks of a bundle by name and debug ID, so a staging can be matched to its write. */
79
60
  function getBundleSignature(bundle) {
80
- const entries = [];
81
- for (const output of Object.values(bundle)) {
82
- if (output.type === "chunk" && index.isJsFile(output.fileName)) {
83
- const match = output.code.match(DEBUG_ID_PATTERN);
84
- entries.push(`${output.fileName}:${match?.[1] ?? match?.[2] ?? ""}`);
85
- }
86
- }
87
- return entries.sort().join("\n");
61
+ const entries = [];
62
+ for (const output of Object.values(bundle)) if (output.type === "chunk" && require_index.isJsFile(output.fileName)) {
63
+ const match = output.code.match(DEBUG_ID_PATTERN);
64
+ entries.push(`${output.fileName}:${match?.[1] ?? match?.[2] ?? ""}`);
65
+ }
66
+ return entries.sort().join("\n");
88
67
  }
89
68
  function getSourceMapFileName(output) {
90
- return output.sourcemapFileName ?? `${output.fileName}.map`;
69
+ return output.sourcemapFileName ?? `${output.fileName}.map`;
91
70
  }
71
+ /**
72
+ * Source map decisions and upload stagings of one plugin instance. Keyed by output destination
73
+ * because one instance can serve several outputs, and watch mode or several `write()` calls
74
+ * rebuild the same one. Outputs that share a directory are told apart by `OutputMatch`.
75
+ */
92
76
  function createSourceMapHandling(sentryBuildPluginManager) {
93
- const decisions = /* @__PURE__ */ new Map();
94
- const pendingStagings = /* @__PURE__ */ new Map();
95
- function setDecision(destination, record) {
96
- const records = decisions.get(destination) ?? [];
97
- const index = records.findIndex((existing) => isSameMatch(existing.match, record.match));
98
- if (index === -1) {
99
- records.push(record);
100
- } else {
101
- records[index] = record;
102
- }
103
- decisions.set(destination, records);
104
- }
105
- function findDecision(destination, outputOptions) {
106
- const candidates = (decisions.get(destination) ?? []).filter((record) => matchesOutput(record.match, outputOptions));
107
- return candidates.sort((a, b) => countMatchFields(b.match) - countMatchFields(a.match))[0];
108
- }
109
- function dropSourceMaps(bundle) {
110
- for (const output of Object.values(bundle)) {
111
- if (output.type === "chunk" && index.isJsFile(output.fileName)) {
112
- delete bundle[getSourceMapFileName(output)];
113
- }
114
- }
115
- }
116
- return {
117
- outputOptions: (rawOutputOptions) => {
118
- const kind = sourceMapKindFromRollupSetting(rawOutputOptions.sourcemap);
119
- const decision = sentryBuildPluginManager.sourceMaps.decide(kind, { log: false });
120
- const outputOptions = decision.enableHidden ? { ...rawOutputOptions, sourcemap: "hidden" } : rawOutputOptions;
121
- setDecision(getOutputDestination(rawOutputOptions), { match: getOutputMatch(outputOptions), kind, decision });
122
- return decision.enableHidden ? outputOptions : null;
123
- },
124
- setDecision,
125
- stageSourceMaps: async (outputOptions, bundle, isWrite) => {
126
- const destination = getOutputDestination(outputOptions);
127
- const record = findDecision(destination, outputOptions);
128
- if (!record) {
129
- return;
130
- }
131
- if (isWrite === false) {
132
- if (record.kind === "unset" && record.decision.enableHidden) {
133
- dropSourceMaps(bundle);
134
- }
135
- return;
136
- }
137
- sentryBuildPluginManager.sourceMaps.logDecision(record.decision);
138
- if (!record.decision.deleteAfterUpload) {
139
- return;
140
- }
141
- const staging = await sentryBuildPluginManager.createUploadStaging();
142
- try {
143
- for (const output of Object.values(bundle)) {
144
- if (output.type !== "chunk" || !index.isJsFile(output.fileName)) {
145
- continue;
146
- }
147
- const mapFileName = getSourceMapFileName(output);
148
- const mapAsset = bundle[mapFileName];
149
- if (mapAsset?.type !== "asset" || typeof mapAsset.source !== "string") {
150
- continue;
151
- }
152
- const result = await staging.stage({
153
- code: output.code,
154
- mapSource: mapAsset.source,
155
- mapDir: path__namespace.join(destination, path__namespace.dirname(mapFileName)),
156
- chunkPath: path__namespace.join(destination, output.fileName)
157
- });
158
- if (result === "staged" || record.kind === "unset") {
159
- delete bundle[mapFileName];
160
- }
161
- if (result === "skipped" || result === "failed") {
162
- sentryBuildPluginManager.logger.warn(
163
- record.kind === "unset" ? `Could not prepare ${output.fileName} for upload, so it is not uploaded and its source map ${mapFileName} was removed from the build output.` : `Could not prepare ${output.fileName} for upload, so its source map ${mapFileName} stays in the build output.`
164
- );
165
- }
166
- }
167
- } catch (e) {
168
- await staging.discard();
169
- throw e;
170
- }
171
- const stagings = pendingStagings.get(destination) ?? [];
172
- pendingStagings.set(destination, stagings);
173
- const superseded = stagings.filter((pending) => isSameMatch(pending.match, record.match));
174
- for (const pending of superseded) {
175
- stagings.splice(stagings.indexOf(pending), 1);
176
- }
177
- stagings.push({ staging, signature: getBundleSignature(bundle), match: record.match });
178
- for (const pending of superseded) {
179
- sentryBuildPluginManager.logger.debug(
180
- `Discarding staged source maps of an earlier build of ${destination} that was never written.`
181
- );
182
- await pending.staging.discard();
183
- }
184
- },
185
- takeStaging: async (outputOptions, bundle) => {
186
- const destination = getOutputDestination(outputOptions);
187
- const stagings = pendingStagings.get(destination) ?? [];
188
- if (!bundle) {
189
- return stagings.shift()?.staging;
190
- }
191
- const signature = getBundleSignature(bundle);
192
- const index = stagings.findIndex((pending) => pending.signature === signature);
193
- return index === -1 ? void 0 : stagings.splice(index, 1)[0]?.staging;
194
- }
195
- };
77
+ const decisions = /* @__PURE__ */ new Map();
78
+ const pendingStagings = /* @__PURE__ */ new Map();
79
+ function setDecision(destination, record) {
80
+ const records = decisions.get(destination) ?? [];
81
+ const index = records.findIndex((existing) => isSameMatch(existing.match, record.match));
82
+ if (index === -1) records.push(record);
83
+ else records[index] = record;
84
+ decisions.set(destination, records);
85
+ }
86
+ function findDecision(destination, outputOptions) {
87
+ return (decisions.get(destination) ?? []).filter((record) => matchesOutput(record.match, outputOptions)).sort((a, b) => countMatchFields(b.match) - countMatchFields(a.match))[0];
88
+ }
89
+ function dropSourceMaps(bundle, shouldDrop = () => true) {
90
+ for (const output of Object.values(bundle)) if (output.type === "chunk" && require_index.isJsFile(output.fileName) && shouldDrop(output.fileName)) delete bundle[getSourceMapFileName(output)];
91
+ }
92
+ function dropAssetSourceMaps(bundle) {
93
+ const chunkMaps = /* @__PURE__ */ new Set();
94
+ for (const output of Object.values(bundle)) if (output.type === "chunk") chunkMaps.add(getSourceMapFileName(output));
95
+ for (const [fileName, output] of Object.entries(bundle)) if (output.type === "asset" && fileName.endsWith(".map") && !chunkMaps.has(fileName)) delete bundle[fileName];
96
+ }
97
+ return {
98
+ outputOptions: (rawOutputOptions) => {
99
+ const kind = sourceMapKindFromRollupSetting(rawOutputOptions.sourcemap);
100
+ const decision = sentryBuildPluginManager.sourceMaps.decide(kind, { log: false });
101
+ const outputOptions = decision.enableHidden ? {
102
+ ...rawOutputOptions,
103
+ sourcemap: "hidden"
104
+ } : rawOutputOptions;
105
+ setDecision(getOutputDestination(rawOutputOptions), {
106
+ match: getOutputMatch(outputOptions),
107
+ kind,
108
+ decision
109
+ });
110
+ return decision.enableHidden ? outputOptions : null;
111
+ },
112
+ setDecision,
113
+ stageSourceMaps: async (outputOptions, bundle, isWrite) => {
114
+ const destination = getOutputDestination(outputOptions);
115
+ const record = findDecision(destination, outputOptions);
116
+ if (!record) return;
117
+ if (isWrite === false) {
118
+ if (record.kind === "unset" && record.decision.enableHidden) dropSourceMaps(bundle);
119
+ return;
120
+ }
121
+ sentryBuildPluginManager.sourceMaps.logDecision(record.decision);
122
+ if (!record.decision.deleteAfterUpload) return;
123
+ const removeAll = record.decision.removeAllSourceMaps === true;
124
+ if (removeAll && record.kind !== "unset") dropAssetSourceMaps(bundle);
125
+ if (!sentryBuildPluginManager.sourceMaps.uploadPossible) {
126
+ dropSourceMaps(bundle, removeAll ? void 0 : (fileName) => sentryBuildPluginManager.sourceMaps.shouldUpload(node_path.join(destination, fileName)));
127
+ return;
128
+ }
129
+ const staging = await sentryBuildPluginManager.createUploadStaging();
130
+ try {
131
+ for (const output of Object.values(bundle)) {
132
+ if (output.type !== "chunk" || !require_index.isJsFile(output.fileName)) continue;
133
+ const mapFileName = getSourceMapFileName(output);
134
+ const mapAsset = bundle[mapFileName];
135
+ if (mapAsset?.type !== "asset" || typeof mapAsset.source !== "string") continue;
136
+ const result = await staging.stage({
137
+ code: output.code,
138
+ mapSource: mapAsset.source,
139
+ mapDir: node_path.join(destination, node_path.dirname(mapFileName)),
140
+ chunkPath: node_path.join(destination, output.fileName)
141
+ });
142
+ if (result === "staged" || removeAll) delete bundle[mapFileName];
143
+ if (result === "skipped" || result === "failed") sentryBuildPluginManager.logger.warn(removeAll ? `Could not prepare ${output.fileName} for upload, so it is not uploaded and its source map ${mapFileName} was removed from the build output.` : `Could not prepare ${output.fileName} for upload, so its source map ${mapFileName} stays in the build output.`);
144
+ }
145
+ } catch (e) {
146
+ await staging.discard();
147
+ throw e;
148
+ }
149
+ const stagings = pendingStagings.get(destination) ?? [];
150
+ pendingStagings.set(destination, stagings);
151
+ const superseded = stagings.filter((pending) => isSameMatch(pending.match, record.match));
152
+ for (const pending of superseded) stagings.splice(stagings.indexOf(pending), 1);
153
+ stagings.push({
154
+ staging,
155
+ signature: getBundleSignature(bundle),
156
+ match: record.match
157
+ });
158
+ for (const pending of superseded) {
159
+ sentryBuildPluginManager.logger.debug(`Discarding staged source maps of an earlier build of ${destination} that was never written.`);
160
+ await pending.staging.discard();
161
+ }
162
+ },
163
+ takeStaging: async (outputOptions, bundle) => {
164
+ const destination = getOutputDestination(outputOptions);
165
+ const stagings = pendingStagings.get(destination) ?? [];
166
+ if (!bundle) return stagings.shift()?.staging;
167
+ const signature = getBundleSignature(bundle);
168
+ const index = stagings.findIndex((pending) => pending.signature === signature);
169
+ return index === -1 ? void 0 : stagings.splice(index, 1)[0]?.staging;
170
+ }
171
+ };
196
172
  }
197
-
198
173
  exports.createSourceMapHandling = createSourceMapHandling;
199
174
  exports.getOutputDestination = getOutputDestination;
200
175
  exports.getOutputMatch = getOutputMatch;
201
176
  exports.sourceMapKindFromRollupSetting = sourceMapKindFromRollupSetting;
202
- //# sourceMappingURL=source-map-handling.js.map
177
+
178
+ //# sourceMappingURL=source-map-handling.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"source-map-handling.js","sources":["../../../src/rollup/source-map-handling.ts"],"sourcesContent":["import * as path from 'node:path';\nimport type { SentryBuildPluginManager, SourceMapDecision, SourceMapKind, UploadStaging } from '../core';\nimport { isJsFile } from '../core';\nimport type { OutputBundle } from './debug-id-stamping';\n\nexport type RollupSourceMapSetting = boolean | 'inline' | 'hidden' | undefined;\n\nexport type OutputDestinationOptions = { dir?: string; file?: string };\n\n/**\n * The output options that tell outputs of one directory apart. Several outputs can write into the\n * same directory at once, for example an ES and a CJS build, each with its own `sourcemap` setting.\n * `sourcemap` holds the setting as the plugin left it, so an output it switched to hidden maps\n * differs from one the user set.\n */\nexport type OutputMatch = {\n dir?: unknown;\n file?: unknown;\n format?: unknown;\n entryFileNames?: unknown;\n chunkFileNames?: unknown;\n preserveModules?: unknown;\n sourcemap?: unknown;\n};\n\nexport type OutputOptions = OutputDestinationOptions & OutputMatch & { sourcemap?: RollupSourceMapSetting };\n\n/** Maps Rollup's (and Vite's) `sourcemap` setting onto the plugin's source map kinds. */\nexport function sourceMapKindFromRollupSetting(setting: RollupSourceMapSetting): SourceMapKind {\n switch (setting) {\n case undefined:\n return 'unset';\n case false:\n return 'off';\n case true:\n return 'visible';\n default:\n return setting;\n }\n}\n\n/** The directory an output writes to. Decisions and stagings are keyed by it. */\nexport function getOutputDestination(outputOptions: OutputDestinationOptions): string {\n return path.resolve(outputOptions.dir ?? path.dirname(outputOptions.file ?? '.'));\n}\n\nconst MATCH_KEYS = [\n 'dir',\n 'file',\n 'format',\n 'entryFileNames',\n 'chunkFileNames',\n 'preserveModules',\n 'sourcemap',\n] as const;\n\n/** The raw options accept aliases that the normalized options do not carry. */\nfunction normalizeFormat(format: unknown): unknown {\n switch (format) {\n case 'esm':\n case 'module':\n return 'es';\n case 'commonjs':\n return 'cjs';\n case 'systemjs':\n return 'system';\n default:\n return format;\n }\n}\n\n/** The fields of `OutputMatch` an output sets, in the form the normalized options carry them. */\nexport function getOutputMatch(outputOptions: OutputMatch): OutputMatch {\n const match: OutputMatch = {};\n for (const key of MATCH_KEYS) {\n const value = outputOptions[key];\n if (value === undefined) {\n continue;\n }\n match[key] =\n key === 'format' ? normalizeFormat(value) : key === 'dir' || key === 'file' ? path.resolve(String(value)) : value;\n }\n return match;\n}\n\nfunction matchesOutput(match: OutputMatch, outputOptions: OutputMatch): boolean {\n const actual = getOutputMatch(outputOptions);\n return MATCH_KEYS.every(key => match[key] === undefined || match[key] === actual[key]);\n}\n\nfunction isSameMatch(a: OutputMatch, b: OutputMatch): boolean {\n return MATCH_KEYS.every(key => a[key] === b[key]);\n}\n\nfunction countMatchFields(match: OutputMatch): number {\n return MATCH_KEYS.filter(key => match[key] !== undefined).length;\n}\n\nconst DEBUG_ID_PATTERN = /sentry-dbid-([0-9a-f-]{36})|\\/\\/# debugId=([0-9a-f-]{36})/i;\n\n/** Identifies the chunks of a bundle by name and debug ID, so a staging can be matched to its write. */\nfunction getBundleSignature(bundle: OutputBundle): string {\n const entries: string[] = [];\n for (const output of Object.values(bundle)) {\n if (output.type === 'chunk' && isJsFile(output.fileName)) {\n const match = output.code.match(DEBUG_ID_PATTERN);\n entries.push(`${output.fileName}:${match?.[1] ?? match?.[2] ?? ''}`);\n }\n }\n return entries.sort().join('\\n');\n}\n\nfunction getSourceMapFileName(output: { fileName: string; sourcemapFileName?: string | null }): string {\n return output.sourcemapFileName ?? `${output.fileName}.map`;\n}\n\ntype PendingStaging = { staging: UploadStaging; signature: string; match: OutputMatch };\n\nexport type DecisionRecord = { match: OutputMatch; kind: SourceMapKind; decision: SourceMapDecision };\n\nexport type SourceMapHandling = {\n /** Rollup's `outputOptions` hook: decides for the output and switches it to hidden source maps when needed. */\n outputOptions: (rawOutputOptions: OutputOptions) => OutputOptions | null;\n /** Records the decision for an output, for bundlers that decide outside `outputOptions`. */\n setDecision: (destination: string, record: DecisionRecord) => void;\n /**\n * `generateBundle` with `order: 'post'`: copies each chunk and its source map into a staging folder\n * and drops the map asset from the bundle, so the bundler never writes it.\n */\n stageSourceMaps: (outputOptions: OutputOptions, bundle: OutputBundle, isWrite?: boolean) => Promise<void>;\n /**\n * Hands the staging of this bundle to `writeBundle`. Without a bundle (SvelteKit calls the hook\n * with output options only) the oldest staging is taken.\n */\n takeStaging: (\n outputOptions: OutputDestinationOptions,\n bundle: OutputBundle | undefined,\n ) => Promise<UploadStaging | undefined>;\n};\n\n/**\n * Source map decisions and upload stagings of one plugin instance. Keyed by output destination\n * because one instance can serve several outputs, and watch mode or several `write()` calls\n * rebuild the same one. Outputs that share a directory are told apart by `OutputMatch`.\n */\nexport function createSourceMapHandling(sentryBuildPluginManager: SentryBuildPluginManager): SourceMapHandling {\n const decisions = new Map<string, DecisionRecord[]>();\n const pendingStagings = new Map<string, PendingStaging[]>();\n\n function setDecision(destination: string, record: DecisionRecord): void {\n const records = decisions.get(destination) ?? [];\n const index = records.findIndex(existing => isSameMatch(existing.match, record.match));\n if (index === -1) {\n records.push(record);\n } else {\n records[index] = record;\n }\n decisions.set(destination, records);\n }\n\n function findDecision(destination: string, outputOptions: OutputOptions): DecisionRecord | undefined {\n const candidates = (decisions.get(destination) ?? []).filter(record => matchesOutput(record.match, outputOptions));\n // The record that sets the most fields describes this output best. Equal\n // candidates keep their order, so the first one recorded wins.\n return candidates.sort((a, b) => countMatchFields(b.match) - countMatchFields(a.match))[0];\n }\n\n function dropSourceMaps(bundle: OutputBundle): void {\n for (const output of Object.values(bundle)) {\n if (output.type === 'chunk' && isJsFile(output.fileName)) {\n // oxlint-disable-next-line typescript/no-dynamic-delete -- Rollup drops an asset when its key is deleted from the bundle\n delete bundle[getSourceMapFileName(output)];\n }\n }\n }\n\n return {\n outputOptions: rawOutputOptions => {\n const kind = sourceMapKindFromRollupSetting(rawOutputOptions.sourcemap);\n // Logged in `generateBundle`, which knows whether the output is written.\n const decision = sentryBuildPluginManager.sourceMaps.decide(kind, { log: false });\n const outputOptions = decision.enableHidden\n ? { ...rawOutputOptions, sourcemap: 'hidden' as const }\n : rawOutputOptions;\n setDecision(getOutputDestination(rawOutputOptions), { match: getOutputMatch(outputOptions), kind, decision });\n\n return decision.enableHidden ? outputOptions : null;\n },\n\n setDecision,\n\n stageSourceMaps: async (outputOptions, bundle, isWrite) => {\n const destination = getOutputDestination(outputOptions);\n const record = findDecision(destination, outputOptions);\n if (!record) {\n return;\n }\n\n // `generate()` never reaches `writeBundle`, so nothing would upload a staging. Maps the\n // plugin turned on are dropped, so the result holds what the user configured.\n if (isWrite === false) {\n if (record.kind === 'unset' && record.decision.enableHidden) {\n dropSourceMaps(bundle);\n }\n return;\n }\n\n sentryBuildPluginManager.sourceMaps.logDecision(record.decision);\n if (!record.decision.deleteAfterUpload) {\n return;\n }\n\n const staging = await sentryBuildPluginManager.createUploadStaging();\n\n try {\n for (const output of Object.values(bundle)) {\n if (output.type !== 'chunk' || !isJsFile(output.fileName)) {\n continue;\n }\n\n const mapFileName = getSourceMapFileName(output);\n const mapAsset = bundle[mapFileName];\n if (mapAsset?.type !== 'asset' || typeof mapAsset.source !== 'string') {\n continue;\n }\n\n const result = await staging.stage({\n code: output.code,\n mapSource: mapAsset.source,\n mapDir: path.join(destination, path.dirname(mapFileName)),\n chunkPath: path.join(destination, output.fileName),\n });\n\n // A map the plugin turned on never reaches the output, whether or\n // not the chunk is uploaded. A map the user enabled stays unless\n // it was staged.\n if (result === 'staged' || record.kind === 'unset') {\n // oxlint-disable-next-line typescript/no-dynamic-delete -- Rollup drops an asset when its key is deleted from the bundle\n delete bundle[mapFileName];\n }\n if (result === 'skipped' || result === 'failed') {\n sentryBuildPluginManager.logger.warn(\n record.kind === 'unset'\n ? `Could not prepare ${output.fileName} for upload, so it is not uploaded and its source map ${mapFileName} was removed from the build output.`\n : `Could not prepare ${output.fileName} for upload, so its source map ${mapFileName} stays in the build output.`,\n );\n }\n }\n } catch (e) {\n // The error fails the build before anything is written.\n await staging.discard();\n throw e;\n }\n\n // A staging of the same output that no `writeBundle` took belongs to a\n // write that never finished. Stagings of other outputs to this directory\n // may still be in flight, so the shared list changes in place and without\n // an await in between.\n const stagings = pendingStagings.get(destination) ?? [];\n pendingStagings.set(destination, stagings);\n const superseded = stagings.filter(pending => isSameMatch(pending.match, record.match));\n for (const pending of superseded) {\n stagings.splice(stagings.indexOf(pending), 1);\n }\n stagings.push({ staging, signature: getBundleSignature(bundle), match: record.match });\n\n for (const pending of superseded) {\n sentryBuildPluginManager.logger.debug(\n `Discarding staged source maps of an earlier build of ${destination} that was never written.`,\n );\n await pending.staging.discard();\n }\n },\n\n takeStaging: async (outputOptions, bundle) => {\n const destination = getOutputDestination(outputOptions);\n const stagings = pendingStagings.get(destination) ?? [];\n\n if (!bundle) {\n return stagings.shift()?.staging;\n }\n\n const signature = getBundleSignature(bundle);\n const index = stagings.findIndex(pending => pending.signature === signature);\n return index === -1 ? undefined : stagings.splice(index, 1)[0]?.staging;\n },\n };\n}\n"],"names":["path","isJsFile"],"mappings":";;;;;;;;;;;;;;;;;;;AA4BO,SAAS,+BAA+B,OAAA,EAAgD;AAC7F,EAAA,QAAQ,OAAA;AAAS,IACf,KAAK,MAAA;AACH,MAAA,OAAO,OAAA;AAAA,IACT,KAAK,KAAA;AACH,MAAA,OAAO,KAAA;AAAA,IACT,KAAK,IAAA;AACH,MAAA,OAAO,SAAA;AAAA,IACT;AACE,MAAA,OAAO,OAAA;AAAA;AAEb;AAGO,SAAS,qBAAqB,aAAA,EAAiD;AACpF,EAAA,OAAOA,eAAA,CAAK,QAAQ,aAAA,CAAc,GAAA,IAAOA,gBAAK,OAAA,CAAQ,aAAA,CAAc,IAAA,IAAQ,GAAG,CAAC,CAAA;AAClF;AAEA,MAAM,UAAA,GAAa;AAAA,EACjB,KAAA;AAAA,EACA,MAAA;AAAA,EACA,QAAA;AAAA,EACA,gBAAA;AAAA,EACA,gBAAA;AAAA,EACA,iBAAA;AAAA,EACA;AACF,CAAA;AAGA,SAAS,gBAAgB,MAAA,EAA0B;AACjD,EAAA,QAAQ,MAAA;AAAQ,IACd,KAAK,KAAA;AAAA,IACL,KAAK,QAAA;AACH,MAAA,OAAO,IAAA;AAAA,IACT,KAAK,UAAA;AACH,MAAA,OAAO,KAAA;AAAA,IACT,KAAK,UAAA;AACH,MAAA,OAAO,QAAA;AAAA,IACT;AACE,MAAA,OAAO,MAAA;AAAA;AAEb;AAGO,SAAS,eAAe,aAAA,EAAyC;AACtE,EAAA,MAAM,QAAqB,EAAC;AAC5B,EAAA,KAAA,MAAW,OAAO,UAAA,EAAY;AAC5B,IAAA,MAAM,KAAA,GAAQ,cAAc,GAAG,CAAA;AAC/B,IAAA,IAAI,UAAU,MAAA,EAAW;AACvB,MAAA;AAAA,IACF;AACA,IAAA,KAAA,CAAM,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;AAAA,MAChC;AAAA,IACF,CAAA;AAAA,IAEA,WAAA,EAAa,OAAO,aAAA,EAAe,MAAA,KAAW;AAC5C,MAAA,MAAM,WAAA,GAAc,qBAAqB,aAAa,CAAA;AACtD,MAAA,MAAM,QAAA,GAAW,eAAA,CAAgB,GAAA,CAAI,WAAW,KAAK,EAAC;AAEtD,MAAA,IAAI,CAAC,MAAA,EAAQ;AACX,QAAA,OAAO,QAAA,CAAS,OAAM,EAAG,OAAA;AAAA,MAC3B;AAEA,MAAA,MAAM,SAAA,GAAY,mBAAmB,MAAM,CAAA;AAC3C,MAAA,MAAM,QAAQ,QAAA,CAAS,SAAA,CAAU,CAAA,OAAA,KAAW,OAAA,CAAQ,cAAc,SAAS,CAAA;AAC3E,MAAA,OAAO,KAAA,KAAU,KAAK,MAAA,GAAY,QAAA,CAAS,OAAO,KAAA,EAAO,CAAC,CAAA,CAAE,CAAC,CAAA,EAAG,OAAA;AAAA,IAClE;AAAA,GACF;AACF;;;;;;;"}
1
+ {"version":3,"file":"source-map-handling.js","names":["path","isJsFile"],"sources":["../../../src/rollup/source-map-handling.ts"],"sourcesContent":["import * as path from 'node:path';\nimport type { SentryBuildPluginManager, SourceMapDecision, SourceMapKind, UploadStaging } from '../core';\nimport { isJsFile } from '../core';\nimport type { OutputBundle } from './debug-id-stamping';\n\nexport type RollupSourceMapSetting = boolean | 'inline' | 'hidden' | undefined;\n\nexport type OutputDestinationOptions = { dir?: string; file?: string };\n\n/**\n * The output options that tell outputs of one directory apart. Several outputs can write into the\n * same directory at once, for example an ES and a CJS build, each with its own `sourcemap` setting.\n * `sourcemap` holds the setting as the plugin left it, so an output it switched to hidden maps\n * differs from one the user set.\n */\nexport type OutputMatch = {\n dir?: unknown;\n file?: unknown;\n format?: unknown;\n entryFileNames?: unknown;\n chunkFileNames?: unknown;\n preserveModules?: unknown;\n sourcemap?: unknown;\n};\n\nexport type OutputOptions = OutputDestinationOptions & OutputMatch & { sourcemap?: RollupSourceMapSetting };\n\n/** Maps Rollup's (and Vite's) `sourcemap` setting onto the plugin's source map kinds. */\nexport function sourceMapKindFromRollupSetting(setting: RollupSourceMapSetting): SourceMapKind {\n switch (setting) {\n case undefined:\n return 'unset';\n case false:\n return 'off';\n case true:\n return 'visible';\n default:\n return setting;\n }\n}\n\n/** The directory an output writes to. Decisions and stagings are keyed by it. */\nexport function getOutputDestination(outputOptions: OutputDestinationOptions): string {\n return path.resolve(outputOptions.dir ?? path.dirname(outputOptions.file ?? '.'));\n}\n\nconst MATCH_KEYS = [\n 'dir',\n 'file',\n 'format',\n 'entryFileNames',\n 'chunkFileNames',\n 'preserveModules',\n 'sourcemap',\n] as const;\n\n/** The raw options accept aliases that the normalized options do not carry. */\nfunction normalizeFormat(format: unknown): unknown {\n switch (format) {\n case 'esm':\n case 'module':\n return 'es';\n case 'commonjs':\n return 'cjs';\n case 'systemjs':\n return 'system';\n default:\n return format;\n }\n}\n\n/** The fields of `OutputMatch` an output sets, in the form the normalized options carry them. */\nexport function getOutputMatch(outputOptions: OutputMatch): OutputMatch {\n const match: OutputMatch = {};\n for (const key of MATCH_KEYS) {\n const value = outputOptions[key];\n if (value === undefined) {\n continue;\n }\n match[key] =\n key === 'format' ? normalizeFormat(value) : key === 'dir' || key === 'file' ? path.resolve(String(value)) : value;\n }\n return match;\n}\n\nfunction matchesOutput(match: OutputMatch, outputOptions: OutputMatch): boolean {\n const actual = getOutputMatch(outputOptions);\n return MATCH_KEYS.every(key => match[key] === undefined || match[key] === actual[key]);\n}\n\nfunction isSameMatch(a: OutputMatch, b: OutputMatch): boolean {\n return MATCH_KEYS.every(key => a[key] === b[key]);\n}\n\nfunction countMatchFields(match: OutputMatch): number {\n return MATCH_KEYS.filter(key => match[key] !== undefined).length;\n}\n\nconst DEBUG_ID_PATTERN = /sentry-dbid-([0-9a-f-]{36})|\\/\\/# debugId=([0-9a-f-]{36})/i;\n\n/** Identifies the chunks of a bundle by name and debug ID, so a staging can be matched to its write. */\nfunction getBundleSignature(bundle: OutputBundle): string {\n const entries: string[] = [];\n for (const output of Object.values(bundle)) {\n if (output.type === 'chunk' && isJsFile(output.fileName)) {\n const match = output.code.match(DEBUG_ID_PATTERN);\n entries.push(`${output.fileName}:${match?.[1] ?? match?.[2] ?? ''}`);\n }\n }\n return entries.sort().join('\\n');\n}\n\nfunction getSourceMapFileName(output: { fileName: string; sourcemapFileName?: string | null }): string {\n return output.sourcemapFileName ?? `${output.fileName}.map`;\n}\n\ntype PendingStaging = { staging: UploadStaging; signature: string; match: OutputMatch };\n\nexport type DecisionRecord = { match: OutputMatch; kind: SourceMapKind; decision: SourceMapDecision };\n\nexport type SourceMapHandling = {\n /** Rollup's `outputOptions` hook: decides for the output and switches it to hidden source maps when needed. */\n outputOptions: (rawOutputOptions: OutputOptions) => OutputOptions | null;\n /** Records the decision for an output, for bundlers that decide outside `outputOptions`. */\n setDecision: (destination: string, record: DecisionRecord) => void;\n /**\n * `generateBundle` with `order: 'post'`: copies each chunk and its source map into a staging folder\n * and drops the map asset from the bundle, so the bundler never writes it.\n */\n stageSourceMaps: (outputOptions: OutputOptions, bundle: OutputBundle, isWrite?: boolean) => Promise<void>;\n /**\n * Hands the staging of this bundle to `writeBundle`. Without a bundle (SvelteKit calls the hook\n * with output options only) the oldest staging is taken.\n */\n takeStaging: (\n outputOptions: OutputDestinationOptions,\n bundle: OutputBundle | undefined,\n ) => Promise<UploadStaging | undefined>;\n};\n\n/**\n * Source map decisions and upload stagings of one plugin instance. Keyed by output destination\n * because one instance can serve several outputs, and watch mode or several `write()` calls\n * rebuild the same one. Outputs that share a directory are told apart by `OutputMatch`.\n */\nexport function createSourceMapHandling(sentryBuildPluginManager: SentryBuildPluginManager): SourceMapHandling {\n const decisions = new Map<string, DecisionRecord[]>();\n const pendingStagings = new Map<string, PendingStaging[]>();\n\n function setDecision(destination: string, record: DecisionRecord): void {\n const records = decisions.get(destination) ?? [];\n const index = records.findIndex(existing => isSameMatch(existing.match, record.match));\n if (index === -1) {\n records.push(record);\n } else {\n records[index] = record;\n }\n decisions.set(destination, records);\n }\n\n function findDecision(destination: string, outputOptions: OutputOptions): DecisionRecord | undefined {\n const candidates = (decisions.get(destination) ?? []).filter(record => matchesOutput(record.match, outputOptions));\n // The record that sets the most fields describes this output best. Equal\n // candidates keep their order, so the first one recorded wins.\n return candidates.sort((a, b) => countMatchFields(b.match) - countMatchFields(a.match))[0];\n }\n\n function dropSourceMaps(bundle: OutputBundle, shouldDrop: (fileName: string) => boolean = () => true): void {\n for (const output of Object.values(bundle)) {\n if (output.type === 'chunk' && isJsFile(output.fileName) && shouldDrop(output.fileName)) {\n // oxlint-disable-next-line typescript/no-dynamic-delete -- Rollup drops an asset when its key is deleted from the bundle\n delete bundle[getSourceMapFileName(output)];\n }\n }\n }\n\n // Other plugins emit maps as assets, e.g. for CSS or for Vite worker\n // bundles. Chunk maps stay here, because staging still needs them.\n function dropAssetSourceMaps(bundle: OutputBundle): void {\n const chunkMaps = new Set<string>();\n for (const output of Object.values(bundle)) {\n if (output.type === 'chunk') {\n chunkMaps.add(getSourceMapFileName(output));\n }\n }\n for (const [fileName, output] of Object.entries(bundle)) {\n if (output.type === 'asset' && fileName.endsWith('.map') && !chunkMaps.has(fileName)) {\n // oxlint-disable-next-line typescript/no-dynamic-delete -- Rollup drops an asset when its key is deleted from the bundle\n delete bundle[fileName];\n }\n }\n }\n\n return {\n outputOptions: rawOutputOptions => {\n const kind = sourceMapKindFromRollupSetting(rawOutputOptions.sourcemap);\n // Logged in `generateBundle`, which knows whether the output is written.\n const decision = sentryBuildPluginManager.sourceMaps.decide(kind, { log: false });\n const outputOptions = decision.enableHidden\n ? { ...rawOutputOptions, sourcemap: 'hidden' as const }\n : rawOutputOptions;\n setDecision(getOutputDestination(rawOutputOptions), { match: getOutputMatch(outputOptions), kind, decision });\n\n return decision.enableHidden ? outputOptions : null;\n },\n\n setDecision,\n\n stageSourceMaps: async (outputOptions, bundle, isWrite) => {\n const destination = getOutputDestination(outputOptions);\n const record = findDecision(destination, outputOptions);\n if (!record) {\n return;\n }\n\n // `generate()` never reaches `writeBundle`, so nothing would upload a staging. Maps the\n // plugin turned on are dropped, so the result holds what the user configured.\n if (isWrite === false) {\n if (record.kind === 'unset' && record.decision.enableHidden) {\n dropSourceMaps(bundle);\n }\n return;\n }\n\n sentryBuildPluginManager.sourceMaps.logDecision(record.decision);\n if (!record.decision.deleteAfterUpload) {\n return;\n }\n\n const removeAll = record.decision.removeAllSourceMaps === true;\n // With `unset` the plugin only turned on the chunk maps. Asset maps\n // come from other plugins' own settings.\n if (removeAll && record.kind !== 'unset') {\n dropAssetSourceMaps(bundle);\n }\n\n if (!sentryBuildPluginManager.sourceMaps.uploadPossible) {\n dropSourceMaps(\n bundle,\n removeAll\n ? undefined\n : fileName => sentryBuildPluginManager.sourceMaps.shouldUpload(path.join(destination, fileName)),\n );\n return;\n }\n\n const staging = await sentryBuildPluginManager.createUploadStaging();\n\n try {\n for (const output of Object.values(bundle)) {\n if (output.type !== 'chunk' || !isJsFile(output.fileName)) {\n continue;\n }\n\n const mapFileName = getSourceMapFileName(output);\n const mapAsset = bundle[mapFileName];\n if (mapAsset?.type !== 'asset' || typeof mapAsset.source !== 'string') {\n continue;\n }\n\n const result = await staging.stage({\n code: output.code,\n mapSource: mapAsset.source,\n mapDir: path.join(destination, path.dirname(mapFileName)),\n chunkPath: path.join(destination, output.fileName),\n });\n\n // A map the plugin or the SDK turned on never reaches the output,\n // whether or not the chunk is uploaded. A map the user enabled\n // stays unless it was staged.\n if (result === 'staged' || removeAll) {\n // oxlint-disable-next-line typescript/no-dynamic-delete -- Rollup drops an asset when its key is deleted from the bundle\n delete bundle[mapFileName];\n }\n if (result === 'skipped' || result === 'failed') {\n sentryBuildPluginManager.logger.warn(\n removeAll\n ? `Could not prepare ${output.fileName} for upload, so it is not uploaded and its source map ${mapFileName} was removed from the build output.`\n : `Could not prepare ${output.fileName} for upload, so its source map ${mapFileName} stays in the build output.`,\n );\n }\n }\n } catch (e) {\n // The error fails the build before anything is written.\n await staging.discard();\n throw e;\n }\n\n // A staging of the same output that no `writeBundle` took belongs to a\n // write that never finished. Stagings of other outputs to this directory\n // may still be in flight, so the shared list changes in place and without\n // an await in between.\n const stagings = pendingStagings.get(destination) ?? [];\n pendingStagings.set(destination, stagings);\n const superseded = stagings.filter(pending => isSameMatch(pending.match, record.match));\n for (const pending of superseded) {\n stagings.splice(stagings.indexOf(pending), 1);\n }\n stagings.push({ staging, signature: getBundleSignature(bundle), match: record.match });\n\n for (const pending of superseded) {\n sentryBuildPluginManager.logger.debug(\n `Discarding staged source maps of an earlier build of ${destination} that was never written.`,\n );\n await pending.staging.discard();\n }\n },\n\n takeStaging: async (outputOptions, bundle) => {\n const destination = getOutputDestination(outputOptions);\n const stagings = pendingStagings.get(destination) ?? [];\n\n if (!bundle) {\n return stagings.shift()?.staging;\n }\n\n const signature = getBundleSignature(bundle);\n const index = stagings.findIndex(pending => pending.signature === signature);\n return index === -1 ? undefined : stagings.splice(index, 1)[0]?.staging;\n },\n };\n}\n"],"mappings":";;;;;;AA4BA,SAAgB,+BAA+B,SAAgD;CAC7F,QAAQ,SAAR;EACE,KAAK,KAAA,GACH,OAAO;EACT,KAAK,OACH,OAAO;EACT,KAAK,MACH,OAAO;EACT,SACE,OAAO;CACX;AACF;;AAGA,SAAgB,qBAAqB,eAAiD;CACpF,OAAOA,UAAK,QAAQ,cAAc,OAAOA,UAAK,QAAQ,cAAc,QAAQ,GAAG,CAAC;AAClF;AAEA,MAAM,aAAa;CACjB;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAGA,SAAS,gBAAgB,QAA0B;CACjD,QAAQ,QAAR;EACE,KAAK;EACL,KAAK,UACH,OAAO;EACT,KAAK,YACH,OAAO;EACT,KAAK,YACH,OAAO;EACT,SACE,OAAO;CACX;AACF;;AAGA,SAAgB,eAAe,eAAyC;CACtE,MAAM,QAAqB,CAAC;CAC5B,KAAK,MAAM,OAAO,YAAY;EAC5B,MAAM,QAAQ,cAAc;EAC5B,I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;GAMA,MAAM,WAAW,gBAAgB,IAAI,WAAW,KAAK,CAAC;GACtD,gBAAgB,IAAI,aAAa,QAAQ;GACzC,MAAM,aAAa,SAAS,QAAO,YAAW,YAAY,QAAQ,OAAO,OAAO,KAAK,CAAC;GACtF,KAAK,MAAM,WAAW,YACpB,SAAS,OAAO,SAAS,QAAQ,OAAO,GAAG,CAAC;GAE9C,SAAS,KAAK;IAAE;IAAS,WAAW,mBAAmB,MAAM;IAAG,OAAO,OAAO;GAAM,CAAC;GAErF,KAAK,MAAM,WAAW,YAAY;IAChC,yBAAyB,OAAO,MAC9B,wDAAwD,YAAY,yBACtE;IACA,MAAM,QAAQ,QAAQ,QAAQ;GAChC;EACF;EAEA,aAAa,OAAO,eAAe,WAAW;GAC5C,MAAM,cAAc,qBAAqB,aAAa;GACtD,MAAM,WAAW,gBAAgB,IAAI,WAAW,KAAK,CAAC;GAEtD,IAAI,CAAC,QACH,OAAO,SAAS,MAAM,CAAC,EAAE;GAG3B,MAAM,YAAY,mBAAmB,MAAM;GAC3C,MAAM,QAAQ,SAAS,WAAU,YAAW,QAAQ,cAAc,SAAS;GAC3E,OAAO,UAAU,KAAK,KAAA,IAAY,SAAS,OAAO,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;EAClE;CACF;AACF"}
@@ -1,26 +1,24 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
-
3
- const index = require('../rollup/index.js');
4
- const node_module = require('node:module');
5
-
6
- var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_index = require("../rollup/index.js");
3
+ let node_module = require("node:module");
4
+ // src/vite/index.ts
7
5
  function getViteMajorVersion() {
8
- try {
9
- const req = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('vite/index.js', document.baseURI).href)));
10
- const vite = req("vite");
11
- return vite.version?.split(".")[0];
12
- } catch {
13
- }
14
- return void 0;
6
+ try {
7
+ return (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)("vite").version?.split(".")[0];
8
+ } catch {}
15
9
  }
16
10
  const sentryVitePlugin = (options) => {
17
- const { main, post } = index._createRollupPluginInternals(options, "vite", getViteMajorVersion());
18
- const plugins = [{ enforce: "pre", ...main }];
19
- if (post) {
20
- plugins.push({ enforce: "post", ...post });
21
- }
22
- return plugins;
11
+ const { main, post } = require_index._createRollupPluginInternals(options, "vite", getViteMajorVersion());
12
+ const plugins = [{
13
+ enforce: "pre",
14
+ ...main
15
+ }];
16
+ if (post) plugins.push({
17
+ enforce: "post",
18
+ ...post
19
+ });
20
+ return plugins;
23
21
  };
24
-
25
22
  exports.sentryVitePlugin = sentryVitePlugin;
26
- //# sourceMappingURL=index.js.map
23
+
24
+ //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/vite/index.ts"],"sourcesContent":["import type { SentryRollupPluginOptions } from '../rollup';\nimport { _createRollupPluginInternals } from '../rollup';\nimport { createRequire } from 'node:module';\n\ninterface SentryVitePlugin {\n name: string;\n enforce: 'pre' | 'post';\n [hook: string]: unknown;\n}\n\nfunction getViteMajorVersion(): string | undefined {\n try {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore - Rollup already transpiles this for us\n const req = createRequire(import.meta.url);\n const vite = req('vite') as { version?: string };\n return vite.version?.split('.')[0];\n } catch {\n // do nothing, we'll just not report a version\n }\n\n return undefined;\n}\n\nexport const sentryVitePlugin = (options?: SentryRollupPluginOptions): SentryVitePlugin[] => {\n const { main, post } = _createRollupPluginInternals(options, 'vite', getViteMajorVersion());\n\n const plugins: SentryVitePlugin[] = [{ enforce: 'pre', ...main }];\n\n if (post) {\n plugins.push({ enforce: 'post', ...post });\n }\n\n return plugins;\n};\n\nexport type { Options as SentryVitePluginOptions } from '../core';\n"],"names":["createRequire","_createRollupPluginInternals"],"mappings":";;;;;;AAUA,SAAS,mBAAA,GAA0C;AACjD,EAAA,IAAI;AAGF,IAAA,MAAM,GAAA,GAAMA,yBAAA,CAAc,+PAAe,CAAA;AACzC,IAAA,MAAM,IAAA,GAAO,IAAI,MAAM,CAAA;AACvB,IAAA,OAAO,IAAA,CAAK,OAAA,EAAS,KAAA,CAAM,GAAG,EAAE,CAAC,CAAA;AAAA,EACnC,CAAA,CAAA,MAAQ;AAAA,EAER;AAEA,EAAA,OAAO,MAAA;AACT;AAEO,MAAM,gBAAA,GAAmB,CAAC,OAAA,KAA4D;AAC3F,EAAA,MAAM,EAAE,MAAM,IAAA,EAAK,GAAIC,mCAA6B,OAAA,EAAS,MAAA,EAAQ,qBAAqB,CAAA;AAE1F,EAAA,MAAM,UAA8B,CAAC,EAAE,SAAS,KAAA,EAAO,GAAG,MAAM,CAAA;AAEhE,EAAA,IAAI,IAAA,EAAM;AACR,IAAA,OAAA,CAAQ,KAAK,EAAE,OAAA,EAAS,MAAA,EAAQ,GAAG,MAAM,CAAA;AAAA,EAC3C;AAEA,EAAA,OAAO,OAAA;AACT;;;;"}
1
+ {"version":3,"file":"index.js","names":["createRequire","_createRollupPluginInternals"],"sources":["../../../src/vite/index.ts"],"sourcesContent":["import type { InternalOptions } from '../core';\nimport { _createRollupPluginInternals } from '../rollup';\nimport { createRequire } from 'node:module';\n\ninterface SentryVitePlugin {\n name: string;\n enforce: 'pre' | 'post';\n [hook: string]: unknown;\n}\n\nfunction getViteMajorVersion(): string | undefined {\n try {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore - Rollup already transpiles this for us\n const req = createRequire(import.meta.url);\n const vite = req('vite') as { version?: string };\n return vite.version?.split('.')[0];\n } catch {\n // do nothing, we'll just not report a version\n }\n\n return undefined;\n}\n\nexport const sentryVitePlugin = (options?: InternalOptions): SentryVitePlugin[] => {\n const { main, post } = _createRollupPluginInternals(options, 'vite', getViteMajorVersion());\n\n const plugins: SentryVitePlugin[] = [{ enforce: 'pre', ...main }];\n\n if (post) {\n plugins.push({ enforce: 'post', ...post });\n }\n\n return plugins;\n};\n\nexport type { Options as SentryVitePluginOptions, InternalOptions as SentryVitePluginInternalOptions } from '../core';\n"],"mappings":";;;;AAUA,SAAS,sBAA0C;CACjD,IAAI;EAKF,QAAA,GAFYA,YAAAA,cAAAA,CAAAA,QAAAA,KAAAA,CAAAA,CAAAA,cAAAA,UAAAA,CAAAA,CAAAA,IACG,CAAC,CAAC,MACP,CAAC,CAAC,SAAS,MAAM,GAAG,CAAC,CAAC;CAClC,QAAQ,CAER;AAGF;AAEA,MAAa,oBAAoB,YAAkD;CACjF,MAAM,EAAE,MAAM,SAASC,cAAAA,6BAA6B,SAAS,QAAQ,oBAAoB,CAAC;CAE1F,MAAM,UAA8B,CAAC;EAAE,SAAS;EAAO,GAAG;CAAK,CAAC;CAEhE,IAAI,MACF,QAAQ,KAAK;EAAE,SAAS;EAAQ,GAAG;CAAK,CAAC;CAG3C,OAAO;AACT"}