Skip to content

Commit 3a3fd8f

Browse files
committed
chore(scripts): add script to update internal versions to asterisk
1 parent 07fdfb3 commit 3a3fd8f

File tree

1 file changed

+37
-0
lines changed
  • scripts/update-versions-asterisk

1 file changed

+37
-0
lines changed

scripts/update-versions-asterisk/index.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,40 @@
22

33
// Updates versions for internal packages `@aws-sdk/*` to `*`
44
// in dependencies/devDependencies/peerDependencies
5+
6+
import { readdirSync, readFileSync, writeFileSync } from "fs";
7+
import { join } from "path";
8+
9+
const rootDir = join(__dirname, "..", "..");
10+
const packageJsonPath = join(rootDir, "package.json");
11+
const packageJson = JSON.parse(readFileSync(packageJsonPath).toString());
12+
13+
const packages = packageJson.workspaces.packages;
14+
15+
const replaceInternalDepVersionWithAsterisk = (section) => {
16+
for (const name of Object.keys(section)) {
17+
if (name.startsWith("@aws-sdk/")) {
18+
section[name] = "*";
19+
}
20+
}
21+
};
22+
23+
packages
24+
.map((dir: string) => dir.replace("/*", ""))
25+
.forEach((workspacesDir: string) => {
26+
// Process each workspace in workspace directory
27+
readdirSync(join(rootDir, workspacesDir), { withFileTypes: true })
28+
.filter((dirent) => dirent.isDirectory())
29+
.map((dirent) => dirent.name)
30+
.forEach((workspaceDir) => {
31+
const cwd = join(rootDir, workspacesDir, workspaceDir);
32+
const packageJsonPath = join(cwd, "package.json");
33+
const packageJson = JSON.parse(readFileSync(packageJsonPath).toString());
34+
35+
["dependencies", "devDependencies", "peerDependencies"]
36+
.filter((section) => packageJson[section] !== undefined)
37+
.forEach((section) => replaceInternalDepVersionWithAsterisk(packageJson[section]));
38+
39+
writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2).concat(`\n`));
40+
});
41+
});

0 commit comments

Comments
 (0)