@pnpm/cli.commands 1100.0.26 → 1100.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/package.json +7 -7
- package/lib/completion/complete.d.ts +0 -16
- package/lib/completion/complete.js +0 -70
- package/lib/completion/completionServer.d.ts +0 -12
- package/lib/completion/completionServer.js +0 -36
- package/lib/completion/generateCompletion.d.ts +0 -11
- package/lib/completion/generateCompletion.js +0 -41
- package/lib/completion/getOptionType.d.ts +0 -12
- package/lib/completion/getOptionType.js +0 -46
- package/lib/completion/getShell.d.ts +0 -3
- package/lib/completion/getShell.js +0 -22
- package/lib/completion/optionTypesToCompletions.d.ts +0 -2
- package/lib/completion/optionTypesToCompletions.js +0 -14
- package/lib/index.d.ts +0 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @pnpm/cli.commands
|
|
2
2
|
|
|
3
|
+
## 1100.0.28
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies:
|
|
8
|
+
- @pnpm/config.reader@1101.12.1
|
|
9
|
+
|
|
10
|
+
## 1100.0.27
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies:
|
|
15
|
+
- @pnpm/config.reader@1101.12.0
|
|
16
|
+
|
|
3
17
|
## 1100.0.26
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pnpm/cli.commands",
|
|
3
|
-
"version": "1100.0.
|
|
3
|
+
"version": "1100.0.28",
|
|
4
4
|
"description": "Commands for pnpm CLI",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pnpm",
|
|
@@ -28,15 +28,15 @@
|
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@pnpm/cli.command": "^1100.0.1",
|
|
31
|
-
"@pnpm/cli.parse-cli-args": "^1100.1.
|
|
32
|
-
"@pnpm/cli.utils": "^1101.0.
|
|
33
|
-
"@pnpm/config.reader": "1101.
|
|
31
|
+
"@pnpm/cli.parse-cli-args": "^1100.1.6",
|
|
32
|
+
"@pnpm/cli.utils": "^1101.0.15",
|
|
33
|
+
"@pnpm/config.reader": "1101.12.1",
|
|
34
34
|
"@pnpm/error": "^1100.0.1",
|
|
35
35
|
"@pnpm/nopt": "^0.3.1",
|
|
36
36
|
"@pnpm/tabtab": "^0.5.4",
|
|
37
|
-
"@pnpm/workspace.projects-reader": "^1101.0.
|
|
37
|
+
"@pnpm/workspace.projects-reader": "^1101.0.15",
|
|
38
38
|
"@pnpm/workspace.root-finder": "^1100.0.3",
|
|
39
|
-
"@pnpm/workspace.workspace-manifest-reader": "^1100.0
|
|
39
|
+
"@pnpm/workspace.workspace-manifest-reader": "^1100.1.0",
|
|
40
40
|
"ramda": "npm:@pnpm/ramda@0.28.1",
|
|
41
41
|
"render-help": "^2.0.0",
|
|
42
42
|
"split-cmd": "^1.1.0"
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@jest/globals": "30.4.1",
|
|
49
|
-
"@pnpm/cli.commands": "1100.0.
|
|
49
|
+
"@pnpm/cli.commands": "1100.0.28",
|
|
50
50
|
"@pnpm/logger": "1100.0.0",
|
|
51
51
|
"@types/ramda": "0.31.1"
|
|
52
52
|
},
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { CompletionFunc } from '@pnpm/cli.command';
|
|
2
|
-
import type { CompletionItem } from '@pnpm/tabtab';
|
|
3
|
-
export declare function complete(ctx: {
|
|
4
|
-
cliOptionsTypesByCommandName: Record<string, () => Record<string, unknown>>;
|
|
5
|
-
completionByCommandName: Record<string, CompletionFunc>;
|
|
6
|
-
initialCompletion: () => CompletionItem[];
|
|
7
|
-
shorthandsByCommandName: Record<string, Record<string, string | string[]>>;
|
|
8
|
-
universalOptionsTypes: Record<string, unknown>;
|
|
9
|
-
universalShorthands: Record<string, string>;
|
|
10
|
-
}, input: {
|
|
11
|
-
params: string[];
|
|
12
|
-
cmd: string | null;
|
|
13
|
-
currentTypedWordType: 'option' | 'value' | null;
|
|
14
|
-
lastOption: string | null;
|
|
15
|
-
options: Record<string, unknown>;
|
|
16
|
-
}): Promise<CompletionItem[]>;
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { findWorkspaceProjects } from '@pnpm/workspace.projects-reader';
|
|
2
|
-
import { findWorkspaceDir } from '@pnpm/workspace.root-finder';
|
|
3
|
-
import { readWorkspaceManifest } from '@pnpm/workspace.workspace-manifest-reader';
|
|
4
|
-
import { getOptionCompletions } from './getOptionType.js';
|
|
5
|
-
import { optionTypesToCompletions } from './optionTypesToCompletions.js';
|
|
6
|
-
export async function complete(ctx, input) {
|
|
7
|
-
if (input.options.version)
|
|
8
|
-
return [];
|
|
9
|
-
const optionTypes = {
|
|
10
|
-
...ctx.universalOptionsTypes,
|
|
11
|
-
...((input.cmd && ctx.cliOptionsTypesByCommandName[input.cmd]?.()) ?? {}),
|
|
12
|
-
};
|
|
13
|
-
// Autocompleting option values
|
|
14
|
-
if (input.currentTypedWordType !== 'option') {
|
|
15
|
-
if (input.lastOption === '--filter' || input.lastOption === '-F') {
|
|
16
|
-
const workspaceDir = await findWorkspaceDir(process.cwd()) ?? process.cwd();
|
|
17
|
-
const workspaceManifest = await readWorkspaceManifest(workspaceDir);
|
|
18
|
-
const allProjects = await findWorkspaceProjects(workspaceDir, {
|
|
19
|
-
patterns: workspaceManifest?.packages,
|
|
20
|
-
supportedArchitectures: {
|
|
21
|
-
os: ['current'],
|
|
22
|
-
cpu: ['current'],
|
|
23
|
-
libc: ['current'],
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
return allProjects
|
|
27
|
-
.map(({ manifest }) => ({ name: manifest.name }))
|
|
28
|
-
.filter((item) => !!item.name);
|
|
29
|
-
}
|
|
30
|
-
else if (input.lastOption) {
|
|
31
|
-
const optionCompletions = getOptionCompletions(optionTypes, // eslint-disable-line
|
|
32
|
-
{
|
|
33
|
-
...ctx.universalShorthands,
|
|
34
|
-
...(input.cmd ? ctx.shorthandsByCommandName[input.cmd] : {}),
|
|
35
|
-
}, input.lastOption);
|
|
36
|
-
if (optionCompletions !== undefined) {
|
|
37
|
-
return optionCompletions.map((name) => ({ name }));
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
let completions = [];
|
|
42
|
-
if (input.currentTypedWordType !== 'option') {
|
|
43
|
-
if (!input.cmd || input.currentTypedWordType === 'value' && !ctx.completionByCommandName[input.cmd]) {
|
|
44
|
-
completions = ctx.initialCompletion();
|
|
45
|
-
}
|
|
46
|
-
else if (ctx.completionByCommandName[input.cmd]) {
|
|
47
|
-
try {
|
|
48
|
-
completions = await ctx.completionByCommandName[input.cmd](input.options, input.params);
|
|
49
|
-
}
|
|
50
|
-
catch {
|
|
51
|
-
// Ignore
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
if (input.currentTypedWordType === 'value') {
|
|
56
|
-
return completions;
|
|
57
|
-
}
|
|
58
|
-
if (!input.cmd) {
|
|
59
|
-
return [
|
|
60
|
-
...completions,
|
|
61
|
-
...optionTypesToCompletions(optionTypes),
|
|
62
|
-
{ name: '--version' },
|
|
63
|
-
];
|
|
64
|
-
}
|
|
65
|
-
return [
|
|
66
|
-
...completions,
|
|
67
|
-
...optionTypesToCompletions(optionTypes), // eslint-disable-line
|
|
68
|
-
];
|
|
69
|
-
}
|
|
70
|
-
//# sourceMappingURL=complete.js.map
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { CompletionFunc } from '@pnpm/cli.command';
|
|
2
|
-
import type { ParsedCliArgs } from '@pnpm/cli.parse-cli-args';
|
|
3
|
-
import { type CompletionItem } from '@pnpm/tabtab';
|
|
4
|
-
export declare function createCompletionServer(opts: {
|
|
5
|
-
cliOptionsTypesByCommandName: Record<string, () => Record<string, unknown>>;
|
|
6
|
-
completionByCommandName: Record<string, CompletionFunc>;
|
|
7
|
-
initialCompletion: () => CompletionItem[];
|
|
8
|
-
shorthandsByCommandName: Record<string, Record<string, string | string[]>>;
|
|
9
|
-
parseCliArgs: (args: string[]) => Promise<ParsedCliArgs>;
|
|
10
|
-
universalOptionsTypes: Record<string, unknown>;
|
|
11
|
-
universalShorthands: Record<string, string>;
|
|
12
|
-
}): () => Promise<void>;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import tabtab from '@pnpm/tabtab';
|
|
2
|
-
import { getShellFromEnv } from '@pnpm/tabtab';
|
|
3
|
-
import { split as splitCmd } from 'split-cmd/index.modern.mjs';
|
|
4
|
-
import { complete } from './complete.js';
|
|
5
|
-
import { currentTypedWordType, getLastOption, } from './getOptionType.js';
|
|
6
|
-
export function createCompletionServer(opts) {
|
|
7
|
-
return async () => {
|
|
8
|
-
const shell = getShellFromEnv(process.env);
|
|
9
|
-
const env = tabtab.parseEnv(process.env);
|
|
10
|
-
if (!env.complete)
|
|
11
|
-
return;
|
|
12
|
-
const inputArgv = splitCmd(stripPartialWord(env)).slice(1);
|
|
13
|
-
// We cannot autocomplete what a user types after "pnpm test --"
|
|
14
|
-
if (inputArgv.includes('--'))
|
|
15
|
-
return;
|
|
16
|
-
const { params, options, cmd } = await opts.parseCliArgs(inputArgv);
|
|
17
|
-
tabtab.log(await complete(opts, {
|
|
18
|
-
cmd,
|
|
19
|
-
currentTypedWordType: currentTypedWordType(env),
|
|
20
|
-
lastOption: getLastOption(env),
|
|
21
|
-
options,
|
|
22
|
-
params,
|
|
23
|
-
}), shell);
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Returns the portion of the command line that consists of fully typed words,
|
|
28
|
-
*/
|
|
29
|
-
function stripPartialWord(env) {
|
|
30
|
-
if (env.lastPartial.length > 0) {
|
|
31
|
-
// stripping any word the user is currently typing.
|
|
32
|
-
return env.partial.slice(0, -env.lastPartial.length);
|
|
33
|
-
}
|
|
34
|
-
return env.partial;
|
|
35
|
-
}
|
|
36
|
-
//# sourceMappingURL=completionServer.js.map
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export declare const commandNames: string[];
|
|
2
|
-
export declare const skipPackageManagerCheck = true;
|
|
3
|
-
export declare const rcOptionsTypes: () => Record<string, unknown>;
|
|
4
|
-
export declare const cliOptionsTypes: () => Record<string, unknown>;
|
|
5
|
-
export declare function help(): string;
|
|
6
|
-
export interface Context {
|
|
7
|
-
readonly log: (output: string) => void;
|
|
8
|
-
}
|
|
9
|
-
export type CompletionGenerator = (_opts: unknown, params: string[]) => Promise<void>;
|
|
10
|
-
export declare function createCompletionGenerator(ctx: Context): CompletionGenerator;
|
|
11
|
-
export declare const handler: CompletionGenerator;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { getCompletionScript, SUPPORTED_SHELLS } from '@pnpm/tabtab';
|
|
2
|
-
import { renderHelp } from 'render-help';
|
|
3
|
-
import { getShellFromParams } from './getShell.js';
|
|
4
|
-
export const commandNames = ['completion'];
|
|
5
|
-
export const skipPackageManagerCheck = true;
|
|
6
|
-
export const rcOptionsTypes = () => ({});
|
|
7
|
-
export const cliOptionsTypes = () => ({});
|
|
8
|
-
export function help() {
|
|
9
|
-
return renderHelp({
|
|
10
|
-
description: 'Print shell completion code to stdout',
|
|
11
|
-
url: 'https://pnpm.io/completion',
|
|
12
|
-
usages: SUPPORTED_SHELLS.map(shell => `pnpm completion ${shell}`),
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
const PNPM_COMMAND = 'pnpm';
|
|
16
|
-
const PNPM_SHORT_ALIAS = 'pn';
|
|
17
|
-
export function createCompletionGenerator(ctx) {
|
|
18
|
-
return async function handler(_opts, params) {
|
|
19
|
-
const shell = getShellFromParams(params);
|
|
20
|
-
const output = await getCompletionScript({ name: PNPM_COMMAND, completer: PNPM_COMMAND, shell });
|
|
21
|
-
ctx.log(registerShortAlias(output, shell));
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
function registerShortAlias(output, shell) {
|
|
25
|
-
switch (shell) {
|
|
26
|
-
case 'bash':
|
|
27
|
-
return output.replace(`complete -o default -F _${PNPM_COMMAND}_completion ${PNPM_COMMAND}`, `complete -o default -F _${PNPM_COMMAND}_completion ${PNPM_COMMAND} ${PNPM_SHORT_ALIAS}`);
|
|
28
|
-
case 'fish':
|
|
29
|
-
return output.replace(`complete -f -d '${PNPM_COMMAND}' -c ${PNPM_COMMAND} -a "(_${PNPM_COMMAND}_completion)"`, `complete -f -d '${PNPM_COMMAND}' -c ${PNPM_COMMAND} -a "(_${PNPM_COMMAND}_completion)"\ncomplete -f -d '${PNPM_COMMAND}' -c ${PNPM_SHORT_ALIAS} -a "(_${PNPM_COMMAND}_completion)"`);
|
|
30
|
-
case 'pwsh':
|
|
31
|
-
return output.replace(`Register-ArgumentCompleter -CommandName '${PNPM_COMMAND}' -ScriptBlock`, `Register-ArgumentCompleter -CommandName '${PNPM_COMMAND}','${PNPM_SHORT_ALIAS}' -ScriptBlock`);
|
|
32
|
-
case 'zsh':
|
|
33
|
-
return output
|
|
34
|
-
.replace(`#compdef ${PNPM_COMMAND}`, `#compdef ${PNPM_COMMAND} ${PNPM_SHORT_ALIAS}`)
|
|
35
|
-
.replace(`compdef _${PNPM_COMMAND}_completion ${PNPM_COMMAND}`, `compdef _${PNPM_COMMAND}_completion ${PNPM_COMMAND} ${PNPM_SHORT_ALIAS}`);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
export const handler = createCompletionGenerator({
|
|
39
|
-
log: console.log,
|
|
40
|
-
});
|
|
41
|
-
//# sourceMappingURL=generateCompletion.js.map
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export interface CompletionCtx {
|
|
2
|
-
last: string;
|
|
3
|
-
lastPartial: string;
|
|
4
|
-
line: string;
|
|
5
|
-
partial: string;
|
|
6
|
-
point: number;
|
|
7
|
-
prev: string;
|
|
8
|
-
words: number;
|
|
9
|
-
}
|
|
10
|
-
export declare function getOptionCompletions(optionTypes: Record<string, unknown>, shorthands: Record<string, string | string[]>, option: string): string[] | undefined;
|
|
11
|
-
export declare function getLastOption(completionCtx: CompletionCtx): string | null;
|
|
12
|
-
export declare function currentTypedWordType(completionCtx: CompletionCtx): 'option' | 'value' | null;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import nopt from '@pnpm/nopt';
|
|
2
|
-
import { omit } from 'ramda';
|
|
3
|
-
export function getOptionCompletions(optionTypes, shorthands, option) {
|
|
4
|
-
const optionType = getOptionType(optionTypes, shorthands, option);
|
|
5
|
-
return optionTypeToCompletion(optionType);
|
|
6
|
-
}
|
|
7
|
-
function optionTypeToCompletion(optionType) {
|
|
8
|
-
switch (optionType) {
|
|
9
|
-
// In this case the option is complete
|
|
10
|
-
case undefined:
|
|
11
|
-
case Boolean: return undefined;
|
|
12
|
-
// In this case, anything may be the option value
|
|
13
|
-
case String:
|
|
14
|
-
case Number: return [];
|
|
15
|
-
}
|
|
16
|
-
if (!Array.isArray(optionType))
|
|
17
|
-
return [];
|
|
18
|
-
if (optionType.length === 1) {
|
|
19
|
-
return optionTypeToCompletion(optionType);
|
|
20
|
-
}
|
|
21
|
-
return optionType.filter((ot) => typeof ot === 'string');
|
|
22
|
-
}
|
|
23
|
-
function getOptionType(optionTypes, shorthands, option) {
|
|
24
|
-
const allBools = Object.fromEntries(Object.keys(optionTypes).map((optionName) => [optionName, Boolean]));
|
|
25
|
-
const result = omit(['argv'], nopt(allBools, shorthands, [option], 0));
|
|
26
|
-
return optionTypes[Object.entries(result)[0]?.[0]];
|
|
27
|
-
}
|
|
28
|
-
export function getLastOption(completionCtx) {
|
|
29
|
-
if (isOption(completionCtx.prev))
|
|
30
|
-
return completionCtx.prev;
|
|
31
|
-
if (completionCtx.lastPartial === '' || completionCtx.words <= 1)
|
|
32
|
-
return null;
|
|
33
|
-
const words = completionCtx.line.slice(0, completionCtx.point).trim().split(/\s+/);
|
|
34
|
-
const lastWord = words[words.length - 2];
|
|
35
|
-
return isOption(lastWord) ? lastWord : null;
|
|
36
|
-
}
|
|
37
|
-
function isOption(word) {
|
|
38
|
-
return word.startsWith('--') && word.length >= 3 ||
|
|
39
|
-
word[0] === '-' && word.length >= 2;
|
|
40
|
-
}
|
|
41
|
-
export function currentTypedWordType(completionCtx) {
|
|
42
|
-
if (completionCtx.partial.endsWith(' '))
|
|
43
|
-
return null;
|
|
44
|
-
return completionCtx.lastPartial[0] === '-' ? 'option' : 'value';
|
|
45
|
-
}
|
|
46
|
-
//# sourceMappingURL=getOptionType.js.map
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { PnpmError } from '@pnpm/error';
|
|
2
|
-
import { isShellSupported, SUPPORTED_SHELLS } from '@pnpm/tabtab';
|
|
3
|
-
export function getShellFromString(shell) {
|
|
4
|
-
shell = shell?.trim();
|
|
5
|
-
if (!shell) {
|
|
6
|
-
throw new PnpmError('MISSING_SHELL_NAME', '`pnpm completion` requires a shell name');
|
|
7
|
-
}
|
|
8
|
-
if (!isShellSupported(shell)) {
|
|
9
|
-
throw new PnpmError('UNSUPPORTED_SHELL', `'${shell}' is not supported`, {
|
|
10
|
-
hint: `Supported shells are: ${SUPPORTED_SHELLS.join(', ')}`,
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
return shell;
|
|
14
|
-
}
|
|
15
|
-
export function getShellFromParams(params) {
|
|
16
|
-
const [shell, ...rest] = params;
|
|
17
|
-
if (rest.length) {
|
|
18
|
-
throw new PnpmError('REDUNDANT_PARAMETERS', `The ${rest.length} parameters after shell is not necessary`);
|
|
19
|
-
}
|
|
20
|
-
return getShellFromString(shell);
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=getShell.js.map
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export function optionTypesToCompletions(optionTypes) {
|
|
2
|
-
const completions = [];
|
|
3
|
-
for (const [name, typeObj] of Object.entries(optionTypes)) {
|
|
4
|
-
if (typeObj === Boolean) {
|
|
5
|
-
completions.push({ name: `--${name}` });
|
|
6
|
-
completions.push({ name: `--no-${name}` });
|
|
7
|
-
}
|
|
8
|
-
else {
|
|
9
|
-
completions.push({ name: `--${name}` });
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
return completions;
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=optionTypesToCompletions.js.map
|
package/lib/index.d.ts
DELETED