🚀 Big News:Socket Has Acquired Secure Annex.Learn More
Socket
Book a DemoSign in
Socket

@alessiofrittoli/node-scripts

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@alessiofrittoli/node-scripts - npm Package Compare versions

Comparing version
3.3.0
to
3.4.0
+15
-6
dist/index.d.mts

@@ -6,2 +6,3 @@ import { ParsedPath } from 'path';

export { Release } from './types.mjs';
import * as _alessiofrittoli_web_utils from '@alessiofrittoli/web-utils';

@@ -176,2 +177,11 @@ declare const FileSystem: {

declare const popStashByIndex: (index: number) => NonSharedBuffer;
/**
* Get git diff and optionally write `patch` file.
*
* Options can also be passed via process arguments, which are merged with the provided options.
*
* @param options An object defining custom options. See {@link Git.Diff.Options}.
* @returns The `git diff` output as a Buffer.
*/
declare const patchDiffToFile: (options?: Git.Diff.Options) => NonSharedBuffer;

@@ -240,11 +250,10 @@ /**

* - If the next argument does not start with a hyphen, it is considered the value for the current option key.
* - If the next argument does start with a hyphen, the current option key is mapped to `null`.
* - If the next argument does start with a hyphen, the current option key is mapped to `true`.
*
* @template K - The type of the keys in the resulting Map.
* @template V - The type of the values in the resulting Map, extending `NodeJS.Process.ArgvValue`.
* @template T - The type of custom option names.
*
* @returns {Map<K, V>} A Map containing the processed command line options.
* @returns A Map containing the processed command line options.
*/
declare const getProcessOptions: <K, V extends NodeJS.Process.ArgvValue>() => Map<K, V>;
declare const getProcessOptions: <T extends string>() => _alessiofrittoli_web_utils.TypedMap<NodeJS.Process.OptionsMap<T>, true, NodeJS.Process.OptionName<T>>;
export { type DirectoryTreeEntry, ErrorCode, FileSystem, type ForEachDirectoryEntryOptions, Git, NodeJS, type OnIteration, type OnIterationOptions, Package, type PackageJson, forEachDirectoryEntry, formatStash, formatStashList, getDefaultRemote, getDefaultRemoteAndBranch, getDirectoryTree, getPackage, getPackageJson, getPreReleaseTag, getProcessOptions, getProcessRoot, getRemotes, getStashBy, getStashList, isExternalPackage, isPackageInstalled, popStashByIndex };
export { type DirectoryTreeEntry, ErrorCode, FileSystem, type ForEachDirectoryEntryOptions, Git, NodeJS, type OnIteration, type OnIterationOptions, Package, type PackageJson, forEachDirectoryEntry, formatStash, formatStashList, getDefaultRemote, getDefaultRemoteAndBranch, getDirectoryTree, getPackage, getPackageJson, getPreReleaseTag, getProcessOptions, getProcessRoot, getRemotes, getStashBy, getStashList, isExternalPackage, isPackageInstalled, patchDiffToFile, popStashByIndex };

@@ -6,2 +6,3 @@ import { ParsedPath } from 'path';

export { Release } from './types.js';
import * as _alessiofrittoli_web_utils from '@alessiofrittoli/web-utils';

@@ -176,2 +177,11 @@ declare const FileSystem: {

declare const popStashByIndex: (index: number) => NonSharedBuffer;
/**
* Get git diff and optionally write `patch` file.
*
* Options can also be passed via process arguments, which are merged with the provided options.
*
* @param options An object defining custom options. See {@link Git.Diff.Options}.
* @returns The `git diff` output as a Buffer.
*/
declare const patchDiffToFile: (options?: Git.Diff.Options) => NonSharedBuffer;

@@ -240,11 +250,10 @@ /**

* - If the next argument does not start with a hyphen, it is considered the value for the current option key.
* - If the next argument does start with a hyphen, the current option key is mapped to `null`.
* - If the next argument does start with a hyphen, the current option key is mapped to `true`.
*
* @template K - The type of the keys in the resulting Map.
* @template V - The type of the values in the resulting Map, extending `NodeJS.Process.ArgvValue`.
* @template T - The type of custom option names.
*
* @returns {Map<K, V>} A Map containing the processed command line options.
* @returns A Map containing the processed command line options.
*/
declare const getProcessOptions: <K, V extends NodeJS.Process.ArgvValue>() => Map<K, V>;
declare const getProcessOptions: <T extends string>() => _alessiofrittoli_web_utils.TypedMap<NodeJS.Process.OptionsMap<T>, true, NodeJS.Process.OptionName<T>>;
export { type DirectoryTreeEntry, ErrorCode, FileSystem, type ForEachDirectoryEntryOptions, Git, NodeJS, type OnIteration, type OnIterationOptions, Package, type PackageJson, forEachDirectoryEntry, formatStash, formatStashList, getDefaultRemote, getDefaultRemoteAndBranch, getDirectoryTree, getPackage, getPackageJson, getPreReleaseTag, getProcessOptions, getProcessRoot, getRemotes, getStashBy, getStashList, isExternalPackage, isPackageInstalled, popStashByIndex };
export { type DirectoryTreeEntry, ErrorCode, FileSystem, type ForEachDirectoryEntryOptions, Git, NodeJS, type OnIteration, type OnIterationOptions, Package, type PackageJson, forEachDirectoryEntry, formatStash, formatStashList, getDefaultRemote, getDefaultRemoteAndBranch, getDirectoryTree, getPackage, getPackageJson, getPreReleaseTag, getProcessOptions, getProcessRoot, getRemotes, getStashBy, getStashList, isExternalPackage, isPackageInstalled, patchDiffToFile, popStashByIndex };

@@ -1,4 +0,4 @@

'use strict';var code=require('@alessiofrittoli/exception/code'),A=require('path'),j=require('fs'),exception=require('@alessiofrittoli/exception'),child_process=require('child_process');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var A__default=/*#__PURE__*/_interopDefault(A);var j__default=/*#__PURE__*/_interopDefault(j);var N=Object.defineProperty;var g=Object.getOwnPropertySymbols;var k=Object.prototype.hasOwnProperty,b=Object.prototype.propertyIsEnumerable;var d=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t);var y=(t,e,r)=>e in t?N(t,e,{enumerable:true,configurable:true,writable:true,value:r}):t[e]=r,m=(t,e)=>{for(var r in e||(e={}))k.call(e,r)&&y(t,r,e[r]);if(g)for(var r of g(e))b.call(e,r)&&y(t,r,e[r]);return t};var x=(t,e,r)=>(e=t[d("asyncIterator")])?e.call(t):(t=t[d("iterator")](),e={},r=(o,s)=>(s=t[o])&&(e[o]=n=>new Promise((a,i,p)=>(n=s.call(t,n),p=n.done,Promise.resolve(n.value).then(c=>a({value:c,done:p}),i)))),r("next"),r("return"),e);var O={ENOENT:"ERR:ENOENT"},h=m(m({},code.ErrorCode),O);var S=(t,e)=>{if(e!=null&&e.includes(t))return [];if(!j.existsSync(t))throw new exception.Exception(`No such file or directory, '${t}'`,{code:h.ENOENT});let r=j.lstatSync(t),o=A.parse(t),s=r.isFile(),n={path:t,parsedPath:o,stats:r};return s?[n]:[...j.readdirSync(t).map(a=>S(A.join(o.dir,o.base,a),e)).flat(),n]},Q=async t=>{let{path:e,exclude:r,signal:o,onIteration:s}=t,n=S(e,r),a=[];try{for(var i=x(n),p,c,P;p=!(c=await i.next()).done;p=!1){let l=c.value;if(o!=null&&o.aborted)break;a.push(await s(l,a.length,n.length));}}catch(c){P=[c];}finally{try{p&&(c=i.return)&&await c.call(i);}finally{if(P)throw P[0]}}return a};var E=()=>{let e=child_process.execSync("git remote -v",{encoding:"buffer"}).toString().split(`
`),r=new Map;return e.map(o=>{var f;let[s,n]=o.split(" ");if(!s||!n)return null;let a=r.get(s)||new Map,i=a.get("urls")||new Map,p=n.split(" "),c=((f=p.at(1))==null?void 0:f.replace(/\(|\)/g,""))||"fetch",P=i.has(c)?c==="fetch"?"push":"fetch":c,l=p.at(0);if(!l)return null;i.set(P,l),a.set("name",s),a.set("urls",i),r.has(s)||r.set(s,a);}),r},M=()=>{var t,e,r;return ((r=(e=(t=child_process.execSync("git branch -rl '*/HEAD'"))==null?void 0:t.toString().split(`
`).filter(Boolean).at(0))==null?void 0:e.split(" -> ").at(1))==null?void 0:r.split("/"))||[null,null]},tt=()=>{var e;let[t]=M();return t?E().get(t):(e=E().entries().next().value)==null?void 0:e[1]},B=()=>child_process.execSync("git stash list").toString().split(`
`).map(T).filter(Boolean),T=t=>{var n;if(!t)return null;let e=t.split(": "),r=Number(e.at(0).split("@{").pop().split("}").at(0)||"invalid");if(isNaN(r))return null;let o=(e.at(2)?e.at(1).split(" ").pop():null)||"main",s=e.at(2)||((n=e.at(1))==null?void 0:n.split(" ").pop())||null;return {index:r,branch:o,name:s}},et=t=>t.map(T),rt=t=>B().find(e=>"name"in t?e.name===t.name:e.index===t.index),ot=t=>child_process.execFileSync("git",["stash","pop","--index",t.toString()],{stdio:"inherit"});var V=t=>JSON.parse(child_process.execSync(`npm list --json${t?" -g":""}`).toString()),at=(t,e)=>t in(V(e).dependencies||{});var K=t=>JSON.parse(j__default.default.readFileSync(A__default.default.resolve(t,"package.json")).toString()),lt=({root:t,name:e})=>{try{return !K(t).name.endsWith(e)}catch(r){throw new Error("Couldn't check if script is running in an external project.",{cause:r})}},mt=t=>{let e=t.match(/-(\w+)\.\d+/);return e?e[1]:null};var ft=()=>process.env.INIT_CWD||process.cwd(),gt=()=>new Map(process.argv.map(t=>({value:t,isValue:!t.startsWith("-")})).map((t,e,r)=>{switch(e){case 0:return ["--executable",t.value];case 1:return ["--scriptPath",t.value];default:{let o=r[e+1];if(!t.isValue)return o!=null&&o.isValue?[t.value,o.value]:[t.value,"true"]}}}).filter(Boolean));exports.ErrorCode=h;exports.FileSystem=O;exports.forEachDirectoryEntry=Q;exports.formatStash=T;exports.formatStashList=et;exports.getDefaultRemote=tt;exports.getDefaultRemoteAndBranch=M;exports.getDirectoryTree=S;exports.getPackage=V;exports.getPackageJson=K;exports.getPreReleaseTag=mt;exports.getProcessOptions=gt;exports.getProcessRoot=ft;exports.getRemotes=E;exports.getStashBy=rt;exports.getStashList=B;exports.isExternalPackage=lt;exports.isPackageInstalled=at;exports.popStashByIndex=ot;
'use strict';var code=require('@alessiofrittoli/exception/code'),W=require('path'),U=require('fs'),exception=require('@alessiofrittoli/exception'),child_process=require('child_process'),webUtils=require('@alessiofrittoli/web-utils');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var W__default=/*#__PURE__*/_interopDefault(W);var U__default=/*#__PURE__*/_interopDefault(U);var O=Object.defineProperty;var d=Object.getOwnPropertySymbols;var v=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable;var y=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t);var h=(t,e,r)=>e in t?O(t,e,{enumerable:true,configurable:true,writable:true,value:r}):t[e]=r,u=(t,e)=>{for(var r in e||(e={}))v.call(e,r)&&h(t,r,e[r]);if(d)for(var r of d(e))N.call(e,r)&&h(t,r,e[r]);return t};var x=(t,e,r)=>(e=t[y("asyncIterator")])?e.call(t):(t=t[y("iterator")](),e={},r=(o,n)=>(n=t[o])&&(e[o]=s=>new Promise((a,c,i)=>(s=n.call(t,s),i=s.done,Promise.resolve(s.value).then(p=>a({value:p,done:i}),c)))),r("next"),r("return"),e);var w={ENOENT:"ERR:ENOENT"},S=u(u({},code.ErrorCode),w);var T=(t,e)=>{if(e!=null&&e.includes(t))return [];if(!U.existsSync(t))throw new exception.Exception(`No such file or directory, '${t}'`,{code:S.ENOENT});let r=U.lstatSync(t),o=W.parse(t),n=r.isFile(),s={path:t,parsedPath:o,stats:r};return n?[s]:[...U.readdirSync(t).map(a=>T(W.join(o.dir,o.base,a),e)).flat(),s]},Z=async t=>{let{path:e,exclude:r,signal:o,onIteration:n}=t,s=T(e,r),a=[];try{for(var c=x(s),i,p,f;i=!(p=await c.next()).done;i=!1){let m=p.value;if(o!=null&&o.aborted)break;a.push(await n(m,a.length,s.length));}}catch(p){f=[p];}finally{try{i&&(p=c.return)&&await p.call(c);}finally{if(f)throw f[0]}}return a};var ot=()=>process.env.INIT_CWD||process.cwd(),E=()=>webUtils.getTypedMap(process.argv.map(t=>({value:t,isValue:!t.startsWith("-")})).map((t,e,r)=>{switch(e){case 0:return ["--executable",t.value];case 1:return ["--scriptPath",t.value];default:{let o=r[e+1];if(!t.isValue)return o!=null&&o.isValue?[t.value,o.value]:[t.value,"true"]}}}).filter(Boolean));var P=()=>{let e=child_process.execSync("git remote -v",{encoding:"buffer"}).toString().split(`
`),r=new Map;return e.map(o=>{var g;let[n,s]=o.split(" ");if(!n||!s)return null;let a=r.get(n)||new Map,c=a.get("urls")||new Map,i=s.split(" "),p=((g=i.at(1))==null?void 0:g.replace(/\(|\)/g,""))||"fetch",f=c.has(p)?p==="fetch"?"push":"fetch":p,m=i.at(0);if(!m)return null;c.set(f,m),a.set("name",n),a.set("urls",c),r.has(n)||r.set(n,a);}),r},A=()=>{var t,e,r;return ((r=(e=(t=child_process.execSync("git branch -rl '*/HEAD'"))==null?void 0:t.toString().split(`
`).filter(Boolean).at(0))==null?void 0:e.split(" -> ").at(1))==null?void 0:r.split("/"))||[null,null]},ct=()=>{var e;let[t]=A();return t?P().get(t):(e=P().entries().next().value)==null?void 0:e[1]},F=()=>child_process.execSync("git stash list").toString().split(`
`).map(b).filter(Boolean),b=t=>{var s;if(!t)return null;let e=t.split(": "),r=Number(e.at(0).split("@{").pop().split("}").at(0)||"invalid");if(isNaN(r))return null;let o=(e.at(2)?e.at(1).split(" ").pop():null)||"main",n=e.at(2)||((s=e.at(1))==null?void 0:s.split(" ").pop())||null;return {index:r,branch:o,name:n}},pt=t=>t.map(b),lt=t=>F().find(e=>"name"in t?e.name===t.name:e.index===t.index),ft=t=>child_process.execFileSync("git",["stash","pop","--index",t.toString()],{stdio:"inherit"}),mt=(t={})=>{let e=new Set(["git diff"]),r=E();t.file&&r.set("--file",t.file.toString()),t.cached&&r.set("--cached","true"),t.staged&&r.set("--staged","true"),t.verbose&&r.set("--verbose","true");let o=r.has("--verbose"),n=r.get("--file"),s=n==="true"?".patch":n,a=r.has("--cached")||r.has("--staged"),c=a&&!!child_process.execSync("git diff --cached --name-only").toString().trim(),i=a&&!c;r.delete("--executable"),r.delete("--scriptPath"),r.delete("--file"),r.delete("--verbose"),i&&child_process.execSync("git add ."),Array.from(r.entries()).map(([m,g])=>{e.add([m,g!=="true"&&g].filter(Boolean).join(" "));}),s&&e.add(`> ${s}`);let p=Array.from(e.values()).join(" "),f=child_process.execSync(p);return i&&child_process.execSync("git restore --staged ."),o?s?(console.log("Git diff written to >",W.resolve(s)),f):(console.log(Buffer.from(f).toString()),f):f};var L=t=>JSON.parse(child_process.execSync(`npm list --json${t?" -g":""}`).toString()),dt=(t,e)=>t in(L(e).dependencies||{});var $=t=>JSON.parse(U__default.default.readFileSync(W__default.default.resolve(t,"package.json")).toString()),St=({root:t,name:e})=>{try{return !$(t).name.endsWith(e)}catch(r){throw new Error("Couldn't check if script is running in an external project.",{cause:r})}},Tt=t=>{let e=t.match(/-(\w+)\.\d+/);return e?e[1]:null};exports.ErrorCode=S;exports.FileSystem=w;exports.forEachDirectoryEntry=Z;exports.formatStash=b;exports.formatStashList=pt;exports.getDefaultRemote=ct;exports.getDefaultRemoteAndBranch=A;exports.getDirectoryTree=T;exports.getPackage=L;exports.getPackageJson=$;exports.getPreReleaseTag=Tt;exports.getProcessOptions=E;exports.getProcessRoot=ot;exports.getRemotes=P;exports.getStashBy=lt;exports.getStashList=F;exports.isExternalPackage=St;exports.isPackageInstalled=dt;exports.patchDiffToFile=mt;exports.popStashByIndex=ft;

