New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

lint-prepush

Package Overview
Dependencies
Maintainers
0
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lint-prepush - npm Package Compare versions

Comparing version

to
3.0.2

32

dist/lint-prepush.js
#!/usr/bin/env node
import _ from"listr";import E from"chalk";import q from"debug";import z from"os";import{Cache as J}from"file-system-cache";import{cosmiconfigSync as F}from"cosmiconfig";import{execSync as O}from"child_process";var b=(F("lint-prepush").search()||{}).config,a=(t="")=>{let e=O(t).toString()||"";return e=e.split(`
import q from"listr";import v from"chalk";import z from"debug";import J from"os";import{Cache as K}from"file-system-cache";import{cosmiconfigSync as F}from"cosmiconfig";import{execSync as H}from"child_process";var C=(F("lint-prepush").search()||{}).config,a=(t="")=>{let e=H(t).toString()||"";return e=e.split(`
`),e=e.slice(0,-1),e=e.join(`
`),e};import W from"listr";import I from"path";import U from"micromatch";import{execa as A}from"execa";import H from"dedent";import P from"chalk";import T from"log-symbols";import G from"npm-which";var D=G(process.cwd());function j(t){return Math.round(t[0]*1e3+t[1]/1e6)}function y({command:t,fileList:e,task:r,options:o={}}){let{executor:n,args:m}=M({command:t,fileList:e}),f=process.hrtime();return()=>A(n,m,{reject:!1}).then(l=>{let x=process.hrtime(f),c=`(${j(x)}ms)`;if(r.title=`${r.title} ${P.grey(c)}`,!l.failed)return o.verbose&&N(t,l,o),`Passed ${t}`;throw R(t,l.stderr,l.stdout)})}function M({command:t,fileList:e}){let[r,...o]=t.split(" ");return r=D.sync(r),o=o.concat(e),{executor:r,args:o}}function R(t,e,r){let o=new Error;return o.customErrorMessage=H`\n
${T.error} "${t}" is having Errors. Consider revisiting them one more time😉
`),e};import M from"listr";import W from"path";import I from"micromatch";import{execa as D}from"execa";import O from"dedent";import _ from"chalk";import L from"log-symbols";import R from"npm-which";var P=R(process.cwd());function G(t){return Math.round(t[0]*1e3+t[1]/1e6)}function y({command:t,fileList:e,task:r,options:o={}}){let{executor:n,args:m}=N({command:t,fileList:e}),p=process.hrtime();return()=>D(n,m,{reject:!1}).then(l=>{let b=process.hrtime(p),c=`(${G(b)}ms)`;if(r.title=`${r.title} ${_.grey(c)}`,!l.failed)return o.verbose&&j(t,l,o),`Passed ${t}`;throw U(t,l.stderr,l.stdout)})}function N({command:t,fileList:e}){let[r,...o]=t.split(" ");return r=P.sync(r),o=o.concat(e),{executor:r,args:o}}function U(t,e,r){let o=new Error;return o.customErrorMessage=O`\n
${L.error} "${t}" is having Errors. Consider revisiting them one more time😉
${r}
${e}
`,o}function N(t,{stderr:e,stdout:r},o){if(!!e||!!r){let m=[].concat(`
${T.info} Task: ${t}
`,o}function j(t,{stderr:e,stdout:r},o){if(!!e||!!r){let m=[].concat(`
${L.info} Task: ${t}
`).concat(e||[]).concat(r||[]);o.output.push(m.join(`
`))}}function C(t,e,r){return t.map(o=>({title:o,task:(n,m)=>y({command:o,fileList:e,ctx:n,task:m,options:r})()}))}var V=process.cwd();function k(t={}){return Y(t).map(e=>({title:`Linting ${e.fileFormat} files`,task:()=>new W(C(e.commandList.concurrent||e.commandList,e.fileList,t.options),{exitOnError:!0,concurrent:Array.isArray(e.commandList.concurrent)}),skip:()=>e.fileList.length===0?`No files found with ${e.fileFormat}`:!1}))}function Y({tasks:t={},committedGitFiles:e=[]}={}){return Object.keys(t).map(r=>{let o=[],n=t[r];return o=U(e,[r],{matchBase:!r.includes("/"),dot:!0}).map(m=>I.resolve(V,m)),{fileFormat:r,commandList:n,fileList:o}})}function v(t="master"){let e=`git diff --relative --name-only --diff-filter=d ${t}...HEAD`,r=a(e)||"";return r=r.split(`
`),r}function w(t="master",e=""){let r=`git branch --list ${t}`;return e&&(r=`git ls-remote --heads ${e} ${t}`),!!(a(r)||"")}function $(t="master"){let e=`git ls-tree -r ${t} --name-only`,r=a(e)||"";return r=r.split(`
`),r}var s=q("lint-prepush:index");process.stdout.isTTY&&(process.env.FORCE_COLOR="1");(()=>{let t=new J({basePath:`${z.homedir()}/.lint-prepush`,ns:process.cwd()}),e=E.green,r=E.red,o=E.yellow,{log:n}=console;if(!b){process.exitCode=1,n(r(`
`))}}function E(t,e,r){return t.map(o=>({title:o,task:(n,m)=>y({command:o,fileList:e,ctx:n,task:m,options:r})()}))}var V=process.cwd();function A(t={}){return Y(t).map(e=>({title:`Linting ${e.fileFormat} files`,task:()=>new M(E(e.commandList.concurrent||e.commandList,e.fileList,t.options),{exitOnError:!0,concurrent:Array.isArray(e.commandList.concurrent)}),skip:()=>e.fileList.length===0?`No files found with ${e.fileFormat}`:!1}))}function Y({tasks:t={},committedGitFiles:e=[]}={}){return Object.keys(t).map(r=>{let o=[],n=t[r];return o=I(e,[r],{matchBase:!r.includes("/"),dot:!0}).map(m=>W.resolve(V,m)),{fileFormat:r,commandList:n,fileList:o}})}var f="main";function B(t=f){let e=`git diff --relative --name-only --diff-filter=d ${t}...HEAD`,r=a(e)||"";return r=r.split(`
`),r}function T(t=f,e=""){let r=`git branch --list ${t}`;return e&&(r=`git ls-remote --heads ${e} ${t}`),!!(a(r)||"")}function k(t=f){let e=`git ls-tree -r ${t} --name-only`,r=a(e)||"";return r=r.split(`
`),r}var s=z("lint-prepush:index");process.stdout.isTTY&&(process.env.FORCE_COLOR="1");(()=>{let t=new K({basePath:`${J.homedir()}/.lint-prepush`,ns:process.cwd()}),e=v.green,r=v.red,o=v.yellow,{log:n}=console;if(!C){process.exitCode=1,n(r(`
Loading Configuration\u2699\uFE0F Failed!\u{1F611}
`));return}let m=t.getSync("linted-hash")||"";s("Cached Commit SHA: "+m);let f="";try{f=a("git rev-parse HEAD"),s("Latest Commit SHA: "+f)}catch(i){n(r(i)),process.exitCode=1;return}if(f===m){s("Skipping checks since the commit(s) have been linted already."),n(o(`
`));return}let m=t.getSync("linted-hash")||"";s("Cached Commit SHA: "+m);let p="";try{p=a("git rev-parse HEAD"),s("Latest Commit SHA: "+p)}catch(i){n(r(i)),process.exitCode=1;return}if(p===m){s("Skipping checks since the commit(s) have been linted already."),n(o(`
NOTE: Skipping checks since the commit(s) have been linted already.
`));return}let l="",x="git rev-parse --abbrev-ref HEAD";try{l=a(x),s("Current Branch: "+l)}catch(i){n(i(`
`));return}let l="",b="git rev-parse --abbrev-ref HEAD";try{l=a(b),s("Current Branch: "+l)}catch(i){n(i(`
Error while retrieving current branch name
`)),n(i),process.exitCode=1;return}let{base:c,tasks:L={},verbose:B=!1}=b||{},h=!1;if(!c){s("Base not specified, checking for upstream ref");try{c=a("git rev-parse --abbrev-ref $branch@{upstream}"),h=!0,s("Upstream branch name",c)}catch(i){n(i),c="master"}}s("Base Branch: "+c);let p=c,d="";if(l===c){s("Fetching the remote of base branch since current branch and base branch is same");try{d=a("git remote | head -1"),p=`${d}/${c}`,s("Remote of base branch: ",d)}catch(i){s("Couldn't find the remote."),n(i)}s("Branch to Diff: ",p)}try{h=h||w(c,d),s("Check whether branch exists: ",p)}catch(i){process.exitCode=1,n(o(`
`)),n(i),process.exitCode=1;return}let{base:c,tasks:w={},verbose:$=!1}=C||{},h=!1;if(!c){s("Base not specified, checking for upstream ref");try{c=a("git rev-parse --abbrev-ref $branch@{upstream}"),h=!0,s("Upstream branch name",c)}catch(i){n(i),c=f}}s("Base Branch: "+c);let u=c,g="";if(l===c){s("Fetching the remote of base branch since current branch and base branch is same");try{g=a("git remote | head -1"),u=`${g}/${c}`,s("Remote of base branch: ",g)}catch(i){s("Couldn't find the remote."),n(i)}s("Branch to Diff: ",u)}try{h=h||T(c,g),s("Check whether branch exists: ",u)}catch(i){process.exitCode=1,n(o(`
Check for diffBranch existence process has been stopped with the following error
`)),n(i);return}let u=[];if(h){s("Base branch exists.");try{u=v(p),s("Committed GIT files: ",u)}catch(i){process.exitCode=1,n(o(`
`)),n(i);return}let d=[];if(h){s("Base branch exists.");try{d=B(u),s("Committed GIT files: ",d)}catch(i){process.exitCode=1,n(o(`
Fetching committed file list process has been stopped with the following error
`)),n(i);return}}else{n(o(`
\u26A0\uFE0F The base branch(`+p+") doesn't exist.")),n(o(`Hence all the files will be considered
`));try{u=$(l),s("Tracked files: ",u)}catch(i){process.exitCode=1,n(o(`
\u26A0\uFE0F The base branch(`+u+") doesn't exist.")),n(o(`Hence all the files will be considered
`));try{d=k(l),s("Tracked files: ",d)}catch(i){process.exitCode=1,n(o(`
Getting tracked file list process has been stopped with the following error
`)),n(i);return}}let g={verbose:B,output:[]};new _(k({tasks:L,committedGitFiles:u,options:g}),{exitOnError:!1,concurrent:!0,collapse:!1}).run().then(()=>{if(t.setSync("linted-hash",f),s("Cached Current Commit Hash"),g.verbose&&g.output.length){n(e(`
`)),n(i);return}}let x={verbose:$,output:[]};new q(A({tasks:w,committedGitFiles:d,options:x}),{exitOnError:!1,concurrent:!0,collapse:!1}).run().then(()=>{if(t.setSync("linted-hash",p),s("Cached Current Commit Hash"),x.verbose&&x.output.length){n(e(`
All tasks completed successfully. Printing tasks output.
`));for(let i of g.output)n(i)}n(e(`
`));for(let i of x.output)n(i)}n(e(`
Voila! \u{1F389} Code is ready to be Shipped.
`))}).catch(({errors:i})=>{process.exitCode=1,i.forEach(S=>{console.error(S.customErrorMessage)})})})();
{
"name": "lint-prepush",
"version": "3.0.1",
"version": "3.0.2",
"description": "Run linters on committed files in a Branch🔬",

@@ -5,0 +5,0 @@ "author": "“Theenadayalan” <“puduvai.theena@gmail.com”>",

@@ -40,3 +40,3 @@ # lint-prepush

+ "lint-prepush": {
+ "base": "master",
+ "base": "main",
+ "tasks": {

@@ -43,0 +43,0 @@ + "*.js": [