From d14cc077a634ff14e5e47843c9ef3c592af60293 Mon Sep 17 00:00:00 2001 From: Sahejkm <163521239+Sahejkm@users.noreply.github.com> Date: Fri, 31 May 2024 20:59:34 +0800 Subject: [PATCH] [Lexical][Size-Checks] Measure both cjs/esm builds for regression checks (#6219) --- .github/workflows/tests-extended.yml | 1 + .size-limit.js | 59 ++++++++++++++-------------- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/.github/workflows/tests-extended.yml b/.github/workflows/tests-extended.yml index fbb522084a8..fd1fad554ea 100644 --- a/.github/workflows/tests-extended.yml +++ b/.github/workflows/tests-extended.yml @@ -6,6 +6,7 @@ on: paths-ignore: - 'packages/lexical-website/**' - 'packages/*/README.md' + - '.size-limit.js' concurrency: group: ${{ github.workflow }}-${{ github.ref }} diff --git a/.size-limit.js b/.size-limit.js index 4e7211782cb..6e709a0be8a 100644 --- a/.size-limit.js +++ b/.size-limit.js @@ -32,47 +32,48 @@ const path = require('node:path'); * as that is what was measured previously in #3600. */ const {packagesManager} = require('./scripts/shared/packagesManager'); -const alias = Object.fromEntries( - packagesManager - .getPublicPackages() - .flatMap((pkg) => - pkg - .getNormalizedNpmModuleExportEntries() - .map(([k, v]) => [k, pkg.resolve('dist', v.require.default)]), - ), -); +const getAliasType = (type) => + Object.fromEntries( + packagesManager + .getPublicPackages() + .flatMap((pkg) => + pkg + .getNormalizedNpmModuleExportEntries() + .map(([k, v]) => [k, pkg.resolve('dist', v[type].default)]), + ), + ); -const extendConfig = {resolve: {alias}}; -const modifyWebpackConfig = (config) => Object.assign(config, extendConfig); +const modifyWebpackConfigForType = (config, alias) => + Object.assign(config, {resolve: {alias}}); function sizeLimitConfig(pkg) { - return { - path: - alias[pkg] != null - ? alias[pkg] - : Object.keys(alias) - .filter((k) => k.startsWith(pkg)) - .map((k) => alias[k]), - modifyWebpackConfig, - running: false, - name: pkg, - }; + return ['require', 'import'].map((type) => { + const aliasType = getAliasType(type); + return { + path: + aliasType[pkg] != null + ? aliasType[pkg] + : Object.keys(aliasType) + .filter((k) => k.startsWith(pkg)) + .map((k) => aliasType[k]), + modifyWebpackConfig: (config) => + modifyWebpackConfigForType(config, aliasType), + running: false, + name: pkg + ' - ' + (type === 'require' ? 'cjs' : 'esm'), + }; + }); } /** - * These are the packages that were measured previously in #3600 * We could consider adding more packages and/or also measuring - * other build combinations such as esbuild/webpack, mjs/cjs, dev/prod, etc. + * other build combinations such as esbuild/webpack. * - * The current configuration measures only: webpack + cjs + prod. + * The current configuration measures only: webpack + esm/cjs + prod. * - * In order to also measure dev, we would want to change the size script in - * package.json to run build-release instead of build-prod so both - * dev and prod artifacts would be available. */ module.exports = [ 'lexical', '@lexical/rich-text', '@lexical/plain-text', '@lexical/react', -].map(sizeLimitConfig); +].flatMap(sizeLimitConfig);