Repository navigation
Expand file tree
/
Copy pathyarn.config.cjs
More file actions
107 lines (98 loc) · 3.57 KB
/
Copy pathyarn.config.cjs
File metadata and controls
107 lines (98 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// @ts-check
/**
* @import { Yarn } from "@yarnpkg/types"
*/
const fs = require("node:fs/promises");
const { defineConfig } = require("@yarnpkg/types");
const { exec } = require("node:child_process");
const util = require("node:util");
const execPromise = util.promisify(exec);
/**
* @param {Yarn.Constraints.Context} ctx
*/
async function enforceCompilerMeta({ Yarn }) {
const EXPECTED_VERSION = "13.0.0-alpha.7";
for (const workspace of Yarn.workspaces()) {
const { ident } = workspace.pkg;
if (
ident === "rescript" ||
(workspace.cwd.startsWith("packages") && ident.startsWith("@rescript/"))
) {
workspace.set("version", EXPECTED_VERSION);
workspace.set("homepage", "https://rescript-lang.org");
workspace.set("bugs", "https://github.com/rescript-lang/rescript/issues");
workspace.set("repository", {
type: "git",
url: "git+https://github.com/rescript-lang/rescript.git",
});
workspace.set("author", {
name: "Hongbo Zhang",
email: "bobzhang1988@gmail.com",
});
workspace.set("maintainers", [
"Christoph Knittel (https://github.com/cknitt)",
"Cristiano Calcagno (https://github.com/cristianoc)",
"Dmitry Zakharov (https://github.com/DZakh)",
"Florian Hammerschmidt (https://github.com/fhammerschmidt)",
"Gabriel Nordeborn (https://github.com/zth)",
"Hyeseong Kim (https://github.com/cometkim)",
"Jaap Frolich (https://github.com/jfrolich)",
"Matthias Le Brun (https://github.com/bloodyowl)",
"Patrick Ecker (https://github.com/ryyppy)",
"Paul Tsnobiladzé (https://github.com/tsnobip)",
"Shulhi Sapli (https://github.com/shulhi)",
"Woonki Moon (https://github.com/mununki)",
]);
workspace.set("preferUnplugged", true);
}
}
const versionPattern = /^let version = "(?<version>[^"]+)"$/m;
/** @param {string} path */
async function enforceMlVersionFile(path) {
const content = await fs.readFile(path, "utf8");
if (process.argv.includes("--fix")) {
await fs.writeFile(
path,
content.replace(versionPattern, `let version = "${EXPECTED_VERSION}"`),
);
} else {
const foundVersion = content.match(versionPattern)?.groups?.version;
if (foundVersion !== EXPECTED_VERSION) {
Yarn.workspace().error(
`${path} file need to be fixed; expected ${EXPECTED_VERSION}, found ${foundVersion}.`,
);
}
}
}
const { compilerVersionFile } = await import("#dev/paths");
await enforceMlVersionFile(compilerVersionFile);
await enforceMlVersionFile("rewatch-ocaml/rewatch_version.ml");
const rewatchCargoFile = "rewatch/Cargo.toml";
const rewatchCargoContent = await fs.readFile(rewatchCargoFile, "utf8");
const rewatchVersionPattern = /^version = "(?<version>[^"]+)"$/m;
if (process.argv.includes("--fix")) {
await fs.writeFile(
rewatchCargoFile,
rewatchCargoContent.replace(
rewatchVersionPattern,
`version = "${EXPECTED_VERSION}"`,
),
);
await execPromise("cargo check", { cwd: "rewatch" });
} else {
const rewatchVersionMatch = rewatchCargoContent.match(
rewatchVersionPattern,
);
const foundRewatchVersion = rewatchVersionMatch?.groups?.version;
if (foundRewatchVersion !== EXPECTED_VERSION) {
Yarn.workspace().error(
`rewatch/Cargo.toml file need to be fixed; expected ${EXPECTED_VERSION}, found ${foundRewatchVersion}.`,
);
}
}
}
module.exports = defineConfig({
async constraints(ctx) {
await enforceCompilerMeta(ctx);
},
});