/// const S = Smithers import { scopedShell } from '../../factory/scoped-shell.js' const Shell = scopedShell('packages/server') // packages/contract/PACKAGE.ts is the exemplar for the common shape; this file // follows it with one difference: build:types also runs tsc, so there is a // declarations target. The manifest's top-level `types` points at // types/index.d.ts, so the tsc emit is what npm consumers resolve. // Scripts with no target: `all` and `build` are nx aggregates the check // suite and the graph replace, `test` is `vitest --watch` (interactive), // `format`/`format:check` run `biome format`, which `biome check` covers, // and `package:up` is a dependency installer. const packageJson = S.file('package.json') const tsconfig = S.file('tsconfig.json') const tsupConfig = S.file('tsup.config.ts') const typedocConfig = S.file('typedoc.json') const vitestConfig = S.file('vitest.config.ts') const biomeConfig = S.file('biome.json') const rootBiomeConfig = S.file('//biome.json') // Sources and tests are separate groups so a spec edit re-keys the test // targets and nothing else. const srcs = S.Filegroup({ srcs: S.glob(['src/**', '!src/**/*.spec.ts', '!src/**/*.test.ts', '!src/**/__snapshots__/**']), }) const tests = S.Filegroup({ srcs: S.glob(['src/**/*.spec.ts', 'src/**/*.test.ts', 'src/**/__snapshots__/**']), }) // Workspace dependencies as data: the build outputs of every workspace:* // dependency in this manifest, in topological order. const deps = S.Filegroup({ srcs: [packageJson] }) // build:dist. const build = Shell.Build({ bin: S.NodeModule.Bin('tsup'), data: [srcs, deps, tsupConfig, tsconfig, packageJson], outDirs: ['dist'], }) // build:types, tsup half. const types = Shell.Build({ bin: S.NodeModule.Bin('tsup'), args: ['--dts-only'], data: [srcs, deps, tsupConfig, tsconfig, packageJson], outDirs: ['dist'], }) // build:types, tsc half: `tsc --emitDeclarationOnly --declaration` emits // into the tsconfig outDir (types/). const declarations = Shell.Build({ bin: S.NodeModule.Bin('typescript', 'tsc'), args: ['--emitDeclarationOnly', '--declaration'], data: [srcs, deps, tsconfig], outDirs: ['types'], }) // typecheck. tsconfig has no spec-file exclude, so tests are key material. const typecheck = Shell.Test({ bin: S.NodeModule.Bin('typescript', 'tsc'), args: ['--noEmit'], data: [srcs, tests, deps, tsconfig], }) // test:run. No spec file needs a live RPC; the WebSocket suite does bind a // real 127.0.0.1 listener, so loopback is allowed while egress stays denied. const test = Shell.Test({ bin: S.NodeModule.Bin('vitest'), args: ['run'], data: [srcs, tests, deps, vitestConfig, tsconfig], sandbox: { network: 'loopback' }, }) // test:coverage. This config's thresholds block sets `autoUpdate: true`, // which rewrites vitest.config.ts when coverage rises. That write lands // outside any declared write set, so the graph treats the config as input // only and the ratchet stays a local convenience. const testCoverage = Shell.Test({ bin: S.NodeModule.Bin('vitest'), args: ['run', '--coverage'], data: [srcs, tests, deps, vitestConfig, tsconfig], sandbox: { network: 'loopback' }, }) // The floors are vitest.config.ts's thresholds verbatim. const coverageGate = S.Alias(testCoverage) // generate:docs. const docs = Shell.Build({ bin: S.NodeModule.Bin('typedoc'), data: [srcs, deps, typedocConfig, packageJson], outDirs: ['docs'], }) // The publishable tarball over the manifest's files allowlist. const pack = S.Npm.Pack({ manifest: packageJson, data: [build, types, declarations, srcs], }) // lint:package. publint and attw run against the packed tarball, not the // source tree. const packageLint = Shell.Test({ command: 'pnpm exec publint --strict . && pnpm exec attw --pack .', data: [pack], }) // Semver as a gate: baseline is the last published @tevm/server // declarations from the registry, surface is this tree's emit. const apiCompat = S.Api.Compat({ baseline: S.Npm.Published({ manifest: packageJson }), surface: types, manifest: packageJson, }) // lint:deps. const depsLint = Shell.Test({ bin: S.NodeModule.Bin('depcheck'), data: [srcs, tests, packageJson], }) // lint:check. The package biome.json extends the root config, so both are // key material. const lint = Shell.Test({ bin: S.NodeModule.Bin('@biomejs/biome'), args: ['check', '.', '--verbose'], data: [srcs, tests, biomeConfig, rootBiomeConfig], }) // lint + format as one Diff: `biome check --write --unsafe` applies lint // fixes and formatting inside the package. const format = Shell.Diff({ bin: S.NodeModule.Bin('@biomejs/biome'), args: ['check', '.', '--write', '--unsafe'], data: [srcs, tests, biomeConfig, rootBiomeConfig], changes: ['**'], }) // clean. node_modules is left to the workspace's install layer. const clean = S.Clean({ targets: [build, types, declarations, testCoverage, docs], paths: ['dist', 'types', 'coverage', 'docs', 'artifacts', 'cache'], }) // Every check ci.yml runs for this package, as one suite: // `smthrs //packages/server:check`. const check = S.Suite({ tests: [lint, typecheck, test, coverageGate, depsLint, packageLint], }) export const Package = S.Package({ targets: { apiCompat, build, check, clean, coverageGate, declarations, depsLint, docs, format, lint, pack, packageLint, srcs, test, testCoverage, tests, typecheck, types, }, })