@langpkg/pkg 0.0.7 → 0.0.8

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
@@ -13,7 +13,7 @@
13
13
  <b>Stop worrying about configuration. Start building.</b>
14
14
  <br>
15
15
  </p>
16
- <img data="version" src="https://img.shields.io/badge/v-0.0.7-black"/>
16
+ <img data="version" src="https://img.shields.io/badge/v-0.0.8-black"/>
17
17
  <a href="https://github.com/langpkg"><img src="https://img.shields.io/badge/@-langpkg-black"/></a>
18
18
  <br>
19
19
  <img src="https://img.shields.io/badge/coverage-~%25-brightgreen" alt="Test Coverage" />
package/dist/index.cjs CHANGED
@@ -48,4 +48,4 @@
48
48
  `);for(let a of c)!h(a)&&!y(a)&&a.trim()&&process.stderr.write(a+`
49
49
  `);}),n.on("close",r=>{s.nl(),t(),process.exit(r||0);}),n.on("error",r=>{s.error(`Failed to list packages: ${r.message}`),s.nl(),process.exit(1);});})}catch{return g("list")}}};var se=class{constructor(){this.cache=null;this.dirty=false;this.initialized=false;this.cacheDir=P.join(process.cwd(),".pkg"),this.cacheFile=P.join(this.cacheDir,"cache");}initialize(){try{if(v.existsSync(this.cacheDir)||v.mkdirSync(this.cacheDir,{recursive:!0}),v.existsSync(this.cacheFile))try{let e=v.readFileSync(this.cacheFile,"utf-8");this.cache=JSON.parse(e);}catch{this.cache=this.createNewCache(),this.dirty=!0;}else this.cache=this.createNewCache(),this.dirty=!0;this.initialized=!0;}catch{this.cache=this.createNewCache(),this.initialized=true;}}shouldFormat(e){if(!this.initialized||!this.cache)return true;let t=this.normalizePath(e);try{let n=v.readFileSync(e,"utf-8"),r=this.hashContent(n),c=this.cache.files[t];return c?c.hash!==r:!0}catch{return true}}markFormatted(e){if(!this.initialized||!this.cache)return;let t=this.normalizePath(e);try{let n=v.readFileSync(e,"utf-8"),r=this.hashContent(n);this.cache.files[t]={hash:r},this.dirty=!0;}catch{}}save(){if(!this.initialized||!this.cache||!this.dirty){this.dirty;return}try{v.existsSync(this.cacheDir)||v.mkdirSync(this.cacheDir,{recursive:!0}),this.cache.timestamp=Date.now();let e=this.formatCacheJson(this.cache);v.writeFileSync(this.cacheFile,e,"utf-8"),this.dirty=!1;}catch{}}formatCacheJson(e){let t={timestamp:e.timestamp,files:e.files},n=JSON.stringify(t,null,2);return n.endsWith(`
50
50
  `)||(n+=`
