mirror of
https://github.com/hanzoai/gui.git
synced 2026-10-25 02:31:41 +00:00
Babel and esbuild were never here for TypeScript. Babel carried the static optimizing compiler and one plugin that appended extensions to esbuild's emitted imports; source now names its own extensions and the compiler rewrites them on emit. A sixty-line runner replaces the tool: an ESM emit with declarations, a CommonJS emit where a manifest states a require entry, and a native emit where a .native sibling takes its sibling's name. The compiler packages keep Babel as their own substrate; nothing else runs over the code. Eighteen packages still carry type errors the previous tool never checked.
40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import { basename } from 'node:path'
|
|
|
|
import type { GuiOptions } from '../types.ts'
|
|
import { getPrefixLogs } from './getPrefixLogs.ts'
|
|
|
|
export function createLogger(sourcePath: string, options: GuiOptions) {
|
|
const shouldLogTiming = options.logTimings ?? true
|
|
const start = Date.now()
|
|
const mem =
|
|
process.env.GUI_SHOW_MEMORY_USAGE && shouldLogTiming ? process.memoryUsage() : null
|
|
|
|
return (res) => {
|
|
if (!shouldLogTiming) {
|
|
return
|
|
}
|
|
|
|
const memUsed = mem
|
|
? Math.round(((process.memoryUsage().heapUsed - mem.heapUsed) / 1024 / 1204) * 10) /
|
|
10
|
|
: 0
|
|
const path = basename(sourcePath || '')
|
|
.replace(/\.[jt]sx?$/, '')
|
|
.slice(0, 22)
|
|
.trim()
|
|
.padEnd(24)
|
|
|
|
const numOptimized = `${res.optimized + res.styled}`.padStart(3)
|
|
const numFound = `${res.found + res.styled}`.padStart(3)
|
|
const numFlattened = `${res.flattened}`.padStart(3)
|
|
const memory = memUsed ? ` ${memUsed}MB` : ''
|
|
const timing = Date.now() - start
|
|
const timingStr = `${timing}ms`.padStart(6)
|
|
const pre = getPrefixLogs(options)
|
|
const memStr = memory ? `(${memory})` : ''
|
|
console.info(
|
|
`${pre} ${path} · ${numFound} found · ${numOptimized} opt · ${numFlattened} flat ${timingStr} ${memStr}`
|
|
)
|
|
}
|
|
}
|