Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix size-limit config #4415

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions .github/workflows/size.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,42 @@
name: size
on:
pull_request:
branches:
- master
- 'feature/infinite-query-integration'
permissions:
pull-requests: write
name: Check Bundle-Size

on: [push, pull_request, workflow_dispatch]

jobs:
size:
runs-on: ubuntu-latest
name: Check Bundle-Size

strategy:
matrix:
node: ['22.x']

env:
CI_JOB_NUMBER: 1
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: 'yarn'
check-latest: true

- run: yarn install

- uses: EskiMojo14/size-limit-action@v2
id: size
continue-on-error: true

with:
directory: packages/toolkit
github_token: ${{ secrets.GITHUB_TOKEN }}
build_script: build-only
build_script: build
package_manager: yarn
size_margin: non-zero

- name: Run size-limit locally
if: ${{ success() && steps.size.outcome == 'failure' }}
working-directory: packages/toolkit
run: |
yarn run build
yarn run size
22 changes: 0 additions & 22 deletions .yarn/patches/size-limit-npm-11.0.1-05996e44e7.patch

This file was deleted.

2 changes: 1 addition & 1 deletion packages/rtk-query-codegen-openapi/package.json
Original file line number Diff line number Diff line change
@@ -59,7 +59,7 @@
"@types/semver": "^7.3.9",
"chalk": "^4.1.0",
"del": "^6.0.0",
"esbuild": "^0.23.1",
"esbuild": "^0.25.0",
"esbuild-runner": "^2.2.1",
"husky": "^4.3.6",
"msw": "^2.1.5",
208 changes: 0 additions & 208 deletions packages/toolkit/.size-limit.cjs

This file was deleted.

69 changes: 69 additions & 0 deletions packages/toolkit/.size-limit.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import type { Check, SizeLimitConfig } from 'size-limit'
import type { Configuration } from 'webpack'
import packageJson from './package.json' with { type: 'json' }

/**
* An array of all possible Node environments.
*/
const allNodeEnvs = ['production'] as const

const allPackageEntryPoints = [
'./dist/redux-toolkit.modern.mjs',
'./dist/react/redux-toolkit-react.modern.mjs',
'./dist/query/rtk-query.modern.mjs',
'./dist/query/react/rtk-query-react.modern.mjs',
] as const

const dependencies = Object.keys(packageJson.dependencies ?? {})

const sizeLimitConfig: SizeLimitConfig = (
await Promise.all(
allNodeEnvs.flatMap((nodeEnv) => {
const modifyWebpackConfig = ((config: Configuration) => {
;(config.optimization ??= {}).nodeEnv = nodeEnv

return config
}) satisfies Check['modifyWebpackConfig']

return allPackageEntryPoints.map(async (entryPoint, index) => {
const allNamedImports = Object.keys(await import(entryPoint)).filter(
(namedImport) => namedImport !== 'default',
)

const sizeLimitConfigWithDependencies = allNamedImports
.map<Check>((namedImport, namedImportIndex) => ({
path: entryPoint,
name: `${index + 1}-${namedImportIndex + 1}. import { ${namedImport} } from "${entryPoint}" ('${nodeEnv}' mode)`,
import: `{ ${namedImport} }`,
modifyWebpackConfig,
}))
.concat([
{
path: entryPoint,
name: `${index + 1}-${allNamedImports.length + 1}. import * from "${entryPoint}" ('${nodeEnv}' mode)`,
import: '*',
modifyWebpackConfig,
},
{
path: entryPoint,
name: `${index + 1}-${allNamedImports.length + 2}. import "${entryPoint}" ('${nodeEnv}' mode)`,
modifyWebpackConfig,
},
])

const sizeLimitConfigWithoutDependencies =
sizeLimitConfigWithDependencies.map((check) => ({
...check,
name: `${check.name} (excluding dependencies)`,
ignore: dependencies,
}))

return sizeLimitConfigWithDependencies.concat(
sizeLimitConfigWithoutDependencies,
)
})
}),
)
).flat()

export default sizeLimitConfig
Loading
Oops, something went wrong.