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: allow publishing private packages #569

Closed
Closed
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/breezy-seahorses-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@changesets/cli": minor
---

allows git-tagging private packages without publishing them to npm
9 changes: 7 additions & 2 deletions packages/cli/src/commands/publish/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,13 @@ export default async function run(
if (tool !== "root") {
for (const pkg of successful) {
const tag = `${pkg.name}@${pkg.newVersion}`;
log("New tag: ", tag);
await git.tag(tag, cwd);
const isMissingTag = !(await git.tagExists(tag));
if (isMissingTag) {
log("New tag: ", tag);
await git.tag(tag, cwd);
} else {
log("Skipping existing tag: ", tag);
Copy link
Member

Choose a reason for hiding this comment

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

When this branch could be chosen? Tag conflict seems like a problem and not something that should be silently silenced

}
}
} else {
const tag = `v${successful[0].newVersion}`;
Expand Down
48 changes: 28 additions & 20 deletions packages/cli/src/commands/publish/publishPackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export default async function publishPackages({
isRequired: Promise.resolve(true)
};
const unpublishedPackagesInfo = await getUnpublishedPackages(
publicPackages,
packages,
preState
);

Expand All @@ -105,31 +105,39 @@ async function publishAPackage(
twoFactorState: TwoFactorState,
tag: string
): Promise<PublishedResult> {
const { name, version, publishConfig } = pkg.packageJson;
const { name, version, publishConfig, private: isPrivate } = pkg.packageJson;
const localAccess = publishConfig && publishConfig.access;
info(
`Publishing ${chalk.cyan(`"${name}"`)} at ${chalk.green(`"${version}"`)}`
);

const publishDir =
publishConfig && publishConfig.directory
? join(pkg.dir, publishConfig.directory)
: pkg.dir;

const publishConfirmation = await npmUtils.publish(
name,
{
cwd: publishDir,
access: localAccess || access,
tag
},
twoFactorState
);
let published;
if (!isPrivate) {
info(
`Publishing ${chalk.cyan(`"${name}"`)} at ${chalk.green(`"${version}"`)}`
);

const publishDir =
publishConfig && publishConfig.directory
? join(pkg.dir, publishConfig.directory)
: pkg.dir;

const publishConfirmation = await npmUtils.publish(
name,
{
cwd: publishDir,
access: localAccess || access,
tag
},
twoFactorState
);

published = publishConfirmation.published;
} else {
published = true;
}

return {
name,
newVersion: version,
published: publishConfirmation.published
published
};
}

Expand Down
8 changes: 8 additions & 0 deletions packages/git/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ async function tag(tagStr: string, cwd: string) {
return gitCmd.code === 0;
}

async function tagExists(tagStr: string) {
Copy link
Member

Choose a reason for hiding this comment

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

this is a new export from the @changesets/git package so a changeset should be created to account for that

const gitCmd = await spawn("git", ["tag", "-l", tagStr]);
const output = gitCmd.stdout.toString().trim();
const tagExists = !!output;
return tagExists;
}

// Find the commit where we diverged from `ref` at using `git merge-base`
export async function getDivergedCommit(cwd: string, ref: string) {
const cmd = await spawn("git", ["merge-base", ref, "HEAD"], { cwd });
Expand Down Expand Up @@ -259,6 +266,7 @@ export {
add,
commit,
tag,
tagExists,
getChangedPackagesSinceRef,
getChangedChangesetFilesSinceRef
};