mirror of
https://github.com/hanzoai/gui.git
synced 2026-10-25 02:31:41 +00:00
Match the layout convention used elsewhere in the Hanzo / Liquidity stack
(pkgs/* for libraries, apps/* for consumer apps, templates/* for starters).
Layout changes:
pkgs/ ← code/{compiler,core,packages,ui,ui-admin}/
apps/ ← code/{admin-base,admin-tasks,demos,gui.hanzo.ai,
kitchen-sink*,sandbox,tests}/
templates/ ← code/starters/* (flattened — no more starters/ subdir)
Updated:
- package.json workspaces glob.
- All scripts/* path references (postinstall, format, repair, release,
sync-gui-versions, ci-serve, check-references, etc).
- ../../tasks/scripts/sync-admin-ui.sh — DEFAULT_SRC now points at
../gui/apps/admin-tasks (and scrubbed Tamagui mentions in comments).
- ~/work/hanzo/HANZO_BINARY.md doctrine doc.
- ~/work/hanzo/ui/pkg/ui/BASES.md framework-bases doc.
- gui CLAUDE.md, CONTRIBUTING.md.
- Memory entries.
Side-effect fix: ui-admin/src/primitives/index.ts now re-exports
PageShell from ../shell/PageShell. Several IAM identity pages
(GroupEdit, OrgEdit, GroupTree, UserEdit, RoleEdit) imported PageShell
from ./primitives — pre-existing barrel mismatch the test suite missed
because the smoke tests don't full-render. The rename surfaced it via
production build; back-compat re-export keeps both barrels working.
Verification:
- bun install: clean.
- ui-admin tests: 127/127 green.
- admin-tasks vite build: 721 KB JS / 213 KB gzip + 10 KB CSS, clean.
84 lines
2.4 KiB
TypeScript
84 lines
2.4 KiB
TypeScript
import type { NodePath } from '@babel/traverse'
|
|
import * as t from '@babel/types'
|
|
|
|
const hooks = {
|
|
useMedia: true,
|
|
useTheme: true,
|
|
}
|
|
|
|
export function removeUnusedHooks(
|
|
compFn: NodePath<any>,
|
|
shouldPrintDebug: boolean | 'verbose'
|
|
) {
|
|
compFn.scope.crawl()
|
|
// check the top level statements
|
|
let bodyStatements = compFn?.get('body')
|
|
if (!bodyStatements) {
|
|
console.info('no body statemnts?', compFn)
|
|
return
|
|
}
|
|
if (!Array.isArray(bodyStatements)) {
|
|
if (bodyStatements.isFunctionExpression()) {
|
|
bodyStatements = bodyStatements.scope.path.get('body')
|
|
} else {
|
|
bodyStatements = bodyStatements.get('body')
|
|
}
|
|
}
|
|
if (!bodyStatements || !Array.isArray(bodyStatements)) {
|
|
return
|
|
}
|
|
const statements = bodyStatements as NodePath<any>[]
|
|
for (const statement of statements) {
|
|
if (!statement.isVariableDeclaration()) {
|
|
continue
|
|
}
|
|
const declarations = statement.get('declarations')
|
|
if (!Array.isArray(declarations)) {
|
|
continue
|
|
}
|
|
const isBindingReferenced = (name: string) => {
|
|
return !!statement.scope.getBinding(name)?.referenced
|
|
}
|
|
for (const declarator of declarations) {
|
|
const id = declarator.get('id')
|
|
const init = declarator.node.init
|
|
if (Array.isArray(id) || Array.isArray(init)) {
|
|
continue
|
|
}
|
|
const shouldRemove = (() => {
|
|
const isHook =
|
|
init &&
|
|
t.isCallExpression(init) &&
|
|
t.isIdentifier(init.callee) &&
|
|
hooks[init.callee.name]
|
|
if (!isHook) {
|
|
return false
|
|
}
|
|
if (t.isIdentifier(id.node)) {
|
|
// remove "const media = useMedia()"
|
|
const name = id.node.name
|
|
return !isBindingReferenced(name)
|
|
}
|
|
if (t.isObjectPattern(id.node)) {
|
|
// remove "const { sm } = useMedia()"
|
|
const propPaths = id.get('properties') as NodePath<any>[]
|
|
return propPaths.every((prop) => {
|
|
if (!prop.isObjectProperty()) return false
|
|
const value = prop.get('value')
|
|
if (Array.isArray(value) || !value.isIdentifier()) return false
|
|
const name = value.node.name
|
|
return !isBindingReferenced(name)
|
|
})
|
|
}
|
|
return false
|
|
})()
|
|
if (shouldRemove) {
|
|
declarator.remove()
|
|
if (shouldPrintDebug) {
|
|
console.info(` [🪝] removed ${id.node['name'] ?? ''}`)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|