51
- `),n}clear(){this.initialized&&(this.cache=this.createNewCache(),this.dirty=true,this.save());}cleanup(){if(!this.initialized||!this.cache)return;let e=[],t=new Map;for(let n of Object.keys(this.cache.files))try{if(v.existsSync(n)){let r=this.normalizePath(n);t.has(r)?t.get(r)!==n&&e.push(n):t.set(r,n);}else {let r=!1;if(n.includes(":/")){let c="./"+n.split(/[\/\\]/).slice(-2).join("/");v.existsSync(c)&&(r=!0);}r||e.push(n);}}catch{}if(e.length>0){for(let n of e)delete this.cache.files[n];this.dirty=true,this.save();}}loadFromDisk(){try{if(v.existsSync(this.cacheFile)){let e=v.readFileSync(this.cacheFile,"utf-8");if(this.cache=JSON.parse(e),this.cache&&this.cache.files&&typeof this.cache.files=="object"){let t=!1,n={};for(let[r,c]of Object.entries(this.cache.files)){let a=r;a.startsWith("./")&&(a=a.substring(2),t=!0),n[a]=c;}t&&(this.cache.files=n,this.dirty=!0,this.save());}}}catch{}}hashContent(e){return crypto.createHash("sha256").update(e).digest("hex")}normalizePath(e){try{let t;return P.isAbsolute(e)?t=P.relative(process.cwd(),e):t=e,t=t.replace(/\\/g,"/"),t.startsWith("./")&&(t=t.substring(2)),t=t.replace(/\/+/g,"/"),t}catch{return e}}createNewCache(){return {timestamp:Date.now(),files:{}}}};var ne=class{constructor(e){this.params=e;}async run(){try{s.nl();let e=new se;e.initialize(),this.params.options?.clean&&e.clear();let t=P.resolve(P.isAbsolute(this.params.args.path||".")?this.params.args.path||".":this.params.args.path||".");if(!S(t)&&!A(t)){s.error(`Path not found: ${t}`),s.nl();return}let n=x(p.muted("Formatting files..."));n.start();let r=[],c=[],a=[];for(let d of ["src","test","bench"])A(d)&&this.collectTsFiles(d,r);S("eslint.config.mjs")&&r.push("eslint.config.mjs"),S("tsup.config.ts")&&r.push("tsup.config.ts"),S("README.md")&&a.push("README.md"),A("docs")&&be("docs",a);let l=0,o=new Set;for(let d of r)if(S(d))try{if(!e.shouldFormat(d))continue;let u=I(d),f=mcs_fmt.formatTS(u,d);if(f.errors?.length===0){e.markFormatted(d),T(d,f.formatted)&&(o.add(d),l+=f.count);continue}else f.errors?.forEach(b=>{s.warn(` ${d}:${b.line}:${b.column??0} - ${b.message}`);}),s.nl();}catch{}for(let d of c)if(S(d))try{let u=I(d);if(!e.shouldFormat(d))continue;let f=mcs_fmt.formatJSON(u,d);if(f.errors?.length===0){e.markFormatted(d),T(d,f.formatted)&&(o.add(d),l+=f.count);continue}else f.errors?.forEach(b=>{s.warn(` ${d}:${b.line}:${b.column??0} - ${b.message}`);}),s.nl();}catch{}for(let d of a)if(S(d))try{let u=I(d);if(!e.shouldFormat(d))continue;let f=mcs_fmt.formatMD(u,d);if(f.errors?.length===0){e.markFormatted(d),T(d,f.formatted)&&(o.add(d),l+=f.count);continue}else f.errors?.forEach(b=>{s.warn(` ${d}:${b.line}:${b.column??0} - ${b.message}`);}),s.nl();}catch{}let i=[];for(let d of ["src","test","bench"])A(d)&&i.push(...mt(d));if(n.stop(),l===0&&i.length===0){s.success("All files formatted correctly."),s.nl(),e.save();return}if(l>0&&s.success(`Fixed ${l} issue${l>1?"s":""} across ${o.size} file${o.size>1?"s":""}`),i.length>0){s.warn(`Found ${i.length} naming issue${i.length>1?"s":""} (not auto-fixable)`);for(let d of i.slice(0,5))s.info(` ${this.shortenPath(d.file)}:${d.line} ${d.message}`);i.length>5&&s.info(` ... and ${i.length-5} more`);}e.save(),s.nl();}catch{return g("fmt")}}collectTsFiles(e,t){try{let n=v.readdirSync(e,{withFileTypes:!0});for(let r of n){let c=P.join(e,r.name);r.isDirectory()&&!r.name.startsWith(".")?this.collectTsFiles(c,t):r.isFile()&&r.name.endsWith(".ts")&&t.push(c);}}catch{}}collectJsonFiles(e,t){try{let n=v.readdirSync(e,{withFileTypes:!0});for(let r of n){let c=P.join(e,r.name);r.isDirectory()&&!r.name.startsWith(".")?this.collectJsonFiles(c,t):r.isFile()&&r.name.endsWith(".json")&&t.push(c);}}catch{}}shortenPath(e){let t=e.replace(/\\/g,"/");for(let n of ["src","test","bench",".vscode"]){let r=t.indexOf(`/${n}/`);if(r!==-1)return t.substring(r+1)}return t}};function be(m,e){try{let t=v.readdirSync(m,{withFileTypes:!0});for(let n of t){let r=P.join(m,n.name);n.isDirectory()&&!n.name.startsWith(".")&&n.name!=="node_modules"?be(r,e):n.isFile()&&n.name.endsWith(".md")&&e.push(r);}}catch{}}function ct(m){return /^[a-z0-9_]+(\.[a-z0-9]+)?$/.test(m)}function lt(m){return /^[a-z0-9_-]+(\.[a-z0-9]+)?$/.test(m)}function mt(m){let e=[];try{let t=glob.glob.sync(`${m}/**/*.ts`,{dot:!1});for(let n of t){let r=n.split(/[\\/]/).pop()??"",c=r.replace(/\.ts$/,"");lt(c)||e.push({file:n,line:1,code:"FILE_NAME_INVALID",message:`File name "${r}" must follow snake_case convention (e.g., my_file.ts)`,severity:"warning",fixable:!1});let a=n.split(/[\\/]/);for(let l=a.indexOf(m)+1;l<a.length-1;l++){let o=a[l];if(o&&!ct(o)){e.push({file:n,line:1,code:"FOLDER_NAME_INVALID",message:`Folder name "${o}" must follow snake_case convention (e.g., my_folder/)`,severity:"warning",fixable:!1});break}}}}catch{}return e}var ie=class{constructor(e){this.config=e;}run(){cli.cli(this.config.name,this.config.version).description(this.config.desc).command({name:"init",description:"Initialize a new project",args:[{name:"name",required:false,description:"Package name (e.g. @org/repo or myrepo)"}],options:[{name:"as",flag:"--as",type:"string",required:false,description:"Project type: normal (library) or cli (executable)"},{name:"dir",flag:"--dir",type:"string",required:false,description:"Target directory to initialize in (skips creating a <name> subfolder)"},{name:"yes",flag:"-y",type:"boolean",required:false,description:"Skip all prompts and use defaults (requires <name> and --as to be passed)"}],action:e=>{let t={args:{name:e.args.name},options:{as:e.options?.as,dir:e.options?.dir,yes:e.options?.yes}};this.runInitCommand(t);}}).command({name:"build",description:"Build package with tsup",args:[],options:[{name:"watch",flag:"--watch",type:"boolean",required:false,description:"Watch mode"},{name:"clean",flag:"--clean",type:"boolean",required:false,description:"Remove dist/ before building"}],action:e=>{let t={args:{},options:{watch:e.options?.watch,clean:e.options?.clean}};this.runBuildCommand(t);}}).command({name:"test",description:"Run tests with bun test",args:[{name:"patterns",required:false,description:"Test file patterns (e.g., src/, file.test.ts)"}],allowDynamicArgs:true,options:[{name:"watch",flag:"--watch",type:"boolean",required:false,description:"Watch mode"},{name:"coverage",flag:"--coverage",type:"boolean",required:false,description:"Generate coverage report"},{name:"testNamePattern",flag:"-t",type:"string",required:false,description:"Filter tests by name pattern"},{name:"retry",flag:"--retry",type:"string",required:false,description:"Retry failed tests"},{name:"timeout",flag:"--timeout",type:"string",required:false,description:"Per-test timeout in milliseconds"},{name:"concurrent",flag:"--concurrent",type:"boolean",required:false,description:"Run tests in parallel"},{name:"bail",flag:"--bail",type:"string",required:false,description:"Bail after n failures (use --bail or --bail=2)"}],action:e=>{let t={args:{},dynamicArgs:e.dynamicArgs,options:{watch:e.options?.watch,coverage:e.options?.coverage,testNamePattern:e.options?.testNamePattern,retry:e.options?.retry?parseInt(e.options.retry):void 0,timeout:e.options?.timeout?parseInt(e.options.timeout):void 0,bail:e.options?.bail?e.options.bail==="true"||e.options.bail===""?true:parseInt(e.options.bail):void 0,concurrent:e.options?.concurrent}};this.runTestCommand(t);}}).command({name:"lint",description:"Lint code with eslint",args:[{name:"paths",required:false,description:"Paths to lint (defaults to src/ and test/)"}],allowDynamicArgs:true,options:[{name:"fix",flag:"--fix",type:"boolean",required:false,description:"Automatically fix violations"},{name:"fixDryRun",flag:"--fix-dry-run",type:"boolean",required:false,description:"Check fixes without writing"},{name:"format",flag:"--format",type:"string",required:false,description:"Output format: stylish, json, compact"},{name:"maxWarnings",flag:"--max-warnings",type:"string",required:false,description:"Fail if warnings exceed this number"},{name:"cache",flag:"--cache",type:"boolean",required:false,description:"Use cache for faster runs"},{name:"quiet",flag:"--quiet",type:"boolean",required:false,description:"Report errors only"}],action:e=>{let t={args:{},dynamicArgs:e.dynamicArgs,options:{fix:e.options?.fix,fixDryRun:e.options?.fixDryRun,format:e.options?.format,maxWarnings:e.options?.maxWarnings?parseInt(e.options.maxWarnings):void 0,cache:e.options?.cache,quiet:e.options?.quiet}};this.runLintCommand(t);}}).command({name:"i",aliases:["install"],description:"Install dependencies or add packages",args:[{name:"packages",required:false,description:"Packages to install (e.g., lodash react)"}],allowDynamicArgs:true,options:[{name:"dev",flag:"-D",aliases:["--dev"],type:"boolean",required:false,description:"Install as dev dependency"},{name:"peer",flag:"-p",aliases:["--peer"],type:"boolean",required:false,description:"Install as peer dependency"},{name:"exact",flag:"--exact",type:"boolean",required:false,description:"Use exact version instead of ranges"},{name:"global",flag:"-g",aliases:["--global"],type:"boolean",required:false,description:"Install globally instead of locally"}],action:e=>{let t=[];e.args?.packages&&(Array.isArray(e.args.packages)?t.push(...e.args.packages):typeof e.args.packages=="string"&&t.push(e.args.packages)),e.dynamicArgs&&e.dynamicArgs.length>0&&t.push(...e.dynamicArgs);let n={args:{},dynamicArgs:t,options:{dev:e.options?.dev,peer:e.options?.peer,exact:e.options?.exact,global:e.options?.global}};this.runInstallCommand(n);}}).command({name:"uninstall",aliases:["un"],description:"Uninstall packages from project or globally",args:[{name:"packages",required:false,description:"Package names to uninstall"}],allowDynamicArgs:true,options:[{name:"global",flag:"-g",aliases:["--global"],type:"boolean",required:false,description:"Uninstall globally instead of locally"}],action:e=>{let t=[];e.args?.packages&&(Array.isArray(e.args.packages)?t.push(...e.args.packages):typeof e.args.packages=="string"&&t.push(e.args.packages)),e.dynamicArgs&&e.dynamicArgs.length>0&&t.push(...e.dynamicArgs);let n={args:{},dynamicArgs:t,options:{global:e.options?.global}};this.runUninstallCommand(n);}}).command({name:"link",description:"Link current package globally or link global packages to project",args:[{name:"packages",required:false,description:"Package names to link from global (optional)"}],allowDynamicArgs:true,options:[],action:e=>{let t=[];e.args.packages&&t.push(e.args.packages),e.dynamicArgs&&e.dynamicArgs.length>0&&t.push(...e.dynamicArgs);let n={args:{},dynamicArgs:t.length>0?t:void 0,options:{}};this.runLinkCommand(n);}}).command({name:"unlink",description:"Unlink current package from global or unlink global packages from project",args:[{name:"packages",required:false,description:"Package names to unlink from project (optional)"}],allowDynamicArgs:true,options:[],action:e=>{let t=[];e.args.packages&&t.push(e.args.packages),e.dynamicArgs&&e.dynamicArgs.length>0&&t.push(...e.dynamicArgs);let n={args:{},dynamicArgs:t.length>0?t:void 0,options:{}};this.runUnlinkCommand(n);}}).command({name:"up",aliases:["update"],description:"Update all or specific packages",args:[{name:"packages",required:false,description:"Packages to update (e.g., lodash react)"}],allowDynamicArgs:true,options:[{name:"interactive",flag:"-i",aliases:["--interactive"],type:"boolean",required:false,description:"Interactive update mode"},{name:"latest",flag:"-l",aliases:["--latest"],type:"boolean",required:false,description:"Update to latest versions"}],action:e=>{let t={args:{},dynamicArgs:e.dynamicArgs,options:{interactive:e.options?.interactive,latest:e.options?.latest}};this.runUpdateCommand(t);}}).command({name:"publish",aliases:["pub"],description:"Publish package to npm registry",args:[],options:[{name:"tag",flag:"--tag",type:"string",required:false,description:"Publish under specific dist-tag (e.g., beta, next)"},{name:"public",flag:"-y",type:"boolean",required:false,description:"Public access (default)"}],action:e=>{let t={args:{},options:{tag:e.options?.tag,public:e.options?.public}};this.runPublishCommand(t);}}).command({name:"exec",description:"Execute TypeScript/JavaScript code directly",args:[{name:"code",required:true,description:"Code to execute"}],options:[],action:e=>{let t={args:{code:e.args.code},options:{}};this.runExecCommand(t);}}).command({name:"list",aliases:["ls"],description:"List installed packages (local or global)",args:[],options:[{name:"global",flag:"-g",aliases:["--global"],type:"boolean",required:false,description:"List global packages instead of local"}],action:e=>{let t={args:{},options:{global:e.options?.global}};this.runListCommand(t);}}).command({name:"version",aliases:["ver"],description:"Bump package version and update version badges",args:[{name:"type",required:false,description:"Bump type: major, minor, patch, or version string (e.g., 1.2.3)"}],options:[{name:"major",flag:"--major",type:"string",required:false,description:"Set major version"},{name:"minor",flag:"--minor",type:"string",required:false,description:"Set minor version"},{name:"patch",flag:"--patch",type:"string",required:false,description:"Set patch version"}],action:e=>{let t={args:{type:e.args.type},options:{major:e.options?.major,minor:e.options?.minor,patch:e.options?.patch}};this.runVersionCommand(t);}}).command({name:"fmt",aliases:[],description:"Format TypeScript and JSON files",args:[{name:"path",required:false,description:"Target file or directory (default: current directory)"}],options:[{name:"clean",flag:"--clean",aliases:["-c"],type:"boolean",required:false,description:"Clear the formatter cache before running"}],action:e=>{let t={args:{path:e.args.path},options:{clean:e.options?.clean}};this.runFmtCommand(t);}}).build().run();}runInitCommand(e){new K(e).run();}runBuildCommand(e){new G(e).run();}runTestCommand(e){new Y(e).run();}runLintCommand(e){new Z(e).run();}runInstallCommand(e){new M(e).run();}runUninstallCommand(e){new U(e).run();}runLinkCommand(e){new Q(e).run();}runUnlinkCommand(e){new W(e).run();}runUpdateCommand(e){new J(e).run();}runPublishCommand(e){new _(e).run();}runExecCommand(e){new X(e).run();}runListCommand(e){new ee(e).run();}runVersionCommand(e){new z(e).run();}runFmtCommand(e){new ne(e).run();}};var dt=new ie({name:"pkg",version:"0.0.1",desc:"Build, manage, publish, and test packages with zero configuration."});dt.run();
51
+ `),n}clear(){this.initialized&&(this.cache=this.createNewCache(),this.dirty=true,this.save());}cleanup(){if(!this.initialized||!this.cache)return;let e=[],t=new Map;for(let n of Object.keys(this.cache.files))try{if(v.existsSync(n)){let r=this.normalizePath(n);t.has(r)?t.get(r)!==n&&e.push(n):t.set(r,n);}else {let r=!1;if(n.includes(":/")){let c="./"+n.split(/[\/\\]/).slice(-2).join("/");v.existsSync(c)&&(r=!0);}r||e.push(n);}}catch{}if(e.length>0){for(let n of e)delete this.cache.files[n];this.dirty=true,this.save();}}loadFromDisk(){try{if(v.existsSync(this.cacheFile)){let e=v.readFileSync(this.cacheFile,"utf-8");if(this.cache=JSON.parse(e),this.cache&&this.cache.files&&typeof this.cache.files=="object"){let t=!1,n={};for(let[r,c]of Object.entries(this.cache.files)){let a=r;a.startsWith("./")&&(a=a.substring(2),t=!0),n[a]=c;}t&&(this.cache.files=n,this.dirty=!0,this.save());}}}catch{}}hashContent(e){return crypto.createHash("sha256").update(e).digest("hex")}normalizePath(e){try{let t;return P.isAbsolute(e)?t=P.relative(process.cwd(),e):t=e,t=t.replace(/\\/g,"/"),t.startsWith("./")&&(t=t.substring(2)),t=t.replace(/\/+/g,"/"),t}catch{return e}}createNewCache(){return {timestamp:Date.now(),files:{}}}};var ne=class{constructor(e){this.params=e;}async run(){try{s.nl();let e=new se;e.initialize(),this.params.options?.clean&&e.clear();let t=P.resolve(P.isAbsolute(this.params.args.path||".")?this.params.args.path||".":this.params.args.path||".");if(!S(t)&&!A(t)){s.error(`Path not found: ${t}`),s.nl();return}let n=x(p.muted("Formatting files..."));n.start();let r=[],c=[],a=[];for(let d of ["src","test","bench"])A(d)&&this.collectTsFiles(d,r);S("eslint.config.mjs")&&r.push("eslint.config.mjs"),S("tsup.config.ts")&&r.push("tsup.config.ts"),S("README.md")&&a.push("README.md"),A("docs")&&be("docs",a);let l=0,o=new Set;for(let d of r)if(S(d))try{if(!e.shouldFormat(d))continue;let u=I(d),f=mcs_fmt.formatTS(u,d);if(f.errors?.length===0){e.markFormatted(d),T(d,f.formatted)&&(o.add(d),l+=f.count);continue}else f.errors?.forEach(b=>{s.warn(` ${d}:${b.line}:${b.column??0} - ${b.message}`);}),s.nl();}catch{}for(let d of c)if(S(d))try{let u=I(d);if(!e.shouldFormat(d))continue;let f=mcs_fmt.formatJSON(u,d);if(f.errors?.length===0){e.markFormatted(d),T(d,f.formatted)&&(o.add(d),l+=f.count);continue}else f.errors?.forEach(b=>{s.warn(` ${d}:${b.line}:${b.column??0} - ${b.message}`);}),s.nl();}catch{}for(let d of a)if(S(d))try{let u=I(d);if(!e.shouldFormat(d))continue;let f=mcs_fmt.formatMD(u,d);if(f.errors?.length===0){e.markFormatted(d),T(d,f.formatted)&&(o.add(d),l+=f.count);continue}else f.errors?.forEach(b=>{s.warn(` ${d}:${b.line}:${b.column??0} - ${b.message}`);}),s.nl();}catch{}let i=[];for(let d of ["src","test","bench"])A(d)&&i.push(...mt(d));if(n.stop(),l===0&&i.length===0){s.success("All files formatted correctly."),s.nl(),e.save();return}if(l>0&&s.success(`Fixed ${l} issue${l>1?"s":""} across ${o.size} file${o.size>1?"s":""}`),i.length>0){s.warn(`Found ${i.length} naming issue${i.length>1?"s":""} (not auto-fixable)`);for(let d of i.slice(0,5))s.info(` ${this.shortenPath(d.file)}:${d.line} ${d.message}`);i.length>5&&s.info(` ... and ${i.length-5} more`);}e.save(),s.nl();}catch{return g("fmt")}}collectTsFiles(e,t){try{let n=v.readdirSync(e,{withFileTypes:!0});for(let r of n){let c=P.join(e,r.name);r.isDirectory()&&!r.name.startsWith(".")?this.collectTsFiles(c,t):r.isFile()&&r.name.endsWith(".ts")&&t.push(c);}}catch{}}collectJsonFiles(e,t){try{let n=v.readdirSync(e,{withFileTypes:!0});for(let r of n){let c=P.join(e,r.name);r.isDirectory()&&!r.name.startsWith(".")?this.collectJsonFiles(c,t):r.isFile()&&r.name.endsWith(".json")&&t.push(c);}}catch{}}shortenPath(e){let t=e.replace(/\\/g,"/");for(let n of ["src","test","bench",".vscode"]){let r=t.indexOf(`/${n}/`);if(r!==-1)return t.substring(r+1)}return t}};function be(m,e){try{let t=v.readdirSync(m,{withFileTypes:!0});for(let n of t){let r=P.join(m,n.name);n.isDirectory()&&!n.name.startsWith(".")&&n.name!=="node_modules"?be(r,e):n.isFile()&&n.name.endsWith(".md")&&e.push(r);}}catch{}}function ct(m){return /^[a-z0-9_]+(\.[a-z0-9]+)?$/.test(m)}function lt(m){return /^[a-z0-9_-]+(\.[a-z0-9]+)?$/.test(m)}function mt(m){let e=[];try{let t=glob.glob.sync(`${m}/**/*.ts`,{dot:!1});for(let n of t){let r=n.split(/[\\/]/).pop()??"",c=r.replace(/\.ts$/,"");lt(c)||e.push({file:n,line:1,code:"FILE_NAME_INVALID",message:`File name "${r}" must follow snake_case convention (e.g., my_file.ts)`,severity:"warning",fixable:!1});let a=n.split(/[\\/]/);for(let l=a.indexOf(m)+1;l<a.length-1;l++){let o=a[l];if(o&&!ct(o)){e.push({file:n,line:1,code:"FOLDER_NAME_INVALID",message:`Folder name "${o}" must follow snake_case convention (e.g., my_folder/)`,severity:"warning",fixable:!1});break}}}}catch{}return e}var ie=class{constructor(e){this.config=e;}run(){cli.cli(this.config.name,this.config.version).description(this.config.desc).command({name:"init",description:"Initialize a new project",args:[{name:"name",required:false,description:"Package name (e.g. @org/repo or myrepo)"}],options:[{name:"as",flag:"--as",type:"string",required:false,description:"Project type: normal (library) or cli (executable)"},{name:"dir",flag:"--dir",type:"string",required:false,description:"Target directory to initialize in (skips creating a <name> subfolder)"},{name:"yes",flag:"-y",type:"boolean",required:false,description:"Skip all prompts and use defaults (requires <name> and --as to be passed)"}],action:e=>{let t={args:{name:e.args.name},options:{as:e.options?.as,dir:e.options?.dir,yes:e.options?.yes}};this.runInitCommand(t);}}).command({name:"build",description:"Build package with tsup",args:[],options:[{name:"watch",flag:"--watch",type:"boolean",required:false,description:"Watch mode"},{name:"clean",flag:"--clean",type:"boolean",required:false,description:"Remove dist/ before building"}],action:e=>{let t={args:{},options:{watch:e.options?.watch,clean:e.options?.clean}};this.runBuildCommand(t);}}).command({name:"test",description:"Run tests with bun test",allowDynamicArgs:true,options:[{name:"watch",flag:"--watch",type:"boolean",required:false,description:"Watch mode"},{name:"coverage",flag:"--coverage",type:"boolean",required:false,description:"Generate coverage report"},{name:"testNamePattern",flag:"-t",type:"string",required:false,description:"Filter tests by name pattern"},{name:"retry",flag:"--retry",type:"string",required:false,description:"Retry failed tests"},{name:"timeout",flag:"--timeout",type:"string",required:false,description:"Per-test timeout in milliseconds"},{name:"concurrent",flag:"--concurrent",type:"boolean",required:false,description:"Run tests in parallel"},{name:"bail",flag:"--bail",type:"string",required:false,description:"Bail after n failures (use --bail or --bail=2)"}],action:e=>{let t={args:{},dynamicArgs:e.dynamicArgs,options:{watch:e.options?.watch,coverage:e.options?.coverage,testNamePattern:e.options?.testNamePattern,retry:e.options?.retry?parseInt(e.options.retry):void 0,timeout:e.options?.timeout?parseInt(e.options.timeout):void 0,bail:e.options?.bail?e.options.bail==="true"||e.options.bail===""?true:parseInt(e.options.bail):void 0,concurrent:e.options?.concurrent}};this.runTestCommand(t);}}).command({name:"lint",description:"Lint code with eslint",args:[{name:"paths",required:false,description:"Paths to lint (defaults to src/ and test/)"}],allowDynamicArgs:true,options:[{name:"fix",flag:"--fix",type:"boolean",required:false,description:"Automatically fix violations"},{name:"fixDryRun",flag:"--fix-dry-run",type:"boolean",required:false,description:"Check fixes without writing"},{name:"format",flag:"--format",type:"string",required:false,description:"Output format: stylish, json, compact"},{name:"maxWarnings",flag:"--max-warnings",type:"string",required:false,description:"Fail if warnings exceed this number"},{name:"cache",flag:"--cache",type:"boolean",required:false,description:"Use cache for faster runs"},{name:"quiet",flag:"--quiet",type:"boolean",required:false,description:"Report errors only"}],action:e=>{let t={args:{},dynamicArgs:e.dynamicArgs,options:{fix:e.options?.fix,fixDryRun:e.options?.fixDryRun,format:e.options?.format,maxWarnings:e.options?.maxWarnings?parseInt(e.options.maxWarnings):void 0,cache:e.options?.cache,quiet:e.options?.quiet}};this.runLintCommand(t);}}).command({name:"i",aliases:["install"],description:"Install dependencies or add packages",args:[{name:"packages",required:false,description:"Packages to install (e.g., lodash react)"}],allowDynamicArgs:true,options:[{name:"dev",flag:"-D",aliases:["--dev"],type:"boolean",required:false,description:"Install as dev dependency"},{name:"peer",flag:"-p",aliases:["--peer"],type:"boolean",required:false,description:"Install as peer dependency"},{name:"exact",flag:"--exact",type:"boolean",required:false,description:"Use exact version instead of ranges"},{name:"global",flag:"-g",aliases:["--global"],type:"boolean",required:false,description:"Install globally instead of locally"}],action:e=>{let t=[];e.args?.packages&&(Array.isArray(e.args.packages)?t.push(...e.args.packages):typeof e.args.packages=="string"&&t.push(e.args.packages)),e.dynamicArgs&&e.dynamicArgs.length>0&&t.push(...e.dynamicArgs);let n={args:{},dynamicArgs:t,options:{dev:e.options?.dev,peer:e.options?.peer,exact:e.options?.exact,global:e.options?.global}};this.runInstallCommand(n);}}).command({name:"uninstall",aliases:["un"],description:"Uninstall packages from project or globally",args:[{name:"packages",required:false,description:"Package names to uninstall"}],allowDynamicArgs:true,options:[{name:"global",flag:"-g",aliases:["--global"],type:"boolean",required:false,description:"Uninstall globally instead of locally"}],action:e=>{let t=[];e.args?.packages&&(Array.isArray(e.args.packages)?t.push(...e.args.packages):typeof e.args.packages=="string"&&t.push(e.args.packages)),e.dynamicArgs&&e.dynamicArgs.length>0&&t.push(...e.dynamicArgs);let n={args:{},dynamicArgs:t,options:{global:e.options?.global}};this.runUninstallCommand(n);}}).command({name:"link",description:"Link current package globally or link global packages to project",args:[{name:"packages",required:false,description:"Package names to link from global (optional)"}],allowDynamicArgs:true,options:[],action:e=>{let t=[];e.args.packages&&t.push(e.args.packages),e.dynamicArgs&&e.dynamicArgs.length>0&&t.push(...e.dynamicArgs);let n={args:{},dynamicArgs:t.length>0?t:void 0,options:{}};this.runLinkCommand(n);}}).command({name:"unlink",description:"Unlink current package from global or unlink global packages from project",args:[{name:"packages",required:false,description:"Package names to unlink from project (optional)"}],allowDynamicArgs:true,options:[],action:e=>{let t=[];e.args.packages&&t.push(e.args.packages),e.dynamicArgs&&e.dynamicArgs.length>0&&t.push(...e.dynamicArgs);let n={args:{},dynamicArgs:t.length>0?t:void 0,options:{}};this.runUnlinkCommand(n);}}).command({name:"up",aliases:["update"],description:"Update all or specific packages",args:[{name:"packages",required:false,description:"Packages to update (e.g., lodash react)"}],allowDynamicArgs:true,options:[{name:"interactive",flag:"-i",aliases:["--interactive"],type:"boolean",required:false,description:"Interactive update mode"},{name:"latest",flag:"-l",aliases:["--latest"],type:"boolean",required:false,description:"Update to latest versions"}],action:e=>{let t={args:{},dynamicArgs:e.dynamicArgs,options:{interactive:e.options?.interactive,latest:e.options?.latest}};this.runUpdateCommand(t);}}).command({name:"publish",aliases:["pub"],description:"Publish package to npm registry",args:[],options:[{name:"tag",flag:"--tag",type:"string",required:false,description:"Publish under specific dist-tag (e.g., beta, next)"},{name:"public",flag:"-y",type:"boolean",required:false,description:"Public access (default)"}],action:e=>{let t={args:{},options:{tag:e.options?.tag,public:e.options?.public}};this.runPublishCommand(t);}}).command({name:"exec",description:"Execute TypeScript/JavaScript code directly",args:[{name:"code",required:true,description:"Code to execute"}],options:[],action:e=>{let t={args:{code:e.args.code},options:{}};this.runExecCommand(t);}}).command({name:"list",aliases:["ls"],description:"List installed packages (local or global)",args:[],options:[{name:"global",flag:"-g",aliases:["--global"],type:"boolean",required:false,description:"List global packages instead of local"}],action:e=>{let t={args:{},options:{global:e.options?.global}};this.runListCommand(t);}}).command({name:"version",aliases:["ver"],description:"Bump package version and update version badges",args:[{name:"type",required:false,description:"Bump type: major, minor, patch, or version string (e.g., 1.2.3)"}],options:[{name:"major",flag:"--major",type:"string",required:false,description:"Set major version"},{name:"minor",flag:"--minor",type:"string",required:false,description:"Set minor version"},{name:"patch",flag:"--patch",type:"string",required:false,description:"Set patch version"}],action:e=>{let t={args:{type:e.args.type},options:{major:e.options?.major,minor:e.options?.minor,patch:e.options?.patch}};this.runVersionCommand(t);}}).command({name:"fmt",aliases:[],description:"Format TypeScript and JSON files",args:[{name:"path",required:false,description:"Target file or directory (default: current directory)"}],options:[{name:"clean",flag:"--clean",aliases:["-c"],type:"boolean",required:false,description:"Clear the formatter cache before running"}],action:e=>{let t={args:{path:e.args.path},options:{clean:e.options?.clean}};this.runFmtCommand(t);}}).build().run();}runInitCommand(e){new K(e).run();}runBuildCommand(e){new G(e).run();}runTestCommand(e){new Y(e).run();}runLintCommand(e){new Z(e).run();}runInstallCommand(e){new M(e).run();}runUninstallCommand(e){new U(e).run();}runLinkCommand(e){new Q(e).run();}runUnlinkCommand(e){new W(e).run();}runUpdateCommand(e){new J(e).run();}runPublishCommand(e){new _(e).run();}runExecCommand(e){new X(e).run();}runListCommand(e){new ee(e).run();}runVersionCommand(e){new z(e).run();}runFmtCommand(e){new ne(e).run();}};var dt=new ie({name:"pkg",version:"0.0.1",desc:"Build, manage, publish, and test packages with zero configuration."});dt.run();
package/dist/index.js CHANGED
@@ -48,4 +48,4 @@ import C from'chalk';import Pe from'boxen';import ve from'ora';import*as P from'
48
48
  `);for(let a of c)!h(a)&&!y(a)&&a.trim()&&process.stderr.write(a+`