@@ -1,4 +0,4 @@

import {ErrorCode}from'@alessiofrittoli/exception/code';import A,{parse,join}from'path';import j,{existsSync,lstatSync,readdirSync}from'fs';import {Exception}from'@alessiofrittoli/exception';import {execSync,execFileSync}from'child_process';var N=Object.defineProperty;var g=Object.getOwnPropertySymbols;var k=Object.prototype.hasOwnProperty,b=Object.prototype.propertyIsEnumerable;var d=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t);var y=(t,e,r)=>e in t?N(t,e,{enumerable:true,configurable:true,writable:true,value:r}):t[e]=r,m=(t,e)=>{for(var r in e||(e={}))k.call(e,r)&&y(t,r,e[r]);if(g)for(var r of g(e))b.call(e,r)&&y(t,r,e[r]);return t};var x=(t,e,r)=>(e=t[d("asyncIterator")])?e.call(t):(t=t[d("iterator")](),e={},r=(o,s)=>(s=t[o])&&(e[o]=n=>new Promise((a,i,p)=>(n=s.call(t,n),p=n.done,Promise.resolve(n.value).then(c=>a({value:c,done:p}),i)))),r("next"),r("return"),e);var O={ENOENT:"ERR:ENOENT"},h=m(m({},ErrorCode),O);var S=(t,e)=>{if(e!=null&&e.includes(t))return [];if(!existsSync(t))throw new Exception(`No such file or directory, '${t}'`,{code:h.ENOENT});let r=lstatSync(t),o=parse(t),s=r.isFile(),n={path:t,parsedPath:o,stats:r};return s?[n]:[...readdirSync(t).map(a=>S(join(o.dir,o.base,a),e)).flat(),n]},Q=async t=>{let{path:e,exclude:r,signal:o,onIteration:s}=t,n=S(e,r),a=[];try{for(var i=x(n),p,c,P;p=!(c=await i.next()).done;p=!1){let l=c.value;if(o!=null&&o.aborted)break;a.push(await s(l,a.length,n.length));}}catch(c){P=[c];}finally{try{p&&(c=i.return)&&await c.call(i);}finally{if(P)throw P[0]}}return a};var E=()=>{let e=execSync("git remote -v",{encoding:"buffer"}).toString().split(`
`),r=new Map;return e.map(o=>{var f;let[s,n]=o.split(" ");if(!s||!n)return null;let a=r.get(s)||new Map,i=a.get("urls")||new Map,p=n.split(" "),c=((f=p.at(1))==null?void 0:f.replace(/\(|\)/g,""))||"fetch",P=i.has(c)?c==="fetch"?"push":"fetch":c,l=p.at(0);if(!l)return null;i.set(P,l),a.set("name",s),a.set("urls",i),r.has(s)||r.set(s,a);}),r},M=()=>{var t,e,r;return ((r=(e=(t=execSync("git branch -rl '*/HEAD'"))==null?void 0:t.toString().split(`
`).filter(Boolean).at(0))==null?void 0:e.split(" -> ").at(1))==null?void 0:r.split("/"))||[null,null]},tt=()=>{var e;let[t]=M();return t?E().get(t):(e=E().entries().next().value)==null?void 0:e[1]},B=()=>execSync("git stash list").toString().split(`
`).map(T).filter(Boolean),T=t=>{var n;if(!t)return null;let e=t.split(": "),r=Number(e.at(0).split("@{").pop().split("}").at(0)||"invalid");if(isNaN(r))return null;let o=(e.at(2)?e.at(1).split(" ").pop():null)||"main",s=e.at(2)||((n=e.at(1))==null?void 0:n.split(" ").pop())||null;return {index:r,branch:o,name:s}},et=t=>t.map(T),rt=t=>B().find(e=>"name"in t?e.name===t.name:e.index===t.index),ot=t=>execFileSync("git",["stash","pop","--index",t.toString()],{stdio:"inherit"});var V=t=>JSON.parse(execSync(`npm list --json${t?" -g":""}`).toString()),at=(t,e)=>t in(V(e).dependencies||{});var K=t=>JSON.parse(j.readFileSync(A.resolve(t,"package.json")).toString()),lt=({root:t,name:e})=>{try{return !K(t).name.endsWith(e)}catch(r){throw new Error("Couldn't check if script is running in an external project.",{cause:r})}},mt=t=>{let e=t.match(/-(\w+)\.\d+/);return e?e[1]:null};var ft=()=>process.env.INIT_CWD||process.cwd(),gt=()=>new Map(process.argv.map(t=>({value:t,isValue:!t.startsWith("-")})).map((t,e,r)=>{switch(e){case 0:return ["--executable",t.value];case 1:return ["--scriptPath",t.value];default:{let o=r[e+1];if(!t.isValue)return o!=null&&o.isValue?[t.value,o.value]:[t.value,"true"]}}}).filter(Boolean));export{h as ErrorCode,O as FileSystem,Q as forEachDirectoryEntry,T as formatStash,et as formatStashList,tt as getDefaultRemote,M as getDefaultRemoteAndBranch,S as getDirectoryTree,V as getPackage,K as getPackageJson,mt as getPreReleaseTag,gt as getProcessOptions,ft as getProcessRoot,E as getRemotes,rt as getStashBy,B as getStashList,lt as isExternalPackage,at as isPackageInstalled,ot as popStashByIndex};
import {ErrorCode}from'@alessiofrittoli/exception/code';import W,{parse,join,resolve}from'path';import U,{existsSync,lstatSync,readdirSync}from'fs';import {Exception}from'@alessiofrittoli/exception';import {execSync,execFileSync}from'child_process';import {getTypedMap}from'@alessiofrittoli/web-utils';var O=Object.defineProperty;var d=Object.getOwnPropertySymbols;var v=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable;var y=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t);var h=(t,e,r)=>e in t?O(t,e,{enumerable:true,configurable:true,writable:true,value:r}):t[e]=r,u=(t,e)=>{for(var r in e||(e={}))v.call(e,r)&&h(t,r,e[r]);if(d)for(var r of d(e))N.call(e,r)&&h(t,r,e[r]);return t};var x=(t,e,r)=>(e=t[y("asyncIterator")])?e.call(t):(t=t[y("iterator")](),e={},r=(o,n)=>(n=t[o])&&(e[o]=s=>new Promise((a,c,i)=>(s=n.call(t,s),i=s.done,Promise.resolve(s.value).then(p=>a({value:p,done:i}),c)))),r("next"),r("return"),e);var w={ENOENT:"ERR:ENOENT"},S=u(u({},ErrorCode),w);var T=(t,e)=>{if(e!=null&&e.includes(t))return [];if(!existsSync(t))throw new Exception(`No such file or directory, '${t}'`,{code:S.ENOENT});let r=lstatSync(t),o=parse(t),n=r.isFile(),s={path:t,parsedPath:o,stats:r};return n?[s]:[...readdirSync(t).map(a=>T(join(o.dir,o.base,a),e)).flat(),s]},Z=async t=>{let{path:e,exclude:r,signal:o,onIteration:n}=t,s=T(e,r),a=[];try{for(var c=x(s),i,p,f;i=!(p=await c.next()).done;i=!1){let m=p.value;if(o!=null&&o.aborted)break;a.push(await n(m,a.length,s.length));}}catch(p){f=[p];}finally{try{i&&(p=c.return)&&await p.call(c);}finally{if(f)throw f[0]}}return a};var ot=()=>process.env.INIT_CWD||process.cwd(),E=()=>getTypedMap(process.argv.map(t=>({value:t,isValue:!t.startsWith("-")})).map((t,e,r)=>{switch(e){case 0:return ["--executable",t.value];case 1:return ["--scriptPath",t.value];default:{let o=r[e+1];if(!t.isValue)return o!=null&&o.isValue?[t.value,o.value]:[t.value,"true"]}}}).filter(Boolean));var P=()=>{let e=execSync("git remote -v",{encoding:"buffer"}).toString().split(`
`),r=new Map;return e.map(o=>{var g;let[n,s]=o.split(" ");if(!n||!s)return null;let a=r.get(n)||new Map,c=a.get("urls")||new Map,i=s.split(" "),p=((g=i.at(1))==null?void 0:g.replace(/\(|\)/g,""))||"fetch",f=c.has(p)?p==="fetch"?"push":"fetch":p,m=i.at(0);if(!m)return null;c.set(f,m),a.set("name",n),a.set("urls",c),r.has(n)||r.set(n,a);}),r},A=()=>{var t,e,r;return ((r=(e=(t=execSync("git branch -rl '*/HEAD'"))==null?void 0:t.toString().split(`
`).filter(Boolean).at(0))==null?void 0:e.split(" -> ").at(1))==null?void 0:r.split("/"))||[null,null]},ct=()=>{var e;let[t]=A();return t?P().get(t):(e=P().entries().next().value)==null?void 0:e[1]},F=()=>execSync("git stash list").toString().split(`
`).map(b).filter(Boolean),b=t=>{var s;if(!t)return null;let e=t.split(": "),r=Number(e.at(0).split("@{").pop().split("}").at(0)||"invalid");if(isNaN(r))return null;let o=(e.at(2)?e.at(1).split(" ").pop():null)||"main",n=e.at(2)||((s=e.at(1))==null?void 0:s.split(" ").pop())||null;return {index:r,branch:o,name:n}},pt=t=>t.map(b),lt=t=>F().find(e=>"name"in t?e.name===t.name:e.index===t.index),ft=t=>execFileSync("git",["stash","pop","--index",t.toString()],{stdio:"inherit"}),mt=(t={})=>{let e=new Set(["git diff"]),r=E();t.file&&r.set("--file",t.file.toString()),t.cached&&r.set("--cached","true"),t.staged&&r.set("--staged","true"),t.verbose&&r.set("--verbose","true");let o=r.has("--verbose"),n=r.get("--file"),s=n==="true"?".patch":n,a=r.has("--cached")||r.has("--staged"),c=a&&!!execSync("git diff --cached --name-only").toString().trim(),i=a&&!c;r.delete("--executable"),r.delete("--scriptPath"),r.delete("--file"),r.delete("--verbose"),i&&execSync("git add ."),Array.from(r.entries()).map(([m,g])=>{e.add([m,g!=="true"&&g].filter(Boolean).join(" "));}),s&&e.add(`> ${s}`);let p=Array.from(e.values()).join(" "),f=execSync(p);return i&&execSync("git restore --staged ."),o?s?(console.log("Git diff written to >",resolve(s)),f):(console.log(Buffer.from(f).toString()),f):f};var L=t=>JSON.parse(execSync(`npm list --json${t?" -g":""}`).toString()),dt=(t,e)=>t in(L(e).dependencies||{});var $=t=>JSON.parse(U.readFileSync(W.resolve(t,"package.json")).toString()),St=({root:t,name:e})=>{try{return !$(t).name.endsWith(e)}catch(r){throw new Error("Couldn't check if script is running in an external project.",{cause:r})}},Tt=t=>{let e=t.match(/-(\w+)\.\d+/);return e?e[1]:null};export{S as ErrorCode,w as FileSystem,Z as forEachDirectoryEntry,b as formatStash,pt as formatStashList,ct as getDefaultRemote,A as getDefaultRemoteAndBranch,T as getDirectoryTree,L as getPackage,$ as getPackageJson,Tt as getPreReleaseTag,E as getProcessOptions,ot as getProcessRoot,P as getRemotes,lt as getStashBy,F as getStashList,St as isExternalPackage,dt as isPackageInstalled,mt as patchDiffToFile,ft as popStashByIndex};

