envhound 0.1.0 → 0.1.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.
Files changed (2) hide show
  1. package/dist/envhound.js +1 -1
  2. package/package.json +1 -1
package/dist/envhound.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import{spawnSync as vr}from"node:child_process";import{existsSync as br,readFileSync as Mn,realpathSync as yr}from"node:fs";import{dirname as wr,resolve as L}from"node:path";import{fileURLToPath as xr}from"node:url";import{parseArgs as $r}from"node:util";var te={name:"envhound",version:"0.1.0",description:"Find which startup file sets each environment variable, and audit your PATH",keywords:["environment","env","path","bashrc","profile","dotfiles","shell"],license:"MIT",author:"Michel Salib",repository:{type:"git",url:"git+https://github.com/michelsalib/envhound.git"},homepage:"https://github.com/michelsalib/envhound#readme",bugs:"https://github.com/michelsalib/envhound/issues",type:"module",bin:{envhound:"dist/envhound.js"},files:["dist"],engines:{node:">=20"},scripts:{dev:"bun src/cli.ts",build:"bun build src/cli.ts --target=node --minify --outfile dist/envhound.js",test:"bun test",typecheck:"tsc",prepublishOnly:"bun run typecheck && bun run build && bun test"},devDependencies:{"@types/bun":"^1.4.2","@types/node":"^26.6.4",typescript:"^7.0.2"}};import{statSync as _n}from"node:fs";function _(e,n){return e.assignments.filter((t)=>t.name===n&&!t.local)}function Re(e,n){let t=_(e,n).at(-1);if(!t)return;let i=e.final[n];if(t.result===void 0)return i===void 0?"unset":"not-effective";if(i===void 0)return"not-exported";return t.result===i?"effective":"not-effective"}function Z(e){return e.via?.kind==="function"?e.via.at:e.at}var Hn=new Set(["PWD","OLDPWD","SHLVL","_"]);function re(e,n){return Object.keys(n).filter((t)=>t!=="_"&&n[t]!==void 0).sort().map((t)=>{let i=_(e,t),r=n[t];return{name:t,value:r,kind:i.length?"startup":(t in e.final)?"shell":"inherited",last:i.at(-1),count:i.length,status:Re(e,t),differsFromFresh:!Hn.has(t)&&t in e.final&&e.final[t]!==r}})}function he(e,n,t){return{name:n,assignments:_(e,n),status:Re(e,n),fresh:e.final[n],current:t[n],pathSteps:n==="PATH"?Me(e):void 0}}var F=(e)=>e===void 0?[]:e.split(":"),pe=(e)=>[...new Set(e)];function Me(e){let n=e.initial.PATH??"",t=[{value:n,added:pe(F(n)),removed:[],reordered:!1}];for(let i of _(e,"PATH")){let r=i.result??"",s=new Set(F(n)),a=new Set(F(r)),l=pe(F(r).filter((o)=>!s.has(o))),c=pe(F(n).filter((o)=>!a.has(o))),u=!l.length&&!c.length&&[...s].join(":")!==[...a].join(":");t.push({assignment:i,value:r,added:l,removed:c,reordered:u}),n=r}return t}function Nn(e){try{return _n(e).isDirectory()}catch{return!1}}function z(e,n){let t=new Map;for(let r of Me(e)){for(let s of r.removed)t.delete(s);for(let s of r.added)t.set(s,r.assignment??"initial")}let i=new Map;return F(n).map((r,s)=>{let a=t.get(r),l=s+1,c=i.get(r);if(c===void 0)i.set(r,l);return{index:l,dir:r,exists:r!==""&&Nn(r),duplicateOf:c,source:a===void 0?"inherited":a==="initial"?"initial":"startup",addedBy:a==="initial"?void 0:a}})}var Vn={list:"every exported variable and where it is set",blame:"every startup line that assigns a variable",path:"PATH entries, who added them, missing and duplicates",dotenv:"check .env files against your shell",set:"set variables for future login shells (or a .env file)",unset:"remove variables envhound set",edit:"interactive editor for variables, PATH and .env files",completion:"print a shell completion script",upgrade:"update envhound to the latest release"},Cn={"--json":"machine-readable output","--show-secrets":"don't mask secret values","--home":"act as if HOME were DIR","--file":"set/unset: edit this .env file","--yes":"write without asking","--dry-run":"show the diff, write nothing","--append":"path add: put DIR at the end","--help":"show help","--version":"show the version"},ie=["bash","zsh","fish"],Le=new Set(["--home","--file","-f"]),jn={add:"put a directory in PATH",remove:"remove a directory envhound added"};function _e(e,n){let t=e.at(-1)??"",i=e.slice(0,-1);if(Le.has(i.at(-1)??""))return[];let r=i.filter((a,l)=>!a.startsWith("-")&&!Le.has(i[l-1]??"")),s=[];if(t.startsWith("-"))s=Object.entries(Cn);else if(r.length===0)s=Object.entries(Vn);else if(r[0]==="blame"&&r.length===1)s=Object.keys(n).sort().map((a)=>[a]);else if(r[0]==="unset")s=Object.keys(n).sort().map((a)=>[a]);else if(r[0]==="set"&&!t.includes("="))s=Object.keys(n).filter((a)=>a!=="PATH").sort().map((a)=>[`${a}=`]);else if(r[0]==="path"&&r.length===1)s=Object.entries(jn);else if(r.length===1&&r[0]==="completion")s=ie.map((a)=>[a]);return s.filter(([a])=>a.startsWith(t)).map(([a,l])=>l?`${a} ${l}`:a)}function He(e){switch(e){case"bash":return`# envhound completion for bash. Add to ~/.bashrc: eval "$(envhound completion bash)"
2
+ import{spawnSync as vr}from"node:child_process";import{existsSync as br,readFileSync as Mn,realpathSync as yr}from"node:fs";import{dirname as wr,resolve as L}from"node:path";import{fileURLToPath as xr}from"node:url";import{parseArgs as $r}from"node:util";var te={name:"envhound",version:"0.1.1",description:"Find which startup file sets each environment variable, and audit your PATH",keywords:["environment","env","path","bashrc","profile","dotfiles","shell"],license:"MIT",author:"Michel Salib",repository:{type:"git",url:"git+https://github.com/michelsalib/envhound.git"},homepage:"https://github.com/michelsalib/envhound#readme",bugs:"https://github.com/michelsalib/envhound/issues",type:"module",bin:{envhound:"dist/envhound.js"},files:["dist"],engines:{node:">=20"},scripts:{dev:"bun src/cli.ts",build:"bun build src/cli.ts --target=node --minify --outfile dist/envhound.js",test:"bun test",typecheck:"tsc",prepublishOnly:"bun run typecheck && bun run build && bun test"},devDependencies:{"@types/bun":"^1.4.2","@types/node":"^26.6.4",typescript:"^7.0.2"}};import{statSync as _n}from"node:fs";function _(e,n){return e.assignments.filter((t)=>t.name===n&&!t.local)}function Re(e,n){let t=_(e,n).at(-1);if(!t)return;let i=e.final[n];if(t.result===void 0)return i===void 0?"unset":"not-effective";if(i===void 0)return"not-exported";return t.result===i?"effective":"not-effective"}function Z(e){return e.via?.kind==="function"?e.via.at:e.at}var Hn=new Set(["PWD","OLDPWD","SHLVL","_"]);function re(e,n){return Object.keys(n).filter((t)=>t!=="_"&&n[t]!==void 0).sort().map((t)=>{let i=_(e,t),r=n[t];return{name:t,value:r,kind:i.length?"startup":(t in e.final)?"shell":"inherited",last:i.at(-1),count:i.length,status:Re(e,t),differsFromFresh:!Hn.has(t)&&t in e.final&&e.final[t]!==r}})}function he(e,n,t){return{name:n,assignments:_(e,n),status:Re(e,n),fresh:e.final[n],current:t[n],pathSteps:n==="PATH"?Me(e):void 0}}var F=(e)=>e===void 0?[]:e.split(":"),pe=(e)=>[...new Set(e)];function Me(e){let n=e.initial.PATH??"",t=[{value:n,added:pe(F(n)),removed:[],reordered:!1}];for(let i of _(e,"PATH")){let r=i.result??"",s=new Set(F(n)),a=new Set(F(r)),l=pe(F(r).filter((o)=>!s.has(o))),c=pe(F(n).filter((o)=>!a.has(o))),u=!l.length&&!c.length&&[...s].join(":")!==[...a].join(":");t.push({assignment:i,value:r,added:l,removed:c,reordered:u}),n=r}return t}function Nn(e){try{return _n(e).isDirectory()}catch{return!1}}function z(e,n){let t=new Map;for(let r of Me(e)){for(let s of r.removed)t.delete(s);for(let s of r.added)t.set(s,r.assignment??"initial")}let i=new Map;return F(n).map((r,s)=>{let a=t.get(r),l=s+1,c=i.get(r);if(c===void 0)i.set(r,l);return{index:l,dir:r,exists:r!==""&&Nn(r),duplicateOf:c,source:a===void 0?"inherited":a==="initial"?"initial":"startup",addedBy:a==="initial"?void 0:a}})}var Vn={list:"every exported variable and where it is set",blame:"every startup line that assigns a variable",path:"PATH entries, who added them, missing and duplicates",dotenv:"check .env files against your shell",set:"set variables for future login shells (or a .env file)",unset:"remove variables envhound set",edit:"interactive editor for variables, PATH and .env files",completion:"print a shell completion script",upgrade:"update envhound to the latest release"},Cn={"--json":"machine-readable output","--show-secrets":"don't mask secret values","--home":"act as if HOME were DIR","--file":"set/unset: edit this .env file","--yes":"write without asking","--dry-run":"show the diff, write nothing","--append":"path add: put DIR at the end","--help":"show help","--version":"show the version"},ie=["bash","zsh","fish"],Le=new Set(["--home","--file","-f"]),jn={add:"put a directory in PATH",remove:"remove a directory envhound added"};function _e(e,n){let t=e.at(-1)??"",i=e.slice(0,-1);if(Le.has(i.at(-1)??""))return[];let r=i.filter((a,l)=>!a.startsWith("-")&&!Le.has(i[l-1]??"")),s=[];if(t.startsWith("-"))s=Object.entries(Cn);else if(r.length===0)s=Object.entries(Vn);else if(r[0]==="blame"&&r.length===1)s=Object.keys(n).sort().map((a)=>[a]);else if(r[0]==="unset")s=Object.keys(n).sort().map((a)=>[a]);else if(r[0]==="set"&&!t.includes("="))s=Object.keys(n).filter((a)=>a!=="PATH").sort().map((a)=>[`${a}=`]);else if(r[0]==="path"&&r.length===1)s=Object.entries(jn);else if(r.length===1&&r[0]==="completion")s=ie.map((a)=>[a]);return s.filter(([a])=>a.startsWith(t)).map(([a,l])=>l?`${a} ${l}`:a)}function He(e){switch(e){case"bash":return`# envhound completion for bash. Add to ~/.bashrc: eval "$(envhound completion bash)"
3
3
  _envhound() {
4
4
  local cur=\${COMP_WORDS[COMP_CWORD]}
5
5
  case \${COMP_WORDS[COMP_CWORD-1]} in
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "envhound",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Find which startup file sets each environment variable, and audit your PATH",
5
5
  "keywords": [
6
6
  "environment",