mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-20 14:54:12 +00:00
Add testing for telemetry in local dist assets
This commit is contained in:
57
scripts/verify-dist-no-telemetry.ts
Normal file
57
scripts/verify-dist-no-telemetry.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import { readFile, stat } from 'node:fs/promises'
|
||||
import { extname, resolve } from 'node:path'
|
||||
import { glob } from 'glob'
|
||||
|
||||
type Pattern = {
|
||||
label: string
|
||||
regex: RegExp
|
||||
}
|
||||
|
||||
const distDir = resolve('dist')
|
||||
const ignoredExtensions = new Set(['.map', '.svg'])
|
||||
const telemetryPatterns: Pattern[] = [
|
||||
{ label: 'GTM container', regex: /GTM-[A-Z0-9]+/i },
|
||||
{ label: 'GTM script', regex: /gtm\.js/i },
|
||||
{ label: 'Google Tag Manager', regex: /googletagmanager/i },
|
||||
{ label: 'dataLayer', regex: /\bdataLayer\b/ }
|
||||
]
|
||||
|
||||
const distStats = await stat(distDir).catch(() => null)
|
||||
if (!distStats?.isDirectory()) {
|
||||
console.error('dist directory not found. Run pnpm build first.')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const files = await glob('dist/**/*', { nodir: true })
|
||||
const violations: Array<{
|
||||
file: string
|
||||
hits: Array<{ label: string; match: string }>
|
||||
}> = []
|
||||
|
||||
for (const file of files) {
|
||||
const extension = extname(file).toLowerCase()
|
||||
if (ignoredExtensions.has(extension)) continue
|
||||
|
||||
const content = (await readFile(file)).toString('utf8')
|
||||
const hits = telemetryPatterns
|
||||
.map((pattern) => {
|
||||
const match = content.match(pattern.regex)
|
||||
return match ? { label: pattern.label, match: match[0] } : null
|
||||
})
|
||||
.filter((hit): hit is { label: string; match: string } => hit !== null)
|
||||
|
||||
if (hits.length > 0) {
|
||||
violations.push({ file, hits })
|
||||
}
|
||||
}
|
||||
|
||||
if (violations.length > 0) {
|
||||
console.error('Telemetry references found in dist assets:')
|
||||
for (const violation of violations) {
|
||||
const formattedHits = violation.hits
|
||||
.map((hit) => `${hit.label} (${hit.match})`)
|
||||
.join(', ')
|
||||
console.error(`- ${violation.file}: ${formattedHits}`)
|
||||
}
|
||||
process.exit(1)
|
||||
}
|
||||
Reference in New Issue
Block a user