@crustjs/core 0.0.14 → 0.0.15
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 +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{a as
|
|
2
|
+
import{a as A,b as $,c as B,d as S}from"./shared/chunk-vt64gs69.js";function I(j){return{meta:{name:j},localFlags:{},effectiveFlags:{},args:void 0,subCommands:{},plugins:[],preRun:void 0,run:void 0,postRun:void 0}}function X(j,q){let J={};for(let[Q,G]of Object.entries(j))if(G.inherit===!0)J[Q]=G;for(let[Q,G]of Object.entries(q))J[Q]=G;return J}function D(j,q){let J=[j.meta.name],Q=j,G=q;while(G.length>0){let H=Q.subCommands;if(!H||Object.keys(H).length===0)break;let Z=G[0];if(!Z||Z.startsWith("-"))break;if(Z in H&&H[Z]){Q=H[Z],J.push(Z),G=G.slice(1);continue}if(Q.run)break;let Y=Object.keys(H);throw new $("COMMAND_NOT_FOUND",`Unknown command "${Z}".`,{input:Z,available:Y,commandPath:[...J],parentCommand:Q})}return{command:Q,argv:G,commandPath:J}}function F(j){for(let[q,J]of Object.entries(j)){if(q.startsWith("no-")){let Q=q.slice(3);throw new $("DEFINITION",`Flag "--${q}" must not use "no-" prefix; define "${Q}" and negate with "--no-${Q}"`)}if(J.short?.startsWith("no-"))throw new $("DEFINITION",`Short alias "-${J.short}" on "--${q}" must not use "no-" prefix (reserved for negation)`);if(J.aliases){for(let Q of J.aliases)if(Q.startsWith("no-"))throw new $("DEFINITION",`Alias "--${Q}" on "--${q}" must not use "no-" prefix (reserved for negation)`)}}}var P="CRUST_INTERNAL_VALIDATE_ONLY",_=130,k="__CRUST_VALIDATE_RESULT__";function w(){let j=new Map;return{get(q){return j.get(q)},has(q){return j.has(q)},set(q,J){j.set(q,J)},delete(q){return j.delete(q)}}}function L(j){if(!(j instanceof Error))return!1;return j.name==="CancelledError"}function O(j,q){j.effectiveFlags=X(q,j.localFlags);for(let J of Object.values(j.subCommands))O(J,j.effectiveFlags)}function N(j){return{addFlag(q,J,Q){if(J in q.effectiveFlags)j?.push(`Plugin flag "--${J}" on "${q.meta.name}" overrides existing flag`);q.effectiveFlags[J]=Q},addSubCommand(q,J,Q){if(!J.trim())throw new $("DEFINITION","addSubCommand: name must be a non-empty string");if(q.subCommands[J]){j?.push(`Plugin subcommand "${J}" on "${q.meta.name}" skipped (already exists)`);return}O(Q,q.effectiveFlags),q.subCommands[J]=Q}}}async function b(j,q,J){for(let Q of j){if(!Q.setup)continue;await Q.setup(q,J)}}async function T(j,q,J){let Q=j.map((Z)=>Z.middleware).filter((Z)=>Boolean(Z)),G=-1,H=async(Z)=>{if(Z<=G)throw new $("DEFINITION","Plugin middleware called next() multiple times");if(G=Z,Z===Q.length){await J();return}let Y=Q[Z];if(!Y)throw new $("DEFINITION","Plugin middleware stack is invalid");await Y(q,()=>H(Z+1))};await H(0)}function x(j){let q=[...j.plugins];for(let J of Object.values(j.subCommands))q.push(...x(J));return q}function y(j){if(Object.freeze(j),Object.freeze(j.localFlags),Object.freeze(j.effectiveFlags),Object.freeze(j.meta),Object.freeze(j.plugins),j.args)Object.freeze(j.args);for(let q of Object.values(j.subCommands))y(q);Object.freeze(j.subCommands)}class R{_node;_inheritedFlags;constructor(j){if(!j.trim())throw new $("DEFINITION","meta.name must be a non-empty string");this._node=I(j),this._inheritedFlags={}}static _createChild(j,q){let J=new R(j);return J._inheritedFlags=q,J}_clone(j){let q=Object.create(Object.getPrototypeOf(this)),J={...this._node,localFlags:{...this._node.localFlags},effectiveFlags:{...this._node.effectiveFlags},subCommands:{...this._node.subCommands},plugins:[...this._node.plugins],meta:{...this._node.meta},args:this._node.args?[...this._node.args]:void 0,...j};return q._node=J,q._inheritedFlags=this._inheritedFlags,q}meta(j){return this._clone({meta:{...this._node.meta,...j}})}flags(j){F(j);let q={};for(let[J,Q]of Object.entries(j))q[J]={...Q};return this._clone({localFlags:q,effectiveFlags:X(this._inheritedFlags,q)})}args(j){let q=j.map((J)=>({...J}));return this._clone({args:q})}run(j){return this._clone({run:j})}preRun(j){return this._clone({preRun:j})}postRun(j){return this._clone({postRun:j})}use(j){return this._clone({plugins:[...this._node.plugins,j]})}sub(j){if(!j.trim())throw new $("DEFINITION","Subcommand name must be a non-empty string");let q=X(this._inheritedFlags,this._node.localFlags);return R._createChild(j,q)}command(j,q){if(typeof j==="string"){let H=j;if(!q)throw new $("DEFINITION","command(name, cb) requires a callback");if(!H.trim())throw new $("DEFINITION","Subcommand name must be a non-empty string");if(this._node.subCommands[H])throw new $("DEFINITION",`Subcommand "${H}" is already registered`);let Z=X(this._inheritedFlags,this._node.localFlags),Y=R._createChild(H,Z),z=q(Y),W={...z._node,effectiveFlags:X(z._inheritedFlags,z._node.localFlags)};return this._clone({subCommands:{...this._node.subCommands,[H]:W}})}let J=j,Q=J._node.meta.name;if(!Q.trim())throw new $("DEFINITION","Subcommand name must be a non-empty string");if(this._node.subCommands[Q])throw new $("DEFINITION",`Subcommand "${Q}" is already registered`);let G={...J._node,effectiveFlags:X(J._inheritedFlags,J._node.localFlags)};return this._clone({subCommands:{...this._node.subCommands,[Q]:G}})}async execute(j){let q=j?.argv??process.argv.slice(2),J=this._node,Q=x(J),G=[],H=w(),Z={argv:[...q],rootCommand:J,state:H},Y=N(G);try{await b(Q,Z,Y)}catch(W){if(L(W)){process.exitCode=_;return}if(W instanceof $){console.error(`Error: ${W.message}`),process.exitCode=1;return}let K=W instanceof Error?W.message:String(W);console.error(`Error: ${K}`),process.exitCode=1;return}if(y(J),process.env[P]==="1"){let W=(async()=>{try{let{validateCommandTree:K}=await import("./shared/chunk-5apf3vnv.js");K(J);for(let U of G)console.warn(`Warning: ${U}`);return{ok:!0}}catch(K){let U=K instanceof Error?K.message:String(K);return console.error(U),process.exitCode=1,{ok:!1,error:K}}})();return globalThis[k]=W,await W,process.exit(process.exitCode??0)}for(let W of G)console.warn(`Warning: ${W}`);let z={argv:[...q],rootCommand:J,state:H,route:null,input:null};try{let W,K;try{let U=D(J,[...q]);z.route=U,W=U.command,K=B(W,U.argv),z.input=K}catch(U){await T(Q,z,async()=>{throw U});return}await T(Q,z,async()=>{if(S(W,K),!W.run)return;let U={args:K.args,flags:K.flags,rawArgs:K.rawArgs,command:W},V;try{if(W.preRun)await W.preRun(U);await W.run(U)}catch(M){V=M}if(W.postRun)try{await W.postRun(U)}catch(M){if(!V)V=M;else console.error(`Error in postRun: ${M instanceof Error?M.message:String(M)}`)}if(V)throw V})}catch(W){if(L(W)){process.exitCode=_;return}if(W instanceof $){console.error(`Error: ${W.message}`),process.exitCode=1;return}if(W instanceof Error){let K=new $("EXECUTION",W.message).withCause(W);console.error(`Error: ${K.message}`),process.exitCode=1;return}console.error(`Error: ${String(W)}`),process.exitCode=1}}}export{S as validateParsed,D as resolveCommand,B as parseArgs,P as VALIDATION_MODE_ENV,$ as CrustError,R as Crust};
|