Skip to content

Commit 3fa49d6

Browse files
committed
Update build scripts and utilities
1 parent 4b08a1b commit 3fa49d6

File tree

11 files changed

+2354
-8
lines changed

11 files changed

+2354
-8
lines changed

scripts/build.mjs

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44

55
import { spawn } from 'node:child_process'
6-
import { existsSync } from 'node:fs'
6+
import { existsSync, statSync } from 'node:fs'
77
import path from 'node:path'
88
import { fileURLToPath } from 'node:url'
99
import { parseArgs } from 'node:util'
@@ -230,6 +230,14 @@ async function main() {
230230
type: 'boolean',
231231
default: false,
232232
},
233+
node: {
234+
type: 'boolean',
235+
default: false,
236+
},
237+
stub: {
238+
type: 'boolean',
239+
default: false,
240+
},
233241
},
234242
allowPositionals: false,
235243
strict: false,
@@ -244,15 +252,66 @@ async function main() {
244252
console.log(' --types Build TypeScript declarations only')
245253
console.log(' --watch Watch mode for development')
246254
console.log(' --needed Only build if dist files are missing')
255+
console.log(' --node Build custom Node.js binary (socket-node)')
256+
console.log(' --stub Build stub/SEA binary (includes Node build if needed)')
247257
console.log('\nExamples:')
248258
console.log(' pnpm build # Full build (source + types)')
249259
console.log(' pnpm build --src # Build source only')
250260
console.log(' pnpm build --types # Build types only')
251261
console.log(' pnpm build --watch # Watch mode')
262+
console.log(' pnpm build --node # Build custom Node.js binary')
263+
console.log(' pnpm build --stub # Build standalone executable')
252264
process.exitCode = 0
253265
return
254266
}
255267

268+
// Handle custom Node.js build.
269+
if (values.node) {
270+
printHeader('Custom Node.js Builder')
271+
log.step('Building custom Node.js binary')
272+
273+
const buildNodeScript = path.join(__dirname, 'build', 'build-tiny-node.mjs')
274+
const nodeArgs = ['exec', 'node', buildNodeScript]
275+
276+
const nodeExitCode = await runCommand('pnpm', nodeArgs)
277+
278+
if (nodeExitCode !== 0) {
279+
log.error('Node build failed')
280+
process.exitCode = nodeExitCode
281+
} else {
282+
// Report file size
283+
const nodeBinary = WIN32 ? 'node.exe' : 'node'
284+
const nodePath = path.join(rootPath, 'build', 'tiny-node', `node-v24.9.0-custom`, 'out', 'Release', nodeBinary)
285+
if (existsSync(nodePath)) {
286+
const stats = statSync(nodePath)
287+
const sizeMB = (stats.size / 1024 / 1024).toFixed(1)
288+
printFooter(`Node.js built successfully! Size: ${sizeMB}MB`)
289+
} else {
290+
printFooter('Node.js built successfully!')
291+
}
292+
}
293+
return
294+
}
295+
296+
// Handle stub/SEA build.
297+
if (values.stub) {
298+
printHeader('Stub/SEA Builder')
299+
log.step('Building standalone executable')
300+
301+
const buildStubScript = path.join(__dirname, 'build', 'build-stub.mjs')
302+
const stubArgs = ['exec', 'node', buildStubScript]
303+
304+
const stubExitCode = await runCommand('pnpm', stubArgs)
305+
306+
if (stubExitCode !== 0) {
307+
log.error('Stub build failed')
308+
process.exitCode = stubExitCode
309+
} else {
310+
printFooter('Stub/SEA binary built successfully!')
311+
}
312+
return
313+
}
314+
256315
// Detect build configuration.
257316
const config = detectBuildConfig()
258317

scripts/build/build-stub.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export async function buildStub(options = {}) {
5454
console.log('📦 Building distribution files first...')
5555

5656
const buildExitCode = await new Promise((resolve) => {
57-
const child = spawn('pnpm', ['run', 'build:dist:src'], {
57+
const child = spawn('pnpm', ['run', 'build', '--src'], {
5858
cwd: ROOT_DIR,
5959
stdio: quiet ? 'pipe' : 'inherit'
6060
})

scripts/build/build-tiny-node.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const logger = {
4141

4242
// Configuration
4343
const ROOT_DIR = join(__dirname, '../..')
44-
const BUILD_DIR = join(ROOT_DIR, 'build', 'tiny-node')
44+
const BUILD_DIR = join(ROOT_DIR, 'build', 'socket-node')
4545
const CUSTOM_PATCHES_DIR = join(__dirname, 'stub', 'patches', 'socket')
4646

4747
// Parse command line arguments
@@ -87,7 +87,7 @@ Options:
8787
Examples: --version=v24.9.0, --version=v22.19.0
8888
--skip-download Skip downloading if source already exists
8989
--skip-yao-patch Skip applying yao-pkg patches
90-
--custom-patches Apply custom patches from build/tiny-node/patches/
90+
--custom-patches Apply custom patches from build/socket-node/patches/
9191
--skip-code-mods Skip V8 flags and node-gyp modifications
9292
--help, -h Show this help
9393

scripts/build/ensure-node-in-cache.mjs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const PKG_CACHE_DIR = join(homedir(), '.pkg-cache', 'v3.5')
1818
/**
1919
* Ensure custom Node binary is in pkg cache
2020
*
21-
* This function looks for the custom Node.js binary built by build-tiny-node.mjs
21+
* This function looks for the custom Node.js binary built by build-socket-node.mjs
2222
* and copies it to pkg's cache directory if not already there.
2323
*
2424
* @param {string} nodeVersion - Node version (e.g., 'v24.9.0')
@@ -46,9 +46,10 @@ export default async function ensureCustomNodeInCache(nodeVersion = 'v24.9.0', p
4646
const nodeBinary = platform === 'win32' ? 'node.exe' : 'node'
4747

4848
const possiblePaths = [
49-
join(rootDir, 'build', 'tiny-node', `node-${nodeVersion}-custom`, 'out', 'Release', nodeBinary),
50-
join(rootDir, 'build', 'tiny-node', 'node-yao-pkg', 'out', 'Release', nodeBinary),
51-
join(rootDir, 'build', 'tiny-node', 'node', 'out', 'Release', nodeBinary)
49+
join(rootDir, 'binaries', 'socket-node', `node-${nodeVersion}-${platform}-${arch}${platform === 'win32' ? '.exe' : ''}`),
50+
join(rootDir, 'build', 'socket-node', `node-${nodeVersion}-custom`, 'out', 'Release', nodeBinary),
51+
join(rootDir, 'build', 'socket-node', 'node-yao-pkg', 'out', 'Release', nodeBinary),
52+
join(rootDir, 'build', 'socket-node', 'node', 'out', 'Release', nodeBinary)
5253
]
5354

5455
let sourcePath = null
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"lastSync": "2025-10-09T12:32:10.950Z",
3+
"versions": [
4+
"v24.9.0",
5+
"v22.19.0",
6+
"v20.19.5"
7+
],
8+
"source": "https://github.com/yao-pkg/pkg-fetch/tree/main/patches"
9+
}

0 commit comments

Comments
 (0)