|
1 |
| -module.exports = { |
| 1 | +const { defineConfig } = require("@yarnpkg/types"); |
| 2 | + |
| 3 | +module.exports = defineConfig({ |
2 | 4 | async constraints({ Yarn }) {
|
| 5 | + const rootWorkspace = Yarn.workspace({ cwd: "." }); |
| 6 | + if (rootWorkspace == null) { |
| 7 | + Yarn.workspace().error("Didn't find a root workspace?!"); |
| 8 | + return; |
| 9 | + } |
| 10 | + |
| 11 | + // Use ESM everywhere. |
3 | 12 | for (const workspace of Yarn.workspaces()) {
|
4 | 13 | workspace.set("type", "module");
|
5 | 14 | }
|
| 15 | + |
| 16 | + // Set a consistent repository for all workspaces. |
| 17 | + if (rootWorkspace.manifest.repository == null) { |
| 18 | + rootWorkspace.error("Missing repository specification!"); |
| 19 | + } |
| 20 | + for (const workspace of Yarn.workspaces()) { |
| 21 | + if (workspace.cwd !== ".") { |
| 22 | + workspace.set("repository.directory", workspace.cwd); |
| 23 | + workspace.set( |
| 24 | + "repository.type", |
| 25 | + rootWorkspace.manifest.repository.type, |
| 26 | + ); |
| 27 | + workspace.set("repository.url", rootWorkspace.manifest.repository.url); |
| 28 | + } else { |
| 29 | + workspace.unset("repository.directory"); |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + // Expect each workspace to either have a license or be private. |
| 34 | + for (const workspace of Yarn.workspaces()) { |
| 35 | + if (workspace.manifest.license == null && !workspace.manifest.private) { |
| 36 | + // Don't default since we want a human to make the call. |
| 37 | + workspace.error("Missing license for non-private workspace!"); |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + // Expect each workspace to specify a version, except for the root. |
| 42 | + for (const workspace of Yarn.workspaces()) { |
| 43 | + if (workspace.cwd !== ".") { |
| 44 | + workspace.set("version", workspace.manifest.version ?? "0.0.1"); |
| 45 | + } else { |
| 46 | + workspace.unset("version"); |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + // Explicitly specify whether the workspace is private or not. |
| 51 | + for (const workspace of Yarn.workspaces()) { |
| 52 | + workspace.set("private", !!workspace.manifest.private); |
| 53 | + } |
6 | 54 | },
|
7 |
| -}; |
| 55 | +}); |
0 commit comments