Skip to content

Commit 3992b90

Browse files
committed
build: migrate from rollup to esbuild for faster builds
1 parent 99b6321 commit 3992b90

File tree

15 files changed

+687
-1572
lines changed

15 files changed

+687
-1572
lines changed

.config/.oxlintrc.json

Lines changed: 0 additions & 32 deletions
This file was deleted.

.config/babel.config.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

.config/esbuild.config.mjs

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/**
2+
* @fileoverview esbuild configuration for fast builds with smaller bundles
3+
*/
4+
5+
import { builtinModules } from 'node:module'
6+
import path from 'node:path'
7+
8+
const rootPath = path.join(import.meta.dirname, '..')
9+
const srcPath = path.join(rootPath, 'src')
10+
const distPath = path.join(rootPath, 'dist')
11+
12+
// External packages that should not be bundled
13+
const EXTERNAL_PACKAGES = new Set(['@socketsecurity/registry'])
14+
15+
// Build configuration for CommonJS output
16+
export const buildConfig = {
17+
entryPoints: [`${srcPath}/index.ts`],
18+
outdir: distPath,
19+
bundle: true,
20+
format: 'cjs',
21+
platform: 'node',
22+
// Minimum Node version from package.json
23+
target: 'node18',
24+
sourcemap: false,
25+
minify: true,
26+
treeShaking: true,
27+
// For bundle analysis
28+
metafile: true,
29+
logLevel: 'info',
30+
31+
// Preserve module structure for better tree-shaking
32+
splitting: false,
33+
34+
// External dependencies
35+
external: [
36+
// Node.js built-ins
37+
...builtinModules,
38+
...builtinModules.map(m => `node:${m}`),
39+
// External packages
40+
...Array.from(EXTERNAL_PACKAGES)
41+
],
42+
43+
// Banner for generated code
44+
banner: {
45+
js: '/* Socket PackageURL - Built with esbuild */'
46+
},
47+
48+
// TypeScript configuration
49+
tsconfig: path.join(rootPath, 'tsconfig.json'),
50+
51+
// Define constants for optimization
52+
define: {
53+
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'production')
54+
}
55+
}
56+
57+
// Watch configuration for development
58+
export const watchConfig = {
59+
...buildConfig,
60+
minify: false,
61+
sourcemap: 'inline',
62+
logLevel: 'debug',
63+
watch: {
64+
onRebuild(error, result) {
65+
if (error) {
66+
console.error('Watch build failed:', error)
67+
} else {
68+
console.log('Watch build succeeded')
69+
if (result.metafile) {
70+
const analysis = analyzeMetafile(result.metafile)
71+
console.log(analysis)
72+
}
73+
}
74+
}
75+
}
76+
}
77+
78+
/**
79+
* Analyze build output for size information
80+
*/
81+
function analyzeMetafile(metafile) {
82+
const outputs = Object.keys(metafile.outputs)
83+
let totalSize = 0
84+
85+
const files = outputs.map(file => {
86+
const output = metafile.outputs[file]
87+
totalSize += output.bytes
88+
return {
89+
name: path.relative(rootPath, file),
90+
size: (output.bytes / 1024).toFixed(2) + ' KB'
91+
}
92+
})
93+
94+
return {
95+
files,
96+
totalSize: (totalSize / 1024).toFixed(2) + ' KB'
97+
}
98+
}
99+
100+
export { analyzeMetafile }

.config/rollup.base.config.mjs

Lines changed: 0 additions & 119 deletions
This file was deleted.

.config/rollup.dist.config.mjs

Lines changed: 0 additions & 28 deletions
This file was deleted.

CLAUDE.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ TypeScript implementation of [Package URL specification](https://github.com/pack
8686

8787
### TypeScript Patterns
8888

89+
#### Import Style
90+
🚨 MANDATORY - Type imports must be on separate lines:
91+
-`import { parseScriptArgs, isQuiet } from './argv.mjs'`
92+
`import type { ArgParserConfig } from './argv.mjs'`
93+
-`import { parseScriptArgs, isQuiet, type ArgParserConfig } from './argv.mjs'`
94+
8995
#### Optional Properties
9096
With `exactOptionalPropertyTypes`, assign conditionally:
9197
-`if (value !== undefined) { this.prop = value }`

package.json

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,14 @@
3434
"check:lint": "node scripts/lint.mjs --all",
3535
"build": "node scripts/build.mjs",
3636
"check:tsc": "tsgo --noEmit -p .config/tsconfig.check.json",
37-
"clean:dist": "node scripts/clean.mjs --dist",
38-
"clean:dist:types": "node scripts/clean.mjs --dist-types",
3937
"clean": "node scripts/clean.mjs",
40-
"clean:cache": "node scripts/clean.mjs --cache",
41-
"clean:coverage": "node scripts/clean.mjs --coverage",
42-
"clean:node_modules": "node scripts/clean.mjs --node-modules",
4338
"coverage": "node scripts/coverage.mjs",
4439
"coverage:test": "node scripts/coverage.mjs --code-only",
4540
"coverage:percent": "node scripts/coverage-percent.mjs",
4641
"coverage:type": "type-coverage",
4742
"coverage:type:verbose": "type-coverage --detail",
4843
"lint": "node scripts/lint.mjs",
4944
"fix": "node scripts/lint.mjs --fix",
50-
"knip:dependencies": "knip --dependencies",
51-
"knip:exports": "knip --include exports,duplicates",
5245
"prepare": "husky",
5346
"prepublishOnly": "echo 'ERROR: Use GitHub Actions workflow for publishing' && exit 1",
5447
"test": "node scripts/test.mjs",
@@ -60,18 +53,10 @@
6053
"update:data:npm": "node ./scripts/update-data-npm.mjs"
6154
},
6255
"devDependencies": {
63-
"@babel/core": "7.28.4",
64-
"@babel/plugin-transform-runtime": "7.28.3",
65-
"@babel/preset-typescript": "7.27.1",
66-
"@babel/runtime": "7.28.4",
6756
"@biomejs/biome": "2.2.4",
6857
"@dotenvx/dotenvx": "1.49.0",
6958
"@eslint/compat": "1.3.2",
7059
"@eslint/js": "9.35.0",
71-
"@rollup/plugin-babel": "6.0.4",
72-
"@rollup/plugin-commonjs": "28.0.6",
73-
"@rollup/plugin-json": "6.1.0",
74-
"@rollup/plugin-node-resolve": "16.0.1",
7560
"@socketsecurity/registry": "1.5.3",
7661
"@types/node": "24.6.2",
7762
"@typescript/native-preview": "7.0.0-dev.20250926.1",
@@ -80,6 +65,7 @@
8065
"all-the-package-names-v1.3905.0": "npm:[email protected]",
8166
"del-cli": "6.0.0",
8267
"dev-null-cli": "2.0.0",
68+
"esbuild": "^0.25.10",
8369
"eslint": "9.35.0",
8470
"eslint-plugin-import-x": "4.16.1",
8571
"eslint-plugin-n": "17.23.1",
@@ -88,11 +74,8 @@
8874
"fast-glob": "3.3.3",
8975
"globals": "16.4.0",
9076
"husky": "9.1.7",
91-
"knip": "5.63.1",
9277
"npm-run-all2": "8.0.4",
93-
"oxlint": "1.15.0",
9478
"pacote": "21.0.1",
95-
"rollup": "4.50.1",
9679
"semver": "7.7.2",
9780
"taze": "19.6.0",
9881
"type-coverage": "2.29.7",

0 commit comments

Comments
 (0)