Skip to content

Commit 9e1a8a6

Browse files
jdaltonclaude
andcommitted
Add pkg configuration and build scripts
Add configuration for building standalone binaries and scripts to build custom/patched Node.js binaries with optimizations. πŸ€– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 9fa11bd commit 9e1a8a6

File tree

3 files changed

+173
-0
lines changed

3 files changed

+173
-0
lines changed

β€Žpkg.jsonβ€Ž

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "socket",
3+
"bin": {
4+
"socket": "dist/cli.js",
5+
"socket-npm": "dist/npm-cli.js",
6+
"socket-npx": "dist/npx-cli.js",
7+
"socket-pnpm": "dist/pnpm-cli.js",
8+
"socket-yarn": "dist/yarn-cli.js"
9+
},
10+
"node": "/Users/jdalton/projects/socket-cli/.custom-node-build/node/out/Release/node",
11+
"targets": [
12+
"node22-macos-arm64",
13+
"node22-macos-x64",
14+
"node22-linux-arm64",
15+
"node22-linux-x64",
16+
"node22-win-arm64",
17+
"node22-win-x64"
18+
],
19+
"outputPath": "pkg-binaries",
20+
"assets": [
21+
"dist/**/*",
22+
"requirements.json",
23+
"translations.json",
24+
"shadow-bin/**/*"
25+
]
26+
}

β€Žscripts/build-custom-node.shβ€Ž

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Build custom Node.js v22 with aggressive optimizations for yao-pkg
5+
# This produces a smaller binary by:
6+
# - Using -O3 and -flto optimizations
7+
# - Building with small ICU
8+
# - Zeroing out V8 compile-time flags (done in configure)
9+
10+
VARIANT="${1:-optimized}"
11+
NODE_VERSION="v22.11.0"
12+
BUILD_DIR="/Users/jdalton/projects/socket-cli/.custom-node-build"
13+
NODE_DIR="$BUILD_DIR/node"
14+
15+
echo "πŸ”¨ Building custom Node.js $NODE_VERSION ($VARIANT variant)"
16+
17+
# Create build directory
18+
mkdir -p "$BUILD_DIR"
19+
cd "$BUILD_DIR"
20+
21+
# Clone Node.js if not already present
22+
if [ ! -d "node" ]; then
23+
echo "πŸ“₯ Cloning Node.js $NODE_VERSION..."
24+
git clone --depth 1 --branch "$NODE_VERSION" https://github.com/nodejs/node.git
25+
cd node
26+
else
27+
echo "πŸ“‚ Using existing Node.js clone..."
28+
cd node
29+
fi
30+
31+
# Clean previous build (but don't delete directory)
32+
echo "🧹 Cleaning previous build..."
33+
make clean 2>/dev/null || true
34+
35+
# Configure with optimizations
36+
echo "βš™οΈ Configuring Node.js..."
37+
./configure \
38+
--enable-lto \
39+
--with-intl=small-icu \
40+
--without-npm \
41+
--without-corepack
42+
43+
# Build with optimizations
44+
echo "πŸ—οΈ Building Node.js (this will take 30-60 minutes)..."
45+
echo " Using $(sysctl -n hw.ncpu) CPU cores"
46+
47+
# Set compiler flags for aggressive optimization
48+
export CFLAGS="-O3 -flto"
49+
export CXXFLAGS="-O3 -flto"
50+
export LDFLAGS="-flto"
51+
52+
# Build using all available cores
53+
make -j$(sysctl -n hw.ncpu)
54+
55+
# Test the binary
56+
echo "βœ… Testing binary..."
57+
./out/Release/node --version
58+
./out/Release/node -e "console.log('Hello from custom Node.js!')"
59+
60+
# Report size
61+
echo ""
62+
echo "πŸŽ‰ Build complete!"
63+
echo " Binary: $NODE_DIR/out/Release/node"
64+
echo " Size: $(du -h "$NODE_DIR/out/Release/node" | cut -f1)"
65+
echo ""
66+
echo "πŸ“ To use with yao-pkg, update package.json:"
67+
echo ' "pkg": {'
68+
echo ' "node": "'$NODE_DIR/out/Release/node'",'
69+
echo ' ...'
70+
echo ' }'
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Build Node.js v22.19.0 with yao-pkg patches + aggressive optimizations
5+
VARIANT="${1:-optimized}"
6+
NODE_VERSION="v22.19.0"
7+
BUILD_DIR="/Users/jdalton/projects/socket-cli/.custom-node-build"
8+
NODE_DIR="$BUILD_DIR/node-patched"
9+
PATCH_FILE="/tmp/node.v22.19.0.cpp.patch"
10+
11+
echo "πŸ”¨ Building patched Node.js $NODE_VERSION ($VARIANT variant)"
12+
13+
# Create build directory
14+
mkdir -p "$BUILD_DIR"
15+
cd "$BUILD_DIR"
16+
17+
# Clone Node.js if not already present
18+
if [ ! -d "node-patched" ]; then
19+
echo "πŸ“₯ Cloning Node.js $NODE_VERSION..."
20+
git clone --depth 1 --branch "$NODE_VERSION" https://github.com/nodejs/node.git node-patched
21+
cd node-patched
22+
else
23+
echo "πŸ“‚ Using existing Node.js clone..."
24+
cd node-patched
25+
# Reset to clean state
26+
git reset --hard HEAD
27+
git clean -fd
28+
fi
29+
30+
# Apply yao-pkg patch
31+
echo "🩹 Applying yao-pkg patches..."
32+
if [ ! -f "$PATCH_FILE" ]; then
33+
echo "❌ Patch file not found: $PATCH_FILE"
34+
echo " Downloading from yao-pkg/pkg-fetch..."
35+
curl -L -o "$PATCH_FILE" https://raw.githubusercontent.com/yao-pkg/pkg-fetch/main/patches/node.v22.19.0.cpp.patch
36+
fi
37+
38+
git apply "$PATCH_FILE" --verbose
39+
40+
# Clean previous build
41+
echo "🧹 Cleaning previous build..."
42+
make clean 2>/dev/null || true
43+
44+
# Configure with optimizations
45+
echo "βš™οΈ Configuring Node.js..."
46+
./configure \
47+
--enable-lto \
48+
--with-intl=small-icu \
49+
--without-npm \
50+
--without-corepack
51+
52+
# Build with optimizations
53+
echo "πŸ—οΈ Building Node.js (this will take 30-60 minutes)..."
54+
echo " Using $(sysctl -n hw.ncpu) CPU cores"
55+
56+
# Set compiler flags for aggressive optimization
57+
export CFLAGS="-O3 -flto"
58+
export CXXFLAGS="-O3 -flto"
59+
export LDFLAGS="-flto"
60+
61+
# Build using all available cores
62+
make -j$(sysctl -n hw.ncpu)
63+
64+
# Test the binary
65+
echo "βœ… Testing binary..."
66+
./out/Release/node --version
67+
./out/Release/node -e "console.log('Hello from patched Node.js!')"
68+
69+
# Report size
70+
echo ""
71+
echo "πŸŽ‰ Build complete!"
72+
echo " Binary: $NODE_DIR/out/Release/node"
73+
echo " Size: $(du -h "$NODE_DIR/out/Release/node" | cut -f1)"
74+
echo ""
75+
echo "πŸ“ To use with yao-pkg:"
76+
echo " export PKG_NODE_PATH=\"$NODE_DIR/out/Release/node\""
77+
echo " pnpm exec pkg . --targets node22-macos-arm64"

0 commit comments

Comments
Β (0)