@@ -8,6 +8,11 @@ const pacote = require('pacote')
8
8
const validateNpmPackageName = require ( 'validate-npm-package-name' )
9
9
10
10
const 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' )
11
16
12
17
const rootPath = path . resolve ( __dirname , '..' )
13
18
const dataPath = path . join ( rootPath , 'data' )
@@ -20,59 +25,6 @@ const { compare: alphanumericComparator } = new Intl.Collator(undefined, {
20
25
sensitivity : 'base'
21
26
} )
22
27
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
-
76
28
void ( async ( ) => {
77
29
const spinner = yoctoSpinner ( ) . start ( )
78
30
const builtinNames = Module . builtinModules . toSorted ( alphanumericComparator )
@@ -112,7 +64,7 @@ void (async () => {
112
64
}
113
65
return false
114
66
} ,
115
- { retries : 3 }
67
+ { retries : 3 , signal : abortSignal }
116
68
)
117
69
spinner . text = 'Writing json files...'
118
70
await Promise . all (
@@ -125,6 +77,6 @@ void (async () => {
125
77
)
126
78
spinner . stop ( )
127
79
if ( invalidNames . size ) {
128
- console . log ( `⚠️ Removed missing packages:` , [ ...invalidNames ] )
80
+ console . warn ( `⚠️ Removed missing packages:` , [ ...invalidNames ] )
129
81
}
130
82
} ) ( )
0 commit comments