// `prepack` guard for `@tlecommunity/super-ui`. // // The package is published as a single self-contained tarball: every third-party // runtime dependency of the bundled workspaces (`super-cli`, `super-core`, // `super-tasks`) must be hoisted into the root `dependencies` (npm does not // recurse into a bundled package's own manifest on the consumer side), and the // bundled workspaces must carry a real `version` or `npm pack` refuses them. // This script fails the pack early, with a pointed message, when that drifts. import { readFileSync, existsSync, readdirSync } from 'node:fs' import path from 'node:path' import { fileURLToPath } from 'node:url' const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..') const problems = [] const readJson = (rel) => JSON.parse(readFileSync(path.join(root, rel), 'utf8')) const rootPkg = readJson('package.json') const rootDeps = rootPkg.dependencies ?? {} const bundled = rootPkg.bundleDependencies ?? rootPkg.bundledDependencies ?? [] const workspaceDirs = { '@tlecommunity/super-cli': 'packages/cli', '@tlecommunity/super-core': 'packages/core', '@tlecommunity/super-tasks': 'packages/tasks', } for (const name of [ '@tlecommunity/super-cli', '@tlecommunity/super-core', '@tlecommunity/super-tasks', ]) { if (!bundled.includes(name)) { problems.push(`bundleDependencies is missing "${name}"`) } } for (const [name, dir] of Object.entries(workspaceDirs)) { const pkg = readJson(path.join(dir, 'package.json')) if (!pkg.name || !pkg.version) { problems.push( `${dir}/package.json needs both "name" and "version" to be bundled (npm pack rejects it otherwise)` ) } for (const dep of Object.keys(pkg.dependencies ?? {})) { if (dep.startsWith('@tlecommunity/super-')) continue // bundled sibling if (!(dep in rootDeps)) { problems.push( `"${dep}" is a dependency of ${name} but is not in the root "dependencies" - a consumer install would not get it` ) } } const nm = path.join(root, dir, 'node_modules') if (existsSync(nm)) { const stray = readdirSync(nm).filter((entry) => entry !== '.vite' && !entry.startsWith('.')) if (stray.length) { problems.push( `${dir}/node_modules contains ${stray.join(', ')} - these would be bundled into the tarball; run a clean "npm ci" at the root first` ) } } } if (problems.length) { console.error('check-publishable: cannot pack @tlecommunity/super-ui\n') for (const p of problems) console.error(` - ${p}`) console.error('') process.exit(1) } console.log('check-publishable: ok')