@@ -8,6 +8,11 @@ const pacote = require('pacote')
88const validateNpmPackageName = require ( 'validate-npm-package-name' )
99
1010const yoctoSpinner = require ( '@socketregistry/yocto-spinner' )
11+ const constants = require ( '@socketsecurity/registry/lib/constants' )
12+ const {
13+ abortSignal
14+ } = constants
15+ const { pFilter } = require ( '@socketsecurity/registry/lib/promises' )
1116
1217const rootPath = path . resolve ( __dirname , '..' )
1318const dataPath = path . join ( rootPath , 'data' )
@@ -20,59 +25,6 @@ const { compare: alphanumericComparator } = new Intl.Collator(undefined, {
2025 sensitivity : 'base'
2126} )
2227
23- function arrayChunk ( arr , size = 2 ) {
24- const { length } = arr
25- const chunkSize = Math . min ( length , size )
26- const chunks = [ ]
27- for ( let i = 0 ; i < length ; i += chunkSize ) {
28- chunks . push ( arr . slice ( i , i + chunkSize ) )
29- }
30- return chunks
31- }
32-
33- async function pFilter ( array , concurrency , callbackFn , options ) {
34- return (
35- await pFilterChunk ( arrayChunk ( array , concurrency ) , callbackFn , options )
36- ) . flat ( )
37- }
38-
39- async function pFilterChunk ( chunks , callbackFn , options ) {
40- const { retries = 0 , signal } = { __proto__ : null , ...options }
41- const { length } = chunks
42- const filteredChunks = Array ( length )
43- for ( let i = 0 ; i < length ; i += 1 ) {
44- // Process each chunk, filtering based on the callback function.
45- if ( signal ?. aborted ) {
46- filteredChunks [ i ] = [ ]
47- } else {
48- const chunk = chunks [ i ]
49- // eslint-disable-next-line no-await-in-loop
50- const predicateResults = await Promise . all (
51- chunk . map ( value => {
52- if ( signal ?. aborted ) {
53- return Promise . resolve ( )
54- }
55- if ( retries === 0 ) {
56- return callbackFn ( value , { signal } )
57- }
58- let attempts = retries
59- return ( async ( ) => {
60- while ( attempts -- >= 0 ) {
61- // eslint-disable-next-line no-await-in-loop
62- if ( await callbackFn ( value , { signal } ) ) {
63- return true
64- }
65- }
66- return false
67- } ) ( )
68- } )
69- )
70- filteredChunks [ i ] = chunk . filter ( ( _v , i ) => predicateResults [ i ] )
71- }
72- }
73- return filteredChunks
74- }
75-
7628void ( async ( ) => {
7729 const spinner = yoctoSpinner ( ) . start ( )
7830 const builtinNames = Module . builtinModules . toSorted ( alphanumericComparator )
@@ -112,7 +64,7 @@ void (async () => {
11264 }
11365 return false
11466 } ,
115- { retries : 3 }
67+ { retries : 3 , signal : abortSignal }
11668 )
11769 spinner . text = 'Writing json files...'
11870 await Promise . all (
@@ -125,6 +77,6 @@ void (async () => {
12577 )
12678 spinner . stop ( )
12779 if ( invalidNames . size ) {
128- console . log ( `⚠️ Removed missing packages:` , [ ...invalidNames ] )
80+ console . warn ( `⚠️ Removed missing packages:` , [ ...invalidNames ] )
12981 }
13082} ) ( )
0 commit comments