Skip to content

Commit 8b6096e

Browse files
committed
Add size-limit
1 parent 1af75b3 commit 8b6096e

File tree

3 files changed

+748
-10
lines changed

3 files changed

+748
-10
lines changed

.size-limit.mts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import path from 'node:path'
2+
import { fileURLToPath } from 'node:url'
3+
import type { Check, SizeLimitConfig } from 'size-limit'
4+
5+
const __dirname = fileURLToPath(new URL('.', import.meta.url))
6+
7+
const getAllEntryPoints = async () => {
8+
const pkgJson = await import('./package.json', { with: { type: 'json' } })
9+
10+
const entryPoints = Object.entries(pkgJson.exports['.'])
11+
.filter(([condition]) => condition !== 'types')
12+
.map(([, entryPoint]) =>
13+
path.isAbsolute(entryPoint) ? `./${entryPoint}` : entryPoint,
14+
)
15+
16+
return entryPoints
17+
}
18+
19+
const getAllImports = async (
20+
entryPoint: string,
21+
index: number,
22+
): Promise<SizeLimitConfig> => {
23+
const allImports = await import(entryPoint)
24+
25+
return Object.keys(allImports)
26+
.map<Check>((namedImport) => ({
27+
path: entryPoint,
28+
name: `${namedImport} (${entryPoint})`,
29+
import: `{ ${namedImport} }`,
30+
}))
31+
.concat({
32+
path: entryPoint,
33+
name: `${index + 1}. Entry point: ${entryPoint}`,
34+
import: '*',
35+
})
36+
}
37+
38+
const config: Promise<SizeLimitConfig> = (async () =>
39+
(await Promise.all((await getAllEntryPoints()).map(getAllImports))).flat())()
40+
41+
export default config

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"test": "vitest --run",
4848
"test:watch": "vitest --watch",
4949
"type-tests": "yarn tsc -p test/typetests/tsconfig.json",
50+
"size": "size-limit",
5051
"coverage": "codecov"
5152
},
5253
"peerDependencies": {
@@ -79,6 +80,8 @@
7980
"@babel/preset-typescript": "^7.14.5",
8081
"@microsoft/api-extractor": "^7.18.1",
8182
"@reduxjs/toolkit": "^2.0.0-beta.4",
83+
"@size-limit/file": "^11.1.2",
84+
"@size-limit/webpack": "^11.1.2",
8285
"@testing-library/jest-dom": "^6.3.0",
8386
"@testing-library/react": "^14.1.2",
8487
"@testing-library/react-hooks": "^8.0.1",
@@ -103,6 +106,7 @@
103106
"react-test-renderer": "18.0.0",
104107
"redux": "^5.0.0",
105108
"rimraf": "^3.0.2",
109+
"size-limit": "^11.1.2",
106110
"tsup": "^7.0.0",
107111
"typescript": "^5.4.2",
108112
"vitest": "^1.2.1"

0 commit comments

Comments
 (0)