Skip to content

Commit 5e2a161

Browse files
committed
build: migrate to esbuild and reorganize config
- Migrate from rollup to esbuild for faster builds - Move config files to .config directory - Remove unnecessary build tools (oxlint, knip, babel) - Simplify build configuration - Update vitest and eslint configs
1 parent f0304f4 commit 5e2a161

File tree

10 files changed

+128
-230
lines changed

10 files changed

+128
-230
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.

biome.json renamed to .config/biome.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
2+
"$schema": "../node_modules/@biomejs/biome/configuration_schema.json",
33
"files": {
44
"includes": [
55
"**",
@@ -15,7 +15,8 @@
1515
"!**/dist",
1616
"!**/package.json",
1717
"!**/pnpm-lock.yaml"
18-
]
18+
],
19+
"maxSize": 8388608
1920
},
2021
"formatter": {
2122
"enabled": true,
@@ -62,7 +63,7 @@
6263
"useSingleVarDeclarator": "error",
6364
"noUnusedTemplateLiteral": "error",
6465
"useNumberNamespace": "error",
65-
"noInferrableTypes": "error",
66+
"noInferrableTypes": "off",
6667
"noUselessElse": "error",
6768
"useNumericSeparators": "error"
6869
}

.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/eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const nodeGlobalsConfig = Object.fromEntries(
2626
Object.entries(globals.node).map(([k]) => [k, 'readonly']),
2727
)
2828

29-
const biomeConfigPath = path.join(rootPath, 'biome.json')
29+
const biomeConfigPath = path.join(rootPath, '.config', 'biome.json')
3030
const biomeConfig = require(biomeConfigPath)
3131
const biomeIgnores = {
3232
name: `Imported biome.json ignore patterns`,

.config/knip.json

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

.config/rollup.base.config.mjs

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

.config/rollup.dist.config.mjs

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
2-
"extends": "./.config/tsconfig.base.json",
2+
"extends": "./tsconfig.base.json",
33
"compilerOptions": {
44
"declaration": true,
55
"declarationMap": false,
66
"emitDeclarationOnly": true,
77
"module": "commonjs",
88
"moduleResolution": "node",
9-
"outDir": "./dist",
10-
"rootDir": "./src",
9+
"outDir": "../dist",
10+
"rootDir": "../src",
1111
"verbatimModuleSyntax": false
1212
},
13-
"include": ["src/**/*.ts"]
13+
"include": ["../src/**/*.ts"]
1414
}

0 commit comments

Comments
 (0)