Skip to content

Commit

Permalink
chore(scripts): add dist-cjs byte count script
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed Apr 14, 2023
1 parent 45a5e24 commit a91e897
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 3 deletions.
8 changes: 7 additions & 1 deletion Makefile
Expand Up @@ -27,4 +27,10 @@ protocols:

server-protocols:
yarn generate-clients -s
yarn test:server-protocols
yarn test:server-protocols

bytes-cjs:
npx turbo run clean
node scripts/remote-cache/ start&
npx turbo run build:cjs --api="http://localhost:3000" --team="aws-sdk-js" --token="xyz"
node scripts/remote-cache/ stop
56 changes: 56 additions & 0 deletions scripts/byte-count/get-cjs-byte-count.js
@@ -0,0 +1,56 @@
#!/usr/bin/env node

const { join } = require("path");
const { readdirSync, statSync, rmSync } = require("fs");
const { removeSync } = require("fs-extra");
const { spawnProcess } = require("../utils/spawn-process");
const walk = require("../utils/walk");
const assert = require("assert");

/**
*
* Counts packed byte size for clients with only dist-cjs included.
*
*/

const locations = {};

locations.root = join(__dirname, "..", "..");
locations.clients = join(locations.root, "clients");

(async () => {
const packs = [];

for await (const clientFolderName of readdirSync(locations.clients)) {
const clientLocation = join(locations.clients, clientFolderName);
removeSync(join(clientLocation, "dist-types"));
removeSync(join(clientLocation, "dist-es"));

packs.push(
spawnProcess("npm", ["pack"], {
cwd: clientLocation,
})
);
}

await Promise.all(packs);

let bytes = 0;
const packFiles = [];

for await (file of walk(locations.clients)) {
if (file.includes("aws-sdk-client-")) {
bytes += statSync(file).size;
packFiles.push(file);
}
}

assert(6_000_000 < bytes, "byte count expected to be more than 6 million");
assert(bytes < 20_000_000, "byte count expected to be less than 20 million");

console.log("all clients dist-cjs total bytes:", bytes);

for (const packFile of packFiles) {
rmSync(packFile);
}
})();
6 changes: 4 additions & 2 deletions turbo.json
Expand Up @@ -8,7 +8,7 @@
},
"build:cjs": {
"outputs": ["dist-cjs/**"],
"dependsOn": ["build:types", "^build:types"]
"dependsOn": ["^build:types"]
},
"build:docs": {
"outputs": ["dist-cjs/**"],
Expand All @@ -30,7 +30,9 @@
"outputs": ["dist-types/ts3.4/**"],
"dependsOn": ["^build:types:downlevel"]
},
"clean": {},
"clean": {
"cache": false
},
"generate:client": {
"outputs": ["src/**", "package.json", "README.md"],
"inputs": []
Expand Down

0 comments on commit a91e897

Please sign in to comment.