Skip to content

Commit 2197dc6

Browse files
authored
feat: support visibility in publish (#108)
Signed-off-by: Kevin Cui <bh@bugs.cc>
1 parent 6a0983c commit 2197dc6

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

src/bin.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ program.command("publish")
2525
.argument("[dir]", "The package directory", ".")
2626
.option("-r --registry <registry>", "The registry", "https://registry.oomol.com")
2727
.requiredOption("-t --token <token>", "The token")
28+
.option("--visibility <visibility>", "The visibility of the package", "public")
2829
.action(async (dir, options) => {
29-
await publish(path.resolve(dir), options.registry, options.token);
30+
await publish(path.resolve(dir), options.registry, options.token, options.visibility);
3031
});
3132

3233
const STORE_DIR = "OOPM_STORE_DIR";

src/cmd/publish.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ beforeEach(async (ctx) => {
1616
describe.sequential("publish", () => {
1717
it("should success for new package", async (ctx) => {
1818
const p = fixture("publish_new_success");
19-
const data = await publish(p, ctx.registry.endpoint, "fake_token");
19+
const data = await publish(p, ctx.registry.endpoint, "fake_token", "public");
2020
expect(data.version).toBe("0.0.1");
2121

2222
const data2 = ctx.registry.getData("publish_success", "0.0.1");
@@ -31,13 +31,13 @@ describe.sequential("publish", () => {
3131
it("should success for update package", async (ctx) => {
3232
{
3333
const p = fixture("publish_new_success");
34-
const data = await publish(p, ctx.registry.endpoint, "fake_token");
34+
const data = await publish(p, ctx.registry.endpoint, "fake_token", "public");
3535
expect(data.version).toBe("0.0.1");
3636
}
3737

3838
{
3939
const p = fixture("publish_update_success");
40-
const data = await publish(p, ctx.registry.endpoint, "fake_token");
40+
const data = await publish(p, ctx.registry.endpoint, "fake_token", "public");
4141
expect(data.version).toBe("0.0.2");
4242
}
4343

@@ -54,7 +54,7 @@ describe.sequential("publish", () => {
5454
const p = fixture("publish_depend_itself");
5555

5656
await expect(
57-
publish(p, ctx.registry.endpoint, "fake_token"),
57+
publish(p, ctx.registry.endpoint, "fake_token", "public"),
5858
).rejects.toThrow(ERR_OOPM_DEPEND_ITSELF);
5959
});
6060
});

src/cmd/publish.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { env } from "../utils/misc";
55
import { createNpmrc, getOOPackageBasicInfo } from "../utils/npm";
66
import { defaultIgnore, prePack } from "./pack";
77

8-
export async function publish(p: string, registry: string, token: string): Promise<{
8+
export async function publish(p: string, registry: string, token: string, visibility: "public" | "private" = "public"): Promise<{
99
name: string;
1010
version: string;
1111
}> {
@@ -22,7 +22,7 @@ export async function publish(p: string, registry: string, token: string): Promi
2222
await execa({
2323
cwd: workdir,
2424
env: env(registry),
25-
})`npm publish`;
25+
})`npm publish --access ${visibility === "public" ? "public" : "restricted"}`;
2626

2727
await remove(workdir).catch(() => {});
2828

0 commit comments

Comments
 (0)