@sentry/bundler-plugins 11.10.0 → 11.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/core/build-plugin-manager.js +165 -33
- package/build/cjs/core/build-plugin-manager.js.map +1 -1
- package/build/cjs/core/debug-id-upload.js +63 -54
- package/build/cjs/core/debug-id-upload.js.map +1 -1
- package/build/cjs/core/index.js +2 -0
- package/build/cjs/core/index.js.map +1 -1
- package/build/cjs/core/options-mapping.js +6 -0
- package/build/cjs/core/options-mapping.js.map +1 -1
- package/build/cjs/core/sentry/telemetry.js +4 -0
- package/build/cjs/core/sentry/telemetry.js.map +1 -1
- package/build/cjs/core/sourcemap-settings.js +63 -0
- package/build/cjs/core/sourcemap-settings.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 +2 -2
- package/build/cjs/esbuild/index.js.map +1 -1
- package/build/esm/core/build-plugin-manager.js +166 -34
- package/build/esm/core/build-plugin-manager.js.map +1 -1
- package/build/esm/core/debug-id-upload.js +62 -56
- package/build/esm/core/debug-id-upload.js.map +1 -1
- package/build/esm/core/index.js +1 -0
- package/build/esm/core/index.js.map +1 -1
- package/build/esm/core/options-mapping.js +6 -0
- package/build/esm/core/options-mapping.js.map +1 -1
- package/build/esm/core/sentry/telemetry.js +4 -0
- package/build/esm/core/sentry/telemetry.js.map +1 -1
- package/build/esm/core/sourcemap-settings.js +61 -0
- package/build/esm/core/sourcemap-settings.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 +2 -2
- package/build/esm/esbuild/index.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/types/core/build-plugin-manager.d.ts +57 -1
- package/build/types/core/build-plugin-manager.d.ts.map +1 -1
- package/build/types/core/debug-id-upload.d.ts +38 -2
- package/build/types/core/debug-id-upload.d.ts.map +1 -1
- package/build/types/core/index.d.ts +3 -0
- package/build/types/core/index.d.ts.map +1 -1
- package/build/types/core/options-mapping.d.ts +1 -0
- package/build/types/core/options-mapping.d.ts.map +1 -1
- package/build/types/core/sentry/telemetry.d.ts.map +1 -1
- package/build/types/core/sourcemap-settings.d.ts +28 -0
- package/build/types/core/sourcemap-settings.d.ts.map +1 -0
- package/build/types/core/types.d.ts +11 -0
- package/build/types/core/types.d.ts.map +1 -1
- package/build/types/core/version.d.ts +1 -1
- package/build/types/esbuild/index.d.ts.map +1 -1
- package/package.json +7 -7
|
@@ -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 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, 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 // Clear state from previous builds (important for watch mode and test suites)\n 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","generateModuleMetadataInjectorCode","path","randomUUID","getDebugIdSnippet","createDebugIdUploadFunction","isJsFile","addDebugIdToEmittedArtifacts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAwEA,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,K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G,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}\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","generateModuleMetadataInjectorCode","path","randomUUID","getDebugIdSnippet","createDebugIdUploadFunction","isJsFile","addDebugIdToEmittedArtifacts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAyEA,SAAS,sBAAA,GAA6C;AACpD,EAAA,IAAI;AAGF,IAAA,MAAM,GAAA,GAAMA,yBAAA,CAAc,kQAAe,CAAA;AACzC,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AA,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;;;;;"}
|
|
@@ -3,13 +3,15 @@ import * as dotenv from 'dotenv';
|
|
|
3
3
|
import * as fs from 'fs';
|
|
4
4
|
import * as os from 'os';
|
|
5
5
|
import * as path from 'path';
|
|
6
|
+
import { escape } from 'glob';
|
|
6
7
|
import { SentryCliAdapter } from './cli.js';
|
|
7
8
|
import { normalizeUserOptions, validateOptions } from './options-mapping.js';
|
|
8
9
|
import { createLogger } from './logger.js';
|
|
9
10
|
import { allowedToSendTelemetry, createSentryInstance, safeFlushTelemetry } from './sentry/telemetry.js';
|
|
10
11
|
import { getProjects, stripQueryAndHashFromPath, getTurborepoEnvPassthroughWarning, arrayify } from './utils.js';
|
|
11
|
-
import {
|
|
12
|
+
import { defaultRewriteSourcesHook, prepareArtifactForUpload, writePreparedArtifact, prepareBundleForDebugIdUpload } from './debug-id-upload.js';
|
|
12
13
|
import { globFiles } from './glob.js';
|
|
14
|
+
import { decideSourceMapHandling } from './sourcemap-settings.js';
|
|
13
15
|
import { LIB_VERSION } from './version.js';
|
|
14
16
|
|
|
15
17
|
const _deployedReleases = /* @__PURE__ */ new Set();
|
|
@@ -42,7 +44,20 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
|
|
|
42
44
|
bundleMetadata: {},
|
|
43
45
|
createRelease: async () => {
|
|
44
46
|
},
|
|
45
|
-
uploadSourcemaps: async () => {
|
|
47
|
+
uploadSourcemaps: async () => ({ uploaded: false }),
|
|
48
|
+
createUploadStaging: async () => ({
|
|
49
|
+
dir: "",
|
|
50
|
+
count: 0,
|
|
51
|
+
stagedChunkPaths: /* @__PURE__ */ new Set(),
|
|
52
|
+
stage: async () => "skipped",
|
|
53
|
+
discard: async () => {
|
|
54
|
+
},
|
|
55
|
+
keep: async () => {
|
|
56
|
+
}
|
|
57
|
+
}),
|
|
58
|
+
sourceMaps: {
|
|
59
|
+
uploadPossible: false,
|
|
60
|
+
decide: () => ({ enableHidden: false, deleteAfterUpload: false })
|
|
46
61
|
},
|
|
47
62
|
deleteArtifacts: async () => {
|
|
48
63
|
},
|
|
@@ -123,6 +138,8 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
|
|
|
123
138
|
notifyBuildArtifactDependencySubscribers();
|
|
124
139
|
};
|
|
125
140
|
}
|
|
141
|
+
const sourceMapUploadPossible = getSourceMapUploadBlocker(options, isDevMode) === void 0;
|
|
142
|
+
const loggedSourceMapMessages = /* @__PURE__ */ new Set();
|
|
126
143
|
function waitUntilBuildArtifactDependenciesAreFreed() {
|
|
127
144
|
return new Promise((resolve) => {
|
|
128
145
|
buildArtifactsDependencySubscribers.push(() => {
|
|
@@ -335,21 +352,20 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
|
|
|
335
352
|
* @param opts - Optional flags to control temp folder usage and preparation
|
|
336
353
|
*/
|
|
337
354
|
async uploadSourcemaps(buildArtifactPaths, opts) {
|
|
355
|
+
const staging = opts?.staging;
|
|
338
356
|
if (!canUploadSourceMaps(options, logger, isDevMode)) {
|
|
339
|
-
|
|
357
|
+
await staging?.discard();
|
|
358
|
+
return { uploaded: false };
|
|
340
359
|
}
|
|
341
360
|
const assets = options.sourcemaps?.assets;
|
|
342
|
-
|
|
343
|
-
logger.debug("Empty `sourcemaps.assets` option provided. Will not upload sourcemaps with debug ID.");
|
|
344
|
-
return;
|
|
345
|
-
}
|
|
361
|
+
let uploaded = false;
|
|
346
362
|
await startSpan(
|
|
347
363
|
// This is `forceTransaction`ed because this span is used in dashboards in the form of indexed transactions.
|
|
348
364
|
// oxlint-disable-next-line typescript/no-deprecated
|
|
349
365
|
{ name: "debug-id-sourcemap-upload", scope: sentryScope, forceTransaction: true },
|
|
350
366
|
async () => {
|
|
351
367
|
const shouldPrepare = opts?.prepareArtifacts ?? true;
|
|
352
|
-
let folderToCleanUp;
|
|
368
|
+
let folderToCleanUp = staging?.dir;
|
|
353
369
|
const freeUploadDependencyOnBuildArtifacts = createDependencyOnBuildArtifacts();
|
|
354
370
|
try {
|
|
355
371
|
if (!shouldPrepare) {
|
|
@@ -362,6 +378,15 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
|
|
|
362
378
|
} else {
|
|
363
379
|
pathsToUpload = buildArtifactPaths;
|
|
364
380
|
}
|
|
381
|
+
if (staging && staging.count > 0) {
|
|
382
|
+
pathsToUpload = [...pathsToUpload, staging.dir];
|
|
383
|
+
}
|
|
384
|
+
if (pathsToUpload.length === 0) {
|
|
385
|
+
logger.warn(
|
|
386
|
+
"Didn't find any matching sources for debug ID upload. Please check the `sourcemaps.assets` option."
|
|
387
|
+
);
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
365
390
|
await startSpan({ name: "upload", scope: sentryScope }, async () => {
|
|
366
391
|
const cliInstance = new SentryCliAdapter(options);
|
|
367
392
|
await cliInstance.uploadSourcemaps(
|
|
@@ -373,6 +398,7 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
|
|
|
373
398
|
}))
|
|
374
399
|
);
|
|
375
400
|
});
|
|
401
|
+
uploaded = true;
|
|
376
402
|
logger.info("Successfully uploaded source maps to Sentry");
|
|
377
403
|
} else {
|
|
378
404
|
let globAssets;
|
|
@@ -382,31 +408,31 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
|
|
|
382
408
|
logger.debug(
|
|
383
409
|
"No `sourcemaps.assets` option provided, falling back to uploading detected build artifacts."
|
|
384
410
|
);
|
|
385
|
-
globAssets = buildArtifactPaths;
|
|
411
|
+
globAssets = buildArtifactPaths.map((asset) => escape(asset.split(path.sep).join("/")));
|
|
386
412
|
}
|
|
387
413
|
const globResult = await startSpan(
|
|
388
414
|
{ name: "glob", scope: sentryScope },
|
|
389
415
|
async () => globFiles(globAssets, { ignore: options.sourcemaps?.ignore })
|
|
390
416
|
);
|
|
391
417
|
const debugIdChunkFilePaths = globResult.filter((debugIdChunkFilePath) => {
|
|
392
|
-
|
|
418
|
+
const filePath = stripQueryAndHashFromPath(debugIdChunkFilePath);
|
|
419
|
+
return !!filePath.match(/\.(js|mjs|cjs)$/) && !staging?.stagedChunkPaths.has(path.resolve(filePath));
|
|
393
420
|
});
|
|
394
421
|
debugIdChunkFilePaths.sort();
|
|
395
|
-
|
|
422
|
+
const stagedCount = staging?.count ?? 0;
|
|
423
|
+
if (debugIdChunkFilePaths.length === 0 && stagedCount === 0) {
|
|
396
424
|
logger.warn(
|
|
397
425
|
"Didn't find any matching sources for debug ID upload. Please check the `sourcemaps.assets` option."
|
|
398
426
|
);
|
|
399
427
|
} else {
|
|
400
|
-
const tmpUploadFolder = await startSpan({ name: "mkdtemp", scope: sentryScope },
|
|
401
|
-
return process.env?.["SENTRY_TEST_OVERRIDE_TEMP_DIR"] || await fs.promises.mkdtemp(path.join(os.tmpdir(), "sentry-bundler-plugin-upload-"));
|
|
402
|
-
});
|
|
428
|
+
const tmpUploadFolder = staging?.dir ?? await startSpan({ name: "mkdtemp", scope: sentryScope }, () => createTempUploadFolder());
|
|
403
429
|
folderToCleanUp = tmpUploadFolder;
|
|
404
430
|
await startSpan({ name: "prepare-bundles", scope: sentryScope }, async (prepBundlesSpan) => {
|
|
405
431
|
const preparationTasks = debugIdChunkFilePaths.map((chunkFilePath, chunkIndex) => async () => {
|
|
406
432
|
await prepareBundleForDebugIdUpload(
|
|
407
433
|
chunkFilePath,
|
|
408
434
|
tmpUploadFolder,
|
|
409
|
-
chunkIndex,
|
|
435
|
+
stagedCount + chunkIndex,
|
|
410
436
|
logger,
|
|
411
437
|
options.sourcemaps?.rewriteSources ?? defaultRewriteSourcesHook,
|
|
412
438
|
options.sourcemaps?.resolveSourceMap
|
|
@@ -435,7 +461,7 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
|
|
|
435
461
|
setMeasurement("upload_size", uploadSize, "byte", prepBundlesSpan);
|
|
436
462
|
if (files.length === 0) {
|
|
437
463
|
logger.warn(
|
|
438
|
-
`No source maps found for any of the ${debugIdChunkFilePaths.length} matched build artifacts, so no source maps were uploaded to Sentry. This usually means source map generation is not enabled in your bundler. Enable it so Sentry can un-minify your stack traces.`
|
|
464
|
+
`No source maps found for any of the ${debugIdChunkFilePaths.length + stagedCount} matched build artifacts, so no source maps were uploaded to Sentry. This usually means source map generation is not enabled in your bundler. Enable it so Sentry can un-minify your stack traces.`
|
|
439
465
|
);
|
|
440
466
|
return;
|
|
441
467
|
}
|
|
@@ -448,11 +474,16 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
|
|
|
448
474
|
}
|
|
449
475
|
]);
|
|
450
476
|
});
|
|
477
|
+
uploaded = true;
|
|
451
478
|
logger.info("Successfully uploaded source maps to Sentry");
|
|
452
479
|
});
|
|
453
480
|
}
|
|
454
481
|
}
|
|
455
482
|
} catch (e) {
|
|
483
|
+
if (staging && folderToCleanUp) {
|
|
484
|
+
await staging.keep("Source map upload failed.");
|
|
485
|
+
folderToCleanUp = void 0;
|
|
486
|
+
}
|
|
456
487
|
sentryScope.captureException('Error in "debugIdUploadPlugin" writeBundle hook');
|
|
457
488
|
handleRecoverableError(e, false);
|
|
458
489
|
} finally {
|
|
@@ -477,6 +508,82 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
|
|
|
477
508
|
}
|
|
478
509
|
}
|
|
479
510
|
);
|
|
511
|
+
return { uploaded };
|
|
512
|
+
},
|
|
513
|
+
async createUploadStaging() {
|
|
514
|
+
const dir = await createTempUploadFolder();
|
|
515
|
+
const rewriteSourcesHook = options.sourcemaps?.rewriteSources ?? defaultRewriteSourcesHook;
|
|
516
|
+
let count = 0;
|
|
517
|
+
let discarded = false;
|
|
518
|
+
const stagedChunkPaths = /* @__PURE__ */ new Set();
|
|
519
|
+
const discard = async () => {
|
|
520
|
+
if (discarded) {
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
discarded = true;
|
|
524
|
+
if (process.env["SENTRY_TEST_OVERRIDE_TEMP_DIR"]) {
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
try {
|
|
528
|
+
await fs.promises.rm(dir, { recursive: true, force: true });
|
|
529
|
+
} catch (e) {
|
|
530
|
+
logger.debug(`Failed to remove staging folder ${dir}:`, e);
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
return {
|
|
534
|
+
dir,
|
|
535
|
+
get count() {
|
|
536
|
+
return count;
|
|
537
|
+
},
|
|
538
|
+
stagedChunkPaths,
|
|
539
|
+
async stage(input) {
|
|
540
|
+
const result = prepareArtifactForUpload({
|
|
541
|
+
code: input.code,
|
|
542
|
+
mapSource: input.mapSource,
|
|
543
|
+
mapDir: input.mapDir,
|
|
544
|
+
rewriteSourcesHook
|
|
545
|
+
});
|
|
546
|
+
if (!result.ok) {
|
|
547
|
+
logger.debug(`Not staging ${input.fileName} for upload: ${result.reason}`);
|
|
548
|
+
return "skipped";
|
|
549
|
+
}
|
|
550
|
+
const index = count++;
|
|
551
|
+
try {
|
|
552
|
+
await writePreparedArtifact(dir, `${result.artifact.debugId}-${index}`, result.artifact);
|
|
553
|
+
stagedChunkPaths.add(path.resolve(input.mapDir, path.basename(input.fileName)));
|
|
554
|
+
return "staged";
|
|
555
|
+
} catch (e) {
|
|
556
|
+
sentryScope.captureException("Error staging build artifact for upload");
|
|
557
|
+
handleRecoverableError(e, true);
|
|
558
|
+
return "failed";
|
|
559
|
+
}
|
|
560
|
+
},
|
|
561
|
+
discard,
|
|
562
|
+
async keep(reason) {
|
|
563
|
+
if (count === 0) {
|
|
564
|
+
await discard();
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
567
|
+
if (discarded) {
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
discarded = true;
|
|
571
|
+
logger.error(
|
|
572
|
+
`${reason} The source maps were kept in ${dir}. Upload them with \`sentry sourcemap upload ${dir}\`.`
|
|
573
|
+
);
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
},
|
|
577
|
+
sourceMaps: {
|
|
578
|
+
uploadPossible: sourceMapUploadPossible,
|
|
579
|
+
decide(kind) {
|
|
580
|
+
const decision = decideSourceMapHandling(kind, options, sourceMapUploadPossible);
|
|
581
|
+
if (decision.log && !loggedSourceMapMessages.has(decision.log.message)) {
|
|
582
|
+
loggedSourceMapMessages.add(decision.log.message);
|
|
583
|
+
logger[decision.log.level](decision.log.message);
|
|
584
|
+
}
|
|
585
|
+
return decision;
|
|
586
|
+
}
|
|
480
587
|
},
|
|
481
588
|
/**
|
|
482
589
|
* Will delete artifacts based on the passed `sourcemaps.filesToDeleteAfterUpload` option.
|
|
@@ -508,34 +615,59 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
|
|
|
508
615
|
createDependencyOnBuildArtifacts
|
|
509
616
|
};
|
|
510
617
|
}
|
|
511
|
-
function
|
|
618
|
+
async function createTempUploadFolder() {
|
|
619
|
+
return process.env["SENTRY_TEST_OVERRIDE_TEMP_DIR"] || await fs.promises.mkdtemp(path.join(os.tmpdir(), "sentry-bundler-plugin-upload-"));
|
|
620
|
+
}
|
|
621
|
+
function getSourceMapUploadBlocker(options, isDevMode) {
|
|
512
622
|
if (options.sourcemaps?.disable) {
|
|
513
|
-
|
|
514
|
-
|
|
623
|
+
return "disabled";
|
|
624
|
+
}
|
|
625
|
+
if (Array.isArray(options.sourcemaps?.assets) && options.sourcemaps.assets.length === 0) {
|
|
626
|
+
return "no-assets";
|
|
515
627
|
}
|
|
516
628
|
if (isDevMode) {
|
|
517
|
-
|
|
518
|
-
return false;
|
|
629
|
+
return "dev-mode";
|
|
519
630
|
}
|
|
520
631
|
if (!options.authToken) {
|
|
521
|
-
|
|
522
|
-
`No auth token provided. Will not upload source maps. Please set the \`authToken\` option. You can find information on how to generate a Sentry auth token here: https://docs.sentry.io/api/auth/${getTurborepoEnvPassthroughWarning("SENTRY_AUTH_TOKEN")}`
|
|
523
|
-
);
|
|
524
|
-
return false;
|
|
632
|
+
return "no-auth-token";
|
|
525
633
|
}
|
|
526
634
|
if (!options.org && !options.authToken.startsWith("sntrys_")) {
|
|
527
|
-
|
|
528
|
-
`No org provided. Will not upload source maps. Please set the \`org\` option to your Sentry organization slug.${getTurborepoEnvPassthroughWarning("SENTRY_ORG")}`
|
|
529
|
-
);
|
|
530
|
-
return false;
|
|
635
|
+
return "no-org";
|
|
531
636
|
}
|
|
532
637
|
if (!getProjects(options.project)?.[0]) {
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
638
|
+
return "no-project";
|
|
639
|
+
}
|
|
640
|
+
return void 0;
|
|
641
|
+
}
|
|
642
|
+
function canUploadSourceMaps(options, logger, isDevMode) {
|
|
643
|
+
switch (getSourceMapUploadBlocker(options, isDevMode)) {
|
|
644
|
+
case "disabled":
|
|
645
|
+
logger.debug("Source map upload was disabled. Will not upload sourcemaps using debug ID process.");
|
|
646
|
+
return false;
|
|
647
|
+
case "no-assets":
|
|
648
|
+
logger.debug("Empty `sourcemaps.assets` option provided. Will not upload sourcemaps with debug ID.");
|
|
649
|
+
return false;
|
|
650
|
+
case "dev-mode":
|
|
651
|
+
logger.debug("Running in development mode. Will not upload sourcemaps.");
|
|
652
|
+
return false;
|
|
653
|
+
case "no-auth-token":
|
|
654
|
+
logger.warn(
|
|
655
|
+
`No auth token provided. Will not upload source maps. Please set the \`authToken\` option. You can find information on how to generate a Sentry auth token here: https://docs.sentry.io/api/auth/${getTurborepoEnvPassthroughWarning("SENTRY_AUTH_TOKEN")}`
|
|
656
|
+
);
|
|
657
|
+
return false;
|
|
658
|
+
case "no-org":
|
|
659
|
+
logger.warn(
|
|
660
|
+
`No org provided. Will not upload source maps. Please set the \`org\` option to your Sentry organization slug.${getTurborepoEnvPassthroughWarning("SENTRY_ORG")}`
|
|
661
|
+
);
|
|
662
|
+
return false;
|
|
663
|
+
case "no-project":
|
|
664
|
+
logger.warn(
|
|
665
|
+
`No project provided. Will not upload source maps. Please set the \`project\` option to your Sentry project slug.${getTurborepoEnvPassthroughWarning("SENTRY_PROJECT")}`
|
|
666
|
+
);
|
|
667
|
+
return false;
|
|
668
|
+
default:
|
|
669
|
+
return true;
|
|
537
670
|
}
|
|
538
|
-
return true;
|
|
539
671
|
}
|
|
540
672
|
|
|
541
673
|
export { createSentryBuildPluginManager };
|