Skip to content

Commit

Permalink
chore(internal): copy over estimate-bytes improvements from glint/v5 …
Browse files Browse the repository at this point in the history
…branch
  • Loading branch information
NullVoxPopuli committed Jun 18, 2022
1 parent e8d80bc commit 8fc4f1f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ tsconfig.tsbuildinfo
node_modules/

# misc
.vscode
.env*
.pnp*
.sass-cache
Expand Down
35 changes: 31 additions & 4 deletions build/estimate-bytes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
const root = path.join(__dirname, '../..');
const dist = path.join(root, 'ember-resources/dist');

const bundlePatterns = ['core/index.js', 'util/*.js'];

const config = {
bundles: {
'index.js': {
alias: '.',
nest: ['core/index.js', 'util/function-resource.js']
},
'core/index.js': { alias: 'core' },
'util/*.js': {},
}
}
/**
* 1. Create bundles
* 2. Minify
Expand All @@ -22,6 +30,7 @@ const bundlePatterns = ['core/index.js', 'util/*.js'];
async function collectStats() {
let { path: tmp } = await tmpDir();

let bundlePatterns = Object.keys(config.bundles);
let originalDistPaths = await globby(bundlePatterns.map((p) => path.join(dist, p)));
let stats = {};

Expand All @@ -44,10 +53,28 @@ async function collectStats() {
output += '| | js | min | min + gzip | min + brotli |\n';
output += '|--| -- | --- | ---------- | ------------ |\n';

for (let [file, fileStats] of Object.entries(stats)) {
let rowFor = (file, fileStats, indent = '') => {
let { js, 'js.min': min, 'js.min.br': brotli, 'js.min.gz': gzip } = fileStats;

output += `| ${file} | ${js} | ${min} | ${gzip} | ${brotli} |\n`;
return `| ${indent}${file} | ${js} | ${min} | ${gzip} | ${brotli} |\n`;
}

for (let [file, fileStats] of Object.entries(stats)) {
output += rowFor(file, fileStats);

let relativeFile = file.replace(/^\//, '');
if (config.bundles[relativeFile]?.nest) {
let nest = config.bundles[relativeFile].nest;

for (let nested of nest) {
if (stats['/' + nested]) {
let isLast = nest.indexOf(nested) === nest.length - 1;
let glyph = isLast ? '└── ' : '├── ';

output += rowFor(nested, stats['/' + nested], glyph);
}
}
}
}

console.debug(output);
Expand Down

0 comments on commit 8fc4f1f

Please sign in to comment.