Skip to content

Commit

Permalink
Limit the concurrency when installing packages.
Browse files Browse the repository at this point in the history
  • Loading branch information
francois2metz committed Feb 28, 2024
1 parent 1fb9adc commit 3ec4164
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 24 deletions.
44 changes: 35 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"license": "GPL-3.0-or-later",
"dependencies": {
"francois-libyear": "^0.8.0",
"p-limit": "^5.0.0",
"preferred-pm": "^3.0.3",
"semver": "^7.5.2",
"simple-git": "^3.19.0"
Expand Down
34 changes: 19 additions & 15 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import simpleGit from 'simple-git';
import { libyear } from 'francois-libyear';
import preferredPM from 'preferred-pm';
import semver from 'semver';
import pLimit from 'p-limit';
import { parseFile, parseRepositoryLine, replaceRepositoryWithSafeChar } from './utils.js';
import packageJSON from '../package.json' assert { type: 'json' };

Expand Down Expand Up @@ -41,21 +42,24 @@ export async function main() {
const content = await readFile(filePath, { encoding: 'utf8' });
const lines = parseFile(content);
const clonedRepositoriesPath = await cloneRepositories(lines);
const installResult = await Promise.all(lines.map(async ({ repository, path }) => {
try {
const repositoryPath = clonedRepositoriesPath[repository];
const packagePath = join(repositoryPath, path);
const packageManager = await getPreferredPm(packagePath);
await installDependencies(packagePath, packageManager);
return {
repository,
path,
packagePath,
packageManager,
};
} catch(e) {
throw new Error(`Error while processing the ${repository}#${path}: ${e}`);
}
const limit = pLimit(3);
const installResult = await Promise.all(lines.map(({ repository, path }) => {
return limit(async () => {
try {
const repositoryPath = clonedRepositoriesPath[repository];
const packagePath = join(repositoryPath, path);
const packageManager = await getPreferredPm(packagePath);
await installDependencies(packagePath, packageManager);
return {
repository,
path,
packagePath,
packageManager,
};
} catch(e) {
throw new Error(`Error while processing the ${repository}#${path}: ${e}`);
}
});
}));
const indexResult = {};
for await (const { repository, path, packagePath, packageManager } of installResult) {
Expand Down

0 comments on commit 3ec4164

Please sign in to comment.