@sentry/bundler-plugins 11.11.0 → 11.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/core/build-plugin-manager.js +27 -8
- package/build/cjs/core/build-plugin-manager.js.map +1 -1
- package/build/cjs/core/index.js.map +1 -1
- package/build/cjs/core/upload-filter.js +57 -0
- package/build/cjs/core/upload-filter.js.map +1 -0
- package/build/cjs/core/version.js +1 -1
- package/build/cjs/core/version.js.map +1 -1
- package/build/cjs/esbuild/index.js +1 -0
- package/build/cjs/esbuild/index.js.map +1 -1
- package/build/cjs/rollup/index.js +49 -9
- package/build/cjs/rollup/index.js.map +1 -1
- package/build/cjs/rollup/source-map-handling.js +202 -0
- package/build/cjs/rollup/source-map-handling.js.map +1 -0
- package/build/cjs/vite/index.js +4 -18
- package/build/cjs/vite/index.js.map +1 -1
- package/build/cjs/vite/source-map-hooks.js +93 -0
- package/build/cjs/vite/source-map-hooks.js.map +1 -0
- package/build/cjs/webpack/index.js +113 -1
- package/build/cjs/webpack/index.js.map +1 -1
- package/build/esm/core/build-plugin-manager.js +27 -8
- package/build/esm/core/build-plugin-manager.js.map +1 -1
- package/build/esm/core/index.js.map +1 -1
- package/build/esm/core/upload-filter.js +41 -0
- package/build/esm/core/upload-filter.js.map +1 -0
- package/build/esm/core/version.js +1 -1
- package/build/esm/core/version.js.map +1 -1
- package/build/esm/esbuild/index.js +1 -0
- package/build/esm/esbuild/index.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/rollup/index.js +49 -10
- package/build/esm/rollup/index.js.map +1 -1
- package/build/esm/rollup/source-map-handling.js +183 -0
- package/build/esm/rollup/source-map-handling.js.map +1 -0
- package/build/esm/vite/index.js +5 -19
- package/build/esm/vite/index.js.map +1 -1
- package/build/esm/vite/source-map-hooks.js +77 -0
- package/build/esm/vite/source-map-hooks.js.map +1 -0
- package/build/esm/webpack/index.js +114 -2
- package/build/esm/webpack/index.js.map +1 -1
- package/build/types/core/build-plugin-manager.d.ts +17 -5
- package/build/types/core/build-plugin-manager.d.ts.map +1 -1
- package/build/types/core/index.d.ts +1 -0
- package/build/types/core/index.d.ts.map +1 -1
- package/build/types/core/types.d.ts +7 -0
- package/build/types/core/types.d.ts.map +1 -1
- package/build/types/core/upload-filter.d.ts +9 -0
- package/build/types/core/upload-filter.d.ts.map +1 -0
- package/build/types/core/version.d.ts +1 -1
- package/build/types/esbuild/index.d.ts.map +1 -1
- package/build/types/rollup/index.d.ts +106 -6
- package/build/types/rollup/index.d.ts.map +1 -1
- package/build/types/rollup/source-map-handling.d.ts +59 -0
- package/build/types/rollup/source-map-handling.d.ts.map +1 -0
- package/build/types/vite/index.d.ts +1 -5
- package/build/types/vite/index.d.ts.map +1 -1
- package/build/types/vite/source-map-hooks.d.ts +45 -0
- package/build/types/vite/source-map-hooks.d.ts.map +1 -0
- package/build/types/webpack/index.d.ts.map +1 -1
- package/package.json +40 -38
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/esbuild/index.ts"],"sourcesContent":["import type { Options } from '../core';\nimport {\n createSentryBuildPluginManager,\n generateReleaseInjectorCode,\n generateModuleMetadataInjectorCode,\n getDebugIdSnippet,\n createDebugIdUploadFunction,\n CodeInjection,\n addDebugIdToEmittedArtifacts,\n isJsFile,\n} from '../core';\nimport * as path from 'node:path';\nimport { createRequire } from 'node:module';\nimport { randomUUID } from 'node:crypto';\n\ninterface EsbuildOnResolveArgs {\n path: string;\n kind: string;\n importer?: string;\n resolveDir: string;\n pluginData?: unknown;\n}\n\ninterface EsbuildOnResolveResult {\n path: string;\n sideEffects?: boolean;\n pluginName?: string;\n namespace?: string;\n suffix?: string;\n pluginData?: unknown;\n}\n\ninterface EsbuildOnLoadArgs {\n path: string;\n pluginData?: unknown;\n}\n\ninterface EsbuildOnLoadResult {\n loader: string;\n pluginName: string;\n contents: string;\n resolveDir?: string;\n}\n\ninterface EsbuildOnEndArgs {\n metafile?: {\n outputs: Record<string, unknown>;\n };\n}\n\ninterface EsbuildInitialOptions {\n bundle?: boolean;\n inject?: string[];\n metafile?: boolean;\n define?: Record<string, string>;\n write?: boolean;\n absWorkingDir?: string;\n}\n\ninterface EsbuildPluginBuild {\n initialOptions: EsbuildInitialOptions;\n onLoad: (\n options: { filter: RegExp; namespace?: string },\n callback: (args: EsbuildOnLoadArgs) => EsbuildOnLoadResult | null,\n ) => void;\n onResolve: (\n options: { filter: RegExp },\n callback: (args: EsbuildOnResolveArgs) => EsbuildOnResolveResult | undefined,\n ) => void;\n onStart: (callback: () => void) => void;\n onEnd: (callback: (result: EsbuildOnEndArgs) => void | Promise<void>) => void;\n}\n\nfunction getEsbuildMajorVersion(): string | undefined {\n try {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore - esbuild transpiles this for us\n const req = createRequire(import.meta.url);\n const esbuild = req('esbuild') as { version?: string };\n // esbuild hasn't released a v1 yet, so we'll return the minor version as the major version\n return esbuild.version?.split('.')[1];\n } catch {\n // do nothing, we'll just not report a version\n }\n\n return undefined;\n}\n\nconst pluginName = 'sentry-esbuild-plugin';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function sentryEsbuildPlugin(userOptions: Options = {}): any {\n const sentryBuildPluginManager = createSentryBuildPluginManager(userOptions, {\n loggerPrefix: userOptions._metaOptions?.loggerPrefixOverride ?? `[${pluginName}]`,\n buildTool: 'esbuild',\n buildToolMajorVersion: getEsbuildMajorVersion(),\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 name: 'sentry-esbuild-noop-plugin',\n setup() {\n // noop plugin\n },\n };\n }\n\n if (process.cwd().match(/\\\\node_modules\\\\|\\/node_modules\\//)) {\n logger.warn('Running Sentry plugin from within a `node_modules` folder. Some features may not work.');\n }\n\n const sourcemapsEnabled = options.sourcemaps?.disable !== true;\n const 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 // Component annotation warning\n if (options.reactComponentAnnotation?.enabled) {\n logger.warn(\n 'Component name annotation is not supported in esbuild. Please use a separate transform step or consider using a different bundler.',\n );\n }\n\n const transformReplace = Object.keys(replacementValues).length > 0;\n\n // Track entry points wrapped for debug ID injection\n const debugIdWrappedPaths = new Set<string>();\n\n void sentryBuildPluginManager.telemetry.emitBundlerPluginExecutionSignal().catch(() => {\n // Telemetry failures are acceptable\n });\n\n return {\n name: pluginName,\n setup({ initialOptions, onLoad, onResolve, onStart, onEnd }: EsbuildPluginBuild) {\n // Release and/or metadata injection\n if (!staticInjectionCode.isEmpty()) {\n const virtualInjectionFilePath = path.resolve('_sentry-injection-stub');\n initialOptions.inject = initialOptions.inject || [];\n // esbuild emits injected files after an entry's directive prologue. A banner would precede\n // \"use strict\" and turn it into an ordinary string expression.\n initialOptions.inject.push(virtualInjectionFilePath);\n\n onResolve({ filter: /_sentry-injection-stub/ }, args => {\n return {\n path: args.path,\n sideEffects: true,\n pluginName,\n };\n });\n\n onLoad({ filter: /_sentry-injection-stub/ }, () => {\n return {\n loader: 'js',\n pluginName,\n contents: staticInjectionCode.code(),\n };\n });\n }\n\n // Bundle size optimizations\n if (transformReplace) {\n const replacementStringValues: Record<string, string> = {};\n Object.entries(replacementValues).forEach(([key, value]) => {\n replacementStringValues[key] = JSON.stringify(value);\n });\n\n initialOptions.define = { ...initialOptions.define, ...replacementStringValues };\n }\n\n // Debug ID injection - requires per-entry-point unique IDs\n if (sourcemapsEnabled) {\n // `setup` runs once per context, `onStart` once per build, so a\n // rebuild wraps the entry points again.\n onStart(() => debugIdWrappedPaths.clear());\n\n if (!initialOptions.bundle) {\n logger.warn(\n 'The Sentry esbuild plugin only supports esbuild with `bundle: true` being set in the esbuild build options. Esbuild will probably crash now. Sorry about that. If you need to upload sourcemaps without `bundle: true`, it is recommended to use Sentry CLI instead: https://docs.sentry.io/platforms/javascript/sourcemaps/uploading/cli/',\n );\n }\n\n // Wrap entry points to inject debug IDs\n onResolve({ filter: /.*/ }, args => {\n if (args.kind !== 'entry-point') {\n return;\n }\n\n // Skip injecting debug IDs into modules specified in the esbuild `inject` option\n // since they're already part of the entry points\n if (initialOptions.inject?.includes(args.path)) {\n return;\n }\n\n const resolvedPath = path.isAbsolute(args.path) ? args.path : path.join(args.resolveDir, args.path);\n\n // Skip injecting debug IDs into paths that have already been wrapped\n if (debugIdWrappedPaths.has(resolvedPath)) {\n return;\n }\n debugIdWrappedPaths.add(resolvedPath);\n\n return {\n pluginName,\n path: resolvedPath,\n pluginData: {\n isDebugIdProxy: true,\n originalPath: args.path,\n originalResolveDir: args.resolveDir,\n },\n // We need to add a suffix here, otherwise esbuild will mark the entrypoint as resolved and won't traverse\n // the module tree any further down past the proxy module because we're essentially creating a dependency\n // loop back to the proxy module.\n // By setting a suffix we're telling esbuild that the entrypoint and proxy module are two different things,\n // making it re-resolve the entrypoint when it is imported from the proxy module.\n // Super confusing? Yes. Works? Apparently... Let's see.\n suffix: '?sentryDebugIdProxy=true',\n };\n });\n\n onLoad({ filter: /.*/ }, args => {\n if (!(args.pluginData as { isDebugIdProxy?: boolean })?.isDebugIdProxy) {\n return null;\n }\n\n const originalPath = (args.pluginData as { originalPath: string }).originalPath;\n const originalResolveDir = (args.pluginData as { originalResolveDir: string }).originalResolveDir;\n\n return {\n loader: 'js',\n pluginName,\n contents: `\n import \"_sentry-debug-id-injection-stub\";\n import * as OriginalModule from ${JSON.stringify(originalPath)};\n export default OriginalModule.default;\n export * from ${JSON.stringify(originalPath)};`,\n resolveDir: originalResolveDir,\n };\n });\n\n onResolve({ filter: /_sentry-debug-id-injection-stub/ }, args => {\n return {\n path: args.path,\n sideEffects: true,\n pluginName,\n namespace: 'sentry-debug-id-stub',\n suffix: `?sentry-module-id=${randomUUID()}`,\n };\n });\n\n onLoad({ filter: /_sentry-debug-id-injection-stub/, namespace: 'sentry-debug-id-stub' }, () => {\n return {\n loader: 'js',\n pluginName,\n contents: getDebugIdSnippet(randomUUID()).code(),\n };\n });\n }\n\n // Create release and optionally upload\n const freeGlobalDependencyOnBuildArtifacts = createDependencyOnBuildArtifacts();\n const upload = createDebugIdUploadFunction({ sentryBuildPluginManager });\n\n initialOptions.metafile = true;\n onEnd(async result => {\n try {\n await sentryBuildPluginManager.createRelease();\n\n if (sourcemapsEnabled) {\n const buildArtifacts = result.metafile ? Object.keys(result.metafile.outputs) : [];\n\n if (options.sourcemaps?.disable !== 'disable-upload') {\n await upload(buildArtifacts);\n } else if (initialOptions.write === false) {\n logger.debug('Build output is not written to disk. Skipping debug ID injection into build artifacts.');\n } else {\n // The upload routine (which stamps debug IDs into temp copies of the artifacts) is\n // skipped with `disable-upload`. esbuild has no hook to modify outputs before they are\n // written, so the emitted artifacts get stamped on disk instead.\n const outputDir = initialOptions.absWorkingDir ?? process.cwd();\n await Promise.all(\n buildArtifacts\n .filter(isJsFile)\n .map(bundle =>\n addDebugIdToEmittedArtifacts(\n path.resolve(outputDir, bundle),\n logger,\n options.sourcemaps?.resolveSourceMap,\n ),\n ),\n );\n }\n }\n } finally {\n freeGlobalDependencyOnBuildArtifacts();\n await sentryBuildPluginManager.deleteArtifacts();\n }\n });\n },\n };\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport default sentryEsbuildPlugin;\nexport type { Options as SentryEsbuildPluginOptions } from '../core';\n"],"names":["createRequire","createSentryBuildPluginManager","CodeInjection","generateReleaseInjectorCode","generateModuleMetadataInj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OAAA,KAAY,gBAAA,EAAkB;AACpD,cAAA,MAAM,OAAO,cAAc,CAAA;AAAA,YAC7B,CAAA,MAAA,IAAW,cAAA,CAAe,KAAA,KAAU,KAAA,EAAO;AACzC,cAAA,MAAA,CAAO,MAAM,wFAAwF,CAAA;AAAA,YACvG,CAAA,MAAO;AAIL,cAAA,MAAM,SAAA,GAAY,cAAA,CAAe,aAAA,IAAiB,OAAA,CAAQ,GAAA,EAAI;AAC9D,cAAA,MAAM,OAAA,CAAQ,GAAA;AAAA,gBACZ,cAAA,CACG,MAAA,CAAOC,cAAQ,CAAA,CACf,GAAA;AAAA,kBAAI,CAAA,MAAA,KACHC,0CAAA;AAAA,oBACEL,eAAA,CAAK,OAAA,CAAQ,SAAA,EAAW,MAAM,CAAA;AAAA,oBAC9B,MAAA;AAAA,oBACA,QAAQ,UAAA,EAAY;AAAA;AACtB;AACF,eACJ;AAAA,YACF;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;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/esbuild/index.ts"],"sourcesContent":["import type { Options } from '../core';\nimport {\n createSentryBuildPluginManager,\n generateReleaseInjectorCode,\n generateModuleMetadataInjectorCode,\n getDebugIdSnippet,\n createDebugIdUploadFunction,\n CodeInjection,\n addDebugIdToEmittedArtifacts,\n isJsFile,\n} from '../core';\nimport * as path from 'node:path';\nimport { createRequire } from 'node:module';\nimport { randomUUID } from 'node:crypto';\n\ninterface EsbuildOnResolveArgs {\n path: string;\n kind: string;\n importer?: string;\n resolveDir: string;\n pluginData?: unknown;\n}\n\ninterface EsbuildOnResolveResult {\n path: string;\n sideEffects?: boolean;\n pluginName?: string;\n namespace?: string;\n suffix?: string;\n pluginData?: unknown;\n}\n\ninterface EsbuildOnLoadArgs {\n path: string;\n pluginData?: unknown;\n}\n\ninterface EsbuildOnLoadResult {\n loader: string;\n pluginName: string;\n contents: string;\n resolveDir?: string;\n}\n\ninterface EsbuildOnEndArgs {\n metafile?: {\n outputs: Record<string, unknown>;\n };\n}\n\ninterface EsbuildInitialOptions {\n bundle?: boolean;\n inject?: string[];\n metafile?: boolean;\n define?: Record<string, string>;\n write?: boolean;\n absWorkingDir?: string;\n logOverride?: Record<string, string>;\n}\n\ninterface EsbuildPluginBuild {\n initialOptions: EsbuildInitialOptions;\n onLoad: (\n options: { filter: RegExp; namespace?: string },\n callback: (args: EsbuildOnLoadArgs) => EsbuildOnLoadResult | null,\n ) => void;\n onResolve: (\n options: { filter: RegExp },\n callback: (args: EsbuildOnResolveArgs) => EsbuildOnResolveResult | undefined,\n ) => void;\n onStart: (callback: () => void) => void;\n onEnd: (callback: (result: EsbuildOnEndArgs) => void | Promise<void>) => void;\n}\n\nfunction getEsbuildMajorVersion(): string | undefined {\n try {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore - esbuild transpiles this for us\n const req = createRequire(import.meta.url);\n const esbuild = req('esbuild') as { version?: string };\n // esbuild hasn't released a v1 yet, so we'll return the minor version as the major version\n return esbuild.version?.split('.')[1];\n } catch {\n // do nothing, we'll just not report a version\n }\n\n return undefined;\n}\n\nconst pluginName = 'sentry-esbuild-plugin';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function sentryEsbuildPlugin(userOptions: Options = {}): any {\n const sentryBuildPluginManager = createSentryBuildPluginManager(userOptions, {\n loggerPrefix: userOptions._metaOptions?.loggerPrefixOverride ?? `[${pluginName}]`,\n buildTool: 'esbuild',\n buildToolMajorVersion: getEsbuildMajorVersion(),\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 name: 'sentry-esbuild-noop-plugin',\n setup() {\n // noop plugin\n },\n };\n }\n\n if (process.cwd().match(/\\\\node_modules\\\\|\\/node_modules\\//)) {\n logger.warn('Running Sentry plugin from within a `node_modules` folder. Some features may not work.');\n }\n\n const sourcemapsEnabled = options.sourcemaps?.disable !== true;\n const 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 // Component annotation warning\n if (options.reactComponentAnnotation?.enabled) {\n logger.warn(\n 'Component name annotation is not supported in esbuild. Please use a separate transform step or consider using a different bundler.',\n );\n }\n\n const transformReplace = Object.keys(replacementValues).length > 0;\n\n // Track entry points wrapped for debug ID injection\n const debugIdWrappedPaths = new Set<string>();\n\n void sentryBuildPluginManager.telemetry.emitBundlerPluginExecutionSignal().catch(() => {\n // Telemetry failures are acceptable\n });\n\n return {\n name: pluginName,\n setup({ initialOptions, onLoad, onResolve, onStart, onEnd }: EsbuildPluginBuild) {\n // Release and/or metadata injection\n if (!staticInjectionCode.isEmpty()) {\n const virtualInjectionFilePath = path.resolve('_sentry-injection-stub');\n initialOptions.inject = initialOptions.inject || [];\n // esbuild emits injected files after an entry's directive prologue. A banner would precede\n // \"use strict\" and turn it into an ordinary string expression.\n initialOptions.inject.push(virtualInjectionFilePath);\n\n onResolve({ filter: /_sentry-injection-stub/ }, args => {\n return {\n path: args.path,\n sideEffects: true,\n pluginName,\n };\n });\n\n onLoad({ filter: /_sentry-injection-stub/ }, () => {\n return {\n loader: 'js',\n pluginName,\n contents: staticInjectionCode.code(),\n };\n });\n }\n\n // Bundle size optimizations\n if (transformReplace) {\n const replacementStringValues: Record<string, string> = {};\n Object.entries(replacementValues).forEach(([key, value]) => {\n replacementStringValues[key] = JSON.stringify(value);\n });\n\n initialOptions.define = { ...initialOptions.define, ...replacementStringValues };\n }\n\n // Debug ID injection - requires per-entry-point unique IDs\n if (sourcemapsEnabled) {\n // `setup` runs once per context, `onStart` once per build, so a\n // rebuild wraps the entry points again.\n onStart(() => debugIdWrappedPaths.clear());\n\n // The proxy module re-exports `OriginalModule.default` statically so downstream bundlers can tree-shake it,\n // but esbuild warns about that access when the entry point has no default export.\n initialOptions.logOverride = { 'import-is-undefined': 'silent', ...initialOptions.logOverride };\n\n if (!initialOptions.bundle) {\n logger.warn(\n 'The Sentry esbuild plugin only supports esbuild with `bundle: true` being set in the esbuild build options. Esbuild will probably crash now. Sorry about that. If you need to upload sourcemaps without `bundle: true`, it is recommended to use Sentry CLI instead: https://docs.sentry.io/platforms/javascript/sourcemaps/uploading/cli/',\n );\n }\n\n // Wrap entry points to inject debug IDs\n onResolve({ filter: /.*/ }, args => {\n if (args.kind !== 'entry-point') {\n return;\n }\n\n // Skip injecting debug IDs into modules specified in the esbuild `inject` option\n // since they're already part of the entry points\n if (initialOptions.inject?.includes(args.path)) {\n return;\n }\n\n const resolvedPath = path.isAbsolute(args.path) ? args.path : path.join(args.resolveDir, args.path);\n\n // Skip injecting debug IDs into paths that have already been wrapped\n if (debugIdWrappedPaths.has(resolvedPath)) {\n return;\n }\n debugIdWrappedPaths.add(resolvedPath);\n\n return {\n pluginName,\n path: resolvedPath,\n pluginData: {\n isDebugIdProxy: true,\n originalPath: args.path,\n originalResolveDir: args.resolveDir,\n },\n // We need to add a suffix here, otherwise esbuild will mark the entrypoint as resolved and won't traverse\n // the module tree any further down past the proxy module because we're essentially creating a dependency\n // loop back to the proxy module.\n // By setting a suffix we're telling esbuild that the entrypoint and proxy module are two different things,\n // making it re-resolve the entrypoint when it is imported from the proxy module.\n // Super confusing? Yes. Works? Apparently... Let's see.\n suffix: '?sentryDebugIdProxy=true',\n };\n });\n\n onLoad({ filter: /.*/ }, args => {\n if (!(args.pluginData as { isDebugIdProxy?: boolean })?.isDebugIdProxy) {\n return null;\n }\n\n const originalPath = (args.pluginData as { originalPath: string }).originalPath;\n const originalResolveDir = (args.pluginData as { originalResolveDir: string }).originalResolveDir;\n\n return {\n loader: 'js',\n pluginName,\n contents: `\n import \"_sentry-debug-id-injection-stub\";\n import * as OriginalModule from ${JSON.stringify(originalPath)};\n export default OriginalModule.default;\n export * from ${JSON.stringify(originalPath)};`,\n resolveDir: originalResolveDir,\n };\n });\n\n onResolve({ filter: /_sentry-debug-id-injection-stub/ }, args => {\n return {\n path: args.path,\n sideEffects: true,\n pluginName,\n namespace: 'sentry-debug-id-stub',\n suffix: `?sentry-module-id=${randomUUID()}`,\n };\n });\n\n onLoad({ filter: /_sentry-debug-id-injection-stub/, namespace: 'sentry-debug-id-stub' }, () => {\n return {\n loader: 'js',\n pluginName,\n contents: getDebugIdSnippet(randomUUID()).code(),\n };\n });\n }\n\n // Create release and optionally upload\n const freeGlobalDependencyOnBuildArtifacts = createDependencyOnBuildArtifacts();\n const upload = createDebugIdUploadFunction({ sentryBuildPluginManager });\n\n initialOptions.metafile = true;\n onEnd(async result => {\n try {\n await sentryBuildPluginManager.createRelease();\n\n if (sourcemapsEnabled) {\n const buildArtifacts = result.metafile ? Object.keys(result.metafile.outputs) : [];\n\n if (options.sourcemaps?.disable !== 'disable-upload') {\n await upload(buildArtifacts);\n } else if (initialOptions.write === false) {\n logger.debug('Build output is not written to disk. Skipping debug ID injection into build artifacts.');\n } else {\n // The upload routine (which stamps debug IDs into temp copies of the artifacts) is\n // skipped with `disable-upload`. esbuild has no hook to modify outputs before they are\n // written, so the emitted artifacts get stamped on disk instead.\n const outputDir = initialOptions.absWorkingDir ?? process.cwd();\n await Promise.all(\n buildArtifacts\n .filter(isJsFile)\n .map(bundle =>\n addDebugIdToEmittedArtifacts(\n path.resolve(outputDir, bundle),\n logger,\n options.sourcemaps?.resolveSourceMap,\n ),\n ),\n );\n }\n }\n } finally {\n freeGlobalDependencyOnBuildArtifacts();\n await sentryBuildPluginManager.deleteArtifacts();\n }\n });\n },\n };\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport default sentryEsbuildPlugin;\nexport type { Options as SentryEsbuildPluginOptions } from '../core';\n"],"names":["createRequire","createSentryBuildPluginManager","CodeInjection","generateReleaseInjectorCode","generateModuleMetadataInjectorCode","path","randomUUID","getDebugIdSnippet","createDebugIdUploadFunction","isJsFile","addDebugIdToEmittedArtifacts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA0EA,SAAS,sBAAA,GAA6C;AACpD,EAAA,IAAI;AAGF,IAAA,MAAM,GAAA,GAAMA,yBAAA,CAAc,kQAAe,CAAA;AACzC,IAAA,MAAM,OAAA,GAAU,IAAI,SAAS,CAAA;AAE7B,IAAA,OAAO,OAAA,CAAQ,OAAA,EAAS,KAAA,CAAM,GAAG,EAAE,CAAC,CAAA;AAAA,EACtC,CAAA,CAAA,MAAQ;AAAA,EAER;AAEA,EAAA,OAAO,MAAA;AACT;AAEA,MAAM,UAAA,GAAa,uBAAA;AAGZ,SAAS,mBAAA,CAAoB,WAAA,GAAuB,EAAC,EAAQ;AAClE,EAAA,MAAM,wBAAA,GAA2BC,kDAA+B,WAAA,EAAa;AAAA,IAC3E,YAAA,EAAc,WAAA,CAAY,YAAA,EAAc,oBAAA,IAAwB,IAAI,UAAU,CAAA,CAAA,CAAA;AAAA,IAC9E,SAAA,EAAW,SAAA;AAAA,IACX,uBAAuB,sBAAA;AAAuB,GAC/C,CAAA;AAED,EAAA,MAAM;AAAA,IACJ,MAAA;AAAA,IACA,iBAAA,EAAmB,OAAA;AAAA,IACnB,uCAAA,EAAyC,iBAAA;AAAA,IACzC,cAAA;AAAA,IACA;AAAA,GACF,GAAI,wBAAA;AAEJ,EAAA,IAAI,QAAQ,OAAA,EAAS;AACnB,IAAA,OAAO;AAAA,MACL,IAAA,EAAM,4BAAA;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wBAAA,EAA0B,CAAA;AAEvE,MAAA,cAAA,CAAe,QAAA,GAAW,IAAA;AAC1B,MAAA,KAAA,CAAM,OAAM,MAAA,KAAU;AACpB,QAAA,IAAI;AACF,UAAA,MAAM,yBAAyB,aAAA,EAAc;AAE7C,UAAA,IAAI,iBAAA,EAAmB;AACrB,YAAA,MAAM,cAAA,GAAiB,OAAO,QAAA,GAAW,MAAA,CAAO,KAAK,MAAA,CAAO,QAAA,CAAS,OAAO,CAAA,GAAI,EAAC;AAEjF,YAAA,IAAI,OAAA,CAAQ,UAAA,EAAY,OAAA,KAAY,gBAAA,EAAkB;AACpD,cAAA,MAAM,OAAO,cAAc,CAAA;AAAA,YAC7B,CAAA,MAAA,IAAW,cAAA,CAAe,KAAA,KAAU,KAAA,EAAO;AACzC,cAAA,MAAA,CAAO,MAAM,wFAAwF,CAAA;AAAA,YACvG,CAAA,MAAO;AAIL,cAAA,MAAM,SAAA,GAAY,cAAA,CAAe,aAAA,IAAiB,OAAA,CAAQ,GAAA,EAAI;AAC9D,cAAA,MAAM,OAAA,CAAQ,GAAA;AAAA,gBACZ,cAAA,CACG,MAAA,CAAOC,cAAQ,CAAA,CACf,GAAA;AAAA,kBAAI,CAAA,MAAA,KACHC,0CAAA;AAAA,oBACEL,eAAA,CAAK,OAAA,CAAQ,SAAA,EAAW,MAAM,CAAA;AAAA,oBAC9B,MAAA;AAAA,oBACA,QAAQ,UAAA,EAAY;AAAA;AACtB;AACF,eACJ;AAAA,YACF;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;;;;;"}
|
|
@@ -6,6 +6,8 @@ const path = require('node:path');
|
|
|
6
6
|
const node_module = require('node:module');
|
|
7
7
|
const debugIdInjection = require('./debug-id-injection.js');
|
|
8
8
|
const debugIdStamping = require('./debug-id-stamping.js');
|
|
9
|
+
const sourceMapHandling = require('./source-map-handling.js');
|
|
10
|
+
const sourceMapHooks = require('../vite/source-map-hooks.js');
|
|
9
11
|
const buildPluginManager = require('../core/build-plugin-manager.js');
|
|
10
12
|
const utils = require('../core/utils.js');
|
|
11
13
|
const componentAnnotateHooks = require('../core/component-annotate-hooks.js');
|
|
@@ -59,7 +61,7 @@ function getViteParseAstAsync() {
|
|
|
59
61
|
}
|
|
60
62
|
return viteParseAstAsyncPromise;
|
|
61
63
|
}
|
|
62
|
-
function
|
|
64
|
+
function _createRollupPluginInternals(userOptions = {}, buildTool, buildToolMajorVersion) {
|
|
63
65
|
const sentryBuildPluginManager = buildPluginManager.createSentryBuildPluginManager(userOptions, {
|
|
64
66
|
loggerPrefix: userOptions._metaOptions?.loggerPrefixOverride ?? `[sentry-${buildTool}-plugin]`,
|
|
65
67
|
buildTool,
|
|
@@ -74,7 +76,10 @@ function _rollupPluginInternal(userOptions = {}, buildTool, buildToolMajorVersio
|
|
|
74
76
|
} = sentryBuildPluginManager;
|
|
75
77
|
if (options.disable) {
|
|
76
78
|
return {
|
|
77
|
-
|
|
79
|
+
main: {
|
|
80
|
+
name: "sentry-noop-plugin"
|
|
81
|
+
},
|
|
82
|
+
post: void 0
|
|
78
83
|
};
|
|
79
84
|
}
|
|
80
85
|
if (process.cwd().match(/\\node_modules\\|\/node_modules\//)) {
|
|
@@ -83,6 +88,7 @@ function _rollupPluginInternal(userOptions = {}, buildTool, buildToolMajorVersio
|
|
|
83
88
|
const freeGlobalDependencyOnBuildArtifacts = createDependencyOnBuildArtifacts();
|
|
84
89
|
const upload = debugIdUpload.createDebugIdUploadFunction({ sentryBuildPluginManager });
|
|
85
90
|
const sourcemapsEnabled = options.sourcemaps?.disable !== true;
|
|
91
|
+
const sourceMapHandling$1 = sourceMapHandling.createSourceMapHandling(sentryBuildPluginManager);
|
|
86
92
|
const releaseInjectionCode = new utils.CodeInjection();
|
|
87
93
|
const chunkInjectionCode = new utils.CodeInjection();
|
|
88
94
|
if (!options.release.inject) {
|
|
@@ -171,9 +177,12 @@ ${injectCode.code()}` : injectCode.code();
|
|
|
171
177
|
debugIdStamping.stampDebugIds(bundle, true);
|
|
172
178
|
}
|
|
173
179
|
async function writeBundle(outputOptions, bundle) {
|
|
180
|
+
const staging = await sourceMapHandling$1.takeStaging(outputOptions, bundle);
|
|
181
|
+
let stagingHandedOver = false;
|
|
174
182
|
try {
|
|
175
183
|
await sentryBuildPluginManager.createRelease();
|
|
176
184
|
if (sourcemapsEnabled && options.sourcemaps?.disable !== "disable-upload") {
|
|
185
|
+
let buildArtifacts;
|
|
177
186
|
if (outputOptions.dir) {
|
|
178
187
|
const outputDir = outputOptions.dir;
|
|
179
188
|
const JS_AND_MAP_PATTERNS = [
|
|
@@ -184,15 +193,23 @@ ${injectCode.code()}` : injectCode.code();
|
|
|
184
193
|
"/**/*.mjs.map",
|
|
185
194
|
"/**/*.cjs.map"
|
|
186
195
|
].map((q) => `${q}?(\\?*)?(#*)`);
|
|
187
|
-
|
|
188
|
-
await upload(buildArtifacts);
|
|
196
|
+
buildArtifacts = await glob.globFiles(JS_AND_MAP_PATTERNS, { root: outputDir });
|
|
189
197
|
} else if (outputOptions.file) {
|
|
190
|
-
|
|
198
|
+
buildArtifacts = [outputOptions.file];
|
|
191
199
|
} else {
|
|
192
|
-
|
|
193
|
-
await upload(buildArtifacts);
|
|
200
|
+
buildArtifacts = Object.keys(bundle ?? {}).map((asset) => path__namespace.join(path__namespace.resolve(), asset));
|
|
194
201
|
}
|
|
202
|
+
stagingHandedOver = true;
|
|
203
|
+
await upload(buildArtifacts, { staging });
|
|
204
|
+
} else {
|
|
205
|
+
stagingHandedOver = true;
|
|
206
|
+
await staging?.discard();
|
|
207
|
+
}
|
|
208
|
+
} catch (e) {
|
|
209
|
+
if (!stagingHandedOver) {
|
|
210
|
+
await staging?.keep("The source map upload did not run.");
|
|
195
211
|
}
|
|
212
|
+
throw e;
|
|
196
213
|
} finally {
|
|
197
214
|
freeGlobalDependencyOnBuildArtifacts();
|
|
198
215
|
await sentryBuildPluginManager.deleteArtifacts();
|
|
@@ -203,19 +220,42 @@ ${injectCode.code()}` : injectCode.code();
|
|
|
203
220
|
filter: { id: JS_MODULE_ID_FILTER },
|
|
204
221
|
handler: transform
|
|
205
222
|
} : transform;
|
|
206
|
-
|
|
223
|
+
const viteSourceMapHooks = buildTool === "vite" ? sourceMapHooks.createViteSourceMapHooks(sentryBuildPluginManager, sourceMapHandling$1) : void 0;
|
|
224
|
+
const main = {
|
|
207
225
|
name,
|
|
208
226
|
buildStart,
|
|
209
227
|
...shouldTransform ? { transform: transformHook } : {},
|
|
228
|
+
...viteSourceMapHooks ? { configResolved: viteSourceMapHooks.configResolved } : { outputOptions: sourceMapHandling$1.outputOptions },
|
|
210
229
|
renderChunk,
|
|
211
230
|
generateBundle: { order: "pre", handler: generateBundle },
|
|
212
231
|
writeBundle
|
|
213
232
|
};
|
|
233
|
+
const post = {
|
|
234
|
+
name: buildTool === "vite" ? "sentry-vite-upload-staging" : "sentry-rollup-upload-staging",
|
|
235
|
+
// On the post plugin, so framework plugins that set `build.sourcemap`
|
|
236
|
+
// themselves run first and the decision sees the merged setting.
|
|
237
|
+
...viteSourceMapHooks ? { config: viteSourceMapHooks.config } : {},
|
|
238
|
+
generateBundle: {
|
|
239
|
+
order: "post",
|
|
240
|
+
async handler(outputOptions, bundle, isWrite) {
|
|
241
|
+
if (buildTool === "vite" && options.sourcemaps?.disable === "disable-upload") {
|
|
242
|
+
debugIdStamping.stampDebugIds(bundle, false);
|
|
243
|
+
}
|
|
244
|
+
await sourceMapHandling$1.stageSourceMaps(outputOptions, bundle, isWrite);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
return { main, post };
|
|
249
|
+
}
|
|
250
|
+
function _rollupPluginInternal(userOptions = {}, buildTool, buildToolMajorVersion) {
|
|
251
|
+
return _createRollupPluginInternals(userOptions, buildTool, buildToolMajorVersion).main;
|
|
214
252
|
}
|
|
215
253
|
function sentryRollupPlugin(userOptions = {}) {
|
|
216
|
-
|
|
254
|
+
const { main, post } = _createRollupPluginInternals(userOptions, "rollup");
|
|
255
|
+
return post ? [main, post] : [main];
|
|
217
256
|
}
|
|
218
257
|
|
|
258
|
+
exports._createRollupPluginInternals = _createRollupPluginInternals;
|
|
219
259
|
exports._rollupPluginInternal = _rollupPluginInternal;
|
|
220
260
|
exports.sentryRollupPlugin = sentryRollupPlugin;
|
|
221
261
|
//# sourceMappingURL=index.js.map
|
|
@@ -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';\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 - 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 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 name: 'sentry-noop-plugin',\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 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(\n outputOptions: { dir?: string; file?: string },\n bundle: { [fileName: string]: unknown },\n ): Promise<void> {\n try {\n await sentryBuildPluginManager.createRelease();\n\n if (sourcemapsEnabled && options.sourcemaps?.disable !== 'disable-upload') {\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 const buildArtifacts = await globFiles(JS_AND_MAP_PATTERNS, { root: outputDir });\n await upload(buildArtifacts);\n } else if (outputOptions.file) {\n await upload([outputOptions.file]);\n } else {\n const buildArtifacts = Object.keys(bundle).map(asset => path.join(path.resolve(), asset));\n await upload(buildArtifacts);\n }\n }\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 return {\n name,\n buildStart,\n ...(shouldTransform ? { transform: transformHook } : {}),\n renderChunk,\n generateBundle: { order: 'pre' as const, handler: generateBundle },\n writeBundle,\n };\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 // We return an array here so we don't break backwards compatibility with what\n // unplugin used to return\n return [_rollupPluginInternal(userOptions, 'rollup')];\n}\n\nexport type { Options as SentryRollupPluginOptions } from '../core';\n"],"names":["createRequire","createSentryBuildPluginManager","createDebugIdUploadFunction","CodeInjection","generateReleaseInjectorCode","generateModuleMetadataInjectorCode","createComponentNameAnnotateHooks","replaceBooleanFlagsInCode","isJsFile","shouldSkipCodeInjection","isInitialChunk","hasExistingDebugID","getDebugIdForChunk","getDebugIdSnippet","MagicString","getCodeInjectionPosition","finalizeRolldownDebugIds","stampDebugIds","globFiles","path"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,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,aAAA,KAAkB,UAAA,EAAY;AAClD,QAAA,OAAO,IAAA;AAAA,MACT;AAEA,MAAA,IAAI;AACF,QAAA,MAAM,WAAW,aAAA,CAAc,oBAAA,EAAsB,EAAE,IAAA,EAAM,OAAO,CAAA;AAAA,MACtE,CAAA,CAAA,MAAQ;AACN,QAAA,OAAO,IAAA;AAAA,MACT;AAEA,MAAA,OAAO,UAAA,CAAW,aAAA;AAAA,IACpB,CAAC,CAAA,CACA,KAAA,CAAM,MAAM,IAAI,CAAA;AAAA,EACrB;AAEA,EAAA,OAAO,wBAAA;AACT;AAMO,SAAS,qBAAA,CACd,WAAA,GAAuB,EAAC,EACxB,WACA,qBAAA,EACA;AACA,EAAA,MA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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,4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,QAAQ,CAAA;AAGzE,EAAA,OAAO,OAAO,CAAC,IAAA,EAAM,IAAI,CAAA,GAAI,CAAC,IAAI,CAAA;AACpC;;;;;;"}
|
|
@@ -0,0 +1,202 @@
|
|
|
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
|
+
|
|
20
|
+
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
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function getOutputDestination(outputOptions) {
|
|
33
|
+
return path__namespace.resolve(outputOptions.dir ?? path__namespace.dirname(outputOptions.file ?? "."));
|
|
34
|
+
}
|
|
35
|
+
const MATCH_KEYS = [
|
|
36
|
+
"dir",
|
|
37
|
+
"file",
|
|
38
|
+
"format",
|
|
39
|
+
"entryFileNames",
|
|
40
|
+
"chunkFileNames",
|
|
41
|
+
"preserveModules",
|
|
42
|
+
"sourcemap"
|
|
43
|
+
];
|
|
44
|
+
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
|
+
}
|
|
56
|
+
}
|
|
57
|
+
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;
|
|
67
|
+
}
|
|
68
|
+
function matchesOutput(match, outputOptions) {
|
|
69
|
+
const actual = getOutputMatch(outputOptions);
|
|
70
|
+
return MATCH_KEYS.every((key) => match[key] === void 0 || match[key] === actual[key]);
|
|
71
|
+
}
|
|
72
|
+
function isSameMatch(a, b) {
|
|
73
|
+
return MATCH_KEYS.every((key) => a[key] === b[key]);
|
|
74
|
+
}
|
|
75
|
+
function countMatchFields(match) {
|
|
76
|
+
return MATCH_KEYS.filter((key) => match[key] !== void 0).length;
|
|
77
|
+
}
|
|
78
|
+
const DEBUG_ID_PATTERN = /sentry-dbid-([0-9a-f-]{36})|\/\/# debugId=([0-9a-f-]{36})/i;
|
|
79
|
+
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");
|
|
88
|
+
}
|
|
89
|
+
function getSourceMapFileName(output) {
|
|
90
|
+
return output.sourcemapFileName ?? `${output.fileName}.map`;
|
|
91
|
+
}
|
|
92
|
+
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
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
exports.createSourceMapHandling = createSourceMapHandling;
|
|
199
|
+
exports.getOutputDestination = getOutputDestination;
|
|
200
|
+
exports.getOutputMatch = getOutputMatch;
|
|
201
|
+
exports.sourceMapKindFromRollupSetting = sourceMapKindFromRollupSetting;
|
|
202
|
+
//# sourceMappingURL=source-map-handling.js.map
|
|
@@ -0,0 +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,Q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AAErF,MAAA,KAAA,MAAW,WAAW,UAAA,EAAY;AAChC,QAAA,wBAAA,CAAyB,MAAA,CAAO,KAAA;AAAA,UAC9B,wDAAwD,WAAW,CAAA,wBAAA;AAAA,SACrE;AACA,QAAA,MAAM,OAAA,CAAQ,QAAQ,OAAA,EAAQ;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;;;;;;;"}
|
package/build/cjs/vite/index.js
CHANGED
|
@@ -2,7 +2,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
|
|
3
3
|
const index = require('../rollup/index.js');
|
|
4
4
|
const node_module = require('node:module');
|
|
5
|
-
const debugIdStamping = require('../rollup/debug-id-stamping.js');
|
|
6
5
|
|
|
7
6
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
8
7
|
function getViteMajorVersion() {
|
|
@@ -15,23 +14,10 @@ function getViteMajorVersion() {
|
|
|
15
14
|
return void 0;
|
|
16
15
|
}
|
|
17
16
|
const sentryVitePlugin = (options) => {
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
];
|
|
24
|
-
if (!options?.disable && options?.sourcemaps?.disable === "disable-upload") {
|
|
25
|
-
plugins.push({
|
|
26
|
-
name: "sentry-vite-debug-id-sourcemaps",
|
|
27
|
-
enforce: "post",
|
|
28
|
-
generateBundle: {
|
|
29
|
-
order: "post",
|
|
30
|
-
handler(_outputOptions, bundle) {
|
|
31
|
-
debugIdStamping.stampDebugIds(bundle, false);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
});
|
|
17
|
+
const { main, post } = index._createRollupPluginInternals(options, "vite", getViteMajorVersion());
|
|
18
|
+
const plugins = [{ enforce: "pre", ...main }];
|
|
19
|
+
if (post) {
|
|
20
|
+
plugins.push({ enforce: "post", ...post });
|
|
35
21
|
}
|
|
36
22
|
return plugins;
|
|
37
23
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/vite/index.ts"],"sourcesContent":["import type { SentryRollupPluginOptions } from '../rollup';\nimport {
|
|
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;;;;"}
|