Skip to content

Commit a84c013

Browse files
authored
chore(scripts): update internal dependency versions (#3221)
1 parent dbb4a02 commit a84c013

9 files changed

+98
-2
lines changed

Diff for: package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
"test:server-protocols": "yarn build:server-protocols && lerna run test --scope '@aws-sdk/*-server'",
3838
"test:size": "cd scripts/benchmark-size/runner && yarn && ./cli.ts",
3939
"test:unit": "jest --config jest.config.js",
40-
"test:versions": "jest --config tests/versions/jest.config.js tests/versions/index.spec.ts"
40+
"test:versions": "jest --config tests/versions/jest.config.js tests/versions/index.spec.ts",
41+
"update:versions:default": "./scripts/update-versions/default.ts",
42+
"update:versions:current": "./scripts/update-versions/current.ts"
4143
},
4244
"repository": {
4345
"type": "git",
@@ -141,4 +143,4 @@
141143
],
142144
"**/*.{ts,js,md,json}": "prettier --write"
143145
}
144-
}
146+
}

Diff for: scripts/update-versions/current.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env ts-node
2+
3+
// Updates versions for internal packages `@aws-sdk/*` to exact versions
4+
// in dependencies/devDependencies/peerDependencies
5+
6+
import { getDepToCurrentVersionHash } from "./getDepToCurrentVersionHash";
7+
import { updateVersions } from "./updateVersions";
8+
9+
updateVersions(getDepToCurrentVersionHash());

Diff for: scripts/update-versions/default.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env ts-node
2+
3+
// Updates versions for internal packages `@aws-sdk/*` to `*`
4+
// in dependencies/devDependencies/peerDependencies
5+
6+
import { getDepToDefaultVersionHash } from "./getDepToDefaultVersionHash";
7+
import { updateVersions } from "./updateVersions";
8+
9+
updateVersions(getDepToDefaultVersionHash());
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { readFileSync } from "fs";
2+
import { basename, join } from "path";
3+
4+
import { getWorkspacePaths } from "./getWorkspacePaths";
5+
6+
export const getDepToCurrentVersionHash = () =>
7+
getWorkspacePaths().reduce((acc, workspacePath) => {
8+
const packageJsonPath = join(workspacePath, "package.json");
9+
const packageJson = JSON.parse(readFileSync(packageJsonPath).toString());
10+
return {
11+
...acc,
12+
[`@aws-sdk/${basename(workspacePath)}`]: packageJson.version,
13+
};
14+
}, {});
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { basename } from "path";
2+
3+
import { getWorkspacePaths } from "./getWorkspacePaths";
4+
5+
export const getDepToDefaultVersionHash = () =>
6+
getWorkspacePaths().reduce(
7+
(acc, workspacePath) => ({
8+
...acc,
9+
[`@aws-sdk/${basename(workspacePath)}`]: "*",
10+
}),
11+
{}
12+
);

Diff for: scripts/update-versions/getUpdatedPackageJson.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { getUpdatedPackageJsonSection } from "./getUpdatedPackageJsonSection";
2+
3+
export const getUpdatedPackageJson = (packageJson, depToVersionHash) =>
4+
["dependencies", "devDependencies"]
5+
.filter((sectionName) => sectionName in packageJson)
6+
.reduce(
7+
(acc, sectionName) => ({
8+
...acc,
9+
[sectionName]: getUpdatedPackageJsonSection(packageJson[sectionName], depToVersionHash),
10+
}),
11+
packageJson
12+
);
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const getUpdatedPackageJsonSection = (
2+
section: { [key: string]: string },
3+
depToVersionHash: { [key: string]: string }
4+
) =>
5+
Object.entries(section)
6+
.filter(([key, value]) => key.startsWith("@aws-sdk/") && !value.startsWith("file:"))
7+
.reduce((acc, [key, value]) => ({ ...acc, [key]: depToVersionHash[key] || value }), section);

Diff for: scripts/update-versions/getWorkspacePaths.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { readdirSync, readFileSync } from "fs";
2+
import { join } from "path";
3+
4+
export const getWorkspacePaths = () => {
5+
const rootDir = join(__dirname, "..", "..");
6+
const packageJsonPath = join(rootDir, "package.json");
7+
const packageJson = JSON.parse(readFileSync(packageJsonPath).toString());
8+
9+
return packageJson.workspaces.packages
10+
.map((dir: string) => dir.replace("/*", ""))
11+
.flatMap((workspacesDir) =>
12+
readdirSync(join(rootDir, workspacesDir), { withFileTypes: true })
13+
.filter((dirent) => dirent.isDirectory())
14+
.map((dirent) => dirent.name)
15+
.map((workspaceDir) => join(rootDir, workspacesDir, workspaceDir))
16+
);
17+
};

Diff for: scripts/update-versions/updateVersions.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { readFileSync, writeFileSync } from "fs";
2+
import { join } from "path";
3+
4+
import { getUpdatedPackageJson } from "./getUpdatedPackageJson";
5+
import { getWorkspacePaths } from "./getWorkspacePaths";
6+
7+
export const updateVersions = (depToVersionHash) => {
8+
getWorkspacePaths().forEach((workspacePath) => {
9+
const packageJsonPath = join(workspacePath, "package.json");
10+
const packageJson = JSON.parse(readFileSync(packageJsonPath).toString());
11+
const updatedPackageJson = getUpdatedPackageJson(packageJson, depToVersionHash);
12+
writeFileSync(packageJsonPath, JSON.stringify(updatedPackageJson, null, 2).concat(`\n`));
13+
});
14+
};

0 commit comments

Comments
 (0)