Skip to content

Commit

Permalink
feat!: bump size-limit, migrate to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin committed Nov 10, 2023
1 parent 1fae830 commit 077d680
Show file tree
Hide file tree
Showing 14 changed files with 8,770 additions and 4,411 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,22 @@ jobs:
strategy:
matrix:
node:
- 14
- 16
- 18
- 20
os:
- macos-latest
- windows-latest
- ubuntu-latest
runs-on: ${{ matrix.os }}
steps:
- name: Checkout Repo
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: latest

- name: Setup Node.js ${{ matrix.node }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: pnpm
Expand Down
44 changes: 44 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: 'CodeQL'

on:
push:
branches:
- main
pull_request:
branches:
- main
schedule:
- cron: '58 4 * * 2'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language:
- javascript

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
queries: +security-and-quality

- name: Autobuild
uses: github/codeql-action/autobuild@v2

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: '/language:${{ matrix.language }}'
8 changes: 3 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,18 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
fetch-depth: 0

- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: latest

- name: Setup Node.js 16
- name: Setup Node.js LTS
uses: actions/setup-node@v3
with:
node-version: 16
node-version: lts/*
cache: pnpm

- name: Install Dependencies
Expand Down
10 changes: 4 additions & 6 deletions .github/workflows/size-limit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@ jobs:
size-limit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: latest

- name: Setup Node.js 16
uses: actions/setup-node@v3
- name: Setup Node.js LTS
uses: actions/setup-node@v4
with:
node-version: 16
node-version: lts/*
cache: pnpm

- name: Install Dependencies
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/vercel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Check Branch
id: branch
if: ${{ github.ref == 'refs/heads/main' }}
run: |
echo "::set-output name=args::--prod"
echo "::set-output name=comment::false"
echo "args=--prod" >> $GITHUB_OUTPUT
echo "comment=false" >> $GITHUB_OUTPUT
- name: Deploy
uses: amondnet/vercel-action@v25
Expand Down
37 changes: 18 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@
"workspaces": [
"packages/*"
],
"packageManager": "pnpm@7.12.1",
"packageManager": "pnpm@8.10.2",
"scripts": {
"build": "run-s build:tsc build:r",
"build:r": "r -f cjs",
"build:tsc": "tsc -b",
"clean": "rimraf 'packages/**/{lib,*.tsbuildinfo}'",
"build": "tsc -b",
"clean": "rimraf --glob 'packages/**/{lib,*.tsbuildinfo}'",
"codesandbox:install": "yarn",
"dev": "w -e docs --disableDotRule --publicPath /",
"lint": "run-p lint:*",
Expand All @@ -33,26 +31,27 @@
"version": "changeset version"
},
"devDependencies": {
"@1stg/app-config": "^7.3.0",
"@1stg/lib-config": "^10.3.0",
"@changesets/changelog-github": "^0.4.6",
"@changesets/cli": "^2.24.4",
"@1stg/app-config": "^9.0.0",
"@1stg/lib-config": "^12.0.0",
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.2",
"@pkgr/webpack": "^3.4.0",
"@pkgr/webpack-mdx": "^2.2.0",
"@types/node": "^18.7.18",
"@types/react": "^18.0.20",
"@types/react-dom": "^18.0.6",
"@types/web": "^0.0.73",
"github-markdown-css": "^5.1.0",
"@types/node": "^18.18.9",
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.15",
"@types/web": "^0.0.119",
"github-markdown-css": "^5.4.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.4.0",
"react-router-dom": "^6.18.0",
"rimraf": "^5.0.5",
"sirv-cli": "^2.0.2",
"size-limit": "^8.1.0",
"size-limit": "^10.0.2",
"size-limit-node-esbuild": "link:packages/node-esbuild",
"size-limit-preset-node-lib": "link:packages/preset-node-lib",
"type-coverage": "^2.22.0",
"typescript": "^4.8.3"
"type-coverage": "^2.27.0",
"typescript": "^5.2.2"
},
"resolutions": {
"prettier": "^2.7.1"
Expand Down Expand Up @@ -88,7 +87,7 @@
"size-limit": [
{
"path": "./packages/node-esbuild/lib/index.js",
"limit": "500B"
"limit": "650B"
},
{
"path": "./packages/preset-node-lib/lib/index.js",
Expand Down
12 changes: 5 additions & 7 deletions packages/node-esbuild/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,20 @@
"engines": {
"node": "^12.20.0 || ^14.18.0 || >=16.0.0"
},
"main": "./lib/index.cjs",
"module": "./lib/index.js",
"main": "./lib/index.js",
"exports": {
"types": "./lib/index.d.ts",
"import": "./lib/index.js",
"require": "./lib/index.cjs"
"default": "./lib/index.js"
},
"types": "./lib/index.d.ts",
"files": [
"lib",
"shim.d.ts"
],
"dependencies": {
"@size-limit/esbuild": "^8.1.0",
"nanoid": "^3.2.0",
"tslib": "^2.4.0"
"nanoid": "^5.0.3",
"size-limit": "^10.0.2",
"tslib": "^2.6.2"
},
"publishConfig": {
"access": "public"
Expand Down
42 changes: 19 additions & 23 deletions packages/node-esbuild/shim.d.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
declare module '@size-limit/esbuild/convert-config' {
declare module 'size-limit' {
import { BuildOptions } from 'esbuild'

function convertConfig(esbuildConfig: BuildOptions, configPath: string): void
export interface SizeLimitConfig {
configPath: string
saveBundle: string
}

export = convertConfig
}

declare module '@size-limit/esbuild/get-config' {
import { BuildOptions } from 'esbuild'

function getConfig(
config: {
configPath: string
saveBundle: string
},
check: {
esbuild?: false
config?: string
esbuildConfig: BuildOptions
esbuildOutfile: string
modifyEsbuildConfig?(esbuildConfig: BuildOptions): BuildOptions
},
esbuildOutfile: string,
): Promise<BuildOptions>
export interface SizeLimitCheck {
import?: string
files: string[] | string
ignore?: string[]
esbuild?: false
config?: string
esbuildConfig: BuildOptions
esbuildOutfile: string
modifyEsbuildConfig?(esbuildConfig: BuildOptions): BuildOptions
}

export = getConfig
export const processImport: (
check: SizeLimitCheck,
output: string,
) => Promise<void>
}
55 changes: 32 additions & 23 deletions packages/node-esbuild/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,38 @@
import { tmpdir } from 'node:os'
import { join } from 'node:path'

import convertConfig from '@size-limit/esbuild/convert-config'
import getConfig from '@size-limit/esbuild/get-config'
import type { BuildOptions } from 'esbuild'
import { nanoid } from 'nanoid/non-secure'
import { SizeLimitCheck, SizeLimitConfig, processImport } from 'size-limit'

// https://github.com/ai/size-limit/blob/f2493379fefc00559af2a8c54fc52cedbbc9b0bd/packages/esbuild/get-config.js
async function getConfig(
_config: SizeLimitConfig,
check: SizeLimitCheck,
output: string,
): Promise<BuildOptions> {
await processImport(check, output)

return {
allowOverwrite: !!check.import,
bundle: true,
entryPoints: Array.isArray(check.files) ? check.files : [check.files],

external: check.ignore,
metafile: true,
minifyIdentifiers: true,

minifySyntax: true,
minifyWhitespace: true,
outdir: output,
treeShaking: true,
write: true,
}
}

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

async step20(
config: {
configPath: string
saveBundle: string
},
check: {
esbuild?: false
config?: string
esbuildConfig: BuildOptions
esbuildOutfile: string
modifyEsbuildConfig?(esbuildConfig: BuildOptions): BuildOptions
},
) {
async step20(config: SizeLimitConfig, check: SizeLimitCheck) {
if (check.esbuild === false) {
return
}
Expand All @@ -43,14 +57,9 @@ export default [
const esbuildConfig = (await import(check.config)) as
| BuildOptions
| { default: BuildOptions }
convertConfig(
setPlatformNode(
(check.esbuildConfig =
'default' in esbuildConfig
? esbuildConfig.default
: esbuildConfig),
),
config.configPath,
setPlatformNode(
(check.esbuildConfig =
'default' in esbuildConfig ? esbuildConfig.default : esbuildConfig),
)
} else {
check.esbuildConfig = setPlatformNode(
Expand Down
1 change: 1 addition & 0 deletions packages/node-esbuild/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "@1stg/tsconfig/node16",
"compilerOptions": {
"composite": true,
"module": "Node16",
"rootDir": "src",
"outDir": "lib"
}
Expand Down
10 changes: 4 additions & 6 deletions packages/preset-node-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,20 @@
"engines": {
"node": "^12.20.0 || ^14.18.0 || >=16.0.0"
},
"main": "./lib/index.cjs",
"module": "./lib/index.js",
"main": "./lib/index.js",
"exports": {
"types": "./lib/index.d.ts",
"import": "./lib/index.js",
"require": "./lib/index.cjs"
"default": "./lib/index.js"
},
"types": "./lib/index.d.ts",
"files": [
"lib",
"shim.d.ts"
],
"dependencies": {
"@size-limit/file": "^8.1.0",
"@size-limit/file": "^10.0.2",
"size-limit-node-esbuild": "^0.2.0",
"tslib": "^2.4.0"
"tslib": "^2.6.2"
},
"publishConfig": {
"access": "public"
Expand Down
Loading

0 comments on commit 077d680

Please sign in to comment.