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 5 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 @@ -50,6 +50,7 @@ This is useful when a previous `lerna publish` failed to publish all packages to
- [`--dist-tag <tag>`](#--dist-tag-tag)
- [`--git-head <sha>`](#--git-head-sha)
- [`--graph-type <all|dependencies>`](#--graph-type-alldependencies)
- [`--legacy-auth`](#--legacy-auth)
- [`--no-git-reset`](#--no-git-reset)
- [`--no-verify-access`](#--no-verify-access)
- [`--otp`](#--otp)
Expand All @@ -62,6 +63,7 @@ This is useful when a previous `lerna publish` failed to publish all packages to
- [`--yes`](#--yes)
- [`--tag-version-prefix`](#--tag-version-prefix)


### `--canary`

```sh
Expand Down Expand Up @@ -150,6 +152,14 @@ Configured via `lerna.json`:
}
```

### `--legacy-auth`

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. This is the same as the NPM publish `_auth` flag.

```sh
lerna publish --legacy-auth aGk6bW9t
```

### `--no-git-reset`

By default, `lerna publish` ensures any changes to the working tree have been reset.
Expand Down
17 changes: 17 additions & 0 deletions commands/publish/__tests__/publish-command.test.js
Expand Up @@ -250,6 +250,23 @@ Map {
});
});

describe("--legacy-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)("--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
4 changes: 4 additions & 0 deletions commands/publish/command.js
Expand Up @@ -35,6 +35,10 @@ exports.builder = yargs => {
type: "string",
requiresArg: true,
},
"legacy-auth": {
describe: "Legacy Base64 Encoded username and password.",
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
39 changes: 39 additions & 0 deletions integration/lerna-publish-auth.test.js
@@ -0,0 +1,39 @@
"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 --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
`);
});