-
-
Notifications
You must be signed in to change notification settings - Fork 200
feat: add deprecate command with custom reason #921
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
eryue0220
wants to merge
12
commits into
npmx-dev:main
Choose a base branch
from
eryue0220:feat/resolve-40
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
12 commits
Select commit
Hold shift + click to select a range
2231fd7
feat: add deprecate feature
eryue0220 f9d0df5
add i18n
eryue0220 36d03de
Merge branch 'main' into feat/resolve-40
eryue0220 bb37228
[autofix.ci] apply automated fixes
autofix-ci[bot] fb860dc
Merge branch 'main' into feat/resolve-40
eryue0220 58e112d
update
eryue0220 2159074
update
eryue0220 2530ba9
update
eryue0220 d80dd64
ut
eryue0220 0c221f5
Update app/components/Package/DeprecatePackageModal.vue
eryue0220 4264814
add ut
eryue0220 1b38e9e
Merge branch 'feat/resolve-40' of github.com:eryue0220/npmx.dev into …
eryue0220 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,7 @@ test-results | |
|
|
||
| # Test coverage | ||
| coverage/ | ||
| *.junit.xml | ||
|
|
||
| # Playwright | ||
| playwright-report/ | ||
|
|
||
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,178 @@ | ||
| <script setup lang="ts"> | ||
| import type { NewOperation } from '~/composables/useConnector' | ||
| import type Modal from '~/components/Modal.client.vue' | ||
|
|
||
| const props = withDefaults( | ||
| defineProps<{ | ||
| packageName: string | ||
| version?: string | ||
| }>(), | ||
| { version: '' }, | ||
| ) | ||
|
|
||
| const { t } = useI18n() | ||
| const { isConnected, state, addOperation, approveOperation, executeOperations, refreshState } = | ||
| useConnector() | ||
|
|
||
| const deprecateMessage = ref('') | ||
| const deprecateVersion = ref(props.version) | ||
| const isDeprecating = shallowRef(false) | ||
| const deprecateSuccess = shallowRef(false) | ||
| const deprecateError = shallowRef<string | null>(null) | ||
|
|
||
| const connectorModal = useModal('connector-modal') | ||
|
|
||
| const modalTitle = computed(() => | ||
| deprecateVersion.value | ||
| ? `${t('package.deprecation.modal.title')} ${props.packageName}@${deprecateVersion.value}` | ||
| : `${t('package.deprecation.modal.title')} ${props.packageName}`, | ||
| ) | ||
|
|
||
| async function handleDeprecate() { | ||
| const message = deprecateMessage.value.trim() | ||
| if (!message || !isConnected.value) return | ||
|
|
||
| isDeprecating.value = true | ||
| deprecateError.value = null | ||
|
|
||
| try { | ||
| const params: Record<string, string> = { | ||
| pkg: props.packageName, | ||
| message, | ||
| } | ||
| if (deprecateVersion.value.trim()) { | ||
| params.version = deprecateVersion.value.trim() | ||
| } | ||
|
|
||
| const escapedMessage = message.replace(/"/g, '\\"') | ||
| const command = params.version | ||
| ? `npm deprecate ${props.packageName}@${params.version} "${escapedMessage}"` | ||
| : `npm deprecate ${props.packageName} "${escapedMessage}"` | ||
|
|
||
| const operation = await addOperation({ | ||
| type: 'package:deprecate', | ||
| params, | ||
| description: params.version | ||
| ? `Deprecate ${props.packageName}@${params.version}` | ||
| : `Deprecate ${props.packageName}`, | ||
| command, | ||
| } as NewOperation) | ||
|
|
||
| if (!operation) { | ||
| throw new Error('Failed to create operation') | ||
| } | ||
|
|
||
| await approveOperation(operation.id) | ||
| await executeOperations() | ||
| await refreshState() | ||
|
|
||
| const completedOp = state.value.operations.find(op => op.id === operation.id) | ||
| if (completedOp?.status === 'completed') { | ||
| deprecateSuccess.value = true | ||
| } else if (completedOp?.status === 'failed') { | ||
| if (completedOp.result?.requiresOtp) { | ||
| close() | ||
| connectorModal.open() | ||
| } else { | ||
| deprecateError.value = completedOp.result?.stderr || t('common.try_again') | ||
| } | ||
| } else { | ||
| close() | ||
| connectorModal.open() | ||
| } | ||
| } catch (err) { | ||
| deprecateError.value = err instanceof Error ? err.message : t('common.try_again') | ||
| } finally { | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| isDeprecating.value = false | ||
| } | ||
| } | ||
|
|
||
| const dialogRef = ref<InstanceType<typeof Modal> | undefined>() | ||
|
|
||
| function open() { | ||
| deprecateError.value = null | ||
| deprecateSuccess.value = false | ||
| deprecateMessage.value = '' | ||
| deprecateVersion.value = props.version ?? '' | ||
| dialogRef.value?.showModal() | ||
| } | ||
|
|
||
| function close() { | ||
| dialogRef.value?.close() | ||
| } | ||
|
|
||
| defineExpose({ open, close }) | ||
| </script> | ||
|
|
||
| <template> | ||
| <Modal ref="dialogRef" :modal-title="modalTitle" id="deprecate-package-modal" class="max-w-md"> | ||
| <!-- Success state --> | ||
| <div v-if="deprecateSuccess" class="space-y-4"> | ||
| <div | ||
| class="flex items-center gap-3 p-4 bg-green-500/10 border border-green-500/20 rounded-lg" | ||
| > | ||
| <span class="i-carbon-checkmark-filled text-green-500 w-6 h-6" aria-hidden="true" /> | ||
| <div> | ||
| <p class="font-mono text-sm text-fg">{{ $t('package.deprecation.modal.success') }}</p> | ||
| <p class="text-xs text-fg-muted"> | ||
| {{ $t('package.deprecation.modal.success_detail') }} | ||
| </p> | ||
| </div> | ||
| </div> | ||
| <button | ||
| type="button" | ||
| class="w-full px-4 py-2 font-mono text-sm text-fg-muted bg-bg-subtle border border-border rounded-md transition-colors duration-200 hover:text-fg hover:border-border-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fg/50" | ||
| @click="close" | ||
| > | ||
| {{ $t('common.close') }} | ||
| </button> | ||
| </div> | ||
|
|
||
| <!-- Form (only shown when connected; parent only opens modal when isConnected) --> | ||
| <div v-else class="space-y-4"> | ||
| <div> | ||
| <label for="deprecate-message" class="block text-sm font-medium text-fg mb-1"> | ||
| {{ $t('package.deprecation.modal.reason') }} | ||
| </label> | ||
| <textarea | ||
| id="deprecate-message" | ||
| v-model="deprecateMessage" | ||
| rows="3" | ||
| class="w-full px-3 py-2 font-mono text-sm bg-bg border border-border rounded-md text-fg placeholder:text-fg-muted focus:outline-none focus:ring-2 focus:ring-fg/50" | ||
| :placeholder="$t('package.deprecation.modal.reason_placeholder')" | ||
| /> | ||
| </div> | ||
| <div> | ||
| <label for="deprecate-version" class="block text-sm font-medium text-fg mb-1"> | ||
| {{ $t('package.deprecation.modal.version') }} | ||
| </label> | ||
| <input | ||
| id="deprecate-version" | ||
| v-model="deprecateVersion" | ||
| type="text" | ||
| class="w-full px-3 py-2 font-mono text-sm bg-bg border border-border rounded-md text-fg placeholder:text-fg-muted focus:outline-none focus:ring-2 focus:ring-fg/50" | ||
| :placeholder="$t('package.deprecation.modal.version_placeholder')" | ||
| /> | ||
| </div> | ||
| <div | ||
| v-if="deprecateError" | ||
| role="alert" | ||
| class="p-3 text-sm text-red-400 bg-red-500/10 border border-red-500/20 rounded-md" | ||
| > | ||
| {{ deprecateError }} | ||
| </div> | ||
| <button | ||
| type="button" | ||
| :disabled="isDeprecating || !deprecateMessage.trim()" | ||
| class="w-full px-4 py-2 font-mono text-sm text-bg bg-fg rounded-md transition-colors duration-200 hover:bg-fg/90 disabled:opacity-50 disabled:cursor-not-allowed focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fg/50" | ||
| @click="handleDeprecate" | ||
| > | ||
| {{ | ||
| isDeprecating | ||
| ? $t('package.deprecation.modal.deprecating') | ||
| : $t('package.deprecation.action') | ||
| }} | ||
| </button> | ||
| </div> | ||
| </Modal> | ||
| </template> | ||
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
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.
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.
Uh oh!
There was an error while loading. Please reload this page.