Skip to content

Commit

Permalink
Add prepublish script to test changed package names exist on npm
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Nov 5, 2024
1 parent 3cafbf5 commit be7b461
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"generate:map": "tsx scripts/generateClientTypesMap",
"generate:tests": "tsx scripts/generateNewClientTests",
"lint": "biome lint --write",
"prepublishOnly": "tsx scripts/testChangedPackageNames",
"release": "npm run build && changeset publish",
"test": "vitest"
},
Expand Down
29 changes: 29 additions & 0 deletions scripts/testChangedPackageNames/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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_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 tempDir = await mkdtemp(join(tmpdir(), "testChangedPackageNames-"));
await execAsync("npm install aws-sdk-js-codemod@latest", { cwd: tempDir });

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

const changedPackageNames = Object.keys(PACKAGE_NAMES_MAP_TO_PUBLISH)
.filter((key) => PACKAGE_NAMES_MAP_TO_PUBLISH[key] !== PACKAGE_NAMES_MAP_LATEST[key])
.map((key) => PACKAGE_NAMES_MAP_TO_PUBLISH[key]);

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`);
}
})();

0 comments on commit be7b461

Please sign in to comment.