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BAAmB,CAAC,CAAC,IAAI,CACrD,CAAC,CAAC,UAAU,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAGlC,EAAE,EAAE;gBACJ,IAAI,UAAU,KAAK,uCAAmB,EAAE,CAAC;oBACxC,OAAO,KAAK,CAAC;gBACd,CAAC;gBACD,OAAO,OAAO,CAAC,UAAU,GAAG,QAAQ,CAAC,UAAU,GAAG,yBAAyB,CAAC;YAC7E,CAAC,CACD,CAAC;QACH,CAAC,CAAC,IAAI,KAAK,CAAC;QAEb,wDAAwD;QACxD,IAAI,sBAAsB,EAAE,CAAC;YAC5B,IAAI,CAAC,uEAAuE,CAAC,CAAC;YAE9E,IAAI,CAAC;gBACJ,MAAM,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC;oBAC1C,KAAK,EAAE,QAAQ;oBACf,WAAW,EAAE,4CAA4C;oBACzD,IAAI,EAAE,iBAAiB;iBACvB,CAAC,CAAC;YACJ,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,OAAO,CAAC,KAAK,CAAC,uBAAuB,KAAK,EAAE,CAAC,CAAC;YAC/C,CAAC;QACF,CAAC;QAED,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC1B,CAAC;SAAM,CAAC;QACP,OAAO,CAAC,GAAG,CAAC,uDAAuD,CAAC,CAAC;IACtE,CAAC;AACF,CAAC;AA3DD,gCA2DC;AAED,0DAA0D;AAC1D,UAAU,EAAE,CAAC,KAAK,CAAC,CAAC,KAAa,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tADOSizeComparator,\n\ttype BundleComparison,\n\ttype BundleComparisonResult,\n\ttype BundleMetric,\n\tbundlesContainNoChanges,\n\tgetAzureDevopsApi,\n\ttotalSizeMetricName,\n} from \"@fluidframework/bundle-size-tools\";\n\n// Handle weirdness with Danger import.  The current module setup prevents us\n// from using this file directly, and the js transpilation renames the danger\n// import which prevents danger from removing it before evaluation (because it\n// actually puts its exports in the global namespace at that time)\ndeclare function markdown(message: string, file?: string, line?: number): void;\n\ndeclare function warn(message: string, file?: string, line?: number): void;\n\ndeclare const danger: {\n\tgithub: {\n\t\tutils: {\n\t\t\tcreateOrAddLabel: (\n\t\t\t\tlabelConfig: { color: string; description: string; name: string },\n\t\t\t\trepoConfig?: { owner: string; repo: string; id: number },\n\t\t\t) => Promise<void>;\n\t\t};\n\t};\n};\nconst adoConstants = {\n\torgUrl: \"https://dev.azure.com/fluidframework\",\n\tprojectName: \"public\",\n\tciBuildDefinitionId: 48,\n\tbundleAnalysisArtifactName: \"bundleAnalysis\",\n};\n\nconst localReportPath = \"./artifacts/bundleAnalysis\";\n\nconst sizeWarningThresholdBytes = 5120;\n\nexport async function dangerfile(): Promise<void> {\n\tif (process.env.ADO_API_TOKEN === undefined) {\n\t\tthrow new Error(\"no env ado api token provided\");\n\t}\n\n\tif (process.env.DANGER_GITHUB_API_TOKEN === undefined) {\n\t\tthrow new Error(\"no env github api token provided\");\n\t}\n\n\tconst adoConnection = getAzureDevopsApi(process.env.ADO_API_TOKEN, adoConstants.orgUrl);\n\tconst sizeComparator = new ADOSizeComparator(\n\t\tadoConstants,\n\t\tadoConnection,\n\t\tlocalReportPath,\n\t\tundefined,\n\t\tADOSizeComparator.naiveFallbackCommitGenerator,\n\t);\n\tconst result: BundleComparisonResult =\n\t\tawait sizeComparator.createSizeComparisonMessage(false);\n\n\t// Post a message only if there was an error (result.comparison is undefined) or if\n\t// there were actual changes to the bundle sizes.  In other cases, we don't post a\n\t// message and danger will delete its previous message\n\tif (result.comparison === undefined || !bundlesContainNoChanges(result.comparison)) {\n\t\t// Check for bundle size regression\n\t\tconst sizeRegressionDetected =\n\t\t\tresult.comparison?.some((bundle: BundleComparison) => {\n\t\t\t\treturn Object.entries(bundle.commonBundleMetrics).some(\n\t\t\t\t\t([metricName, { baseline, compare }]: [\n\t\t\t\t\t\tstring,\n\t\t\t\t\t\t{ baseline: BundleMetric; compare: BundleMetric },\n\t\t\t\t\t]) => {\n\t\t\t\t\t\tif (metricName === totalSizeMetricName) {\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn compare.parsedSize - baseline.parsedSize > sizeWarningThresholdBytes;\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t}) ?? false;\n\n\t\t// Add warning message in case of bundle size regression\n\t\tif (sizeRegressionDetected) {\n\t\t\twarn(\"Bundle size regression detected -- please investigate before merging!\");\n\n\t\t\ttry {\n\t\t\t\tawait danger.github.utils.createOrAddLabel({\n\t\t\t\t\tcolor: \"ff0000\",\n\t\t\t\t\tdescription: \"Significant bundle size regression (>5 KB)\",\n\t\t\t\t\tname: \"size regression\",\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error(`Error adding label: ${error}`);\n\t\t\t}\n\t\t}\n\n\t\tmarkdown(result.message);\n\t} else {\n\t\tconsole.log(\"No size changes detected, skipping posting PR comment\");\n\t}\n}\n\n// eslint-disable-next-line unicorn/prefer-top-level-await\ndangerfile().catch((error: string) => console.error(error));\n"]}