mirror of
https://github.com/larvit/adf-codec.git
synced 2026-11-20 15:15:44 +01:00
Measure each package as a namespace so default exports count, add the loaded JavaScript to the WebAssembly row, drop the growth claim
This commit is contained in:
@@ -4,6 +4,7 @@ import { gzipSync } from "node:zlib";
|
||||
|
||||
const bytesPerKilobyte = 1000;
|
||||
|
||||
// A namespace export keeps default exports and same-named exports, which a star re-export drops.
|
||||
// What a consumer's bundler ships for the whole of the packages: their code and dependencies, minified, gzipped.
|
||||
export const minifiedGzippedBytes = async (resolveDir, specifiers) => {
|
||||
const { outputFiles } = await build({
|
||||
@@ -12,7 +13,7 @@ export const minifiedGzippedBytes = async (resolveDir, specifiers) => {
|
||||
logLevel: "silent",
|
||||
minify: true,
|
||||
platform: "node",
|
||||
stdin: { contents: specifiers.map((specifier) => `export * from ${JSON.stringify(specifier)};`).join("\n"), resolveDir },
|
||||
stdin: { contents: specifiers.map((specifier, i) => `import * as m${i} from ${JSON.stringify(specifier)}; export { m${i} };`).join("\n"), resolveDir },
|
||||
write: false,
|
||||
});
|
||||
return gzipSync(outputFiles[0].contents, { level: 9 }).length;
|
||||
|
||||
@@ -34,6 +34,17 @@ test("minified size counts every package it is given", async () => {
|
||||
assert.ok(await minifiedGzippedBytes(dir, ["./one.js", "./two.js"]) > await minifiedGzippedBytes(dir, ["./one.js"]) + 500);
|
||||
});
|
||||
|
||||
test("minified size counts a default export and exports two packages share by name", async () => {
|
||||
const dir = fixture({
|
||||
"first.js": `export const same = ${JSON.stringify(Array.from({ length: 200 }, (_, i) => (i * 2654435761 % 4294967296).toString(36)))};`,
|
||||
"second.js": `export const same = ${JSON.stringify(Array.from({ length: 200 }, (_, i) => (i * 40503 % 4294967296 * 65537).toString(36)))};`,
|
||||
"only-default.js": `export default ${JSON.stringify(Array.from({ length: 200 }, (_, i) => (i * 69069 % 4294967296 * 97).toString(36)))};`,
|
||||
});
|
||||
const first = await minifiedGzippedBytes(dir, ["./first.js"]);
|
||||
assert.ok(await minifiedGzippedBytes(dir, ["./first.js", "./second.js"]) > first + 500);
|
||||
assert.ok(await minifiedGzippedBytes(dir, ["./only-default.js"]) > 500);
|
||||
});
|
||||
|
||||
test("minified size counts the dependencies a bundler pulls in", async () => {
|
||||
const alone = fixture({ "entry.js": "export const a = 1;" });
|
||||
const withDependency = fixture({
|
||||
|
||||
Reference in New Issue
Block a user