@@ -25,11 +25,6 @@ import { getDefaultLogger } from '@socketsecurity/lib/logger'
2525import { downloadSocketBtmRelease } from '@socketsecurity/lib/releases/socket-btm'
2626import { spawn } from '@socketsecurity/lib/spawn'
2727
28- import {
29- computeFileHash ,
30- generateHeader ,
31- } from './utils/socket-btm-releases.mjs'
32-
3328const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) )
3429const rootPath = path . join ( __dirname , '..' )
3530const logger = getDefaultLogger ( )
@@ -99,14 +94,7 @@ const ASSETS = {
9994 * Download a single asset.
10095 */
10196async function downloadAsset ( config ) {
102- const {
103- description,
104- download,
105- extract,
106- name,
107- process : processConfig ,
108- type,
109- } = config
97+ const { description, download, extract, name, type } = config
11098
11199 try {
112100 logger . group ( `Extracting ${ name } from socket-btm releases...` )
@@ -132,8 +120,6 @@ async function downloadAsset(config) {
132120 // Process based on asset type.
133121 if ( type === 'archive' && extract ) {
134122 await extractArchive ( assetPath , extract , name )
135- } else if ( type === 'processed' && processConfig ) {
136- await processAsset ( assetPath , processConfig , name )
137123 }
138124
139125 logger . groupEnd ( )
@@ -204,78 +190,6 @@ async function extractArchive(tarGzPath, extractConfig, assetName) {
204190 await fs . writeFile ( versionPath , tag , 'utf-8' )
205191}
206192
207- /**
208- * Process and transform asset (e.g., add header to JS file).
209- */
210- async function processAsset ( assetPath , processConfig , assetName ) {
211- const { outputPath } = processConfig
212-
213- // Check if extraction needed by comparing version.
214- const assetDir = path . dirname ( assetPath )
215- const sourceVersionPath = path . join ( assetDir , '.version' )
216- const outputVersionPath = path . join (
217- path . dirname ( outputPath ) ,
218- `${ path . basename ( outputPath , path . extname ( outputPath ) ) } .version` ,
219- )
220-
221- if (
222- existsSync ( outputVersionPath ) &&
223- existsSync ( outputPath ) &&
224- existsSync ( sourceVersionPath )
225- ) {
226- const cachedVersion = ( await fs . readFile ( outputVersionPath , 'utf8' ) ) . trim ( )
227- const sourceVersion = ( await fs . readFile ( sourceVersionPath , 'utf8' ) ) . trim ( )
228- if ( cachedVersion === sourceVersion ) {
229- logger . info ( `${ assetName } already up to date` )
230- return
231- }
232-
233- logger . info ( `${ assetName } version changed, re-extracting...` )
234- }
235-
236- // Read the downloaded asset.
237- let content = await fs . readFile ( assetPath , 'utf-8' )
238-
239- // Compute source hash for cache validation.
240- const sourceHash = await computeFileHash ( assetPath )
241-
242- // Get tag from source version file.
243- if ( ! existsSync ( sourceVersionPath ) ) {
244- throw new Error (
245- `Source version file not found: ${ sourceVersionPath } . ` +
246- 'Please download assets first using the build system.' ,
247- )
248- }
249-
250- const tag = ( await fs . readFile ( sourceVersionPath , 'utf8' ) ) . trim ( )
251- if ( ! tag || tag . length === 0 ) {
252- throw new Error (
253- `Invalid version file content at ${ sourceVersionPath } . ` +
254- 'Please re-download assets.' ,
255- )
256- }
257-
258- // Generate output file with header.
259- const header = generateHeader ( {
260- assetName : path . basename ( assetPath ) ,
261- scriptName : 'scripts/download-assets.mjs' ,
262- sourceHash,
263- tag,
264- } )
265-
266- const output = `${ header }
267-
268- ${ content }
269- `
270-
271- // Ensure build directory exists before writing.
272- await fs . mkdir ( path . dirname ( outputPath ) , { recursive : true } )
273- await fs . writeFile ( outputPath , output , 'utf-8' )
274-
275- // Write version file.
276- await fs . writeFile ( outputVersionPath , tag , 'utf-8' )
277- }
278-
279193/**
280194 * Download multiple assets (parallel by default, sequential opt-in).
281195 *
0 commit comments