Skip to content

Commit

Permalink
Add prerelease script to test updated identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Nov 7, 2024
1 parent 510d969 commit 22880f7
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 30 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"generate:map": "tsx scripts/generateClientTypesMap",
"generate:tests": "tsx scripts/generateNewClientTests",
"lint": "biome lint --write",
"release": "tsx scripts/testChangedPackageNames && npm run build && changeset publish",
"release": "tsx scripts/testUpdatedIdentifiers && npm run build && changeset publish",
"test": "vitest",
"version": "changeset version && npm i --package-lock-only"
},
Expand Down
29 changes: 0 additions & 29 deletions scripts/testChangedPackageNames/index.ts

This file was deleted.

52 changes: 52 additions & 0 deletions scripts/testUpdatedIdentifiers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { exec } from "node:child_process";
import { mkdtemp } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { promisify } from "node:util";
import {
CLIENT_NAMES_MAP as CLIENT_NAMES_MAP_TO_PUBLISH,
CLIENT_PACKAGE_NAMES_MAP as PACKAGE_NAMES_MAP_TO_PUBLISH,
} from "../../src/transforms/v2-to-v3/config";

const execAsync = promisify(exec);

(async () => {
// Create temporary directory
const tempDirCodemod = await mkdtemp(join(tmpdir(), "codemod-"));
await execAsync("npm install aws-sdk-js-codemod@latest", { cwd: tempDirCodemod });

const { CLIENT_NAMES_MAP, CLIENT_PACKAGE_NAMES_MAP } = await import(
join(tempDirCodemod, "node_modules/aws-sdk-js-codemod/dist/transforms/v2-to-v3/config")
);

const changedPackages = Object.entries(PACKAGE_NAMES_MAP_TO_PUBLISH).filter(
([key]) => PACKAGE_NAMES_MAP_TO_PUBLISH[key] !== CLIENT_PACKAGE_NAMES_MAP[key]
);

const changedPackageNames = Object.values(changedPackages);
console.log(`Changed package names: [ ${changedPackageNames.join(", ")} ]`);
for (const packageName of changedPackageNames) {
const npmPackageName = `@aws-sdk/${packageName}`;
await execAsync(`npm show ${npmPackageName} version`);
console.log(`${npmPackageName} exists`);
}

const changedClients = Object.entries(CLIENT_NAMES_MAP_TO_PUBLISH).filter(
([key]) => CLIENT_NAMES_MAP_TO_PUBLISH[key] !== CLIENT_NAMES_MAP[key]
);

console.log(`Changed clients: [ ${changedClients.map(([, value]) => value).join(", ")} ]`);
for (const [clientKey, clientName] of changedClients) {
const npmPackageName = `@aws-sdk/${PACKAGE_NAMES_MAP_TO_PUBLISH[clientKey]}`;
const tempDirClient = await mkdtemp(join(tmpdir(), "codemod-"));

const execOptions = { cwd: tempDirClient };
await execAsync(`npm install ${npmPackageName}`, execOptions);
await execAsync(
`echo 'import { ${clientName} } from "${npmPackageName}"' > index.mjs`,
execOptions
);
await execAsync("node index.mjs", execOptions);
console.log(`Client '${clientName}' exists in '${npmPackageName}'.`);
}
})();

0 comments on commit 22880f7

Please sign in to comment.