Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions bin/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ Options:
--high-speed-store: specify high speed store script to cache tgz files, and so on. Should export '* getStream(url)' function.
--dependencies-tree: install with dependencies tree to restore the last install.
--force-link-latest: force link latest version package to module root path.
--concurrency: install concurrency, default is 10
--retry: retry count, default is 3
`
);
process.exit(0);
Expand Down Expand Up @@ -296,6 +298,9 @@ debug('argv: %j, env: %j', argv, env);
config.trace = argv.trace;
config.engineStrict = argv['engine-strict'];
config.registryOnly = argv['registry-only'];
config.concurrency = process.env.concurrency || argv.concurrency;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

process.env.concurrency and process.env.retry are not needed and can be removed, as they are currently passed in as CLI parameters.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里南取特意提醒我加上去的,因为 tnpm 是 fork 的 npminstall 进程,cli 传参传不进去,env 传参会更加方便、合适。

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那可能需要设置一下环境变量前缀,如 NPMINSTALL_CONCURRENCY 这样,要不然 concurrency 太通用了

config.retry = process.env.retry || argv.retry;

if (config.production || argv.global) {
// make sure show detail on production install or global install
config.detail = true;
Expand Down
2 changes: 1 addition & 1 deletion lib/download/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ async function download(pkg, options) {
const tarballUrls = utils.parseTarballUrls(pkg.dist.tarball);
let tarballUrlIndex = 0;
let tarballUrl;
while (count < 3) {
while (count < options.retry) {
tarballUrl = tarballUrls[tarballUrlIndex++];
if (!tarballUrl) {
tarballUrlIndex = 0;
Expand Down
3 changes: 3 additions & 0 deletions lib/format_install_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ module.exports = function formatInstallOptions(options) {
options.pruneCount = 0;
options.pruneSize = 0;

options.concurrency = isNaN(options.concurrency) ? 10 : Number(options.concurrency);
options.retry = isNaN(options.retry) ? 3 : Number(options.retry);

debug('options: %j', options);

return options;
Expand Down
4 changes: 3 additions & 1 deletion lib/local_install.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ const Context = require('./context');
* - {Boolean} [trace] - show memory and cpu usages traces of installation
* - {Boolean} [flatten] - flatten dependencies by matching ancestors' dependencies
* - {Boolean} [disableDedupe] - disable dedupe mode, will back to npm@2 node_modules tree
* - {Number} [concurrency] - install concurrency, default is `10`
* - {Number} [retry] - retry count, default is `3`
* @param {Object} context - install context
*/
module.exports = async (options, context = new Context()) => {
Expand Down Expand Up @@ -147,7 +149,7 @@ async function _install(options, context) {
await installOne(options.targetDir, childPkg, options, context);
};

await pMap(pkgs, mapper, 10);
await pMap(pkgs, mapper, options.concurrency);
options.downloadFinished = Date.now();
options.spinner && options.spinner.succeed(`Installed ${pkgs.length} packages`);

Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/options-concurrency/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "options-concurrency",
"dependencies": {
"lodash": "*"
}
}
6 changes: 6 additions & 0 deletions test/fixtures/options-retry/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "options-retry",
"dependencies": {
"ladaygagaloadshnotexisit": "*"
}
}
19 changes: 19 additions & 0 deletions test/install_concurrency.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const coffee = require('coffee');
const helper = require('./helper');

describe('test/install_concurrency.test.js', () => {
describe('concurrency', () => {
const root = helper.fixtures('options-concurrency');
const cleanup = helper.cleanup(root);

beforeEach(cleanup);
afterEach(cleanup);

it('should use 5 concurrency success', async () => {
await coffee.fork(helper.npminstall, [ '--concurrency', '5' ], { cwd: root })
.debug()
.expect('code', 0)
.end();
});
});
});
19 changes: 19 additions & 0 deletions test/install_retry.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const coffee = require('coffee');
const helper = require('./helper');

describe('test/install_retry.test.js', () => {
describe('retry', () => {
const root = helper.fixtures('options-retry');
const cleanup = helper.cleanup(root);

beforeEach(cleanup);
afterEach(cleanup);

it('should use 5 retry failed', async () => {
await coffee.fork(helper.npminstall, [ '--retry', '5' ], { cwd: root })
.debug()
.notExpect('code', 0)
.end();
});
});
});