Skip to content

Commit e6905a9

Browse files
committed
chore: update package dependencies and script changes
- Update package.json and pnpm-lock.yaml - Update build.mjs and clean.mjs scripts - Update various utilities and constants
1 parent f09ad96 commit e6905a9

File tree

12 files changed

+280
-344
lines changed

12 files changed

+280
-344
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"lint-staged": "lint-staged",
4949
"precommit": "lint-staged",
5050
"prepare": "husky",
51-
"bs": "pnpm run build:dist:src; pnpm exec socket --",
51+
"bs": "pnpm run build --src; pnpm exec socket --",
5252
"s": "pnpm exec socket --",
5353
"test": "node scripts/test.mjs",
5454
"test:validate": "node scripts/validate-tests.mjs",

pnpm-lock.yaml

Lines changed: 1 addition & 89 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/build.mjs

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,87 @@ async function watchBuild(options = {}) {
127127
return exitCode
128128
}
129129

130+
/**
131+
* Build SEA stub.
132+
*/
133+
async function buildStub(options = {}) {
134+
const { quiet = false } = options
135+
136+
if (!quiet) {
137+
log.progress('Building SEA stub')
138+
}
139+
140+
process.env['NODE_ENV'] = 'production'
141+
const exitCode = await runCommand(
142+
'pnpm',
143+
['exec', 'rollup', '-c', '.config/rollup.sea.config.mjs'],
144+
{
145+
stdio: quiet ? 'pipe' : 'inherit'
146+
}
147+
)
148+
149+
if (exitCode !== 0) {
150+
if (!quiet) {
151+
log.failed('SEA stub build failed')
152+
}
153+
return exitCode
154+
}
155+
156+
if (!quiet) {
157+
log.done('SEA stub built')
158+
}
159+
160+
return 0
161+
}
162+
163+
/**
164+
* Build SEA binary using yao-pkg.
165+
*/
166+
async function buildSea(options = {}) {
167+
const {
168+
arch = process.arch,
169+
minify = false, // Default to current platform
170+
platform = process.platform, // Default to current architecture
171+
quiet = false
172+
} = options
173+
174+
if (!quiet) {
175+
log.progress(`Building yao-pkg binary for ${platform}-${arch}`)
176+
}
177+
178+
// Build the SEA using yao-pkg (which uses the custom Node.js with patches)
179+
const args = [path.join(rootPath, 'scripts', 'build', 'build-stub.mjs')]
180+
181+
// Always pass platform and arch (using defaults if not specified)
182+
args.push(`--platform=${platform}`)
183+
args.push(`--arch=${arch}`)
184+
185+
if (minify) {
186+
args.push('--minify')
187+
}
188+
189+
if (quiet) {
190+
args.push('--quiet')
191+
}
192+
193+
const exitCode = await runCommand('node', args, {
194+
stdio: quiet ? 'pipe' : 'inherit'
195+
})
196+
197+
if (exitCode !== 0) {
198+
if (!quiet) {
199+
log.failed('yao-pkg binary build failed')
200+
}
201+
return exitCode
202+
}
203+
204+
if (!quiet) {
205+
log.done('yao-pkg binary built')
206+
}
207+
208+
return 0
209+
}
210+
130211
/**
131212
* Check if build is needed.
132213
*/
@@ -174,6 +255,20 @@ async function main() {
174255
type: 'boolean',
175256
default: false,
176257
},
258+
sea: {
259+
type: 'boolean',
260+
default: false,
261+
},
262+
stub: {
263+
type: 'boolean',
264+
default: false,
265+
},
266+
platform: {
267+
type: 'string',
268+
},
269+
arch: {
270+
type: 'string',
271+
},
177272
},
178273
allowPositionals: false,
179274
strict: false,
@@ -187,6 +282,10 @@ async function main() {
187282
console.log(' --help Show this help message')
188283
console.log(' --src Build source code only')
189284
console.log(' --types Build TypeScript declarations only')
285+
console.log(' --sea Build self-contained binary with yao-pkg')
286+
console.log(' --stub Build SEA stub only (for Node.js native SEA)')
287+
console.log(' --platform Platform for SEA build (darwin, linux, win32)')
288+
console.log(' --arch Architecture for SEA build (x64, arm64)')
190289
console.log(' --watch Watch mode for development')
191290
console.log(' --needed Only build if dist files are missing')
192291
console.log(' --quiet, --silent Suppress progress messages')
@@ -195,6 +294,9 @@ async function main() {
195294
console.log(' pnpm build # Full build (source + types)')
196295
console.log(' pnpm build --src # Build source only')
197296
console.log(' pnpm build --types # Build types only')
297+
console.log(' pnpm build --stub # Build SEA stub only (for Node.js native SEA)')
298+
console.log(' pnpm build --sea # Build self-contained binary with yao-pkg')
299+
console.log(' pnpm build --sea --platform=darwin --arch=arm64 # Build macOS ARM64 binary')
198300
console.log(' pnpm build --watch # Watch mode')
199301
console.log(' pnpm build --needed # Build only if needed')
200302
process.exitCode = 0
@@ -223,6 +325,20 @@ async function main() {
223325
if (values.watch) {
224326
exitCode = await watchBuild({ quiet, verbose })
225327
}
328+
// Build SEA binary
329+
else if (values.sea) {
330+
if (!quiet) {
331+
log.step('Building SEA binary')
332+
}
333+
exitCode = await buildSea({ quiet, verbose, platform: values.platform, arch: values.arch })
334+
}
335+
// Build SEA stub only
336+
else if (values.stub) {
337+
if (!quiet) {
338+
log.step('Building SEA stub only')
339+
}
340+
exitCode = await buildStub({ quiet, verbose })
341+
}
226342
// Build types only
227343
else if (values.types && !values.src) {
228344
if (!quiet) {

scripts/clean.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ async function main() {
155155
}
156156

157157
if (!quiet) {
158-
printHeader('Socket PackageURL Clean Runner')
158+
printHeader('Clean Runner')
159159
log.step('Cleaning project directories')
160160
}
161161

scripts/cleanup-builds.mjs

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ const __dirname = dirname(__filename)
2020
const ROOT_DIR = join(__dirname, '..')
2121
const DIST_DIR = join(ROOT_DIR, 'dist')
2222
const BUILD_DIR = join(ROOT_DIR, 'build')
23-
const PKG_BINARIES_DIR = join(ROOT_DIR, 'pkg-binaries')
24-
const CUSTOM_NODE_BUILD_DIR = join(ROOT_DIR, '.custom-node-build')
23+
const STUB_DIR = join(BUILD_DIR, 'stub')
24+
const TINY_NODE_BUILD_DIR = join(BUILD_DIR, 'tiny-node')
2525
const NODE_MODULES_DIR = join(ROOT_DIR, 'node_modules')
2626
const ROLLUP_CACHE_DIR = join(ROOT_DIR, '.rollup.cache')
2727
const CACHE_DIR = join(ROOT_DIR, '.cache')
@@ -96,31 +96,8 @@ async function cleanPkg() {
9696
console.log('🧹 Cleaning pkg binaries...')
9797
let totalRemoved = 0
9898

99-
// Clean pkg-binaries directory
100-
totalRemoved += await removeDir(PKG_BINARIES_DIR, 'pkg-binaries/')
101-
102-
// Clean build directory
103-
totalRemoved += await removeDir(BUILD_DIR, 'build/')
104-
105-
// Also remove any binaries in root (legacy cleanup)
106-
const rootBinaries = [
107-
'socket',
108-
'socket-macos-arm64',
109-
'socket-macos-x64',
110-
'socket-linux-x64',
111-
'socket-linux-arm64',
112-
'socket-win-x64',
113-
'socket-win-arm64',
114-
]
115-
116-
for (const binary of rootBinaries) {
117-
const binaryPath = join(ROOT_DIR, binary)
118-
if (existsSync(binaryPath)) {
119-
// eslint-disable-next-line no-await-in-loop
120-
await rm(binaryPath, { force: true })
121-
console.log(` ✅ Removed ${binary} from root (legacy)`)
122-
}
123-
}
99+
// Clean build/stub directory
100+
totalRemoved += await removeDir(STUB_DIR, 'build/stub/')
124101

125102
if (totalRemoved === 0) {
126103
console.log(' ℹ️ No pkg binaries found (already clean)')
@@ -134,13 +111,13 @@ async function cleanPkg() {
134111
async function cleanOldNode() {
135112
console.log('🧹 Cleaning old Node.js builds...')
136113

137-
if (!existsSync(CUSTOM_NODE_BUILD_DIR)) {
138-
console.log(' ℹ️ .custom-node-build/ not found')
114+
if (!existsSync(TINY_NODE_BUILD_DIR)) {
115+
console.log(' ℹ️ build/tiny-node/ not found')
139116
console.log()
140117
return
141118
}
142119

143-
const entries = await readdir(CUSTOM_NODE_BUILD_DIR, { withFileTypes: true })
120+
const entries = await readdir(TINY_NODE_BUILD_DIR, { withFileTypes: true })
144121
let totalRemoved = 0
145122

146123
for (const entry of entries) {
@@ -155,7 +132,7 @@ async function cleanOldNode() {
155132
}
156133

157134
// Remove old builds
158-
const dirPath = join(CUSTOM_NODE_BUILD_DIR, entry.name)
135+
const dirPath = join(TINY_NODE_BUILD_DIR, entry.name)
159136
// eslint-disable-next-line no-await-in-loop
160137
totalRemoved += await removeDir(dirPath, entry.name + '/')
161138
}
@@ -185,10 +162,10 @@ async function cleanCurrentNode() {
185162
console.log('🧹 Cleaning current Node.js build...')
186163
console.log(' ⚠️ This will require rebuilding (30-60 minutes)')
187164

188-
const removed = await removeDir(CUSTOM_NODE_BUILD_DIR, '.custom-node-build/')
165+
const removed = await removeDir(TINY_NODE_BUILD_DIR, 'build/tiny-node/')
189166
if (removed > 0) {
190167
console.log(` 🎉 Freed ~${removed.toFixed(1)} GB`)
191-
console.log(' 📝 Rebuild with: pnpm run build:yao-pkg:node')
168+
console.log(' 📝 Rebuild with: node scripts/build/build-tiny-node.mjs')
192169
}
193170
console.log()
194171
}

scripts/esbuild-inject-helper.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

22
// esbuild inject helper for import.meta compatibility
33
if (typeof __filename === 'undefined') {
4-
global.__filename = require('url').fileURLToPath(import.meta.url);
4+
global.__filename = require('node:url').fileURLToPath(import.meta.url);
55
}
66
if (typeof __dirname === 'undefined') {
7-
global.__dirname = require('path').dirname(__filename);
7+
global.__dirname = require('node:path').dirname(__filename);
88
}

0 commit comments

Comments
 (0)