Skip to content

Commit

Permalink
--advanced -> --threads & remove from interactive cli
Browse files Browse the repository at this point in the history
Resolves 57bb3a0#r1714034609
  • Loading branch information
VandeurenGlenn committed Aug 12, 2024
1 parent 57bb3a0 commit 16dc098
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 62 deletions.
10 changes: 0 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,6 @@ The interactive CLI can guide you through the following steps:
npx esperf
```

## Advanced Usage

The interactive CLI will show more steps:

- Set scan speed

```sh
npx esperf --advanced
```

## License

MIT
71 changes: 19 additions & 52 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,27 @@ import {traverseFiles} from './stages/traverse-files.js';
import {scanDependencies} from './stages/scan-dependencies.js';
import {availableParallelism} from 'node:os';

let advanced = false;
const maxThreads = availableParallelism();

const params: {
threads: number;
} = {
threads: maxThreads * 0.5
};

for (let i = 0; i < process.argv.length; ++i) {
if (process.argv[i] === '--advanced') advanced = true;
if (process.argv[i] === '--threads') {
params.threads = Math.min(
Math.max(Number(process.argv[i]) + 1, 1),
maxThreads
);
}
}

function getWantedThreads(scanSpeed: string): number {
const threads = availableParallelism();
switch (scanSpeed) {
case 'slow':
return threads * 0.25;
case 'medium':
return threads * 0.5;
case 'fast':
return threads * 0.75;
case 'fastest':
return threads;
}
return 1;
if (params.threads) {
if (params.threads > maxThreads) params.threads = maxThreads;
} else {
params.threads = maxThreads * 0.5;
}

const availableManifests: Record<string, modReplacements.ManifestModule> = {
Expand Down Expand Up @@ -140,41 +142,7 @@ async function runModuleReplacements(): Promise<void> {
cl.confirm({
message: 'Automatically uninstall packages?',
initialValue: false
}),
scanSpeed: () =>
advanced
? cl.select({
message: 'Preferred scan speed',
options: [
{
value: 'fastest',
label: 'Fastest',
hint: 'uses all the threads, pushes cpu to 100%'
},
{
value: 'fast',
label: 'Fast',
hint: '75% of available threads'
},
{
value: 'medium',
label: 'Medium',
hint: '50% of available threads'
},
{
value: 'slow',
label: 'Slow',
hint: '25% of available threads'
},
{
value: 'slowest',
label: 'Slowest',
hint: 'disables parallelism, 1 thread'
}
],
initialValue: 'medium'
})
: Promise.resolve('medium')
})
},
{
onCancel: () => {
Expand Down Expand Up @@ -254,12 +222,11 @@ async function runModuleReplacements(): Promise<void> {

try {
const files = await traverseFiles(options.filesDir);
const threads = getWantedThreads(options.scanSpeed);

const scanFilesResult = await scanFiles(
files,
manifestReplacements,
threads,
params.threads,
scanSpinner
);

Expand Down

0 comments on commit 16dc098

Please sign in to comment.