Skip to content

chore(scripts): add script to update internal versions to asterisk #3214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
9ef6f27
chore(scripts): add update-versions-asterisk folder with index.ts
trivikr Jan 19, 2022
3bebfd0
chore(package.json): add script update:versions:asterisk
trivikr Jan 19, 2022
07fdfb3
fix(scripts): add execute permission for update-versions-asterisk script
trivikr Jan 19, 2022
3a3fd8f
chore(scripts): add script to update internal versions to asterisk
trivikr Jan 20, 2022
74f89e2
chore: yarn update:versions:asterisk
trivikr Jan 20, 2022
3ae4f4f
chore: update yarn.lock with --force
trivikr Jan 20, 2022
8fe4ae5
chore: revert update yarn.lock with --force
trivikr Jan 20, 2022
33d9493
chore: revert yarn update:versions:asterisk
trivikr Jan 20, 2022
c4c8641
chore(scripts): skip local path imports for internal deps
trivikr Jan 20, 2022
2ae12e2
chore(scripts): rename update:version:asterisk to :default
trivikr Jan 20, 2022
05fac9d
chore(scripts): add update:versions:exact
trivikr Jan 20, 2022
33adc5b
chore(scripts): skip peerDeps as they're not exact
trivikr Jan 20, 2022
5b0e5be
chore(scripts): use flatMap in exact.ts
trivikr Jan 20, 2022
5587bbc
chore(scripts): add utility getWorkspacePaths
trivikr Jan 20, 2022
6c2b4b8
chore(scripts): add utility getPackageNameToVersionHash
trivikr Jan 20, 2022
92e54cc
chore(scripts): add utility getPackageNameToDefaultHash
trivikr Jan 20, 2022
e1fc88a
chore(scripts): add utility getUpdatedPackageJson
trivikr Jan 20, 2022
e8f8b02
chore(scripts): add utility updateVersions
trivikr Jan 20, 2022
da3ee21
chore(scripts): update utility file names
trivikr Jan 20, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
"test:server-protocols": "yarn build:server-protocols && lerna run test --scope '@aws-sdk/*-server'",
"test:size": "cd scripts/benchmark-size/runner && yarn && ./cli.ts",
"test:unit": "jest --config jest.config.js",
"test:versions": "jest --config tests/versions/jest.config.js tests/versions/index.spec.ts"
"test:versions": "jest --config tests/versions/jest.config.js tests/versions/index.spec.ts",
"update:versions:default": "./scripts/update-versions/default.ts",
"update:versions:exact": "./scripts/update-versions/exact.ts"
},
"repository": {
"type": "git",
Expand Down
9 changes: 9 additions & 0 deletions scripts/update-versions/default.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env ts-node

// Updates versions for internal packages `@aws-sdk/*` to `*`
// in dependencies/devDependencies/peerDependencies

import { getDepToDefaultVersionHash } from "./getDepToDefaultVersionHash";
import { updateVersions } from "./updateVersions";

updateVersions(getDepToDefaultVersionHash());
9 changes: 9 additions & 0 deletions scripts/update-versions/exact.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env ts-node

// Updates versions for internal packages `@aws-sdk/*` to exact versions
// in dependencies/devDependencies/peerDependencies

import { getDepToExactVersionHash } from "./getDepToExactVersionHash";
import { updateVersions } from "./updateVersions";

updateVersions(getDepToExactVersionHash());
12 changes: 12 additions & 0 deletions scripts/update-versions/getDepToDefaultVersionHash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { basename } from "path";

import { getWorkspacePaths } from "./getWorkspacePaths";

export const getDepToDefaultVersionHash = () =>
getWorkspacePaths().reduce(
(acc, workspacePath) => ({
...acc,
[`@aws-sdk/${basename(workspacePath)}`]: "*",
}),
{}
);
14 changes: 14 additions & 0 deletions scripts/update-versions/getDepToExactVersionHash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { readFileSync } from "fs";
import { basename, join } from "path";

import { getWorkspacePaths } from "./getWorkspacePaths";

export const getDepToExactVersionHash = () =>
getWorkspacePaths().reduce((acc, workspacePath) => {
const packageJsonPath = join(workspacePath, "package.json");
const packageJson = JSON.parse(readFileSync(packageJsonPath).toString());
return {
...acc,
[`@aws-sdk/${basename(workspacePath)}`]: packageJson.version,
};
}, {});
12 changes: 12 additions & 0 deletions scripts/update-versions/getUpdatedPackageJson.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { getUpdatedPackageJsonSection } from "./getUpdatedPackageJsonSection";

export const getUpdatedPackageJson = (packageJson, depToVersionHash) =>
["dependencies", "devDependencies"]
.filter((sectionName) => sectionName in packageJson)
.reduce(
(acc, sectionName) => ({
...acc,
[sectionName]: getUpdatedPackageJsonSection(packageJson[sectionName], depToVersionHash),
}),
packageJson
);
7 changes: 7 additions & 0 deletions scripts/update-versions/getUpdatedPackageJsonSection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const getUpdatedPackageJsonSection = (
section: { [key: string]: string },
depToVersionHash: { [key: string]: string }
) =>
Object.entries(section)
.filter(([key, value]) => key.startsWith("@aws-sdk/") && !value.startsWith("file:"))
.reduce((acc, [key, value]) => ({ ...acc, [key]: depToVersionHash[key] || value }), section);
17 changes: 17 additions & 0 deletions scripts/update-versions/getWorkspacePaths.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { readdirSync, readFileSync } from "fs";
import { join } from "path";

export const getWorkspacePaths = () => {
const rootDir = join(__dirname, "..", "..");
const packageJsonPath = join(rootDir, "package.json");
const packageJson = JSON.parse(readFileSync(packageJsonPath).toString());

return packageJson.workspaces.packages
.map((dir: string) => dir.replace("/*", ""))
.flatMap((workspacesDir) =>
readdirSync(join(rootDir, workspacesDir), { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
.map((dirent) => dirent.name)
.map((workspaceDir) => join(rootDir, workspacesDir, workspaceDir))
);
};
14 changes: 14 additions & 0 deletions scripts/update-versions/updateVersions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { readFileSync, writeFileSync } from "fs";
import { join } from "path";

import { getUpdatedPackageJson } from "./getUpdatedPackageJson";
import { getWorkspacePaths } from "./getWorkspacePaths";

export const updateVersions = (depToVersionHash) => {
getWorkspacePaths().forEach((workspacePath) => {
const packageJsonPath = join(workspacePath, "package.json");
const packageJson = JSON.parse(readFileSync(packageJsonPath).toString());
const updatedPackageJson = getUpdatedPackageJson(packageJson, depToVersionHash);
writeFileSync(packageJsonPath, JSON.stringify(updatedPackageJson, null, 2).concat(`\n`));
});
};