@@ -10,25 +10,27 @@ import {traverseFiles} from './stages/traverse-files.js';
1010import { scanDependencies } from './stages/scan-dependencies.js' ;
1111import { availableParallelism } from 'node:os' ;
1212
13- let advanced = false ;
13+ const maxThreads = availableParallelism ( ) ;
14+
15+ const params : {
16+ threads : number ;
17+ } = {
18+ threads : maxThreads * 0.5
19+ } ;
1420
1521for ( let i = 0 ; i < process . argv . length ; ++ i ) {
16- if ( process . argv [ i ] === '--advanced' ) advanced = true ;
22+ if ( process . argv [ i ] === '--threads' ) {
23+ params . threads = Math . min (
24+ Math . max ( Number ( process . argv [ i ] ) + 1 , 1 ) ,
25+ maxThreads
26+ ) ;
27+ }
1728}
1829
19- function getWantedThreads ( scanSpeed : string ) : number {
20- const threads = availableParallelism ( ) ;
21- switch ( scanSpeed ) {
22- case 'slow' :
23- return threads * 0.25 ;
24- case 'medium' :
25- return threads * 0.5 ;
26- case 'fast' :
27- return threads * 0.75 ;
28- case 'fastest' :
29- return threads ;
30- }
31- return 1 ;
30+ if ( params . threads ) {
31+ if ( params . threads > maxThreads ) params . threads = maxThreads ;
32+ } else {
33+ params . threads = maxThreads * 0.5 ;
3234}
3335
3436const availableManifests : Record < string , modReplacements . ManifestModule > = {
@@ -140,41 +142,7 @@ async function runModuleReplacements(): Promise<void> {
140142 cl . confirm ( {
141143 message : 'Automatically uninstall packages?' ,
142144 initialValue : false
143- } ) ,
144- scanSpeed : ( ) =>
145- advanced
146- ? cl . select ( {
147- message : 'Preferred scan speed' ,
148- options : [
149- {
150- value : 'fastest' ,
151- label : 'Fastest' ,
152- hint : 'uses all the threads, pushes cpu to 100%'
153- } ,
154- {
155- value : 'fast' ,
156- label : 'Fast' ,
157- hint : '75% of available threads'
158- } ,
159- {
160- value : 'medium' ,
161- label : 'Medium' ,
162- hint : '50% of available threads'
163- } ,
164- {
165- value : 'slow' ,
166- label : 'Slow' ,
167- hint : '25% of available threads'
168- } ,
169- {
170- value : 'slowest' ,
171- label : 'Slowest' ,
172- hint : 'disables parallelism, 1 thread'
173- }
174- ] ,
175- initialValue : 'medium'
176- } )
177- : Promise . resolve ( 'medium' )
145+ } )
178146 } ,
179147 {
180148 onCancel : ( ) => {
@@ -254,12 +222,11 @@ async function runModuleReplacements(): Promise<void> {
254222
255223 try {
256224 const files = await traverseFiles ( options . filesDir ) ;
257- const threads = getWantedThreads ( options . scanSpeed ) ;
258225
259226 const scanFilesResult = await scanFiles (
260227 files ,
261228 manifestReplacements ,
262- threads ,
229+ params . threads ,
263230 scanSpinner
264231 ) ;
265232
0 commit comments