@@ -1,4 +0,4 @@

'use strict';var i=require('fs'),f=require('path');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var i__default=/*#__PURE__*/_interopDefault(i);var f__default=/*#__PURE__*/_interopDefault(f);var p=()=>process.env.INIT_CWD||process.cwd();var h=r=>JSON.parse(i__default.default.readFileSync(f__default.default.resolve(r,"package.json")).toString()),u=({root:r,name:n})=>{try{return !h(r).name.endsWith(n)}catch(e){throw new Error("Couldn't check if script is running in an external project.",{cause:e})}};var w=r=>{let{root:n}=r,{name:e}=r,{outputFile:t}=r,o=`/// <reference types="${e}" />
'use strict';var i=require('fs'),f=require('path');require('@alessiofrittoli/web-utils');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var i__default=/*#__PURE__*/_interopDefault(i);var f__default=/*#__PURE__*/_interopDefault(f);var p=()=>process.env.INIT_CWD||process.cwd();var h=r=>JSON.parse(i__default.default.readFileSync(f__default.default.resolve(r,"package.json")).toString()),u=({root:r,name:n})=>{try{return !h(r).name.endsWith(n)}catch(e){throw new Error("Couldn't check if script is running in an external project.",{cause:e})}};var w=r=>{let{root:n}=r,{name:e}=r,{outputFile:t}=r,o=`/// <reference types="${e}" />
`,c="// NOTE: This file should not be edited",s=f__default.default.resolve(n,t);if(i__default.default.existsSync(s)){let a=i__default.default.readFileSync(s);if(a.toString().split(`
`).includes(o.replace(/\n/g,""))){console.log({package:e,message:`The "${t}" file already exists and it includes the needed type references.`});return}let d=Buffer.concat([Buffer.from(o),a]);try{i__default.default.writeFileSync(s,d),console.log({package:e,message:`The "${t}" file already exists and it has been edited with new type references.`});return}catch(g){throw new Error(`An error occured while editing "${t}" in your project. Some global types may not work as expected.`,{cause:g})}}let l=[o,c].join(`
`);try{return i__default.default.writeFileSync(s,Buffer.from(l)),console.log({package:e,message:`"${t}" has been created at the root of your project.`}),!0}catch(a){throw new Error(`An error occurred while creating "${t}" at the root of your project. Some global types may not work as expected.`,{cause:a})}},x=r=>{let{root:n}=r,{name:e}=r,{outputFile:t}=r,o="tsconfig.json";try{let c=f__default.default.resolve(n,o),s=JSON.parse(i__default.default.readFileSync(c).toString());s.include||(s.include=[]);let{include:l}=s;if(Array.isArray(l)&&!l.includes(t)){l.push(t);try{i__default.default.writeFileSync(c,Buffer.from(JSON.stringify(s,void 0," "))),console.log({package:e,message:`"${t}" added to \`include\` property of your "${o}" file.`});}catch(a){throw new Error(`Couldn't update your "${o}" file. You should manually update it by adding ${t} in the \`include\` array.`,{cause:a})}}}catch(c){throw new Error(`An error occured while updating your "${o}" file.`,{cause:c})}},O=r=>{let{outputFile:n="alessiofrittoli-env.d.ts"}=r,{name:e}=r,t=p();try{if(!u({name:e,root:t})){console.log({package:e,message:`Skip "postinstall" script. Running in ${e}`});return}w({name:e,root:t,outputFile:n}),x({root:t,name:e,outputFile:n});}catch(o){console.error(o),process.exit(1);}};exports.addTypesReference=O;exports.createReferenceFile=w;exports.updateTsConfig=x;
`);try{return i__default.default.writeFileSync(s,Buffer.from(l)),console.log({package:e,message:`"${t}" has been created at the root of your project.`}),!0}catch(a){throw new Error(`An error occurred while creating "${t}" at the root of your project. Some global types may not work as expected.`,{cause:a})}},x=r=>{let{root:n}=r,{name:e}=r,{outputFile:t}=r,o="tsconfig.json";try{let c=f__default.default.resolve(n,o),s=JSON.parse(i__default.default.readFileSync(c).toString());s.include||(s.include=[]);let{include:l}=s;if(Array.isArray(l)&&!l.includes(t)){l.push(t);try{i__default.default.writeFileSync(c,Buffer.from(JSON.stringify(s,void 0," "))),console.log({package:e,message:`"${t}" added to \`include\` property of your "${o}" file.`});}catch(a){throw new Error(`Couldn't update your "${o}" file. You should manually update it by adding ${t} in the \`include\` array.`,{cause:a})}}}catch(c){throw new Error(`An error occured while updating your "${o}" file.`,{cause:c})}},A=r=>{let{outputFile:n="alessiofrittoli-env.d.ts"}=r,{name:e}=r,t=p();try{if(!u({name:e,root:t})){console.log({package:e,message:`Skip "postinstall" script. Running in ${e}`});return}w({name:e,root:t,outputFile:n}),x({root:t,name:e,outputFile:n});}catch(o){console.error(o),process.exit(1);}};exports.addTypesReference=A;exports.createReferenceFile=w;exports.updateTsConfig=x;

