Skip to content

Commit

Permalink
Add support for NARN_PUBLISH env variable.
Browse files Browse the repository at this point in the history
  • Loading branch information
jolyndenning committed Jan 11, 2021
1 parent 635dfa9 commit f41fc40
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,12 @@ To set the default package manager that's used in projects that don't have a yar
export NARN_DEFAULT_PM=pnpm
narn
```

## Publish behavior

By default, narn uses [`np`](https://github.com/sindresorhus/np) on npm and pnpm projects. However, [`np` doesn't support pnpm](https://github.com/sindresorhus/np/issues/251). Because of that, it might be desireable to turn off `np` as the handler for `npm publish`. To disable `np`, set the following environment variable:

```js
export NARN_PUBLISH=passthrough
narn publish
```
10 changes: 7 additions & 3 deletions lib/narn-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,13 @@ exports.getNpmArgs = (narnArgs, isPnpm = false) => {
npmArgs = yarnSubCommands;
break;
case "publish":
result = [];
result.command = "np";
return result;
if (process.env.NARN_PUBLISH === "passthrough") {
return narnArgs;
} else {
result = [];
result.command = "np";
return result;
}
case "version":
npmTarget = "version";
npmArgs = yarnSubCommands;
Expand Down
9 changes: 9 additions & 0 deletions test/publish.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
const { getNpmArgs } = require("../lib/narn-lib");

describe("narn publish", () => {
afterEach(() => {
delete process.env.NARN_PUBLISH;
});

it("runs np", () => {
const expected = [];
expected.command = "np";
expect(getNpmArgs(["publish"])).toEqual(expected);
});

it("doesn't run np with correct env set", () => {
process.env.NARN_PUBLISH = "passthrough";
expect(getNpmArgs(["publish"])).toEqual(["publish"]);
});
});

0 comments on commit f41fc40

Please sign in to comment.