Skip to content

Commit

Permalink
feat(publish): Add --legacy-auth flag (#2347)
Browse files Browse the repository at this point in the history
Passed as `_auth` internally because that is what NPM expects.
  • Loading branch information
agirton authored and evocateur committed Dec 15, 2019
1 parent ea6ec63 commit 0e9bda7
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 0 deletions.
9 changes: 9 additions & 0 deletions commands/publish/README.md
Expand Up @@ -54,6 +54,7 @@ This is useful when a previous `lerna publish` failed to publish all packages to
- [`--graph-type <all|dependencies>`](#--graph-type-alldependencies)
- [`--ignore-scripts`](#--ignore-scripts)
- [`--ignore-prepublish`](#--ignore-prepublish)
- [`--legacy-auth`](#--legacy-auth)
- [`--no-git-reset`](#--no-git-reset)
- [`--no-verify-access`](#--no-verify-access)
- [`--otp`](#--otp)
Expand Down Expand Up @@ -160,6 +161,14 @@ When passed, this flag will disable running [lifecycle scripts](#lifecycle-scrip

When passed, this flag will disable running [deprecated](https://docs.npmjs.com/misc/scripts#prepublish-and-prepare) [`prepublish` scripts](#lifecycle-scripts) during `lerna publish`.

### `--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 @@ -241,6 +241,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
`);
});

0 comments on commit 0e9bda7

Please sign in to comment.