-
-
Notifications
You must be signed in to change notification settings - Fork 69
feat: add prompt to update npm publish config #103
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
Open
zcf0508
wants to merge
7
commits into
antfu-collective:main
Choose a base branch
from
zcf0508:feat-publish-config-tag
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1f81ef3
feat: add prompt to update npm publish config
zcf0508 806b367
feat(cli): add support for custom npm publish tag flag
zcf0508 45a2561
test: add test for `--npm-tag`
zcf0508 4b71649
docs: update readme
zcf0508 81b7469
Merge branch 'main' into feat-publish-config-tag
zcf0508 a4dba4e
test: clarify test case for publishConfig removal
zcf0508 6e03dde
Merge remote-tracking branch 'upstream/main' into feat-publish-config…
zcf0508 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import type { Operation } from './operation' | ||
| import prompts from 'prompts' | ||
| import { prerelease } from 'semver' | ||
|
|
||
| export type PublishConfig = Partial<{ | ||
| tag: string | ||
| access: string | ||
| provenance: boolean | ||
| registry: string | ||
| }> | ||
|
|
||
| export async function resolvePublishTag(operation: Operation) { | ||
| if (!operation.options.npmTag) { | ||
| return | ||
| } | ||
|
|
||
| if (typeof operation.options.npmTag === 'string') { | ||
| operation.update({ | ||
| npmTag: operation.options.npmTag, | ||
| }) | ||
| return | ||
| } | ||
|
|
||
| const { newVersion } = operation.state | ||
| const pre = prerelease(newVersion) | ||
| const defaultTag = pre ? String(pre[0]) : 'latest' | ||
|
|
||
| const response = await prompts({ | ||
| type: 'text', | ||
| name: 'tag', | ||
| message: 'Publish Tag', | ||
| initial: defaultTag, | ||
| }) | ||
|
|
||
| const { tag } = response | ||
|
|
||
| if (tag) { | ||
| operation.update({ | ||
| npmTag: tag, | ||
| }) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import type { Operation } from './operation' | ||
| import type { PublishConfig } from './publish-config-tag' | ||
| import { existsSync } from 'node:fs' | ||
| import * as path from 'node:path' | ||
| import { readJsoncFile, readTextFile, writeJsoncFile, writeTextFile } from './fs' | ||
|
|
@@ -86,10 +87,34 @@ async function updateManifestFile(relPath: string, operation: Operation): Promis | |
| if (isPackageLockManifest(file.data)) | ||
| file.modified.push([['packages', '', 'version'], newVersion]) | ||
|
|
||
| await writeJsoncFile(file) | ||
| modified = true | ||
| } | ||
|
|
||
| if (operation.state.npmTag) { | ||
| const currentTag = (file.data.publishConfig as PublishConfig)?.tag | ||
| const newTag = operation.state.npmTag | ||
|
|
||
| if (newTag === 'latest') { | ||
| if (currentTag) { | ||
| if (Object.keys((file.data as any).publishConfig).length === 1) { | ||
| file.modified.push([['publishConfig'], undefined]) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not so sure if we should write the tag into the package.json |
||
| } | ||
| else { | ||
| file.modified.push([['publishConfig', 'tag'], undefined]) | ||
| } | ||
| modified = true | ||
| } | ||
| } | ||
| else if (newTag !== currentTag) { | ||
| file.modified.push([['publishConfig', 'tag'], newTag]) | ||
| modified = true | ||
| } | ||
| } | ||
|
|
||
| if (modified) { | ||
| await writeJsoncFile(file) | ||
| } | ||
|
|
||
| return modified | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I love this idea, I am a bit worried this could be a bit too annoying as I see 95% of the time I would want to publish to
latestand in very rare cases I need to publish to a different tag (for example, when doing beta releases in another branch, I would only publish packages to thebetatag, and I could configure or update the command for a specific branch, prompting everytime can also increse the chance of mistakes).Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have an idea that we could add a command parameter like
--change-publish-tagor something.By default, this parameter is false, and the publish tag prompt will not be shown. If mantainer wants to publish the current version to another tag like
beta, he can runbumpp --chang-publish-taglocally and then the publish tag prompt will be shown to confirm the tag name.