@sentry/bundler-plugins 11.18.0 → 11.20.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/index.js +1 -2
- package/build/cjs/core/index.js.map +1 -1
- package/build/cjs/core/options-mapping.js.map +1 -1
- package/build/cjs/core/sentry/telemetry.js +1 -1
- package/build/cjs/core/sentry/telemetry.js.map +1 -1
- package/build/cjs/core/sourcemap-settings.js +26 -22
- package/build/cjs/core/sourcemap-settings.js.map +1 -1
- package/build/cjs/core/version.js +1 -1
- package/build/cjs/core/version.js.map +1 -1
- package/build/cjs/rewriter/arrays.js +25 -0
- package/build/cjs/rewriter/arrays.js.map +1 -0
- package/build/cjs/rewriter/ast.js +102 -0
- package/build/cjs/rewriter/ast.js.map +1 -0
- package/build/cjs/rewriter/class-extends.js +67 -0
- package/build/cjs/rewriter/class-extends.js.map +1 -0
- package/build/cjs/rewriter/exports.js +241 -0
- package/build/cjs/rewriter/exports.js.map +1 -0
- package/build/cjs/rewriter/imports.js +22 -0
- package/build/cjs/rewriter/imports.js.map +1 -0
- package/build/cjs/rewriter/index.js +45 -0
- package/build/cjs/rewriter/module-shape.js +120 -0
- package/build/cjs/rewriter/module-shape.js.map +1 -0
- package/build/cjs/rewriter/parse.js +64 -0
- package/build/cjs/rewriter/parse.js.map +1 -0
- package/build/cjs/rewriter/report.js +17 -0
- package/build/cjs/rewriter/report.js.map +1 -0
- package/build/cjs/rewriter/rewriter.js +68 -0
- package/build/cjs/rewriter/rewriter.js.map +1 -0
- package/build/cjs/vite/source-map-hooks.js +1 -1
- package/build/cjs/vite/source-map-hooks.js.map +1 -1
- package/build/esm/core/index.js +2 -2
- package/build/esm/core/index.js.map +1 -1
- package/build/esm/core/options-mapping.js.map +1 -1
- package/build/esm/core/sentry/telemetry.js +1 -1
- package/build/esm/core/sentry/telemetry.js.map +1 -1
- package/build/esm/core/sourcemap-settings.js +26 -21
- package/build/esm/core/sourcemap-settings.js.map +1 -1
- package/build/esm/core/version.js +1 -1
- package/build/esm/core/version.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/rewriter/arrays.js +25 -0
- package/build/esm/rewriter/arrays.js.map +1 -0
- package/build/esm/rewriter/ast.js +95 -0
- package/build/esm/rewriter/ast.js.map +1 -0
- package/build/esm/rewriter/class-extends.js +67 -0
- package/build/esm/rewriter/class-extends.js.map +1 -0
- package/build/esm/rewriter/exports.js +231 -0
- package/build/esm/rewriter/exports.js.map +1 -0
- package/build/esm/rewriter/imports.js +21 -0
- package/build/esm/rewriter/imports.js.map +1 -0
- package/build/esm/rewriter/index.js +11 -0
- package/build/esm/rewriter/module-shape.js +118 -0
- package/build/esm/rewriter/module-shape.js.map +1 -0
- package/build/esm/rewriter/parse.js +60 -0
- package/build/esm/rewriter/parse.js.map +1 -0
- package/build/esm/rewriter/report.js +16 -0
- package/build/esm/rewriter/report.js.map +1 -0
- package/build/esm/rewriter/rewriter.js +65 -0
- package/build/esm/rewriter/rewriter.js.map +1 -0
- package/build/esm/vite/source-map-hooks.js +2 -2
- package/build/esm/vite/source-map-hooks.js.map +1 -1
- package/build/types/core/index.d.ts +1 -1
- package/build/types/core/index.d.ts.map +1 -1
- package/build/types/core/options-mapping.d.ts +2 -2
- 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 +8 -6
- package/build/types/core/sourcemap-settings.d.ts.map +1 -1
- package/build/types/core/types.d.ts +14 -11
- package/build/types/core/types.d.ts.map +1 -1
- package/build/types/core/version.d.ts +1 -1
- package/build/types/rewriter/arrays.d.ts +12 -0
- package/build/types/rewriter/arrays.d.ts.map +1 -0
- package/build/types/rewriter/ast.d.ts +120 -0
- package/build/types/rewriter/ast.d.ts.map +1 -0
- package/build/types/rewriter/class-extends.d.ts +16 -0
- package/build/types/rewriter/class-extends.d.ts.map +1 -0
- package/build/types/rewriter/exports.d.ts +88 -0
- package/build/types/rewriter/exports.d.ts.map +1 -0
- package/build/types/rewriter/imports.d.ts +7 -0
- package/build/types/rewriter/imports.d.ts.map +1 -0
- package/build/types/rewriter/index.d.ts +10 -0
- package/build/types/rewriter/index.d.ts.map +1 -0
- package/build/types/rewriter/module-shape.d.ts +47 -0
- package/build/types/rewriter/module-shape.d.ts.map +1 -0
- package/build/types/rewriter/parse.d.ts +27 -0
- package/build/types/rewriter/parse.d.ts.map +1 -0
- package/build/types/rewriter/report.d.ts +12 -0
- package/build/types/rewriter/report.d.ts.map +1 -0
- package/build/types/rewriter/rewriter.d.ts +64 -0
- package/build/types/rewriter/rewriter.d.ts.map +1 -0
- package/build/types/vite/source-map-hooks.d.ts.map +1 -1
- package/package.json +9 -4
package/build/cjs/core/index.js
CHANGED
|
@@ -81,8 +81,7 @@ exports.generateReleaseInjectorCode = require_utils.generateReleaseInjectorCode;
|
|
|
81
81
|
exports.getCodeInjectionPosition = require_get_code_injection_position.getCodeInjectionPosition;
|
|
82
82
|
exports.getDebugIdSnippet = getDebugIdSnippet;
|
|
83
83
|
exports.getDeleteOption = require_sourcemap_settings.getDeleteOption;
|
|
84
|
-
exports.
|
|
85
|
-
exports.getSdkEnabledSourceMaps = require_sourcemap_settings.getSdkEnabledSourceMaps;
|
|
84
|
+
exports.getSdkDeleteSourceMaps = require_sourcemap_settings.getSdkDeleteSourceMaps;
|
|
86
85
|
exports.getSourceMapFeatures = require_sourcemap_settings.getSourceMapFeatures;
|
|
87
86
|
exports.globFiles = require_glob.globFiles;
|
|
88
87
|
exports.hasSourceMapUploadCredentials = require_upload_credentials.hasSourceMapUploadCredentials;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["stripQueryAndHashFromPath","containsOnlyImports","CodeInjection"],"sources":["../../../src/core/index.ts"],"sourcesContent":["import { CodeInjection, containsOnlyImports, stripQueryAndHashFromPath } from './utils';\n\n/**\n * Checks if a file is a JavaScript file based on its extension.\n * Handles query strings and hashes in the filename.\n */\nexport function isJsFile(fileName: string): boolean {\n const cleanFileName = stripQueryAndHashFromPath(fileName);\n return ['.js', '.mjs', '.cjs'].some(ext => cleanFileName.endsWith(ext));\n}\n\n/**\n * Checks if a chunk should be skipped for code injection\n *\n * This is necessary to handle Vite's MPA (multi-page application) mode where\n * HTML entry points create \"facade\" chunks that should not contain injected code.\n * See: https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/829\n *\n * However, in SPA mode, the main bundle also has an HTML facade but contains\n * substantial application code. We should NOT skip injection for these bundles.\n *\n * @param code - The chunk's code content\n * @param facadeModuleId - The facade module ID (if any) - HTML files create facade chunks\n * @returns true if the chunk should be skipped\n */\nexport function shouldSkipCodeInjection(code: string, facadeModuleId: string | null | undefined): boolean {\n // Skip empty chunks - these are placeholder chunks that should be optimized away\n if (code.trim().length === 0) {\n return true;\n }\n\n // For HTML facade chunks, only skip if they contain only import statements\n if (facadeModuleId && stripQueryAndHashFromPath(facadeModuleId).endsWith('.html')) {\n return containsOnlyImports(code);\n }\n\n return false;\n}\n\nexport interface ChunkGraphNode {\n fileName: string;\n isEntry?: boolean;\n imports?: string[];\n}\n\nconst initialChunksCache = new WeakMap<Record<string, ChunkGraphNode>, Set<string>>();\n\nfunction getInitialChunks(chunks: Record<string, ChunkGraphNode>): Set<string> {\n const cached = initialChunksCache.get(chunks);\n if (cached) {\n return cached;\n }\n\n const initial = new Set<string>();\n const queue = Object.values(chunks).filter(chunk => chunk.isEntry);\n\n for (let chunk = queue.shift(); chunk; chunk = queue.shift()) {\n if (initial.has(chunk.fileName)) {\n continue;\n }\n initial.add(chunk.fileName);\n for (const imported of chunk.imports ?? []) {\n const importedChunk = chunks[imported];\n if (importedChunk) {\n queue.push(importedChunk);\n }\n }\n }\n\n initialChunksCache.set(chunks, initial);\n return initial;\n}\n\n/**\n * Whether a chunk loads at startup: it is an entry chunk, or an entry chunk\n * reaches it through static imports. Chunks that only dynamic imports reach\n * load later, after startup code already ran.\n *\n * Without the chunk graph every chunk counts as initial.\n */\nexport function isInitialChunk(\n chunk: Pick<ChunkGraphNode, 'fileName' | 'isEntry'>,\n chunks: Record<string, ChunkGraphNode> | undefined,\n): boolean {\n if (chunk.isEntry || !chunks) {\n return true;\n }\n\n return getInitialChunks(chunks).has(chunk.fileName);\n}\n\nexport { globFiles } from './glob';\nexport { getCodeInjectionPosition } from './get-code-injection-position';\n\nexport { createComponentNameAnnotateHooks } from './component-annotate-hooks';\n\nexport function getDebugIdSnippet(debugId: string): CodeInjection {\n return new CodeInjection(\n `var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]=\"${debugId}\",e._sentryDebugIdIdentifier=\"sentry-dbid-${debugId}\");`,\n );\n}\n\nexport type { Logger } from './logger';\nexport type { InternalOptions, Options, SentrySDKBuildFlags } from './types';\nexport {\n CodeInjection,\n replaceBooleanFlagsInCode,\n stringToUUID,\n generateReleaseInjectorCode,\n generateModuleMetadataInjectorCode,\n resolveReleaseName,\n} from './utils';\nexport { createSentryBuildPluginManager } from './build-plugin-manager';\nexport type { SentryBuildPluginManager, UploadResult, UploadStaging } from './build-plugin-manager';\nexport { createDebugIdUploadFunction, addDebugIdToEmittedArtifacts, stampDebugId } from './debug-id-upload';\nexport {\n decideSourceMapHandling,\n getDeleteOption,\n
|
|
1
|
+
{"version":3,"file":"index.js","names":["stripQueryAndHashFromPath","containsOnlyImports","CodeInjection"],"sources":["../../../src/core/index.ts"],"sourcesContent":["import { CodeInjection, containsOnlyImports, stripQueryAndHashFromPath } from './utils';\n\n/**\n * Checks if a file is a JavaScript file based on its extension.\n * Handles query strings and hashes in the filename.\n */\nexport function isJsFile(fileName: string): boolean {\n const cleanFileName = stripQueryAndHashFromPath(fileName);\n return ['.js', '.mjs', '.cjs'].some(ext => cleanFileName.endsWith(ext));\n}\n\n/**\n * Checks if a chunk should be skipped for code injection\n *\n * This is necessary to handle Vite's MPA (multi-page application) mode where\n * HTML entry points create \"facade\" chunks that should not contain injected code.\n * See: https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/829\n *\n * However, in SPA mode, the main bundle also has an HTML facade but contains\n * substantial application code. We should NOT skip injection for these bundles.\n *\n * @param code - The chunk's code content\n * @param facadeModuleId - The facade module ID (if any) - HTML files create facade chunks\n * @returns true if the chunk should be skipped\n */\nexport function shouldSkipCodeInjection(code: string, facadeModuleId: string | null | undefined): boolean {\n // Skip empty chunks - these are placeholder chunks that should be optimized away\n if (code.trim().length === 0) {\n return true;\n }\n\n // For HTML facade chunks, only skip if they contain only import statements\n if (facadeModuleId && stripQueryAndHashFromPath(facadeModuleId).endsWith('.html')) {\n return containsOnlyImports(code);\n }\n\n return false;\n}\n\nexport interface ChunkGraphNode {\n fileName: string;\n isEntry?: boolean;\n imports?: string[];\n}\n\nconst initialChunksCache = new WeakMap<Record<string, ChunkGraphNode>, Set<string>>();\n\nfunction getInitialChunks(chunks: Record<string, ChunkGraphNode>): Set<string> {\n const cached = initialChunksCache.get(chunks);\n if (cached) {\n return cached;\n }\n\n const initial = new Set<string>();\n const queue = Object.values(chunks).filter(chunk => chunk.isEntry);\n\n for (let chunk = queue.shift(); chunk; chunk = queue.shift()) {\n if (initial.has(chunk.fileName)) {\n continue;\n }\n initial.add(chunk.fileName);\n for (const imported of chunk.imports ?? []) {\n const importedChunk = chunks[imported];\n if (importedChunk) {\n queue.push(importedChunk);\n }\n }\n }\n\n initialChunksCache.set(chunks, initial);\n return initial;\n}\n\n/**\n * Whether a chunk loads at startup: it is an entry chunk, or an entry chunk\n * reaches it through static imports. Chunks that only dynamic imports reach\n * load later, after startup code already ran.\n *\n * Without the chunk graph every chunk counts as initial.\n */\nexport function isInitialChunk(\n chunk: Pick<ChunkGraphNode, 'fileName' | 'isEntry'>,\n chunks: Record<string, ChunkGraphNode> | undefined,\n): boolean {\n if (chunk.isEntry || !chunks) {\n return true;\n }\n\n return getInitialChunks(chunks).has(chunk.fileName);\n}\n\nexport { globFiles } from './glob';\nexport { getCodeInjectionPosition } from './get-code-injection-position';\n\nexport { createComponentNameAnnotateHooks } from './component-annotate-hooks';\n\nexport function getDebugIdSnippet(debugId: string): CodeInjection {\n return new CodeInjection(\n `var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]=\"${debugId}\",e._sentryDebugIdIdentifier=\"sentry-dbid-${debugId}\");`,\n );\n}\n\nexport type { Logger } from './logger';\nexport type { InternalOptions, Options, SentrySDKBuildFlags } from './types';\nexport {\n CodeInjection,\n replaceBooleanFlagsInCode,\n stringToUUID,\n generateReleaseInjectorCode,\n generateModuleMetadataInjectorCode,\n resolveReleaseName,\n} from './utils';\nexport { createSentryBuildPluginManager } from './build-plugin-manager';\nexport type { SentryBuildPluginManager, UploadResult, UploadStaging } from './build-plugin-manager';\nexport { createDebugIdUploadFunction, addDebugIdToEmittedArtifacts, stampDebugId } from './debug-id-upload';\nexport {\n decideSourceMapHandling,\n getDeleteOption,\n getSdkDeleteSourceMaps,\n getSourceMapFeatures,\n} from './sourcemap-settings';\nexport type { SourceMapDecision, SourceMapKind } from './sourcemap-settings';\nexport { hasSourceMapUploadCredentials } from './upload-credentials';\nexport type { UploadFilter } from './upload-filter';\n"],"mappings":";;;;;;;;;;;;;;AAMA,SAAgB,SAAS,UAA2B;CAClD,MAAM,gBAAgBA,cAAAA,0BAA0B,QAAQ;CACxD,OAAO;EAAC;EAAO;EAAQ;CAAM,CAAC,CAAC,MAAK,QAAO,cAAc,SAAS,GAAG,CAAC;AACxE;;;;;;;;;;;;;;;AAgBA,SAAgB,wBAAwB,MAAc,gBAAoD;CAExG,IAAI,KAAK,KAAK,CAAC,CAAC,WAAW,GACzB,OAAO;CAIT,IAAI,kBAAkBA,cAAAA,0BAA0B,cAAc,CAAC,CAAC,SAAS,OAAO,GAC9E,OAAOC,cAAAA,oBAAoB,IAAI;CAGjC,OAAO;AACT;AAQA,MAAM,qCAAqB,IAAI,QAAqD;AAEpF,SAAS,iBAAiB,QAAqD;CAC7E,MAAM,SAAS,mBAAmB,IAAI,MAAM;CAC5C,IAAI,QACF,OAAO;CAGT,MAAM,0BAAU,IAAI,IAAY;CAChC,MAAM,QAAQ,OAAO,OAAO,MAAM,CAAC,CAAC,QAAO,UAAS,MAAM,OAAO;CAEjE,KAAK,IAAI,QAAQ,MAAM,MAAM,GAAG,OAAO,QAAQ,MAAM,MAAM,GAAG;EAC5D,IAAI,QAAQ,IAAI,MAAM,QAAQ,GAC5B;EAEF,QAAQ,IAAI,MAAM,QAAQ;EAC1B,KAAK,MAAM,YAAY,MAAM,WAAW,CAAC,GAAG;GAC1C,MAAM,gBAAgB,OAAO;GAC7B,IAAI,eACF,MAAM,KAAK,aAAa;EAE5B;CACF;CAEA,mBAAmB,IAAI,QAAQ,OAAO;CACtC,OAAO;AACT;;;;;;;;AASA,SAAgB,eACd,OACA,QACS;CACT,IAAI,MAAM,WAAW,CAAC,QACpB,OAAO;CAGT,OAAO,iBAAiB,MAAM,CAAC,CAAC,IAAI,MAAM,QAAQ;AACpD;AAOA,SAAgB,kBAAkB,SAAgC;CAChE,OAAO,IAAIC,cAAAA,cACT,+FAA+F,QAAQ,4CAA4C,QAAQ,IAC7J;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options-mapping.js","names":["parseProjectEnvVar","resolveReleaseName","getVercelEnv","readCommitEnvVar","canAutoDetectRepository","warnOnConflictingSourceMapOptions"],"sources":["../../../src/core/options-mapping.ts"],"sourcesContent":["import { getVercelEnv, warnOnConflictingSourceMapOptions } from '@sentry/core';\nimport type { Logger } from './logger';\nimport type {\n InternalOptions as UserOptions,\n SetCommitsOptions,\n RewriteSourcesHook,\n ResolveSourceMapHook,\n IncludeEntry,\n ModuleMetadata,\n ModuleMetadataCallback,\n} from './types';\nimport { parseProjectEnvVar } from './upload-credentials';\nimport { canAutoDetectRepository, readCommitEnvVar, resolveReleaseName } from './utils';\n\nexport type NormalizedOptions = {\n org: string | undefined;\n project: string | string[] | undefined;\n authToken: string | undefined;\n url: string | undefined;\n headers: Record<string, string> | undefined;\n debug: boolean;\n silent: boolean;\n errorHandler: ((err: Error) => void) | undefined;\n telemetry: boolean;\n disable: boolean;\n sourcemaps:\n | {\n disable?: boolean | 'disable-upload';\n upload?: boolean;\n injectDebugIds?: boolean;\n delete?: boolean;\n assets?: string | string[];\n ignore?: string | string[];\n rewriteSources?: RewriteSourcesHook;\n resolveSourceMap?: ResolveSourceMapHook;\n filesToDeleteAfterUpload?: string | string[] | Promise<string | string[] | undefined>;\n deleteSourcemapsAfterUpload?: boolean | ((environment?: string) => boolean | undefined);\n sdkEnabledSourceMaps?: boolean | ((environment?: string) => boolean | undefined);\n }\n | undefined;\n release: {\n name: string | undefined;\n inject: boolean | 'html';\n create: boolean;\n finalize: boolean;\n vcsRemote: string;\n setCommits:\n | (SetCommitsOptions & {\n shouldNotThrowOnFailure?: boolean;\n })\n | false\n | undefined;\n dist?: string;\n deploy?:\n | {\n env: string;\n started?: number | string;\n finished?: number | string;\n time?: number;\n name?: string;\n url?: string;\n }\n | false;\n uploadLegacySourcemaps?: string | IncludeEntry | Array<string | IncludeEntry>;\n };\n bundleSizeOptimizations:\n | {\n excludeDebugStatements?: boolean;\n excludeTracing?: boolean;\n excludeChannelInjection?: boolean;\n excludeReplayCanvas?: boolean;\n excludeReplayShadowDom?: boolean;\n excludeReplayIframe?: boolean;\n excludeReplayWorker?: boolean;\n }\n | undefined;\n reactComponentAnnotation:\n | {\n enabled?: boolean;\n ignoredComponents?: string[];\n _experimentalInjectIntoHtml?: boolean;\n }\n | undefined;\n _metaOptions: {\n telemetry: {\n metaFramework: string | undefined;\n bundlerMajorVersion: string | undefined;\n };\n };\n applicationKey: string | undefined;\n moduleMetadata: ModuleMetadata | ModuleMetadataCallback | undefined;\n _experiments: {\n injectBuildInformation?: boolean;\n } & Record<string, unknown>;\n};\n\nexport const SENTRY_SAAS_URL = 'https://sentry.io';\n\n// oxlint-disable-next-line complexity\nexport function normalizeUserOptions(userOptions: UserOptions): NormalizedOptions {\n const options = {\n org: userOptions.org ?? process.env['SENTRY_ORG'],\n project: userOptions.project ?? parseProjectEnvVar(process.env['SENTRY_PROJECT']),\n authToken: userOptions.authToken ?? process.env['SENTRY_AUTH_TOKEN'],\n // No sentry.io default: the CLI then uses the server an `sntrys_` org token was issued for, and\n // sentry.io otherwise. A default here would send self-hosted tokens to sentry.io.\n url: userOptions.url ?? process.env['SENTRY_URL'],\n headers: userOptions.headers,\n debug: userOptions.debug ?? false,\n silent: userOptions.silent ?? false,\n errorHandler: userOptions.errorHandler,\n telemetry: userOptions.telemetry ?? true,\n disable: userOptions.disable ?? false,\n sourcemaps: userOptions.sourcemaps,\n release: {\n ...userOptions.release,\n name: resolveReleaseName(userOptions.release?.name),\n inject: userOptions.release?.inject ?? true,\n create: userOptions.release?.create ?? true,\n finalize: userOptions.release?.finalize ?? true,\n vcsRemote: userOptions.release?.vcsRemote ?? process.env['SENTRY_VSC_REMOTE'] ?? 'origin',\n // oxlint-disable-next-line typescript/no-unnecessary-type-assertion -- rule false positive: the cast carries the internal `shouldNotThrowOnFailure` field; tsc errors without it\n setCommits: userOptions.release?.setCommits as\n | (SetCommitsOptions & { shouldNotThrowOnFailure?: boolean })\n | false\n | undefined,\n },\n bundleSizeOptimizations: userOptions.bundleSizeOptimizations,\n reactComponentAnnotation: userOptions.reactComponentAnnotation,\n _metaOptions: {\n telemetry: {\n metaFramework: userOptions._metaOptions?.telemetry?.metaFramework,\n bundlerMajorVersion: userOptions._metaOptions?.telemetry?.bundlerMajorVersion,\n },\n },\n applicationKey: userOptions.applicationKey,\n moduleMetadata: userOptions.moduleMetadata,\n _experiments: userOptions._experiments ?? {},\n };\n\n const vercelEnv = getVercelEnv();\n\n if (options.release.setCommits === undefined) {\n const vercelCommitSha = readCommitEnvVar('VERCEL_GIT_COMMIT_SHA');\n if (\n process.env['VERCEL'] &&\n vercelCommitSha &&\n process.env['VERCEL_GIT_REPO_SLUG'] &&\n process.env['VERCEL_GIT_REPO_OWNER'] &&\n // We only want to set commits for the production env because Sentry becomes extremely noisy (eg on slack) for\n // preview environments because the previous commit is always the \"stem\" commit of the preview/PR causing Sentry\n // to notify you for other people creating PRs.\n vercelEnv === 'production'\n ) {\n options.release.setCommits = {\n shouldNotThrowOnFailure: true,\n commit: vercelCommitSha,\n previousCommit: readCommitEnvVar('VERCEL_GIT_PREVIOUS_SHA'),\n repo: `${process.env['VERCEL_GIT_REPO_OWNER']}/${process.env['VERCEL_GIT_REPO_SLUG']}`,\n ignoreEmpty: true,\n ignoreMissing: true,\n };\n } else if (\n process.env['VERCEL'] &&\n vercelEnv !== 'production' &&\n !canAutoDetectRepository(options.release.vcsRemote)\n ) {\n // Vercel's own builders have no git remote and no other CI variables, so commit association can only fail there.\n // Builds that have either, such as `vercel build` in GitHub Actions, keep `auto: true` below.\n options.release.setCommits = false;\n } else {\n options.release.setCommits = {\n shouldNotThrowOnFailure: true,\n auto: true,\n ignoreEmpty: true,\n ignoreMissing: true,\n };\n }\n }\n\n if (options.release.deploy === undefined && process.env['VERCEL'] && vercelEnv) {\n options.release.deploy = {\n env: vercelEnv,\n url: process.env['VERCEL_URL'] ? `https://${process.env['VERCEL_URL']}` : undefined,\n };\n }\n\n return options;\n}\n\n/**\n * Validates a few combinations of options that are not checked by Sentry CLI.\n *\n * For all other options, we can rely on Sentry CLI to validate them. In fact,\n * we can't validate them in the plugin because Sentry CLI might pick up options from\n * its config file.\n *\n * @param options the internal options\n * @param logger the logger\n *\n * @returns `true` if the options are valid, `false` otherwise\n */\nexport function validateOptions(options: NormalizedOptions, logger: Logger): boolean {\n const setCommits = options.release?.setCommits;\n if (setCommits) {\n if (!setCommits.auto && !(setCommits.repo && setCommits.commit)) {\n logger.error(\n 'The `setCommits` option was specified but is missing required properties.',\n 'Please set either `auto` or both, `repo` and `commit`.',\n );\n return false;\n }\n if (setCommits.auto && setCommits.repo && setCommits) {\n logger.warn(\n 'The `setCommits` options includes `auto` but also `repo` and `commit`.',\n 'Ignoring `repo` and `commit`.',\n 'Please only set either `auto` or both, `repo` and `commit`.',\n );\n }\n }\n\n warnOnConflictingSourceMapOptions(options.sourcemaps, message => logger.warn(message));\n\n if (options.release?.deploy && typeof options.release.deploy === 'object' && !options.release.deploy.env) {\n logger.error(\n 'The `deploy` option was specified but is missing the required `env` property.',\n 'Please set the `env` property.',\n );\n return false;\n }\n\n if (options.project && Array.isArray(options.project)) {\n if (options.project.length === 0) {\n logger.error(\n 'The `project` option was specified as an array but is empty.',\n 'Please provide at least one project slug.',\n );\n return false;\n }\n // Check each project is a non-empty string\n const invalidProjects = options.project.filter(p => typeof p !== 'string' || p.trim() === '');\n if (invalidProjects.length > 0) {\n logger.error('The `project` option contains invalid project slugs.', 'All projects must be non-empty strings.');\n return false;\n }\n }\n\n return true;\n}\n"],"mappings":";;;;AAgGA,MAAa,kBAAkB;AAG/B,SAAgB,qBAAqB,aAA6C;CAChF,MAAM,UAAU;EACd,KAAK,YAAY,OAAO,QAAQ,IAAI;EACpC,SAAS,YAAY,WAAWA,2BAAAA,mBAAmB,QAAQ,IAAI,iBAAiB;EAChF,WAAW,YAAY,aAAa,QAAQ,IAAI;EAGhD,KAAK,YAAY,OAAO,QAAQ,IAAI;EACpC,SAAS,YAAY;EACrB,OAAO,YAAY,SAAS;EAC5B,QAAQ,YAAY,UAAU;EAC9B,cAAc,YAAY;EAC1B,WAAW,YAAY,aAAa;EACpC,SAAS,YAAY,WAAW;EAChC,YAAY,YAAY;EACxB,SAAS;GACP,GAAG,YAAY;GACf,MAAMC,cAAAA,mBAAmB,YAAY,SAAS,IAAI;GAClD,QAAQ,YAAY,SAAS,UAAU;GACvC,QAAQ,YAAY,SAAS,UAAU;GACvC,UAAU,YAAY,SAAS,YAAY;GAC3C,WAAW,YAAY,SAAS,aAAa,QAAQ,IAAI,wBAAwB;GAEjF,YAAY,YAAY,SAAS;EAInC;EACA,yBAAyB,YAAY;EACrC,0BAA0B,YAAY;EACtC,cAAc,EACZ,WAAW;GACT,eAAe,YAAY,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CAAAA,GAAAA,aAAAA,kCAAAA,CAAkC,QAAQ,aAAY,YAAW,OAAO,KAAK,OAAO,CAAC;CAErF,IAAI,QAAQ,SAAS,UAAU,OAAO,QAAQ,QAAQ,WAAW,YAAY,CAAC,QAAQ,QAAQ,OAAO,KAAK;EACxG,OAAO,MACL,iFACA,gCACF;EACA,OAAO;CACT;CAEA,IAAI,QAAQ,WAAW,MAAM,QAAQ,QAAQ,OAAO,GAAG;EACrD,IAAI,QAAQ,QAAQ,WAAW,GAAG;GAChC,OAAO,MACL,gEACA,2CACF;GACA,OAAO;EACT;EAGA,IADwB,QAAQ,QAAQ,QAAO,MAAK,OAAO,MAAM,YAAY,EAAE,KAAK,MAAM,EACxE,CAAC,CAAC,SAAS,GAAG;GAC9B,OAAO,MAAM,wDAAwD,yCAAyC;GAC9G,OAAO;EACT;CACF;CAEA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"options-mapping.js","names":["parseProjectEnvVar","resolveReleaseName","getVercelEnv","readCommitEnvVar","canAutoDetectRepository","warnOnConflictingSourceMapOptions"],"sources":["../../../src/core/options-mapping.ts"],"sourcesContent":["import { getVercelEnv, warnOnConflictingSourceMapOptions } from '@sentry/core';\nimport type { Logger } from './logger';\nimport type {\n InternalOptions as UserOptions,\n SetCommitsOptions,\n RewriteSourcesHook,\n ResolveSourceMapHook,\n IncludeEntry,\n ModuleMetadata,\n ModuleMetadataCallback,\n} from './types';\nimport { parseProjectEnvVar } from './upload-credentials';\nimport { canAutoDetectRepository, readCommitEnvVar, resolveReleaseName } from './utils';\n\nexport type NormalizedOptions = {\n org: string | undefined;\n project: string | string[] | undefined;\n authToken: string | undefined;\n url: string | undefined;\n headers: Record<string, string> | undefined;\n debug: boolean;\n silent: boolean;\n errorHandler: ((err: Error) => void) | undefined;\n telemetry: boolean;\n disable: boolean;\n sourcemaps:\n | {\n disable?: boolean | 'disable-upload';\n upload?: boolean;\n injectDebugIds?: boolean;\n delete?: boolean;\n assets?: string | string[];\n ignore?: string | string[];\n rewriteSources?: RewriteSourcesHook;\n resolveSourceMap?: ResolveSourceMapHook;\n filesToDeleteAfterUpload?: string | string[] | Promise<string | string[] | undefined>;\n deleteSourcemapsAfterUpload?: boolean;\n sdkDeleteSourceMaps?: boolean | ((environment?: string) => boolean | undefined);\n }\n | undefined;\n release: {\n name: string | undefined;\n inject: boolean | 'html';\n create: boolean;\n finalize: boolean;\n vcsRemote: string;\n setCommits:\n | (SetCommitsOptions & {\n shouldNotThrowOnFailure?: boolean;\n })\n | false\n | undefined;\n dist?: string;\n deploy?:\n | {\n env: string;\n started?: number | string;\n finished?: number | string;\n time?: number;\n name?: string;\n url?: string;\n }\n | false;\n uploadLegacySourcemaps?: string | IncludeEntry | Array<string | IncludeEntry>;\n };\n bundleSizeOptimizations:\n | {\n excludeDebugStatements?: boolean;\n excludeTracing?: boolean;\n excludeChannelInjection?: boolean;\n excludeReplayCanvas?: boolean;\n excludeReplayShadowDom?: boolean;\n excludeReplayIframe?: boolean;\n excludeReplayWorker?: boolean;\n }\n | undefined;\n reactComponentAnnotation:\n | {\n enabled?: boolean;\n ignoredComponents?: string[];\n _experimentalInjectIntoHtml?: boolean;\n }\n | undefined;\n _metaOptions: {\n telemetry: {\n metaFramework: string | undefined;\n bundlerMajorVersion: string | undefined;\n };\n };\n applicationKey: string | undefined;\n moduleMetadata: ModuleMetadata | ModuleMetadataCallback | undefined;\n _experiments: {\n injectBuildInformation?: boolean;\n } & Record<string, unknown>;\n};\n\nexport const SENTRY_SAAS_URL = 'https://sentry.io';\n\n// oxlint-disable-next-line complexity\nexport function normalizeUserOptions(userOptions: UserOptions): NormalizedOptions {\n const options = {\n org: userOptions.org ?? process.env['SENTRY_ORG'],\n project: userOptions.project ?? parseProjectEnvVar(process.env['SENTRY_PROJECT']),\n authToken: userOptions.authToken ?? process.env['SENTRY_AUTH_TOKEN'],\n // No sentry.io default: the CLI then uses the server an `sntrys_` org token was issued for, and\n // sentry.io otherwise. A default here would send self-hosted tokens to sentry.io.\n url: userOptions.url ?? process.env['SENTRY_URL'],\n headers: userOptions.headers,\n debug: userOptions.debug ?? false,\n silent: userOptions.silent ?? false,\n errorHandler: userOptions.errorHandler,\n telemetry: userOptions.telemetry ?? true,\n disable: userOptions.disable ?? false,\n sourcemaps: userOptions.sourcemaps,\n release: {\n ...userOptions.release,\n name: resolveReleaseName(userOptions.release?.name),\n inject: userOptions.release?.inject ?? true,\n create: userOptions.release?.create ?? true,\n finalize: userOptions.release?.finalize ?? true,\n vcsRemote: userOptions.release?.vcsRemote ?? process.env['SENTRY_VSC_REMOTE'] ?? 'origin',\n // oxlint-disable-next-line typescript/no-unnecessary-type-assertion -- rule false positive: the cast carries the internal `shouldNotThrowOnFailure` field; tsc errors without it\n setCommits: userOptions.release?.setCommits as\n | (SetCommitsOptions & { shouldNotThrowOnFailure?: boolean })\n | false\n | undefined,\n },\n bundleSizeOptimizations: userOptions.bundleSizeOptimizations,\n reactComponentAnnotation: userOptions.reactComponentAnnotation,\n _metaOptions: {\n telemetry: {\n metaFramework: userOptions._metaOptions?.telemetry?.metaFramework,\n bundlerMajorVersion: userOptions._metaOptions?.telemetry?.bundlerMajorVersion,\n },\n },\n applicationKey: userOptions.applicationKey,\n moduleMetadata: userOptions.moduleMetadata,\n _experiments: userOptions._experiments ?? {},\n };\n\n const vercelEnv = getVercelEnv();\n\n if (options.release.setCommits === undefined) {\n const vercelCommitSha = readCommitEnvVar('VERCEL_GIT_COMMIT_SHA');\n if (\n process.env['VERCEL'] &&\n vercelCommitSha &&\n process.env['VERCEL_GIT_REPO_SLUG'] &&\n process.env['VERCEL_GIT_REPO_OWNER'] &&\n // We only want to set commits for the production env because Sentry becomes extremely noisy (eg on slack) for\n // preview environments because the previous commit is always the \"stem\" commit of the preview/PR causing Sentry\n // to notify you for other people creating PRs.\n vercelEnv === 'production'\n ) {\n options.release.setCommits = {\n shouldNotThrowOnFailure: true,\n commit: vercelCommitSha,\n previousCommit: readCommitEnvVar('VERCEL_GIT_PREVIOUS_SHA'),\n repo: `${process.env['VERCEL_GIT_REPO_OWNER']}/${process.env['VERCEL_GIT_REPO_SLUG']}`,\n ignoreEmpty: true,\n ignoreMissing: true,\n };\n } else if (\n process.env['VERCEL'] &&\n vercelEnv !== 'production' &&\n !canAutoDetectRepository(options.release.vcsRemote)\n ) {\n // Vercel's own builders have no git remote and no other CI variables, so commit association can only fail there.\n // Builds that have either, such as `vercel build` in GitHub Actions, keep `auto: true` below.\n options.release.setCommits = false;\n } else {\n options.release.setCommits = {\n shouldNotThrowOnFailure: true,\n auto: true,\n ignoreEmpty: true,\n ignoreMissing: true,\n };\n }\n }\n\n if (options.release.deploy === undefined && process.env['VERCEL'] && vercelEnv) {\n options.release.deploy = {\n env: vercelEnv,\n url: process.env['VERCEL_URL'] ? `https://${process.env['VERCEL_URL']}` : undefined,\n };\n }\n\n return options;\n}\n\n/**\n * Validates a few combinations of options that are not checked by Sentry CLI.\n *\n * For all other options, we can rely on Sentry CLI to validate them. In fact,\n * we can't validate them in the plugin because Sentry CLI might pick up options from\n * its config file.\n *\n * @param options the internal options\n * @param logger the logger\n *\n * @returns `true` if the options are valid, `false` otherwise\n */\nexport function validateOptions(options: NormalizedOptions, logger: Logger): boolean {\n const setCommits = options.release?.setCommits;\n if (setCommits) {\n if (!setCommits.auto && !(setCommits.repo && setCommits.commit)) {\n logger.error(\n 'The `setCommits` option was specified but is missing required properties.',\n 'Please set either `auto` or both, `repo` and `commit`.',\n );\n return false;\n }\n if (setCommits.auto && setCommits.repo && setCommits) {\n logger.warn(\n 'The `setCommits` options includes `auto` but also `repo` and `commit`.',\n 'Ignoring `repo` and `commit`.',\n 'Please only set either `auto` or both, `repo` and `commit`.',\n );\n }\n }\n\n warnOnConflictingSourceMapOptions(options.sourcemaps, message => logger.warn(message));\n\n if (options.release?.deploy && typeof options.release.deploy === 'object' && !options.release.deploy.env) {\n logger.error(\n 'The `deploy` option was specified but is missing the required `env` property.',\n 'Please set the `env` property.',\n );\n return false;\n }\n\n if (options.project && Array.isArray(options.project)) {\n if (options.project.length === 0) {\n logger.error(\n 'The `project` option was specified as an array but is empty.',\n 'Please provide at least one project slug.',\n );\n return false;\n }\n // Check each project is a non-empty string\n const invalidProjects = options.project.filter(p => typeof p !== 'string' || p.trim() === '');\n if (invalidProjects.length > 0) {\n logger.error('The `project` option contains invalid project slugs.', 'All projects must be non-empty strings.');\n return false;\n }\n }\n\n return true;\n}\n"],"mappings":";;;;AAgGA,MAAa,kBAAkB;AAG/B,SAAgB,qBAAqB,aAA6C;CAChF,MAAM,UAAU;EACd,KAAK,YAAY,OAAO,QAAQ,IAAI;EACpC,SAAS,YAAY,WAAWA,2BAAAA,mBAAmB,QAAQ,IAAI,iBAAiB;EAChF,WAAW,YAAY,aAAa,QAAQ,IAAI;EAGhD,KAAK,YAAY,OAAO,QAAQ,IAAI;EACpC,SAAS,YAAY;EACrB,OAAO,YAAY,SAAS;EAC5B,QAAQ,YAAY,UAAU;EAC9B,cAAc,YAAY;EAC1B,WAAW,YAAY,aAAa;EACpC,SAAS,YAAY,WAAW;EAChC,YAAY,YAAY;EACxB,SAAS;GACP,GAAG,YAAY;GACf,MAAMC,cAAAA,mBAAmB,YAAY,SAAS,IAAI;GAClD,QAAQ,YAAY,SAAS,UAAU;GACvC,QAAQ,YAAY,SAAS,UAAU;GACvC,UAAU,YAAY,SAAS,YAAY;GAC3C,WAAW,YAAY,SAAS,aAAa,QAAQ,IAAI,wBAAwB;GAEjF,YAAY,YAAY,SAAS;EAInC;EACA,yBAAyB,YAAY;EACrC,0BAA0B,YAAY;EACtC,cAAc,EACZ,WAAW;GACT,eAAe,YAAY,cAAc,WAAW;GACpD,qBAAqB,YAAY,cAAc,WAAW;EAC5D,EACF;EACA,gBAAgB,YAAY;EAC5B,gBAAgB,YAAY;EAC5B,cAAc,YAAY,gBAAgB,CAAC;CAC7C;CAEA,MAAM,aAAA,GAAYC,aAAAA,aAAAA,CAAa;CAE/B,IAAI,QAAQ,QAAQ,eAAe,KAAA,GAA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IAAI,QAAQ,WAAW,MAAM,QAAQ,QAAQ,OAAO,GAAG;EACrD,IAAI,QAAQ,QAAQ,WAAW,GAAG;GAChC,OAAO,MACL,gEACA,2CACF;GACA,OAAO;EACT;EAGA,IADwB,QAAQ,QAAQ,QAAO,MAAK,OAAO,MAAM,YAAY,EAAE,KAAK,MAAM,EACxE,CAAC,CAAC,SAAS,GAAG;GAC9B,OAAO,MAAM,wDAAwD,yCAAyC;GAC9G,OAAO;EACT;CACF;CAEA,OAAO;AACT"}
|
|
@@ -62,7 +62,7 @@ function setTelemetryDataOnScope(options, scope, buildTool, buildToolMajorVersio
|
|
|
62
62
|
scope.setTag("custom-error-handler", !!errorHandler);
|
|
63
63
|
scope.setTag("sourcemaps-assets", !!sourcemaps?.assets);
|
|
64
64
|
scope.setTag("delete-after-upload", !!sourcemaps?.filesToDeleteAfterUpload);
|
|
65
|
-
scope.setTag("delete-sourcemaps-after-upload",
|
|
65
|
+
scope.setTag("delete-sourcemaps-after-upload", sourcemaps?.deleteSourcemapsAfterUpload === void 0 ? "auto" : String(sourcemaps.deleteSourcemapsAfterUpload));
|
|
66
66
|
scope.setTag("sourcemaps-disabled", !!sourcemaps?.disable);
|
|
67
67
|
scope.setTag("sourcemaps-upload", sourcemaps?.upload === void 0 ? "auto" : String(sourcemaps.upload));
|
|
68
68
|
scope.setTag("sourcemaps-inject-debug-ids", sourcemaps?.injectDebugIds === void 0 ? "auto" : String(sourcemaps.injectDebugIds));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry.js","names":["createStackParser","nodeStackLineParser","LIB_VERSION","makeOptionallyEnabledNodeTransport","applySdkMetadata","ServerRuntimeClient","Scope","SentryCliAdapter"],"sources":["../../../../src/core/sentry/telemetry.ts"],"sourcesContent":["import type { Client } from '@sentry/core';\nimport type { ServerRuntimeClientOptions } from '@sentry/core/server';\nimport { applySdkMetadata } from '@sentry/core';\nimport { ServerRuntimeClient } from '@sentry/core/server';\nimport type { NormalizedOptions } from '../options-mapping';\nimport { SENTRY_SAAS_URL } from '../options-mapping';\nimport { Scope } from '@sentry/core';\nimport { createStackParser } from '@sentry/core';\nimport { nodeStackLineParser } from '@sentry/core/server';\nimport { makeOptionallyEnabledNodeTransport } from './transports';\nimport { SentryCliAdapter } from '../cli';\nimport { LIB_VERSION } from '../version';\n\nconst SENTRY_SAAS_HOSTNAME = 'sentry.io';\n\nconst stackParser = createStackParser(nodeStackLineParser());\n\nexport function createSentryInstance(\n options: NormalizedOptions,\n shouldSendTelemetry: Promise<boolean>,\n buildTool: string,\n buildToolMajorVersion: string | undefined,\n): { sentryScope: Scope; sentryClient: Client } {\n const clientOptions: ServerRuntimeClientOptions = {\n platform: 'node',\n runtime: { name: 'node', version: global.process.version },\n\n dsn: 'https://4c2bae7d9fbc413e8f7385f55c515d51@o1.ingest.sentry.io/6690737',\n\n tracesSampleRate: 0.3,\n traceLifecycle: 'static',\n sampleRate: 1,\n\n release: LIB_VERSION,\n integrations: [],\n tracePropagationTargets: ['sentry.io/api'],\n\n stackParser,\n\n beforeSend: event => {\n event.exception?.values?.forEach(exception => {\n delete exception.stacktrace;\n });\n\n delete event.server_name; // Server name might contain PII\n return event;\n },\n\n // Deprecated, but still applied because this client runs on the static trace lifecycle.\n // oxlint-disable-next-line typescript/no-deprecated\n beforeSendTransaction: event => {\n delete event.server_name; // Server name might contain PII\n return event;\n },\n\n // We create a transport that stalls sending events until we know that we're allowed to (i.e. when Sentry CLI told\n // us that the upload URL is the Sentry SaaS URL)\n transport: makeOptionallyEnabledNodeTransport(shouldSendTelemetry),\n };\n\n applySdkMetadata(clientOptions, 'node');\n\n const client = new ServerRuntimeClient(clientOptions);\n const scope = new Scope();\n scope.setClient(client);\n\n // Integration tests snapshot the emitted transaction, so the sampling decision must not depend on chance.\n if (process.env['SENTRY_TEST_OUT_DIR']) {\n scope.setPropagationContext({ ...scope.getPropagationContext(), sampleRand: 0 });\n }\n\n setTelemetryDataOnScope(options, scope, buildTool, buildToolMajorVersion);\n\n return { sentryScope: scope, sentryClient: client };\n}\n\nexport function setTelemetryDataOnScope(\n options: NormalizedOptions,\n scope: Scope,\n buildTool: string,\n buildToolMajorVersion?: string,\n): void {\n const { org, project, release, errorHandler, sourcemaps, reactComponentAnnotation } = options;\n\n scope.setTag('upload-legacy-sourcemaps', !!release.uploadLegacySourcemaps);\n if (release.uploadLegacySourcemaps) {\n scope.setTag(\n 'uploadLegacySourcemapsEntries',\n Array.isArray(release.uploadLegacySourcemaps) ? release.uploadLegacySourcemaps.length : 1,\n );\n }\n\n scope.setTag('module-metadata', !!options.moduleMetadata);\n scope.setTag('inject-build-information', !!options._experiments.injectBuildInformation);\n\n // Optional release pipeline steps\n if (release.setCommits) {\n scope.setTag('set-commits', release.setCommits.auto === true ? 'auto' : 'manual');\n } else {\n scope.setTag('set-commits', 'undefined');\n }\n scope.setTag('finalize-release', release.finalize);\n scope.setTag('deploy-options', !!release.deploy);\n\n // Miscellaneous options\n scope.setTag('custom-error-handler', !!errorHandler);\n scope.setTag('sourcemaps-assets', !!sourcemaps?.assets);\n scope.setTag('delete-after-upload', !!sourcemaps?.filesToDeleteAfterUpload);\n scope.setTag(\n 'delete-sourcemaps-after-upload',\n
|
|
1
|
+
{"version":3,"file":"telemetry.js","names":["createStackParser","nodeStackLineParser","LIB_VERSION","makeOptionallyEnabledNodeTransport","applySdkMetadata","ServerRuntimeClient","Scope","SentryCliAdapter"],"sources":["../../../../src/core/sentry/telemetry.ts"],"sourcesContent":["import type { Client } from '@sentry/core';\nimport type { ServerRuntimeClientOptions } from '@sentry/core/server';\nimport { applySdkMetadata } from '@sentry/core';\nimport { ServerRuntimeClient } from '@sentry/core/server';\nimport type { NormalizedOptions } from '../options-mapping';\nimport { SENTRY_SAAS_URL } from '../options-mapping';\nimport { Scope } from '@sentry/core';\nimport { createStackParser } from '@sentry/core';\nimport { nodeStackLineParser } from '@sentry/core/server';\nimport { makeOptionallyEnabledNodeTransport } from './transports';\nimport { SentryCliAdapter } from '../cli';\nimport { LIB_VERSION } from '../version';\n\nconst SENTRY_SAAS_HOSTNAME = 'sentry.io';\n\nconst stackParser = createStackParser(nodeStackLineParser());\n\nexport function createSentryInstance(\n options: NormalizedOptions,\n shouldSendTelemetry: Promise<boolean>,\n buildTool: string,\n buildToolMajorVersion: string | undefined,\n): { sentryScope: Scope; sentryClient: Client } {\n const clientOptions: ServerRuntimeClientOptions = {\n platform: 'node',\n runtime: { name: 'node', version: global.process.version },\n\n dsn: 'https://4c2bae7d9fbc413e8f7385f55c515d51@o1.ingest.sentry.io/6690737',\n\n tracesSampleRate: 0.3,\n traceLifecycle: 'static',\n sampleRate: 1,\n\n release: LIB_VERSION,\n integrations: [],\n tracePropagationTargets: ['sentry.io/api'],\n\n stackParser,\n\n beforeSend: event => {\n event.exception?.values?.forEach(exception => {\n delete exception.stacktrace;\n });\n\n delete event.server_name; // Server name might contain PII\n return event;\n },\n\n // Deprecated, but still applied because this client runs on the static trace lifecycle.\n // oxlint-disable-next-line typescript/no-deprecated\n beforeSendTransaction: event => {\n delete event.server_name; // Server name might contain PII\n return event;\n },\n\n // We create a transport that stalls sending events until we know that we're allowed to (i.e. when Sentry CLI told\n // us that the upload URL is the Sentry SaaS URL)\n transport: makeOptionallyEnabledNodeTransport(shouldSendTelemetry),\n };\n\n applySdkMetadata(clientOptions, 'node');\n\n const client = new ServerRuntimeClient(clientOptions);\n const scope = new Scope();\n scope.setClient(client);\n\n // Integration tests snapshot the emitted transaction, so the sampling decision must not depend on chance.\n if (process.env['SENTRY_TEST_OUT_DIR']) {\n scope.setPropagationContext({ ...scope.getPropagationContext(), sampleRand: 0 });\n }\n\n setTelemetryDataOnScope(options, scope, buildTool, buildToolMajorVersion);\n\n return { sentryScope: scope, sentryClient: client };\n}\n\nexport function setTelemetryDataOnScope(\n options: NormalizedOptions,\n scope: Scope,\n buildTool: string,\n buildToolMajorVersion?: string,\n): void {\n const { org, project, release, errorHandler, sourcemaps, reactComponentAnnotation } = options;\n\n scope.setTag('upload-legacy-sourcemaps', !!release.uploadLegacySourcemaps);\n if (release.uploadLegacySourcemaps) {\n scope.setTag(\n 'uploadLegacySourcemapsEntries',\n Array.isArray(release.uploadLegacySourcemaps) ? release.uploadLegacySourcemaps.length : 1,\n );\n }\n\n scope.setTag('module-metadata', !!options.moduleMetadata);\n scope.setTag('inject-build-information', !!options._experiments.injectBuildInformation);\n\n // Optional release pipeline steps\n if (release.setCommits) {\n scope.setTag('set-commits', release.setCommits.auto === true ? 'auto' : 'manual');\n } else {\n scope.setTag('set-commits', 'undefined');\n }\n scope.setTag('finalize-release', release.finalize);\n scope.setTag('deploy-options', !!release.deploy);\n\n // Miscellaneous options\n scope.setTag('custom-error-handler', !!errorHandler);\n scope.setTag('sourcemaps-assets', !!sourcemaps?.assets);\n scope.setTag('delete-after-upload', !!sourcemaps?.filesToDeleteAfterUpload);\n scope.setTag(\n 'delete-sourcemaps-after-upload',\n sourcemaps?.deleteSourcemapsAfterUpload === undefined ? 'auto' : String(sourcemaps.deleteSourcemapsAfterUpload),\n );\n scope.setTag('sourcemaps-disabled', !!sourcemaps?.disable);\n scope.setTag('sourcemaps-upload', sourcemaps?.upload === undefined ? 'auto' : String(sourcemaps.upload));\n scope.setTag(\n 'sourcemaps-inject-debug-ids',\n sourcemaps?.injectDebugIds === undefined ? 'auto' : String(sourcemaps.injectDebugIds),\n );\n scope.setTag('sourcemaps-delete', sourcemaps?.delete === undefined ? 'auto' : String(sourcemaps.delete));\n\n scope.setTag('react-annotate', !!reactComponentAnnotation?.enabled);\n\n scope.setTag('node', process.version);\n scope.setTag('platform', process.platform);\n\n scope.setTag('meta-framework', options._metaOptions.telemetry.metaFramework ?? 'none');\n\n scope.setTag('application-key-set', options.applicationKey !== undefined);\n\n scope.setTag('ci', !!process.env['CI']);\n\n scope.setTags({\n organization: org,\n project: Array.isArray(project) ? project.join(', ') : (project ?? 'undefined'),\n bundler: buildTool,\n });\n\n if (buildToolMajorVersion) {\n scope.setTag('bundler-major-version', buildToolMajorVersion);\n }\n\n scope.setUser({ id: org });\n}\n\nexport async function allowedToSendTelemetry(options: NormalizedOptions): Promise<boolean> {\n const { telemetry } = options;\n const url = options.url ?? SENTRY_SAAS_URL;\n\n // `options.telemetry` defaults to true\n if (telemetry === false) {\n return false;\n }\n\n if (url === SENTRY_SAAS_URL) {\n return true;\n }\n\n // Ask the CLI which Sentry server URL it resolves to. This can differ from the default (or the\n // configured `url`) because the CLI also honors a possibly existing `.sentryclirc` file.\n const cliInfoUrl = await new SentryCliAdapter(options).getServerUrl();\n\n if (cliInfoUrl === undefined) {\n return false;\n }\n\n return new URL(cliInfoUrl).hostname === SENTRY_SAAS_HOSTNAME;\n}\n\n/**\n * Flushing the SDK client can fail. We never want to crash the plugin because of telemetry.\n */\nexport async function safeFlushTelemetry(sentryClient: Client): Promise<void> {\n try {\n await sentryClient.flush(2000);\n } catch {\n // Noop when flushing fails.\n // We don't even need to log anything because there's likely nothing the user can do and they likely will not care.\n }\n}\n"],"mappings":";;;;;;;AAaA,MAAM,uBAAuB;AAE7B,MAAM,eAAA,GAAcA,aAAAA,kBAAAA,EAAAA,GAAkBC,oBAAAA,oBAAAA,CAAoB,CAAC;AAE3D,SAAgB,qBACd,SACA,qBACA,WACA,uBAC8C;CAC9C,MAAM,gBAA4C;EAChD,UAAU;EACV,SAAS;GAAE,MAAM;GAAQ,SAAS,OAAO,QAAQ;EAAQ;EAEzD,KAAK;EAEL,kBAAkB;EAClB,gBAAgB;EAChB,YAAY;EAEZ,SAASC,gBAAAA;EACT,cAAc,CAAC;EACf,yBAAyB,CAAC,eAAe;EAEzC;EAEA,aAAY,UAAS;GACnB,MAAM,WAAW,QAAQ,SAAQ,cAAa;IAC5C,OAAO,UAAU;GACnB,CAAC;GAED,OAAO,MAAM;GACb,OAAO;EACT;EAIA,wBAAuB,UAAS;GAC9B,OAAO,MAAM;GACb,OAAO;EACT;EAIA,WAAWC,mBAAAA,mCAAmC,mBAAmB;CACnE;CAEAC,CAAAA,GAAAA,aA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
|
|
20
20
|
}
|
|
21
|
-
/** Reads `sourcemaps.
|
|
22
|
-
function
|
|
23
|
-
const value = options.sourcemaps?.
|
|
21
|
+
/** Reads the internal `sourcemaps.sdkDeleteSourceMaps` option, calling its function form if given. */
|
|
22
|
+
function getSdkDeleteSourceMaps(options, environment) {
|
|
23
|
+
const value = options.sourcemaps?.sdkDeleteSourceMaps;
|
|
24
24
|
return typeof value === "function" ? value(environment) : value;
|
|
25
25
|
}
|
|
26
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* Reads `sourcemaps.delete`. When it is unset, `sourcemaps.deleteSourcemapsAfterUpload` decides, and
|
|
28
|
+
* then the SDK.
|
|
29
|
+
*/
|
|
27
30
|
function getDeleteOption(options, environment) {
|
|
28
|
-
return options.sourcemaps?.delete ??
|
|
29
|
-
}
|
|
30
|
-
/** Reads the internal `sourcemaps.sdkEnabledSourceMaps` option, calling its function form if given. */
|
|
31
|
-
function getSdkEnabledSourceMaps(options, environment) {
|
|
32
|
-
const value = options.sourcemaps?.sdkEnabledSourceMaps;
|
|
33
|
-
return (typeof value === "function" ? value(environment) : value) === true;
|
|
31
|
+
return options.sourcemaps?.delete ?? options.sourcemaps?.deleteSourcemapsAfterUpload ?? getSdkDeleteSourceMaps(options, environment);
|
|
34
32
|
}
|
|
35
33
|
/**
|
|
36
34
|
* Decides whether the plugin turns hidden source maps on and whether it removes the maps from the
|
|
37
35
|
* build output after the upload. The plugin only turns maps on when an upload can run, and only
|
|
38
|
-
* removes maps it turned on itself unless `deleteSourcemapsAfterUpload`
|
|
36
|
+
* removes maps it turned on itself unless `deleteSourcemapsAfterUpload` or the SDK's
|
|
37
|
+
* `sdkDeleteSourceMaps` says otherwise. The user's `deleteSourcemapsAfterUpload` wins over the SDK.
|
|
39
38
|
*/
|
|
40
39
|
function decideSourceMapHandling(kind, options, uploadPossible, environment) {
|
|
41
40
|
const features = getSourceMapFeatures(options);
|
|
42
41
|
if (options.sourcemaps?.delete !== void 0) return decideWithDeleteOption(kind, options.sourcemaps.delete, features, uploadPossible);
|
|
43
|
-
const
|
|
44
|
-
const
|
|
42
|
+
const userDeleteOption = options.sourcemaps?.deleteSourcemapsAfterUpload;
|
|
43
|
+
const sdkDeleteOption = getSdkDeleteSourceMaps(options, environment);
|
|
44
|
+
const deleteOption = userDeleteOption ?? sdkDeleteOption;
|
|
45
|
+
const sdkRemovesAll = sdkDeleteOption === true;
|
|
46
|
+
const fromUser = userDeleteOption !== void 0;
|
|
45
47
|
if (!uploadPossible || !features.upload) {
|
|
46
48
|
if (deleteOption !== true || kind !== "hidden" && kind !== "visible") return NO_CHANGE;
|
|
47
|
-
if (!features.upload && !
|
|
49
|
+
if (!features.upload && !sdkRemovesAll) return {
|
|
48
50
|
...NO_CHANGE,
|
|
49
51
|
log: {
|
|
50
52
|
level: "warn",
|
|
@@ -54,10 +56,13 @@ function decideSourceMapHandling(kind, options, uploadPossible, environment) {
|
|
|
54
56
|
return {
|
|
55
57
|
enableHidden: kind === "visible",
|
|
56
58
|
deleteAfterUpload: true,
|
|
57
|
-
removeAllSourceMaps:
|
|
58
|
-
log: {
|
|
59
|
+
removeAllSourceMaps: sdkRemovesAll,
|
|
60
|
+
log: fromUser ? {
|
|
59
61
|
level: "warn",
|
|
60
62
|
message: "Source maps are not uploaded, but they are removed from the build output because `sourcemaps.deleteSourcemapsAfterUpload` is set."
|
|
63
|
+
} : {
|
|
64
|
+
level: "info",
|
|
65
|
+
message: "Source maps are not uploaded, but the Sentry SDK removes them from the build output."
|
|
61
66
|
}
|
|
62
67
|
};
|
|
63
68
|
}
|
|
@@ -91,7 +96,7 @@ function decideSourceMapHandling(kind, options, uploadPossible, environment) {
|
|
|
91
96
|
removeAllSourceMaps: true,
|
|
92
97
|
log: {
|
|
93
98
|
level: "info",
|
|
94
|
-
message: "Enabling hidden source maps. They are uploaded to Sentry and removed from the build output. Set `sourcemaps.
|
|
99
|
+
message: "Enabling hidden source maps. They are uploaded to Sentry and removed from the build output. Set `sourcemaps.delete: false` to keep them."
|
|
95
100
|
}
|
|
96
101
|
};
|
|
97
102
|
case "hidden":
|
|
@@ -99,17 +104,17 @@ function decideSourceMapHandling(kind, options, uploadPossible, environment) {
|
|
|
99
104
|
return {
|
|
100
105
|
enableHidden: false,
|
|
101
106
|
deleteAfterUpload: true,
|
|
102
|
-
removeAllSourceMaps:
|
|
107
|
+
removeAllSourceMaps: sdkRemovesAll
|
|
103
108
|
};
|
|
104
109
|
case "visible":
|
|
105
110
|
if (deleteOption !== true) return NO_CHANGE;
|
|
106
111
|
return {
|
|
107
112
|
enableHidden: true,
|
|
108
113
|
deleteAfterUpload: true,
|
|
109
|
-
removeAllSourceMaps:
|
|
114
|
+
removeAllSourceMaps: sdkRemovesAll,
|
|
110
115
|
log: {
|
|
111
116
|
level: "info",
|
|
112
|
-
message: "Switching to hidden source maps because `sourcemaps.deleteSourcemapsAfterUpload` is set. Without the `sourceMappingURL` comment browsers do not request the removed map files."
|
|
117
|
+
message: fromUser ? "Switching to hidden source maps because `sourcemaps.deleteSourcemapsAfterUpload` is set. Without the `sourceMappingURL` comment browsers do not request the removed map files." : "Switching to hidden source maps, because the Sentry SDK removes them from the build output. Without the `sourceMappingURL` comment browsers do not request the removed map files."
|
|
113
118
|
}
|
|
114
119
|
};
|
|
115
120
|
}
|
|
@@ -173,8 +178,7 @@ function decideWithDeleteOption(kind, deleteSourceMaps, features, uploadPossible
|
|
|
173
178
|
}
|
|
174
179
|
exports.decideSourceMapHandling = decideSourceMapHandling;
|
|
175
180
|
exports.getDeleteOption = getDeleteOption;
|
|
176
|
-
exports.
|
|
177
|
-
exports.getSdkEnabledSourceMaps = getSdkEnabledSourceMaps;
|
|
181
|
+
exports.getSdkDeleteSourceMaps = getSdkDeleteSourceMaps;
|
|
178
182
|
exports.getSourceMapFeatures = getSourceMapFeatures;
|
|
179
183
|
|
|
180
184
|
//# sourceMappingURL=sourcemap-settings.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sourcemap-settings.js","names":["resolveSourceMapsFeatures"],"sources":["../../../src/core/sourcemap-settings.ts"],"sourcesContent":["import { resolveSourceMapsFeatures } from '@sentry/core';\nimport type { NormalizedOptions } from './options-mapping';\n\n/**\n * The user's source map setting in the bundler, reduced to what matters for upload and deletion.\n *\n * - `unset`: the user did not configure source maps\n * - `off`: source map generation is turned off\n * - `visible`: separate map files with a `sourceMappingURL` comment\n * - `hidden`: separate map files without the comment\n * - `inline`: the map is embedded into the bundle\n */\nexport type SourceMapKind = 'unset' | 'off' | 'visible' | 'hidden' | 'inline';\n\nexport type SourceMapDecision = {\n /** Switch the bundler to hidden source maps. */\n enableHidden: boolean;\n /** Remove the source maps from the build output once they are uploaded. */\n deleteAfterUpload: boolean;\n /**\n * With `deleteAfterUpload`, remove every source map of the build, also those of CSS and of chunks\n * the upload leaves out. Set when the plugin or the SDK turned the source maps on.\n */\n removeAllSourceMaps?: boolean;\n log?: { level: 'info' | 'warn'; message: string };\n};\n\nconst NO_CHANGE: SourceMapDecision = { enableHidden: false, deleteAfterUpload: false };\n\nconst SOURCE_MAPS_OFF_MESSAGE =\n 'Source map generation is turned off in your bundler, so Sentry cannot un-minify your stack traces. ' +\n 'Remove the setting to let the plugin generate hidden source maps, upload them to Sentry and remove them from the build output.';\n\nconst INLINE_SOURCE_MAPS_MESSAGE =\n 'Source maps are inlined into your bundles. They are uploaded to Sentry, but inline source maps ship your source code to users and cannot be removed after the upload. ' +\n 'Remove the setting to let the plugin generate hidden source maps instead.';\n\nexport type SourceMapFeatures = {\n /** The plugin adds debug IDs to the bundles and their source maps. */\n injectDebugIds: boolean;\n /** The plugin uploads the source maps. Never `true` without `injectDebugIds`. */\n upload: boolean;\n /**\n * The plugin writes the debug IDs into the emitted files and source maps. The upload only stamps\n * temp copies, so without an upload the emitted files get them and a later manual upload needs\n * no inject step.\n */\n stampEmittedFiles: boolean;\n};\n\n/**\n * Reads `sourcemaps.upload` and `sourcemaps.injectDebugIds`. When neither is set,\n * `sourcemaps.disable` decides.\n */\nexport function getSourceMapFeatures(options: NormalizedOptions): SourceMapFeatures {\n const { injectDebugIds, upload } = resolveSourceMapsFeatures(options.sourcemaps);\n\n return { injectDebugIds, upload, stampEmittedFiles: injectDebugIds && !upload };\n}\n\n/** Reads `sourcemaps.deleteSourcemapsAfterUpload`, calling the internal function form if given. */\nexport function getDeleteSourcemapsAfterUpload(options: NormalizedOptions, environment?: string): boolean | undefined {\n const value = options.sourcemaps?.deleteSourcemapsAfterUpload;\n return typeof value === 'function' ? value(environment) : value;\n}\n\n/** Reads `sourcemaps.delete`. When it is unset, `sourcemaps.deleteSourcemapsAfterUpload` decides. */\nexport function getDeleteOption(options: NormalizedOptions, environment?: string): boolean | undefined {\n return options.sourcemaps?.delete ?? getDeleteSourcemapsAfterUpload(options, environment);\n}\n\n/** Reads the internal `sourcemaps.sdkEnabledSourceMaps` option, calling its function form if given. */\nexport function getSdkEnabledSourceMaps(options: NormalizedOptions, environment?: string): boolean {\n const value = options.sourcemaps?.sdkEnabledSourceMaps;\n return (typeof value === 'function' ? value(environment) : value) === true;\n}\n\n/**\n * Decides whether the plugin turns hidden source maps on and whether it removes the maps from the\n * build output after the upload. The plugin only turns maps on when an upload can run, and only\n * removes maps it turned on itself unless `deleteSourcemapsAfterUpload` says otherwise.\n */\nexport function decideSourceMapHandling(\n kind: SourceMapKind,\n options: NormalizedOptions,\n uploadPossible: boolean,\n environment?: string,\n): SourceMapDecision {\n const features = getSourceMapFeatures(options);\n\n if (options.sourcemaps?.delete !== undefined) {\n return decideWithDeleteOption(kind, options.sourcemaps.delete, features, uploadPossible);\n }\n\n const deleteOption = getDeleteSourcemapsAfterUpload(options, environment);\n const sdkEnabledSourceMaps = getSdkEnabledSourceMaps(options, environment);\n\n if (!uploadPossible || !features.upload) {\n if (deleteOption !== true || (kind !== 'hidden' && kind !== 'visible')) {\n return NO_CHANGE;\n }\n // Users switch the upload off to upload the maps themselves. Maps the\n // SDK turned on are still removed, as the SDKs' own globs did.\n if (!features.upload && !sdkEnabledSourceMaps) {\n return {\n ...NO_CHANGE,\n log: {\n level: 'warn',\n message: `\\`sourcemaps.deleteSourcemapsAfterUpload\\` is set, but source map upload is disabled with ${\n resolveSourceMapsFeatures(options.sourcemaps).legacyDisable\n ? '`sourcemaps.disable`'\n : '`sourcemaps.upload` or `sourcemaps.injectDebugIds`'\n }, so the source maps are not removed.`,\n },\n };\n }\n return {\n enableHidden: kind === 'visible',\n deleteAfterUpload: true,\n removeAllSourceMaps: sdkEnabledSourceMaps,\n log: {\n level: 'warn',\n message:\n 'Source maps are not uploaded, but they are removed from the build output because `sourcemaps.deleteSourcemapsAfterUpload` is set.',\n },\n };\n }\n\n switch (kind) {\n case 'off':\n return {\n ...NO_CHANGE,\n log: {\n level: 'warn',\n message: SOURCE_MAPS_OFF_MESSAGE,\n },\n };\n\n case 'inline':\n return {\n ...NO_CHANGE,\n log: {\n level: 'warn',\n message: INLINE_SOURCE_MAPS_MESSAGE,\n },\n };\n\n case 'unset':\n if (deleteOption === false) {\n return {\n enableHidden: true,\n deleteAfterUpload: false,\n log: {\n level: 'info',\n message: 'Enabling hidden source maps. They are uploaded to Sentry and kept in the build output.',\n },\n };\n }\n return {\n enableHidden: true,\n deleteAfterUpload: true,\n removeAllSourceMaps: true,\n log: {\n level: 'info',\n message:\n 'Enabling hidden source maps. They are uploaded to Sentry and removed from the build output. ' +\n 'Set `sourcemaps.deleteSourcemapsAfterUpload: false` to keep them.',\n },\n };\n\n case 'hidden':\n if (deleteOption !== true) {\n return NO_CHANGE;\n }\n return { enableHidden: false, deleteAfterUpload: true, removeAllSourceMaps: sdkEnabledSourceMaps };\n\n case 'visible':\n if (deleteOption !== true) {\n return NO_CHANGE;\n }\n return {\n enableHidden: true,\n deleteAfterUpload: true,\n removeAllSourceMaps: sdkEnabledSourceMaps,\n log: {\n level: 'info',\n message:\n 'Switching to hidden source maps because `sourcemaps.deleteSourcemapsAfterUpload` is set. ' +\n 'Without the `sourceMappingURL` comment browsers do not request the removed map files.',\n },\n };\n }\n}\n\n/**\n * The decision when `sourcemaps.delete` is set. Unlike `deleteSourcemapsAfterUpload`, it does not\n * depend on an upload: `true` removes every source map of the build, and `false` keeps the hidden\n * source maps the plugin turns on, also when nothing is uploaded.\n */\nfunction decideWithDeleteOption(\n kind: SourceMapKind,\n deleteSourceMaps: boolean,\n features: SourceMapFeatures,\n uploadPossible: boolean,\n): SourceMapDecision {\n switch (kind) {\n case 'off':\n return uploadPossible ? { ...NO_CHANGE, log: { level: 'warn', message: SOURCE_MAPS_OFF_MESSAGE } } : NO_CHANGE;\n\n case 'inline':\n return uploadPossible ? { ...NO_CHANGE, log: { level: 'warn', message: INLINE_SOURCE_MAPS_MESSAGE } } : NO_CHANGE;\n\n case 'unset':\n if (deleteSourceMaps) {\n // Maps that are only turned on to be removed again are not turned on.\n return uploadPossible\n ? {\n enableHidden: true,\n deleteAfterUpload: true,\n removeAllSourceMaps: true,\n log: {\n level: 'info',\n message: 'Enabling hidden source maps. They are uploaded to Sentry and removed from the build output.',\n },\n }\n : NO_CHANGE;\n }\n // Without debug IDs the maps are of no use to Sentry.\n if (!features.injectDebugIds) {\n return NO_CHANGE;\n }\n return {\n enableHidden: true,\n deleteAfterUpload: false,\n log: {\n level: 'info',\n message: uploadPossible\n ? 'Enabling hidden source maps. They are uploaded to Sentry and kept in the build output.'\n : 'Enabling hidden source maps. They are not uploaded to Sentry and are kept in the build output, because `sourcemaps.delete` is `false`.',\n },\n };\n\n case 'hidden':\n case 'visible':\n if (!deleteSourceMaps) {\n return NO_CHANGE;\n }\n return {\n enableHidden: kind === 'visible',\n deleteAfterUpload: true,\n removeAllSourceMaps: true,\n log: uploadPossible\n ? kind === 'visible'\n ? {\n level: 'info',\n message:\n 'Switching to hidden source maps because `sourcemaps.delete` is set. ' +\n 'Without the `sourceMappingURL` comment browsers do not request the removed map files.',\n }\n : undefined\n : {\n level: 'warn',\n message:\n 'Source maps are not uploaded, but they are removed from the build output because `sourcemaps.delete` is set.',\n },\n };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AAK;GACH,IAAI,CAAC,kBACH,OAAO;GAET,OAAO;IACL,cAAc,SAAS;IACvB,mBAAmB;IACnB,qBAAqB;IACrB,KAAK,iBACD,SAAS,YACP;KACE,OAAO;KACP,SACE;IAEJ,IACA,KAAA,IACF;KACE,OAAO;KACP,SACE;IACJ;GACN;CACJ;AACF"}
|
|
1
|
+
{"version":3,"file":"sourcemap-settings.js","names":["resolveSourceMapsFeatures"],"sources":["../../../src/core/sourcemap-settings.ts"],"sourcesContent":["import { resolveSourceMapsFeatures } from '@sentry/core';\nimport type { NormalizedOptions } from './options-mapping';\n\n/**\n * The user's source map setting in the bundler, reduced to what matters for upload and deletion.\n *\n * - `unset`: the user did not configure source maps\n * - `off`: source map generation is turned off\n * - `visible`: separate map files with a `sourceMappingURL` comment\n * - `hidden`: separate map files without the comment\n * - `inline`: the map is embedded into the bundle\n */\nexport type SourceMapKind = 'unset' | 'off' | 'visible' | 'hidden' | 'inline';\n\nexport type SourceMapDecision = {\n /** Switch the bundler to hidden source maps. */\n enableHidden: boolean;\n /** Remove the source maps from the build output once they are uploaded. */\n deleteAfterUpload: boolean;\n /**\n * With `deleteAfterUpload`, remove every source map of the build, also those of CSS and of chunks\n * the upload leaves out. Set when the plugin or the SDK turned the source maps on.\n */\n removeAllSourceMaps?: boolean;\n log?: { level: 'info' | 'warn'; message: string };\n};\n\nconst NO_CHANGE: SourceMapDecision = { enableHidden: false, deleteAfterUpload: false };\n\nconst SOURCE_MAPS_OFF_MESSAGE =\n 'Source map generation is turned off in your bundler, so Sentry cannot un-minify your stack traces. ' +\n 'Remove the setting to let the plugin generate hidden source maps, upload them to Sentry and remove them from the build output.';\n\nconst INLINE_SOURCE_MAPS_MESSAGE =\n 'Source maps are inlined into your bundles. They are uploaded to Sentry, but inline source maps ship your source code to users and cannot be removed after the upload. ' +\n 'Remove the setting to let the plugin generate hidden source maps instead.';\n\nexport type SourceMapFeatures = {\n /** The plugin adds debug IDs to the bundles and their source maps. */\n injectDebugIds: boolean;\n /** The plugin uploads the source maps. Never `true` without `injectDebugIds`. */\n upload: boolean;\n /**\n * The plugin writes the debug IDs into the emitted files and source maps. The upload only stamps\n * temp copies, so without an upload the emitted files get them and a later manual upload needs\n * no inject step.\n */\n stampEmittedFiles: boolean;\n};\n\n/**\n * Reads `sourcemaps.upload` and `sourcemaps.injectDebugIds`. When neither is set,\n * `sourcemaps.disable` decides.\n */\nexport function getSourceMapFeatures(options: NormalizedOptions): SourceMapFeatures {\n const { injectDebugIds, upload } = resolveSourceMapsFeatures(options.sourcemaps);\n\n return { injectDebugIds, upload, stampEmittedFiles: injectDebugIds && !upload };\n}\n\n/** Reads the internal `sourcemaps.sdkDeleteSourceMaps` option, calling its function form if given. */\nexport function getSdkDeleteSourceMaps(options: NormalizedOptions, environment?: string): boolean | undefined {\n const value = options.sourcemaps?.sdkDeleteSourceMaps;\n return typeof value === 'function' ? value(environment) : value;\n}\n\n/**\n * Reads `sourcemaps.delete`. When it is unset, `sourcemaps.deleteSourcemapsAfterUpload` decides, and\n * then the SDK.\n */\nexport function getDeleteOption(options: NormalizedOptions, environment?: string): boolean | undefined {\n return (\n options.sourcemaps?.delete ??\n options.sourcemaps?.deleteSourcemapsAfterUpload ??\n getSdkDeleteSourceMaps(options, environment)\n );\n}\n\n/**\n * Decides whether the plugin turns hidden source maps on and whether it removes the maps from the\n * build output after the upload. The plugin only turns maps on when an upload can run, and only\n * removes maps it turned on itself unless `deleteSourcemapsAfterUpload` or the SDK's\n * `sdkDeleteSourceMaps` says otherwise. The user's `deleteSourcemapsAfterUpload` wins over the SDK.\n */\nexport function decideSourceMapHandling(\n kind: SourceMapKind,\n options: NormalizedOptions,\n uploadPossible: boolean,\n environment?: string,\n): SourceMapDecision {\n const features = getSourceMapFeatures(options);\n\n if (options.sourcemaps?.delete !== undefined) {\n return decideWithDeleteOption(kind, options.sourcemaps.delete, features, uploadPossible);\n }\n\n const userDeleteOption = options.sourcemaps?.deleteSourcemapsAfterUpload;\n const sdkDeleteOption = getSdkDeleteSourceMaps(options, environment);\n const deleteOption = userDeleteOption ?? sdkDeleteOption;\n const sdkRemovesAll = sdkDeleteOption === true;\n const fromUser = userDeleteOption !== undefined;\n\n if (!uploadPossible || !features.upload) {\n if (deleteOption !== true || (kind !== 'hidden' && kind !== 'visible')) {\n return NO_CHANGE;\n }\n // Users switch the upload off to upload the maps themselves. The SDK's\n // deletion still runs, as the SDKs' own globs did.\n if (!features.upload && !sdkRemovesAll) {\n return {\n ...NO_CHANGE,\n log: {\n level: 'warn',\n message: `\\`sourcemaps.deleteSourcemapsAfterUpload\\` is set, but source map upload is disabled with ${\n resolveSourceMapsFeatures(options.sourcemaps).legacyDisable\n ? '`sourcemaps.disable`'\n : '`sourcemaps.upload` or `sourcemaps.injectDebugIds`'\n }, so the source maps are not removed.`,\n },\n };\n }\n return {\n enableHidden: kind === 'visible',\n deleteAfterUpload: true,\n removeAllSourceMaps: sdkRemovesAll,\n log: fromUser\n ? {\n level: 'warn',\n message:\n 'Source maps are not uploaded, but they are removed from the build output because `sourcemaps.deleteSourcemapsAfterUpload` is set.',\n }\n : {\n level: 'info',\n message: 'Source maps are not uploaded, but the Sentry SDK removes them from the build output.',\n },\n };\n }\n\n switch (kind) {\n case 'off':\n return {\n ...NO_CHANGE,\n log: {\n level: 'warn',\n message: SOURCE_MAPS_OFF_MESSAGE,\n },\n };\n\n case 'inline':\n return {\n ...NO_CHANGE,\n log: {\n level: 'warn',\n message: INLINE_SOURCE_MAPS_MESSAGE,\n },\n };\n\n case 'unset':\n if (deleteOption === false) {\n return {\n enableHidden: true,\n deleteAfterUpload: false,\n log: {\n level: 'info',\n message: 'Enabling hidden source maps. They are uploaded to Sentry and kept in the build output.',\n },\n };\n }\n return {\n enableHidden: true,\n deleteAfterUpload: true,\n removeAllSourceMaps: true,\n log: {\n level: 'info',\n message:\n 'Enabling hidden source maps. They are uploaded to Sentry and removed from the build output. ' +\n 'Set `sourcemaps.delete: false` to keep them.',\n },\n };\n\n case 'hidden':\n if (deleteOption !== true) {\n return NO_CHANGE;\n }\n return { enableHidden: false, deleteAfterUpload: true, removeAllSourceMaps: sdkRemovesAll };\n\n case 'visible':\n if (deleteOption !== true) {\n return NO_CHANGE;\n }\n return {\n enableHidden: true,\n deleteAfterUpload: true,\n removeAllSourceMaps: sdkRemovesAll,\n log: {\n level: 'info',\n message: fromUser\n ? 'Switching to hidden source maps because `sourcemaps.deleteSourcemapsAfterUpload` is set. ' +\n 'Without the `sourceMappingURL` comment browsers do not request the removed map files.'\n : 'Switching to hidden source maps, because the Sentry SDK removes them from the build output. ' +\n 'Without the `sourceMappingURL` comment browsers do not request the removed map files.',\n },\n };\n }\n}\n\n/**\n * The decision when `sourcemaps.delete` is set. Unlike `deleteSourcemapsAfterUpload`, it does not\n * depend on an upload: `true` removes every source map of the build, and `false` keeps the hidden\n * source maps the plugin turns on, also when nothing is uploaded.\n */\nfunction decideWithDeleteOption(\n kind: SourceMapKind,\n deleteSourceMaps: boolean,\n features: SourceMapFeatures,\n uploadPossible: boolean,\n): SourceMapDecision {\n switch (kind) {\n case 'off':\n return uploadPossible ? { ...NO_CHANGE, log: { level: 'warn', message: SOURCE_MAPS_OFF_MESSAGE } } : NO_CHANGE;\n\n case 'inline':\n return uploadPossible ? { ...NO_CHANGE, log: { level: 'warn', message: INLINE_SOURCE_MAPS_MESSAGE } } : NO_CHANGE;\n\n case 'unset':\n if (deleteSourceMaps) {\n // Maps that are only turned on to be removed again are not turned on.\n return uploadPossible\n ? {\n enableHidden: true,\n deleteAfterUpload: true,\n removeAllSourceMaps: true,\n log: {\n level: 'info',\n message: 'Enabling hidden source maps. They are uploaded to Sentry and removed from the build output.',\n },\n }\n : NO_CHANGE;\n }\n // Without debug IDs the maps are of no use to Sentry.\n if (!features.injectDebugIds) {\n return NO_CHANGE;\n }\n return {\n enableHidden: true,\n deleteAfterUpload: false,\n log: {\n level: 'info',\n message: uploadPossible\n ? 'Enabling hidden source maps. They are uploaded to Sentry and kept in the build output.'\n : 'Enabling hidden source maps. They are not uploaded to Sentry and are kept in the build output, because `sourcemaps.delete` is `false`.',\n },\n };\n\n case 'hidden':\n case 'visible':\n if (!deleteSourceMaps) {\n return NO_CHANGE;\n }\n return {\n enableHidden: kind === 'visible',\n deleteAfterUpload: true,\n removeAllSourceMaps: true,\n log: uploadPossible\n ? kind === 'visible'\n ? {\n level: 'info',\n message:\n 'Switching to hidden source maps because `sourcemaps.delete` is set. ' +\n 'Without the `sourceMappingURL` comment browsers do not request the removed map files.',\n }\n : undefined\n : {\n level: 'warn',\n message:\n 'Source maps are not uploaded, but they are removed from the build output because `sourcemaps.delete` is set.',\n },\n };\n }\n}\n"],"mappings":";;AA2BA,MAAM,YAA+B;CAAE,cAAc;CAAO,mBAAmB;AAAM;AAErF,MAAM,0BACJ;AAGF,MAAM,6BACJ;;;;;AAoBF,SAAgB,qBAAqB,SAA+C;CAClF,MAAM,EAAE,gBAAgB,YAAA,GAAWA,aAAAA,0BAAAA,CAA0B,QAAQ,UAAU;CAE/E,OAAO;EAAE;EAAgB;EAAQ,mBAAmB,kBAAkB,CAAC;CAAO;AAChF;;AAGA,SAAgB,uBAAuB,SAA4B,aAA2C;CAC5G,MAAM,QAAQ,QAAQ,YAAY;CAClC,OAAO,OAAO,UAAU,aAAa,MAAM,WAAW,IAAI;AAC5D;;;;;AAMA,SAAgB,gBAAgB,SAA4B,aAA2C;CACrG,OACE,QAAQ,YAAY,UACpB,QAAQ,YAAY,+BACpB,uBAAuB,SAAS,WAAW;AAE/C;;;;;;;AAQA,SAAgB,wBACd,MACA,SACA,gBACA,aACmB;CACnB,MAAM,WAAW,qBAAqB,OAAO;CAE7C,IAAI,QAAQ,YAAY,WAAW,KAAA,GACjC,OAAO,uBAAuB,MAAM,QAAQ,WAAW,QAAQ,UAAU,cAAc;CAGzF,MAAM,mBAAmB,QAAQ,YAAY;CAC7C,MAAM,kBAAkB,uBAAuB,SAAS,WAAW;CACnE,MAAM,eAAe,oBAAoB;CACzC,MAAM,gBAAgB,oB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,OAAO;IAAQ,SAAS;GAAwB;EAAE,IAAI;EAEvG,KAAK,UACH,OAAO,iBAAiB;GAAE,GAAG;GAAW,KAAK;IAAE,OAAO;IAAQ,SAAS;GAA2B;EAAE,IAAI;EAE1G,KAAK;GACH,IAAI,kBAEF,OAAO,iBACH;IACE,cAAc;IACd,mBAAmB;IACnB,qBAAqB;IACrB,KAAK;KACH,OAAO;KACP,SAAS;IACX;GACF,IACA;GAGN,IAAI,CAAC,SAAS,gBACZ,OAAO;GAET,OAAO;IACL,cAAc;IACd,mBAAmB;IACnB,KAAK;KACH,OAAO;KACP,SAAS,iBACL,2FACA;IACN;GACF;EAEF,KAAK;EACL,KAAK;GACH,IAAI,CAAC,kBACH,OAAO;GAET,OAAO;IACL,cAAc,SAAS;IACvB,mBAAmB;IACnB,qBAAqB;IACrB,KAAK,iBACD,SAAS,YACP;KACE,OAAO;KACP,SACE;IAEJ,IACA,KAAA,IACF;KACE,OAAO;KACP,SACE;IACJ;GACN;CACJ;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","names":[],"sources":["../../../src/core/version.ts"],"sourcesContent":["export const LIB_VERSION = \"11.
|
|
1
|
+
{"version":3,"file":"version.js","names":[],"sources":["../../../src/core/version.ts"],"sourcesContent":["export const LIB_VERSION = \"11.20.0\";\n"],"mappings":";AAAA,MAAa,cAAc"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// src/rewriter/arrays.ts
|
|
2
|
+
/**
|
|
3
|
+
* Replace an array literal of identifiers with `build(names)`, where `names`
|
|
4
|
+
* holds each identifier once, in source order. An empty array is left alone.
|
|
5
|
+
* An array holding anything other than plain identifiers is left alone and
|
|
6
|
+
* recorded as skipped under `label`.
|
|
7
|
+
*
|
|
8
|
+
* @returns whether the array was replaced
|
|
9
|
+
*/
|
|
10
|
+
function wrapArrayLiteral(state, arrayNode, label, build) {
|
|
11
|
+
const elements = arrayNode.elements ?? [];
|
|
12
|
+
if (elements.length === 0) return false;
|
|
13
|
+
if (!elements.every((element) => element?.type === "Identifier")) {
|
|
14
|
+
state.report.skipped.push(label);
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
const names = [...new Set(elements.map((element) => element.name))];
|
|
18
|
+
state.ms.overwrite(arrayNode.start, arrayNode.end, build(names));
|
|
19
|
+
state.needsImport = true;
|
|
20
|
+
state.report.wrapped.push(label);
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
exports.wrapArrayLiteral = wrapArrayLiteral;
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=arrays.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arrays.js","names":[],"sources":["../../../src/rewriter/arrays.ts"],"sourcesContent":["import type { ArrayExpressionNode, BaseNode, IdentifierNode } from './ast';\nimport type { RewriteState } from './rewriter';\n\n/**\n * Replace an array literal of identifiers with `build(names)`, where `names`\n * holds each identifier once, in source order. An empty array is left alone.\n * An array holding anything other than plain identifiers is left alone and\n * recorded as skipped under `label`.\n *\n * @returns whether the array was replaced\n */\nexport function wrapArrayLiteral(\n state: RewriteState,\n arrayNode: BaseNode,\n label: string,\n build: (names: string[]) => string,\n): boolean {\n const elements = (arrayNode as ArrayExpressionNode).elements ?? [];\n if (elements.length === 0) return false;\n\n if (!elements.every(element => element?.type === 'Identifier')) {\n state.report.skipped.push(label);\n return false;\n }\n\n const names = [...new Set(elements.map(element => (element as IdentifierNode).name))];\n state.ms.overwrite(arrayNode.start, arrayNode.end, build(names));\n state.needsImport = true;\n state.report.wrapped.push(label);\n return true;\n}\n"],"mappings":";;;;;;;;;AAWA,SAAgB,iBACd,OACA,WACA,OACA,OACS;CACT,MAAM,WAAY,UAAkC,YAAY,CAAC;CACjE,IAAI,SAAS,WAAW,GAAG,OAAO;CAElC,IAAI,CAAC,SAAS,OAAM,YAAW,SAAS,SAAS,YAAY,GAAG;EAC9D,MAAM,OAAO,QAAQ,KAAK,KAAK;EAC/B,OAAO;CACT;CAEA,MAAM,QAAQ,CAAC,GAAG,IAAI,IAAI,SAAS,KAAI,YAAY,QAA2B,IAAI,CAAC,CAAC;CACpF,MAAM,GAAG,UAAU,UAAU,OAAO,UAAU,KAAK,MAAM,KAAK,CAAC;CAC/D,MAAM,cAAc;CACpB,MAAM,OAAO,QAAQ,KAAK,KAAK;CAC/B,OAAO;AACT"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// src/rewriter/ast.ts
|
|
2
|
+
/** The declaration a top-level statement makes, looking through `export` (`export const x = ...`). */
|
|
3
|
+
function declarationOf(node) {
|
|
4
|
+
return node.type === "ExportNamedDeclaration" ? node.declaration : node;
|
|
5
|
+
}
|
|
6
|
+
/** Whether `node` calls `methodName`, either bare (`fn()`) or as a member (`ns.fn()`). */
|
|
7
|
+
function isCallToMethod(node, methodName) {
|
|
8
|
+
if (node.type !== "CallExpression") return false;
|
|
9
|
+
const callee = node.callee;
|
|
10
|
+
if (!callee) return false;
|
|
11
|
+
if (callee.type === "Identifier" && callee.name === methodName) return true;
|
|
12
|
+
return callee.type === "MemberExpression" && callee.property?.type === "Identifier" && callee.property.name === methodName;
|
|
13
|
+
}
|
|
14
|
+
function isAnonymousFunctionOrClass(node) {
|
|
15
|
+
if (node.type === "ArrowFunctionExpression") return true;
|
|
16
|
+
return [
|
|
17
|
+
"FunctionExpression",
|
|
18
|
+
"FunctionDeclaration",
|
|
19
|
+
"ClassExpression",
|
|
20
|
+
"ClassDeclaration"
|
|
21
|
+
].includes(node.type) && !node.id;
|
|
22
|
+
}
|
|
23
|
+
/** `export type { X }` or `export { type X }`, which TypeScript erases. */
|
|
24
|
+
function isTypeOnlyExport(node) {
|
|
25
|
+
return node.exportKind === "type";
|
|
26
|
+
}
|
|
27
|
+
/** The name an export or import specifier refers to, for both `x` and `"x"`. */
|
|
28
|
+
function exportedName(node) {
|
|
29
|
+
if (node?.type === "Identifier") return node.name;
|
|
30
|
+
if (node?.type === "Literal" && typeof node.value === "string") return node.value;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The offset after the hashbang and the directive prologue (`'use server'`),
|
|
34
|
+
* where code may be inserted without changing what the module means.
|
|
35
|
+
*/
|
|
36
|
+
function directivesEnd(ast) {
|
|
37
|
+
let end = ast.hashbang?.end ?? 0;
|
|
38
|
+
for (const node of ast.body) {
|
|
39
|
+
if (node.type !== "ExpressionStatement" || typeof node.directive !== "string") break;
|
|
40
|
+
end = node.end;
|
|
41
|
+
}
|
|
42
|
+
return end;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The binding names a declaration introduces, including names inside
|
|
46
|
+
* destructuring patterns. `undefined` for a declaration that binds no runtime
|
|
47
|
+
* value (`interface`, `type`).
|
|
48
|
+
*/
|
|
49
|
+
function declaredNames(declaration) {
|
|
50
|
+
switch (declaration.type) {
|
|
51
|
+
case "ClassDeclaration":
|
|
52
|
+
case "FunctionDeclaration": {
|
|
53
|
+
const name = declaration.id?.name;
|
|
54
|
+
return name ? [name] : void 0;
|
|
55
|
+
}
|
|
56
|
+
case "VariableDeclaration": {
|
|
57
|
+
const names = [];
|
|
58
|
+
for (const declarator of declaration.declarations ?? []) collectPatternNames(declarator.id, names);
|
|
59
|
+
return names;
|
|
60
|
+
}
|
|
61
|
+
default: return;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function collectPatternNames(pattern, names) {
|
|
65
|
+
if (!pattern) return;
|
|
66
|
+
const node = pattern;
|
|
67
|
+
switch (node.type) {
|
|
68
|
+
case "Identifier":
|
|
69
|
+
if (node.name) names.push(node.name);
|
|
70
|
+
break;
|
|
71
|
+
case "ObjectPattern":
|
|
72
|
+
for (const property of node.properties ?? []) collectPatternNames(property.type === "RestElement" ? property.argument : property.value, names);
|
|
73
|
+
break;
|
|
74
|
+
case "ArrayPattern":
|
|
75
|
+
for (const element of node.elements ?? []) collectPatternNames(element, names);
|
|
76
|
+
break;
|
|
77
|
+
case "AssignmentPattern":
|
|
78
|
+
collectPatternNames(node.left, names);
|
|
79
|
+
break;
|
|
80
|
+
case "RestElement": collectPatternNames(node.argument, names);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/** Visit `node` and every node below it, parents first. */
|
|
84
|
+
function walk(node, visit) {
|
|
85
|
+
if (Array.isArray(node)) {
|
|
86
|
+
for (const child of node) walk(child, visit);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (!node || typeof node !== "object" || typeof node.type !== "string") return;
|
|
90
|
+
visit(node);
|
|
91
|
+
for (const value of Object.values(node)) if (value && typeof value === "object") walk(value, visit);
|
|
92
|
+
}
|
|
93
|
+
exports.declarationOf = declarationOf;
|
|
94
|
+
exports.declaredNames = declaredNames;
|
|
95
|
+
exports.directivesEnd = directivesEnd;
|
|
96
|
+
exports.exportedName = exportedName;
|
|
97
|
+
exports.isAnonymousFunctionOrClass = isAnonymousFunctionOrClass;
|
|
98
|
+
exports.isCallToMethod = isCallToMethod;
|
|
99
|
+
exports.isTypeOnlyExport = isTypeOnlyExport;
|
|
100
|
+
exports.walk = walk;
|
|
101
|
+
|
|
102
|
+
//# sourceMappingURL=ast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast.js","names":[],"sources":["../../../src/rewriter/ast.ts"],"sourcesContent":["// Minimal ESTree node shapes. Any parser that puts `start`/`end` offsets on\n// every node fits (oxc, acorn, Rollup's `this.parse`).\n\nexport interface BaseNode {\n type: string;\n start: number;\n end: number;\n}\n\nexport interface ProgramBody {\n body: BaseNode[];\n hashbang?: BaseNode | null;\n}\n\nexport interface IdentifierNode extends BaseNode {\n name: string;\n}\n\n/** An `Identifier` or, for `export { x as \"name\" }`, a string `Literal`. */\nexport interface NameNode {\n type: string;\n name?: string;\n value?: unknown;\n}\n\nexport interface CallExpressionNode extends BaseNode {\n callee?: { type: string; name?: string; property?: { type: string; name?: string } };\n arguments?: BaseNode[];\n}\n\nexport interface MemberExpressionNode extends BaseNode {\n object?: { type: string; name?: string };\n property?: { type: string; name?: string };\n}\n\nexport interface ClassDeclarationNode extends BaseNode {\n id?: IdentifierNode | null;\n superClass?: BaseNode | null;\n decorators?: BaseNode[] | null;\n}\n\nexport interface ExportDefaultNode extends BaseNode {\n declaration: BaseNode;\n}\n\nexport interface ExportSpecifierNode extends BaseNode {\n local?: NameNode;\n exported?: NameNode;\n exportKind?: string;\n}\n\nexport interface ExportNamedNode extends BaseNode {\n declaration?: BaseNode | null;\n source?: (BaseNode & { value?: unknown }) | null;\n specifiers?: ExportSpecifierNode[];\n exportKind?: string;\n}\n\nexport interface ExportAllNode extends BaseNode {\n source?: { value?: unknown };\n exported?: NameNode | null;\n exportKind?: string;\n}\n\nexport interface VariableDeclaratorNode {\n id?: BaseNode | null;\n init?: BaseNode | null;\n}\n\nexport interface VariableDeclarationNode extends BaseNode {\n declarations?: VariableDeclaratorNode[];\n}\n\nexport interface ImportSpecifierNode {\n type: string;\n imported?: NameNode;\n local?: NameNode;\n importKind?: string;\n}\n\nexport interface ImportDeclarationNode extends BaseNode {\n source?: { value?: unknown };\n specifiers?: ImportSpecifierNode[];\n importKind?: string;\n}\n\nexport interface ArrayExpressionNode extends BaseNode {\n elements?: Array<BaseNode | null>;\n}\n\nexport interface PropertyNode extends BaseNode {\n key?: NameNode;\n value?: BaseNode;\n computed?: boolean;\n}\n\n/** The declaration a top-level statement makes, looking through `export` (`export const x = ...`). */\nexport function declarationOf(node: BaseNode): BaseNode | null | undefined {\n return node.type === 'ExportNamedDeclaration' ? (node as ExportNamedNode).declaration : node;\n}\n\n/** Whether `node` calls `methodName`, either bare (`fn()`) or as a member (`ns.fn()`). */\nexport function isCallToMethod(node: BaseNode, methodName: string): boolean {\n if (node.type !== 'CallExpression') return false;\n const callee = (node as CallExpressionNode).callee;\n if (!callee) return false;\n if (callee.type === 'Identifier' && callee.name === methodName) return true;\n return (\n callee.type === 'MemberExpression' && callee.property?.type === 'Identifier' && callee.property.name === methodName\n );\n}\n\nexport function isAnonymousFunctionOrClass(node: BaseNode): boolean {\n if (node.type === 'ArrowFunctionExpression') return true;\n const isFunctionOrClass = [\n 'FunctionExpression',\n 'FunctionDeclaration',\n 'ClassExpression',\n 'ClassDeclaration',\n ].includes(node.type);\n return isFunctionOrClass && !(node as ClassDeclarationNode).id;\n}\n\n/** `export type { X }` or `export { type X }`, which TypeScript erases. */\nexport function isTypeOnlyExport(node: { exportKind?: string }): boolean {\n return node.exportKind === 'type';\n}\n\n/** The name an export or import specifier refers to, for both `x` and `\"x\"`. */\nexport function exportedName(node: NameNode | undefined): string | undefined {\n if (node?.type === 'Identifier') return node.name;\n if (node?.type === 'Literal' && typeof node.value === 'string') return node.value;\n return undefined;\n}\n\n/**\n * The offset after the hashbang and the directive prologue (`'use server'`),\n * where code may be inserted without changing what the module means.\n */\nexport function directivesEnd(ast: ProgramBody): number {\n let end = ast.hashbang?.end ?? 0;\n for (const node of ast.body) {\n if (node.type !== 'ExpressionStatement' || typeof (node as { directive?: unknown }).directive !== 'string') break;\n end = node.end;\n }\n return end;\n}\n\n/**\n * The binding names a declaration introduces, including names inside\n * destructuring patterns. `undefined` for a declaration that binds no runtime\n * value (`interface`, `type`).\n */\nexport function declaredNames(declaration: BaseNode): string[] | undefined {\n switch (declaration.type) {\n case 'ClassDeclaration':\n case 'FunctionDeclaration': {\n const name = (declaration as ClassDeclarationNode).id?.name;\n return name ? [name] : undefined;\n }\n case 'VariableDeclaration': {\n const names: string[] = [];\n for (const declarator of (declaration as VariableDeclarationNode).declarations ?? []) {\n collectPatternNames(declarator.id, names);\n }\n return names;\n }\n default:\n return undefined;\n }\n}\n\nfunction collectPatternNames(pattern: BaseNode | null | undefined, names: string[]): void {\n if (!pattern) return;\n const node = pattern as BaseNode & {\n name?: string;\n properties?: Array<BaseNode & { value?: BaseNode; argument?: BaseNode }>;\n elements?: Array<BaseNode | null>;\n left?: BaseNode;\n argument?: BaseNode;\n };\n switch (node.type) {\n case 'Identifier':\n if (node.name) names.push(node.name);\n break;\n case 'ObjectPattern':\n for (const property of node.properties ?? []) {\n collectPatternNames(property.type === 'RestElement' ? property.argument : property.value, names);\n }\n break;\n case 'ArrayPattern':\n for (const element of node.elements ?? []) collectPatternNames(element, names);\n break;\n case 'AssignmentPattern':\n collectPatternNames(node.left, names);\n break;\n case 'RestElement':\n collectPatternNames(node.argument, names);\n break;\n }\n}\n\n/** Visit `node` and every node below it, parents first. */\nexport function walk(node: unknown, visit: (node: BaseNode) => void): void {\n if (Array.isArray(node)) {\n for (const child of node) walk(child, visit);\n return;\n }\n if (!node || typeof node !== 'object' || typeof (node as BaseNode).type !== 'string') return;\n\n visit(node as BaseNode);\n for (const value of Object.values(node)) {\n if (value && typeof value === 'object') walk(value, visit);\n }\n}\n"],"mappings":";;AAiGA,SAAgB,cAAc,MAA6C;CACzE,OAAO,KAAK,SAAS,2BAA4B,KAAyB,cAAc;AAC1F;;AAGA,SAAgB,eAAe,MAAgB,YAA6B;CAC1E,IAAI,KAAK,SAAS,kBAAkB,OAAO;CAC3C,MAAM,SAAU,KAA4B;CAC5C,IAAI,CAAC,QAAQ,OAAO;CACpB,IAAI,OAAO,SAAS,gBAAgB,OAAO,SAAS,YAAY,OAAO;CACvE,OACE,OAAO,SAAS,sBAAsB,OAAO,UAAU,SAAS,gBAAgB,OAAO,SAAS,SAAS;AAE7G;AAEA,SAAgB,2BAA2B,MAAyB;CAClE,IAAI,KAAK,SAAS,2BAA2B,OAAO;CAOpD,OAN0B;EACxB;EACA;EACA;EACA;CACF,CAAC,CAAC,SAAS,KAAK,IACO,KAAK,CAAE,KAA8B;AAC9D;;AAGA,SAAgB,iBAAiB,MAAwC;CACvE,OAAO,KAAK,eAAe;AAC7B;;AAGA,SAAgB,aAAa,MAAgD;CAC3E,IAAI,MAAM,SAAS,cAAc,OAAO,KAAK;CAC7C,IAAI,MAAM,SAAS,aAAa,OAAO,KAAK,UAAU,UAAU,OAAO,KAAK;AAE9E;;;;;AAMA,SAAgB,cAAc,KAA0B;CACtD,IAAI,MAAM,IA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AAI,SAAS,OAAO,UAAU,UAAU,KAAK,OAAO,KAAK;AAE7D"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const require_ast = require("./ast.js");
|
|
2
|
+
// src/rewriter/class-extends.ts
|
|
3
|
+
/**
|
|
4
|
+
* Find top-level classes that (transitively, within this module) extend the
|
|
5
|
+
* given base class. A superclass must be a plain identifier (`extends Base`)
|
|
6
|
+
* or member access (`extends ns.Base`).
|
|
7
|
+
*
|
|
8
|
+
* Only same-file base chains are resolvable here; a base class imported from
|
|
9
|
+
* another module under a different name is invisible.
|
|
10
|
+
*/
|
|
11
|
+
function findClassesExtending(ast, base) {
|
|
12
|
+
const bases = collectBaseImports(ast, base);
|
|
13
|
+
if (bases.named.size === 0 && bases.namespaces.size === 0) return /* @__PURE__ */ new Set();
|
|
14
|
+
const classes = /* @__PURE__ */ new Map();
|
|
15
|
+
for (const node of ast.body) {
|
|
16
|
+
const declaration = require_ast.declarationOf(node);
|
|
17
|
+
if (declaration?.type !== "ClassDeclaration") continue;
|
|
18
|
+
const classNode = declaration;
|
|
19
|
+
if (classNode.id?.name) classes.set(classNode.id.name, classNode);
|
|
20
|
+
}
|
|
21
|
+
const found = /* @__PURE__ */ new Set();
|
|
22
|
+
let changed = true;
|
|
23
|
+
while (changed) {
|
|
24
|
+
changed = false;
|
|
25
|
+
for (const [name, classNode] of classes) {
|
|
26
|
+
if (found.has(name)) continue;
|
|
27
|
+
if (extendsBase(classNode.superClass, base, bases, found)) {
|
|
28
|
+
found.add(name);
|
|
29
|
+
changed = true;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return found;
|
|
34
|
+
}
|
|
35
|
+
function collectBaseImports(ast, base) {
|
|
36
|
+
const named = /* @__PURE__ */ new Set();
|
|
37
|
+
const namespaces = /* @__PURE__ */ new Set();
|
|
38
|
+
for (const node of ast.body) {
|
|
39
|
+
if (node.type !== "ImportDeclaration") continue;
|
|
40
|
+
const importNode = node;
|
|
41
|
+
if (importNode.source?.value !== base.module || importNode.importKind === "type") continue;
|
|
42
|
+
for (const specifier of importNode.specifiers ?? []) {
|
|
43
|
+
if (specifier.importKind === "type") continue;
|
|
44
|
+
if (specifier.type === "ImportSpecifier" && specifier.imported?.name === base.name && specifier.local?.name) named.add(specifier.local.name);
|
|
45
|
+
else if (specifier.type === "ImportNamespaceSpecifier" && specifier.local?.name) namespaces.add(specifier.local.name);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
named,
|
|
50
|
+
namespaces
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function extendsBase(superClass, base, bases, detected) {
|
|
54
|
+
if (!superClass) return false;
|
|
55
|
+
if (superClass.type === "Identifier") {
|
|
56
|
+
const name = superClass.name;
|
|
57
|
+
return bases.named.has(name) || detected.has(name);
|
|
58
|
+
}
|
|
59
|
+
if (superClass.type === "MemberExpression") {
|
|
60
|
+
const member = superClass;
|
|
61
|
+
return member.object?.type === "Identifier" && !!member.object.name && bases.namespaces.has(member.object.name) && member.property?.name === base.name;
|
|
62
|
+
}
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
exports.findClassesExtending = findClassesExtending;
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=class-extends.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"class-extends.js","names":["declarationOf"],"sources":["../../../src/rewriter/class-extends.ts"],"sourcesContent":["import type {\n BaseNode,\n ClassDeclarationNode,\n IdentifierNode,\n ImportDeclarationNode,\n MemberExpressionNode,\n ProgramBody,\n} from './ast';\nimport { declarationOf } from './ast';\n\n/** A base class, named by the module it is imported from and its export name. */\nexport interface BaseClassRef {\n module: string;\n name: string;\n}\n\ninterface BaseBindings {\n /** Local identifiers bound to the named import of the base class. */\n named: Set<string>;\n /** Local identifiers bound to a `* as ns` import of the base module. */\n namespaces: Set<string>;\n}\n\n/**\n * Find top-level classes that (transitively, within this module) extend the\n * given base class. A superclass must be a plain identifier (`extends Base`)\n * or member access (`extends ns.Base`).\n *\n * Only same-file base chains are resolvable here; a base class imported from\n * another module under a different name is invisible.\n */\nexport function findClassesExtending(ast: ProgramBody, base: BaseClassRef): Set<string> {\n const bases = collectBaseImports(ast, base);\n if (bases.named.size === 0 && bases.namespaces.size === 0) {\n return new Set<string>();\n }\n\n // Every top-level class, including the `export class Foo {}` form.\n const classes = new Map<string, ClassDeclarationNode>();\n for (const node of ast.body) {\n const declaration = declarationOf(node);\n if (declaration?.type !== 'ClassDeclaration') continue;\n const classNode = declaration as ClassDeclarationNode;\n if (classNode.id?.name) classes.set(classNode.id.name, classNode);\n }\n\n const found = new Set<string>();\n // Iterate to a fixed point so an indirect chain (A extends B extends Base) is\n // fully resolved regardless of declaration order.\n let changed = true;\n while (changed) {\n changed = false;\n for (const [name, classNode] of classes) {\n if (found.has(name)) continue;\n if (extendsBase(classNode.superClass, base, bases, found)) {\n found.add(name);\n changed = true;\n }\n }\n }\n return found;\n}\n\nfunction collectBaseImports(ast: ProgramBody, base: BaseClassRef): BaseBindings {\n const named = new Set<string>();\n const namespaces = new Set<string>();\n for (const node of ast.body) {\n if (node.type !== 'ImportDeclaration') continue;\n const importNode = node as ImportDeclarationNode;\n if (importNode.source?.value !== base.module || importNode.importKind === 'type') continue;\n for (const specifier of importNode.specifiers ?? []) {\n if (specifier.importKind === 'type') continue;\n if (specifier.type === 'ImportSpecifier' && specifier.imported?.name === base.name && specifier.local?.name) {\n named.add(specifier.local.name);\n } else if (specifier.type === 'ImportNamespaceSpecifier' && specifier.local?.name) {\n namespaces.add(specifier.local.name);\n }\n }\n }\n return { named, namespaces };\n}\n\nfunction extendsBase(\n superClass: BaseNode | null | undefined,\n base: BaseClassRef,\n bases: BaseBindings,\n detected: Set<string>,\n): boolean {\n if (!superClass) return false;\n if (superClass.type === 'Identifier') {\n const name = (superClass as IdentifierNode).name;\n return bases.named.has(name) || detected.has(name);\n }\n if (superClass.type === 'MemberExpression') {\n const member = superClass as MemberExpressionNode;\n return (\n member.object?.type === 'Identifier' &&\n !!member.object.name &&\n bases.namespaces.has(member.object.name) &&\n member.property?.name === base.name\n );\n }\n return false;\n}\n"],"mappings":";;;;;;;;;;AA+BA,SAAgB,qBAAqB,KAAkB,MAAiC;CACtF,MAAM,QAAQ,mBAAmB,KAAK,IAAI;CAC1C,IAAI,MAAM,MAAM,SAAS,KAAK,MAAM,WAAW,SAAS,GACtD,uBAAO,IAAI,IAAY;CAIzB,MAAM,0BAAU,IAAI,IAAkC;CACtD,KAAK,MAAM,QAAQ,IAAI,MAAM;EAC3B,MAAM,cAAcA,YAAAA,cAAc,IAAI;EACtC,IAAI,aAAa,SAAS,oBAAoB;EAC9C,MAAM,YAAY;EAClB,IAAI,UAAU,IAAI,MAAM,QAAQ,IAAI,UAAU,GAAG,MAAM,SAAS;CAClE;CAEA,MAAM,wBAAQ,IAAI,IAAY;CAG9B,IAAI,UAAU;CACd,OAAO,SAAS;EACd,UAAU;EACV,KAAK,MAAM,CAAC,MAAM,cAAc,SAAS;GACvC,IAAI,MAAM,IAAI,IAAI,GAAG;GACrB,IAAI,YAAY,UAAU,YAAY,MAAM,OAAO,KAAK,GAAG;IACzD,MAAM,IAAI,IAAI;IACd,UAAU;GACZ;EACF;CACF;CACA,OAAO;AACT;AAEA,SAAS,mBAAmB,KAAkB,MAAkC;CAC9E,MAAM,wBAAQ,IAAI,IAAY;CAC9B,MAAM,6BAAa,IAAI,IAAY;CACnC,KAAK,MAAM,QAAQ,IAAI,MAAM;EAC3B,IAAI,KAAK,SAAS,qBAAqB;EACvC,MAAM,aAAa;EACnB,IAAI,WAAW,QAAQ,UAAU,KAAK,UAAU,WAAW,eAAe,QAAQ;EAClF,KAAK,MAAM,aAAa,WAAW,cAAc,CAAC,GAAG;GACnD,IAAI,UAAU,eAAe,QAAQ;GACrC,IAAI,UAAU,SAAS,qBAAqB,UAAU,UAAU,SAAS,KAAK,QAAQ,UAAU,OAAO,MACrG,MAAM,IAAI,U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