|
2 | 2 |
|
3 | 3 | // Updates versions for internal packages `@aws-sdk/*` to `*`
|
4 | 4 | // 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