27 lines
1.1 KiB
TypeScript
27 lines
1.1 KiB
TypeScript
import { getPackageInfo } from "@workshop/shared/packages"
|
|
import { test, expect } from "bun:test"
|
|
import { basename } from "node:path"
|
|
import { ensure } from "@workshop/shared/utils"
|
|
|
|
test("verify all package.json", async () => {
|
|
const packageInfo = await getPackageInfo()
|
|
const mainPackageFile = await Bun.file("package.json")
|
|
const mainPackageJson = await mainPackageFile.json()
|
|
const catalog = mainPackageJson.workshop?.catalog ?? {}
|
|
|
|
for (const { json, path } of packageInfo) {
|
|
const dirname = basename(path)
|
|
ensure(json, `package.json in ${dirname} must exist`)
|
|
|
|
const unscopedName = json.name.replace("@workshop/", "")
|
|
expect(unscopedName, `Name in package.json must match the dir name`).toBe(dirname)
|
|
|
|
const dependencies = { ...json.dependencies, ...json.devDependencies }
|
|
Object.entries(dependencies).forEach(([dep, version]) => {
|
|
if (catalog[dep]) {
|
|
expect(version, `Dependency "${dep}" in "${json.name}" must be "catalog:"`).toBe("catalog:") // The dep is in the catalog because having multiple versions causes hard to diagnose bugs
|
|
}
|
|
})
|
|
}
|
|
})
|