Skip to content

Commit 7a776b0

Browse files
committed
Update size-limit workflow and configuration
1 parent 87b4487 commit 7a776b0

File tree

3 files changed

+72
-125
lines changed

3 files changed

+72
-125
lines changed

.github/workflows/size.yml

+25-9
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,41 @@
1-
name: size
1+
name: Check Bundle-Size
22

3-
on:
4-
pull_request:
5-
branches:
6-
- master
7-
8-
permissions:
9-
pull-requests: write
3+
on: [push, pull_request, workflow_dispatch]
104

115
jobs:
126
size:
13-
name: Check compressed size
147
runs-on: ubuntu-latest
8+
name: Check Bundle-Size
9+
10+
strategy:
11+
matrix:
12+
node: ['22.x']
13+
1514
env:
1615
CI_JOB_NUMBER: 1
1716
steps:
1817
- uses: actions/checkout@v4
18+
- uses: actions/setup-node@v4
19+
with:
20+
node-version: ${{ matrix.node }}
21+
cache: 'yarn'
22+
check-latest: true
23+
24+
- run: yarn install
25+
1926
- uses: EskiMojo14/size-limit-action@v2
27+
id: size
28+
continue-on-error: true
29+
2030
with:
2131
directory: .
2232
github_token: ${{ secrets.GITHUB_TOKEN }}
2333
build_script: build
2434
package_manager: yarn
2535
size_margin: non-zero
36+
37+
- name: Run size-limit locally
38+
if: ${{ success() && steps.size.outcome == 'failure' }}
39+
run: |
40+
yarn run build
41+
yarn run size

.size-limit.mts

+46-115
Original file line numberDiff line numberDiff line change
@@ -6,122 +6,53 @@ import type { Configuration } from 'webpack'
66
*/
77
const allNodeEnvs = ['production'] as const
88

