55 * Usage:
66 * node scripts/download-assets.mjs [asset-names...] [options]
77 * node scripts/download-assets.mjs # Download all assets (parallel)
8- * node scripts/download-assets.mjs yoga models # Download specific assets (parallel)
8+ * node scripts/download-assets.mjs models # Download specific assets (parallel)
99 * node scripts/download-assets.mjs --no-parallel # Download all assets (sequential)
1010 *
1111 * Assets:
1212 * binject - Binary injection tool
1313 * iocraft - iocraft native bindings (.node files)
1414 * models - AI models tar.gz (MiniLM, CodeT5)
1515 * node-smol - Minimal Node.js binaries
16- * yoga - Yoga layout WASM (yoga-sync.mjs)
1716 */
1817
1918import { existsSync , promises as fs } from 'node:fs'
@@ -26,11 +25,6 @@ import { getDefaultLogger } from '@socketsecurity/lib/logger'
2625import { downloadSocketBtmRelease } from '@socketsecurity/lib/releases/socket-btm'
2726import { spawn } from '@socketsecurity/lib/spawn'
2827
29- import {
30- computeFileHash ,
31- generateHeader ,
32- } from './utils/socket-btm-releases.mjs'
33-
3428const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) )
3529const rootPath = path . join ( __dirname , '..' )
3630const logger = getDefaultLogger ( )
@@ -94,36 +88,13 @@ const ASSETS = {
9488 name : 'node-smol' ,
9589 type : 'binary' ,
9690 } ,
97- yoga : {
98- description : 'Yoga layout WASM' ,
99- download : {
100- asset : 'yoga-sync-*.mjs' ,
101- cwd : rootPath ,
102- downloadDir : '../../packages/build-infra/build/downloaded' ,
103- quiet : false ,
104- tool : 'yoga-layout' ,
105- } ,
106- name : 'yoga' ,
107- process : {
108- format : 'javascript' ,
109- outputPath : path . join ( rootPath , 'build/yoga-sync.mjs' ) ,
110- } ,
111- type : 'processed' ,
112- } ,
11391}
11492
11593/**
11694 * Download a single asset.
11795 */
11896async function downloadAsset ( config ) {
119- const {
120- description,
121- download,
122- extract,
123- name,
124- process : processConfig ,
125- type,
126- } = config
97+ const { description, download, extract, name, type } = config
12798
12899 try {
129100 logger . group ( `Extracting ${ name } from socket-btm releases...` )
@@ -149,8 +120,6 @@ async function downloadAsset(config) {
149120 // Process based on asset type.
150121 if ( type === 'archive' && extract ) {
151122 await extractArchive ( assetPath , extract , name )
152- } else if ( type === 'processed' && processConfig ) {
153- await processAsset ( assetPath , processConfig , name )
154123 }
155124
156125 logger . groupEnd ( )
@@ -221,106 +190,6 @@ async function extractArchive(tarGzPath, extractConfig, assetName) {
221190 await fs . writeFile ( versionPath , tag , 'utf-8' )
222191}
223192
224- /**
225- * Transform yoga-sync.mjs to remove top-level await for CJS compatibility.
226- *
227- * The newer yoga-sync builds incorrectly use top-level await which isn't
228- * compatible with esbuild's CJS output format. Despite the name, yogaPromise
229- * is synchronous (-sWASM_ASYNC_COMPILATION=0), so we can call it directly.
230- */
231- function transformYogaSync ( content ) {
232- // Pattern: const Yoga = wrapAssembly(await yogaPromise);
233- // Transform to: const Yoga = wrapAssembly(yogaPromise);
234- // (yogaPromise is synchronous despite its name)
235- const hasTopLevelAwait = content . includes ( 'wrapAssembly(await yogaPromise)' )
236- if ( ! hasTopLevelAwait ) {
237- return content
238- }
239-
240- // Replace the top-level await pattern with synchronous call.
241- return content . replace (
242- / c o n s t Y o g a = w r a p A s s e m b l y \( a w a i t y o g a P r o m i s e \) ; / ,
243- 'const Yoga = wrapAssembly(yogaPromise);' ,
244- )
245- }
246-
247- /**
248- * Process and transform asset (e.g., add header to JS file).
249- */
250- async function processAsset ( assetPath , processConfig , assetName ) {
251- const { outputPath } = processConfig
252-
253- // Check if extraction needed by comparing version.
254- const assetDir = path . dirname ( assetPath )
255- const sourceVersionPath = path . join ( assetDir , '.version' )
256- const outputVersionPath = path . join (
257- path . dirname ( outputPath ) ,
258- `${ path . basename ( outputPath , path . extname ( outputPath ) ) } .version` ,
259- )
260-
261- if (
262- existsSync ( outputVersionPath ) &&
263- existsSync ( outputPath ) &&
264- existsSync ( sourceVersionPath )
265- ) {
266- const cachedVersion = ( await fs . readFile ( outputVersionPath , 'utf8' ) ) . trim ( )
267- const sourceVersion = ( await fs . readFile ( sourceVersionPath , 'utf8' ) ) . trim ( )
268- if ( cachedVersion === sourceVersion ) {
269- logger . info ( `${ assetName } already up to date` )
270- return
271- }
272-
273- logger . info ( `${ assetName } version changed, re-extracting...` )
274- }
275-
276- // Read the downloaded asset.
277- let content = await fs . readFile ( assetPath , 'utf-8' )
278-
279- // Transform yoga-sync to remove top-level await for CJS compatibility.
280- if ( assetName === 'yoga' ) {
281- content = transformYogaSync ( content )
282- }
283-
284- // Compute source hash for cache validation.
285- const sourceHash = await computeFileHash ( assetPath )
286-
287- // Get tag from source version file.
288- if ( ! existsSync ( sourceVersionPath ) ) {
289- throw new Error (
290- `Source version file not found: ${ sourceVersionPath } . ` +
291- 'Please download assets first using the build system.' ,
292- )
293- }
294-
295- const tag = ( await fs . readFile ( sourceVersionPath , 'utf8' ) ) . trim ( )
296- if ( ! tag || tag . length === 0 ) {
297- throw new Error (
298- `Invalid version file content at ${ sourceVersionPath } . ` +
299- 'Please re-download assets.' ,
300- )
301- }
302-
303- // Generate output file with header.
304- const header = generateHeader ( {
305- assetName : path . basename ( assetPath ) ,
306- scriptName : 'scripts/download-assets.mjs' ,
307- sourceHash,
308- tag,
309- } )
310-
311- const output = `${ header }
312-
313- ${ content }
314- `
315-
316- // Ensure build directory exists before writing.
317- await fs . mkdir ( path . dirname ( outputPath ) , { recursive : true } )
318- await fs . writeFile ( outputPath , output , 'utf-8' )
319-
320- // Write version file.
321- await fs . writeFile ( outputVersionPath , tag , 'utf-8' )
322- }
323-
324193/**
325194 * Download multiple assets (parallel by default, sequential opt-in).
326195 *
0 commit comments