@@ -1,4 +0,4 @@

import i from'fs';import f from'path';var p=()=>process.env.INIT_CWD||process.cwd();var h=r=>JSON.parse(i.readFileSync(f.resolve(r,"package.json")).toString()),u=({root:r,name:n})=>{try{return !h(r).name.endsWith(n)}catch(e){throw new Error("Couldn't check if script is running in an external project.",{cause:e})}};var w=r=>{let{root:n}=r,{name:e}=r,{outputFile:t}=r,o=`/// <reference types="${e}" />
import i from'fs';import f from'path';import'@alessiofrittoli/web-utils';var p=()=>process.env.INIT_CWD||process.cwd();var h=r=>JSON.parse(i.readFileSync(f.resolve(r,"package.json")).toString()),u=({root:r,name:n})=>{try{return !h(r).name.endsWith(n)}catch(e){throw new Error("Couldn't check if script is running in an external project.",{cause:e})}};var w=r=>{let{root:n}=r,{name:e}=r,{outputFile:t}=r,o=`/// <reference types="${e}" />
`,c="// NOTE: This file should not be edited",s=f.resolve(n,t);if(i.existsSync(s)){let a=i.readFileSync(s);if(a.toString().split(`
`).includes(o.replace(/\n/g,""))){console.log({package:e,message:`The "${t}" file already exists and it includes the needed type references.`});return}let d=Buffer.concat([Buffer.from(o),a]);try{i.writeFileSync(s,d),console.log({package:e,message:`The "${t}" file already exists and it has been edited with new type references.`});return}catch(g){throw new Error(`An error occured while editing "${t}" in your project. Some global types may not work as expected.`,{cause:g})}}let l=[o,c].join(`
`);try{return i.writeFileSync(s,Buffer.from(l)),console.log({package:e,message:`"${t}" has been created at the root of your project.`}),!0}catch(a){throw new Error(`An error occurred while creating "${t}" at the root of your project. Some global types may not work as expected.`,{cause:a})}},x=r=>{let{root:n}=r,{name:e}=r,{outputFile:t}=r,o="tsconfig.json";try{let c=f.resolve(n,o),s=JSON.parse(i.readFileSync(c).toString());s.include||(s.include=[]);let{include:l}=s;if(Array.isArray(l)&&!l.includes(t)){l.push(t);try{i.writeFileSync(c,Buffer.from(JSON.stringify(s,void 0," "))),console.log({package:e,message:`"${t}" added to \`include\` property of your "${o}" file.`});}catch(a){throw new Error(`Couldn't update your "${o}" file. You should manually update it by adding ${t} in the \`include\` array.`,{cause:a})}}}catch(c){throw new Error(`An error occured while updating your "${o}" file.`,{cause:c})}},O=r=>{let{outputFile:n="alessiofrittoli-env.d.ts"}=r,{name:e}=r,t=p();try{if(!u({name:e,root:t})){console.log({package:e,message:`Skip "postinstall" script. Running in ${e}`});return}w({name:e,root:t,outputFile:n}),x({root:t,name:e,outputFile:n});}catch(o){console.error(o),process.exit(1);}};export{O as addTypesReference,w as createReferenceFile,x as updateTsConfig};
`);try{return i.writeFileSync(s,Buffer.from(l)),console.log({package:e,message:`"${t}" has been created at the root of your project.`}),!0}catch(a){throw new Error(`An error occurred while creating "${t}" at the root of your project. Some global types may not work as expected.`,{cause:a})}},x=r=>{let{root:n}=r,{name:e}=r,{outputFile:t}=r,o="tsconfig.json";try{let c=f.resolve(n,o),s=JSON.parse(i.readFileSync(c).toString());s.include||(s.include=[]);let{include:l}=s;if(Array.isArray(l)&&!l.includes(t)){l.push(t);try{i.writeFileSync(c,Buffer.from(JSON.stringify(s,void 0," "))),console.log({package:e,message:`"${t}" added to \`include\` property of your "${o}" file.`});}catch(a){throw new Error(`Couldn't update your "${o}" file. You should manually update it by adding ${t} in the \`include\` array.`,{cause:a})}}}catch(c){throw new Error(`An error occured while updating your "${o}" file.`,{cause:c})}},A=r=>{let{outputFile:n="alessiofrittoli-env.d.ts"}=r,{name:e}=r,t=p();try{if(!u({name:e,root:t})){console.log({package:e,message:`Skip "postinstall" script. Running in ${e}`});return}w({name:e,root:t,outputFile:n}),x({root:t,name:e,outputFile:n});}catch(o){console.error(o),process.exit(1);}};export{A as addTypesReference,w as createReferenceFile,x as updateTsConfig};