9-
/**
10-
* Represents a specific environment for a Node.js application.
11-
*/
12-
type NodeEnv = (typeof allNodeEnvs)[number]
13-
14-
/**
15-
* Gets all import configurations for a given entry point.
16-
* This function dynamically imports the specified entry point and
17-
* generates a size limit configuration for each named export found
18-
* within the module. It includes configurations for named imports,
19-
* wildcard imports, and the default import.
20-
*
21-
* @param entryPoint - The entry point to import.
22-
* @param index - The index of the entry point in the list.
23-
* @returns A promise that resolves to a size limit configuration object.
24-
*/
25-
const getAllImportsForEntryPoint = async (
26-
entryPoint: string,
27-
index: number
28-
): Promise<SizeLimitConfig> => {
29-
const allNamedImports = Object.keys(await import(entryPoint)).filter(
30-
namedImport => namedImport !== 'default'
31-
)
32-
33-
return allNamedImports
34-
.map<Check>(namedImport => ({
35-
path: entryPoint,
36-
name: `${index + 1}. import { ${namedImport} } from "${entryPoint}"`,
37-
import: `{ ${namedImport} }`
38-
}))
39-
.concat([
40-
{
41-
path: entryPoint,
42-
name: `${index + 1}. import * from "${entryPoint}"`,
43-
import: '*'
44-
},
45-
{
46-
path: entryPoint,
47-
name: `${index + 1}. import "${entryPoint}"`
48-
}
49-
])
50-
}
51-
52-
/**
53-
* Sets the `NODE_ENV` for a given Webpack configuration.
54-
*
55-
* @param nodeEnv - The `NODE_ENV` to set (either 'development' or 'production').
56-
* @returns A function that modifies the Webpack configuration.
57-
*/
58-
const setNodeEnv = (nodeEnv: NodeEnv) => {
59-
const modifyWebpackConfig = ((config: Configuration) => {
60-
;(config.optimization ??= {}).nodeEnv = nodeEnv
61-
62-
return config
63-
}) satisfies Check['modifyWebpackConfig']
64-
65-
return modifyWebpackConfig
66-
}
67-
68-
/**
69-
* Gets all import configurations with a specified `NODE_ENV`.
70-
*
71-
* @param nodeEnv - The `NODE_ENV` to set (either 'development' or 'production').
72-
* @returns A promise that resolves to a size limit configuration object.
73-
*/
74-
const getAllImportsWithNodeEnv = async (nodeEnv: NodeEnv) => {
75-
const allPackageEntryPoints = ['./dist/reselect.mjs']
76-
77-
const allImportsFromAllEntryPoints = (
78-
await Promise.all(allPackageEntryPoints.map(getAllImportsForEntryPoint))
79-
).flat()
80-
81-
const modifyWebpackConfig = setNodeEnv(nodeEnv)
82-
83-
const allImportsWithNodeEnv = allImportsFromAllEntryPoints.map<Check>(
84-
importsFromEntryPoint => ({
85-
...importsFromEntryPoint,
86-
name: `${importsFromEntryPoint.name} ('${nodeEnv}' mode)`,
87-
modifyWebpackConfig
9+
const allPackageEntryPoints = ['./dist/reselect.mjs'] as const
10+
11+
const sizeLimitConfig: SizeLimitConfig = (
12+
await Promise.all(
13+
allNodeEnvs.flatMap(nodeEnv => {
14+
const modifyWebpackConfig = ((config: Configuration) => {
15+
;(config.optimization ??= {}).nodeEnv = nodeEnv
16+
17+
return config
18+
}) satisfies Check['modifyWebpackConfig']
19+
20+
return allPackageEntryPoints.map(async (entryPoint, index) => {
21+
const allNamedImports = Object.keys(await import(entryPoint)).filter(
22+
namedImport => namedImport !== 'default'
23+
)
24+
25+
const sizeLimitConfigWithDependencies = allNamedImports
26+
.map<Check>((namedImport, namedImportIndex) => ({
27+
path: entryPoint,
28+
name: `${index + 1}-${
29+
namedImportIndex + 1
30+
}. import { ${namedImport} } from "${entryPoint}" ('${nodeEnv}' mode)`,
31+
import: `{ ${namedImport} }`,
32+
modifyWebpackConfig
33+
}))
34+
.concat([
35+
{
36+
path: entryPoint,
37+
name: `${index + 1}-${
38+
allNamedImports.length + 1
39+
}. import * from "${entryPoint}" ('${nodeEnv}' mode)`,
40+
import: '*',
41+
modifyWebpackConfig
42+
},
43+
{
44+
path: entryPoint,
45+
name: `${index + 1}-${
46+
allNamedImports.length + 2
47+
}. import "${entryPoint}" ('${nodeEnv}' mode)`,
48+
modifyWebpackConfig
49+
}
50+
])
51+
52+
return sizeLimitConfigWithDependencies
53+
})
8854
})
8955
)
90-
91-
return allImportsWithNodeEnv
92-
}
93-
94-
/**
95-
* Gets the size limit configuration for all `NODE_ENV`s.
96-
*
97-
* @returns A promise that resolves to the size limit configuration object.
98-
*/
99-
const getSizeLimitConfig = async (): Promise<SizeLimitConfig> => {
100-
const packageJson = (
101-
await import('./package.json', { with: { type: 'json' } })
102-
).default
103-
104-
const sizeLimitConfig = (
105-
await Promise.all(allNodeEnvs.map(getAllImportsWithNodeEnv))
106-
).flat()
107-
108-
if ('dependencies' in packageJson) {
109-
const dependencies = Object.keys(packageJson.dependencies ?? {})
110-
111-
const sizeLimitConfigWithoutDependencies = sizeLimitConfig.map<Check>(
112-
check => ({
113-
...check,
114-
name: `${check.name} (excluding dependencies)`,
115-
ignore: dependencies
116-
})
117-
)
118-
119-
return sizeLimitConfigWithoutDependencies
120-
}
121-
122-
return sizeLimitConfig
123-
}
124-
125-
const sizeLimitConfig: Promise<SizeLimitConfig> = getSizeLimitConfig()
56+
).flat()
12657

12758
export default sizeLimitConfig

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"type-check": "vitest --run --typecheck.only",
3535
"type-check:trace": "vitest --run --typecheck.only && tsc --noEmit -p typescript_test/tsconfig.json --generateTrace trace && npx @typescript/analyze-trace trace && rimraf trace",
3636
"test:typescript": "tsc --noEmit -p typescript_test/tsconfig.json",
37-
"size": "size-limit",
37+
"size": "size-limit --config $INIT_CWD/.size-limit.mts",
3838
"docs:start": "yarn --cwd website start",
3939
"docs:build": "yarn --cwd website build",
4040
"docs:clear": "yarn --cwd website clear",

0 commit comments

Comments
 (0)