@oclif/plugin-search 0.0.24 → 1.0.2

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.
@@ -1,17 +1,29 @@
1
1
  {
2
- "version": "0.0.24",
3
2
  "commands": {
4
3
  "search": {
5
- "id": "search",
6
- "summary": "Search for a command.",
4
+ "aliases": [],
5
+ "args": {},
7
6
  "description": "Once you select a command, hit enter and it will show the help for that command.",
8
- "strict": true,
9
- "pluginName": "@oclif/plugin-search",
7
+ "flags": {},
8
+ "hasDynamicHelp": false,
9
+ "id": "search",
10
10
  "pluginAlias": "@oclif/plugin-search",
11
+ "pluginName": "@oclif/plugin-search",
11
12
  "pluginType": "core",
12
- "aliases": [],
13
- "flags": {},
14
- "args": {}
13
+ "strict": true,
14
+ "summary": "Search for a command.",
15
+ "enableJsonFlag": false,
16
+ "isESM": true,
17
+ "relativePath": [
18
+ "dist",
19
+ "commands",
20
+ "search.js"
21
+ ],
22
+ "aliasPermutations": [],
23
+ "permutations": [
24
+ "search"
25
+ ]
15
26
  }
16
- }
27
+ },
28
+ "version": "1.0.2"
17
29
  }