@@ -1,4 +0,4 @@

'use strict';var child_process=require('child_process'),T=require('fs'),O=require('path');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var T__default=/*#__PURE__*/_interopDefault(T);var O__default=/*#__PURE__*/_interopDefault(O);var k=()=>process.env.INIT_CWD||process.cwd(),P=()=>new Map(process.argv.map(e=>({value:e,isValue:!e.startsWith("-")})).map((e,t,s)=>{switch(t){case 0:return ["--executable",e.value];case 1:return ["--scriptPath",e.value];default:{let a=s[t+1];if(!e.isValue)return a!=null&&a.isValue?[e.value,a.value]:[e.value,"true"]}}}).filter(Boolean));var R=e=>JSON.parse(T__default.default.readFileSync(O__default.default.resolve(e,"package.json")).toString());var N=e=>{let t=e.match(/-(\w+)\.\d+/);return t?t[1]:null};var J=()=>{let t=child_process.execSync("git remote -v",{encoding:"buffer"}).toString().split(`
`),s=new Map;return t.map(a=>{var m;let[n,r]=a.split(" ");if(!n||!r)return null;let o=s.get(n)||new Map,c=o.get("urls")||new Map,p=r.split(" "),l=((m=p.at(1))==null?void 0:m.replace(/\(|\)/g,""))||"fetch",d=c.has(l)?l==="fetch"?"push":"fetch":l,g=p.at(0);if(!g)return null;c.set(d,g),o.set("name",n),o.set("urls",c),s.has(n)||s.set(n,o);}),s},I=()=>{var e,t,s;return ((s=(t=(e=child_process.execSync("git branch -rl '*/HEAD'"))==null?void 0:e.toString().split(`
`).filter(Boolean).at(0))==null?void 0:t.split(" -> ").at(1))==null?void 0:s.split("/"))||[null,null]},$=()=>{var t;let[e]=I();return e?J().get(e):(t=J().entries().next().value)==null?void 0:t[1]},V=()=>child_process.execSync("git stash list").toString().split(`
`).map(E).filter(Boolean),E=e=>{var r;if(!e)return null;let t=e.split(": "),s=Number(t.at(0).split("@{").pop().split("}").at(0)||"invalid");if(isNaN(s))return null;let a=(t.at(2)?t.at(1).split(" ").pop():null)||"main",n=t.at(2)||((r=t.at(1))==null?void 0:r.split(" ").pop())||null;return {index:s,branch:a,name:n}};var w=e=>V().find(t=>"name"in e?t.name===e.name:t.index===e.index),B=e=>child_process.execFileSync("git",["stash","pop","--index",e.toString()],{stdio:"inherit"});var A=e=>JSON.parse(child_process.execSync(`npm list --json${" -g"}`).toString()),G=(e,t)=>e in(A().dependencies||{});var ee=e=>{var g,m,x,y,S,v,b;let t=null;try{t=R(k());}catch(i){}let s=P(),a=(g=e==null?void 0:e.verbose)!=null?g:s.has("--verbose"),n=(m=e==null?void 0:e.build)!=null?m:s.get("--build")||"build",r=(x=e==null?void 0:e.version)!=null?x:s.get("--version")||(t==null?void 0:t.version),o=(S=e==null?void 0:e.origin)!=null?S:s.get("--origin")||s.get("--o")||((y=$())==null?void 0:y.get("name"))||"origin",c=(v=e==null?void 0:e.npm)!=null?v:s.has("--npm"),p=(b=e==null?void 0:e.access)!=null?b:s.get("--access")||"public",l="pre-release",d="npm run";try{d=G("pnpm",!0)?"pnpm":"npm run";}catch(i){let f=i;console.log({package:t==null?void 0:t.name,message:"Couldn't check if `pnpm` is installed. Using `npm` instead.",error:f.message});}if((!r||typeof r!="string")&&(console.error("No `version` found in `package.json`"),process.exit(1)),c)switch(p){case "public":break;case "restricted":break;default:console.error("Invalid `--access` option. `public` or `restricted` accepted."),process.exit(1);}try{let i=N(r);if(child_process.execSync(`git stash save -u -m "${l}"`,{stdio:"inherit"}),child_process.execSync(`${d} ${n}`,{stdio:"inherit"}),child_process.execSync(`git tag v${r}`,{stdio:"inherit"}),child_process.execSync(`git push ${o} tag v${r}`,{stdio:"inherit"}),c){let M=[`--access ${p}`,i&&`--tag ${i}`].filter(Boolean).join(" ");child_process.execSync(`npm publish ${M}`,{stdio:"inherit"});}let f=w({name:l});f&&B(f.index),a&&console.log({package:t==null?void 0:t.name,message:`Released version ${r}`,origin:o,tag:`v${r}`,npmPublish:c});}catch(i){console.error("Error during release process:",i),process.exit(1);}};exports.release=ee;
'use strict';var child_process=require('child_process'),webUtils=require('@alessiofrittoli/web-utils'),D=require('fs'),M=require('path');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var D__default=/*#__PURE__*/_interopDefault(D);var M__default=/*#__PURE__*/_interopDefault(M);var P=()=>process.env.INIT_CWD||process.cwd(),k=()=>webUtils.getTypedMap(process.argv.map(e=>({value:e,isValue:!e.startsWith("-")})).map((e,t,r)=>{switch(t){case 0:return ["--executable",e.value];case 1:return ["--scriptPath",e.value];default:{let a=r[t+1];if(!e.isValue)return a!=null&&a.isValue?[e.value,a.value]:[e.value,"true"]}}}).filter(Boolean));var R=e=>JSON.parse(D__default.default.readFileSync(M__default.default.resolve(e,"package.json")).toString());var N=e=>{let t=e.match(/-(\w+)\.\d+/);return t?t[1]:null};var T=()=>{let t=child_process.execSync("git remote -v",{encoding:"buffer"}).toString().split(`
`),r=new Map;return t.map(a=>{var m;let[n,s]=a.split(" ");if(!n||!s)return null;let o=r.get(n)||new Map,i=o.get("urls")||new Map,p=s.split(" "),l=((m=p.at(1))==null?void 0:m.replace(/\(|\)/g,""))||"fetch",f=i.has(l)?l==="fetch"?"push":"fetch":l,g=p.at(0);if(!g)return null;i.set(f,g),o.set("name",n),o.set("urls",i),r.has(n)||r.set(n,o);}),r},A=()=>{var e,t,r;return ((r=(t=(e=child_process.execSync("git branch -rl '*/HEAD'"))==null?void 0:e.toString().split(`
`).filter(Boolean).at(0))==null?void 0:t.split(" -> ").at(1))==null?void 0:r.split("/"))||[null,null]},J=()=>{var t;let[e]=A();return e?T().get(e):(t=T().entries().next().value)==null?void 0:t[1]},E=()=>child_process.execSync("git stash list").toString().split(`
`).map(j).filter(Boolean),j=e=>{var s;if(!e)return null;let t=e.split(": "),r=Number(t.at(0).split("@{").pop().split("}").at(0)||"invalid");if(isNaN(r))return null;let a=(t.at(2)?t.at(1).split(" ").pop():null)||"main",n=t.at(2)||((s=t.at(1))==null?void 0:s.split(" ").pop())||null;return {index:r,branch:a,name:n}};var O=e=>E().find(t=>"name"in e?t.name===e.name:t.index===e.index),B=e=>child_process.execFileSync("git",["stash","pop","--index",e.toString()],{stdio:"inherit"});var V=e=>JSON.parse(child_process.execSync(`npm list --json${" -g"}`).toString()),G=(e,t)=>e in(V().dependencies||{});var ae=e=>{var g,m,x,S,v,y,b;let t=null;try{t=R(P());}catch(c){}let r=k(),a=(g=e==null?void 0:e.verbose)!=null?g:r.has("--verbose"),n=(m=e==null?void 0:e.build)!=null?m:r.get("--build")||"build",s=(x=e==null?void 0:e.version)!=null?x:r.get("--version")||(t==null?void 0:t.version),o=(v=e==null?void 0:e.origin)!=null?v:r.get("--origin")||r.get("--o")||((S=J())==null?void 0:S.get("name"))||"origin",i=(y=e==null?void 0:e.npm)!=null?y:r.has("--npm"),p=(b=e==null?void 0:e.access)!=null?b:r.get("--access")||"public",l="pre-release",f="npm run";try{f=G("pnpm",!0)?"pnpm":"npm run";}catch(c){let d=c;console.log({package:t==null?void 0:t.name,message:"Couldn't check if `pnpm` is installed. Using `npm` instead.",error:d.message});}if((!s||typeof s!="string")&&(console.error("No `version` found in `package.json`"),process.exit(1)),i)switch(p){case "public":break;case "restricted":break;default:console.error("Invalid `--access` option. `public` or `restricted` accepted."),process.exit(1);}try{let c=N(s);if(child_process.execSync(`git stash save -u -m "${l}"`,{stdio:"inherit"}),child_process.execSync(`${f} ${n}`,{stdio:"inherit"}),child_process.execSync(`git tag v${s}`,{stdio:"inherit"}),child_process.execSync(`git push ${o} tag v${s}`,{stdio:"inherit"}),i){let $=[`--access ${p}`,c&&`--tag ${c}`].filter(Boolean).join(" ");child_process.execSync(`npm publish ${$}`,{stdio:"inherit"});}let d=O({name:l});d&&B(d.index),a&&console.log({package:t==null?void 0:t.name,message:`Released version ${s}`,origin:o,tag:`v${s}`,npmPublish:i});}catch(c){console.error("Error during release process:",c),process.exit(1);}};exports.release=ae;