49
49
  `);}),n.on("close",r=>{s.nl(),t(),process.exit(r||0);}),n.on("error",r=>{s.error(`Failed to list packages: ${r.message}`),s.nl(),process.exit(1);});})}catch{return g("list")}}};var se=class{constructor(){this.cache=null;this.dirty=false;this.initialized=false;this.cacheDir=join(process.cwd(),".pkg"),this.cacheFile=join(this.cacheDir,"cache");}initialize(){try{if(existsSync(this.cacheDir)||mkdirSync(this.cacheDir,{recursive:!0}),existsSync(this.cacheFile))try{let e=readFileSync(this.cacheFile,"utf-8");this.cache=JSON.parse(e);}catch{this.cache=this.createNewCache(),this.dirty=!0;}else this.cache=this.createNewCache(),this.dirty=!0;this.initialized=!0;}catch{this.cache=this.createNewCache(),this.initialized=true;}}shouldFormat(e){if(!this.initialized||!this.cache)return true;let t=this.normalizePath(e);try{let n=readFileSync(e,"utf-8"),r=this.hashContent(n),c=this.cache.files[t];return c?c.hash!==r:!0}catch{return true}}markFormatted(e){if(!this.initialized||!this.cache)return;let t=this.normalizePath(e);try{let n=readFileSync(e,"utf-8"),r=this.hashContent(n);this.cache.files[t]={hash:r},this.dirty=!0;}catch{}}save(){if(!this.initialized||!this.cache||!this.dirty){this.dirty;return}try{existsSync(this.cacheDir)||mkdirSync(this.cacheDir,{recursive:!0}),this.cache.timestamp=Date.now();let e=this.formatCacheJson(this.cache);writeFileSync(this.cacheFile,e,"utf-8"),this.dirty=!1;}catch{}}formatCacheJson(e){let t={timestamp:e.timestamp,files:e.files},n=JSON.stringify(t,null,2);return n.endsWith(`
