mirror of
https://github.com/hanzoai/insights-js.git
synced 2026-10-30 18:34:19 +00:00
We own the ingestion server (hanzoai/insights: Django + rust/capture + nodejs plugin) AND this SDK, so there is no external wire contract to preserve. The server is already 100% posthog-free; this SDK was the last laggard. - $last_posthog_reset -> $last_insights_reset. This FIXES A LIVE MISMATCH: the server taxonomy (insights/taxonomy/taxonomy.py, insights/insightsql/ai.py) already expected the insights form while the SDK emitted the posthog form. - __PosthogExtensions__ -> __InsightsExtensions__; all PostHog/posthog/POSTHOG identifiers -> Insights/insights/INSIGHTS (src, tests, playground, playwright, scripts, rrweb subpackages, package.json keywords). - Hosts: DEFAULT_PLUGIN_HOST + DEFAULT_NUXT_HOST + the core host default pointed at PostHog's cloud (us.i.posthog.com) — a real bug. All -> insights.hanzo.ai. - Removed the us-assets/eu-assets CDN split in getRemoteConfig (PostHog-specific; Hanzo serves remote config from the same host) — it had degenerated to a no-op. - Fixed generate-docs writing to a stray references/@hanzo/ subdir. - Renamed the 3 posthog-named test files; dropped 58MB of stale reference snapshots named for upstream posthog versions we never shipped (they are generated output — references/ is now gitignored). Verified: typecheck errors 42 (HEAD) -> 18 (all pre-existing test-mock looseness); types package 0; every package.json valid with @hanzo/* names. Guard: grep -rioE 'posthog' packages ... | wc -l => 0
60 lines
1.9 KiB
JavaScript
60 lines
1.9 KiB
JavaScript
import fs from 'node:fs'
|
|
import path from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
const distDir = new URL('../dist/', import.meta.url)
|
|
const allowedExtensions = /\.(?:js|mjs|cjs|json)$/
|
|
const forbiddenBareSpecifiers = new Set([
|
|
'next/navigation',
|
|
'next/router',
|
|
'next/headers',
|
|
'next/server',
|
|
'insights-js/react',
|
|
])
|
|
const specifierPattern = /\b(?:import|export)\s+(?:[^'"\n]*?\sfrom\s+)?['"]([^'"]+)['"]|\bimport\(\s*['"]([^'"]+)['"]\s*\)/g
|
|
|
|
function listFiles(dirPath) {
|
|
return fs.readdirSync(dirPath, { withFileTypes: true }).flatMap((entry) => {
|
|
const entryPath = path.join(dirPath, entry.name)
|
|
if (entry.isDirectory()) {
|
|
return listFiles(entryPath)
|
|
}
|
|
return entry.name.endsWith('.js') || entry.name.endsWith('.d.ts') ? [entryPath] : []
|
|
})
|
|
}
|
|
|
|
const distPath = fileURLToPath(distDir)
|
|
if (!fs.existsSync(distPath)) {
|
|
throw new Error(`Missing build output at ${distPath}`)
|
|
}
|
|
|
|
const offenders = []
|
|
|
|
for (const filePath of listFiles(distPath)) {
|
|
const text = fs.readFileSync(filePath, 'utf8')
|
|
for (const match of text.matchAll(specifierPattern)) {
|
|
const specifier = match[1] ?? match[2]
|
|
if (!specifier) {
|
|
continue
|
|
}
|
|
|
|
const isRelativeSpecifier = specifier.startsWith('./') || specifier.startsWith('../')
|
|
if (isRelativeSpecifier && !allowedExtensions.test(specifier)) {
|
|
offenders.push(`${path.relative(distPath, filePath)} -> ${specifier}`)
|
|
continue
|
|
}
|
|
|
|
if (forbiddenBareSpecifiers.has(specifier)) {
|
|
offenders.push(`${path.relative(distPath, filePath)} -> ${specifier}`)
|
|
}
|
|
}
|
|
}
|
|
|
|
if (offenders.length > 0) {
|
|
console.error('Found relative import/export specifiers without explicit runtime extensions in dist:')
|
|
for (const offender of offenders) {
|
|
console.error(`- ${offender}`)
|
|
}
|
|
process.exit(1)
|
|
}
|