Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(publish): Add --legacy-auth flag #2347

Merged
merged 7 commits into from Dec 15, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions commands/publish/README.md
Expand Up @@ -45,6 +45,7 @@ This is useful when a previous `lerna publish` failed to publish all packages to

`lerna publish` supports all of the options provided by [`lerna version`](https://github.com/lerna/lerna/tree/master/commands/version#options) in addition to the following:

- [`--_auth`](#--_auth)
- [`--canary`](#--canary)
- [`--contents <dir>`](#--contents-dir)
- [`--dist-tag <tag>`](#--dist-tag-tag)
Expand All @@ -62,6 +63,15 @@ This is useful when a previous `lerna publish` failed to publish all packages to
- [`--yes`](#--yes)
- [`--tag-version-prefix`](#--tag-version-prefix)

### `--_auth`
evocateur marked this conversation as resolved.
Show resolved Hide resolved

```sh
lerna publish --_auth aGk6bW9t
```

When publishing packages that require authentication but you are working with an internally hosted NPM Registry that only uses the legacy Base64 version of username:password.
evocateur marked this conversation as resolved.
Show resolved Hide resolved


### `--canary`

```sh
Expand Down
32 changes: 32 additions & 0 deletions commands/publish/__tests__/publish-command.test.js
Expand Up @@ -250,6 +250,38 @@ Map {
});
});

describe("--_auth", () => {
it("passes auth to npm commands", async () => {
const testDir = await initFixture("normal");
const data = "hi:mom";
const auth = Buffer.from(data).toString("base64");

await lernaPublish(testDir)("--_auth", auth);

expect(npmPublish).toHaveBeenCalledWith(
expect.objectContaining({ name: "package-1" }),
"/TEMP_DIR/package-1-MOCKED.tgz",
expect.objectContaining({ "auth-type": "legacy", _auth: auth }),
expect.objectContaining({ otp: undefined })
);
});

it("passes auth to npm commands if using legacy-auth flag", async () => {
const testDir = await initFixture("normal");
const data = "hi:mom";
const auth = Buffer.from(data).toString("base64");

await lernaPublish(testDir)("--legacy-auth", auth);

expect(npmPublish).toHaveBeenCalledWith(
expect.objectContaining({ name: "package-1" }),
"/TEMP_DIR/package-1-MOCKED.tgz",
expect.objectContaining({ "auth-type": "legacy", _auth: auth }),
expect.objectContaining({ otp: undefined })
);
});
});

describe("--registry", () => {
it("passes registry to npm commands", async () => {
const testDir = await initFixture("normal");
Expand Down
5 changes: 5 additions & 0 deletions commands/publish/command.js
Expand Up @@ -35,6 +35,11 @@ exports.builder = yargs => {
type: "string",
requiresArg: true,
},
"legacy-auth": {
describe: "Legacy Base64 Encoded username and password.",
alias: "_auth",
Copy link
Member

Choose a reason for hiding this comment

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

--_auth is an extremely odd option name. Please don't add this alias.

Copy link
Contributor Author

@agirton agirton Nov 22, 2019

Choose a reason for hiding this comment

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

This is actually the same as the npm _auth flag. So using that as a signal that it's a pass through. But I can remove it and then put this in the description/docs.

type: "string",
},
"pre-dist-tag": {
describe: "Publish prerelease packages with the specified npm dist-tag",
type: "string",
Expand Down
1 change: 1 addition & 0 deletions commands/publish/index.js
Expand Up @@ -116,6 +116,7 @@ class PublishCommand extends Command {

this.conf = npmConf({
lernaCommand: "publish",
_auth: this.options.legacyAuth,
npmSession: this.npmSession,
npmVersion: this.userAgent,
otp: this.options.otp,
Expand Down
63 changes: 63 additions & 0 deletions integration/lerna-publish-auth.test.js
@@ -0,0 +1,63 @@
"use strict";

const path = require("path");

const cliRunner = require("@lerna-test/cli-runner");
const cloneFixture = require("@lerna-test/clone-fixture")(
path.resolve(__dirname, "../commands/publish/__tests__")
);

const env = {
// never actually upload when calling `npm publish`
npm_config_dry_run: true,
// skip npm package validation, none of the stubs are real
LERNA_INTEGRATION: "SKIP",
};

test("lerna publish --_auth", async () => {
const { cwd } = await cloneFixture("normal");
const data = "hi:mom";
const auth = Buffer.from(data).toString("base64");
const args = ["publish", "patch", "--yes", "--_auth", auth];

const { stdout } = await cliRunner(cwd, env)(...args);
expect(stdout).toMatchInlineSnapshot(`

Changes:
- package-1: 1.0.0 => 1.0.1
- package-2: 1.0.0 => 1.0.1
- package-3: 1.0.0 => 1.0.1
- package-4: 1.0.0 => 1.0.1
- package-5: 1.0.0 => 1.0.1 (private)

Successfully published:
- package-1@1.0.1
- package-2@1.0.1
- package-3@1.0.1
- package-4@1.0.1
`);
});

test("lerna publish --legacy-auth", async () => {
const { cwd } = await cloneFixture("normal");
const data = "hi:mom";
const auth = Buffer.from(data).toString("base64");
const args = ["publish", "patch", "--yes", "--legacy-auth", auth];

const { stdout } = await cliRunner(cwd, env)(...args);
expect(stdout).toMatchInlineSnapshot(`

Changes:
- package-1: 1.0.0 => 1.0.1
- package-2: 1.0.0 => 1.0.1
- package-3: 1.0.0 => 1.0.1
- package-4: 1.0.0 => 1.0.1
- package-5: 1.0.0 => 1.0.1 (private)

Successfully published:
- package-1@1.0.1
- package-2@1.0.1
- package-3@1.0.1
- package-4@1.0.1
`);
});