Skip to content

Support for explicit registry argument#563

Closed
noherczeg wants to merge 11 commits intolerna:masterfrom
noherczeg:explicit-registry-argument
Closed

Support for explicit registry argument#563
noherczeg wants to merge 11 commits intolerna:masterfrom
noherczeg:explicit-registry-argument

Conversation

@noherczeg
Copy link
Copy Markdown
Contributor

In response to #515

Copy link
Copy Markdown
Member

@evocateur evocateur left a comment

Choose a reason for hiding this comment

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

We're headed in the right direction, but I think we need to support the new getOptions() API (and thus lerna.json config) at the very least.

I'm concerned that other npm commands might need the registry config as well (dist-tag, install).

Comment thread README.md Outdated
#### --registry [registry]

```sh
$ lerna publish --registry https://my-private-registry
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.

I'm not sure publish is the only command that would need this; certainly bootstrap could also potentially need it (for example, dependencies on private modules that aren't co-located in the monorepo).

We should also allow this setting in lerna.json, accessed via the Command##getOptions() API.

Copy link
Copy Markdown
Contributor

@doug-wade doug-wade Feb 1, 2017

Choose a reason for hiding this comment

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

I might even suggest that all npm operations provide the registry flag -- I think that's what I would expect if I provided a registry key in lerna.json, for instance.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll look into your suggestions, and work on them!

Comment thread src/NpmUtilities.js Outdated
}
});
let command = ("npm publish " + args.join(" ")).trim();
ChildProcessUtilities.exec("cd " + escapeArgs(directory) + " && " + command, null, callback);
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.

I'm not a huge fan of this argument whitelisting, though I understand the purpose.

Instead of direct flags, I would rather provide config like this via env vars passed in the options argument.

const command = ("npm publish --tag " + tag).trim()
const env = {
  npm_config_registry: opts.registry
};
ChildProcessUtilities.exec("cd " + escapeArgs(directory) + " && " + command, { env }, callback);

Comment thread src/commands/PublishCommand.js Outdated
"tag": "lerna-temp"
};
if (this.flags.registry) {
args.registry = this.flags.registry;
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.

this should use getOptions()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I just noticed that that exists after the PR, will swap it out!

@noherczeg
Copy link
Copy Markdown
Contributor Author

@evocateur You mentioned dist-tag for this to apply to as well, but I fail to see what does that have to do with registries. Could you please elaborate on this?

@evocateur
Copy link
Copy Markdown
Member

evocateur commented Feb 2, 2017 via email

- added registry support for bootstrap
- modified config handling, now using getOptions()
- added tests
- updated readme
@noherczeg
Copy link
Copy Markdown
Contributor Author

@evocateur My bad. I checked the docs before my question, but failed to realize that this is not a git related "tag" (never made tags as aliases before). My last addition still does not include dist tag support, but I'll make it happen next evening.

Copy link
Copy Markdown
Member

@evocateur evocateur left a comment

Choose a reason for hiding this comment

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

Please constrain this PR to --registry and lerna.json registry only. If there's a great need for the Nexus stuff, we can do that in a separate PR.

Thanks!

Comment thread src/NpmUtilities.js Outdated
}

const opts = {
let opts = {
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.

const doesn't prohibit object mutation, only reassignment to the identifier.

Comment thread README.md Outdated
> The `registry` flag can also be set in lerna.json.

There could also be scenarios where your private registry is split up into an upstream
and a downstream part (like in [Nexus3](https://books.sonatype.com/nexus-book/3.0/reference/npm.html)).
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.

Let's keep this initial implementation as simple as possible. Is there a great need for Nexus3 support from lerna users?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We are using Nexus, that's where the example came from. I understand your point about keeping it simple, therefore I will remove every other part besides registry from my PR. Mostly because nothing prevents us from keeping our upstream publishConfigs in the packages like they are currently :)

Copy link
Copy Markdown
Contributor

@doug-wade doug-wade Feb 2, 2017

Choose a reason for hiding this comment

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

I agree with @evocateur that the initial implementation should be as simple as possible, but I'd still like to see nexus support in a subsequent pr -- we're using it at the office.

@noherczeg
Copy link
Copy Markdown
Contributor Author

Hey guys!

I'm curious if you find my PR okay or is there anything I can make it better?

Comment thread README.md
$ lerna bootstrap --registry https://my-private-registry
```

When run with this flag, the above commands will use the specified registry for your package(s).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

not just the above commands anymore, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Bad wording, will change it in the evening!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I checked it, and found that the run command does not get decorated yet. Could you guys give me some wisdom on this? Do we need it to be present on run-s as well? I'm not sure about it.

Comment thread src/NpmUtilities.js
ChildProcessUtilities.execSync(`npm dist-tag add ${packageName}@${version} ${tag}`);
static addDistTag(packageName, version, tag, registry) {
const opts = NpmUtilities.getTagOpts(registry);
ChildProcessUtilities.execSync(`npm dist-tag add ${packageName}@${version} ${tag}`, opts);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

making this part of the public api like this makes me think you're shelling out to npm every time. I feel like

ChildProcessUtilities.execSync(`npm dist-tag add ${packageName}@${version} ${tag}`, {registry});

would be better, as would making getTagOpts a function

ChildProcessUtilities.execSync(`npm dist-tag add ${packageName}@${version} ${tag}`, getTagOpts(registry));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I put it there because I thought that since NPM is handling the publish process it'd be a good enough fit there. By "making getTagOpts a function" do you mean a global distinct function?

Copy link
Copy Markdown
Member

@evocateur evocateur left a comment

Choose a reason for hiding this comment

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

Thanks for your patience with this PR, @noherczeg !

We're almost there.

Comment thread src/commands/PublishCommand.js Outdated
});

this.progressBar.init(this.packagesToPublish.length);
const registry = this.getOptions().registry;
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.

Let's set this as an instance prop in the initialize method, like this.npmRegistry = this.getOptions().registry;

Comment thread test/PublishCommand.js
{ args: ["cd " + escapeArgs(path.join(testDir, "packages/package-4")) + " && npm publish --tag lerna-temp", {env: {"npm_config_registry":"https://my-private-registry"}}] }
// No package-5. It's private.
], true],
[ChildProcessUtilities, "execSync", {}, [
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.

I thought the dist-tag commands passed the env var too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@evocateur Sorry, but I can not make the tests error out on me. Seems like I misunderstood how to do them properly so I need to evaluate again :(

@noherczeg
Copy link
Copy Markdown
Contributor Author

Webstorm totally messed up my repo during conflict resolution, will create a proper one soon. Sorry for the inconvenience!

@evocateur
Copy link
Copy Markdown
Member

evocateur commented Feb 11, 2017 via email

@noherczeg
Copy link
Copy Markdown
Contributor Author

noherczeg commented Feb 11, 2017

@evocateur I messed it up really bad, so I didn't wanted to risk losing anything, or creating corrupt commits (because I barely managed to keep track what happened where).

@lock
Copy link
Copy Markdown

lock Bot commented Dec 27, 2018

This thread has been automatically locked because there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock Bot locked as resolved and limited conversation to collaborators Dec 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants