@clerc/plugin-not-found 0.25.1 → 0.27.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/dist/index.js +2 -47
- package/package.json +7 -9
- package/dist/index.mjs +0 -47
package/dist/index.js
CHANGED
|
@@ -1,47 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import pc from 'picocolors';
|
|
4
|
-
|
|
5
|
-
const semanticArray = (arr) => {
|
|
6
|
-
if (arr.length <= 1) {
|
|
7
|
-
return arr[0];
|
|
8
|
-
}
|
|
9
|
-
return `${arr.slice(0, -1).map(pc.bold).join(", ")} and ${pc.bold(arr[arr.length - 1])}`;
|
|
10
|
-
};
|
|
11
|
-
const notFoundPlugin = () => definePlugin({
|
|
12
|
-
setup: (cli) => {
|
|
13
|
-
return cli.inspector({
|
|
14
|
-
enforce: "pre",
|
|
15
|
-
fn: (ctx, next) => {
|
|
16
|
-
const commandKeys = Object.keys(cli._commands);
|
|
17
|
-
const hasCommands = !!commandKeys.length;
|
|
18
|
-
try {
|
|
19
|
-
next();
|
|
20
|
-
} catch (e) {
|
|
21
|
-
if (!(e instanceof NoSuchCommandError || e instanceof NoCommandGivenError)) {
|
|
22
|
-
throw e;
|
|
23
|
-
}
|
|
24
|
-
if (ctx.raw._.length === 0 || e instanceof NoCommandGivenError) {
|
|
25
|
-
console.error("No command given.");
|
|
26
|
-
if (hasCommands) {
|
|
27
|
-
console.error(`Possible commands: ${semanticArray(commandKeys)}.`);
|
|
28
|
-
}
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
const calledCommandName = e.commandName;
|
|
32
|
-
const closestCommandName = didyoumean(calledCommandName, commandKeys);
|
|
33
|
-
console.error(`Command "${pc.strikethrough(calledCommandName)}" not found.`);
|
|
34
|
-
if (hasCommands && closestCommandName) {
|
|
35
|
-
console.error(`Did you mean "${pc.bold(closestCommandName)}"?`);
|
|
36
|
-
} else if (!hasCommands) {
|
|
37
|
-
console.error("NOTE: You haven't register any command yet.");
|
|
38
|
-
}
|
|
39
|
-
process.stderr.write("\n");
|
|
40
|
-
process.exit(2);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
export { notFoundPlugin };
|
|
1
|
+
import{definePlugin as $,NoSuchCommandError as q,NoCommandGivenError as R}from"@clerc/core";import z from"tty";const I=new Uint32Array(65536),Z=(t,e)=>{const s=t.length,x=e.length,i=1<<s-1;let u=-1,f=0,S=s,l=s;for(;l--;)I[t.charCodeAt(l)]|=1<<l;for(l=0;l<x;l++){let b=I[e.charCodeAt(l)];const d=b|f;b|=(b&u)+u^u,f|=~(b|u),u&=b,f&i&&S++,u&i&&S--,f=f<<1|1,u=u<<1|~(d|f),f&=d}for(l=s;l--;)I[t.charCodeAt(l)]=0;return S},B=(t,e)=>{const s=e.length,x=t.length,i=[],u=[],f=Math.ceil(s/32),S=Math.ceil(x/32);for(let r=0;r<f;r++)u[r]=-1,i[r]=0;let l=0;for(;l<S-1;l++){let r=0,c=-1;const h=l*32,y=Math.min(32,x)+h;for(let a=h;a<y;a++)I[t.charCodeAt(a)]|=1<<a;for(let a=0;a<s;a++){const E=I[e.charCodeAt(a)],A=u[a/32|0]>>>a&1,C=i[a/32|0]>>>a&1,M=E|r,k=((E|C)&c)+c^c|E|C;let _=r|~(k|c),O=c&k;_>>>31^A&&(u[a/32|0]^=1<<a),O>>>31^C&&(i[a/32|0]^=1<<a),_=_<<1|A,O=O<<1|C,c=O|~(M|_),r=_&M}for(let a=h;a<y;a++)I[t.charCodeAt(a)]=0}let b=0,d=-1;const T=l*32,o=Math.min(32,x-T)+T;for(let r=T;r<o;r++)I[t.charCodeAt(r)]|=1<<r;let n=x;for(let r=0;r<s;r++){const c=I[e.charCodeAt(r)],h=u[r/32|0]>>>r&1,y=i[r/32|0]>>>r&1,a=c|b,E=((c|y)&d)+d^d|c|y;let A=b|~(E|d),C=d&E;n+=A>>>x-1&1,n-=C>>>x-1&1,A>>>31^h&&(u[r/32|0]^=1<<r),C>>>31^y&&(i[r/32|0]^=1<<r),A=A<<1|h,C=C<<1|y,d=C|~(a|A),b=A&a}for(let r=T;r<o;r++)I[t.charCodeAt(r)]=0;return n},N=(t,e)=>{if(t.length<e.length){const s=e;e=t,t=s}return e.length===0?t.length:t.length<=32?Z(t,e):B(t,e)};var v=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{},J=1/0,K="[object Symbol]",W=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,Q="\\u0300-\\u036f\\ufe20-\\ufe23",V="\\u20d0-\\u20f0",X="["+Q+V+"]",tt=RegExp(X,"g"),et={\u00C0:"A",\u00C1:"A",\u00C2:"A",\u00C3:"A",\u00C4:"A",\u00C5:"A",\u00E0:"a",\u00E1:"a",\u00E2:"a",\u00E3:"a",\u00E4:"a",\u00E5:"a",\u00C7:"C",\u00E7:"c",\u00D0:"D",\u00F0:"d",\u00C8:"E",\u00C9:"E",\u00CA:"E",\u00CB:"E",\u00E8:"e",\u00E9:"e",\u00EA:"e",\u00EB:"e",\u00CC:"I",\u00CD:"I",\u00CE:"I",\u00CF:"I",\u00EC:"i",\u00ED:"i",\u00EE:"i",\u00EF:"i",\u00D1:"N",\u00F1:"n",\u00D2:"O",\u00D3:"O",\u00D4:"O",\u00D5:"O",\u00D6:"O",\u00D8:"O",\u00F2:"o",\u00F3:"o",\u00F4:"o",\u00F5:"o",\u00F6:"o",\u00F8:"o",\u00D9:"U",\u00DA:"U",\u00DB:"U",\u00DC:"U",\u00F9:"u",\u00FA:"u",\u00FB:"u",\u00FC:"u",\u00DD:"Y",\u00FD:"y",\u00FF:"y",\u00C6:"Ae",\u00E6:"ae",\u00DE:"Th",\u00FE:"th",\u00DF:"ss",\u0100:"A",\u0102:"A",\u0104:"A",\u0101:"a",\u0103:"a",\u0105:"a",\u0106:"C",\u0108:"C",\u010A:"C",\u010C:"C",\u0107:"c",\u0109:"c",\u010B:"c",\u010D:"c",\u010E:"D",\u0110:"D",\u010F:"d",\u0111:"d",\u0112:"E",\u0114:"E",\u0116:"E",\u0118:"E",\u011A:"E",\u0113:"e",\u0115:"e",\u0117:"e",\u0119:"e",\u011B:"e",\u011C:"G",\u011E:"G",\u0120:"G",\u0122:"G",\u011D:"g",\u011F:"g",\u0121:"g",\u0123:"g",\u0124:"H",\u0126:"H",\u0125:"h",\u0127:"h",\u0128:"I",\u012A:"I",\u012C:"I",\u012E:"I",\u0130:"I",\u0129:"i",\u012B:"i",\u012D:"i",\u012F:"i",\u0131:"i",\u0134:"J",\u0135:"j",\u0136:"K",\u0137:"k",\u0138:"k",\u0139:"L",\u013B:"L",\u013D:"L",\u013F:"L",\u0141:"L",\u013A:"l",\u013C:"l",\u013E:"l",\u0140:"l",\u0142:"l",\u0143:"N",\u0145:"N",\u0147:"N",\u014A:"N",\u0144:"n",\u0146:"n",\u0148:"n",\u014B:"n",\u014C:"O",\u014E:"O",\u0150:"O",\u014D:"o",\u014F:"o",\u0151:"o",\u0154:"R",\u0156:"R",\u0158:"R",\u0155:"r",\u0157:"r",\u0159:"r",\u015A:"S",\u015C:"S",\u015E:"S",\u0160:"S",\u015B:"s",\u015D:"s",\u015F:"s",\u0161:"s",\u0162:"T",\u0164:"T",\u0166:"T",\u0163:"t",\u0165:"t",\u0167:"t",\u0168:"U",\u016A:"U",\u016C:"U",\u016E:"U",\u0170:"U",\u0172:"U",\u0169:"u",\u016B:"u",\u016D:"u",\u016F:"u",\u0171:"u",\u0173:"u",\u0174:"W",\u0175:"w",\u0176:"Y",\u0177:"y",\u0178:"Y",\u0179:"Z",\u017B:"Z",\u017D:"Z",\u017A:"z",\u017C:"z",\u017E:"z",\u0132:"IJ",\u0133:"ij",\u0152:"Oe",\u0153:"oe",\u0149:"'n",\u017F:"ss"},rt=typeof v=="object"&&v&&v.Object===Object&&v,ot=typeof self=="object"&&self&&self.Object===Object&&self,nt=rt||ot||Function("return this")();function ut(t){return function(e){return t==null?void 0:t[e]}}var st=ut(et),ct=Object.prototype,it=ct.toString,H=nt.Symbol,j=H?H.prototype:void 0,D=j?j.toString:void 0;function xt(t){if(typeof t=="string")return t;if(mt(t))return D?D.call(t):"";var e=t+"";return e=="0"&&1/t==-J?"-0":e}function lt(t){return!!t&&typeof t=="object"}function mt(t){return typeof t=="symbol"||lt(t)&&it.call(t)==K}function at(t){return t==null?"":xt(t)}function ft(t){return t=at(t),t&&t.replace(W,st).replace(tt,"")}var ht=ft;let g,p;(function(t){t.ALL_CLOSEST_MATCHES="all-closest-matches",t.ALL_MATCHES="all-matches",t.ALL_SORTED_MATCHES="all-sorted-matches",t.FIRST_CLOSEST_MATCH="first-closest-match",t.FIRST_MATCH="first-match"})(g||(g={})),function(t){t.EDIT_DISTANCE="edit-distance",t.SIMILARITY="similarity"}(p||(p={}));const Y=new Error("unknown returnType"),w=new Error("unknown thresholdType"),F=(t,e)=>{let s=t;return e.trimSpaces&&(s=s.trim().replace(/\s+/g," ")),e.deburr&&(s=ht(s)),e.caseSensitive||(s=s.toLowerCase()),s},U=(t,e)=>{const{matchPath:s}=e,x=((i,u)=>{const f=u.length>0?u.reduce((S,l)=>S==null?void 0:S[l],i):i;return typeof f!="string"?"":f})(t,s);return F(x,e)};function bt(t,e,s){const x=(o=>{const n={caseSensitive:!1,deburr:!0,matchPath:[],returnType:g.FIRST_CLOSEST_MATCH,thresholdType:p.SIMILARITY,trimSpaces:!0,...o};switch(n.thresholdType){case p.EDIT_DISTANCE:return{threshold:20,...n};case p.SIMILARITY:return{threshold:.4,...n};default:throw w}})(s),{returnType:i,threshold:u,thresholdType:f}=x,S=F(t,x);let l,b;switch(f){case p.EDIT_DISTANCE:l=o=>o<=u,b=o=>N(S,U(o,x));break;case p.SIMILARITY:l=o=>o>=u,b=o=>((n,r)=>{if(!n||!r)return 0;if(n===r)return 1;const c=N(n,r),h=Math.max(n.length,r.length);return(h-c)/h})(S,U(o,x));break;default:throw w}const d=[],T=e.length;switch(i){case g.ALL_CLOSEST_MATCHES:case g.FIRST_CLOSEST_MATCH:{const o=[];let n;switch(f){case p.EDIT_DISTANCE:n=1/0;for(let c=0;c<T;c+=1){const h=b(e[c]);n>h&&(n=h),o.push(h)}break;case p.SIMILARITY:n=0;for(let c=0;c<T;c+=1){const h=b(e[c]);n<h&&(n=h),o.push(h)}break;default:throw w}const r=o.length;for(let c=0;c<r;c+=1){const h=o[c];l(h)&&h===n&&d.push(c)}break}case g.ALL_MATCHES:for(let o=0;o<T;o+=1)l(b(e[o]))&&d.push(o);break;case g.ALL_SORTED_MATCHES:{const o=[];for(let n=0;n<T;n+=1){const r=b(e[n]);l(r)&&o.push({score:r,index:n})}switch(f){case p.EDIT_DISTANCE:o.sort((n,r)=>n.score-r.score);break;case p.SIMILARITY:o.sort((n,r)=>r.score-n.score);break;default:throw w}for(const n of o)d.push(n.index);break}case g.FIRST_MATCH:for(let o=0;o<T;o+=1)if(l(b(e[o]))){d.push(o);break}break;default:throw Y}return((o,n,r)=>{switch(r){case g.ALL_CLOSEST_MATCHES:case g.ALL_MATCHES:case g.ALL_SORTED_MATCHES:return n.map(c=>o[c]);case g.FIRST_CLOSEST_MATCH:case g.FIRST_MATCH:return n.length?o[n[0]]:null;default:throw Y}})(e,d,i)}var L={exports:{}};let dt=z,St=!("NO_COLOR"in process.env||process.argv.includes("--no-color"))&&("FORCE_COLOR"in process.env||process.argv.includes("--color")||process.platform==="win32"||dt.isatty(1)&&process.env.TERM!=="dumb"||"CI"in process.env),m=(t,e,s=t)=>x=>{let i=""+x,u=i.indexOf(e,t.length);return~u?t+G(i,e,s,u)+e:t+i+e},G=(t,e,s,x)=>{let i=t.substring(0,x)+s,u=t.substring(x+e.length),f=u.indexOf(e);return~f?i+G(u,e,s,f):i+u},P=(t=St)=>({isColorSupported:t,reset:t?e=>`\x1B[0m${e}\x1B[0m`:String,bold:t?m("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"):String,dim:t?m("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m"):String,italic:t?m("\x1B[3m","\x1B[23m"):String,underline:t?m("\x1B[4m","\x1B[24m"):String,inverse:t?m("\x1B[7m","\x1B[27m"):String,hidden:t?m("\x1B[8m","\x1B[28m"):String,strikethrough:t?m("\x1B[9m","\x1B[29m"):String,black:t?m("\x1B[30m","\x1B[39m"):String,red:t?m("\x1B[31m","\x1B[39m"):String,green:t?m("\x1B[32m","\x1B[39m"):String,yellow:t?m("\x1B[33m","\x1B[39m"):String,blue:t?m("\x1B[34m","\x1B[39m"):String,magenta:t?m("\x1B[35m","\x1B[39m"):String,cyan:t?m("\x1B[36m","\x1B[39m"):String,white:t?m("\x1B[37m","\x1B[39m"):String,gray:t?m("\x1B[90m","\x1B[39m"):String,bgBlack:t?m("\x1B[40m","\x1B[49m"):String,bgRed:t?m("\x1B[41m","\x1B[49m"):String,bgGreen:t?m("\x1B[42m","\x1B[49m"):String,bgYellow:t?m("\x1B[43m","\x1B[49m"):String,bgBlue:t?m("\x1B[44m","\x1B[49m"):String,bgMagenta:t?m("\x1B[45m","\x1B[49m"):String,bgCyan:t?m("\x1B[46m","\x1B[49m"):String,bgWhite:t?m("\x1B[47m","\x1B[49m"):String});L.exports=P(),L.exports.createColors=P;const gt=t=>t.length<=1?t[0]:`${t.slice(0,-1).map(L.exports.bold).join(", ")} and ${L.exports.bold(t[t.length-1])}`,pt=()=>$({setup:t=>t.inspector({enforce:"pre",fn:(e,s)=>{const x=Object.keys(t._commands),i=!!x.length;try{s()}catch(u){if(!(u instanceof q||u instanceof R))throw u;if(e.raw._.length===0||u instanceof R){console.error("No command given."),i&&console.error(`Possible commands: ${gt(x)}.`);return}const f=u.commandName,S=bt(f,x);console.error(`Command "${L.exports.strikethrough(f)}" not found.`),i&&S?console.error(`Did you mean "${L.exports.bold(S)}"?`):i||console.error("NOTE: You haven't register any command yet."),process.stderr.write(`
|
|
2
|
+
`),process.exit(2)}}})});export{pt as notFoundPlugin};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clerc/plugin-not-found",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.1",
|
|
4
4
|
"author": "Ray <nn_201312@163.com> (https://github.com/so1ve)",
|
|
5
5
|
"description": "Clerc plugin not found (did you mean)",
|
|
6
6
|
"keywords": [
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
"exports": {
|
|
28
28
|
".": {
|
|
29
29
|
"types": "./dist/index.d.ts",
|
|
30
|
-
"import": "./dist/index.
|
|
30
|
+
"import": "./dist/index.js"
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
33
|
"main": "dist/index.js",
|
|
34
|
-
"module": "dist/index.
|
|
34
|
+
"module": "dist/index.js",
|
|
35
35
|
"types": "dist/index.d.ts",
|
|
36
36
|
"typesVersions": {
|
|
37
37
|
"*": {
|
|
@@ -50,16 +50,14 @@
|
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"@clerc/core": "*"
|
|
52
52
|
},
|
|
53
|
-
"
|
|
53
|
+
"devDependencies": {
|
|
54
54
|
"didyoumean2": "^5.0.0",
|
|
55
55
|
"picocolors": "^1.0.0",
|
|
56
|
-
"@clerc/
|
|
57
|
-
|
|
58
|
-
"devDependencies": {
|
|
59
|
-
"@clerc/core": "0.25.1"
|
|
56
|
+
"@clerc/core": "0.27.1",
|
|
57
|
+
"@clerc/utils": "0.27.1"
|
|
60
58
|
},
|
|
61
59
|
"scripts": {
|
|
62
|
-
"build": "puild",
|
|
60
|
+
"build": "puild --minify",
|
|
63
61
|
"watch": "puild --watch"
|
|
64
62
|
}
|
|
65
63
|
}
|
package/dist/index.mjs
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { definePlugin, NoSuchCommandError, NoCommandGivenError } from '@clerc/core';
|
|
2
|
-
import didyoumean from 'didyoumean2';
|
|
3
|
-
import pc from 'picocolors';
|
|
4
|
-
|
|
5
|
-
const semanticArray = (arr) => {
|
|
6
|
-
if (arr.length <= 1) {
|
|
7
|
-
return arr[0];
|
|
8
|
-
}
|
|
9
|
-
return `${arr.slice(0, -1).map(pc.bold).join(", ")} and ${pc.bold(arr[arr.length - 1])}`;
|
|
10
|
-
};
|
|
11
|
-
const notFoundPlugin = () => definePlugin({
|
|
12
|
-
setup: (cli) => {
|
|
13
|
-
return cli.inspector({
|
|
14
|
-
enforce: "pre",
|
|
15
|
-
fn: (ctx, next) => {
|
|
16
|
-
const commandKeys = Object.keys(cli._commands);
|
|
17
|
-
const hasCommands = !!commandKeys.length;
|
|
18
|
-
try {
|
|
19
|
-
next();
|
|
20
|
-
} catch (e) {
|
|
21
|
-
if (!(e instanceof NoSuchCommandError || e instanceof NoCommandGivenError)) {
|
|
22
|
-
throw e;
|
|
23
|
-
}
|
|
24
|
-
if (ctx.raw._.length === 0 || e instanceof NoCommandGivenError) {
|
|
25
|
-
console.error("No command given.");
|
|
26
|
-
if (hasCommands) {
|
|
27
|
-
console.error(`Possible commands: ${semanticArray(commandKeys)}.`);
|
|
28
|
-
}
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
const calledCommandName = e.commandName;
|
|
32
|
-
const closestCommandName = didyoumean(calledCommandName, commandKeys);
|
|
33
|
-
console.error(`Command "${pc.strikethrough(calledCommandName)}" not found.`);
|
|
34
|
-
if (hasCommands && closestCommandName) {
|
|
35
|
-
console.error(`Did you mean "${pc.bold(closestCommandName)}"?`);
|
|
36
|
-
} else if (!hasCommands) {
|
|
37
|
-
console.error("NOTE: You haven't register any command yet.");
|
|
38
|
-
}
|
|
39
|
-
process.stderr.write("\n");
|
|
40
|
-
process.exit(2);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
export { notFoundPlugin };
|