Skip to content

Commit 6126308

Browse files
committed
ci: divvy up queue
Signed-off-by: Logan McAnsh <[email protected]>
1 parent 44f6d60 commit 6126308

File tree

1 file changed

+43
-29
lines changed

1 file changed

+43
-29
lines changed

__scripts/test.mjs

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ const concurrency = os.cpus().length;
1212

1313
console.log({ concurrency });
1414

15-
const queue = new PQueue({ concurrency, autoStart: false });
15+
let installQueue = new PQueue({ concurrency, autoStart: false });
16+
let buildQueue = new PQueue({ concurrency, autoStart: false });
17+
let typecheckQueue = new PQueue({ concurrency, autoStart: false });
1618

1719
const TO_IGNORE = new Set([
1820
"__scripts",
@@ -59,45 +61,41 @@ const list = new Intl.ListFormat("en", { style: "long", type: "conjunction" });
5961
console.log(`Testing changed examples: ${list.format(examples)}`);
6062

6163
for (const example of examples) {
62-
queue.add(async () => {
63-
const pkgJson = await PackageJson.load(example);
64+
const pkgJson = await PackageJson.load(example);
6465

65-
/** @type {import('execa').Options} */
66-
const options = { cwd: example, reject: false };
66+
/** @type {import('execa').Options} */
67+
const options = { cwd: example, reject: false };
6768

68-
const pm = pnpmExamples.has(example)
69-
? "pnpm"
70-
: yarnExamples.has(example)
71-
? "yarn"
72-
: "npm";
69+
const pm = pnpmExamples.has(example)
70+
? "pnpm"
71+
: yarnExamples.has(example)
72+
? "yarn"
73+
: "npm";
7374

75+
installQueue.add(async () => {
7476
const hasSetup = !!pkgJson.content.scripts?.__setup;
7577

7678
if (hasSetup) {
7779
console.log("🔧\u00A0Running setup script for", example);
7880
const setupResult = await execa(pm, ["run", "__setup"], options);
7981
if (setupResult.exitCode) {
8082
console.error(setupResult.stderr);
81-
throw new Error(`🚨\u00A0Error running setup script for ${example}`);
83+
throw new Error(`Error running setup script for ${example}`);
8284
}
8385
}
8486

8587
console.log(`📥\u00A0Installing ${example} with "${pm}"`);
86-
/** @type {import('execa').ExecaChildProcess<string>} */
87-
let installResult;
88-
if (pm === "npm") {
89-
installResult = await execa(
90-
pm,
91-
["--silent", "--legacy-peer-deps"],
92-
options
93-
);
94-
} else {
95-
installResult = await execa(pm, ["--silent"], options);
96-
}
88+
let installResult = await execa(
89+
pm,
90+
pm === "npm"
91+
? ["install", "--silent", "--legacy-peer-deps"]
92+
: ["install", "--silent"],
93+
options
94+
);
9795

9896
if (installResult.exitCode) {
9997
console.error(installResult.stderr);
100-
throw new Error(`🚨\u00A0Error installing ${example}`);
98+
throw new Error(`Error installing ${example}`);
10199
}
102100

103101
const hasPrisma = fse.existsSync(
@@ -114,29 +112,45 @@ for (const example of examples) {
114112

115113
if (prismaGenerateCommand.exitCode) {
116114
console.error(prismaGenerateCommand.stderr);
117-
throw new Error(`🚨\u00A0Error generating prisma types for ${example}`);
115+
throw new Error(`Error generating prisma types for ${example}`);
118116
}
119117
}
118+
});
120119

120+
buildQueue.add(async () => {
121121
console.log(`📦\u00A0Building ${example}`);
122122
const buildResult = await execa(pm, ["run", "build"], options);
123123

124124
if (buildResult.exitCode) {
125125
console.error(buildResult.stderr);
126-
throw new Error(`🚨\u00A0Error building ${example}`);
126+
throw new Error(`Error building ${example}`);
127127
}
128+
});
128129

130+
typecheckQueue.add(async () => {
129131
console.log(`🕵️\u00A0Typechecking ${example}`);
130132
const typecheckResult = await execa(pm, ["run", "typecheck"], options);
131133

132134
if (typecheckResult.exitCode) {
133135
console.error(typecheckResult.stderr);
134-
throw new Error(`🚨\u00A0Error typechecking ${example}`);
136+
throw new Error(`Error typechecking ${example}`);
135137
}
136138
});
137139
}
138140

139-
queue.start();
140-
queue.on("error", (error) => {
141-
console.error("🚨", error);
141+
installQueue.start();
142+
installQueue.on("error", (error) => console.error("🚨", error));
143+
144+
installQueue.on("empty", () => {
145+
console.log(`installQueue is complete, moving on to buildQueue`);
146+
return buildQueue.start();
147+
});
148+
149+
buildQueue.on("empty", () => {
150+
console.log(`buildQueue is complete, moving on to typecheckQueue`);
151+
return typecheckQueue.start();
142152
});
153+
154+
buildQueue.on("error", (error) => console.error("🚨", error));
155+
156+
typecheckQueue.on("error", (error) => console.error("🚨", error));

0 commit comments

Comments
 (0)