Skip to content

Commit

Permalink
fix(scripts): convert update:versions scripts to mjs (#3226)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Jan 21, 2022
1 parent 332ae9a commit c237972
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 19 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"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",
"update:versions:default": "./scripts/update-versions/default.ts",
"update:versions:current": "./scripts/update-versions/current.ts"
"update:versions:default": "node --es-module-specifier-resolution=node ./scripts/update-versions/default.mjs",
"update:versions:current": "node --es-module-specifier-resolution=node ./scripts/update-versions/current.mjs"
},
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env ts-node
// @ts-check

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

import { getDepToCurrentVersionHash } from "./getDepToCurrentVersionHash";
import { updateVersions } from "./updateVersions";
import { getDepToCurrentVersionHash } from "./getDepToCurrentVersionHash.mjs";
import { updateVersions } from "./updateVersions.mjs";

updateVersions(getDepToCurrentVersionHash());
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env ts-node
// @ts-check

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

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

updateVersions(getDepToDefaultVersionHash());
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// @ts-check
import { readFileSync } from "fs";
import { basename, join } from "path";

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

export const getDepToCurrentVersionHash = () =>
getWorkspacePaths().reduce((acc, workspacePath) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @ts-check
import { basename } from "path";

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

export const getDepToDefaultVersionHash = () =>
getWorkspacePaths().reduce(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getUpdatedPackageJsonSection } from "./getUpdatedPackageJsonSection";
// @ts-check
import { getUpdatedPackageJsonSection } from "./getUpdatedPackageJsonSection.mjs";

export const getUpdatedPackageJson = (packageJson, depToVersionHash) =>
["dependencies", "devDependencies"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
export const getUpdatedPackageJsonSection = (
section: { [key: string]: string },
depToVersionHash: { [key: string]: string }
) =>
// @ts-check
export const getUpdatedPackageJsonSection = (section, depToVersionHash) =>
Object.entries(section)
.filter(([key, value]) => key.startsWith("@aws-sdk/") && !value.startsWith("file:"))
.reduce((acc, [key, value]) => ({ ...acc, [key]: depToVersionHash[key] || value }), section);
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
// @ts-check
import { readdirSync, readFileSync } from "fs";
import { join } from "path";
import { dirname, join } from "path";
import { fileURLToPath } from "url";

export const getWorkspacePaths = () => {
const __dirname = dirname(fileURLToPath(import.meta.url));
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("/*", ""))
.map((dir) => dir.replace("/*", ""))
.flatMap((workspacesDir) =>
readdirSync(join(rootDir, workspacesDir), { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// @ts-check
import { readFileSync, writeFileSync } from "fs";
import { join } from "path";

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

export const updateVersions = (depToVersionHash) => {
getWorkspacePaths().forEach((workspacePath) => {
Expand Down

0 comments on commit c237972

Please sign in to comment.