@sentry/bundler-plugins 11.0.0-rc.0 → 11.0.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/{component-annotation-vite-ast.js → component-annotation-oxc-ast.js} +1 -1
- package/build/cjs/core/component-annotation-oxc-ast.js.map +1 -0
- package/build/cjs/core/{component-annotation-vite-fragments.js → component-annotation-oxc-fragments.js} +13 -13
- package/build/cjs/core/component-annotation-oxc-fragments.js.map +1 -0
- package/build/cjs/core/{component-annotation-vite-jsx.js → component-annotation-oxc-jsx.js} +5 -5
- package/build/cjs/core/component-annotation-oxc-jsx.js.map +1 -0
- package/build/cjs/core/{component-annotation-vite-walk.js → component-annotation-oxc-walk.js} +24 -24
- package/build/cjs/core/component-annotation-oxc-walk.js.map +1 -0
- package/build/cjs/core/{component-annotation-vite.js → component-annotation-oxc.js} +27 -11
- package/build/cjs/core/component-annotation-oxc.js.map +1 -0
- package/build/cjs/core/get-code-injection-position.js +87 -0
- package/build/cjs/core/get-code-injection-position.js.map +1 -0
- package/build/cjs/core/index.js +2 -5
- package/build/cjs/core/index.js.map +1 -1
- package/build/cjs/core/sentry/telemetry.js +4 -1
- package/build/cjs/core/sentry/telemetry.js.map +1 -1
- package/build/cjs/core/version.js +1 -1
- package/build/cjs/core/version.js.map +1 -1
- package/build/cjs/esbuild/index.js.map +1 -1
- package/build/cjs/rollup/index.js +15 -15
- package/build/cjs/rollup/index.js.map +1 -1
- package/build/cjs/webpack/index.js +228 -11
- package/build/cjs/webpack/index.js.map +1 -1
- package/build/esm/core/{component-annotation-vite-ast.js → component-annotation-oxc-ast.js} +1 -1
- package/build/esm/core/component-annotation-oxc-ast.js.map +1 -0
- package/build/esm/core/{component-annotation-vite-fragments.js → component-annotation-oxc-fragments.js} +3 -3
- package/build/esm/core/component-annotation-oxc-fragments.js.map +1 -0
- package/build/esm/core/{component-annotation-vite-jsx.js → component-annotation-oxc-jsx.js} +2 -2
- package/build/esm/core/component-annotation-oxc-jsx.js.map +1 -0
- package/build/esm/core/{component-annotation-vite-walk.js → component-annotation-oxc-walk.js} +6 -6
- package/build/esm/core/component-annotation-oxc-walk.js.map +1 -0
- package/build/esm/core/{component-annotation-vite.js → component-annotation-oxc.js} +25 -10
- package/build/esm/core/component-annotation-oxc.js.map +1 -0
- package/build/esm/core/get-code-injection-position.js +85 -0
- package/build/esm/core/get-code-injection-position.js.map +1 -0
- package/build/esm/core/index.js +2 -5
- package/build/esm/core/index.js.map +1 -1
- package/build/esm/core/sentry/telemetry.js +4 -1
- package/build/esm/core/sentry/telemetry.js.map +1 -1
- package/build/esm/core/version.js +1 -1
- package/build/esm/core/version.js.map +1 -1
- package/build/esm/esbuild/index.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/rollup/index.js +16 -16
- package/build/esm/rollup/index.js.map +1 -1
- package/build/esm/webpack/index.js +214 -11
- package/build/esm/webpack/index.js.map +1 -1
- package/build/types/core/{component-annotation-vite-ast.d.ts → component-annotation-oxc-ast.d.ts} +1 -1
- package/build/types/core/component-annotation-oxc-ast.d.ts.map +1 -0
- package/build/types/core/{component-annotation-vite-fragments.d.ts → component-annotation-oxc-fragments.d.ts} +2 -2
- package/build/types/core/component-annotation-oxc-fragments.d.ts.map +1 -0
- package/build/types/core/{component-annotation-vite-jsx.d.ts → component-annotation-oxc-jsx.d.ts} +2 -2
- package/build/types/core/component-annotation-oxc-jsx.d.ts.map +1 -0
- package/build/types/core/component-annotation-oxc-walk.d.ts +3 -0
- package/build/types/core/component-annotation-oxc-walk.d.ts.map +1 -0
- package/build/types/core/component-annotation-oxc.d.ts +7 -0
- package/build/types/core/component-annotation-oxc.d.ts.map +1 -0
- package/build/types/core/get-code-injection-position.d.ts +2 -0
- package/build/types/core/get-code-injection-position.d.ts.map +1 -0
- package/build/types/core/index.d.ts +1 -1
- package/build/types/core/index.d.ts.map +1 -1
- package/build/types/core/sentry/telemetry.d.ts.map +1 -1
- package/build/types/core/version.d.ts +1 -1
- package/build/types/core/version.d.ts.map +1 -1
- package/build/types/esbuild/index.d.ts.map +1 -1
- package/build/types/rollup/index.d.ts +1 -1
- package/build/types/rollup/index.d.ts.map +1 -1
- package/build/types/webpack/index.d.ts +14 -2
- package/build/types/webpack/index.d.ts.map +1 -1
- package/package.json +4 -9
- package/build/cjs/core/component-annotation-vite-ast.js.map +0 -1
- package/build/cjs/core/component-annotation-vite-fragments.js.map +0 -1
- package/build/cjs/core/component-annotation-vite-jsx.js.map +0 -1
- package/build/cjs/core/component-annotation-vite-walk.js.map +0 -1
- package/build/cjs/core/component-annotation-vite.js.map +0 -1
- package/build/cjs/webpack/webpack4and5.js +0 -219
- package/build/cjs/webpack/webpack4and5.js.map +0 -1
- package/build/cjs/webpack/webpack5.js +0 -9
- package/build/cjs/webpack/webpack5.js.map +0 -1
- package/build/esm/core/component-annotation-vite-ast.js.map +0 -1
- package/build/esm/core/component-annotation-vite-fragments.js.map +0 -1
- package/build/esm/core/component-annotation-vite-jsx.js.map +0 -1
- package/build/esm/core/component-annotation-vite-walk.js.map +0 -1
- package/build/esm/core/component-annotation-vite.js.map +0 -1
- package/build/esm/webpack/webpack4and5.js +0 -202
- package/build/esm/webpack/webpack4and5.js.map +0 -1
- package/build/esm/webpack/webpack5.js +0 -7
- package/build/esm/webpack/webpack5.js.map +0 -1
- package/build/types/core/component-annotation-vite-ast.d.ts.map +0 -1
- package/build/types/core/component-annotation-vite-fragments.d.ts.map +0 -1
- package/build/types/core/component-annotation-vite-jsx.d.ts.map +0 -1
- package/build/types/core/component-annotation-vite-walk.d.ts +0 -3
- package/build/types/core/component-annotation-vite-walk.d.ts.map +0 -1
- package/build/types/core/component-annotation-vite.d.ts +0 -6
- package/build/types/core/component-annotation-vite.d.ts.map +0 -1
- package/build/types/webpack/webpack4and5.d.ts +0 -98
- package/build/types/webpack/webpack4and5.d.ts.map +0 -1
- package/build/types/webpack/webpack5.d.ts +0 -4
- package/build/types/webpack/webpack5.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/webpack/index.ts"],"sourcesContent":["import type { SentryWebpackPluginOptions } from './webpack4and5';\nimport { sentryWebpackPluginFactory } from './webpack4and5';\nimport { createRequire } from 'node:module';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype PluginClass = new (options: any) => unknown;\n\ntype WebpackModule = {\n BannerPlugin?: PluginClass;\n DefinePlugin?: PluginClass;\n default?: WebpackModule;\n};\n\n// `webpack` is an optional peer dependency. We require it lazily so the plugin doesn't\n// crash on load in bundlers that don't ship `webpack` (e.g. rspack) — those provide\n// the plugin classes via `compiler.webpack` at runtime instead.\nfunction loadWebpack(): WebpackModule {\n try {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore Rollup transpiles import.meta for CJS\n return createRequire(import.meta.url)('webpack') as WebpackModule;\n } catch {\n return {};\n }\n}\n\nconst webpack = loadWebpack();\nconst BannerPlugin = webpack.BannerPlugin ?? webpack.default?.BannerPlugin;\nconst DefinePlugin = webpack.DefinePlugin ?? webpack.default?.DefinePlugin;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const sentryWebpackPlugin: (options?: SentryWebpackPluginOptions) => any = sentryWebpackPluginFactory({\n BannerPlugin,\n DefinePlugin,\n});\n\nexport type { SentryWebpackPluginOptions };\n"],"names":["createRequire","sentryWebpackPluginFactory"],"mappings":";;;;;;AAgBA,SAAS,WAAA,GAA6B;AACpC,EAAA,IAAI;AAGF,IAAA,OAAOA,yBAAA,CAAc,kQAAe,CAAA,CAAE,SAAS,CAAA;AAAA,EACjD,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,EAAC;AAAA,EACV;AACF;AAEA,MAAM,UAAU,WAAA,EAAY;AAC5B,MAAM,YAAA,GAAe,OAAA,CAAQ,YAAA,IAAgB,OAAA,CAAQ,OAAA,EAAS,YAAA;AAC9D,MAAM,YAAA,GAAe,OAAA,CAAQ,YAAA,IAAgB,OAAA,CAAQ,OAAA,EAAS,YAAA;AAGvD,MAAM,sBAAqEC,uCAAA,CAA2B;AAAA,EAC3G,YAAA;AAAA,EACA;AACF,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/webpack/index.ts"],"sourcesContent":["/* oxlint-disable max-lines */\n\nimport type { Options } from '../core/index';\nimport {\n createSentryBuildPluginManager,\n generateReleaseInjectorCode,\n generateModuleMetadataInjectorCode,\n stringToUUID,\n createComponentNameAnnotateHooks,\n CodeInjection,\n getDebugIdSnippet,\n createDebugIdUploadFunction,\n getCodeInjectionPosition,\n isJsFile,\n stampDebugId,\n} from '../core/index';\nimport * as path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { createRequire } from 'node:module';\nimport { randomUUID } from 'node:crypto';\n\nconst _req = createRequire(import.meta.url);\n\n// Resolve the loader path via the package's own exports.\n// This module may end up in a shared chunk (_chunks/) whose import.meta.url\n// does not point to the webpack/ directory where the transform file lives, so\n// a path-relative lookup would fail. Using require.resolve on the package export\n// always finds the correct installed file regardless of chunk placement.\nlet COMPONENT_ANNOTATION_LOADER: string;\ntry {\n COMPONENT_ANNOTATION_LOADER = _req.resolve('@sentry/bundler-plugins/webpack-loader');\n} catch {\n // Fallback for non-packaged environments (e.g., monorepo source runs without dist)\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore Rollup transpiles import.meta for us for CJS\n const dirname = path.dirname(fileURLToPath(import.meta.url));\n // The Rollup build emits `.js` for both CJS and ESM, so the extension is the same in both.\n COMPONENT_ANNOTATION_LOADER = path.resolve(dirname, 'component-annotation-transform.js');\n}\n\ntype PluginClass = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (options: any): unknown;\n};\n\ntype WebpackSource = {\n source: () => string | Buffer;\n};\n\ntype WebpackRawSource = {\n new (source: string): WebpackSource;\n};\n\ntype WebpackReplaceSource = WebpackSource & {\n insert: (position: number, value: string) => void;\n};\n\nconst WEBPACK_JAVASCRIPT_ASSET_REGEX = /\\.(?:js|ts|jsx|tsx|mjs|cjs|mts|cts)(?:\\?[^?]*)?(?:#[^#]*)?$/;\n\ntype WebpackAsset = {\n name: string;\n source: WebpackSource;\n info: {\n related?: {\n sourceMap?: string | string[];\n };\n };\n};\n\ntype WebpackCompiler = {\n options: {\n plugins?: unknown[];\n mode?: string;\n module?: {\n rules?: unknown[];\n };\n };\n hooks: {\n compilation: {\n tap: (name: string, callback: (compilation: WebpackCompilation) => void) => void;\n };\n thisCompilation: {\n tap: (name: string, callback: (compilation: WebpackCompilation) => void) => void;\n };\n afterEmit: {\n tapAsync: (name: string, callback: (compilation: WebpackCompilation, cb: () => void) => void) => void;\n };\n done: {\n tap: (name: string, callback: () => void) => void;\n };\n };\n webpack?: {\n DefinePlugin?: PluginClass;\n Compilation?: {\n PROCESS_ASSETS_STAGE_ADDITIONS?: number;\n PROCESS_ASSETS_STAGE_DEV_TOOLING?: number;\n };\n sources?: {\n RawSource?: WebpackRawSource;\n ReplaceSource?: new (source: WebpackSource) => WebpackReplaceSource;\n };\n };\n};\n\ntype WebpackCompilation = {\n chunks: Iterable<{\n files: Iterable<string>;\n hash?: string;\n contentHash?: { javascript?: string };\n }>;\n outputOptions: {\n path?: string;\n };\n assets: Record<string, unknown>;\n getAssets: () => WebpackAsset[];\n getAsset: (name: string) => WebpackAsset | undefined;\n updateAsset: (name: string, source: WebpackSource) => void;\n hooks: {\n processAssets: {\n tap: (\n options: { name: string; stage: number },\n callback: (assets: Record<string, WebpackSource>) => void,\n ) => void;\n };\n };\n};\n\ntype WebpackModule = {\n version?: string;\n default?: { version?: string };\n};\n\n// Only used for telemetry; `webpack` is an optional peer dependency and may be absent (e.g. rspack).\nfunction getWebpackMajorVersion(): string | undefined {\n try {\n const webpack = _req('webpack') as WebpackModule;\n const version = webpack.version ?? webpack.default?.version;\n return version?.split('.')[0];\n } catch {\n return undefined;\n }\n}\n\n/**\n * Stamps each JS asset's debug ID into the asset itself and its source map asset.\n *\n * Runs after source maps have been generated, so the JS asset no longer needs to carry\n * source map information and can be replaced with a plain `RawSource`.\n */\nfunction addDebugIdsToAssets(compilation: WebpackCompilation, RawSource: WebpackRawSource): void {\n for (const asset of compilation.getAssets()) {\n if (!isJsFile(asset.name)) {\n continue;\n }\n\n const bundleSource = asset.source.source().toString();\n const relatedSourceMap = asset.info.related?.sourceMap;\n const sourceMapName = typeof relatedSourceMap === 'string' ? relatedSourceMap : `${asset.name}.map`;\n const sourceMapAsset = compilation.getAsset(sourceMapName);\n\n const stamped = stampDebugId(bundleSource, sourceMapAsset?.source.source().toString());\n if (!stamped) {\n continue;\n }\n\n compilation.updateAsset(asset.name, new RawSource(stamped.bundleSource));\n if (stamped.sourceMapSource !== undefined) {\n compilation.updateAsset(sourceMapName, new RawSource(stamped.sourceMapSource));\n }\n }\n}\n\nfunction createSentryWebpackPlugin(userOptions: SentryWebpackPluginOptions = {}) {\n const sentryBuildPluginManager = createSentryBuildPluginManager(userOptions, {\n loggerPrefix: userOptions._metaOptions?.loggerPrefixOverride ?? '[sentry-webpack-plugin]',\n buildTool: 'webpack',\n buildToolMajorVersion: getWebpackMajorVersion(),\n });\n\n const {\n logger,\n normalizedOptions: options,\n bundleSizeOptimizationReplacementValues: replacementValues,\n bundleMetadata,\n createDependencyOnBuildArtifacts,\n } = sentryBuildPluginManager;\n\n if (options.disable) {\n return {\n apply() {\n // noop plugin\n },\n };\n }\n\n if (process.cwd().match(/\\\\node_modules\\\\|\\/node_modules\\//)) {\n logger.warn('Running Sentry plugin from within a `node_modules` folder. Some features may not work.');\n }\n\n const sourcemapsEnabled = options.sourcemaps?.disable !== true;\n const staticInjectionCode = new CodeInjection();\n\n if (!options.release.inject) {\n logger.debug('Release injection disabled via `release.inject` option. Will not inject release.');\n } else if (!options.release.name) {\n logger.debug(\n 'No release name provided. Will not inject release. Please set the `release.name` option to identify your release.',\n );\n } else {\n staticInjectionCode.append(\n generateReleaseInjectorCode({\n release: options.release.name,\n injectBuildInformation: options._experiments.injectBuildInformation || false,\n }),\n );\n }\n\n if (Object.keys(bundleMetadata).length > 0) {\n staticInjectionCode.append(generateModuleMetadataInjectorCode(bundleMetadata));\n }\n\n const transformAnnotations = options.reactComponentAnnotation?.enabled\n ? createComponentNameAnnotateHooks(\n options.reactComponentAnnotation?.ignoredComponents || [],\n !!options.reactComponentAnnotation?._experimentalInjectIntoHtml,\n )\n : undefined;\n\n const transformReplace = Object.keys(replacementValues).length > 0;\n\n function addCodeInjection(compiler: WebpackCompiler): void {\n if (staticInjectionCode.isEmpty() && !sourcemapsEnabled) {\n return;\n }\n\n const ReplaceSource = compiler.webpack?.sources?.ReplaceSource;\n const processAssetsStage = compiler.webpack?.Compilation?.PROCESS_ASSETS_STAGE_ADDITIONS;\n\n if (!ReplaceSource || processAssetsStage === undefined) {\n logger.warn(\n 'Webpack sources are not available. Skipping code injection. This usually means webpack is not properly configured.',\n );\n return;\n }\n\n compiler.hooks.compilation.tap('sentry-webpack-plugin-injection', compilation => {\n compilation.hooks.processAssets.tap(\n {\n name: 'sentry-webpack-plugin-injection',\n stage: processAssetsStage,\n },\n assets => {\n const injectedAssets = new Set<string>();\n\n for (const chunk of compilation.chunks) {\n for (const assetName of chunk.files) {\n if (injectedAssets.has(assetName) || !WEBPACK_JAVASCRIPT_ASSET_REGEX.test(assetName)) {\n continue;\n }\n\n const source = assets[assetName];\n if (!source) {\n continue;\n }\n injectedAssets.add(assetName);\n\n const sourceContents = source.source();\n const code = typeof sourceContents === 'string' ? sourceContents : Buffer.from(sourceContents).toString();\n const codeToInject = staticInjectionCode.clone();\n if (sourcemapsEnabled) {\n const hash = chunk.contentHash?.javascript ?? chunk.hash;\n codeToInject.append(getDebugIdSnippet(hash ? stringToUUID(hash) : randomUUID()));\n }\n\n const injectionPosition = getCodeInjectionPosition(code);\n const injection = injectionPosition === code.length ? `\\n${codeToInject.code()}` : codeToInject.code();\n const updatedSource = new ReplaceSource(source);\n updatedSource.insert(injectionPosition, injection);\n compilation.updateAsset(assetName, updatedSource);\n }\n }\n },\n );\n });\n }\n\n return {\n apply(compiler: WebpackCompiler) {\n void sentryBuildPluginManager.telemetry.emitBundlerPluginExecutionSignal().catch(() => {\n // Telemetry failures are acceptable\n });\n\n const { DefinePlugin } = compiler.webpack ?? {};\n\n // BannerPlugin prepends executable code before directive prologues.\n addCodeInjection(compiler);\n\n // The upload routine (which stamps debug IDs into temp copies of the artifacts) is skipped\n // with `disable-upload`, so the emitted artifacts get stamped in the asset pipeline instead.\n if (sourcemapsEnabled && options.sourcemaps?.disable === 'disable-upload') {\n const RawSource = compiler.webpack?.sources?.RawSource;\n // Right after source map generation (and thus after minification, which would strip the comment),\n // so later stages (real content hashing, subresource integrity) see the final assets.\n const stage = (compiler.webpack?.Compilation?.PROCESS_ASSETS_STAGE_DEV_TOOLING ?? 500) + 1;\n\n if (!RawSource) {\n logger.warn(\n 'Webpack sources are not available. Skipping debug ID injection into emitted source maps. This usually means webpack is not properly configured.',\n );\n } else {\n compiler.hooks.thisCompilation.tap('sentry-webpack-plugin', compilation => {\n compilation.hooks.processAssets.tap({ name: 'sentry-webpack-plugin', stage }, () => {\n addDebugIdsToAssets(compilation, RawSource);\n });\n });\n }\n }\n\n // Add DefinePlugin for bundle size optimizations\n if (transformReplace && DefinePlugin) {\n compiler.options.plugins = compiler.options.plugins || [];\n compiler.options.plugins.push(new DefinePlugin(replacementValues));\n }\n\n // Add component name annotation transform\n if (transformAnnotations?.transform) {\n compiler.options.module = compiler.options.module || {};\n compiler.options.module.rules = compiler.options.module.rules || [];\n compiler.options.module.rules.unshift({\n test: /\\.[jt]sx$/,\n exclude: /node_modules/,\n enforce: 'pre',\n use: [\n {\n loader: COMPONENT_ANNOTATION_LOADER,\n options: {\n transform: transformAnnotations.transform,\n },\n },\n ],\n });\n }\n\n compiler.hooks.afterEmit.tapAsync(\n 'sentry-webpack-plugin',\n (compilation: WebpackCompilation, callback: (err?: Error) => void) => {\n const freeGlobalDependencyOnBuildArtifacts = createDependencyOnBuildArtifacts();\n const upload = createDebugIdUploadFunction({ sentryBuildPluginManager });\n\n const run = async (): Promise<void> => {\n try {\n await sentryBuildPluginManager.createRelease();\n if (sourcemapsEnabled && options.sourcemaps?.disable !== 'disable-upload') {\n const outputPath = compilation.outputOptions.path ?? path.resolve();\n const buildArtifacts = Object.keys(compilation.assets).map(asset => path.join(outputPath, asset));\n await upload(buildArtifacts);\n }\n } finally {\n freeGlobalDependencyOnBuildArtifacts();\n await sentryBuildPluginManager.deleteArtifacts();\n }\n };\n\n run().then(\n () => callback(),\n (err: Error) => callback(err),\n );\n },\n );\n\n if (userOptions._experiments?.forceExitOnBuildCompletion && compiler.options.mode === 'production') {\n compiler.hooks.done.tap('sentry-webpack-plugin', () => {\n setTimeout(() => {\n logger.debug('Exiting process after debug file upload');\n process.exit(0);\n });\n });\n }\n },\n };\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const sentryWebpackPlugin: (options?: SentryWebpackPluginOptions) => any = createSentryWebpackPlugin;\n\nexport type SentryWebpackPluginOptions = Options & {\n _experiments?: Options['_experiments'] & {\n /**\n * If enabled, the webpack plugin will exit the build process after the build completes.\n * Use this with caution, as it will terminate the process.\n *\n * More information: https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/345\n *\n * @default false\n */\n forceExitOnBuildCompletion?: boolean;\n };\n};\n"],"names":["createRequire","path","fileURLToPath","isJsFile","stampDebugId","createSentryBuildPluginManager","CodeInjection","generateReleaseInjectorCode","generateModuleMetadataInjectorCode","createComponentNameAnnotateHooks","getDebugIdSnippet","stringToUUID","randomUUID","getCodeInjectionPosition","createDebugIdUploadFunction"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,MAAM,IAAA,GAAOA,yBAAA,CAAc,kQAAe,CAAA;AAO1C,IAAI,2BAAA;AACJ,IAAI;AACF,EAAA,2BAAA,GAA8B,IAAA,CAAK,QAAQ,wCAAwC,CAAA;AACrF,CAAA,CAAA,MAAQ;AAIN,EAAA,MA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aAAA,CAAc,IAAA,IAAQb,gBAAK,OAAA,EAAQ;AAClE,gBAAA,MAAM,cAAA,GAAiB,MAAA,CAAO,IAAA,CAAK,WAAA,CAAY,MAAM,CAAA,CAAE,GAAA,CAAI,CAAA,KAAA,KAASA,eAAA,CAAK,IAAA,CAAK,UAAA,EAAY,KAAK,CAAC,CAAA;AAChG,gBAAA,MAAM,OAAO,cAAc,CAAA;AAAA,cAC7B;AAAA,YACF,CAAA,SAAE;AACA,cAAA,oCAAA,EAAqC;AACrC,cAAA,MAAM,yBAAyB,eAAA,EAAgB;AAAA,YACjD;AAAA,UACF,CAAA;AAEA,UAAA,GAAA,EAAI,CAAE,IAAA;AAAA,YACJ,MAAM,QAAA,EAAS;AAAA,YACf,CAAC,GAAA,KAAe,QAAA,CAAS,GAAG;AAAA,WAC9B;AAAA,QACF;AAAA,OACF;AAEA,MAAA,IAAI,YAAY,YAAA,EAAc,0BAAA,IAA8B,QAAA,CAAS,OAAA,CAAQ,SAAS,YAAA,EAAc;AAClG,QAAA,QAAA,CAAS,KAAA,CAAM,IAAA,CAAK,GAAA,CAAI,uBAAA,EAAyB,MAAM;AACrD,UAAA,UAAA,CAAW,MAAM;AACf,YAAA,MAAA,CAAO,MAAM,yCAAyC,CAAA;AACtD,YAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,UAChB,CAAC,CAAA;AAAA,QACH,CAAC,CAAA;AAAA,MACH;AAAA,IACF;AAAA,GACF;AACF;AAGO,MAAM,mBAAA,GAAqE;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-annotation-oxc-ast.js","sources":["../../../src/core/component-annotation-oxc-ast.ts"],"sourcesContent":["import { isObjectLike } from '@sentry/core';\nimport type { SourceMap } from 'magic-string';\n\nimport type { ComponentAnnotationAttribute } from '../babel-plugin/component-annotation';\n\nexport { isObjectLike };\n\nexport type AstNode = {\n type: string;\n start?: number;\n end?: number;\n [key: string]: unknown;\n};\n\nexport type JSXElementNode = AstNode & {\n type: 'JSXElement';\n openingElement: JSXOpeningElementNode;\n children?: AstNode[];\n};\n\nexport type JSXFragmentNode = AstNode & {\n type: 'JSXFragment';\n children?: AstNode[];\n};\n\nexport type JSXRootNode = JSXElementNode | JSXFragmentNode;\n\nexport type JSXOpeningElementNode = AstNode & {\n type: 'JSXOpeningElement';\n name: AstNode;\n attributes?: AstNode[];\n selfClosing?: boolean;\n};\n\nexport type FragmentContext = {\n fragmentAliases: Set<string>;\n reactNamespaceAliases: Set<string>;\n};\n\nexport type AttributeInsertion = {\n offset: number;\n attributes: ComponentAnnotationAttribute[];\n};\n\nexport type ParseAstAsync = (code: string, options: { lang: 'jsx' | 'tsx' }) => Promise<unknown>;\n\nexport type MagicStringLike = {\n appendLeft(offset: number, content: string): void;\n toString(): string;\n generateMap?(options: {\n file?: string;\n source?: string;\n includeContent?: boolean;\n hires?: boolean | 'boundary';\n }): SourceMap | string;\n};\n\nexport type ComponentAnnotationTransformMeta = {\n magicString?: MagicStringLike;\n};\n\nexport type ComponentAnnotationTransformResult =\n | {\n code: string;\n map?: SourceMap | string;\n }\n | null\n | undefined;\n\nexport function isAstNode(value: unknown): value is AstNode {\n return isObjectLike(value) && typeof value.type === 'string';\n}\n\nexport function walkAst(node: unknown, visit: (node: AstNode) => void): void {\n if (!isAstNode(node)) {\n return;\n }\n\n visit(node);\n\n for (const value of Object.values(node)) {\n if (Array.isArray(value)) {\n for (const child of value) {\n walkAst(child, visit);\n }\n } else if (isAstNode(value)) {\n walkAst(value, visit);\n }\n }\n}\n"],"names":[],"mappings":";;;AAqEO,SAAS,UAAU,KAAA,EAAkC;AAC1D,EAAA,OAAO,YAAA,CAAa,KAAK,CAAA,IAAK,OAAO,MAAM,IAAA,KAAS,QAAA;AACtD;AAEO,SAAS,OAAA,CAAQ,MAAe,KAAA,EAAsC;AAC3E,EAAA,IAAI,CAAC,SAAA,CAAU,IAAI,CAAA,EAAG;AACpB,IAAA;AAAA,EACF;AAEA,EAAA,KAAA,CAAM,IAAI,CAAA;AAEV,EAAA,KAAA,MAAW,KAAA,IAAS,MAAA,CAAO,MAAA,CAAO,IAAI,CAAA,EAAG;AACvC,IAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AACxB,MAAA,KAAA,MAAW,SAAS,KAAA,EAAO;AACzB,QAAA,OAAA,CAAQ,OAAO,KAAK,CAAA;AAAA,MACtB;AAAA,IACF,CAAA,MAAA,IAAW,SAAA,CAAU,KAAK,CAAA,EAAG;AAC3B,MAAA,OAAA,CAAQ,OAAO,KAAK,CAAA;AAAA,IACtB;AAAA,EACF;AACF;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { walkAst, isAstNode } from './component-annotation-
|
|
2
|
-
import { getStringName } from './component-annotation-
|
|
1
|
+
import { walkAst, isAstNode } from './component-annotation-oxc-ast.js';
|
|
2
|
+
import { getStringName } from './component-annotation-oxc-jsx.js';
|
|
3
3
|
import { isObjectLike } from '@sentry/core';
|
|
4
4
|
|
|
5
5
|
function collectFragmentContext(ast) {
|
|
@@ -86,4 +86,4 @@ function isFragmentObjectPatternProperty(property) {
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
export { collectFragmentContext };
|
|
89
|
-
//# sourceMappingURL=component-annotation-
|
|
89
|
+
//# sourceMappingURL=component-annotation-oxc-fragments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-annotation-oxc-fragments.js","sources":["../../../src/core/component-annotation-oxc-fragments.ts"],"sourcesContent":["import type { AstNode, FragmentContext } from './component-annotation-oxc-ast';\nimport { isAstNode, isObjectLike, walkAst } from './component-annotation-oxc-ast';\nimport { getStringName } from './component-annotation-oxc-jsx';\n\nexport function collectFragmentContext(ast: AstNode): FragmentContext {\n const context: FragmentContext = {\n fragmentAliases: new Set<string>(),\n reactNamespaceAliases: new Set<string>(['React']),\n };\n\n walkAst(ast, node => {\n collectFragmentAliasesFromImport(node, context);\n collectFragmentAliasesFromVariableDeclarator(node, context);\n });\n\n return context;\n}\n\nfunction collectFragmentAliasesFromImport(node: AstNode, context: FragmentContext): void {\n if (node.type !== 'ImportDeclaration' || !isObjectLike(node.source)) {\n return;\n }\n\n const source = node.source.value;\n if (source !== 'react' && source !== 'React') {\n return;\n }\n\n const specifiers = Array.isArray(node.specifiers) ? node.specifiers : [];\n\n for (const specifier of specifiers) {\n if (!isAstNode(specifier) || !isObjectLike(specifier.local)) {\n continue;\n }\n\n const localName = getStringName(specifier.local);\n if (!localName) {\n continue;\n }\n\n if (specifier.type === 'ImportDefaultSpecifier' || specifier.type === 'ImportNamespaceSpecifier') {\n context.reactNamespaceAliases.add(localName);\n } else if (isImportedReactFragment(specifier)) {\n context.fragmentAliases.add(localName);\n }\n }\n}\n\nfunction collectFragmentAliasesFromVariableDeclarator(node: AstNode, context: FragmentContext): void {\n if (node.type !== 'VariableDeclarator' || !isObjectLike(node.id) || !isObjectLike(node.init)) {\n return;\n }\n\n if (node.id.type === 'Identifier') {\n collectFragmentAliasFromIdentifier(node.id, node.init, context);\n return;\n }\n\n if (node.id.type === 'ObjectPattern') {\n collectFragmentAliasFromObjectPattern(node.id, node.init, context);\n }\n}\n\nfunction collectFragmentAliasFromIdentifier(\n id: Record<string, unknown>,\n init: Record<string, unknown>,\n context: FragmentContext,\n): void {\n const localName = getStringName(id);\n if (!localName) {\n return;\n }\n\n if (init.type === 'Identifier' && context.fragmentAliases.has(getStringName(init) ?? '')) {\n context.fragmentAliases.add(localName);\n }\n\n if (isReactFragmentMemberExpression(init, context)) {\n context.fragmentAliases.add(localName);\n }\n}\n\nfunction collectFragmentAliasFromObjectPattern(\n id: Record<string, unknown>,\n init: Record<string, unknown>,\n context: FragmentContext,\n): void {\n if (\n init.type !== 'Identifier' ||\n !context.reactNamespaceAliases.has(getStringName(init) ?? '') ||\n !Array.isArray(id.properties)\n ) {\n return;\n }\n\n for (const property of id.properties) {\n if (!isFragmentObjectPatternProperty(property)) {\n continue;\n }\n\n const localName = getStringName(property.value);\n if (localName) {\n context.fragmentAliases.add(localName);\n }\n }\n}\n\nfunction isImportedReactFragment(specifier: AstNode): boolean {\n return (\n specifier.type === 'ImportSpecifier' &&\n isObjectLike(specifier.imported) &&\n getStringName(specifier.imported) === 'Fragment'\n );\n}\n\nfunction isReactFragmentMemberExpression(init: Record<string, unknown>, context: FragmentContext): boolean {\n return (\n init.type === 'MemberExpression' &&\n isObjectLike(init.object) &&\n isObjectLike(init.property) &&\n context.reactNamespaceAliases.has(getStringName(init.object) ?? '') &&\n getStringName(init.property) === 'Fragment'\n );\n}\n\nfunction isFragmentObjectPatternProperty(property: unknown): property is { value: unknown } {\n return (\n isObjectLike(property) &&\n (property.type === 'Property' || property.type === 'ObjectProperty') &&\n isObjectLike(property.key) &&\n getStringName(property.key) === 'Fragment' &&\n isObjectLike(property.value)\n );\n}\n"],"names":[],"mappings":";;;;AAIO,SAAS,uBAAuB,GAAA,EAA+B;AACpE,EAAA,MAAM,OAAA,GAA2B;AAAA,IAC/B,eAAA,sBAAqB,GAAA,EAAY;AAAA,IACjC,qBAAA,kBAAuB,IAAI,GAAA,CAAY,CAAC,OAAO,CAAC;AAAA,GAClD;AAEA,EAAA,OAAA,CAAQ,KAAK,CAAA,IAAA,KAAQ;AACnB,IAAA,gCAAA,CAAiC,MAAM,OAAO,CAAA;AAC9C,IAAA,4CAAA,CAA6C,MAAM,OAAO,CAAA;AAAA,EAC5D,CAAC,CAAA;AAED,EAAA,OAAO,OAAA;AACT;AAEA,SAAS,gCAAA,CAAiC,MAAe,OAAA,EAAgC;AACvF,EAAA,IAAI,KAAK,IAAA,KAAS,mBAAA,IAAuB,CAAC,YAAA,CAAa,IAAA,CAAK,MAAM,CAAA,EAAG;AACnE,IAAA;AAAA,EACF;AAEA,EAAA,MAAM,MAAA,GAAS,KAAK,MAAA,CAAO,KAAA;AAC3B,EAAA,IAAI,MAAA,KAAW,OAAA,IAAW,MAAA,KAAW,OAAA,EAAS;AAC5C,IAAA;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AAU,QAAQ,CAAA,IAC/B,aAAA,CAAc,SAAA,CAAU,QAAQ,CAAA,KAAM,UAAA;AAE1C;AAEA,SAAS,+BAAA,CAAgC,MAA+B,OAAA,EAAmC;AACzG,EAAA,OACE,IAAA,CAAK,SAAS,kBAAA,IACd,YAAA,CAAa,KAAK,MAAM,CAAA,IACxB,YAAA,CAAa,IAAA,CAAK,QAAQ,CAAA,IAC1B,QAAQ,qBAAA,CAAsB,GAAA,CAAI,aAAA,CAAc,IAAA,CAAK,MAAM,CAAA,IAAK,EAAE,CAAA,IAClE,aAAA,CAAc,IAAA,CAAK,QAAQ,CAAA,KAAM,UAAA;AAErC;AAEA,SAAS,gCAAgC,QAAA,EAAmD;AAC1F,EAAA,OACE,YAAA,CAAa,QAAQ,CAAA,KACpB,QAAA,CAAS,SAAS,UAAA,IAAc,QAAA,CAAS,SAAS,gBAAA,CAAA,IACnD,YAAA,CAAa,SAAS,GAAG,CAAA,IACzB,cAAc,QAAA,CAAS,GAAG,MAAM,UAAA,IAChC,YAAA,CAAa,SAAS,KAAK,CAAA;AAE/B;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getComponentAnnotationAttributes, WEB_COMPONENT_NAME, WEB_ELEMENT_NAME, WEB_SOURCE_FILE_NAME } from '../babel-plugin/component-annotation.js';
|
|
2
|
-
import { isAstNode } from './component-annotation-
|
|
2
|
+
import { isAstNode } from './component-annotation-oxc-ast.js';
|
|
3
3
|
import { isObjectLike } from '@sentry/core';
|
|
4
4
|
|
|
5
5
|
const UNKNOWN_ELEMENT_NAME = "unknown";
|
|
@@ -127,4 +127,4 @@ function getOrderedAttributes(attributeValues) {
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
export { addPendingAttributes, getInsertionOffset, getJSXName, getStringName, isJSXElement, isJSXFragment, isJSXRoot, isReactFragment, toAttributeInsertions };
|
|
130
|
-
//# sourceMappingURL=component-annotation-
|
|
130
|
+
//# sourceMappingURL=component-annotation-oxc-jsx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-annotation-oxc-jsx.js","sources":["../../../src/core/component-annotation-oxc-jsx.ts"],"sourcesContent":["import {\n getComponentAnnotationAttributes,\n WEB_COMPONENT_NAME,\n WEB_ELEMENT_NAME,\n WEB_SOURCE_FILE_NAME,\n} from '../babel-plugin/component-annotation';\nimport type { ComponentAnnotationAttribute } from '../babel-plugin/component-annotation';\nimport type {\n AttributeInsertion,\n FragmentContext,\n JSXElementNode,\n JSXFragmentNode,\n JSXOpeningElementNode,\n JSXRootNode,\n} from './component-annotation-oxc-ast';\nimport { isAstNode, isObjectLike } from './component-annotation-oxc-ast';\n\nconst UNKNOWN_ELEMENT_NAME = 'unknown';\nconst WEB_ATTRIBUTE_NAMES = [WEB_ELEMENT_NAME, WEB_COMPONENT_NAME, WEB_SOURCE_FILE_NAME] as const;\nconst WEB_ATTRIBUTE_NAME_SET = new Set<string>(WEB_ATTRIBUTE_NAMES);\n\ntype PendingInsertion = {\n offset: number;\n attributeValues: Map<string, string>;\n};\n\nexport function isJSXElement(value: unknown): value is JSXElementNode {\n return isAstNode(value) && value.type === 'JSXElement';\n}\n\nexport function isJSXFragment(value: unknown): value is JSXFragmentNode {\n return isAstNode(value) && value.type === 'JSXFragment';\n}\n\nexport function isJSXRoot(value: unknown): value is JSXRootNode {\n return isJSXElement(value) || isJSXFragment(value);\n}\n\nexport function getStringName(node: unknown): string | null {\n return isObjectLike(node) && typeof node.name === 'string' ? node.name : null;\n}\n\nexport function getJSXName(name: unknown): string {\n if (!isAstNode(name)) {\n return UNKNOWN_ELEMENT_NAME;\n }\n\n if (name.type === 'JSXIdentifier') {\n return getStringName(name) ?? UNKNOWN_ELEMENT_NAME;\n }\n\n if (name.type === 'JSXNamespacedName') {\n return getStringName(name.name) ?? UNKNOWN_ELEMENT_NAME;\n }\n\n if (name.type === 'JSXMemberExpression') {\n const objectName = getJSXName(name.object);\n const propertyName = getJSXName(name.property);\n\n return `${objectName}.${propertyName}`;\n }\n\n return UNKNOWN_ELEMENT_NAME;\n}\n\nexport function getInsertionOffset(code: string, openingElement: JSXOpeningElementNode): number | null {\n if (typeof openingElement.end !== 'number') {\n return null;\n }\n\n if (!openingElement.selfClosing) {\n return openingElement.end - 1;\n }\n\n let offset = openingElement.end - 2;\n\n while (offset > 0 && /\\s/.test(code[offset] ?? '')) {\n offset -= 1;\n }\n\n return code[offset] === '/' ? offset : openingElement.end - 1;\n}\n\nexport function isReactFragment(openingElement: JSXOpeningElementNode, fragmentContext: FragmentContext): boolean {\n const elementName = getJSXName(openingElement.name);\n\n if (elementName === 'Fragment' || elementName === 'React.Fragment') {\n return true;\n }\n\n if (fragmentContext.fragmentAliases.has(elementName)) {\n return true;\n }\n\n if (isObjectLike(openingElement.name) && openingElement.name.type === 'JSXMemberExpression') {\n const objectName = getJSXName(openingElement.name.object);\n const propertyName = getJSXName(openingElement.name.property);\n\n return (\n propertyName === 'Fragment' &&\n (fragmentContext.reactNamespaceAliases.has(objectName) || fragmentContext.fragmentAliases.has(objectName))\n );\n }\n\n return false;\n}\n\nexport function addPendingAttributes(\n code: string,\n openingElement: JSXOpeningElementNode,\n componentName: string,\n ignoredComponents: string[],\n fragmentContext: FragmentContext,\n sourceFileName: string,\n insertionsByOffset: Map<number, PendingInsertion>,\n): void {\n const offset = getInsertionOffset(code, openingElement);\n if (offset === null) {\n return;\n }\n\n const pendingInsertion = insertionsByOffset.get(offset);\n const existingAttributes = getExistingAttributeNames(openingElement);\n\n for (const attributeName of pendingInsertion?.attributeValues.keys() ?? []) {\n existingAttributes.add(attributeName);\n }\n\n const attributes = getComponentAnnotationAttributes({\n attributeNames: [WEB_COMPONENT_NAME, WEB_ELEMENT_NAME, WEB_SOURCE_FILE_NAME],\n componentName,\n elementName: getJSXName(openingElement.name),\n existingAttributes,\n ignoredComponents,\n isFragment: isReactFragment(openingElement, fragmentContext),\n sourceFileName,\n });\n\n if (attributes.length === 0) {\n return;\n }\n\n const insertion =\n pendingInsertion ??\n insertionsByOffset\n .set(offset, {\n offset,\n attributeValues: new Map(),\n })\n .get(offset);\n\n for (const [name, value] of attributes) {\n insertion?.attributeValues.set(name, value);\n }\n}\n\nexport function toAttributeInsertions(insertionsByOffset: Map<number, PendingInsertion>): AttributeInsertion[] {\n return [...insertionsByOffset.values()].map(({ offset, attributeValues }) => ({\n offset,\n attributes: getOrderedAttributes(attributeValues),\n }));\n}\n\nfunction getExistingAttributeNames(openingElement: JSXOpeningElementNode): Set<string> {\n const names = new Set<string>();\n\n for (const attribute of openingElement.attributes ?? []) {\n if (attribute.type === 'JSXAttribute') {\n const name = getStringName(attribute.name);\n if (name) {\n names.add(name);\n }\n }\n }\n\n return names;\n}\n\nfunction getOrderedAttributes(attributeValues: ReadonlyMap<string, string>): ComponentAnnotationAttribute[] {\n const attributes: ComponentAnnotationAttribute[] = [];\n\n for (const name of WEB_ATTRIBUTE_NAMES) {\n const value = attributeValues.get(name);\n if (value) {\n attributes.push([name, value]);\n }\n }\n\n for (const [name, value] of attributeValues) {\n if (!WEB_ATTRIBUTE_NAME_SET.has(name)) {\n attributes.push([name, value]);\n }\n }\n\n return attributes;\n}\n"],"names":[],"mappings":";;;;AAiBA,MAAM,oBAAA,GAAuB,SAAA;AAC7B,MAAM,mBAAA,GAAsB,CAAC,gBAAA,EAAkB,kBAAA,EAAoB,oBAAoB,CAAA;AACvF,MAAM,sBAAA,GAAyB,IAAI,GAAA,CAAY,mBAAmB,CAAA;AAO3D,SAAS,aAAa,KAAA,EAAyC;AACpE,EAAA,OAAO,SAAA,CAAU,KAAK,CAAA,IAAK,KAAA,CAAM,IAAA,KAAS,YAAA;AAC5C;AAEO,SAAS,cAAc,KAAA,EAA0C;AACtE,EAAA,OAAO,SAAA,CAAU,KAAK,CAAA,IAAK,KAAA,CAAM,IAAA,KAAS,aAAA;AAC5C;AAEO,SAAS,UAAU,KAAA,EAAsC;AAC9D,EAAA,OAAO,YAAA,CAAa,KAAK,CAAA,IAAK,aAAA,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AY;AAE9B,EAAA,KAAA,MAAW,SAAA,IAAa,cAAA,CAAe,UAAA,IAAc,EAAC,EAAG;AACvD,IAAA,IAAI,SAAA,CAAU,SAAS,cAAA,EAAgB;AACrC,MAAA,MAAM,IAAA,GAAO,aAAA,CAAc,SAAA,CAAU,IAAI,CAAA;AACzC,MAAA,IAAI,IAAA,EAAM;AACR,QAAA,KAAA,CAAM,IAAI,IAAI,CAAA;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AAEA,EAAA,OAAO,KAAA;AACT;AAEA,SAAS,qBAAqB,eAAA,EAA8E;AAC1G,EAAA,MAAM,aAA6C,EAAC;AAEpD,EAAA,KAAA,MAAW,QAAQ,mBAAA,EAAqB;AACtC,IAAA,MAAM,KAAA,GAAQ,eAAA,CAAgB,GAAA,CAAI,IAAI,CAAA;AACtC,IAAA,IAAI,KAAA,EAAO;AACT,MAAA,UAAA,CAAW,IAAA,CAAK,CAAC,IAAA,EAAM,KAAK,CAAC,CAAA;AAAA,IAC/B;AAAA,EACF;AAEA,EAAA,KAAA,MAAW,CAAC,IAAA,EAAM,KAAK,CAAA,IAAK,eAAA,EAAiB;AAC3C,IAAA,IAAI,CAAC,sBAAA,CAAuB,GAAA,CAAI,IAAI,CAAA,EAAG;AACrC,MAAA,UAAA,CAAW,IAAA,CAAK,CAAC,IAAA,EAAM,KAAK,CAAC,CAAA;AAAA,IAC/B;AAAA,EACF;AAEA,EAAA,OAAO,UAAA;AACT;;;;"}
|
package/build/esm/core/{component-annotation-vite-walk.js → component-annotation-oxc-walk.js}
RENAMED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { toAttributeInsertions, isJSXElement, addPendingAttributes, isJSXRoot, getStringName } from './component-annotation-
|
|
2
|
-
import { walkAst, isAstNode } from './component-annotation-
|
|
3
|
-
import { collectFragmentContext } from './component-annotation-
|
|
1
|
+
import { toAttributeInsertions, isJSXElement, addPendingAttributes, isJSXRoot, getStringName } from './component-annotation-oxc-jsx.js';
|
|
2
|
+
import { walkAst, isAstNode } from './component-annotation-oxc-ast.js';
|
|
3
|
+
import { collectFragmentContext } from './component-annotation-oxc-fragments.js';
|
|
4
4
|
import { isObjectLike } from '@sentry/core';
|
|
5
5
|
|
|
6
|
-
function
|
|
6
|
+
function collectOxcComponentAnnotationInsertions(code, ast, ignoredComponents, sourceFileName) {
|
|
7
7
|
const fragmentContext = collectFragmentContext(ast);
|
|
8
8
|
const components = collectComponentJSXRoots(ast);
|
|
9
9
|
const insertionsByOffset = /* @__PURE__ */ new Map();
|
|
@@ -115,5 +115,5 @@ function processJSX(code, node, componentName, ignoredComponents, fragmentContex
|
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
export {
|
|
119
|
-
//# sourceMappingURL=component-annotation-
|
|
118
|
+
export { collectOxcComponentAnnotationInsertions };
|
|
119
|
+
//# sourceMappingURL=component-annotation-oxc-walk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-annotation-oxc-walk.js","sources":["../../../src/core/component-annotation-oxc-walk.ts"],"sourcesContent":["import type { AstNode, AttributeInsertion, FragmentContext, JSXRootNode } from './component-annotation-oxc-ast';\nimport {\n addPendingAttributes,\n getStringName,\n isJSXElement,\n isJSXRoot,\n toAttributeInsertions,\n} from './component-annotation-oxc-jsx';\nimport { isAstNode, isObjectLike, walkAst } from './component-annotation-oxc-ast';\nimport { collectFragmentContext } from './component-annotation-oxc-fragments';\n\ntype ComponentJSXRoots = { name: string; roots: JSXRootNode[] };\n\nexport function collectOxcComponentAnnotationInsertions(\n code: string,\n ast: AstNode,\n ignoredComponents: string[],\n sourceFileName: string,\n): AttributeInsertion[] {\n const fragmentContext = collectFragmentContext(ast);\n const components = collectComponentJSXRoots(ast);\n const insertionsByOffset = new Map<number, { offset: number; attributeValues: Map<string, string> }>();\n\n for (const component of components) {\n for (const root of component.roots) {\n processJSX(code, root, component.name, ignoredComponents, fragmentContext, sourceFileName, insertionsByOffset);\n }\n }\n\n return toAttributeInsertions(insertionsByOffset);\n}\n\nfunction getJSXRootsFromReturnArgument(argument: unknown): JSXRootNode[] {\n if (isJSXRoot(argument)) {\n return [argument];\n }\n\n if (isObjectLike(argument) && argument.type === 'ConditionalExpression') {\n return [argument.consequent, argument.alternate].filter(isJSXRoot);\n }\n\n return [];\n}\n\nfunction getReturnedJSXFromFunction(functionNode: AstNode): JSXRootNode[] {\n const body = functionNode.body;\n\n if (isJSXRoot(body)) {\n return [body];\n }\n\n if (!isObjectLike(body) || body.type !== 'BlockStatement') {\n return [];\n }\n\n const bodyStatements = Array.isArray(body.body) ? body.body : [];\n const returnStatement = bodyStatements.find(statement => {\n return isAstNode(statement) && statement.type === 'ReturnStatement';\n });\n\n return isObjectLike(returnStatement) ? getJSXRootsFromReturnArgument(returnStatement.argument) : [];\n}\n\nfunction pushFunctionComponent(components: ComponentJSXRoots[], nameNode: unknown, functionNode: AstNode): void {\n const name = getStringName(nameNode);\n\n if (name) {\n components.push({\n name,\n roots: getReturnedJSXFromFunction(functionNode),\n });\n }\n}\n\nfunction collectComponentJSXRoots(ast: AstNode): ComponentJSXRoots[] {\n const components: ComponentJSXRoots[] = [];\n\n walkAst(ast, node => {\n if (node.type === 'FunctionDeclaration' && isObjectLike(node.id)) {\n pushFunctionComponent(components, node.id, node);\n return;\n }\n\n if (node.type === 'VariableDeclarator' && isObjectLike(node.id)) {\n if (isAstNode(node.init) && node.init.type === 'ArrowFunctionExpression') {\n pushFunctionComponent(components, node.id, node.init);\n }\n\n return;\n }\n\n if (node.type === 'ClassDeclaration') {\n pushClassComponent(components, node);\n }\n });\n\n return components;\n}\n\nfunction pushClassComponent(components: ComponentJSXRoots[], node: AstNode): void {\n const renderMethodBody = getClassRenderMethodBody(node);\n\n if (!renderMethodBody) {\n return;\n }\n\n const roots: JSXRootNode[] = [];\n\n walkAst(renderMethodBody, child => {\n if (child.type === 'ReturnStatement' && isJSXRoot(child.argument)) {\n roots.push(child.argument);\n }\n });\n\n components.push({\n name: getStringName(node.id) ?? '',\n roots,\n });\n}\n\nfunction getClassRenderMethodBody(node: AstNode): AstNode | null {\n if (!isObjectLike(node.body) || !Array.isArray(node.body.body)) {\n return null;\n }\n\n const renderMethod = node.body.body.find(member => {\n return (\n isObjectLike(member) &&\n isObjectLike(member.key) &&\n getStringName(member.key) === 'render' &&\n (isObjectLike(member.value) || isObjectLike(member.body))\n );\n });\n\n if (!isObjectLike(renderMethod)) {\n return null;\n }\n\n if (isAstNode(renderMethod.value)) {\n return renderMethod.value;\n }\n\n return isAstNode(renderMethod) ? renderMethod : null;\n}\n\nfunction processJSX(\n code: string,\n node: JSXRootNode,\n componentName: string,\n ignoredComponents: string[],\n fragmentContext: FragmentContext,\n sourceFileName: string,\n insertionsByOffset: Map<number, { offset: number; attributeValues: Map<string, string> }>,\n): void {\n if (isJSXElement(node)) {\n addPendingAttributes(\n code,\n node.openingElement,\n componentName,\n ignoredComponents,\n fragmentContext,\n sourceFileName,\n insertionsByOffset,\n );\n }\n\n for (const child of node.children ?? []) {\n if (isJSXRoot(child)) {\n processJSX(code, child, '', ignoredComponents, fragmentContext, sourceFileName, insertionsByOffset);\n }\n }\n}\n"],"names":[],"mappings":";;;;;AAaO,SAAS,uCAAA,CACd,IAAA,EACA,GAAA,EACA,iBAAA,EACA,cAAA,EACsB;AACtB,EAAA,MAAM,eAAA,GAAkB,uBAAuB,GAAG,CAAA;AAClD,EAAA,MAAM,UAAA,GAAa,yBAAyB,GAAG,CAAA;AAC/C,EAAA,MAAM,kBAAA,uBAAyB,GAAA,EAAsE;AAErG,EAAA,KAAA,MAAW,aAAa,UAAA,EAAY;AAClC,IAAA,KAAA,MAAW,IAAA,IAAQ,UAAU,KAAA,EAAO;AAClC,MAAA,UAAA,CAAW,MAAM,IAAA,EAAM,SAAA,CAAU,MAAM,iBAAA,EAAmB,eAAA,EAAiB,gBAAgB,kBAAkB,CAAA;AAAA,IAC/G;AAAA,EACF;AAEA,EAAA,OAAO,sBAAsB,kBAAkB,CAAA;A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MACA;AAAA,KACF;AAAA,EACF;AAEA,EAAA,KAAA,MAAW,KAAA,IAAS,IAAA,CAAK,QAAA,IAAY,EAAC,EAAG;AACvC,IAAA,IAAI,SAAA,CAAU,KAAK,CAAA,EAAG;AACpB,MAAA,UAAA,CAAW,MAAM,KAAA,EAAO,EAAA,EAAI,iBAAA,EAAmB,eAAA,EAAiB,gBAAgB,kBAAkB,CAAA;AAAA,IACpG;AAAA,EACF;AACF;;;;"}
|
|
@@ -2,12 +2,27 @@ import path__default from 'node:path';
|
|
|
2
2
|
import MagicString from 'magic-string';
|
|
3
3
|
import { KNOWN_INCOMPATIBLE_PLUGINS } from '../babel-plugin/constants.js';
|
|
4
4
|
import { stripQueryAndHashFromPath } from './utils.js';
|
|
5
|
-
import { isAstNode } from './component-annotation-
|
|
6
|
-
import {
|
|
5
|
+
import { isAstNode } from './component-annotation-oxc-ast.js';
|
|
6
|
+
import { collectOxcComponentAnnotationInsertions } from './component-annotation-oxc-walk.js';
|
|
7
7
|
|
|
8
|
+
let oxcParseAstAsyncPromise;
|
|
9
|
+
function getOxcParseAstAsync() {
|
|
10
|
+
if (!oxcParseAstAsyncPromise) {
|
|
11
|
+
oxcParseAstAsyncPromise = import('oxc-parser').then(({ parse }) => {
|
|
12
|
+
return async (code, { lang }) => {
|
|
13
|
+
const { program, errors } = await parse(`component.${lang}`, code, { lang, preserveParens: false });
|
|
14
|
+
if (errors.length > 0) {
|
|
15
|
+
throw new Error(errors[0]?.message);
|
|
16
|
+
}
|
|
17
|
+
return program;
|
|
18
|
+
};
|
|
19
|
+
}).catch(() => null);
|
|
20
|
+
}
|
|
21
|
+
return oxcParseAstAsyncPromise;
|
|
22
|
+
}
|
|
8
23
|
const JSX_TAG_START_REGEXP = /<[$_\p{ID_Start}][$_\u200c\u200d\p{ID_Continue}.:-]*|<>/u;
|
|
9
24
|
const JSX_FILE_REGEXP = /\.[jt]sx$/;
|
|
10
|
-
function
|
|
25
|
+
function isAnnotationFile(idWithoutQueryAndHash) {
|
|
11
26
|
if (idWithoutQueryAndHash.match(/\\node_modules\\|\/node_modules\//)) {
|
|
12
27
|
return false;
|
|
13
28
|
}
|
|
@@ -37,9 +52,9 @@ function getMagicString(code, meta) {
|
|
|
37
52
|
}
|
|
38
53
|
return { magicString: new MagicString(code), isNative: false };
|
|
39
54
|
}
|
|
40
|
-
async function
|
|
55
|
+
async function annotateWithOxcParser(code, id, ignoredComponents, parseAstAsync, meta) {
|
|
41
56
|
const idWithoutQueryAndHash = stripQueryAndHashFromPath(id);
|
|
42
|
-
if (!idWithoutQueryAndHash || !
|
|
57
|
+
if (!idWithoutQueryAndHash || !isAnnotationFile(idWithoutQueryAndHash) || !shouldTryParse(code) || shouldSkipIncompatibleFile(idWithoutQueryAndHash)) {
|
|
43
58
|
return null;
|
|
44
59
|
}
|
|
45
60
|
const ast = await parseAstAsync(code, {
|
|
@@ -48,7 +63,7 @@ async function annotateWithViteParser(code, id, ignoredComponents, parseAstAsync
|
|
|
48
63
|
if (!isAstNode(ast)) {
|
|
49
64
|
return void 0;
|
|
50
65
|
}
|
|
51
|
-
const insertions =
|
|
66
|
+
const insertions = collectOxcComponentAnnotationInsertions(
|
|
52
67
|
code,
|
|
53
68
|
ast,
|
|
54
69
|
ignoredComponents,
|
|
@@ -74,7 +89,7 @@ async function annotateWithViteParser(code, id, ignoredComponents, parseAstAsync
|
|
|
74
89
|
})
|
|
75
90
|
};
|
|
76
91
|
}
|
|
77
|
-
function
|
|
92
|
+
function createOxcComponentNameAnnotateHooks(ignoredComponents, getParseAstAsync) {
|
|
78
93
|
return {
|
|
79
94
|
async transform(code, id, meta) {
|
|
80
95
|
try {
|
|
@@ -82,7 +97,7 @@ function createViteComponentNameAnnotateHooks(ignoredComponents, getParseAstAsyn
|
|
|
82
97
|
if (!parseAstAsync) {
|
|
83
98
|
return void 0;
|
|
84
99
|
}
|
|
85
|
-
return await
|
|
100
|
+
return await annotateWithOxcParser(code, id, ignoredComponents, parseAstAsync, meta);
|
|
86
101
|
} catch {
|
|
87
102
|
return void 0;
|
|
88
103
|
}
|
|
@@ -90,5 +105,5 @@ function createViteComponentNameAnnotateHooks(ignoredComponents, getParseAstAsyn
|
|
|
90
105
|
};
|
|
91
106
|
}
|
|
92
107
|
|
|
93
|
-
export {
|
|
94
|
-
//# sourceMappingURL=component-annotation-
|
|
108
|
+
export { createOxcComponentNameAnnotateHooks, getOxcParseAstAsync };
|
|
109
|
+
//# sourceMappingURL=component-annotation-oxc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-annotation-oxc.js","sources":["../../../src/core/component-annotation-oxc.ts"],"sourcesContent":["import path from 'node:path';\n\nimport MagicString from 'magic-string';\n\nimport { KNOWN_INCOMPATIBLE_PLUGINS } from '../babel-plugin/constants';\nimport { stripQueryAndHashFromPath } from './utils';\nimport { isAstNode } from './component-annotation-oxc-ast';\nimport { collectOxcComponentAnnotationInsertions } from './component-annotation-oxc-walk';\nimport type {\n AttributeInsertion,\n ComponentAnnotationTransformMeta,\n ComponentAnnotationTransformResult,\n MagicStringLike,\n ParseAstAsync,\n} from './component-annotation-oxc-ast';\n\nexport type {\n ComponentAnnotationTransformMeta,\n ComponentAnnotationTransformResult,\n} from './component-annotation-oxc-ast';\n\nlet oxcParseAstAsyncPromise: Promise<ParseAstAsync | null> | undefined;\n\nexport function getOxcParseAstAsync(): Promise<ParseAstAsync | null> {\n if (!oxcParseAstAsyncPromise) {\n oxcParseAstAsyncPromise = import('oxc-parser')\n .then(({ parse }): ParseAstAsync => {\n return async (code, { lang }) => {\n // preserveParens: false matches the AST Vite 8 produces. The walker\n // does not look through ParenthesizedExpression nodes.\n const { program, errors } = await parse(`component.${lang}`, code, { lang, preserveParens: false });\n\n if (errors.length > 0) {\n throw new Error(errors[0]?.message);\n }\n\n return program;\n };\n })\n .catch(() => null);\n }\n\n return oxcParseAstAsyncPromise;\n}\n\n// Keep this as a superset of JSX tag starts Babel can annotate, because a miss suppresses Babel fallback.\nconst JSX_TAG_START_REGEXP = /<[$_\\p{ID_Start}][$_\\u200c\\u200d\\p{ID_Continue}.:-]*|<>/u;\nconst JSX_FILE_REGEXP = /\\.[jt]sx$/;\n\nfunction isAnnotationFile(idWithoutQueryAndHash: string): boolean {\n if (idWithoutQueryAndHash.match(/\\\\node_modules\\\\|\\/node_modules\\//)) {\n return false;\n }\n\n return JSX_FILE_REGEXP.test(idWithoutQueryAndHash);\n}\n\nfunction shouldTryParse(code: string): boolean {\n return JSX_TAG_START_REGEXP.test(code);\n}\n\nfunction shouldSkipIncompatibleFile(idWithoutQueryAndHash: string): boolean {\n return KNOWN_INCOMPATIBLE_PLUGINS.some(pluginName => {\n return (\n idWithoutQueryAndHash.includes(`/node_modules/${pluginName}/`) ||\n idWithoutQueryAndHash.includes(`\\\\node_modules\\\\${pluginName}\\\\`)\n );\n });\n}\n\nfunction escapeAttributeValue(value: string): string {\n return value.replace(/&/g, '&').replace(/\"/g, '"');\n}\n\nfunction makeAttributeText(\n code: string,\n insertionOffset: number,\n attributes: AttributeInsertion['attributes'],\n): string {\n const previousCharIsWhitespace = insertionOffset > 0 && /\\s/.test(code[insertionOffset - 1] ?? '');\n const prefix = previousCharIsWhitespace ? '' : ' ';\n const suffix = previousCharIsWhitespace && code[insertionOffset] === '/' ? ' ' : '';\n const attributeText = attributes.map(([name, value]) => `${name}=\"${escapeAttributeValue(value)}\"`).join(' ');\n\n return `${prefix}${attributeText}${suffix}`;\n}\n\nfunction getMagicString(\n code: string,\n meta?: ComponentAnnotationTransformMeta,\n): { magicString: MagicStringLike; isNative: boolean } {\n if (meta?.magicString) {\n return { magicString: meta.magicString, isNative: true };\n }\n\n return { magicString: new MagicString(code), isNative: false };\n}\n\nasync function annotateWithOxcParser(\n code: string,\n id: string,\n ignoredComponents: string[],\n parseAstAsync: ParseAstAsync,\n meta?: ComponentAnnotationTransformMeta,\n): Promise<ComponentAnnotationTransformResult> {\n const idWithoutQueryAndHash = stripQueryAndHashFromPath(id);\n\n if (\n !idWithoutQueryAndHash ||\n !isAnnotationFile(idWithoutQueryAndHash) ||\n !shouldTryParse(code) ||\n shouldSkipIncompatibleFile(idWithoutQueryAndHash)\n ) {\n return null;\n }\n\n const ast = await parseAstAsync(code, {\n lang: idWithoutQueryAndHash.endsWith('.jsx') ? 'jsx' : 'tsx',\n });\n\n // Fall through to the Babel fallback (return undefined, not null) when the parser yields an\n // unexpected result, mirroring the catch path — null would suppress Babel and drop annotations.\n if (!isAstNode(ast)) {\n return undefined;\n }\n\n const insertions = collectOxcComponentAnnotationInsertions(\n code,\n ast,\n ignoredComponents,\n path.basename(idWithoutQueryAndHash),\n );\n\n if (insertions.length === 0) {\n return null;\n }\n\n const { magicString, isNative } = getMagicString(code, meta);\n\n for (const insertion of insertions) {\n magicString.appendLeft(insertion.offset, makeAttributeText(code, insertion.offset, insertion.attributes));\n }\n\n if (isNative) {\n return { code: magicString as unknown as string };\n }\n\n return {\n code: magicString.toString(),\n map: magicString.generateMap?.({\n file: id,\n source: idWithoutQueryAndHash,\n includeContent: true,\n hires: true,\n }),\n };\n}\n\nexport function createOxcComponentNameAnnotateHooks(\n ignoredComponents: string[],\n getParseAstAsync: () => Promise<ParseAstAsync | null>,\n): {\n transform(\n code: string,\n id: string,\n meta?: ComponentAnnotationTransformMeta,\n ): Promise<ComponentAnnotationTransformResult>;\n} {\n return {\n async transform(code, id, meta) {\n try {\n const parseAstAsync = await getParseAstAsync();\n\n if (!parseAstAsync) {\n return undefined;\n }\n\n return await annotateWithOxcParser(code, id, ignoredComponents, parseAstAsync, meta);\n } catch {\n return undefined;\n }\n },\n };\n}\n"],"names":["path"],"mappings":";;;;;;;AAqBA,IAAI,uBAAA;AAEG,SAAS,mBAAA,GAAqD;AACnE,EAAA,IAAI,CAAC,uBAAA,EAAyB;AAC5B,IAAA,uBAAA,GAA0B,OAAO,YAAY,CAAA,CAC1C,KAAK,CAAC,EAAE,OAAM,KAAqB;AAClC,MAAA,OAAO,OAAO,IAAA,EAAM,EAAE,IAAA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,CAAC,aAAA,EAAe;AAClB,UAAA,OAAO,KAAA,CAAA;AAAA,QACT;AAEA,QAAA,OAAO,MAAM,qBAAA,CAAsB,IAAA,EAAM,EAAA,EAAI,iBAAA,EAAmB,eAAe,IAAI,CAAA;AAAA,MACrF,CAAA,CAAA,MAAQ;AACN,QAAA,OAAO,MAAA;AAAA,MACT;AAAA,IACF;AAAA,GACF;AACF;;;;"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
function isLineTerminator(character) {
|
|
2
|
+
return character === "\n" || character === "\r" || character === "\u2028" || character === "\u2029";
|
|
3
|
+
}
|
|
4
|
+
function skipTrivia(code, start) {
|
|
5
|
+
let position = start;
|
|
6
|
+
let hasLineBreak = false;
|
|
7
|
+
while (position < code.length) {
|
|
8
|
+
const character = code[position];
|
|
9
|
+
if (/\s/.test(character || "")) {
|
|
10
|
+
hasLineBreak || (hasLineBreak = isLineTerminator(character));
|
|
11
|
+
position++;
|
|
12
|
+
} else if (code.startsWith("//", position) || position === 0 && code.startsWith("#!", position)) {
|
|
13
|
+
let lineEnd = position + 2;
|
|
14
|
+
while (lineEnd < code.length && !isLineTerminator(code[lineEnd])) {
|
|
15
|
+
lineEnd++;
|
|
16
|
+
}
|
|
17
|
+
if (lineEnd === code.length) {
|
|
18
|
+
return { end: code.length, hasLineBreak };
|
|
19
|
+
}
|
|
20
|
+
position = lineEnd + 1;
|
|
21
|
+
hasLineBreak = true;
|
|
22
|
+
} else if (code.startsWith("/*", position)) {
|
|
23
|
+
const commentEnd = code.indexOf("*/", position + 2);
|
|
24
|
+
if (commentEnd === -1) {
|
|
25
|
+
return { end: code.length, hasLineBreak };
|
|
26
|
+
}
|
|
27
|
+
const comment = code.slice(position, commentEnd + 2);
|
|
28
|
+
hasLineBreak || (hasLineBreak = /[\n\r\u2028\u2029]/.test(comment));
|
|
29
|
+
position = commentEnd + 2;
|
|
30
|
+
} else {
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return { end: position, hasLineBreak };
|
|
35
|
+
}
|
|
36
|
+
function findStringLiteralEnd(code, start) {
|
|
37
|
+
const quote = code[start];
|
|
38
|
+
if (quote !== '"' && quote !== "'") {
|
|
39
|
+
return void 0;
|
|
40
|
+
}
|
|
41
|
+
for (let position = start + 1; position < code.length; position++) {
|
|
42
|
+
const character = code[position];
|
|
43
|
+
if (character === "\\") {
|
|
44
|
+
position += code[position + 1] === "\r" && code[position + 2] === "\n" ? 2 : 1;
|
|
45
|
+
} else if (character === quote) {
|
|
46
|
+
return position + 1;
|
|
47
|
+
} else if (isLineTerminator(character)) {
|
|
48
|
+
return void 0;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return void 0;
|
|
52
|
+
}
|
|
53
|
+
function startsWithBinaryOperatorKeyword(remainder, keyword) {
|
|
54
|
+
return remainder.startsWith(keyword) && !/^[$_\\\u200C\u200D\p{ID_Continue}]/u.test(remainder.slice(keyword.length));
|
|
55
|
+
}
|
|
56
|
+
function canContinueStringExpression(code, position) {
|
|
57
|
+
const remainder = code.slice(position, position + "instanceof".length + 1);
|
|
58
|
+
if (/^(?:\+\+|--|!(?!=))/.test(remainder)) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
return /^!={1,2}/.test(remainder) || /^[([.`+\-*/%<>=&|^?,:]/.test(remainder) || ["in", "instanceof"].some((keyword) => startsWithBinaryOperatorKeyword(remainder, keyword));
|
|
62
|
+
}
|
|
63
|
+
function getCodeInjectionPosition(code) {
|
|
64
|
+
let position = skipTrivia(code, 0).end;
|
|
65
|
+
let prologueEnd = position;
|
|
66
|
+
while (position < code.length) {
|
|
67
|
+
const stringEnd = findStringLiteralEnd(code, position);
|
|
68
|
+
if (stringEnd === void 0) {
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
const trailingTrivia = skipTrivia(code, stringEnd);
|
|
72
|
+
if (code[trailingTrivia.end] === ";") {
|
|
73
|
+
position = skipTrivia(code, trailingTrivia.end + 1).end;
|
|
74
|
+
} else if (trailingTrivia.end === code.length || trailingTrivia.hasLineBreak && !canContinueStringExpression(code, trailingTrivia.end)) {
|
|
75
|
+
position = trailingTrivia.end;
|
|
76
|
+
} else {
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
prologueEnd = position;
|
|
80
|
+
}
|
|
81
|
+
return prologueEnd;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export { getCodeInjectionPosition };
|
|
85
|
+
//# sourceMappingURL=get-code-injection-position.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-code-injection-position.js","sources":["../../../src/core/get-code-injection-position.ts"],"sourcesContent":["function isLineTerminator(character: string | undefined): boolean {\n return character === '\\n' || character === '\\r' || character === '\\u2028' || character === '\\u2029';\n}\n\nfunction skipTrivia(code: string, start: number): { end: number; hasLineBreak: boolean } {\n let position = start;\n let hasLineBreak = false;\n\n while (position < code.length) {\n const character = code[position];\n\n if (/\\s/.test(character || '')) {\n hasLineBreak ||= isLineTerminator(character);\n position++;\n } else if (code.startsWith('//', position) || (position === 0 && code.startsWith('#!', position))) {\n let lineEnd = position + 2;\n while (lineEnd < code.length && !isLineTerminator(code[lineEnd])) {\n lineEnd++;\n }\n if (lineEnd === code.length) {\n return { end: code.length, hasLineBreak };\n }\n position = lineEnd + 1;\n hasLineBreak = true;\n } else if (code.startsWith('/*', position)) {\n const commentEnd = code.indexOf('*/', position + 2);\n if (commentEnd === -1) {\n return { end: code.length, hasLineBreak };\n }\n const comment = code.slice(position, commentEnd + 2);\n hasLineBreak ||= /[\\n\\r\\u2028\\u2029]/.test(comment);\n position = commentEnd + 2;\n } else {\n break;\n }\n }\n\n return { end: position, hasLineBreak };\n}\n\nfunction findStringLiteralEnd(code: string, start: number): number | undefined {\n const quote = code[start];\n if (quote !== '\"' && quote !== \"'\") {\n return undefined;\n }\n\n for (let position = start + 1; position < code.length; position++) {\n const character = code[position];\n if (character === '\\\\') {\n position += code[position + 1] === '\\r' && code[position + 2] === '\\n' ? 2 : 1;\n } else if (character === quote) {\n return position + 1;\n } else if (isLineTerminator(character)) {\n return undefined;\n }\n }\n\n return undefined;\n}\n\nfunction startsWithBinaryOperatorKeyword(remainder: string, keyword: string): boolean {\n return remainder.startsWith(keyword) && !/^[$_\\\\\\u200C\\u200D\\p{ID_Continue}]/u.test(remainder.slice(keyword.length));\n}\n\nfunction canContinueStringExpression(code: string, position: number): boolean {\n const remainder = code.slice(position, position + 'instanceof'.length + 1);\n if (/^(?:\\+\\+|--|!(?!=))/.test(remainder)) {\n return false;\n }\n\n return (\n /^!={1,2}/.test(remainder) ||\n /^[([.`+\\-*/%<>=&|^?,:]/.test(remainder) ||\n ['in', 'instanceof'].some(keyword => startsWithBinaryOperatorKeyword(remainder, keyword))\n );\n}\n\nexport function getCodeInjectionPosition(code: string): number {\n let position = skipTrivia(code, 0).end;\n let prologueEnd = position;\n\n while (position < code.length) {\n const stringEnd = findStringLiteralEnd(code, position);\n if (stringEnd === undefined) {\n break;\n }\n\n const trailingTrivia = skipTrivia(code, stringEnd);\n if (code[trailingTrivia.end] === ';') {\n position = skipTrivia(code, trailingTrivia.end + 1).end;\n } else if (\n trailingTrivia.end === code.length ||\n (trailingTrivia.hasLineBreak && !canContinueStringExpression(code, trailingTrivia.end))\n ) {\n position = trailingTrivia.end;\n } else {\n break;\n }\n\n prologueEnd = position;\n }\n\n return prologueEnd;\n}\n"],"names":[],"mappings":"AAAA,SAAS,iBAAiB,SAAA,EAAwC;AAChE,EAAA,OAAO,cAAc,IAAA,IAAQ,SAAA,KAAc,IAAA,IAAQ,SAAA,KAAc,YAAY,SAAA,KAAc,QAAA;AAC7F;AAEA,SAAS,UAAA,CAAW,MAAc,KAAA,EAAuD;AACvF,EAAA,IAAI,QAAA,GAAW,KAAA;AACf,EAAA,IAAI,YAAA,GAAe,KAAA;AAEnB,EAAA,OAAO,QAAA,GAAW,KAAK,MAAA,EAAQ;AAC7B,IAAA,MAAM,SAAA,GAAY,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} from '@sentry/core';
|
|
|
2
2
|
import { stripQueryAndHashFromPath, CodeInjection, containsOnlyImports } from './utils.js';
|
|
3
3
|
export { generateModuleMetadataInjectorCode, generateReleaseInjectorCode, replaceBooleanFlagsInCode, stringToUUID } from './utils.js';
|
|
4
4
|
export { globFiles } from './glob.js';
|
|
5
|
+
export { getCodeInjectionPosition } from './get-code-injection-position.js';
|
|
5
6
|
export { createSentryBuildPluginManager } from './build-plugin-manager.js';
|
|
6
7
|
export { addDebugIdToEmittedArtifacts, createDebugIdUploadFunction, stampDebugId } from './debug-id-upload.js';
|
|
7
8
|
|
|
@@ -20,10 +21,6 @@ function loadBabelAnnotationRuntime() {
|
|
|
20
21
|
}
|
|
21
22
|
return babelAnnotationRuntimePromise;
|
|
22
23
|
}
|
|
23
|
-
const COMMENT_USE_STRICT_REGEX = (
|
|
24
|
-
// Note: CodeQL complains that this regex potentially has n^2 runtime. This likely won't affect realistic files.
|
|
25
|
-
/^(?:\s*|\/\*(?:.|\r|\n)*?\*\/|\/\/.*[\n\r])*(?:"[^"]*";|'[^']*';)?/
|
|
26
|
-
);
|
|
27
24
|
function isJsFile(fileName) {
|
|
28
25
|
const cleanFileName = stripQueryAndHashFromPath(fileName);
|
|
29
26
|
return [".js", ".mjs", ".cjs"].some((ext) => cleanFileName.endsWith(ext));
|
|
@@ -87,5 +84,5 @@ function getDebugIdSnippet(debugId) {
|
|
|
87
84
|
);
|
|
88
85
|
}
|
|
89
86
|
|
|
90
|
-
export {
|
|
87
|
+
export { CodeInjection, createComponentNameAnnotateHooks, getDebugIdSnippet, isJsFile, shouldSkipCodeInjection };
|
|
91
88
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/core/index.ts"],"sourcesContent":["import { debug } from '@sentry/core';\nimport { CodeInjection, containsOnlyImports, stripQueryAndHashFromPath } from './utils';\nimport type { transformAsync as babelTransformAsync } from '@babel/core';\nimport type componentNameAnnotatePlugin from '../babel-plugin';\nimport type { experimentalComponentNameAnnotatePlugin } from '../babel-plugin';\n\ntype BabelTransformAsync = typeof babelTransformAsync;\ntype BabelParserPlugins = NonNullable<NonNullable<Parameters<BabelTransformAsync>[1]>['parserOpts']>['plugins'];\ntype BabelAnnotationRuntime = {\n transformAsync: BabelTransformAsync;\n componentNameAnnotatePlugin: typeof componentNameAnnotatePlugin;\n experimentalComponentNameAnnotatePlugin: typeof experimentalComponentNameAnnotatePlugin;\n};\n\nlet babelAnnotationRuntimePromise: Promise<BabelAnnotationRuntime> | undefined;\n\nfunction loadBabelAnnotationRuntime(): Promise<BabelAnnotationRuntime> {\n if (!babelAnnotationRuntimePromise) {\n babelAnnotationRuntimePromise = Promise.all([import('@babel/core'), import('../babel-plugin')]).then(\n ([babel, babelPlugin]) => {\n return {\n transformAsync: babel.transformAsync,\n componentNameAnnotatePlugin: babelPlugin.default,\n experimentalComponentNameAnnotatePlugin: babelPlugin.experimentalComponentNameAnnotatePlugin,\n };\n },\n );\n }\n\n return babelAnnotationRuntimePromise;\n}\n\n
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/core/index.ts"],"sourcesContent":["import { debug } from '@sentry/core';\nimport { CodeInjection, containsOnlyImports, stripQueryAndHashFromPath } from './utils';\nimport type { transformAsync as babelTransformAsync } from '@babel/core';\nimport type componentNameAnnotatePlugin from '../babel-plugin';\nimport type { experimentalComponentNameAnnotatePlugin } from '../babel-plugin';\n\ntype BabelTransformAsync = typeof babelTransformAsync;\ntype BabelParserPlugins = NonNullable<NonNullable<Parameters<BabelTransformAsync>[1]>['parserOpts']>['plugins'];\ntype BabelAnnotationRuntime = {\n transformAsync: BabelTransformAsync;\n componentNameAnnotatePlugin: typeof componentNameAnnotatePlugin;\n experimentalComponentNameAnnotatePlugin: typeof experimentalComponentNameAnnotatePlugin;\n};\n\nlet babelAnnotationRuntimePromise: Promise<BabelAnnotationRuntime> | undefined;\n\nfunction loadBabelAnnotationRuntime(): Promise<BabelAnnotationRuntime> {\n if (!babelAnnotationRuntimePromise) {\n babelAnnotationRuntimePromise = Promise.all([import('@babel/core'), import('../babel-plugin')]).then(\n ([babel, babelPlugin]) => {\n return {\n transformAsync: babel.transformAsync,\n componentNameAnnotatePlugin: babelPlugin.default,\n experimentalComponentNameAnnotatePlugin: babelPlugin.experimentalComponentNameAnnotatePlugin,\n };\n },\n );\n }\n\n return babelAnnotationRuntimePromise;\n}\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 { globFiles } from './glob';\nexport { getCodeInjectionPosition } from './get-code-injection-position';\n\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function createComponentNameAnnotateHooks(ignoredComponents: string[], injectIntoHtml: boolean) {\n return {\n async transform(this: void, code: string, id: string) {\n // id may contain query and hash which will trip up our file extension logic below\n const idWithoutQueryAndHash = stripQueryAndHashFromPath(id);\n\n if (idWithoutQueryAndHash.match(/\\\\node_modules\\\\|\\/node_modules\\//)) {\n return null;\n }\n\n // We will only apply this plugin on jsx and tsx files\n if (!['.jsx', '.tsx'].some(ending => idWithoutQueryAndHash.endsWith(ending))) {\n return null;\n }\n\n const parserPlugins: BabelParserPlugins = [];\n if (idWithoutQueryAndHash.endsWith('.jsx')) {\n parserPlugins.push('jsx');\n } else if (idWithoutQueryAndHash.endsWith('.tsx')) {\n parserPlugins.push('jsx', 'typescript');\n }\n\n const { transformAsync, componentNameAnnotatePlugin, experimentalComponentNameAnnotatePlugin } =\n await loadBabelAnnotationRuntime();\n const plugin = injectIntoHtml ? experimentalComponentNameAnnotatePlugin : componentNameAnnotatePlugin;\n\n try {\n const result = await transformAsync(code, {\n plugins: [[plugin, { ignoredComponents }]],\n filename: id,\n sourceFileName: idWithoutQueryAndHash,\n parserOpts: {\n sourceType: 'module',\n allowAwaitOutsideFunction: true,\n plugins: parserPlugins,\n },\n generatorOpts: {\n decoratorsBeforeExport: true,\n },\n sourceMaps: true,\n });\n\n return {\n code: result?.code ?? code,\n map: result?.map,\n };\n } catch (e) {\n debug.error(`Failed to apply react annotate plugin`, e);\n }\n\n return { code };\n },\n };\n}\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 { Options, SentrySDKBuildFlags } from './types';\nexport {\n CodeInjection,\n replaceBooleanFlagsInCode,\n stringToUUID,\n generateReleaseInjectorCode,\n generateModuleMetadataInjectorCode,\n} from './utils';\nexport { createSentryBuildPluginManager } from './build-plugin-manager';\nexport { createDebugIdUploadFunction, addDebugIdToEmittedArtifacts, stampDebugId } from './debug-id-upload';\n"],"names":[],"mappings":";;;;;;;;AAcA,IAAI,6BAAA;AAEJ,SAAS,0BAAA,GAA8D;AACrE,E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AAA;AAAA,MACxD;AAEA,MAAA,OAAO,EAAE,IAAA,EAAK;AAAA,IAChB;AAAA,GACF;AACF;AAEO,SAAS,kBAAkB,OAAA,EAAgC;AAChE,EAAA,OAAO,IAAI,aAAA;AAAA,IACT,CAAA,4FAAA,EAA+F,OAAO,CAAA,0CAAA,EAA6C,OAAO,CAAA,GAAA;AAAA,GAC5J;AACF;;;;"}
|
|
@@ -12,7 +12,7 @@ function createSentryInstance(options, shouldSendTelemetry, buildTool, buildTool
|
|
|
12
12
|
platform: "node",
|
|
13
13
|
runtime: { name: "node", version: global.process.version },
|
|
14
14
|
dsn: "https://4c2bae7d9fbc413e8f7385f55c515d51@o1.ingest.sentry.io/6690737",
|
|
15
|
-
tracesSampleRate:
|
|
15
|
+
tracesSampleRate: 0.3,
|
|
16
16
|
traceLifecycle: "static",
|
|
17
17
|
sampleRate: 1,
|
|
18
18
|
release: LIB_VERSION,
|
|
@@ -40,6 +40,9 @@ function createSentryInstance(options, shouldSendTelemetry, buildTool, buildTool
|
|
|
40
40
|
const client = new ServerRuntimeClient(clientOptions);
|
|
41
41
|
const scope = new Scope();
|
|
42
42
|
scope.setClient(client);
|
|
43
|
+
if (process.env["SENTRY_TEST_OUT_DIR"]) {
|
|
44
|
+
scope.setPropagationContext({ ...scope.getPropagationContext(), sampleRand: 0 });
|
|
45
|
+
}
|
|
43
46
|
setTelemetryDataOnScope(options, scope, buildTool, buildToolMajorVersion);
|
|
44
47
|
return { sentryScope: scope, sentryClient: client };
|
|
45
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry.js","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:
|
|
1
|
+
{"version":3,"file":"telemetry.js","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('sourcemaps-disabled', !!sourcemaps?.disable);\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, url } = options;\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"],"names":[],"mappings":";;;;;;;AAaA,MAAM,oBAAA,GAAuB,WAAA;AAE7B,MAAM,WAAA,GAAc,iBAAA,CAAkB,mBAAA,EAAqB,CAAA;AAEpD,S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AK,CAAA;AAC3B;AAEA,eAAsB,uBAAuB,OAAA,EAA8C;AACzF,EAAA,MAAM,EAAE,SAAA,EAAW,GAAA,EAAI,GAAI,OAAA;AAG3B,EAAA,IAAI,cAAc,KAAA,EAAO;AACvB,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,IAAI,QAAQ,eAAA,EAAiB;AAC3B,IAAA,OAAO,IAAA;AAAA,EACT;AAIA,EAAA,MAAM,aAAa,MAAM,IAAI,gBAAA,CAAiB,OAAO,EAAE,YAAA,EAAa;AAEpE,EAAA,IAAI,eAAe,MAAA,EAAW;AAC5B,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,OAAO,IAAI,GAAA,CAAI,UAAU,CAAA,CAAE,QAAA,KAAa,oBAAA;AAC1C;AAKA,eAAsB,mBAAmB,YAAA,EAAqC;AAC5E,EAAA,IAAI;AACF,IAAA,MAAM,YAAA,CAAa,MAAM,GAAI,CAAA;AAAA,EAC/B,CAAA,CAAA,MAAQ;AAAA,EAGR;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sources":["../../../src/core/version.ts"],"sourcesContent":["export const LIB_VERSION = \"11.0.0
|
|
1
|
+
{"version":3,"file":"version.js","sources":["../../../src/core/version.ts"],"sourcesContent":["export const LIB_VERSION = \"11.0.0\";\n"],"names":[],"mappings":"AAAO,MAAM,WAAA,GAAc;;;;"}
|