gitpick 4.1.1 → 4.2.0-canary.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -35,12 +35,12 @@ npx gitpick <url/shorthand> [target] [options]
35
35
  Examples:
36
36
 
37
37
  ```sh
38
- npx gitpick https://github.com/TanStack/router # repository without .git
38
+ npx gitpick https://github.com/TanStack/router # repo without .git
39
39
  npx gitpick TanStack/router/tree/main/examples # a folder
40
40
  npx gitpick TanStack/router/tree/main/package.json # a file
41
41
 
42
42
  npx gitpick <url/shorthand> # default git behavior
43
- npx gitpick <url/shorthand> [target] # target is optional
43
+ npx gitpick <url/shorthand> [target] # with optional target
44
44
  npx gitpick <url/shorthand> -b [branch] # a branch
45
45
  npx gitpick <url/shorthand> -o # overwrite if exists
46
46
  npx gitpick <url/shorthand> -r # clone submodules
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ var vt=Object.defineProperty,kt=Object.defineProperties;var Et=Object.getOwnProp
3
3
  for await (const line of spawn(...)) { ... }`);e.isIterating=!0;try{let{[r]:l}=yield new y(t.nodeChildProcess);if(!l)return;let u="";try{for(var i=S(l.iterator({destroyOnReturn:!1})),a,c,p;a=!(c=yield new y(i.next())).done;a=!1){let w=c.value;let m=`${u}${w}`.split(/\r?\n/);u=m.pop(),yield*q(m)}}catch(c){p=[c]}finally{try{a&&(c=i.return)&&(yield new y(c.call(i)))}finally{if(p)throw p[0]}}u&&(yield u)}finally{yield new y(t)}})},Q=function(...t){return F(this,null,function*(){try{let e=[];for(;t.length>0;){e=t.map((i,a)=>{var c;return(c=e[a])!=null?c:It(i)});let[{value:r,done:o},n]=yield new y(Promise.race(e.map((i,a)=>Promise.all([i,a])))),[s]=t.splice(n,1);e.splice(n,1),o||(t.push(s),yield r)}}finally{yield new y(Promise.all(t.map(e=>e.return())))}})},It=async t=>{try{return await t.next()}catch(e){await t.throw(e)}};import k from"node:path";import Y from"node:process";import{fileURLToPath as Rt}from"node:url";var Z=c=>{var p=c,{stdin:t,stdout:e,stderr:r,stdio:o=[t,e,r],env:n,preferLocal:s,cwd:i="."}=p,a=D(p,["stdin","stdout","stderr","stdio","env","preferLocal","cwd"]);var m;let l=i instanceof URL?Rt(i):k.resolve(i),u=n?g(g({},Y.env),n):void 0,w=(m=o[0])==null?void 0:m.string;return b(g({},a),{input:w,stdio:w===void 0?o:["pipe",...o.slice(1)],env:s?At(u!=null?u:Y.env,l):u,cwd:l})},At=(n,o)=>{var s=n,{Path:t="",PATH:e=t}=s,r=D(s,["Path","PATH"]);let i=e.split(k.delimiter),a=X([],k.resolve(o)).map(c=>k.join(c,"node_modules/.bin")).filter(c=>!i.includes(c));return b(g({},r),{PATH:[...a,e].filter(Boolean).join(k.delimiter)})},X=(t,e)=>t.at(-1)===e?t:X([...t,e],k.resolve(e,".."));import{pipeline as Tt}from"node:stream/promises";var tt=async t=>{var o;let[[e,r]]=await Promise.all([Promise.allSettled(t),Dt(t)]);if(r.reason)throw r.reason.pipedFrom=(o=e.reason)!=null?o:e.value,r.reason;if(e.reason)throw e.reason;return b(g({},r.value),{pipedFrom:e.value})},Dt=async t=>{try{let[{stdout:e},{stdin:r}]=await Promise.all(t.map(({nodeChildProcess:o})=>o));if(r===null)throw new Error('The "stdin" option must be set on the first "spawn()" call in the pipeline.');if(e===null)throw new Error('The "stdout" option must be set on the last "spawn()" call in the pipeline.');Tt(e,r).catch(()=>{})}catch(e){throw await Promise.allSettled(t.map(({nodeChildProcess:r})=>Ft(r))),e}},Ft=async t=>{let{stdin:e}=await t;e.end()};import{on as Ot,once as Bt}from"node:events";import Lt from"node:process";var et=async(t,{input:e},r)=>{let o=await t;e!==void 0&&o.stdin.end(e);let n=Bt(o,"close");try{return await Promise.race([n,...o.stdio.filter(Boolean).map(s=>Ut(s))]),Wt(r,rt(o)),ot(r)}catch(s){throw await Promise.allSettled([n]),W(s,o,r)}},Ut=async t=>{try{for(var e=S(Ot(t,"error")),r,o,n;r=!(o=await e.next()).done;r=!1){let[s]=o.value;if(!["ERR_STREAM_PREMATURE_CLOSE","EPIPE"].includes(s==null?void 0:s.code))throw s}}catch(o){n=[o]}finally{try{r&&(o=e.return)&&await o.call(e)}finally{if(n)throw n[0]}}},Wt=({command:t},{exitCode:e,signalName:r})=>{if(r!==void 0)throw new $(`Command was terminated with ${r}: ${t}`);if(e!==void 0)throw new $(`Command failed with exit code ${e}: ${t}`)},W=(t,e,r)=>Object.assign(Mt(t,r),rt(e),ot(r)),Mt=(t,{command:e})=>t instanceof $?t:new $(`Command failed: ${e}`,{cause:t}),$=class extends Error{constructor(){super(...arguments);V(this,"name","SubprocessError")}},rt=({exitCode:t,signalCode:e})=>g(g({},t<1?{}:{exitCode:t}),e===null?{}:{signalName:e}),ot=({state:{stdout:t,stderr:e,output:r},command:o,start:n})=>({stdout:U(t),stderr:U(e),output:U(r),command:o,durationMs:Number(Lt.hrtime.bigint()-n)/1e6}),U=t=>t.at(-1)===`
4
4
  `?t.slice(0,t.at(-2)==="\r"?-2:-1):t;import{spawn as Vt}from"node:child_process";import{once as qt}from"node:events";import ct from"node:process";import{stat as Gt}from"node:fs/promises";import st from"node:path";import nt from"node:process";var it=async(t,e,r)=>await Ht(t,r)?[G(t),e.map(o=>Jt(o)),b(g({},r),{shell:!0})]:[t,e,r],Ht=async(t,{shell:e,cwd:r,env:o=nt.env})=>nt.platform==="win32"&&!e&&!await Nt(t,r,o),Nt=async(t,e,{Path:r="",PATH:o=r})=>{var n,s;return at.some(i=>t.toLowerCase().endsWith(i))||((s=M[n=`${t}\0${e}\0${o}`])!=null?s:M[n]=await _t(t,e,o))},M={},_t=async(t,e,r)=>{let o=r.split(st.delimiter).filter(Boolean).map(n=>n.replace(/^"(.*)"$/,"$1"));try{await Promise.all(at.flatMap(n=>[e,...o].map(s=>`${st.resolve(s,t)}${n}`)).map(async n=>{try{await Gt(n)}catch(s){return}throw 0}))}catch(n){return!0}return!1},at=[".exe",".com"],Jt=t=>G(G(`"${t.replaceAll(/(\\*)"/g,'$1$1\\"').replace(/(\\*)$/,"$1$1")}"`)),G=t=>t.replaceAll(/([()\][%!^"`<>&|;, *?])/g,"^$1");var lt=async(t,e,r,o)=>{try{[t,e]=["node","node.exe"].includes(t.toLowerCase())?[ct.execPath,[...ct.execArgv.filter(s=>!s.startsWith("--inspect")),...e]]:[t,e];let n=Vt(...await it(t,e,r));return pt(n.stdout,o,"stdout"),pt(n.stderr,o,"stderr"),n.once("error",()=>{}),await qt(n,"spawn"),n}catch(n){throw W(n,{},o)}},pt=(t,{state:e},r)=>{t&&(t.setEncoding("utf8"),e.isIterating||(e.isIterating=!1,t.on("data",o=>{e[r]+=o,e.output+=o})))};function x(t,e,r,o){let[n=[],s={}]=Array.isArray(e)?[e,r]:[[],e],i=K([t,...n]),a=Z(s),c=lt(t,n,a,i),p=et(c,a,i);Object.assign(p,{nodeChildProcess:c}),p=o?tt([o,p]):p;let l=L(p,i,"stdout"),u=L(p,i,"stderr");return Object.assign(p,{nodeChildProcess:c,stdout:l,stderr:u,[Symbol.asyncIterator]:()=>Q(l,u),pipe:(w,m,P)=>x(w,m,P,p)})}var I=async(t,e,r)=>{process.platform==="win32"&&await x("git",["config","--global","core.longpaths","true"]);let o=`https://${t.token?t.token+"@":t.token}github.com/${t.owner}/${t.repository}.git`,n=mt.join(zt.tmpdir(),`${t.repository}-${Date.now()}${Math.random().toString(16).slice(2,6)}`);e.watch||console.log(`
5
5
  \u{1F50D} Picking ${t.type}${t.type==="repository"?" without .git":" from repository"} ...`);let s=performance.now();await x("git",["clone",o,n,"--branch",t.branch,"--depth","1","--single-branch",...e.recursive?["--recursive"]:[]]);let i=mt.join(n,t.path);(await E.promises.stat(i)).isDirectory()?(await E.promises.mkdir(r,{recursive:!0}),await B(i,r)):(await E.promises.mkdir(r,{recursive:!0}),await E.promises.copyFile(i,r+"/"+t.path.split("/").pop())),e.watch?console.log("- Synced at "+new Date().toLocaleTimeString()):console.log(`
6
- \u{1F389} Picked ${t.type}${t.type==="repository"?" without .git":" from repository"} in ${((performance.now()-s)/1e3).toFixed(2)} seconds!`),await E.promises.rm(n,{recursive:!0,force:!0})};import Kt from"node:tty";var ht,ut,R,dt,ft,Qt=(ft=(dt=(R=(ut=(ht=Kt)==null?void 0:ht.WriteStream)==null?void 0:ut.prototype)==null?void 0:R.hasColors)==null?void 0:dt.call(R))!=null?ft:!1,h=(t,e)=>{if(!Qt)return n=>n;let r=`\x1B[${t}m`,o=`\x1B[${e}m`;return n=>{let s=n+"",i=s.indexOf(o);if(i===-1)return r+s+o;let a=r,c=0;for(;i!==-1;)a+=s.slice(c,i)+r,c=i+o.length,i=s.indexOf(o,c);return a+=s.slice(c)+o,a}},Ke=h(0,0),d=h(1,22),Qe=h(2,22),Ye=h(3,23),Ze=h(4,24),Xe=h(53,55),tr=h(7,27),er=h(8,28),rr=h(9,29),or=h(30,39),H=h(31,39),A=h(32,39),j=h(33,39),sr=h(34,39),nr=h(35,39),f=h(36,39),ir=h(37,39),ar=h(90,39);function N(t){if(typeof t=="number"||/^\d+$/.test(t))return typeof t=="number"?t:parseInt(t,10);let e=/(\d+)([hms])/g,r=0,o;for(;(o=e.exec(t))!==null;){let n=parseInt(o[1],10);switch(o[2]){case"h":r+=n*36e5;break;case"m":r+=n*6e4;break;case"s":r+=n*1e3;break}}return r}var gt=async t=>{var n,s;let e=(await x("git",["ls-remote",t])).stdout,r=(n=e.match(/(.+)\s+HEAD/))==null?void 0:n[1],o=(s=e.match(new RegExp(`${r}\\s+refs/heads/(.+)`)))==null?void 0:s[1];if(!o)throw new Error("Could not determine default branch!");return o};async function wt(t,{branch:e,target:r}){let o=/^https:\/\/([^@]+)@github\.com/,n=t.match(o),s="";n&&(s=n[1],t=t.replace(o,"https://github.com"));let i=["git@github.com:","https://github.com/","https://raw.githubusercontent.com/"];for(let P of i)if(t.startsWith(P)){t=t.replace(P,"");break}let a=t.split("/"),c=a[0],p=a[1].endsWith(".git")?a[1].slice(0,-4):a[1],l=a[2]==="blob"?"blob":a[2]==="tree"?"tree":a[2]+a[3]==="refsheads"?"raw":"repository",u=e||(l==="repository"?await gt(`https://${s&&s+"@"}github.com/${c}/${p}`):l==="raw"?a[4]:a[3]),w=l?l==="raw"?a.slice(5).join("/"):a.slice(4).join("/"):a.slice(2).join("/")||"/",m=r||(l==="blob"?".":w.split("/").pop()||p);return{token:s,owner:c,repository:p,type:l,branch:u,path:w,target:m}}var bt="gitpick",$t="4.1.1";var Xt=`
6
+ \u{1F389} Picked ${t.type}${t.type==="repository"?" without .git":" from repository"} in ${((performance.now()-s)/1e3).toFixed(2)} seconds!`),await E.promises.rm(n,{recursive:!0,force:!0})};import Kt from"node:tty";var ht,ut,R,dt,ft,Qt=(ft=(dt=(R=(ut=(ht=Kt)==null?void 0:ht.WriteStream)==null?void 0:ut.prototype)==null?void 0:R.hasColors)==null?void 0:dt.call(R))!=null?ft:!1,h=(t,e)=>{if(!Qt)return n=>n;let r=`\x1B[${t}m`,o=`\x1B[${e}m`;return n=>{let s=n+"",i=s.indexOf(o);if(i===-1)return r+s+o;let a=r,c=0;for(;i!==-1;)a+=s.slice(c,i)+r,c=i+o.length,i=s.indexOf(o,c);return a+=s.slice(c)+o,a}},Ke=h(0,0),d=h(1,22),Qe=h(2,22),Ye=h(3,23),Ze=h(4,24),Xe=h(53,55),tr=h(7,27),er=h(8,28),rr=h(9,29),or=h(30,39),H=h(31,39),A=h(32,39),j=h(33,39),sr=h(34,39),nr=h(35,39),f=h(36,39),ir=h(37,39),ar=h(90,39);function N(t){if(typeof t=="number"||/^\d+$/.test(t))return typeof t=="number"?t:parseInt(t,10);let e=/(\d+)([hms])/g,r=0,o;for(;(o=e.exec(t))!==null;){let n=parseInt(o[1],10);switch(o[2]){case"h":r+=n*36e5;break;case"m":r+=n*6e4;break;case"s":r+=n*1e3;break}}return r}var gt=async t=>{var n,s;let e=(await x("git",["ls-remote",t])).stdout,r=(n=e.match(/(.+)\s+HEAD/))==null?void 0:n[1],o=(s=e.match(new RegExp(`${r}\\s+refs/heads/(.+)`)))==null?void 0:s[1];if(!o)throw new Error("Could not determine default branch!");return o};async function wt(t,{branch:e,target:r}){let o=/^https:\/\/([^@]+)@github\.com/,n=t.match(o),s="";n&&(s=n[1],t=t.replace(o,"https://github.com"));let i=["git@github.com:","https://github.com/","https://raw.githubusercontent.com/"];for(let P of i)if(t.startsWith(P)){t=t.replace(P,"");break}let a=t.split("/"),c=a[0],p=a[1].endsWith(".git")?a[1].slice(0,-4):a[1],l=a[2]==="blob"?"blob":a[2]==="tree"?"tree":a[2]+a[3]==="refsheads"?"raw":"repository",u=e||(l==="repository"?await gt(`https://${s&&s+"@"}github.com/${c}/${p}`):l==="raw"?a[4]:a[3]),w=l?l==="raw"?a.slice(5).join("/"):a.slice(4).join("/"):a.slice(2).join("/")||"/",m=r||(l==="blob"?".":w.split("/").pop()||p);return{token:s,owner:c,repository:p,type:l,branch:u,path:w,target:m}}var bt="gitpick",$t="4.2.0-canary.1";var Xt=`
7
7
  ${d("With GitPick, you can clone precisely what you need.")}
8
8
 
9
9
  ${d("gitpick")} ${j("<url>")} ${A("[target]")} ${f("[options]")}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gitpick",
3
- "version": "4.1.1",
3
+ "version": "4.2.0-canary.1",
4
4
  "description": "Clone exactly what you need aka straightforward project scaffolding",
5
5
  "keywords": [
6
6
  "clone",