Files
insights/frontend/plugins/vite-insights-js-plugin.ts
zeekay 1b367e2b62 chore: rebase the tree onto upstream master
The tree was a debranded snapshot of upstream taken around 2026-02-20, and
upstream has moved about five months since. This replaces it with upstream
master, mechanically re-derived: bin/debrand does the rename, and the
pipeline and squashed migrations are restored from the shipped tree.

Not a merge. The previous import replaced the tree wholesale in a single
commit, so there is no shared content history to merge against. Reproducing
the rename on the new tree is what actually converges.

What survives: .hanzo/workflows, the Dockerfiles and bin/docker* entrypoints,
compose files, LLM.md, and insights/migrations. The squashed initial
migration is load-bearing — the live database records it by name, so
upstream's ~918 individual migrations cannot come back.

Nine products are dropped as unreferenced. Twenty-one more that we do not run
are kept anyway because the core app still imports them; unpicking those is a
refactor and does not belong in a rebase.

This base does not build yet, and the reasons are not in the rename:
upstream now wants Python 3.13.13 against our 3.12.12 and Django 5.2 against
our 4.2, and the dependency manifests still name upstream packages that we
republish under our own names. Those are decisions, not renames.
2026-08-01 15:44:40 -07:00

111 lines
3.5 KiB
TypeScript

import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'fs'
import { dirname, join, resolve } from 'path'
import type { Plugin } from 'vite'
function copyFile(from: string, to: string): void {
try {
// Ensure target directory exists
const toDir = dirname(to)
if (!existsSync(toDir)) {
mkdirSync(toDir, { recursive: true })
}
// Copy the file
const fileContent = readFileSync(from)
writeFileSync(to, fileContent)
} catch (error) {
// Silently fail if file doesn't exist (matches copy-insights-js script behavior)
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') {
console.warn(`❌ Could not copy ${from} to ${to}:`, error)
}
}
}
function copyInsightsJsFiles(): void {
const nodeModulesInsightsJs = resolve('.', 'node_modules/insights-js/dist')
const distDir = resolve('.', 'dist')
// Ensure dist directory exists
if (!existsSync(distDir)) {
mkdirSync(distDir, { recursive: true })
}
// Copy specific files (matching frontend/bin/copy-insights-js)
const filesToCopy = [
'array.js',
'array.js.map',
'array.full.js',
'array.full.js.map',
'array.full.es5.js',
'array.full.es5.js.map',
'surveys.js',
'surveys.js.map',
'logs.js',
'logs.js.map',
'exception-autocapture.js',
'exception-autocapture.js.map',
'web-vitals.js',
'web-vitals.js.map',
'web-vitals-with-attribution.js',
'web-vitals-with-attribution.js.map',
'tracing-headers.js',
'tracing-headers.js.map',
'dead-clicks-autocapture.js',
'dead-clicks-autocapture.js.map',
'customizations.full.js',
'customizations.full.js.map',
'product-tours.js',
'product-tours.js.map',
]
filesToCopy.forEach((file) => {
const from = join(nodeModulesInsightsJs, file)
const to = join(distDir, file)
copyFile(from, to)
})
// Copy integration files (e.g., *integration.js*)
try {
const files = readdirSync(nodeModulesInsightsJs)
files.forEach((file: string) => {
if (file.includes('integration') && (file.endsWith('.js') || file.endsWith('.js.map'))) {
const from = join(nodeModulesInsightsJs, file)
const to = join(distDir, file)
copyFile(from, to)
}
})
} catch (error) {
console.warn(`❌ Could not copy integration files:`, error)
}
// Copy recorder files (e.g., *recorder*.js*)
try {
const files = readdirSync(nodeModulesInsightsJs)
files.forEach((file: string) => {
if (file.includes('recorder') && (file.endsWith('.js') || file.endsWith('.js.map'))) {
const from = join(nodeModulesInsightsJs, file)
const to = join(distDir, file)
copyFile(from, to)
}
})
} catch (error) {
console.warn(`❌ Could not copy recorder files:`, error)
}
console.info('✅ Copied insights-js files to dist/')
}
export function insightsJsPlugin(): Plugin {
return {
name: 'insights-js-copy',
configureServer() {
// Copy insights-js files when dev server starts
copyInsightsJsFiles()
},
buildStart() {
// Also copy when building
copyInsightsJsFiles()
},
}
}