50
50
  `)||(n+=`
51
- `),n}clear(){this.initialized&&(this.cache=this.createNewCache(),this.dirty=true,this.save());}cleanup(){if(!this.initialized||!this.cache)return;let e=[],t=new Map;for(let n of Object.keys(this.cache.files))try{if(existsSync(n)){let r=this.normalizePath(n);t.has(r)?t.get(r)!==n&&e.push(n):t.set(r,n);}else {let r=!1;if(n.includes(":/")){let c="./"+n.split(/[\/\\]/).slice(-2).join("/");existsSync(c)&&(r=!0);}r||e.push(n);}}catch{}if(e.length>0){for(let n of e)delete this.cache.files[n];this.dirty=true,this.save();}}loadFromDisk(){try{if(existsSync(this.cacheFile)){let e=readFileSync(this.cacheFile,"utf-8");if(this.cache=JSON.parse(e),this.cache&&this.cache.files&&typeof this.cache.files=="object"){let t=!1,n={};for(let[r,c]of Object.entries(this.cache.files)){let a=r;a.startsWith("./")&&(a=a.substring(2),t=!0),n[a]=c;}t&&(this.cache.files=n,this.dirty=!0,this.save());}}}catch{}}hashContent(e){return createHash("sha256").update(e).digest("hex")}normalizePath(e){try{let t;return isAbsolute(e)?t=relative(process.cwd(),e):t=e,t=t.replace(/\\/g,"/"),t.startsWith("./")&&(t=t.substring(2)),t=t.replace(/\/+/g,"/"),t}catch{return e}}createNewCache(){return {timestamp:Date.now(),files:{}}}};var ne=class{constructor(e){this.params=e;}async run(){try{s.nl();let e=new se;e.initialize(),this.params.options?.clean&&e.clear();let t=resolve(isAbsolute(this.params.args.path||".")?this.params.args.path||".":this.params.args.path||".");if(!S(t)&&!A(t)){s.error(`Path not found: ${t}`),s.nl();return}let n=x(p.muted("Formatting files..."));n.start();let r=[],c=[],a=[];for(let d of ["src","test","bench"])A(d)&&this.collectTsFiles(d,r);S("eslint.config.mjs")&&r.push("eslint.config.mjs"),S("tsup.config.ts")&&r.push("tsup.config.ts"),S("README.md")&&a.push("README.md"),A("docs")&&be("docs",a);let l=0,o=new Set;for(let d of r)if(S(d))try{if(!e.shouldFormat(d))continue;let u=I(d),f=formatTS(u,d);if(f.errors?.length===0){e.markFormatted(d),T(d,f.formatted)&&(o.add(d),l+=f.count);continue}else f.errors?.forEach(b=>{s.warn(` ${d}:${b.line}:${b.column??0} - ${b.message}`);}),s.nl();}catch{}for(let d of c)if(S(d))try{let u=I(d);if(!e.shouldFormat(d))continue;let f=formatJSON(u,d);if(f.errors?.length===0){e.markFormatted(d),T(d,f.formatted)&&(o.add(d),l+=f.count);continue}else f.errors?.forEach(b=>{s.warn(` ${d}:${b.line}:${b.column??0} - ${b.message}`);}),s.nl();}catch{}for(let d of a)if(S(d))try{let u=I(d);if(!e.shouldFormat(d))continue;let f=formatMD(u,d);if(f.errors?.length===0){e.markFormatted(d),T(d,f.formatted)&&(o.add(d),l+=f.count);continue}else f.errors?.forEach(b=>{s.warn(` ${d}:${b.line}:${b.column??0} - ${b.message}`);}),s.nl();}catch{}let i=[];for(let d of ["src","test","bench"])A(d)&&i.push(...mt(d));if(n.stop(),l===0&&i.length===0){s.success("All files formatted correctly."),s.nl(),e.save();return}if(l>0&&s.success(`Fixed ${l} issue${l>1?"s":""} across ${o.size} file${o.size>1?"s":""}`),i.length>0){s.warn(`Found ${i.length} naming issue${i.length>1?"s":""} (not auto-fixable)`);for(let d of i.slice(0,5))s.info(` ${this.shortenPath(d.file)}:${d.line} ${d.message}`);i.length>5&&s.info(` ... and ${i.length-5} more`);}e.save(),s.nl();}catch{return g("fmt")}}collectTsFiles(e,t){try{let n=readdirSync(e,{withFileTypes:!0});for(let r of n){let c=join(e,r.name);r.isDirectory()&&!r.name.startsWith(".")?this.collectTsFiles(c,t):r.isFile()&&r.name.endsWith(".ts")&&t.push(c);}}catch{}}collectJsonFiles(e,t){try{let n=readdirSync(e,{withFileTypes:!0});for(let r of n){let c=join(e,r.name);r.isDirectory()&&!r.name.startsWith(".")?this.collectJsonFiles(c,t):r.isFile()&&r.name.endsWith(".json")&&t.push(c);}}catch{}}shortenPath(e){let t=e.replace(/\\/g,"/");for(let n of ["src","test","bench",".vscode"]){let r=t.indexOf(`/${n}/`);if(r!==-1)return t.substring(r+1)}return t}};function be(m,e){try{let t=readdirSync(m,{withFileTypes:!0});for(let n of t){let r=join(m,n.name);n.isDirectory()&&!n.name.startsWith(".")&&n.name!=="node_modules"?be(r,e):n.isFile()&&n.name.endsWith(".md")&&e.push(r);}}catch{}}function ct(m){return /^[a-z0-9_]+(\.[a-z0-9]+)?$/.test(m)}function lt(m){return /^[a-z0-9_-]+(\.[a-z0-9]+)?$/.test(m)}function mt(m){let e=[];try{let t=glob.sync(`${m}/**/*.ts`,{dot:!1});for(let n of t){let r=n.split(/[\\/]/).pop()??"",c=r.replace(/\.ts$/,"");lt(c)||e.push({file:n,line:1,code:"FILE_NAME_INVALID",message:`File name "${r}" must follow snake_case convention (e.g., my_file.ts)`,severity:"warning",fixable:!1});let a=n.split(/[\\/]/);for(let l=a.indexOf(m)+1;l<a.length-1;l++){let o=a[l];if(o&&!ct(o)){e.push({file:n,line:1,code:"FOLDER_NAME_INVALID",message:`Folder name "${o}" must follow snake_case convention (e.g., my_folder/)`,severity:"warning",fixable:!1});break}}}}catch{}return e}var ie=class{constructor(e){this.config=e;}run(){cli(this.config.name,this.config.version).description(this.config.desc).command({name:"init",description:"Initialize a new project",args:[{name:"name",required:false,description:"Package name (e.g. @org/repo or myrepo)"}],options:[{name:"as",flag:"--as",type:"string",required:false,description:"Project type: normal (library) or cli (executable)"},{name:"dir",flag:"--dir",type:"string",required:false,description:"Target directory to initialize in (skips creating a <name> subfolder)"},{name:"yes",flag:"-y",type:"boolean",required:false,description:"Skip all prompts and use defaults (requires <name> and --as to be passed)"}],action:e=>{let t={args:{name:e.args.name},options:{as:e.options?.as,dir:e.options?.dir,yes:e.options?.yes}};this.runInitCommand(t);}}).command({name:"build",description:"Build package with tsup",args:[],options:[{name:"watch",flag:"--watch",type:"boolean",required:false,description:"Watch mode"},{name:"clean",flag:"--clean",type:"boolean",required:false,description:"Remove dist/ before building"}],action:e=>{let t={args:{},options:{watch:e.options?.watch,clean:e.options?.clean}};this.runBuildCommand(t);}}).command({name:"test",description:"Run tests with bun test",args:[{name:"patterns",required:false,description:"Test file patterns (e.g., src/, file.test.ts)"}],allowDynamicArgs:true,options:[{name:"watch",flag:"--watch",type:"boolean",required:false,description:"Watch mode"},{name:"coverage",flag:"--coverage",type:"boolean",required:false,description:"Generate coverage report"},{name:"testNamePattern",flag:"-t",type:"string",required:false,description:"Filter tests by name pattern"},{name:"retry",flag:"--retry",type:"string",required:false,description:"Retry failed tests"},{name:"timeout",flag:"--timeout",type:"string",required:false,description:"Per-test timeout in milliseconds"},{name:"concurrent",flag:"--concurrent",type:"boolean",required:false,description:"Run tests in parallel"},{name:"bail",flag:"--bail",type:"string",required:false,description:"Bail after n failures (use --bail or --bail=2)"}],action:e=>{let t={args:{},dynamicArgs:e.dynamicArgs,options:{watch:e.options?.watch,coverage:e.options?.coverage,testNamePattern:e.options?.testNamePattern,retry:e.options?.retry?parseInt(e.options.retry):void 0,timeout:e.options?.timeout?parseInt(e.options.timeout):void 0,bail:e.options?.bail?e.options.bail==="true"||e.options.bail===""?true:parseInt(e.options.bail):void 0,concurrent:e.options?.concurrent}};this.runTestCommand(t);}}).command({name:"lint",description:"Lint code with eslint",args:[{name:"paths",required:false,description:"Paths to lint (defaults to src/ and test/)"}],allowDynamicArgs:true,options:[{name:"fix",flag:"--fix",type:"boolean",required:false,description:"Automatically fix violations"},{name:"fixDryRun",flag:"--fix-dry-run",type:"boolean",required:false,description:"Check fixes without writing"},{name:"format",flag:"--format",type:"string",required:false,description:"Output format: stylish, json, compact"},{name:"maxWarnings",flag:"--max-warnings",type:"string",required:false,description:"Fail if warnings exceed this number"},{name:"cache",flag:"--cache",type:"boolean",required:false,description:"Use cache for faster runs"},{name:"quiet",flag:"--quiet",type:"boolean",required:false,description:"Report errors only"}],action:e=>{let t={args:{},dynamicArgs:e.dynamicArgs,options:{fix:e.options?.fix,fixDryRun:e.options?.fixDryRun,format:e.options?.format,maxWarnings:e.options?.maxWarnings?parseInt(e.options.maxWarnings):void 0,cache:e.options?.cache,quiet:e.options?.quiet}};this.runLintCommand(t);}}).command({name:"i",aliases:["install"],description:"Install dependencies or add packages",args:[{name:"packages",required:false,description:"Packages to install (e.g., lodash react)"}],allowDynamicArgs:true,options:[{name:"dev",flag:"-D",aliases:["--dev"],type:"boolean",required:false,description:"Install as dev dependency"},{name:"peer",flag:"-p",aliases:["--peer"],type:"boolean",required:false,description:"Install as peer dependency"},{name:"exact",flag:"--exact",type:"boolean",required:false,description:"Use exact version instead of ranges"},{name:"global",flag:"-g",aliases:["--global"],type:"boolean",required:false,description:"Install globally instead of locally"}],action:e=>{let t=[];e.args?.packages&&(Array.isArray(e.args.packages)?t.push(...e.args.packages):typeof e.args.packages=="string"&&t.push(e.args.packages)),e.dynamicArgs&&e.dynamicArgs.length>0&&t.push(...e.dynamicArgs);let n={args:{},dynamicArgs:t,options:{dev:e.options?.dev,peer:e.options?.peer,exact:e.options?.exact,global:e.options?.global}};this.runInstallCommand(n);}}).command({name:"uninstall",aliases:["un"],description:"Uninstall packages from project or globally",args:[{name:"packages",required:false,description:"Package names to uninstall"}],allowDynamicArgs:true,options:[{name:"global",flag:"-g",aliases:["--global"],type:"boolean",required:false,description:"Uninstall globally instead of locally"}],action:e=>{let t=[];e.args?.packages&&(Array.isArray(e.args.packages)?t.push(...e.args.packages):typeof e.args.packages=="string"&&t.push(e.args.packages)),e.dynamicArgs&&e.dynamicArgs.length>0&&t.push(...e.dynamicArgs);let n={args:{},dynamicArgs:t,options:{global:e.options?.global}};this.runUninstallCommand(n);}}).command({name:"link",description:"Link current package globally or link global packages to project",args:[{name:"packages",required:false,description:"Package names to link from global (optional)"}],allowDynamicArgs:true,options:[],action:e=>{let t=[];e.args.packages&&t.push(e.args.packages),e.dynamicArgs&&e.dynamicArgs.length>0&&t.push(...e.dynamicArgs);let n={args:{},dynamicArgs:t.length>0?t:void 0,options:{}};this.runLinkCommand(n);}}).command({name:"unlink",description:"Unlink current package from global or unlink global packages from project",args:[{name:"packages",required:false,description:"Package names to unlink from project (optional)"}],allowDynamicArgs:true,options:[],action:e=>{let t=[];e.args.packages&&t.push(e.args.packages),e.dynamicArgs&&e.dynamicArgs.length>0&&t.push(...e.dynamicArgs);let n={args:{},dynamicArgs:t.length>0?t:void 0,options:{}};this.runUnlinkCommand(n);}}).command({name:"up",aliases:["update"],description:"Update all or specific packages",args:[{name:"packages",required:false,description:"Packages to update (e.g., lodash react)"}],allowDynamicArgs:true,options:[{name:"interactive",flag:"-i",aliases:["--interactive"],type:"boolean",required:false,description:"Interactive update mode"},{name:"latest",flag:"-l",aliases:["--latest"],type:"boolean",required:false,description:"Update to latest versions"}],action:e=>{let t={args:{},dynamicArgs:e.dynamicArgs,options:{interactive:e.options?.interactive,latest:e.options?.latest}};this.runUpdateCommand(t);}}).command({name:"publish",aliases:["pub"],description:"Publish package to npm registry",args:[],options:[{name:"tag",flag:"--tag",type:"string",required:false,description:"Publish under specific dist-tag (e.g., beta, next)"},{name:"public",flag:"-y",type:"boolean",required:false,description:"Public access (default)"}],action:e=>{let t={args:{},options:{tag:e.options?.tag,public:e.options?.public}};this.runPublishCommand(t);}}).command({name:"exec",description:"Execute TypeScript/JavaScript code directly",args:[{name:"code",required:true,description:"Code to execute"}],options:[],action:e=>{let t={args:{code:e.args.code},options:{}};this.runExecCommand(t);}}).command({name:"list",aliases:["ls"],description:"List installed packages (local or global)",args:[],options:[{name:"global",flag:"-g",aliases:["--global"],type:"boolean",required:false,description:"List global packages instead of local"}],action:e=>{let t={args:{},options:{global:e.options?.global}};this.runListCommand(t);}}).command({name:"version",aliases:["ver"],description:"Bump package version and update version badges",args:[{name:"type",required:false,description:"Bump type: major, minor, patch, or version string (e.g., 1.2.3)"}],options:[{name:"major",flag:"--major",type:"string",required:false,description:"Set major version"},{name:"minor",flag:"--minor",type:"string",required:false,description:"Set minor version"},{name:"patch",flag:"--patch",type:"string",required:false,description:"Set patch version"}],action:e=>{let t={args:{type:e.args.type},options:{major:e.options?.major,minor:e.options?.minor,patch:e.options?.patch}};this.runVersionCommand(t);}}).command({name:"fmt",aliases:[],description:"Format TypeScript and JSON files",args:[{name:"path",required:false,description:"Target file or directory (default: current directory)"}],options:[{name:"clean",flag:"--clean",aliases:["-c"],type:"boolean",required:false,description:"Clear the formatter cache before running"}],action:e=>{let t={args:{path:e.args.path},options:{clean:e.options?.clean}};this.runFmtCommand(t);}}).build().run();}runInitCommand(e){new K(e).run();}runBuildCommand(e){new G(e).run();}runTestCommand(e){new Y(e).run();}runLintCommand(e){new Z(e).run();}runInstallCommand(e){new M(e).run();}runUninstallCommand(e){new U(e).run();}runLinkCommand(e){new Q(e).run();}runUnlinkCommand(e){new W(e).run();}runUpdateCommand(e){new J(e).run();}runPublishCommand(e){new _(e).run();}runExecCommand(e){new X(e).run();}runListCommand(e){new ee(e).run();}runVersionCommand(e){new z(e).run();}runFmtCommand(e){new ne(e).run();}};var dt=new ie({name:"pkg",version:"0.0.1",desc:"Build, manage, publish, and test packages with zero configuration."});dt.run();
51
+ `),n}clear(){this.initialized&&(this.cache=this.createNewCache(),this.dirty=true,this.save());}cleanup(){if(!this.initialized||!this.cache)return;let e=[],t=new Map;for(let n of Object.keys(this.cache.files))try{if(existsSync(n)){let r=this.normalizePath(n);t.has(r)?t.get(r)!==n&&e.push(n):t.set(r,n);}else {let r=!1;if(n.includes(":/")){let c="./"+n.split(/[\/\\]/).slice(-2).join("/");existsSync(c)&&(r=!0);}r||e.push(n);}}catch{}if(e.length>0){for(let n of e)delete this.cache.files[n];this.dirty=true,this.save();}}loadFromDisk(){try{if(existsSync(this.cacheFile)){let e=readFileSync(this.cacheFile,"utf-8");if(this.cache=JSON.parse(e),this.cache&&this.cache.files&&typeof this.cache.files=="object"){let t=!1,n={};for(let[r,c]of Object.entries(this.cache.files)){let a=r;a.startsWith("./")&&(a=a.substring(2),t=!0),n[a]=c;}t&&(this.cache.files=n,this.dirty=!0,this.save());}}}catch{}}hashContent(e){return createHash("sha256").update(e).digest("hex")}normalizePath(e){try{let t;return isAbsolute(e)?t=relative(process.cwd(),e):t=e,t=t.replace(/\\/g,"/"),t.startsWith("./")&&(t=t.substring(2)),t=t.replace(/\/+/g,"/"),t}catch{return e}}createNewCache(){return {timestamp:Date.now(),files:{}}}};var ne=class{constructor(e){this.params=e;}async run(){try{s.nl();let e=new se;e.initialize(),this.params.options?.clean&&e.clear();let t=resolve(isAbsolute(this.params.args.path||".")?this.params.args.path||".":this.params.args.path||".");if(!S(t)&&!A(t)){s.error(`Path not found: ${t}`),s.nl();return}let n=x(p.muted("Formatting files..."));n.start();let r=[],c=[],a=[];for(let d of ["src","test","bench"])A(d)&&this.collectTsFiles(d,r);S("eslint.config.mjs")&&r.push("eslint.config.mjs"),S("tsup.config.ts")&&r.push("tsup.config.ts"),S("README.md")&&a.push("README.md"),A("docs")&&be("docs",a);let l=0,o=new Set;for(let d of r)if(S(d))try{if(!e.shouldFormat(d))continue;let u=I(d),f=formatTS(u,d);if(f.errors?.length===0){e.markFormatted(d),T(d,f.formatted)&&(o.add(d),l+=f.count);continue}else f.errors?.forEach(b=>{s.warn(` ${d}:${b.line}:${b.column??0} - ${b.message}`);}),s.nl();}catch{}for(let d of c)if(S(d))try{let u=I(d);if(!e.shouldFormat(d))continue;let f=formatJSON(u,d);if(f.errors?.length===0){e.markFormatted(d),T(d,f.formatted)&&(o.add(d),l+=f.count);continue}else f.errors?.forEach(b=>{s.warn(` ${d}:${b.line}:${b.column??0} - ${b.message}`);}),s.nl();}catch{}for(let d of a)if(S(d))try{let u=I(d);if(!e.shouldFormat(d))continue;let f=formatMD(u,d);if(f.errors?.length===0){e.markFormatted(d),T(d,f.formatted)&&(o.add(d),l+=f.count);continue}else f.errors?.forEach(b=>{s.warn(` ${d}:${b.line}:${b.column??0} - ${b.message}`);}),s.nl();}catch{}let i=[];for(let d of ["src","test","bench"])A(d)&&i.push(...mt(d));if(n.stop(),l===0&&i.length===0){s.success("All files formatted correctly."),s.nl(),e.save();return}if(l>0&&s.success(`Fixed ${l} issue${l>1?"s":""} across ${o.size} file${o.size>1?"s":""}`),i.length>0){s.warn(`Found ${i.length} naming issue${i.length>1?"s":""} (not auto-fixable)`);for(let d of i.slice(0,5))s.info(` ${this.shortenPath(d.file)}:${d.line} ${d.message}`);i.length>5&&s.info(` ... and ${i.length-5} more`);}e.save(),s.nl();}catch{return g("fmt")}}collectTsFiles(e,t){try{let n=readdirSync(e,{withFileTypes:!0});for(let r of n){let c=join(e,r.name);r.isDirectory()&&!r.name.startsWith(".")?this.collectTsFiles(c,t):r.isFile()&&r.name.endsWith(".ts")&&t.push(c);}}catch{}}collectJsonFiles(e,t){try{let n=readdirSync(e,{withFileTypes:!0});for(let r of n){let c=join(e,r.name);r.isDirectory()&&!r.name.startsWith(".")?this.collectJsonFiles(c,t):r.isFile()&&r.name.endsWith(".json")&&t.push(c);}}catch{}}shortenPath(e){let t=e.replace(/\\/g,"/");for(let n of ["src","test","bench",".vscode"]){let r=t.indexOf(`/${n}/`);if(r!==-1)return t.substring(r+1)}return t}};function be(m,e){try{let t=readdirSync(m,{withFileTypes:!0});for(let n of t){let r=join(m,n.name);n.isDirectory()&&!n.name.startsWith(".")&&n.name!=="node_modules"?be(r,e):n.isFile()&&n.name.endsWith(".md")&&e.push(r);}}catch{}}function ct(m){return /^[a-z0-9_]+(\.[a-z0-9]+)?$/.test(m)}function lt(m){return /^[a-z0-9_-]+(\.[a-z0-9]+)?$/.test(m)}function mt(m){let e=[];try{let t=glob.sync(`${m}/**/*.ts`,{dot:!1});for(let n of t){let r=n.split(/[\\/]/).pop()??"",c=r.replace(/\.ts$/,"");lt(c)||e.push({file:n,line:1,code:"FILE_NAME_INVALID",message:`File name "${r}" must follow snake_case convention (e.g., my_file.ts)`,severity:"warning",fixable:!1});let a=n.split(/[\\/]/);for(let l=a.indexOf(m)+1;l<a.length-1;l++){let o=a[l];if(o&&!ct(o)){e.push({file:n,line:1,code:"FOLDER_NAME_INVALID",message:`Folder name "${o}" must follow snake_case convention (e.g., my_folder/)`,severity:"warning",fixable:!1});break}}}}catch{}return e}var ie=class{constructor(e){this.config=e;}run(){cli(this.config.name,this.config.version).description(this.config.desc).command({name:"init",description:"Initialize a new project",args:[{name:"name",required:false,description:"Package name (e.g. @org/repo or myrepo)"}],options:[{name:"as",flag:"--as",type:"string",required:false,description:"Project type: normal (library) or cli (executable)"},{name:"dir",flag:"--dir",type:"string",required:false,description:"Target directory to initialize in (skips creating a <name> subfolder)"},{name:"yes",flag:"-y",type:"boolean",required:false,description:"Skip all prompts and use defaults (requires <name> and --as to be passed)"}],action:e=>{let t={args:{name:e.args.name},options:{as:e.options?.as,dir:e.options?.dir,yes:e.options?.yes}};this.runInitCommand(t);}}).command({name:"build",description:"Build package with tsup",args:[],options:[{name:"watch",flag:"--watch",type:"boolean",required:false,description:"Watch mode"},{name:"clean",flag:"--clean",type:"boolean",required:false,description:"Remove dist/ before building"}],action:e=>{let t={args:{},options:{watch:e.options?.watch,clean:e.options?.clean}};this.runBuildCommand(t);}}).command({name:"test",description:"Run tests with bun test",allowDynamicArgs:true,options:[{name:"watch",flag:"--watch",type:"boolean",required:false,description:"Watch mode"},{name:"coverage",flag:"--coverage",type:"boolean",required:false,description:"Generate coverage report"},{name:"testNamePattern",flag:"-t",type:"string",required:false,description:"Filter tests by name pattern"},{name:"retry",flag:"--retry",type:"string",required:false,description:"Retry failed tests"},{name:"timeout",flag:"--timeout",type:"string",required:false,description:"Per-test timeout in milliseconds"},{name:"concurrent",flag:"--concurrent",type:"boolean",required:false,description:"Run tests in parallel"},{name:"bail",flag:"--bail",type:"string",required:false,description:"Bail after n failures (use --bail or --bail=2)"}],action:e=>{let t={args:{},dynamicArgs:e.dynamicArgs,options:{watch:e.options?.watch,coverage:e.options?.coverage,testNamePattern:e.options?.testNamePattern,retry:e.options?.retry?parseInt(e.options.retry):void 0,timeout:e.options?.timeout?parseInt(e.options.timeout):void 0,bail:e.options?.bail?e.options.bail==="true"||e.options.bail===""?true:parseInt(e.options.bail):void 0,concurrent:e.options?.concurrent}};this.runTestCommand(t);}}).command({name:"lint",description:"Lint code with eslint",args:[{name:"paths",required:false,description:"Paths to lint (defaults to src/ and test/)"}],allowDynamicArgs:true,options:[{name:"fix",flag:"--fix",type:"boolean",required:false,description:"Automatically fix violations"},{name:"fixDryRun",flag:"--fix-dry-run",type:"boolean",required:false,description:"Check fixes without writing"},{name:"format",flag:"--format",type:"string",required:false,description:"Output format: stylish, json, compact"},{name:"maxWarnings",flag:"--max-warnings",type:"string",required:false,description:"Fail if warnings exceed this number"},{name:"cache",flag:"--cache",type:"boolean",required:false,description:"Use cache for faster runs"},{name:"quiet",flag:"--quiet",type:"boolean",required:false,description:"Report errors only"}],action:e=>{let t={args:{},dynamicArgs:e.dynamicArgs,options:{fix:e.options?.fix,fixDryRun:e.options?.fixDryRun,format:e.options?.format,maxWarnings:e.options?.maxWarnings?parseInt(e.options.maxWarnings):void 0,cache:e.options?.cache,quiet:e.options?.quiet}};this.runLintCommand(t);}}).command({name:"i",aliases:["install"],description:"Install dependencies or add packages",args:[{name:"packages",required:false,description:"Packages to install (e.g., lodash react)"}],allowDynamicArgs:true,options:[{name:"dev",flag:"-D",aliases:["--dev"],type:"boolean",required:false,description:"Install as dev dependency"},{name:"peer",flag:"-p",aliases:["--peer"],type:"boolean",required:false,description:"Install as peer dependency"},{name:"exact",flag:"--exact",type:"boolean",required:false,description:"Use exact version instead of ranges"},{name:"global",flag:"-g",aliases:["--global"],type:"boolean",required:false,description:"Install globally instead of locally"}],action:e=>{let t=[];e.args?.packages&&(Array.isArray(e.args.packages)?t.push(...e.args.packages):typeof e.args.packages=="string"&&t.push(e.args.packages)),e.dynamicArgs&&e.dynamicArgs.length>0&&t.push(...e.dynamicArgs);let n={args:{},dynamicArgs:t,options:{dev:e.options?.dev,peer:e.options?.peer,exact:e.options?.exact,global:e.options?.global}};this.runInstallCommand(n);}}).command({name:"uninstall",aliases:["un"],description:"Uninstall packages from project or globally",args:[{name:"packages",required:false,description:"Package names to uninstall"}],allowDynamicArgs:true,options:[{name:"global",flag:"-g",aliases:["--global"],type:"boolean",required:false,description:"Uninstall globally instead of locally"}],action:e=>{let t=[];e.args?.packages&&(Array.isArray(e.args.packages)?t.push(...e.args.packages):typeof e.args.packages=="string"&&t.push(e.args.packages)),e.dynamicArgs&&e.dynamicArgs.length>0&&t.push(...e.dynamicArgs);let n={args:{},dynamicArgs:t,options:{global:e.options?.global}};this.runUninstallCommand(n);}}).command({name:"link",description:"Link current package globally or link global packages to project",args:[{name:"packages",required:false,description:"Package names to link from global (optional)"}],allowDynamicArgs:true,options:[],action:e=>{let t=[];e.args.packages&&t.push(e.args.packages),e.dynamicArgs&&e.dynamicArgs.length>0&&t.push(...e.dynamicArgs);let n={args:{},dynamicArgs:t.length>0?t:void 0,options:{}};this.runLinkCommand(n);}}).command({name:"unlink",description:"Unlink current package from global or unlink global packages from project",args:[{name:"packages",required:false,description:"Package names to unlink from project (optional)"}],allowDynamicArgs:true,options:[],action:e=>{let t=[];e.args.packages&&t.push(e.args.packages),e.dynamicArgs&&e.dynamicArgs.length>0&&t.push(...e.dynamicArgs);let n={args:{},dynamicArgs:t.length>0?t:void 0,options:{}};this.runUnlinkCommand(n);}}).command({name:"up",aliases:["update"],description:"Update all or specific packages",args:[{name:"packages",required:false,description:"Packages to update (e.g., lodash react)"}],allowDynamicArgs:true,options:[{name:"interactive",flag:"-i",aliases:["--interactive"],type:"boolean",required:false,description:"Interactive update mode"},{name:"latest",flag:"-l",aliases:["--latest"],type:"boolean",required:false,description:"Update to latest versions"}],action:e=>{let t={args:{},dynamicArgs:e.dynamicArgs,options:{interactive:e.options?.interactive,latest:e.options?.latest}};this.runUpdateCommand(t);}}).command({name:"publish",aliases:["pub"],description:"Publish package to npm registry",args:[],options:[{name:"tag",flag:"--tag",type:"string",required:false,description:"Publish under specific dist-tag (e.g., beta, next)"},{name:"public",flag:"-y",type:"boolean",required:false,description:"Public access (default)"}],action:e=>{let t={args:{},options:{tag:e.options?.tag,public:e.options?.public}};this.runPublishCommand(t);}}).command({name:"exec",description:"Execute TypeScript/JavaScript code directly",args:[{name:"code",required:true,description:"Code to execute"}],options:[],action:e=>{let t={args:{code:e.args.code},options:{}};this.runExecCommand(t);}}).command({name:"list",aliases:["ls"],description:"List installed packages (local or global)",args:[],options:[{name:"global",flag:"-g",aliases:["--global"],type:"boolean",required:false,description:"List global packages instead of local"}],action:e=>{let t={args:{},options:{global:e.options?.global}};this.runListCommand(t);}}).command({name:"version",aliases:["ver"],description:"Bump package version and update version badges",args:[{name:"type",required:false,description:"Bump type: major, minor, patch, or version string (e.g., 1.2.3)"}],options:[{name:"major",flag:"--major",type:"string",required:false,description:"Set major version"},{name:"minor",flag:"--minor",type:"string",required:false,description:"Set minor version"},{name:"patch",flag:"--patch",type:"string",required:false,description:"Set patch version"}],action:e=>{let t={args:{type:e.args.type},options:{major:e.options?.major,minor:e.options?.minor,patch:e.options?.patch}};this.runVersionCommand(t);}}).command({name:"fmt",aliases:[],description:"Format TypeScript and JSON files",args:[{name:"path",required:false,description:"Target file or directory (default: current directory)"}],options:[{name:"clean",flag:"--clean",aliases:["-c"],type:"boolean",required:false,description:"Clear the formatter cache before running"}],action:e=>{let t={args:{path:e.args.path},options:{clean:e.options?.clean}};this.runFmtCommand(t);}}).build().run();}runInitCommand(e){new K(e).run();}runBuildCommand(e){new G(e).run();}runTestCommand(e){new Y(e).run();}runLintCommand(e){new Z(e).run();}runInstallCommand(e){new M(e).run();}runUninstallCommand(e){new U(e).run();}runLinkCommand(e){new Q(e).run();}runUnlinkCommand(e){new W(e).run();}runUpdateCommand(e){new J(e).run();}runPublishCommand(e){new _(e).run();}runExecCommand(e){new X(e).run();}runListCommand(e){new ee(e).run();}runVersionCommand(e){new z(e).run();}runFmtCommand(e){new ne(e).run();}};var dt=new ie({name:"pkg",version:"0.0.1",desc:"Build, manage, publish, and test packages with zero configuration."});dt.run();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langpkg/pkg",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "Creates and manages packages",
5
5
  "keywords": ["langpkg", "pkg", "framework"],
6
6
  "license": "MIT",