|
| 1 | +import semver from "semver" |
| 2 | + |
| 3 | +import project from "./lib/project.js" |
| 4 | +import workspaces, { Package } from "./lib/workspaces.js" |
| 5 | + |
| 6 | +for (const workspace of Object.values(workspaces)) { |
| 7 | + log(workspace, "Processing.") |
| 8 | + |
| 9 | + if ("private" in workspace) { |
| 10 | + if (workspace.private === false) { |
| 11 | + error(workspace, `Remove "private: false".`) |
| 12 | + } else { |
| 13 | + warn(workspace, `Private.`) |
| 14 | + } |
| 15 | + } |
| 16 | + |
| 17 | + if (!workspace.private && workspace.directory !== "legacy") { |
| 18 | + const nameSplit = workspace.name.match(/(?:@([^/]+)\/)?([^/]+)/) |
| 19 | + |
| 20 | + if (!nameSplit) { |
| 21 | + error( |
| 22 | + workspace, |
| 23 | + `Package name must be in the format @<namespace>/<package>.`, |
| 24 | + ) |
| 25 | + } else { |
| 26 | + if (nameSplit[1] !== project.namespace) { |
| 27 | + error( |
| 28 | + workspace, |
| 29 | + `Package must be in the "${project.namespace}" namespace.`, |
| 30 | + ) |
| 31 | + } |
| 32 | + |
| 33 | + if (nameSplit[2] !== workspace.directory) { |
| 34 | + error(workspace, `Package name and directory must match.`) |
| 35 | + } |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + if (!semver.valid(workspace.version)) { |
| 40 | + error(workspace, `Invalid version: ${workspace.version}`) |
| 41 | + } |
| 42 | + |
| 43 | + if (workspace.dependencies) { |
| 44 | + for (const [name, range] of Object.entries(workspace.dependencies)) { |
| 45 | + if (workspaces[name]) { |
| 46 | + if (!semver.satisfies(workspaces[name].version, range)) { |
| 47 | + error(workspace, `Unsatisfiable package: ${name}@${range}`) |
| 48 | + } |
| 49 | + } |
| 50 | + } |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +/* eslint-disable no-console */ |
| 55 | +function log({ directory }: Package, message: string) { |
| 56 | + console.log(`${directory} - ${message}`) |
| 57 | +} |
| 58 | + |
| 59 | +function warn({ directory }: Package, message: string) { |
| 60 | + console.warn(`${directory} - ${message}`) |
| 61 | +} |
| 62 | + |
| 63 | +function error({ directory }: Package, message: string) { |
| 64 | + console.error(`${directory} - ${message}`) |
| 65 | + process.exitCode = 1 |
| 66 | +} |
0 commit comments