-
Notifications
You must be signed in to change notification settings - Fork 592
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(scripts): add dist-cjs byte count script
- Loading branch information
Showing
3 changed files
with
67 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters