#!/usr/bin/env node /** * Install the packed package into fresh apps, the way a user would, and prove * it works. Run before publishing: * * npm run test:package # all scenarios * npm run test:package -- vite # one scenario: vite | plain | next * * 1. vite Vite + Tailwind v4 + strict TypeScript (library types checked too). * Must type-check, build and render without errors. * 2. plain React without Tailwind, using only the prebuilt styles.css. The * primary button must get its brand colour. * 3. next Next.js App Router. A Server Component imports the components; * `next build` must prerender it, which fails unless the component * modules are marked "use client". * * Apps are created under $TMPDIR/tansy-package-test and installed from npm. */ import { execSync } from 'node:child_process' import { mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs' import { createServer } from 'node:http' import { createRequire } from 'node:module' import { tmpdir } from 'node:os' import { dirname, extname, join, resolve } from 'node:path' import { fileURLToPath } from 'node:url' const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..') const PKG_DIR = join(ROOT, 'packages/ui') const WORK = join(tmpdir(), 'tansy-package-test') const only = process.argv[2] const require = createRequire(import.meta.url) const sh = (cmd, cwd) => execSync(cmd, { cwd, stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf8' }) const write = (dir, files) => { for (const [path, content] of Object.entries(files)) { mkdirSync(dirname(join(dir, path)), { recursive: true }) writeFileSync(join(dir, path), content.trimStart()) } } const log = (msg) => console.log(`[test:package] ${msg}`) // --- pack --------------------------------------------------------------------- rmSync(WORK, { recursive: true, force: true }) mkdirSync(WORK, { recursive: true }) log('building and packing @openkhalix/tansy-ui') sh('npm run build', PKG_DIR) const tarball = join(WORK, sh(`npm pack --pack-destination ${WORK}`, PKG_DIR).trim().split('\n').pop()) const { version } = JSON.parse(readFileSync(join(PKG_DIR, 'package.json'), 'utf8')) log(`packed ${tarball}`) const APP = ` import { Mail } from 'lucide-react' import { Badge, Button, Dialog, FeaturedInput, Select, Tabs, VERSION } from '@openkhalix/tansy-ui' export function Demo() { return (
tansy {VERSION} } />