File size: 910 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import type { TelemetryLoaderContext } from './telemetry-plugin'
export type SwcTransformTelemetryOutput = {
eliminatedPackages?: string
useCacheTelemetryTracker?: string
}
export function updateTelemetryLoaderCtxFromTransformOutput(
ctx: TelemetryLoaderContext,
output: SwcTransformTelemetryOutput
) {
if (output.eliminatedPackages && ctx.eliminatedPackages) {
for (const pkg of JSON.parse(output.eliminatedPackages)) {
ctx.eliminatedPackages.add(pkg)
}
}
if (output.useCacheTelemetryTracker && ctx.useCacheTracker) {
for (const [key, value] of JSON.parse(output.useCacheTelemetryTracker)) {
const prefixedKey = `useCache/${key}` as const
const numericValue = Number(value)
if (!isNaN(numericValue)) {
ctx.useCacheTracker.set(
prefixedKey,
(ctx.useCacheTracker.get(prefixedKey) || 0) + numericValue
)
}
}
}
}
|