Skip to content

Commit 8e6b0ee

Browse files
authored
fix(cli): credentials written in the wrong path (#745)
1 parent 30aa597 commit 8e6b0ee

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

.changeset/jolly-turtles-allow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@shelve/cli": patch
3+
---
4+
5+
Fix `shelve -v` reporting the cwd project version instead of the CLI version. Fix `shelve login` storing credentials in the legacy `~/.shelve` path while API calls read from XDG/keyring storage.

packages/cli/src/index.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#!/usr/bin/env node
22

3+
import { readFileSync } from 'node:fs'
4+
import { dirname, join } from 'node:path'
5+
import { fileURLToPath } from 'node:url'
36
import { defineCommand, runMain } from 'citty'
4-
import { readPackageJSON } from 'pkg-types'
57
import consola from 'consola'
68
import push from './commands/push'
79
import pull from './commands/pull'
@@ -15,13 +17,21 @@ import upgrade from './commands/upgrade'
1517
import run from './commands/run'
1618
import init from './commands/init'
1719

18-
const pkg = await readPackageJSON().catch(() => ({ version: 'unknown' }))
20+
function getCliPackageVersion(): string {
21+
try {
22+
const here = dirname(fileURLToPath(import.meta.url))
23+
const { version } = JSON.parse(readFileSync(join(here, '..', 'package.json'), 'utf-8'))
24+
return version || 'unknown'
25+
} catch {
26+
return 'unknown'
27+
}
28+
}
1929

2030
const main = defineCommand({
2131
meta: {
2232
name: 'shelve',
2333
description: 'Shelve CLI',
24-
version: pkg.version,
34+
version: getCliPackageVersion(),
2535
},
2636
subCommands: {
2737
run,

packages/cli/src/services/base.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { dirname, join } from 'node:path'
44
import { ofetch, type $Fetch, type FetchOptions } from 'ofetch'
55
import { spinner } from '@clack/prompts'
66
import type { User } from '@types'
7-
import { writeUser } from 'rc9'
87
import { askPassword, loadShelveConfig } from '../utils'
98
import { ErrorService } from './error'
9+
import { CredentialsService } from './credentials'
1010

1111
export abstract class BaseService {
1212

@@ -45,7 +45,7 @@ export abstract class BaseService {
4545
const token = await askPassword(`Please provide a valid token (you can generate one on ${sanitizedUrl}/user/tokens)`)
4646
const user = await this.whoAmI(url, token)
4747

48-
writeUser({ token, email: user.email, username: user.username }, '.shelve')
48+
await CredentialsService.writeToken(url, token, { email: user.email, username: user.username })
4949

5050
if (returnUser) return {
5151
user,

0 commit comments

Comments
 (0)