@tsmodule/tsmodule 41.40.0 → 42.1.0

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -3,8 +3,9 @@
3
3
  <h1>TypeScript Module Toolkit</h1>
4
4
  </div>
5
5
 
6
- tsmodule is a toolkit for developing **standardized, pure ESM TypeScript
7
- modules** that target any platform.
6
+ Create standardized TypeScript ESM packages for Node or browser. Includes
7
+ `--bundle` and `--binary` build options, powered by
8
+ [**esbuild**](https://github.com/evanw/esbuild).
8
9
 
9
10
  **Table of contents**
10
11
 
package/dist/bin.js CHANGED
@@ -4,7 +4,7 @@
4
4
  if(typeof process<"u"){let{dirname:e}=await import("path"),{fileURLToPath:i}=await import("url");globalThis.__filename=i(import.meta.url),globalThis.__dirname=e(globalThis.__filename);let{default:a}=await import("module");globalThis.require=a.createRequire(import.meta.url)}
5
5
  /** __ESM_SHIM_END */
6
6
 
7
- import{a as f,b as R,c as B,d as U,f as G,h as J,i as z,j as K,k as Y,l as Q}from"./chunk-CJB3QE3J.js";import{a as E,b as A,c as ft}from"./chunk-UNZJKJGP.js";var x=A(F=>{var v=class extends Error{constructor(t,e,i){super(i),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=e,this.exitCode=t,this.nestedError=void 0}},k=class extends v{constructor(t){super(1,"commander.invalidArgument",t),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}};F.CommanderError=v;F.InvalidArgumentError=k});var $=A(N=>{var{InvalidArgumentError:gt}=x(),D=class{constructor(t,e){switch(this.description=e||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,t[0]){case"<":this.required=!0,this._name=t.slice(1,-1);break;case"[":this.required=!1,this._name=t.slice(1,-1);break;default:this.required=!0,this._name=t;break}this._name.length>3&&this._name.slice(-3)==="..."&&(this.variadic=!0,this._name=this._name.slice(0,-3))}name(){return this._name}_concatValue(t,e){return e===this.defaultValue||!Array.isArray(e)?[t]:e.concat(t)}default(t,e){return this.defaultValue=t,this.defaultValueDescription=e,this}argParser(t){return this.parseArg=t,this}choices(t){return this.argChoices=t.slice(),this.parseArg=(e,i)=>{if(!this.argChoices.includes(e))throw new gt(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._concatValue(e,i):e},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}};function _t(h){let t=h.name()+(h.variadic===!0?"...":"");return h.required?"<"+t+">":"["+t+"]"}N.Argument=D;N.humanReadableArgName=_t});var T=A(X=>{var{humanReadableArgName:Ot}=$(),P=class{constructor(){this.helpWidth=void 0,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}visibleCommands(t){let e=t.commands.filter(i=>!i._hidden);if(t._hasImplicitHelpCommand()){let[,i,n]=t._helpCommandnameAndArgs.match(/([^ ]+) *(.*)/),s=t.createCommand(i).helpOption(!1);s.description(t._helpCommandDescription),n&&s.arguments(n),e.push(s)}return this.sortSubcommands&&e.sort((i,n)=>i.name().localeCompare(n.name())),e}compareOptions(t,e){let i=n=>n.short?n.short.replace(/^-/,""):n.long.replace(/^--/,"");return i(t).localeCompare(i(e))}visibleOptions(t){let e=t.options.filter(s=>!s.hidden),i=t._hasHelpOption&&t._helpShortFlag&&!t._findOption(t._helpShortFlag),n=t._hasHelpOption&&!t._findOption(t._helpLongFlag);if(i||n){let s;i?n?s=t.createOption(t._helpFlags,t._helpDescription):s=t.createOption(t._helpShortFlag,t._helpDescription):s=t.createOption(t._helpLongFlag,t._helpDescription),e.push(s)}return this.sortOptions&&e.sort(this.compareOptions),e}visibleGlobalOptions(t){if(!this.showGlobalOptions)return[];let e=[];for(let i=t.parent;i;i=i.parent){let n=i.options.filter(s=>!s.hidden);e.push(...n)}return this.sortOptions&&e.sort(this.compareOptions),e}visibleArguments(t){return t._argsDescription&&t._args.forEach(e=>{e.description=e.description||t._argsDescription[e.name()]||""}),t._args.find(e=>e.description)?t._args:[]}subcommandTerm(t){let e=t._args.map(i=>Ot(i)).join(" ");return t._name+(t._aliases[0]?"|"+t._aliases[0]:"")+(t.options.length?" [options]":"")+(e?" "+e:"")}optionTerm(t){return t.flags}argumentTerm(t){return t.name()}longestSubcommandTermLength(t,e){return e.visibleCommands(t).reduce((i,n)=>Math.max(i,e.subcommandTerm(n).length),0)}longestOptionTermLength(t,e){return e.visibleOptions(t).reduce((i,n)=>Math.max(i,e.optionTerm(n).length),0)}longestGlobalOptionTermLength(t,e){return e.visibleGlobalOptions(t).reduce((i,n)=>Math.max(i,e.optionTerm(n).length),0)}longestArgumentTermLength(t,e){return e.visibleArguments(t).reduce((i,n)=>Math.max(i,e.argumentTerm(n).length),0)}commandUsage(t){let e=t._name;t._aliases[0]&&(e=e+"|"+t._aliases[0]);let i="";for(let n=t.parent;n;n=n.parent)i=n.name()+" "+i;return i+e+" "+t.usage()}commandDescription(t){return t.description()}subcommandDescription(t){return t.summary()||t.description()}optionDescription(t){let e=[];return t.argChoices&&e.push(`choices: ${t.argChoices.map(i=>JSON.stringify(i)).join(", ")}`),t.defaultValue!==void 0&&(t.required||t.optional||t.isBoolean()&&typeof t.defaultValue=="boolean")&&e.push(`default: ${t.defaultValueDescription||JSON.stringify(t.defaultValue)}`),t.presetArg!==void 0&&t.optional&&e.push(`preset: ${JSON.stringify(t.presetArg)}`),t.envVar!==void 0&&e.push(`env: ${t.envVar}`),e.length>0?`${t.description} (${e.join(", ")})`:t.description}argumentDescription(t){let e=[];if(t.argChoices&&e.push(`choices: ${t.argChoices.map(i=>JSON.stringify(i)).join(", ")}`),t.defaultValue!==void 0&&e.push(`default: ${t.defaultValueDescription||JSON.stringify(t.defaultValue)}`),e.length>0){let i=`(${e.join(", ")})`;return t.description?`${t.description} ${i}`:i}return t.description}formatHelp(t,e){let i=e.padWidth(t,e),n=e.helpWidth||80,s=2,r=2;function a(m,O){if(O){let H=`${m.padEnd(i+r)}${O}`;return e.wrap(H,n-s,i+r)}return m}function o(m){return m.join(`
7
+ import{a as f,b as R,c as B,d as U,f as G,h as J,i as z,j as K,k as Y,l as Q}from"./chunk-QWDDUAEY.js";import{a as E,b as A,c as ft}from"./chunk-UNZJKJGP.js";var x=A(F=>{var v=class extends Error{constructor(t,e,i){super(i),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=e,this.exitCode=t,this.nestedError=void 0}},k=class extends v{constructor(t){super(1,"commander.invalidArgument",t),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}};F.CommanderError=v;F.InvalidArgumentError=k});var $=A(N=>{var{InvalidArgumentError:gt}=x(),D=class{constructor(t,e){switch(this.description=e||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,t[0]){case"<":this.required=!0,this._name=t.slice(1,-1);break;case"[":this.required=!1,this._name=t.slice(1,-1);break;default:this.required=!0,this._name=t;break}this._name.length>3&&this._name.slice(-3)==="..."&&(this.variadic=!0,this._name=this._name.slice(0,-3))}name(){return this._name}_concatValue(t,e){return e===this.defaultValue||!Array.isArray(e)?[t]:e.concat(t)}default(t,e){return this.defaultValue=t,this.defaultValueDescription=e,this}argParser(t){return this.parseArg=t,this}choices(t){return this.argChoices=t.slice(),this.parseArg=(e,i)=>{if(!this.argChoices.includes(e))throw new gt(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._concatValue(e,i):e},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}};function _t(h){let t=h.name()+(h.variadic===!0?"...":"");return h.required?"<"+t+">":"["+t+"]"}N.Argument=D;N.humanReadableArgName=_t});var T=A(X=>{var{humanReadableArgName:Ot}=$(),P=class{constructor(){this.helpWidth=void 0,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}visibleCommands(t){let e=t.commands.filter(i=>!i._hidden);if(t._hasImplicitHelpCommand()){let[,i,n]=t._helpCommandnameAndArgs.match(/([^ ]+) *(.*)/),s=t.createCommand(i).helpOption(!1);s.description(t._helpCommandDescription),n&&s.arguments(n),e.push(s)}return this.sortSubcommands&&e.sort((i,n)=>i.name().localeCompare(n.name())),e}compareOptions(t,e){let i=n=>n.short?n.short.replace(/^-/,""):n.long.replace(/^--/,"");return i(t).localeCompare(i(e))}visibleOptions(t){let e=t.options.filter(s=>!s.hidden),i=t._hasHelpOption&&t._helpShortFlag&&!t._findOption(t._helpShortFlag),n=t._hasHelpOption&&!t._findOption(t._helpLongFlag);if(i||n){let s;i?n?s=t.createOption(t._helpFlags,t._helpDescription):s=t.createOption(t._helpShortFlag,t._helpDescription):s=t.createOption(t._helpLongFlag,t._helpDescription),e.push(s)}return this.sortOptions&&e.sort(this.compareOptions),e}visibleGlobalOptions(t){if(!this.showGlobalOptions)return[];let e=[];for(let i=t.parent;i;i=i.parent){let n=i.options.filter(s=>!s.hidden);e.push(...n)}return this.sortOptions&&e.sort(this.compareOptions),e}visibleArguments(t){return t._argsDescription&&t._args.forEach(e=>{e.description=e.description||t._argsDescription[e.name()]||""}),t._args.find(e=>e.description)?t._args:[]}subcommandTerm(t){let e=t._args.map(i=>Ot(i)).join(" ");return t._name+(t._aliases[0]?"|"+t._aliases[0]:"")+(t.options.length?" [options]":"")+(e?" "+e:"")}optionTerm(t){return t.flags}argumentTerm(t){return t.name()}longestSubcommandTermLength(t,e){return e.visibleCommands(t).reduce((i,n)=>Math.max(i,e.subcommandTerm(n).length),0)}longestOptionTermLength(t,e){return e.visibleOptions(t).reduce((i,n)=>Math.max(i,e.optionTerm(n).length),0)}longestGlobalOptionTermLength(t,e){return e.visibleGlobalOptions(t).reduce((i,n)=>Math.max(i,e.optionTerm(n).length),0)}longestArgumentTermLength(t,e){return e.visibleArguments(t).reduce((i,n)=>Math.max(i,e.argumentTerm(n).length),0)}commandUsage(t){let e=t._name;t._aliases[0]&&(e=e+"|"+t._aliases[0]);let i="";for(let n=t.parent;n;n=n.parent)i=n.name()+" "+i;return i+e+" "+t.usage()}commandDescription(t){return t.description()}subcommandDescription(t){return t.summary()||t.description()}optionDescription(t){let e=[];return t.argChoices&&e.push(`choices: ${t.argChoices.map(i=>JSON.stringify(i)).join(", ")}`),t.defaultValue!==void 0&&(t.required||t.optional||t.isBoolean()&&typeof t.defaultValue=="boolean")&&e.push(`default: ${t.defaultValueDescription||JSON.stringify(t.defaultValue)}`),t.presetArg!==void 0&&t.optional&&e.push(`preset: ${JSON.stringify(t.presetArg)}`),t.envVar!==void 0&&e.push(`env: ${t.envVar}`),e.length>0?`${t.description} (${e.join(", ")})`:t.description}argumentDescription(t){let e=[];if(t.argChoices&&e.push(`choices: ${t.argChoices.map(i=>JSON.stringify(i)).join(", ")}`),t.defaultValue!==void 0&&e.push(`default: ${t.defaultValueDescription||JSON.stringify(t.defaultValue)}`),e.length>0){let i=`(${e.join(", ")})`;return t.description?`${t.description} ${i}`:i}return t.description}formatHelp(t,e){let i=e.padWidth(t,e),n=e.helpWidth||80,s=2,r=2;function a(m,O){if(O){let H=`${m.padEnd(i+r)}${O}`;return e.wrap(H,n-s,i+r)}return m}function o(m){return m.join(`
8
8
  `).replace(/^/gm," ".repeat(s))}let l=[`Usage: ${e.commandUsage(t)}`,""],u=e.commandDescription(t);u.length>0&&(l=l.concat([e.wrap(u,n,0),""]));let c=e.visibleArguments(t).map(m=>a(e.argumentTerm(m),e.argumentDescription(m)));c.length>0&&(l=l.concat(["Arguments:",o(c),""]));let d=e.visibleOptions(t).map(m=>a(e.optionTerm(m),e.optionDescription(m)));if(d.length>0&&(l=l.concat(["Options:",o(d),""])),this.showGlobalOptions){let m=e.visibleGlobalOptions(t).map(O=>a(e.optionTerm(O),e.optionDescription(O)));m.length>0&&(l=l.concat(["Global Options:",o(m),""]))}let C=e.visibleCommands(t).map(m=>a(e.subcommandTerm(m),e.subcommandDescription(m)));return C.length>0&&(l=l.concat(["Commands:",o(C),""])),l.join(`
9
9
  `)}padWidth(t,e){return Math.max(e.longestOptionTermLength(t,e),e.longestGlobalOptionTermLength(t,e),e.longestSubcommandTermLength(t,e),e.longestArgumentTermLength(t,e))}wrap(t,e,i,n=40){let s=" \\f\\t\\v   -    \uFEFF",r=new RegExp(`[\\n][${s}]+`);if(t.match(r))return t;let a=e-i;if(a<n)return t;let o=t.slice(0,i),l=t.slice(i).replace(`\r
10
10
  `,`