@clerc/plugin-not-found 1.0.3 → 1.1.1

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/README.md CHANGED
@@ -2,23 +2,9 @@
2
2
 
3
3
  [![NPM version](https://img.shields.io/npm/v/@clerc/plugin-not-found?color=a1b858&label=)](https://www.npmjs.com/package/@clerc/plugin-not-found)
4
4
 
5
- Clerc plugin to show friendly error message when command not found.
5
+ ## Documenation
6
6
 
7
- ## 📦 Installation
8
-
9
- ```bash
10
- $ npm install @clerc/plugin-not-found
11
- $ yarn add @clerc/plugin-not-found
12
- $ pnpm add @clerc/plugin-not-found
13
- ```
14
-
15
- ## 🚀 Usage
16
-
17
- ```ts
18
- import { notFoundPlugin } from "@clerc/plugin-not-found";
19
-
20
- cli.use(notFoundPlugin());
21
- ```
7
+ Read the [documentation](https://clerc.so1ve.dev/official-plugins/plugin-not-found.html) for more details.
22
8
 
23
9
  ## 📝 License
24
10
 
@@ -0,0 +1,16 @@
1
+ import { Plugin } from "@clerc/core";
2
+
3
+ //#region src/index.d.ts
4
+ interface NotFoundPluginOptions {
5
+ /**
6
+ * Distance threshold for suggesting commands.
7
+ *
8
+ * @default 5
9
+ */
10
+ distanceThreshold?: number;
11
+ }
12
+ declare const notFoundPlugin: ({
13
+ distanceThreshold
14
+ }?: NotFoundPluginOptions) => Plugin;
15
+ //#endregion
16
+ export { NotFoundPluginOptions, notFoundPlugin };
package/dist/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ import{NoCommandSpecifiedError as e,NoSuchCommandError as t,definePlugin as n}from"@clerc/core";import*as r from"@uttr/tint";var i=((e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports))((e=>{e.__esModule=!0,e.distance=e.closest=void 0;var t=new Uint32Array(65536),n=function(e,n){for(var r=e.length,i=n.length,a=1<<r-1,o=-1,s=0,c=r,l=r;l--;)t[e.charCodeAt(l)]|=1<<l;for(l=0;l<i;l++){var u=t[n.charCodeAt(l)],d=u|s;u|=(u&o)+o^o,s|=~(u|o),o&=u,s&a&&c++,o&a&&c--,s=s<<1|1,o=o<<1|~(d|s),s&=d}for(l=r;l--;)t[e.charCodeAt(l)]=0;return c},r=function(e,n){for(var r=n.length,i=e.length,a=[],o=[],s=Math.ceil(r/32),c=Math.ceil(i/32),l=0;l<s;l++)o[l]=-1,a[l]=0;for(var u=0;u<c-1;u++){for(var d=0,f=-1,p=u*32,m=Math.min(32,i)+p,h=p;h<m;h++)t[e.charCodeAt(h)]|=1<<h;for(var l=0;l<r;l++){var g=t[n.charCodeAt(l)],_=o[l/32|0]>>>l&1,v=a[l/32|0]>>>l&1,y=g|d,b=((g|v)&f)+f^f|g|v,x=d|~(b|f),S=f&b;x>>>31^_&&(o[l/32|0]^=1<<l),S>>>31^v&&(a[l/32|0]^=1<<l),x=x<<1|_,S=S<<1|v,f=S|~(y|x),d=x&y}for(var h=p;h<m;h++)t[e.charCodeAt(h)]=0}for(var C=0,w=-1,T=u*32,E=Math.min(32,i-T)+T,h=T;h<E;h++)t[e.charCodeAt(h)]|=1<<h;for(var D=i,l=0;l<r;l++){var g=t[n.charCodeAt(l)],_=o[l/32|0]>>>l&1,v=a[l/32|0]>>>l&1,y=g|C,b=((g|v)&w)+w^w|g|v,x=C|~(b|w),S=w&b;D+=x>>>i-1&1,D-=S>>>i-1&1,x>>>31^_&&(o[l/32|0]^=1<<l),S>>>31^v&&(a[l/32|0]^=1<<l),x=x<<1|_,S=S<<1|v,w=S|~(y|x),C=x&y}for(var h=T;h<E;h++)t[e.charCodeAt(h)]=0;return D},i=function(e,t){if(e.length<t.length){var i=t;t=e,e=i}return t.length===0?e.length:e.length<=32?n(e,t):r(e,t)};e.distance=i,e.closest=function(e,t){for(var n=1/0,r=0,a=0;a<t.length;a++){var o=i(e,t[a]);o<n&&(n=o,r=a)}return t[r]}}))();const a=({distanceThreshold:a=5}={})=>n({setup:n=>n.interceptor({enforce:`post`,handler:async(o,s)=>{let c=[...n._commands.keys()],l=c.length>0;try{await s()}catch(n){if(!(n instanceof t)&&!(n instanceof e))throw n;if(n instanceof e){let t=`No command specified.`;throw l&&(t+=`\nPossible commands: ${c.join(`, `)}.`),new e(t)}let{commandName:o}=n,s=(0,i.closest)(o,c);(0,i.distance)(o,s)>a&&(s=void 0);let u=`Command "${r.strikethrough(o)}" not found.`;throw l&&s?u+=`\nDid you mean "${r.bold(s)}"?`:l||(u+=`
2
+ No commands registered.`),new t(o,u)}}})});export{a as notFoundPlugin};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clerc/plugin-not-found",
3
- "version": "1.0.3",
3
+ "version": "1.1.1",
4
4
  "author": "Ray <i@mk1.io> (https://github.com/so1ve)",
5
5
  "type": "module",
6
6
  "description": "Clerc plugin not found (did you mean)",
@@ -25,19 +25,12 @@
25
25
  "license": "MIT",
26
26
  "sideEffects": false,
27
27
  "exports": {
28
- ".": "./dist/index.js"
29
- },
30
- "main": "./dist/index.js",
31
- "module": "./dist/index.js",
32
- "types": "dist/index.d.ts",
33
- "typesVersions": {
34
- "*": {
35
- "*": [
36
- "./dist/*",
37
- "./dist/index.d.ts"
38
- ]
39
- }
28
+ ".": "./dist/index.mjs",
29
+ "./package.json": "./package.json"
40
30
  },
31
+ "main": "./dist/index.mjs",
32
+ "module": "./dist/index.mjs",
33
+ "types": "./dist/index.d.mts",
41
34
  "files": [
42
35
  "dist"
43
36
  ],
@@ -45,11 +38,11 @@
45
38
  "access": "public"
46
39
  },
47
40
  "dependencies": {
48
- "@uttr/tint": "^0.1.3",
49
- "didyoumean2": "^7.0.4"
41
+ "@uttr/tint": "^0.1.3"
50
42
  },
51
43
  "devDependencies": {
52
- "@clerc/core": "1.0.3"
44
+ "fastest-levenshtein": "^1.0.16",
45
+ "@clerc/core": "1.1.1"
53
46
  },
54
47
  "peerDependencies": {
55
48
  "@clerc/core": "*"
package/dist/index.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import { Plugin } from "@clerc/core";
2
-
3
- //#region src/index.d.ts
4
- declare const notFoundPlugin: () => Plugin;
5
- //#endregion
6
- export { notFoundPlugin };
package/dist/index.js DELETED
@@ -1,31 +0,0 @@
1
- import { NoCommandSpecifiedError, NoSuchCommandError, definePlugin } from "@clerc/core";
2
- import * as tint from "@uttr/tint";
3
- import didyoumean from "didyoumean2";
4
-
5
- //#region src/index.ts
6
- const notFoundPlugin = () => definePlugin({ setup: (cli) => cli.interceptor({
7
- enforce: "post",
8
- handler: async (_ctx, next) => {
9
- const commandKeys = [...cli._commands.keys()];
10
- const hasCommands = commandKeys.length > 0;
11
- try {
12
- await next();
13
- } catch (e) {
14
- if (!(e instanceof NoSuchCommandError || e instanceof NoCommandSpecifiedError)) throw e;
15
- if (e instanceof NoCommandSpecifiedError) {
16
- let text$1 = "No command specified.";
17
- if (hasCommands) text$1 += `\nPossible commands: ${commandKeys.join(", ")}.`;
18
- throw new NoCommandSpecifiedError(text$1);
19
- }
20
- const { commandName } = e;
21
- const closestCommandName = didyoumean(commandName, commandKeys);
22
- let text = `Command "${tint.strikethrough(commandName)}" not found.`;
23
- if (hasCommands && closestCommandName) text += `\nDid you mean "${tint.bold(closestCommandName)}"?`;
24
- else if (!hasCommands) text += "\nNo commands registered.";
25
- throw new NoSuchCommandError(commandName, text);
26
- }
27
- }
28
- }) });
29
-
30
- //#endregion
31
- export { notFoundPlugin };