Skip to content

Commit 077d680

Browse files
committed
feat!: bump size-limit, migrate to ESM
1 parent 1fae830 commit 077d680

File tree

14 files changed

+8770
-4411
lines changed

14 files changed

+8770
-4411
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,22 @@ jobs:
1010
strategy:
1111
matrix:
1212
node:
13-
- 14
14-
- 16
1513
- 18
14+
- 20
1615
os:
1716
- macos-latest
1817
- windows-latest
1918
- ubuntu-latest
2019
runs-on: ${{ matrix.os }}
2120
steps:
2221
- name: Checkout Repo
23-
uses: actions/checkout@v3
22+
uses: actions/checkout@v4
2423

2524
- name: Setup pnpm
2625
uses: pnpm/action-setup@v2
27-
with:
28-
version: latest
2926

3027
- name: Setup Node.js ${{ matrix.node }}
31-
uses: actions/setup-node@v3
28+
uses: actions/setup-node@v4
3229
with:
3330
node-version: ${{ matrix.node }}
3431
cache: pnpm

.github/workflows/codeql.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: 'CodeQL'
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
schedule:
11+
- cron: '58 4 * * 2'
12+
13+
jobs:
14+
analyze:
15+
name: Analyze
16+
runs-on: ubuntu-latest
17+
permissions:
18+
actions: read
19+
contents: read
20+
security-events: write
21+
22+
strategy:
23+
fail-fast: false
24+
matrix:
25+
language:
26+
- javascript
27+
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v4
31+
32+
- name: Initialize CodeQL
33+
uses: github/codeql-action/init@v2
34+
with:
35+
languages: ${{ matrix.language }}
36+
queries: +security-and-quality
37+
38+
- name: Autobuild
39+
uses: github/codeql-action/autobuild@v2
40+
41+
- name: Perform CodeQL Analysis
42+
uses: github/codeql-action/analyze@v2
43+
with:
44+
category: '/language:${{ matrix.language }}'

.github/workflows/release.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,18 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- name: Checkout Repo
14-
uses: actions/checkout@v3
14+
uses: actions/checkout@v4
1515
with:
1616
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
1717
fetch-depth: 0
1818

1919
- name: Setup pnpm
2020
uses: pnpm/action-setup@v2
21-
with:
22-
version: latest
2321