@@ -1,4 +0,4 @@

import {execSync,execFileSync}from'child_process';import T from'fs';import O from'path';var k=()=>process.env.INIT_CWD||process.cwd(),P=()=>new Map(process.argv.map(e=>({value:e,isValue:!e.startsWith("-")})).map((e,t,s)=>{switch(t){case 0:return ["--executable",e.value];case 1:return ["--scriptPath",e.value];default:{let a=s[t+1];if(!e.isValue)return a!=null&&a.isValue?[e.value,a.value]:[e.value,"true"]}}}).filter(Boolean));var R=e=>JSON.parse(T.readFileSync(O.resolve(e,"package.json")).toString());var N=e=>{let t=e.match(/-(\w+)\.\d+/);return t?t[1]:null};var J=()=>{let t=execSync("git remote -v",{encoding:"buffer"}).toString().split(`
`),s=new Map;return t.map(a=>{var m;let[n,r]=a.split(" ");if(!n||!r)return null;let o=s.get(n)||new Map,c=o.get("urls")||new Map,p=r.split(" "),l=((m=p.at(1))==null?void 0:m.replace(/\(|\)/g,""))||"fetch",d=c.has(l)?l==="fetch"?"push":"fetch":l,g=p.at(0);if(!g)return null;c.set(d,g),o.set("name",n),o.set("urls",c),s.has(n)||s.set(n,o);}),s},I=()=>{var e,t,s;return ((s=(t=(e=execSync("git branch -rl '*/HEAD'"))==null?void 0:e.toString().split(`
`).filter(Boolean).at(0))==null?void 0:t.split(" -> ").at(1))==null?void 0:s.split("/"))||[null,null]},$=()=>{var t;let[e]=I();return e?J().get(e):(t=J().entries().next().value)==null?void 0:t[1]},V=()=>execSync("git stash list").toString().split(`
`).map(E).filter(Boolean),E=e=>{var r;if(!e)return null;let t=e.split(": "),s=Number(t.at(0).split("@{").pop().split("}").at(0)||"invalid");if(isNaN(s))return null;let a=(t.at(2)?t.at(1).split(" ").pop():null)||"main",n=t.at(2)||((r=t.at(1))==null?void 0:r.split(" ").pop())||null;return {index:s,branch:a,name:n}};var w=e=>V().find(t=>"name"in e?t.name===e.name:t.index===e.index),B=e=>execFileSync("git",["stash","pop","--index",e.toString()],{stdio:"inherit"});var A=e=>JSON.parse(execSync(`npm list --json${" -g"}`).toString()),G=(e,t)=>e in(A().dependencies||{});var ee=e=>{var g,m,x,y,S,v,b;let t=null;try{t=R(k());}catch(i){}let s=P(),a=(g=e==null?void 0:e.verbose)!=null?g:s.has("--verbose"),n=(m=e==null?void 0:e.build)!=null?m:s.get("--build")||"build",r=(x=e==null?void 0:e.version)!=null?x:s.get("--version")||(t==null?void 0:t.version),o=(S=e==null?void 0:e.origin)!=null?S:s.get("--origin")||s.get("--o")||((y=$())==null?void 0:y.get("name"))||"origin",c=(v=e==null?void 0:e.npm)!=null?v:s.has("--npm"),p=(b=e==null?void 0:e.access)!=null?b:s.get("--access")||"public",l="pre-release",d="npm run";try{d=G("pnpm",!0)?"pnpm":"npm run";}catch(i){let f=i;console.log({package:t==null?void 0:t.name,message:"Couldn't check if `pnpm` is installed. Using `npm` instead.",error:f.message});}if((!r||typeof r!="string")&&(console.error("No `version` found in `package.json`"),process.exit(1)),c)switch(p){case "public":break;case "restricted":break;default:console.error("Invalid `--access` option. `public` or `restricted` accepted."),process.exit(1);}try{let i=N(r);if(execSync(`git stash save -u -m "${l}"`,{stdio:"inherit"}),execSync(`${d} ${n}`,{stdio:"inherit"}),execSync(`git tag v${r}`,{stdio:"inherit"}),execSync(`git push ${o} tag v${r}`,{stdio:"inherit"}),c){let M=[`--access ${p}`,i&&`--tag ${i}`].filter(Boolean).join(" ");execSync(`npm publish ${M}`,{stdio:"inherit"});}let f=w({name:l});f&&B(f.index),a&&console.log({package:t==null?void 0:t.name,message:`Released version ${r}`,origin:o,tag:`v${r}`,npmPublish:c});}catch(i){console.error("Error during release process:",i),process.exit(1);}};export{ee as release};
import {execSync,execFileSync}from'child_process';import {getTypedMap}from'@alessiofrittoli/web-utils';import D from'fs';import M from'path';var P=()=>process.env.INIT_CWD||process.cwd(),k=()=>getTypedMap(process.argv.map(e=>({value:e,isValue:!e.startsWith("-")})).map((e,t,r)=>{switch(t){case 0:return ["--executable",e.value];case 1:return ["--scriptPath",e.value];default:{let a=r[t+1];if(!e.isValue)return a!=null&&a.isValue?[e.value,a.value]:[e.value,"true"]}}}).filter(Boolean));var R=e=>JSON.parse(D.readFileSync(M.resolve(e,"package.json")).toString());var N=e=>{let t=e.match(/-(\w+)\.\d+/);return t?t[1]:null};var T=()=>{let t=execSync("git remote -v",{encoding:"buffer"}).toString().split(`
`),r=new Map;return t.map(a=>{var m;let[n,s]=a.split(" ");if(!n||!s)return null;let o=r.get(n)||new Map,i=o.get("urls")||new Map,p=s.split(" "),l=((m=p.at(1))==null?void 0:m.replace(/\(|\)/g,""))||"fetch",f=i.has(l)?l==="fetch"?"push":"fetch":l,g=p.at(0);if(!g)return null;i.set(f,g),o.set("name",n),o.set("urls",i),r.has(n)||r.set(n,o);}),r},A=()=>{var e,t,r;return ((r=(t=(e=execSync("git branch -rl '*/HEAD'"))==null?void 0:e.toString().split(`
`).filter(Boolean).at(0))==null?void 0:t.split(" -> ").at(1))==null?void 0:r.split("/"))||[null,null]},J=()=>{var t;let[e]=A();return e?T().get(e):(t=T().entries().next().value)==null?void 0:t[1]},E=()=>execSync("git stash list").toString().split(`
`).map(j).filter(Boolean),j=e=>{var s;if(!e)return null;let t=e.split(": "),r=Number(t.at(0).split("@{").pop().split("}").at(0)||"invalid");if(isNaN(r))return null;let a=(t.at(2)?t.at(1).split(" ").pop():null)||"main",n=t.at(2)||((s=t.at(1))==null?void 0:s.split(" ").pop())||null;return {index:r,branch:a,name:n}};var O=e=>E().find(t=>"name"in e?t.name===e.name:t.index===e.index),B=e=>execFileSync("git",["stash","pop","--index",e.toString()],{stdio:"inherit"});var V=e=>JSON.parse(execSync(`npm list --json${" -g"}`).toString()),G=(e,t)=>e in(V().dependencies||{});var ae=e=>{var g,m,x,S,v,y,b;let t=null;try{t=R(P());}catch(c){}let r=k(),a=(g=e==null?void 0:e.verbose)!=null?g:r.has("--verbose"),n=(m=e==null?void 0:e.build)!=null?m:r.get("--build")||"build",s=(x=e==null?void 0:e.version)!=null?x:r.get("--version")||(t==null?void 0:t.version),o=(v=e==null?void 0:e.origin)!=null?v:r.get("--origin")||r.get("--o")||((S=J())==null?void 0:S.get("name"))||"origin",i=(y=e==null?void 0:e.npm)!=null?y:r.has("--npm"),p=(b=e==null?void 0:e.access)!=null?b:r.get("--access")||"public",l="pre-release",f="npm run";try{f=G("pnpm",!0)?"pnpm":"npm run";}catch(c){let d=c;console.log({package:t==null?void 0:t.name,message:"Couldn't check if `pnpm` is installed. Using `npm` instead.",error:d.message});}if((!s||typeof s!="string")&&(console.error("No `version` found in `package.json`"),process.exit(1)),i)switch(p){case "public":break;case "restricted":break;default:console.error("Invalid `--access` option. `public` or `restricted` accepted."),process.exit(1);}try{let c=N(s);if(execSync(`git stash save -u -m "${l}"`,{stdio:"inherit"}),execSync(`${f} ${n}`,{stdio:"inherit"}),execSync(`git tag v${s}`,{stdio:"inherit"}),execSync(`git push ${o} tag v${s}`,{stdio:"inherit"}),i){let $=[`--access ${p}`,c&&`--tag ${c}`].filter(Boolean).join(" ");execSync(`npm publish ${$}`,{stdio:"inherit"});}let d=O({name:l});d&&B(d.index),a&&console.log({package:t==null?void 0:t.name,message:`Released version ${s}`,origin:o,tag:`v${s}`,npmPublish:i});}catch(c){console.error("Error during release process:",c),process.exit(1);}};export{ae as release};

