Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
pnpm doctor
command to do checks for known common issues (#…
- Loading branch information
Showing
17 changed files
with
212 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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,7 @@ | ||
--- | ||
"@pnpm/plugin-commands-doctor": major | ||
"pnpm": minor | ||
"@pnpm/config": patch | ||
--- | ||
|
||
Add `pnpm doctor` command to do checks for known common issues |
This file contains 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 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 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 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 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,15 @@ | ||
# @pnpm/plugin-commands-doctor | ||
|
||
> pnpm commands for checks of known common issues | ||
[![npm version](https://img.shields.io/npm/v/@pnpm/plugin-commands-doctor.svg)](https://www.npmjs.com/package/@pnpm/plugin-commands-doctor) | ||
|
||
## Installation | ||
|
||
```sh | ||
pnpm add @pnpm/plugin-commands-doctor | ||
``` | ||
|
||
## License | ||
|
||
MIT |
This file contains 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 @@ | ||
module.exports = require('../../jest.config.js') |
This file contains 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,47 @@ | ||
{ | ||
"name": "@pnpm/plugin-commands-doctor", | ||
"version": "0.0.0", | ||
"description": "Commands for checks of known common issues ", | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"files": [ | ||
"lib", | ||
"!*.map" | ||
], | ||
"engines": { | ||
"node": ">=14.6" | ||
}, | ||
"scripts": { | ||
"lint": "eslint src/**/*.ts test/**/*.ts", | ||
"_test": "jest", | ||
"test": "pnpm run compile && pnpm run _test", | ||
"prepublishOnly": "pnpm run compile", | ||
"compile": "tsc --build && pnpm run lint --fix" | ||
}, | ||
"repository": "https://github.com/pnpm/pnpm/blob/main/packages/plugin-commands-doctor", | ||
"keywords": [ | ||
"pnpm7", | ||
"pnpm", | ||
"doctor" | ||
], | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/pnpm/pnpm/issues" | ||
}, | ||
"homepage": "https://github.com/pnpm/pnpm/blob/main/packages/plugin-commands-doctor#readme", | ||
"dependencies": { | ||
"@pnpm/cli-utils": "workspace:*", | ||
"@pnpm/config": "workspace:*", | ||
"render-help": "^1.0.2" | ||
}, | ||
"peerDependencies": { | ||
"@pnpm/logger": "^5.0.0" | ||
}, | ||
"devDependencies": { | ||
"@pnpm/plugin-commands-doctor": "workspace:*" | ||
}, | ||
"funding": "https://opencollective.com/pnpm", | ||
"exports": { | ||
".": "./lib/index.js" | ||
} | ||
} |
This file contains 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,35 @@ | ||
import renderHelp from 'render-help' | ||
import { docsUrl } from '@pnpm/cli-utils' | ||
import { logger } from '@pnpm/logger' | ||
import { Config } from '@pnpm/config' | ||
|
||
export const rcOptionsTypes = cliOptionsTypes | ||
|
||
export function cliOptionsTypes () { | ||
return {} | ||
} | ||
|
||
export const shorthands = {} | ||
|
||
export const commandNames = ['doctor'] | ||
|
||
export function help () { | ||
return renderHelp({ | ||
description: 'Checks for known common issues.', | ||
url: docsUrl('doctor'), | ||
usages: ['pnpm doctor [options]'], | ||
}) | ||
} | ||
|
||
export async function handler ( | ||
opts: Pick<Config, 'failedToLoadBuiltInConfig'> | ||
) { | ||
const { failedToLoadBuiltInConfig } = opts | ||
if (failedToLoadBuiltInConfig) { | ||
// If true, means loading npm builtin config failed. Then there may have a prefix error, related: https://github.com/pnpm/pnpm/issues/5404 | ||
logger.warn({ | ||
message: 'Load npm builtin configs failed. If the prefix builtin config does not work, you can use "pnpm config ls" to show builtin configs. And then use "pnpm config --global set <key> <value>" to migrate configs from builtin to global.', | ||
prefix: process.cwd(), | ||
}) | ||
} | ||
} |
This file contains 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,3 @@ | ||
import * as doctor from './doctor' | ||
|
||
export { doctor } |
This file contains 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,22 @@ | ||
import { doctor } from '@pnpm/plugin-commands-doctor' | ||
import { logger } from '@pnpm/logger' | ||
|
||
beforeEach(() => { | ||
jest.spyOn(logger, 'warn') | ||
}) | ||
|
||
afterEach(() => { | ||
(logger.warn as jest.Mock).mockRestore() | ||
}) | ||
|
||
test('doctor', async () => { | ||
// In the scope of jest, require.resolve.paths('npm') cannot reach global npm path by default | ||
await doctor.handler({ | ||
failedToLoadBuiltInConfig: true, | ||
}) | ||
|
||
expect(logger.warn).toHaveBeenCalledWith({ | ||
message: expect.stringMatching(/^Load npm builtin configs failed./), | ||
prefix: process.cwd(), | ||
}) | ||
}) |
This file contains 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,19 @@ | ||
{ | ||
"extends": "@pnpm/tsconfig", | ||
"compilerOptions": { | ||
"outDir": "lib", | ||
"rootDir": "src" | ||
}, | ||
"include": [ | ||
"src/**/*.ts", | ||
"../../typings/**/*.d.ts" | ||
], | ||
"references": [ | ||
{ | ||
"path": "../cli-utils" | ||
}, | ||
{ | ||
"path": "../config" | ||
} | ||
] | ||
} |
This file contains 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,8 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"include": [ | ||
"src/**/*.ts", | ||
"test/**/*.ts", | ||
"../../typings/**/*.d.ts" | ||
] | ||
} |
This file contains 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 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.