From 525adef67c1b065aebebf57803bdda090a2673e2 Mon Sep 17 00:00:00 2001 From: NullVoxPopuli Date: Sat, 18 Jun 2022 08:41:31 -0400 Subject: [PATCH] chore(internal): copy over estimate-bytes improvements from glint/v5 branch --- .gitignore | 1 + build/estimate-bytes/index.js | 55 +++++++++++++++++++++++++++++++---- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 30f9e439d..a2ebde9f6 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ tsconfig.tsbuildinfo node_modules/ # misc +.vscode .env* .pnp* .sass-cache diff --git a/build/estimate-bytes/index.js b/build/estimate-bytes/index.js index 7ab7bc96d..2319a3637 100644 --- a/build/estimate-bytes/index.js +++ b/build/estimate-bytes/index.js @@ -11,17 +11,32 @@ import filesize from 'filesize'; 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 packageJsonPath = path.join(root, 'ember-resources/package.json'); + +let packageJson; + +const config = { + bundles: { + 'index.js': { + alias: '.', + // Uncomment in v5 + // nest: ['core/index.js', 'util/function-resource.js'] + }, + 'core/index.js': { alias: 'core' }, + 'util/*.js': {}, + } +} /** * 1. Create bundles * 2. Minify * 3. Find gzip + brotli sizes */ async function collectStats() { + packageJson = JSON.parse((await fs.readFile(packageJsonPath)).toString()); + let { path: tmp } = await tmpDir(); + let bundlePatterns = Object.keys(config.bundles); let originalDistPaths = await globby(bundlePatterns.map((p) => path.join(dist, p))); let stats = {}; @@ -44,10 +59,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); @@ -56,6 +89,11 @@ async function collectStats() { } async function bundle(entry, outFile) { + let externals = [ + ...Object.keys(packageJson.dependencies || {}), + ...Object.keys(packageJson.peerDependencies || {}) + ]; + /** * Utils are one file */ @@ -67,10 +105,17 @@ async function bundle(entry, outFile) { outfile: outFile, bundle: true, external: [ + ...externals, + 'ember', '@ember/application', '@ember/debug', '@ember/helper', '@ember/destroyable', + '@ember/object', + '@ember/runloop', + '@ember/test', + '@embroider/macros', + '@glimmer/component', '@glimmer/tracking', ], });