package/package.json CHANGED
@@ -1,68 +1,75 @@
1
1
  {
2
2
  "name": "@oclif/plugin-search",
3
- "version": "0.0.24",
3
+ "version": "1.0.2",
4
4
  "description": "A command for searching commands",
5
5
  "author": "Salesforce",
6
- "homepage": "https://github.com/oclif/plugin-search",
7
- "license": "MIT",
8
- "main": "dist/index.js",
9
- "repository": "oclif/plugin-search",
10
- "files": [
11
- "/bin",
12
- "/dist",
13
- "/npm-shrinkwrap.json",
14
- "/oclif.manifest.json"
15
- ],
6
+ "bugs": "https://github.com/oclif/plugin-search/issues",
16
7
  "dependencies": {
17
- "@oclif/core": "^2.9.3",
18
- "chalk": "^4",
19
- "fuse.js": "^6.6.2",
20
- "inquirer": "^8.2.6",
21
- "rxjs": "^7.8.1"
8
+ "@oclif/core": "^3.0.9",
9
+ "inquirer-autocomplete-standalone": "^0.7.0"
22
10
  },
23
11
  "devDependencies": {
12
+ "@commitlint/config-conventional": "^17.7.0",
24
13
  "@oclif/plugin-help": "^5",
25
14
  "@oclif/plugin-plugins": "^2.4.7",
26
- "@oclif/test": "^2",
15
+ "@oclif/prettier-config": "^0.2.1",
16
+ "@oclif/test": "^3.0.2",
27
17
  "@types/chai": "^4",
28
18
  "@types/inquirer": "^8.2.1",
29
- "@types/mocha": "^9.0.0",
30
- "@types/node": "^16.18.58",
19
+ "@types/mocha": "^10.0.2",
20
+ "@types/node": "^18",
31
21
  "chai": "^4",
32
- "eslint": "^7.32.0",
33
- "eslint-config-oclif": "^4",
34
- "eslint-config-oclif-typescript": "^1.0.3",
22
+ "commitlint": "^17.7.2",
23
+ "eslint": "^8.51.0",
24
+ "eslint-config-oclif": "^5.0.0",
25
+ "eslint-config-oclif-typescript": "^3.0.5",
26
+ "eslint-config-prettier": "^9.0.0",
35
27
  "globby": "^11",
36
- "mocha": "^9",
37
- "oclif": "^3.17.2",
28
+ "husky": "^8.0.3",
29
+ "lint-staged": "^14.0.1",
30
+ "mocha": "^10.2.0",
31
+ "oclif": "^4.0.1",
32
+ "prettier": "^3.0.3",
38
33
  "shx": "^0.3.3",
39
- "ts-node": "^10.2.1",
40
- "tslib": "^2.6.2",
41
- "typescript": "^4.4.3"
34
+ "ts-node": "^10.9.1",
35
+ "typescript": "^5.2.2"
36
+ },
37
+ "engines": {
38
+ "node": ">=18.0.0"
42
39
  },
40
+ "exports": "./dist/index.js",
41
+ "files": [
42
+ "/bin",
43
+ "/dist",
44
+ "/npm-shrinkwrap.json",
45
+ "/oclif.manifest.json",
46
+ "/oclif.lock"
47
+ ],
48
+ "homepage": "https://github.com/oclif/plugin-search",
49
+ "keywords": [
50
+ "oclif"
51
+ ],
52
+ "license": "MIT",
43
53
  "oclif": {
44
54
  "commands": "./dist/commands",
45
55
  "devPlugins": [
46
56
  "@oclif/plugin-help",
47
57
  "@oclif/plugin-plugins"
48
58
  ],
49
- "topicSeparator": " "
59
+ "topicSeparator": " ",
60
+ "flexibleTaxonomy": true
50
61
  },
62
+ "repository": "oclif/plugin-search",
51
63
  "scripts": {
52
64
  "build": "shx rm -rf dist && tsc -b",
53
- "lint": "eslint . --ext .ts --config .eslintrc",
54
- "postpack": "shx rm -f oclif.manifest.json",
65
+ "lint": "eslint . --ext .ts",
66
+ "postpack": "shx rm -f oclif.manifest.json oclif.lock",
55
67
  "posttest": "yarn lint",
56
- "prepack": "yarn build && oclif manifest && oclif readme",
68
+ "prepack": "yarn build && oclif lock && oclif manifest && oclif readme",
69
+ "prepare": "husky install",
57
70
  "test": "mocha --forbid-only \"test/**/*.test.ts\"",
58
71
  "version": "oclif readme && git add README.md"
59
72
  },
60
- "engines": {
61
- "node": ">=14.0.0"
62
- },
63
- "bugs": "https://github.com/oclif/plugin-search/issues",
64
- "keywords": [
65
- "oclif"
66
- ],
73
+ "type": "module",
67
74
  "types": "dist/index.d.ts"
68
- }
75
+ }
package/bin/dev DELETED
@@ -1,17 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const oclif = require('@oclif/core')
4
-
5
- const path = require('path')
6
- const project = path.join(__dirname, '..', 'tsconfig.json')
7
-
8
- // In dev mode -> use ts-node and dev plugins
9
- process.env.NODE_ENV = 'development'
10
-
11
- require('ts-node').register({project})
12
-
13
- // In dev mode, always show stack traces
14
- oclif.settings.debug = true;
15
-
16
- // Start the CLI
17
- oclif.run().then(oclif.flush).catch(oclif.Errors.handle)
package/bin/run DELETED
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const oclif = require('@oclif/core')
4
-
5
- oclif.run().then(require('@oclif/core/flush')).catch(require('@oclif/core/handle'))
@@ -1,61 +0,0 @@
1
- /// <reference types="node" />
2
- /**
3
- * TODO: this functionality should eventually be moved to a separate library so that other plugins can use it.
4
- *
5
- * NOTE: this code was adapted from https://github.com/mokkabonna/inquirer-autocomplete-prompt
6
- */
7
- import { Interface as ReadLineInterface } from 'node:readline';
8
- import Base = require('inquirer/lib/prompts/base');
9
- import InquirerChoices = require('inquirer/lib/objects/choices');
10
- import * as Inquirer from 'inquirer';
11
- import Fuse from 'fuse.js';
12
- declare type SearchOptions = Fuse.IFuseOptions<Record<string, unknown>>;
13
- declare type QuestionOpts = {
14
- searchText: string;
15
- footer: (currentChoices: Choices, index: number, output: string) => string;
16
- searchOpts: SearchOptions;
17
- emptyText: string;
18
- displayKey: string;
19
- };
20
- export declare class Choices extends InquirerChoices {
21
- constructor(choices: string[], options?: {
22
- separator?: string;
23
- });
24
- }
25
- export declare class AutocompleteSearch extends Base {
26
- rl: ReadLineInterface;
27
- opt: Inquirer.prompts.PromptOptions<Inquirer.Question> & QuestionOpts & {
28
- loop: boolean;
29
- pageSize: number;
30
- options: Array<Record<string, unknown>>;
31
- };
32
- private currentChoices;
33
- private firstRender;
34
- private selected;
35
- private initialValue;
36
- private paginator;
37
- private done;
38
- private answer;
39
- private shortAnswer;
40
- private answerName;
41
- private searching;
42
- private nbChoices;
43
- private searchedOnce;
44
- private lastSearchTerm;
45
- private fuse;
46
- constructor(question: Inquirer.Question & Partial<QuestionOpts>, rl: ReadLineInterface, answers?: Record<string, any>);
47
- _run(cb: (state: unknown) => void): Promise<AutocompleteSearch>;
48
- render(error?: string): void;
49
- onSubmit(line: string): void;
50
- onSubmitAfterValidation(line: string): void;
51
- search(searchTerm?: string): void;
52
- ensureSelectedInRange(): void;
53
- onKeypress(e: {
54
- key: {
55
- name: string;
56
- ctrl: boolean;
57
- };
58
- value: string;
59
- }): void;
60
- }
61
- export {};
@@ -1,250 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2022, salesforce.com, inc.
4
- * All rights reserved.
5
- * Licensed under the BSD 3-Clause license.
6
- * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.AutocompleteSearch = exports.Choices = void 0;
10
- const tslib_1 = require("tslib");
11
- const ansiEscapes = require("ansi-escapes");
12
- const Base = require("inquirer/lib/prompts/base");
13
- const InquirerChoices = require("inquirer/lib/objects/choices");
14
- const observe = require("inquirer/lib/utils/events");
15
- const utils = require("inquirer/lib/utils/readline");
16
- const Paginator = require("inquirer/lib/utils/paginator");
17
- const operators_1 = require("rxjs/operators");
18
- const Inquirer = (0, tslib_1.__importStar)(require("inquirer"));
19
- const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
20
- const fuse_js_1 = (0, tslib_1.__importDefault)(require("fuse.js"));
21
- class Choices extends InquirerChoices {
22
- constructor(choices, options = {}) {
23
- // @ts-expect-error
24
- super(choices, options);
25
- }
26
- }
27
- exports.Choices = Choices;
28
- class AutocompleteSearch extends Base {
29
- constructor(question, rl, answers = {}) {
30
- super(question, rl, answers);
31
- this.rl = rl;
32
- this.selected = 0;
33
- if (!this.opt.searchOpts) {
34
- this.throwParamError('searchOpts');
35
- }
36
- this.fuse = new fuse_js_1.default(this.opt.options, this.opt.searchOpts);
37
- this.currentChoices = new Choices([], {});
38
- this.firstRender = true;
39
- this.initialValue = this.opt.default;
40
- const shouldLoop = this.opt.loop === undefined ? true : this.opt.loop;
41
- this.paginator = new Paginator(this.screen, { isInfinite: shouldLoop });
42
- }
43
- async _run(cb) {
44
- this.done = cb;
45
- const events = observe(this.rl);
46
- // eslint-disable-next-line unicorn/consistent-function-scoping
47
- const dontHaveAnswer = () => this.answer === undefined;
48
- events.line.pipe((0, operators_1.takeWhile)(dontHaveAnswer)).forEach(this.onSubmit.bind(this));
49
- // @ts-ignore
50
- events.keypress.pipe((0, operators_1.takeWhile)(dontHaveAnswer)).forEach(this.onKeypress.bind(this));
51
- // Call once at init
52
- this.search();
53
- return Promise.resolve(this);
54
- }
55
- render(error) {
56
- // Render question
57
- let content = this.getQuestion();
58
- let bottomContent = '';
59
- if (this.firstRender) {
60
- content += chalk_1.default.dim('(Use arrow keys or type to search , tab to autocomplete)');
61
- }
62
- // Render choices or answer depending on the state
63
- if (this.status === 'answered') {
64
- content += chalk_1.default.cyan(this.shortAnswer || this.answerName || this.answer);
65
- }
66
- else if (this.searching) {
67
- content += this.rl.line;
68
- bottomContent += ' ' + chalk_1.default.dim(this.opt.searchText || 'Searching...');
69
- }
70
- else if (this.nbChoices) {
71
- const choicesStr = renderList(this.currentChoices, this.selected);
72
- content += this.rl.line;
73
- const indexPosition = this.selected;
74
- let realIndexPosition = 0;
75
- this.currentChoices.choices.every((choice, index) => {
76
- if (index > indexPosition) {
77
- return false;
78
- }
79
- if (choice.type === 'separator') {
80
- return false;
81
- }
82
- const name = choice.name;
83
- realIndexPosition += name ? name.split('\n').length : 0;
84
- return true;
85
- });
86
- bottomContent += this.paginator.paginate(choicesStr, realIndexPosition, this.opt.pageSize);
87
- if (this.opt.footer) {
88
- const footer = this.opt.footer(this.currentChoices, this.selected, bottomContent);
89
- if (footer)
90
- bottomContent += `\n${new Inquirer.Separator().line}\n${footer}`;
91
- }
92
- }
93
- else {
94
- content += this.rl.line;
95
- bottomContent += ` ${chalk_1.default.yellow(this.opt.emptyText || 'No results...')}`;
96
- }
97
- if (error) {
98
- bottomContent += `\n${chalk_1.default.red('>> ')}${error}`;
99
- }
100
- this.firstRender = false;
101
- this.screen.render(content, bottomContent);
102
- }
103
- onSubmit(line) {
104
- let lineOrRl = line || this.rl.line;
105
- if (!lineOrRl) {
106
- lineOrRl = (this.opt.default === null ? '' : this.opt.default);
107
- }
108
- if (typeof this.opt.validate === 'function') {
109
- const checkValidationResult = (validationResult) => {
110
- if (validationResult !== true) {
111
- this.render(validationResult || 'Enter something, tab to autocomplete!');
112
- }
113
- else {
114
- this.onSubmitAfterValidation(lineOrRl);
115
- }
116
- };
117
- const choice = this.currentChoices.getChoice(this.selected);
118
- const validationResult = this.opt.validate(choice, this.answers);
119
- if (typeof validationResult === 'object' && typeof validationResult.then === 'function') {
120
- void validationResult.then(checkValidationResult);
121
- }
122
- else {
123
- checkValidationResult(validationResult);
124
- }
125
- }
126
- else {
127
- this.onSubmitAfterValidation(lineOrRl);
128
- }
129
- }
130
- onSubmitAfterValidation(line) {
131
- let choice = {};
132
- if (this.nbChoices <= this.selected) {
133
- this.rl.write(line);
134
- this.search(line);
135
- return;
136
- }
137
- if (this.nbChoices) {
138
- choice = this.currentChoices.getChoice(this.selected);
139
- this.answer = choice.value;
140
- this.answerName = choice.name;
141
- this.shortAnswer = choice.short;
142
- }
143
- else {
144
- this.rl.write(line);
145
- this.search(line);
146
- return;
147
- }
148
- // @ts-expect-error
149
- // eslint-disable-next-line unicorn/no-array-callback-reference, unicorn/no-array-method-this-argument
150
- const value = this.opt.filter(choice.value, this.answers);
151
- choice.value = value;
152
- this.answer = value;
153
- this.status = 'answered';
154
- // Rerender prompt
155
- this.render();
156
- this.screen.done();
157
- this.done(choice.value);
158
- }
159
- search(searchTerm) {
160
- this.selected = 0;
161
- // Only render searching state after first time
162
- if (this.searchedOnce) {
163
- this.searching = true;
164
- this.currentChoices = new Choices([], {});
165
- this.render(); // Now render current searching state
166
- }
167
- else {
168
- this.searchedOnce = true;
169
- }
170
- this.lastSearchTerm = searchTerm;
171
- const choices = searchTerm ?
172
- this.fuse.search(searchTerm).map(el => el.item[this.opt.displayKey]) :
173
- this.opt.options.map(el => el[this.opt.displayKey]).sort();
174
- this.currentChoices = new Choices(choices, {});
175
- // @ts-expect-error
176
- const realChoices = this.currentChoices.filter(choice => choice.type !== 'separator' && !choice.disabled);
177
- this.nbChoices = realChoices.length;
178
- const selectedIndex = realChoices.findIndex(
179
- // @ts-expect-error
180
- choice => choice === this.initialValue || choice.value === this.initialValue);
181
- if (selectedIndex >= 0) {
182
- this.selected = selectedIndex;
183
- }
184
- this.searching = false;
185
- this.render();
186
- }
187
- ensureSelectedInRange() {
188
- const selectedIndex = Math.min(this.selected, this.nbChoices); // Not above currentChoices length - 1
189
- this.selected = Math.max(selectedIndex, 0); // Not below 0
190
- }
191
- onKeypress(e) {
192
- let len;
193
- const keyName = (e.key && e.key.name) || undefined;
194
- if (keyName === 'tab') {
195
- if (this.currentChoices.getChoice(this.selected)) {
196
- this.rl.write(ansiEscapes.cursorLeft);
197
- const autoCompleted = this.currentChoices.getChoice(this.selected).value;
198
- this.rl.write(ansiEscapes.cursorForward(autoCompleted.length));
199
- // @ts-expect-error because readonly property
200
- this.rl.line = autoCompleted;
201
- this.render();
202
- }
203
- }
204
- else if (keyName === 'down' || (keyName === 'n' && e.key.ctrl)) {
205
- len = this.nbChoices;
206
- this.selected = this.selected < len - 1 ? this.selected + 1 : 0;
207
- this.ensureSelectedInRange();
208
- this.render();
209
- utils.up(this.rl, 2);
210
- }
211
- else if (keyName === 'up' || (keyName === 'p' && e.key.ctrl)) {
212
- len = this.nbChoices;
213
- this.selected = this.selected > 0 ? this.selected - 1 : len - 1;
214
- this.ensureSelectedInRange();
215
- this.render();
216
- }
217
- else {
218
- this.render(); // Render input automatically
219
- // Only search if input have actually changed, not because of other keypresses
220
- if (this.lastSearchTerm !== this.rl.line) {
221
- this.search(this.rl.line); // Trigger new search
222
- }
223
- }
224
- }
225
- }
226
- exports.AutocompleteSearch = AutocompleteSearch;
227
- function renderList(choices, pointer) {
228
- let output = '';
229
- let separatorOffset = 0;
230
- choices.forEach((choice, i) => {
231
- if (choice.type === 'separator') {
232
- separatorOffset += 1;
233
- output += ` ${choice}\n`;
234
- return;
235
- }
236
- if (choice.disabled) {
237
- separatorOffset += 1;
238
- output += ` - ${choice.name} ( ${typeof choice.disabled === 'string' ? choice.disabled : 'Disabled'})\n`;
239
- return;
240
- }
241
- const isSelected = i - separatorOffset === pointer;
242
- // eslint-disable-next-line no-useless-concat
243
- let line = (isSelected ? '❯' + ' ' : ' ') + choice.name;
244
- if (isSelected) {
245
- line = chalk_1.default.cyan(line);
246
- }
247
- output += `${line}\n`;
248
- });
249
- return output.replace(/\n$/, '');
250
- }