@@ -16,39 +16,6 @@ /**

* Type representing possible release options.
*
*/
type Option = ('--verbose' | '--version' | '--v' | '--access' | '--origin' | '--o' | '--npm' | '--build');
/**
* Type representing the value associated with a specific release option.
*
* @template T - The release option type.
*/
type OptionValue<T extends Option> = (T extends '--verbose' ? null : T extends '--build' ? string : T extends '--access' ? NodeJS.Process.ArgvValue<'public' | 'restricted'> : NodeJS.Process.ArgvValue);
/**
* Interface representing a map of release options to their values.
*
*/
interface OptionsMap extends Map<Option, OptionValue<Option>> {
/**
* Executes a provided function once per each key/value pair in the Map, in insertion order.
*
* @param callbackfn - Function to execute for each element.
* @param thisArg - Value to use as `this` when executing `callbackfn`.
*/
forEach<K extends Option, V extends OptionValue<K>>(callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): void;
/**
* Returns a specified element from the Map object. If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Map.
*
* @param key - The key of the element to return.
* @returns The element associated with the specified key. If no element is associated with the specified key, `undefined` is returned.
*/
get<K extends Option, V extends OptionValue<K>>(key: K): V | undefined;
/**
* Adds a new element with a specified key and value to the Map. If an element with the same key already exists, the element will be updated.
*
* @param key - The key of the element to add.
* @param value - The value of the element to add.
* @returns The Map object.
*/
set<K extends Option, V extends OptionValue<K>>(key: K, value: V): this;
}
/**
* Interface representing release accepted options.

@@ -122,2 +89,7 @@ *

type ArgvValue<T = string> = T | 'true';
type DefaultOption = '--executable' | '--scriptPath';
type OptionName<T extends string> = T | NodeJS.Process.DefaultOption;
type OptionsMap<T extends string> = {
[x in NodeJS.Process.OptionName<T>]: NodeJS.Process.ArgvValue;
};
}

@@ -227,4 +199,13 @@ interface GlobalPackage {

});
namespace Diff {
type Option = ('--file' | '--cached' | '--staged' | '--verbose');
interface Options {
file?: true | string;
cached?: boolean;
staged?: boolean;
verbose?: boolean;
}
}
}
export { Git, NodeJS, type Package, Release };

@@ -16,39 +16,6 @@ /**

* Type representing possible release options.
*
*/
type Option = ('--verbose' | '--version' | '--v' | '--access' | '--origin' | '--o' | '--npm' | '--build');
/**
* Type representing the value associated with a specific release option.
*
* @template T - The release option type.
*/
type OptionValue<T extends Option> = (T extends '--verbose' ? null : T extends '--build' ? string : T extends '--access' ? NodeJS.Process.ArgvValue<'public' | 'restricted'> : NodeJS.Process.ArgvValue);
/**
* Interface representing a map of release options to their values.
*
*/
interface OptionsMap extends Map<Option, OptionValue<Option>> {
/**
* Executes a provided function once per each key/value pair in the Map, in insertion order.
*
* @param callbackfn - Function to execute for each element.
* @param thisArg - Value to use as `this` when executing `callbackfn`.
*/
forEach<K extends Option, V extends OptionValue<K>>(callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): void;
/**
* Returns a specified element from the Map object. If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Map.
*
* @param key - The key of the element to return.
* @returns The element associated with the specified key. If no element is associated with the specified key, `undefined` is returned.
*/
get<K extends Option, V extends OptionValue<K>>(key: K): V | undefined;
/**
* Adds a new element with a specified key and value to the Map. If an element with the same key already exists, the element will be updated.
*
* @param key - The key of the element to add.
* @param value - The value of the element to add.
* @returns The Map object.
*/
set<K extends Option, V extends OptionValue<K>>(key: K, value: V): this;
}
/**
* Interface representing release accepted options.

@@ -122,2 +89,7 @@ *

type ArgvValue<T = string> = T | 'true';
type DefaultOption = '--executable' | '--scriptPath';
type OptionName<T extends string> = T | NodeJS.Process.DefaultOption;
type OptionsMap<T extends string> = {
[x in NodeJS.Process.OptionName<T>]: NodeJS.Process.ArgvValue;
};
}

@@ -227,4 +199,13 @@ interface GlobalPackage {

});
namespace Diff {
type Option = ('--file' | '--cached' | '--staged' | '--verbose');
interface Options {
file?: true | string;
cached?: boolean;
staged?: boolean;
verbose?: boolean;
}
}
}
export { Git, NodeJS, type Package, Release };
{
"name": "@alessiofrittoli/node-scripts",
"version": "3.3.0",
"version": "3.4.0",
"description": "Utility library with common Node.js scripts",

@@ -88,2 +88,3 @@ "author": {

"release": "node scripts/release.js --verbose --npm",
"diff": "node scripts/diffPatch.js --verbose --staged --file",
"//2a": "*********************************************************************",

@@ -115,13 +116,13 @@ "//2b": "***************************** UNIT TESTS ****************************",

"@alessiofrittoli/type-utils": "^1.9.0",
"@eslint/js": "^9.39.1",
"@jest/globals": "^30.2.0",
"@eslint/js": "^10.0.1",
"@jest/globals": "^30.3.0",
"@types/jest": "^30.0.0",
"@types/node": "^24.10.1",
"@types/node": "^25.5.0",
"concurrently": "^9.2.1",
"cross-env": "^10.1.0",
"dotenv": "^17.2.3",
"eslint": "^9.39.1",
"globals": "^16.5.0",
"dotenv": "^17.3.1",
"eslint": "^10.1.0",
"globals": "^17.4.0",
"http-server": "^14.1.1",
"jest": "^30.2.0",
"jest": "^30.3.0",
"ts-jest": "^29.4.6",

@@ -131,3 +132,3 @@ "ts-node": "^10.9.2",

"typescript": "^5.9.3",
"typescript-eslint": "^8.48.1"
"typescript-eslint": "^8.57.2"
},

@@ -137,4 +138,5 @@ "dependencies": {

"@alessiofrittoli/event-emitter": "^1.6.0",
"@alessiofrittoli/exception": "^3.4.0"
"@alessiofrittoli/exception": "^3.5.0",
"@alessiofrittoli/web-utils": "^2.3.0"
}
}
+40
-40

@@ -23,24 +23,24 @@ # Node.js Scripts 🫧

- [Getting started](#getting-started)
- [API Reference](#api-reference)
- [Post-Install scripts](#post-install-scripts)
- [TypeScript Type Reference Management](#typescript-type-reference-management)
- [Type Reference Interfaces](#type-reference-interfaces)
- [`CommonOptions`](#commonoptions)
- [`AddTypesReferenceOptions`](#addtypesreferenceoptions)
- [Type Reference Functions](#type-reference-functions)
- [`createReferenceFile`](#createreferencefile)
- [`updateTsConfig`](#updatetsconfig)
- [`addTypesReference`](#addtypesreference)
- [Add Types Reference Example usage](#add-types-reference-example-usage)
- [Release Scripts](#release-scripts)
- [Release](#release)
- [Development](#development)
- [Install depenendencies](#install-depenendencies)
- [Build the source code](#build-the-source-code)
- [ESLint](#eslint)
- [Jest](#jest)
- [Contributing](#contributing)
- [Security](#security)
- [Credits](#made-with-)
- [Getting started](#getting-started)
- [API Reference](#api-reference)
- [Post-Install scripts](#post-install-scripts)
- [TypeScript Type Reference Management](#typescript-type-reference-management)
- [Type Reference Interfaces](#type-reference-interfaces)
- [`CommonOptions`](#commonoptions)
- [`AddTypesReferenceOptions`](#addtypesreferenceoptions)
- [Type Reference Functions](#type-reference-functions)
- [`createReferenceFile`](#createreferencefile)
- [`updateTsConfig`](#updatetsconfig)
- [`addTypesReference`](#addtypesreference)
- [Add Types Reference Example usage](#add-types-reference-example-usage)
- [Release Scripts](#release-scripts)
- [Release](#release)
- [Development](#development)
- [Install dependencies](#install-dependencies)
- [Build the source code](#build-the-source-code)
- [ESLint](#eslint)
- [Jest](#jest)
- [Contributing](#contributing)
- [Security](#security)
- [Credits](#made-with-)

@@ -122,3 +122,3 @@ ---

- See [CommonOptions](#commonoptions) interface.
- See [CommonOptions](#commonoptions) interface.

@@ -147,3 +147,3 @@ **Returns**

- See [CommonOptions](#commonoptions) interface.
- See [CommonOptions](#commonoptions) interface.

@@ -174,3 +174,3 @@ **Returns**

- See [AddTypesReferenceOptions](#addtypesreferenceoptions) interface.
- See [AddTypesReferenceOptions](#addtypesreferenceoptions) interface.

@@ -300,5 +300,5 @@ **Returns**

- Attempts to load and parse the `package.json` file.
- Exits the process with code "1" if the file is unavailable or invalid.
- Retrieve the version to use as fallback if no `--version` option has been provided.
- Attempts to load and parse the `package.json` file.
- Exits the process with code "1" if the file is unavailable or invalid.
- Retrieve the version to use as fallback if no `--version` option has been provided.

@@ -309,4 +309,4 @@ </li>

- Retrieves CLI options using `getProcessOptions()`.
- Validates critical parameters such as `version` and `access`.
- Retrieves CLI options using `getProcessOptions()`.
- Validates critical parameters such as `version` and `access`.

@@ -317,6 +317,6 @@ </li>

- Stashes any uncommitted changes with a stash name (`pre-release`).
- Executes the `npm run build` or `pnpm build` command (if `pnpm` is globally installed).
- Create the Git Tag as `v{version}`
- Push the Git Tag the the specified `origin` or to the default Git Repository Remote.
- Stashes any uncommitted changes with a stash name (`pre-release`).
- Executes the `npm run build` or `pnpm build` command (if `pnpm` is globally installed).
- Create the Git Tag as `v{version}`
- Push the Git Tag the the specified `origin` or to the default Git Repository Remote.

@@ -327,3 +327,3 @@ </li>

- Publishes the package using `npm publish` if the `--npm` flag is set.
- Publishes the package using `npm publish` if the `--npm` flag is set.

@@ -334,3 +334,3 @@ </li>

- Restores the stashed changes if any were saved during the process.
- Restores the stashed changes if any were saved during the process.

@@ -341,3 +341,3 @@ </li>

- Logs details of the release process if the `--verbose` flag is set.
- Logs details of the release process if the `--verbose` flag is set.

@@ -413,3 +413,3 @@ </li>

#### Install depenendencies
#### Install dependencies

@@ -436,3 +436,3 @@ ```bash

warnings / errors check.
Run warnings and errors checks.

@@ -455,3 +455,3 @@ ```bash

- See [`package.json`](./package.json) file scripts for more info.
- See [`package.json`](./package.json) file scripts for more info.

@@ -458,0 +458,0 @@ Run tests with coverage.