Skip to content

Commit e289c0a

Browse files
authored
chore(scripts): script to build only unbuilt packages (#7281)
1 parent ad71c7d commit e289c0a

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ turbo-build:
9999
tpk:
100100
npx turbo run build --filter='./packages/*'
101101

102+
# builds only packages that have no build at all.
103+
# for development only - packages may be stale.
104+
unbuilt:
105+
node scripts/build-only-unbuilt.js
106+
102107
# Clears the Turborepo local build cache
103108
turbo-clean:
104109
@read -p "Are you sure you want to delete your local cache? [y/N]: " ans && [ $${ans:-N} = y ]

scripts/build-only-unbuilt.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env node
2+
3+
/*
4+
usage: `make unbuilt`
5+
6+
This script builds only those packages that are not already built.
7+
This is for development when you need for example newly released clients to be built
8+
but do not need the actual latest build of every single client (slow).
9+
10+
As for why this is not a shell script, I found the combination of find with exec to be too slow.
11+
*/
12+
13+
/**
14+
* For reference, this is the equivalent shell command.
15+
* @type {string}
16+
*/
17+
void `find ./clients/client-*/ -type d -maxdepth 0 -exec test -d "{}/dist-types" \\; -exec sh -c "cd {} && yarn build" \\;`;
18+
19+
const path = require("node:path");
20+
const fs = require("node:fs");
21+
const { spawnProcess } = require("./utils/spawn-process");
22+
23+
const root = path.join(__dirname, "..");
24+
25+
const packageFolders = [
26+
...fs.readdirSync(path.join(root, "lib"), { withFileTypes: true }),
27+
...fs.readdirSync(path.join(root, "clients"), { withFileTypes: true }),
28+
...fs.readdirSync(path.join(root, "packages"), { withFileTypes: true }),
29+
...fs.readdirSync(path.join(root, "private"), { withFileTypes: true }),
30+
];
31+
32+
(async () => {
33+
for (const pkgFolder of packageFolders) {
34+
const isPackage = fs.existsSync(path.join(pkgFolder.path, pkgFolder.name, "package.json"));
35+
if (isPackage) {
36+
const cwd = path.join(pkgFolder.path, pkgFolder.name);
37+
const isBuilt = fs.existsSync(path.join(cwd, "dist-types"));
38+
const hasArtifacts = fs.existsSync(path.join(cwd, "tsconfig.json"));
39+
40+
if (!isBuilt && hasArtifacts) {
41+
console.log("Building", cwd);
42+
await spawnProcess("yarn", ["build"], {
43+
cwd,
44+
});
45+
}
46+
}
47+
}
48+
console.log("Done.");
49+
})();

0 commit comments

Comments
 (0)