mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-30 02:28:18 -05:00
fix(cli): suggest to update with Corepack (#4854)
When pnpm was installed with Corepack, suggest to update it with Corepack as well.
This commit is contained in:
6
.changeset/few-horses-happen.md
Normal file
6
.changeset/few-horses-happen.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/default-reporter": minor
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
Suggest to update using Corepack when pnpm was installed via Corepack.
|
||||
@@ -85,7 +85,7 @@ export default function (
|
||||
reportSkippedOptionalDependencies(log$.skippedOptionalDependency, { cwd }),
|
||||
reportHooks(log$.hook, { cwd, isRecursive: opts.isRecursive }),
|
||||
reportContext(log$, { cwd }),
|
||||
reportUpdateCheck(log$.updateCheck),
|
||||
reportUpdateCheck(log$.updateCheck, opts),
|
||||
]
|
||||
|
||||
// logLevelNumber: 0123 = error warn info debug
|
||||
|
||||
@@ -5,26 +5,41 @@ import * as Rx from 'rxjs'
|
||||
import { filter, map, take } from 'rxjs/operators'
|
||||
import semver from 'semver'
|
||||
|
||||
export default (log$: Rx.Observable<UpdateCheckLog>) => {
|
||||
const pkgName = process['pkg'] != null ? '@pnpm/exe' : 'pnpm'
|
||||
export default (log$: Rx.Observable<UpdateCheckLog>, opts: {
|
||||
env: NodeJS.ProcessEnv
|
||||
}) => {
|
||||
return log$.pipe(
|
||||
take(1),
|
||||
filter((log) => semver.gt(log.latestVersion, log.currentVersion)),
|
||||
map((log) => Rx.of({
|
||||
msg: boxen(`\
|
||||
map((log) => {
|
||||
const updateCommand = renderUpdateCommand({
|
||||
latestVersion: log.latestVersion,
|
||||
env: opts.env,
|
||||
})
|
||||
return Rx.of({
|
||||
msg: boxen(`\
|
||||
Update available! ${chalk.red(log.currentVersion)} → ${chalk.green(log.latestVersion)}.
|
||||
${chalk.magenta('Changelog:')} https://github.com/pnpm/pnpm/releases/tag/v${log.latestVersion}
|
||||
Run ${chalk.magenta(`pnpm add -g ${pkgName}`)} to update.
|
||||
Run "${chalk.magenta(updateCommand)}" to update.
|
||||
|
||||
Follow ${chalk.magenta('@pnpmjs')} for updates: https://twitter.com/pnpmjs`,
|
||||
{
|
||||
padding: 1,
|
||||
margin: 1,
|
||||
align: 'center',
|
||||
borderColor: 'yellow',
|
||||
borderStyle: 'round',
|
||||
}
|
||||
),
|
||||
}))
|
||||
{
|
||||
padding: 1,
|
||||
margin: 1,
|
||||
align: 'center',
|
||||
borderColor: 'yellow',
|
||||
borderStyle: 'round',
|
||||
}
|
||||
),
|
||||
})
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
function renderUpdateCommand (opts: { env: NodeJS.ProcessEnv, latestVersion: string }) {
|
||||
if (opts.env.COREPACK_ROOT) {
|
||||
return `corepack prepare pnpm@${opts.latestVersion} --activate`
|
||||
}
|
||||
const pkgName = process['pkg'] != null ? '@pnpm/exe' : 'pnpm'
|
||||
return `pnpm add -g ${pkgName}`
|
||||
}
|
||||
|
||||
@@ -1,12 +1,26 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`print update notification for Corepack if the latest version is greater than the current 1`] = `
|
||||
"
|
||||
╭──────────────────────────────────────────────────────────────────╮
|
||||
│ │
|
||||
│ Update available! 10.0.0 → 11.0.0. │
|
||||
│ Changelog: https://github.com/pnpm/pnpm/releases/tag/v11.0.0 │
|
||||
│ Run \\"corepack prepare pnpm@11.0.0 --activate\\" to update. │
|
||||
│ │
|
||||
│ Follow @pnpmjs for updates: https://twitter.com/pnpmjs │
|
||||
│ │
|
||||
╰──────────────────────────────────────────────────────────────────╯
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`print update notification if the latest version is greater than the current 1`] = `
|
||||
"
|
||||
╭──────────────────────────────────────────────────────────────────╮
|
||||
│ │
|
||||
│ Update available! 10.0.0 → 11.0.0. │
|
||||
│ Changelog: https://github.com/pnpm/pnpm/releases/tag/v11.0.0 │
|
||||
│ Run pnpm add -g pnpm to update. │
|
||||
│ Run \\"pnpm add -g pnpm\\" to update. │
|
||||
│ │
|
||||
│ Follow @pnpmjs for updates: https://twitter.com/pnpmjs │
|
||||
│ │
|
||||
|
||||
@@ -56,3 +56,31 @@ test('print update notification if the latest version is greater than the curren
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
test('print update notification for Corepack if the latest version is greater than the current', (done) => {
|
||||
const output$ = toOutput$({
|
||||
context: {
|
||||
argv: ['install'],
|
||||
config: { recursive: true } as Config,
|
||||
env: {
|
||||
COREPACK_ROOT: '/usr/bin/corepack',
|
||||
},
|
||||
},
|
||||
streamParser: createStreamParser(),
|
||||
})
|
||||
|
||||
updateCheckLogger.debug({
|
||||
currentVersion: '10.0.0',
|
||||
latestVersion: '11.0.0',
|
||||
})
|
||||
|
||||
expect.assertions(1)
|
||||
|
||||
output$.pipe(take(1)).subscribe({
|
||||
complete: () => done(),
|
||||
error: done,
|
||||
next: output => {
|
||||
expect(stripAnsi(output)).toMatchSnapshot()
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user