Skip to content

Commit c237972

Browse files
authored
fix(scripts): convert update:versions scripts to mjs (#3226)
1 parent 332ae9a commit c237972

9 files changed

+24
-19
lines changed

Diff for: package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
"test:size": "cd scripts/benchmark-size/runner && yarn && ./cli.ts",
3939
"test:unit": "jest --config jest.config.js",
4040
"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"
41+
"update:versions:default": "node --es-module-specifier-resolution=node ./scripts/update-versions/default.mjs",
42+
"update:versions:current": "node --es-module-specifier-resolution=node ./scripts/update-versions/current.mjs"
4343
},
4444
"repository": {
4545
"type": "git",
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#!/usr/bin/env ts-node
1+
// @ts-check
22

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

6-
import { getDepToCurrentVersionHash } from "./getDepToCurrentVersionHash";
7-
import { updateVersions } from "./updateVersions";
6+
import { getDepToCurrentVersionHash } from "./getDepToCurrentVersionHash.mjs";
7+
import { updateVersions } from "./updateVersions.mjs";
88

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

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

6-
import { getDepToDefaultVersionHash } from "./getDepToDefaultVersionHash";
7-
import { updateVersions } from "./updateVersions";
6+
import { getDepToDefaultVersionHash } from "./getDepToDefaultVersionHash.mjs";
7+
import { updateVersions } from "./updateVersions.mjs";
88

99
updateVersions(getDepToDefaultVersionHash());

Diff for: scripts/update-versions/getDepToCurrentVersionHash.ts renamed to scripts/update-versions/getDepToCurrentVersionHash.mjs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
// @ts-check
12
import { readFileSync } from "fs";
23
import { basename, join } from "path";
34

4-
import { getWorkspacePaths } from "./getWorkspacePaths";
5+
import { getWorkspacePaths } from "./getWorkspacePaths.mjs";
56

67
export const getDepToCurrentVersionHash = () =>
78
getWorkspacePaths().reduce((acc, workspacePath) => {

Diff for: scripts/update-versions/getDepToDefaultVersionHash.ts renamed to scripts/update-versions/getDepToDefaultVersionHash.mjs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
// @ts-check
12
import { basename } from "path";
23

3-
import { getWorkspacePaths } from "./getWorkspacePaths";
4+
import { getWorkspacePaths } from "./getWorkspacePaths.mjs";
45

56
export const getDepToDefaultVersionHash = () =>
67
getWorkspacePaths().reduce(

Diff for: scripts/update-versions/getUpdatedPackageJson.ts renamed to scripts/update-versions/getUpdatedPackageJson.mjs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { getUpdatedPackageJsonSection } from "./getUpdatedPackageJsonSection";
1+
// @ts-check
2+
import { getUpdatedPackageJsonSection } from "./getUpdatedPackageJsonSection.mjs";
23

34
export const getUpdatedPackageJson = (packageJson, depToVersionHash) =>
45
["dependencies", "devDependencies"]
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
export const getUpdatedPackageJsonSection = (
2-
section: { [key: string]: string },
3-
depToVersionHash: { [key: string]: string }
4-
) =>
1+
// @ts-check
2+
export const getUpdatedPackageJsonSection = (section, depToVersionHash) =>
53
Object.entries(section)
64
.filter(([key, value]) => key.startsWith("@aws-sdk/") && !value.startsWith("file:"))
75
.reduce((acc, [key, value]) => ({ ...acc, [key]: depToVersionHash[key] || value }), section);

Diff for: scripts/update-versions/getWorkspacePaths.ts renamed to scripts/update-versions/getWorkspacePaths.mjs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
// @ts-check
12
import { readdirSync, readFileSync } from "fs";
2-
import { join } from "path";
3+
import { dirname, join } from "path";
4+
import { fileURLToPath } from "url";
35

46
export const getWorkspacePaths = () => {
7+
const __dirname = dirname(fileURLToPath(import.meta.url));
58
const rootDir = join(__dirname, "..", "..");
69
const packageJsonPath = join(rootDir, "package.json");
710
const packageJson = JSON.parse(readFileSync(packageJsonPath).toString());
811

912
return packageJson.workspaces.packages
10-
.map((dir: string) => dir.replace("/*", ""))
13+
.map((dir) => dir.replace("/*", ""))
1114
.flatMap((workspacesDir) =>
1215
readdirSync(join(rootDir, workspacesDir), { withFileTypes: true })
1316
.filter((dirent) => dirent.isDirectory())

Diff for: scripts/update-versions/updateVersions.ts renamed to scripts/update-versions/updateVersions.mjs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
// @ts-check
12
import { readFileSync, writeFileSync } from "fs";
23
import { join } from "path";
34

4-
import { getUpdatedPackageJson } from "./getUpdatedPackageJson";
5-
import { getWorkspacePaths } from "./getWorkspacePaths";
5+
import { getUpdatedPackageJson } from "./getUpdatedPackageJson.mjs";
6+
import { getWorkspacePaths } from "./getWorkspacePaths.mjs";
67

78
export const updateVersions = (depToVersionHash) => {
89
getWorkspacePaths().forEach((workspacePath) => {

0 commit comments

Comments
 (0)