24-
- name: Setup Node.js 16
22+
- name: Setup Node.js LTS
2523
uses: actions/setup-node@v3
2624
with:
27-
node-version: 16
25+
node-version: lts/*
2826
cache: pnpm
2927

3028
- name: Install Dependencies

.github/workflows/size-limit.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,15 @@ jobs:
99
size-limit:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v3
12+
- uses: actions/checkout@v4
1313

1414
- name: Setup pnpm
1515
uses: pnpm/action-setup@v2
16-
with:
17-
version: latest
1816

19-
- name: Setup Node.js 16
20-
uses: actions/setup-node@v3
17+
- name: Setup Node.js LTS
18+
uses: actions/setup-node@v4
2119
with:
22-
node-version: 16
20+
node-version: lts/*
2321
cache: pnpm
2422

2523
- name: Install Dependencies

.github/workflows/vercel.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ jobs:
1010
deploy:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v3
13+
- uses: actions/checkout@v4
1414

1515
- name: Check Branch
1616
id: branch
1717
if: ${{ github.ref == 'refs/heads/main' }}
1818
run: |
19-
echo "::set-output name=args::--prod"
20-
echo "::set-output name=comment::false"
19+
echo "args=--prod" >> $GITHUB_OUTPUT
20+
echo "comment=false" >> $GITHUB_OUTPUT
2121
2222
- name: Deploy
2323
uses: amondnet/vercel-action@v25

package.json

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010
"workspaces": [
1111
"packages/*"
1212
],
13-
"packageManager": "pnpm@7.12.1",
13+
"packageManager": "pnpm@8.10.2",
1414
"scripts": {
15-
"build": "run-s build:tsc build:r",
16-
"build:r": "r -f cjs",
17-
"build:tsc": "tsc -b",
18-
"clean": "rimraf 'packages/**/{lib,*.tsbuildinfo}'",
15+
"build": "tsc -b",
16+
"clean": "rimraf --glob 'packages/**/{lib,*.tsbuildinfo}'",
1917
"codesandbox:install": "yarn",
2018
"dev": "w -e docs --disableDotRule --publicPath /",
2119
"lint": "run-p lint:*",
@@ -33,26 +31,27 @@
3331
"version": "changeset version"
3432
},
3533
"devDependencies": {
36-
"@1stg/app-config": "^7.3.0",
37-
"@1stg/lib-config": "^10.3.0",
38-
"@changesets/changelog-github": "^0.4.6",
39-
"@changesets/cli": "^2.24.4",
34+
"@1stg/app-config": "^9.0.0",
35+
"@1stg/lib-config": "^12.0.0",
36+
"@changesets/changelog-github": "^0.4.8",
37+
"@changesets/cli": "^2.26.2",
4038
"@pkgr/webpack": "^3.4.0",
4139
"@pkgr/webpack-mdx": "^2.2.0",
42-
"@types/node": "^18.7.18",
43-
"@types/react": "^18.0.20",
44-
"@types/react-dom": "^18.0.6",
45-
"@types/web": "^0.0.73",
46-
"github-markdown-css": "^5.1.0",
40+
"@types/node": "^18.18.9",
41+
"@types/react": "^18.2.37",
42+
"@types/react-dom": "^18.2.15",
43+
"@types/web": "^0.0.119",
44+
"github-markdown-css": "^5.4.0",
4745
"react": "^18.2.0",
4846
"react-dom": "^18.2.0",
49-
"react-router-dom": "^6.4.0",
47+
"react-router-dom": "^6.18.0",
48+
"rimraf": "^5.0.5",
5049
"sirv-cli": "^2.0.2",
51-
"size-limit": "^8.1.0",
50+
"size-limit": "^10.0.2",
5251
"size-limit-node-esbuild": "link:packages/node-esbuild",
5352
"size-limit-preset-node-lib": "link:packages/preset-node-lib",
54-
"type-coverage": "^2.22.0",
55-
"typescript": "^4.8.3"
53+
"type-coverage": "^2.27.0",
54+
"typescript": "^5.2.2"
5655
},
5756
"resolutions": {
5857
"prettier": "^2.7.1"
@@ -88,7 +87,7 @@
8887
"size-limit": [
8988
{
9089
"path": "./packages/node-esbuild/lib/index.js",
91-
"limit": "500B"
90+
"limit": "650B"
9291
},
9392
{
9493
"path": "./packages/preset-node-lib/lib/index.js",

packages/node-esbuild/package.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,20 @@
1111
"engines": {
1212
"node": "^12.20.0 || ^14.18.0 || >=16.0.0"
1313
},
14-
"main": "./lib/index.cjs",
15-
"module": "./lib/index.js",
14+
"main": "./lib/index.js",
1615
"exports": {
1716
"types": "./lib/index.d.ts",
18-
"import": "./lib/index.js",
19-
"require": "./lib/index.cjs"
17+
"default": "./lib/index.js"
2018
},
2119
"types": "./lib/index.d.ts",
2220
"files": [
2321
"lib",
2422
"shim.d.ts"
2523
],
2624
"dependencies": {
27-
"@size-limit/esbuild": "^8.1.0",
28-
"nanoid": "^3.2.0",
29-
"tslib": "^2.4.0"
25+
"nanoid": "^5.0.3",
26+
"size-limit": "^10.0.2",
27+
"tslib": "^2.6.2"
3028
},
3129
"publishConfig": {
3230
"access": "public"

packages/node-esbuild/shim.d.ts

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
1-
declare module '@size-limit/esbuild/convert-config' {
1+
declare module 'size-limit' {
22
import { BuildOptions } from 'esbuild'
33

4-
function convertConfig(esbuildConfig: BuildOptions, configPath: string): void
4+
export interface SizeLimitConfig {
5+
configPath: string
6+
saveBundle: string
7+
}
58

6-
export = convertConfig
7-
}
8-
9-
declare module '@size-limit/esbuild/get-config' {
10-
import { BuildOptions } from 'esbuild'
11-
12-
function getConfig(
13-
config: {
14-
configPath: string
15-
saveBundle: string
16-
},
17-
check: {
18-
esbuild?: false
19-
config?: string
20-
esbuildConfig: BuildOptions
21-
esbuildOutfile: string
22-
modifyEsbuildConfig?(esbuildConfig: BuildOptions): BuildOptions
23-
},
24-
esbuildOutfile: string,
25-
): Promise<BuildOptions>
9+
export interface SizeLimitCheck {
10+
import?: string
11+
files: string[] | string
12+
ignore?: string[]
13+
esbuild?: false
14+
config?: string
15+
esbuildConfig: BuildOptions
16+
esbuildOutfile: string
17+
modifyEsbuildConfig?(esbuildConfig: BuildOptions): BuildOptions
18+
}
2619

27-
export = getConfig
20+
export const processImport: (
21+
check: SizeLimitCheck,
22+
output: string,
23+
) => Promise<void>
2824
}

packages/node-esbuild/src/index.ts

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,38 @@
33
import { tmpdir } from 'node:os'
44
import { join } from 'node:path'
55

6-
import convertConfig from '@size-limit/esbuild/convert-config'
7-
import getConfig from '@size-limit/esbuild/get-config'
86
import type { BuildOptions } from 'esbuild'
97
import { nanoid } from 'nanoid/non-secure'
8+
import { SizeLimitCheck, SizeLimitConfig, processImport } from 'size-limit'
9+
10+
// https://github.com/ai/size-limit/blob/f2493379fefc00559af2a8c54fc52cedbbc9b0bd/packages/esbuild/get-config.js
11+
async function getConfig(
12+
_config: SizeLimitConfig,
13+
check: SizeLimitCheck,
14+
output: string,
15+
): Promise<BuildOptions> {
16+
await processImport(check, output)
17+
18+
return {
19+
allowOverwrite: !!check.import,
20+
bundle: true,
21+
entryPoints: Array.isArray(check.files) ? check.files : [check.files],
22+
23+
external: check.ignore,
24+
metafile: true,
25+
minifyIdentifiers: true,
26+
27+
minifySyntax: true,
28+
minifyWhitespace: true,
29+
outdir: output,
30+
treeShaking: true,
31+
write: true,
32+
}
33+
}
1034

1135
const setPlatformNode = (esbuildConfig: BuildOptions) => {
36+
// https://github.com/ai/size-limit/blob/f2493379fefc00559af2a8c54fc52cedbbc9b0bd/packages/esbuild/convert-config.js
37+
esbuildConfig.metafile = true
1238
if (!esbuildConfig.platform) {
1339
esbuildConfig.platform = 'node'
1440
}
@@ -19,19 +45,7 @@ export default [
1945
{
2046
name: 'size-limit-node-esbuild',
2147

22-
async step20(
23-
config: {
24-
configPath: string
25-
saveBundle: string
26-
},
27-
check: {
28-
esbuild?: false
29-
config?: string
30-
esbuildConfig: BuildOptions
31-
esbuildOutfile: string
32-
modifyEsbuildConfig?(esbuildConfig: BuildOptions): BuildOptions
33-
},
34-
) {
48+
async step20(config: SizeLimitConfig, check: SizeLimitCheck) {
3549
if (check.esbuild === false) {
3650
return
3751
}
@@ -43,14 +57,9 @@ export default [
4357
const esbuildConfig = (await import(check.config)) as
4458
| BuildOptions
4559
| { default: BuildOptions }
46-
convertConfig(
47-
setPlatformNode(
48-
(check.esbuildConfig =
49-
'default' in esbuildConfig
50-
? esbuildConfig.default
51-
: esbuildConfig),
52-
),
53-
config.configPath,
60+
setPlatformNode(
61+
(check.esbuildConfig =
62+
'default' in esbuildConfig ? esbuildConfig.default : esbuildConfig),
5463
)
5564
} else {
5665
check.esbuildConfig = setPlatformNode(

packages/node-esbuild/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"extends": "@1stg/tsconfig/node16",
33
"compilerOptions": {
44
"composite": true,
5+
"module": "Node16",
56
"rootDir": "src",
67
"outDir": "lib"
78
}

0 commit comments

Comments
 (0)