@stacksjs/dtsx 0.8.3 → 0.9.3
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 +2 -2
- package/dist/bin/cli.js +9 -0
- package/dist/chunk-pppmq87w.js +482 -0
- package/dist/config.d.ts +3 -2
- package/dist/extractor.d.ts +6 -0
- package/dist/generator.d.ts +9 -0
- package/dist/index.d.ts +7 -6
- package/dist/parser.d.ts +52 -0
- package/dist/processor.d.ts +45 -0
- package/dist/src/index.js +3 -0
- package/dist/types.d.ts +72 -99
- package/dist/utils.d.ts +2 -3
- package/package.json +12 -24
- package/LICENSE.md +0 -21
- package/dist/cli.js +0 -389
- package/dist/extract.d.ts +0 -68
- package/dist/generate.d.ts +0 -4
- package/dist/index.js +0 -46
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
bun install -d @stacksjs/dtsx
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
_@npmjs.com, please allow us to use the `dtsx` package name 🙏_
|
|
27
27
|
|
|
28
28
|
<!-- _Alternatively, you can install:_
|
|
29
29
|
|
|
@@ -63,7 +63,7 @@ const options: DtsGenerationOptions = {
|
|
|
63
63
|
outdir: './dist', // default: './dist'
|
|
64
64
|
clean: true, // default: false
|
|
65
65
|
verbose: true, // default: false
|
|
66
|
-
|
|
66
|
+
keepComments: true, // default: true
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
await generate(options)
|
package/dist/bin/cli.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{r as _}from"../chunk-pppmq87w.js";import{resolve as b}from"path";import G from"process";import{EventEmitter as T}from"events";function x(t){return t==null?[]:Array.isArray(t)?t:[t]}function M(t,e,s,n){var i,o=t[e],l=~n.string.indexOf(e)?s==null||s===!0?"":String(s):typeof s==="boolean"?s:~n.boolean.indexOf(e)?s==="false"?!1:s==="true"||(t._.push((i=+s,i*0===0)?i:s),!!s):(i=+s,i*0===0)?i:s;t[e]=o==null?l:Array.isArray(o)?o.concat(l):[o,l]}function V(t,e){t=t||[],e=e||{};var s,n,i,o,l,c={_:[]},r=0,a=0,u=0,h=t.length;let d=e.alias!==void 0,y=e.unknown!==void 0,v=e.default!==void 0;if(e.alias=e.alias||{},e.string=x(e.string),e.boolean=x(e.boolean),d)for(s in e.alias){n=e.alias[s]=x(e.alias[s]);for(r=0;r<n.length;r++)(e.alias[n[r]]=n.concat(s)).splice(r,1)}for(r=e.boolean.length;r-- >0;){n=e.alias[e.boolean[r]]||[];for(a=n.length;a-- >0;)e.boolean.push(n[a])}for(r=e.string.length;r-- >0;){n=e.alias[e.string[r]]||[];for(a=n.length;a-- >0;)e.string.push(n[a])}if(v){for(s in e.default)if(o=typeof e.default[s],n=e.alias[s]=e.alias[s]||[],e[o]!==void 0){e[o].push(s);for(r=0;r<n.length;r++)e[o].push(n[r])}}let j=y?Object.keys(e.alias):[];for(r=0;r<h;r++){if(i=t[r],i==="--"){c._=c._.concat(t.slice(++r));break}for(a=0;a<i.length;a++)if(i.charCodeAt(a)!==45)break;if(a===0)c._.push(i);else if(i.substring(a,a+3)==="no-"){if(o=i.substring(a+3),y&&!~j.indexOf(o))return e.unknown(i);c[o]=!1}else{for(u=a+1;u<i.length;u++)if(i.charCodeAt(u)===61)break;o=i.substring(a,u),l=i.substring(++u)||(r+1===h||(""+t[r+1]).charCodeAt(0)===45||t[++r]),n=a===2?[o]:o;for(u=0;u<n.length;u++){if(o=n[u],y&&!~j.indexOf(o))return e.unknown("-".repeat(a)+o);M(c,o,u+1<n.length||l,e)}}}if(v){for(s in e.default)if(c[s]===void 0)c[s]=e.default[s]}if(d)for(s in c){n=e.alias[s]||[];while(n.length>0)c[n.shift()]=c[s]}return c}var D=(t)=>t.replace(/[<[].+/,"").trim(),P=(t)=>{let e=/<([^>]+)>/g,s=/\[([^\]]+)\]/g,n=[],i=(c)=>{let r=!1,a=c[1];if(a.startsWith("..."))a=a.slice(3),r=!0;return{required:c[0].startsWith("<"),value:a,variadic:r}},o;while(o=e.exec(t))n.push(i(o));let l;while(l=s.exec(t))n.push(i(l));return n},B=(t)=>{let e={alias:{},boolean:[]};for(let[s,n]of t.entries()){if(n.names.length>1)e.alias[n.names[0]]=n.names.slice(1);if(n.isBoolean)if(n.negated){if(!t.some((o,l)=>{return l!==s&&o.names.some((c)=>n.names.includes(c))&&typeof o.required==="boolean"}))e.boolean.push(n.names[0])}else e.boolean.push(n.names[0])}return e},$=(t)=>{return t.sort((e,s)=>{return e.length>s.length?-1:1})[0]},A=(t,e)=>{return t.length>=e?t:`${t}${" ".repeat(e-t.length)}`},q=(t)=>{return t.replace(/([a-z])-([a-z])/g,(e,s,n)=>{return s+n.toUpperCase()})},I=(t,e,s)=>{let n=0,i=e.length,o=t,l;for(;n<i;++n)l=o[e[n]],o=o[e[n]]=n===i-1?s:l!=null?l:!!~e[n+1].indexOf(".")||!(+e[n+1]>-1)?{}:[]},S=(t,e)=>{for(let s of Object.keys(e)){let n=e[s];if(n.shouldTransform){if(t[s]=Array.prototype.concat.call([],t[s]),typeof n.transformFunction==="function")t[s]=t[s].map(n.transformFunction)}}},R=(t)=>{let e=/([^\\\/]+)$/.exec(t);return e?e[1]:""},E=(t)=>{return t.split(".").map((e,s)=>{return s===0?q(e):e}).join(".")};class g extends Error{constructor(t){super(t);if(this.name=this.constructor.name,typeof Error.captureStackTrace==="function")Error.captureStackTrace(this,this.constructor);else this.stack=new Error(t).stack}}class N{constructor(t,e,s){if(this.rawName=t,this.description=e,this.config=Object.assign({},s),t=t.replace(/\.\*/g,""),this.negated=!1,this.names=D(t).split(",").map((n)=>{let i=n.trim().replace(/^-{1,2}/,"");if(i.startsWith("no-"))this.negated=!0,i=i.replace(/^no-/,"");return E(i)}).sort((n,i)=>n.length>i.length?1:-1),this.name=this.names[this.names.length-1],this.negated&&this.config.default==null)this.config.default=!0;if(t.includes("<"))this.required=!0;else if(t.includes("["))this.required=!1;else this.isBoolean=!0}}var U=process.argv,H=`${process.platform}-${process.arch} node-${process.version}`;class k{constructor(t,e,s={},n){this.rawName=t,this.description=e,this.config=s,this.cli=n,this.options=[],this.aliasNames=[],this.name=D(t),this.args=P(t),this.examples=[]}usage(t){return this.usageText=t,this}allowUnknownOptions(){return this.config.allowUnknownOptions=!0,this}ignoreOptionDefaultValue(){return this.config.ignoreOptionDefaultValue=!0,this}version(t,e="-v, --version"){return this.versionNumber=t,this.option(e,"Display version number"),this}example(t){return this.examples.push(t),this}option(t,e,s){let n=new N(t,e,s);return this.options.push(n),this}alias(t){return this.aliasNames.push(t),this}action(t){return this.commandAction=t,this}isMatched(t){return this.name===t||this.aliasNames.includes(t)}get isDefaultCommand(){return this.name===""||this.aliasNames.includes("!")}get isGlobalCommand(){return this instanceof C}hasOption(t){return t=t.split(".")[0],this.options.find((e)=>{return e.names.includes(t)})}outputHelp(){let{name:t,commands:e}=this.cli,{versionNumber:s,options:n,helpCallback:i}=this.cli.globalCommand,o=[{body:`${t}${s?`/${s}`:""}`}];if(o.push({title:"Usage",body:` $ ${t} ${this.usageText||this.rawName}`}),(this.isGlobalCommand||this.isDefaultCommand)&&e.length>0){let r=$(e.map((a)=>a.rawName));o.push({title:"Commands",body:e.map((a)=>{return` ${A(a.rawName,r.length)} ${a.description}`}).join(`
|
|
3
|
+
`)}),o.push({title:"For more info, run any command with the `--help` flag",body:e.map((a)=>` $ ${t}${a.name===""?"":` ${a.name}`} --help`).join(`
|
|
4
|
+
`)})}let c=this.isGlobalCommand?n:[...this.options,...n||[]];if(!this.isGlobalCommand&&!this.isDefaultCommand)c=c.filter((r)=>r.name!=="version");if(c.length>0){let r=$(c.map((a)=>a.rawName));o.push({title:"Options",body:c.map((a)=>{return` ${A(a.rawName,r.length)} ${a.description} ${a.config.default===void 0?"":`(default: ${a.config.default})`}`}).join(`
|
|
5
|
+
`)})}if(this.examples.length>0)o.push({title:"Examples",body:this.examples.map((r)=>{if(typeof r==="function")return r(t);return r}).join(`
|
|
6
|
+
`)});if(i)o=i(o)||o;console.log(o.map((r)=>{return r.title?`${r.title}:
|
|
7
|
+
${r.body}`:r.body}).join(`
|
|
8
|
+
|
|
9
|
+
`))}outputVersion(){let{name:t}=this.cli,{versionNumber:e}=this.cli.globalCommand;if(e)console.log(`${t}/${e} ${H}`)}checkRequiredArgs(){let t=this.args.filter((e)=>e.required).length;if(this.cli.args.length<t)throw new g(`missing required args for command \`${this.rawName}\``)}checkUnknownOptions(){let{options:t,globalCommand:e}=this.cli;if(!this.config.allowUnknownOptions){for(let s of Object.keys(t))if(s!=="--"&&!this.hasOption(s)&&!e.hasOption(s))throw new g(`Unknown option \`${s.length>1?`--${s}`:`-${s}`}\``)}}checkOptionValue(){let{options:t,globalCommand:e}=this.cli,s=[...e.options,...this.options];for(let n of s){let i=t[n.name.split(".")[0]];if(n.required){let o=s.some((l)=>l.negated&&l.names.includes(n.name));if(i===!0||i===!1&&!o)throw new g(`option \`${n.rawName}\` value is missing`)}}}}class C extends k{constructor(t){super("@@global@@","",{},t)}}var p=Object.assign;class w extends T{constructor(t=""){super();this.name=t,this.commands=[],this.rawArgs=[],this.args=[],this.options={},this.globalCommand=new C(this),this.globalCommand.usage("<command> [options]")}usage(t){return this.globalCommand.usage(t),this}command(t,e,s){let n=new k(t,e||"",s,this);return n.globalCommand=this.globalCommand,this.commands.push(n),n}option(t,e,s){return this.globalCommand.option(t,e,s),this}help(t){return this.globalCommand.option("-h, --help","Display this message"),this.globalCommand.helpCallback=t,this.showHelpOnExit=!0,this}version(t,e="-v, --version"){return this.globalCommand.version(t,e),this.showVersionOnExit=!0,this}example(t){return this.globalCommand.example(t),this}outputHelp(){if(this.matchedCommand)this.matchedCommand.outputHelp();else this.globalCommand.outputHelp()}outputVersion(){this.globalCommand.outputVersion()}setParsedInfo({args:t,options:e},s,n){if(this.args=t,this.options=e,s)this.matchedCommand=s;if(n)this.matchedCommandName=n;return this}unsetMatchedCommand(){this.matchedCommand=void 0,this.matchedCommandName=void 0}parse(t=U,{run:e=!0}={}){if(this.rawArgs=t,!this.name)this.name=t[1]?R(t[1]):"cli";let s=!0;for(let i of this.commands){let o=this.mri(t.slice(2),i),l=o.args[0];if(i.isMatched(l)){s=!1;let c=p(p({},o),{args:o.args.slice(1)});this.setParsedInfo(c,i,l),this.emit(`command:${l}`,i)}}if(s){for(let i of this.commands)if(i.name===""){s=!1;let o=this.mri(t.slice(2),i);this.setParsedInfo(o,i),this.emit("command:!",i)}}if(s){let i=this.mri(t.slice(2));this.setParsedInfo(i)}if(this.options.help&&this.showHelpOnExit)this.outputHelp(),e=!1,this.unsetMatchedCommand();if(this.options.version&&this.showVersionOnExit&&this.matchedCommandName==null)this.outputVersion(),e=!1,this.unsetMatchedCommand();let n={args:this.args,options:this.options};if(e)this.runMatchedCommand();if(!this.matchedCommand&&this.args[0])this.emit("command:*");return n}mri(t,e){let s=[...this.globalCommand.options,...e?e.options:[]],n=B(s),i=[],o=t.indexOf("--");if(o>-1)i=t.slice(o+1),t=t.slice(0,o);let l=V(t,n);l=Object.keys(l).reduce((h,d)=>{return p(p({},h),{[E(d)]:l[d]})},{_:[]});let c=l._,r={"--":i},a=e&&e.config.ignoreOptionDefaultValue?e.config.ignoreOptionDefaultValue:this.globalCommand.config.ignoreOptionDefaultValue,u=Object.create(null);for(let h of s){if(!a&&h.config.default!==void 0)for(let d of h.names)r[d]=h.config.default;if(Array.isArray(h.config.type)){if(u[h.name]===void 0)u[h.name]=Object.create(null),u[h.name].shouldTransform=!0,u[h.name].transformFunction=h.config.type[0]}}for(let h of Object.keys(l))if(h!=="_"){let d=h.split(".");I(r,d,l[h]),S(r,u)}return{args:c,options:r}}runMatchedCommand(){let{args:t,options:e,matchedCommand:s}=this;if(!s||!s.commandAction)return;s.checkUnknownOptions(),s.checkOptionValue(),s.checkRequiredArgs();let n=[];return s.args.forEach((i,o)=>{if(i.variadic)n.push(t.slice(o));else n.push(t[o])}),n.push(e),s.commandAction.apply(this,n)}}var O="0.9.3";var f=new w("dtsx"),m={cwd:G.cwd(),root:"./src",entrypoints:["**/*.ts"],outdir:"./dist",keepComments:!0,clean:!1,tsconfigPath:"tsconfig.json",verbose:!1};f.command("generate","Generate TypeScript declaration files").option("--cwd <path>","Current working directory",{default:m.cwd}).option("--root <path>","Root directory of the project",{default:m.root}).option("--entrypoints <files>","Entry point files (comma-separated)",{default:m.entrypoints?.join(","),type:[String]}).option("--outdir <path>","Output directory for generated .d.ts files",{default:m.outdir}).option("--keep-comments","Keep comments in generated .d.ts files",{default:m.keepComments}).option("--clean","Clean output directory before generation",{default:m.clean}).option("--tsconfig <path>","Path to tsconfig.json",{default:m.tsconfigPath}).option("--verbose","Enable verbose logging",{default:m.verbose}).example("dtsx generate").example("dtsx generate --entrypoints src/index.ts,src/utils.ts --outdir dist/types").action(async(t)=>{try{let e={entrypoints:t.entrypoints?t.entrypoints:m.entrypoints,cwd:b(t.cwd||m.cwd),root:b(t.root||m.root),outdir:b(t.outdir||m.outdir),tsconfigPath:b(t.tsconfigPath||m.tsconfigPath),keepComments:t.keepComments||m.keepComments,clean:t.clean||m.clean,verbose:t.verbose||m.verbose};await _(e)}catch(e){console.error("Error generating .d.ts files:",e),G.exit(1)}});f.command("version","Show the version of dtsx").action(()=>{console.log(O)});f.version(O);f.help();f.parse();
|