Socket
Socket
Sign inDemoInstall

@namchee/dependent

Package Overview
Dependencies
66
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.13.0 to 0.14.0

2

bin/index.js
#!/usr/bin/env node
import e from"ora";import t from"chalk";import n from"yargs";import{resolve as r,basename as o}from"path";import{existsSync as s,readFileSync as i}from"fs";import{spawn as a}from"child_process";import c from"glob";import{Parser as l}from"acorn";import{simple as p,base as u}from"acorn-walk";import d from"acorn-jsx";import{pathToFileURL as f}from"url";import{table as m}from"table";const h=n(process.argv.slice(2)).scriptName("dependent").command("$0 <package> [files...]","Analyze package usage in your project directory.").usage("Usage: $0 <package> [files...]").positional("package",{alias:"p",type:"string",description:"Package name to be analyzed."}).positional("files",{alias:"f",type:"string",description:"Files to be analyzed in glob pattern relative to the current project directory.",default:["!(node_modules)/**/*.js","!(node_modules)/**/*.mjs","!(node_modules)/**/*.ts","!(node_modules)/**/*.jsx","!(node_modules)/**/*.tsx","!(node_modules)/**/*.vue","!(node_modules)/**/*.svelte","*.js","*.mjs","*.ts","*.jsx","*.tsx","*.vue","*.svelte"]}).options({silent:{alias:"s",describe:"Skip all unreadable and unparseable files instead of throwing errors",type:"boolean",default:!1,demandOption:!1},table:{alias:"t",describe:"Print the output in table format",type:"boolean",default:!1,demandOption:!1},precheck:{alias:"c",describe:"Check if the package is installed",type:"boolean",default:!0,demandOption:!1},include:{describe:"Type of possible dependant to be scanned for dependency. Defaults to files and scripts",type:"array",default:["scripts","files"],demandOption:!1}});function g(e,t){return new Promise(((n,r)=>{const o=a(e,t);o.stdout.on("data",(e=>n(e))),o.on("error",(()=>r(new Error("Command not found"))))}))}const y={npm:"ls",pnpm:"ls",yarn:"why"};function v(){var e,t,n,o,a,c;const l=r(process.cwd(),"package.json");if(!s(l))throw new Error("The current project directory is not a NodeJS-based project");try{const r=JSON.parse(i(l,"utf-8"));return{name:null!==(e=r.name)&&void 0!==e?e:"",executables:null!==(t=r.bin)&&void 0!==t?t:{},scripts:null!==(n=r.scripts)&&void 0!==n?n:{},dependencies:null!==(o=r.dependencies)&&void 0!==o?o:{},devDependencies:null!==(a=r.devDependencies)&&void 0!==a?a:{},peerDependencies:null!==(c=r.peerDependencies)&&void 0!==c?c:{}}}catch(e){const{message:t}=e;throw new Error(`Failed to read package.json: ${t}`)}}async function w(e){let t=function(){const e=r(process.cwd(),"package-lock.json");if(s(e))return"npm";const t=r(process.cwd(),"yarn.lock");return s(t)?"yarn":"pnpm"}();const n=y[t];/^win/.test(process.platform)&&(t=`${t}.cmd`);const o=await g(t,[n,e]);if(!(o.includes(e)&&0!==o.lastIndexOf(e)))throw new Error(`Package ${e} has not been installed in this project`)}function j(e){const t=e.split("/");return e.startsWith("@")?t.slice(0,2).join("/"):t[0]}const b=l.extend(d());async function S(e,t){return function(e,t){const n=[];return p(e,{ImportExpression(e){var r;const o=e;"Literal"===o.source.type&&j(null===(r=o.source.value)||void 0===r?void 0:r.toString())===t&&n.push(e.loc.start.line)},ImportDeclaration(e){var r;const o=e;"Literal"===o.source.type&&j(null===(r=o.source.value)||void 0===r?void 0:r.toString())===t&&n.push(e.loc.start.line)},CallExpression(e){var r;const o=e;"Identifier"===o.callee.type&&"require"===o.callee.name&&"Literal"===o.arguments[0].type&&j(null===(r=o.arguments[0].value)||void 0===r?void 0:r.toString())===t&&n.push(e.loc.start.line)}},Object.assign(Object.assign({},u),{JSXElement(){}})),n}(b.parse(e,{ecmaVersion:"latest",locations:!0,allowHashBang:!0,sourceType:"module"}),t)}let k,x,E;function $(e,t,n){const r=[];return e.walk(t,{enter(e){var t,o,s;switch(e.type){case"ImportDeclaration":{const o=e;"Literal"===o.source.type&&j(null===(t=o.source.value)||void 0===t?void 0:t.toString())===n&&r.push(e.loc.start.line);break}case"ImportExpression":{const t=e;"Literal"===t.source.type&&j(null===(o=t.source.value)||void 0===o?void 0:o.toString())===n&&r.push(e.loc.start.line);break}case"CallExpression":{const t=e;"Identifier"===t.callee.type&&"require"===t.callee.name&&"Literal"===t.arguments[0].type&&j(null===(s=t.arguments[0].value)||void 0===s?void 0:s.toString())===n&&r.push(e.loc.start.line);break}}}}),r}async function O(e){if(x)return;const t=["typescript","lib","typescript.js"],n=[r(process.cwd(),"node_modules",...t),...e.map((e=>r(e,...t)))].map((e=>import(f(e).toString()))),o=await Promise.allSettled(n);for(let e=0;e<o.length;e++){const t=o[e];if("fulfilled"===t.status)return void(x=t.value.default)}throw new Error("No TypeScript parsers available")}async function F(e,t){if(!x)throw new Error("TypeScript compiler has not been loaded");return function(e,t){const n=[],r=o=>{switch(o.kind){case x.SyntaxKind.ImportDeclaration:{const r=o.moduleSpecifier;10===r.kind&&j(r.getText().slice(1,-1))===t&&n.push(e.getLineAndCharacterOfPosition(o.getStart()).line+1);break}case x.SyntaxKind.CallExpression:{const r=o,{expression:s}=r,i=r.arguments,a=s.kind===x.SyntaxKind.ImportKeyword&&1===i.length&&i[0].kind===x.SyntaxKind.StringLiteral&&j(i[0].getText().slice(1,-1))===t,c=s.kind===x.SyntaxKind.Identifier&&"require"===s.getText()&&1===i.length&&i[0].kind===x.SyntaxKind.StringLiteral&&j(i[0].getText().slice(1,-1))===t;(a||c)&&n.push(e.getLineAndCharacterOfPosition(o.getStart()).line+1);break}}x.forEachChild(o,r)};return r(e),n}(x.createSourceFile("",e,x.ScriptTarget.Latest,!0,x.ScriptKind.TSX),t)}const T={js:S,mjs:S,cjs:S,jsx:S,ts:F,vue:async function(e,t){var n;if(!E)throw new Error("Vue 3 compiler has not been loaded yet");const r=E.parse(e),o=null!==(n=r.descriptor.script)&&void 0!==n?n:r.descriptor.scriptSetup;if(o){const e=o.loc.start.line,n="ts"===o.lang?F:S;return(await n(o.content,t)).map((t=>t+e-1))}return[]},svelte:async function(e,t){if(!k)throw new Error("Svelte compiler has not been loaded");const n=k.parse(e);return[...$(k,n.instance,t),...$(k,n.module,t)]}},P={ts:O,tsx:O,vue:async function(e){if(E)return;const t=["@vue","compiler-sfc","dist","compiler-sfc.cjs.js"],n=[r(process.cwd(),"node_modules",...t),...e.map((e=>r(e,...t)))].map((e=>import(f(e).toString()))),o=await Promise.allSettled(n);for(let e=0;e<o.length;e++){const t=o[e];if("fulfilled"===t.status)return void(E=t.value.default)}throw new Error("No Vue 3 parser available")},svelte:async function(e){if(k)return;const t=["svelte","compiler.js"],n=[r(process.cwd(),"node_modules",...t),...e.map((e=>r(e,...t)))].map((e=>import(f(e).toString()))),o=await Promise.allSettled(n);for(let e=0;e<o.length;e++){const t=o[e];if("fulfilled"===t.status)return void(k=t.value.default)}throw new Error("No Svelte compiler available")}};const D={js:"JavaScript Files",cjs:"CommonJS Files",mjs:"ESModule Files",jsx:"JavaScript Extended Files",ts:"TypeScript Files",tsx:"TypeScript Extended Files",vue:"Vue's Single File Component",svelte:"Svelte's Single File Component"};function _(e){return e.name.split(".").pop()}let C,L;async function N(){if(C)return C;const e=await g(/^win/.test(process.platform)?"npm.cmd":"npm",["root","--global"]);return C=e.toString().trim(),C}async function I(){if(L)return L;const e=await g(/^win/.test(process.platform)?"yarn.cmd":"yarn",["global","dir"]);return L=r(e.toString().trim(),"node_modules"),L}async function B(e,n,{silent:r}){await async function(e){const t=(await Promise.allSettled([N(),I(),I()])).map((e=>"fulfilled"===e.status?e.value:"")).filter(Boolean),n=[...new Set(e.map((e=>_(e))).filter((e=>!["js","cjs","mjs","jsx"].includes(e))))].map((e=>{try{return function(e){if(!(e in P))throw new Error(`.${e} files are currently not supported`);return P[e]}(e)(t)}catch(t){throw new Error(`Failed to load compiler for ${D[e]}: ${t.message}`)}}));await Promise.all(n)}(e);const o=e.map((async e=>{try{const t=function(e){if(!(e in T))throw new Error(`.${e} files are currently not supported`);return T[e]}(_(e)),r=await t(e.content,n);return r.length?{name:e.name,path:e.path,lineNumbers:r}:null}catch(t){const n=t;throw new Error(`Failed to parse ${e.path}: ${n.message}`)}}));if(!r){return(await Promise.all(o)).filter((e=>null!==e))}const s=await Promise.allSettled(o),i=[];for(const e of s)"rejected"===e.status?console.log(t.yellow(e.reason)):e.value&&i.push(e.value);return i}function J(e){const{scripts:t}=v(),{executables:n}=function(e){var t,n,o,a,c,l;const p=r(process.cwd(),"node_modules",e,"package.json");if(!s(p))throw new Error("The current project directory is not a NodeJS-based project");try{const e=JSON.parse(i(p,"utf-8"));return{name:null!==(t=e.name)&&void 0!==t?t:"",executables:null!==(n=e.bin)&&void 0!==n?n:{},scripts:null!==(o=e.scripts)&&void 0!==o?o:{},dependencies:null!==(a=e.dependencies)&&void 0!==a?a:{},devDependencies:null!==(c=e.devDependencies)&&void 0!==c?c:{},peerDependencies:null!==(l=e.peerDependencies)&&void 0!==l?l:{}}}catch(e){const{message:t}=e;throw new Error(`Failed to read package.json: ${t}`)}}(e),o=[];if(Object.keys(n).length){const e=`(${Object.keys(n).join("|")})`;for(const[n,r]of Object.entries(t))r.match(e)&&o.push(n)}return o}function K(e,t){const n=e.path.split("/").length,r=t.path.split("/").length;return n>r?1:n<r?-1:e.name>t.name?1:-1}function A(e,n,r){return t.cyanBright(`${{files:"📁",scripts:"📜"}[e]} There are ${r} ${e} in this project that depends on '${n}'`)}function z(e){const t=[];for(const[n,r]of Object.entries(e)){const e=D[n];if(r.length){const n=`📜 ${e}`,o=r.map((e=>[e.name,e.path,e.lineNumbers.join(", ")])),s=m([["Filename","Path","Line Number"],...o]);t.push(n+"\n"+s)}}return t.join("\n").slice(0,-1)}function V(e){const n=[];for(const[r,o]of Object.entries(e)){const e=D[r];if(o.length){const r=`📜 ${e}`,s=o.map((({name:e,path:n,lineNumbers:r})=>t.cyan(` └── ${e}:${r.join(", ")} → ${n}`)));n.push(r+"\n"+s.join("\n"))}}return n.join("\n\n")}function q(e){return e.map((e=>t.cyan(` └── ${e}`))).join("\n")}function X(e){return m([["Script"],e.map((e=>[e]))]).slice(0,-1)}function H(e,t,{format:n}){const r=[A("files",t,e.length)],o={lines:V,table:z},s=function(e){const t={js:[],cjs:[],mjs:[],jsx:[],ts:[],tsx:[],vue:[],svelte:[]};for(const n of e)t[n.name.split(".").pop()].push(n);for(const e of Object.values(t))e.sort(K);return t}(e);return e.length&&r.push(o[n](s)),r.join("\n\n")}(async()=>{const n=h.parseSync(),r=e().start();try{const e=n.package;r.text=t.greenBright("Scanning project directory...");const{silent:s,table:a,precheck:l,include:p}=n;l&&(r.text=t.greenBright("Checking package installation..."),function(e,t){if(!(Object.keys(t.dependencies||{}).includes(e)||Object.keys(t.devDependencies||{}).includes(e)||Object.keys(t.peerDependencies||{}).includes(e)))throw new Error(`Package ${e} is not defined in this project`)}(e,v()),await w(e));const u=function(e,t){const n=c.sync(`{${e.join(",")}}`,{silent:!0}),r=[];for(const e of n)try{const t=o(e),n=i(e,"utf-8");r.push({name:t,path:e,content:n})}catch(n){if(t)continue;throw new Error(`Failed to read ${e}`)}return r}(n.files,s);r.text=t.greenBright("Analyzing project for dependency...");const d=[];if(p.includes("files")){const t=await B(u,e,{silent:s});d.push(H(t,e,{format:a?"table":"lines"}))}if(p.includes("scripts")){const t=J(e);d.push(function(e,t,{format:n}){const r=[A("scripts",t,e.length)],o={lines:q,table:X};return e.length&&r.push(o[n](e)),r.join("\n")}(t,e,{format:a?"table":"lines"}))}r.succeed(t.greenBright("Analysis completed successfully")),console.log(d.join("\n\n"))}catch(e){const n=e;r.fail(t.redBright(n.message)),console.log(t.cyanBright("Terminating..."))}})();
import e from"ora";import t from"chalk";import n from"yargs";import{resolve as r,basename as o}from"path";import{existsSync as s,readFileSync as i}from"fs";import{spawn as a}from"child_process";import c from"glob";import{Parser as l}from"acorn";import{simple as p,base as u}from"acorn-walk";import d from"acorn-jsx";import{pathToFileURL as f}from"url";import{table as m}from"table";const h=n(process.argv.slice(2)).scriptName("dependent").command("$0 <package> [files...]","Analyze package usage in your project directory.").usage("Usage: $0 <package> [files...]").positional("package",{alias:"p",type:"string",description:"Package name to be analyzed."}).positional("files",{alias:"f",type:"string",description:"Files to be analyzed in glob pattern relative to the current project directory.",default:["!(node_modules)/**/*.js","!(node_modules)/**/*.mjs","!(node_modules)/**/*.ts","!(node_modules)/**/*.jsx","!(node_modules)/**/*.tsx","!(node_modules)/**/*.vue","!(node_modules)/**/*.svelte","*.js","*.mjs","*.ts","*.jsx","*.tsx","*.vue","*.svelte"]}).options({silent:{alias:"s",describe:"Skip all unreadable and unparseable files instead of throwing errors",type:"boolean",default:!1,demandOption:!1},table:{alias:"t",describe:"Print the output in table format",type:"boolean",default:!1,demandOption:!1},precheck:{alias:"c",describe:"Check if the package is installed",type:"boolean",default:!0,demandOption:!1},include:{describe:"Type of possible dependant to be scanned for dependency. Defaults to files and scripts",type:"array",default:["scripts","files"],demandOption:!1}});function g(e,t){return new Promise(((n,r)=>{const o=a(e,t);o.stdout.on("data",(e=>n(e))),o.on("error",(()=>r(new Error("Command not found"))))}))}const y={npm:"ls",pnpm:"ls",yarn:"why"};function v(){var e,t,n,o,a,c;const l=r(process.cwd(),"package.json");if(!s(l))throw new Error("The current project directory is not a NodeJS-based project");try{const r=JSON.parse(i(l,"utf-8"));return{name:null!==(e=r.name)&&void 0!==e?e:"",executables:null!==(t=r.bin)&&void 0!==t?t:{},scripts:null!==(n=r.scripts)&&void 0!==n?n:{},dependencies:null!==(o=r.dependencies)&&void 0!==o?o:{},devDependencies:null!==(a=r.devDependencies)&&void 0!==a?a:{},peerDependencies:null!==(c=r.peerDependencies)&&void 0!==c?c:{}}}catch(e){const{message:t}=e;throw new Error(`Failed to read package.json: ${t}`)}}async function w(e){let t=function(){const e=r(process.cwd(),"package-lock.json");if(s(e))return"npm";const t=r(process.cwd(),"yarn.lock");return s(t)?"yarn":"pnpm"}();const n=y[t];/^win/.test(process.platform)&&(t=`${t}.cmd`);const o=await g(t,[n,e]);if(!(o.includes(e)&&0!==o.lastIndexOf(e)))throw new Error(`Package ${e} has not been installed in this project`)}function j(e){const t=e.split("/");return e.startsWith("@")?t.slice(0,2).join("/"):t[0]}const b=l.extend(d());async function S(e,t){return function(e,t){const n=[];return p(e,{ImportExpression(e){var r;const o=e;"Literal"===o.source.type&&j(null===(r=o.source.value)||void 0===r?void 0:r.toString())===t&&n.push(e.loc.start.line)},ImportDeclaration(e){var r;const o=e;"Literal"===o.source.type&&j(null===(r=o.source.value)||void 0===r?void 0:r.toString())===t&&n.push(e.loc.start.line)},CallExpression(e){var r;const o=e;"Identifier"===o.callee.type&&"require"===o.callee.name&&"Literal"===o.arguments[0].type&&j(null===(r=o.arguments[0].value)||void 0===r?void 0:r.toString())===t&&n.push(e.loc.start.line)}},Object.assign(Object.assign({},u),{JSXElement(){}})),n}(b.parse(e,{ecmaVersion:"latest",locations:!0,allowHashBang:!0,sourceType:"module"}),t)}let k,x,E;function $(e,t,n){const r=[];return e.walk(t,{enter(e){var t,o,s;switch(e.type){case"ImportDeclaration":{const o=e;"Literal"===o.source.type&&j(null===(t=o.source.value)||void 0===t?void 0:t.toString())===n&&r.push(e.loc.start.line);break}case"ImportExpression":{const t=e;"Literal"===t.source.type&&j(null===(o=t.source.value)||void 0===o?void 0:o.toString())===n&&r.push(e.loc.start.line);break}case"CallExpression":{const t=e;"Identifier"===t.callee.type&&"require"===t.callee.name&&"Literal"===t.arguments[0].type&&j(null===(s=t.arguments[0].value)||void 0===s?void 0:s.toString())===n&&r.push(e.loc.start.line);break}}}}),r}async function O(e){if(x)return;const t=["typescript","lib","typescript.js"],n=[r(process.cwd(),"node_modules",...t),...e.map((e=>r(e,...t)))].map((e=>import(f(e).toString()))),o=await Promise.allSettled(n);for(let e=0;e<o.length;e++){const t=o[e];if("fulfilled"===t.status)return void(x=t.value.default)}throw new Error("No TypeScript parsers available")}async function F(e,t){if(!x)throw new Error("TypeScript compiler has not been loaded");return function(e,t){const n=[],r=o=>{switch(o.kind){case x.SyntaxKind.ImportDeclaration:{const r=o.moduleSpecifier;10===r.kind&&j(r.getText().slice(1,-1))===t&&n.push(e.getLineAndCharacterOfPosition(o.getStart()).line+1);break}case x.SyntaxKind.CallExpression:{const r=o,{expression:s}=r,i=r.arguments,a=s.kind===x.SyntaxKind.ImportKeyword&&1===i.length&&i[0].kind===x.SyntaxKind.StringLiteral&&j(i[0].getText().slice(1,-1))===t,c=s.kind===x.SyntaxKind.Identifier&&"require"===s.getText()&&1===i.length&&i[0].kind===x.SyntaxKind.StringLiteral&&j(i[0].getText().slice(1,-1))===t;(a||c)&&n.push(e.getLineAndCharacterOfPosition(o.getStart()).line+1);break}}x.forEachChild(o,r)};return r(e),n}(x.createSourceFile("",e,x.ScriptTarget.Latest,!0,x.ScriptKind.TSX),t)}const T={js:S,mjs:S,cjs:S,jsx:S,ts:F,vue:async function(e,t){var n;if(!E)throw new Error("Vue 3 compiler has not been loaded yet");const r=E.parse(e),o=null!==(n=r.descriptor.script)&&void 0!==n?n:r.descriptor.scriptSetup;if(o){const e=o.loc.start.line,n="ts"===o.lang?F:S;return(await n(o.content,t)).map((t=>t+e-1))}return[]},svelte:async function(e,t){if(!k)throw new Error("Svelte compiler has not been loaded");const n=k.parse(e);return[...$(k,n.instance,t),...$(k,n.module,t)]}},P={ts:O,tsx:O,vue:async function(e){if(E)return;const t=["@vue","compiler-sfc","dist","compiler-sfc.cjs.js"],n=[r(process.cwd(),"node_modules","vue","compiler-sfc","index.js"),r(process.cwd(),"node_modules",...t),...e.map((e=>r(e,...t)))].map((e=>import(f(e).toString()))),o=await Promise.allSettled(n);for(let e=0;e<o.length;e++){const t=o[e];if("fulfilled"===t.status)return void(E=t.value.default)}throw new Error("No Vue 3 parser available")},svelte:async function(e){if(k)return;const t=["svelte","compiler.js"],n=[r(process.cwd(),"node_modules",...t),...e.map((e=>r(e,...t)))].map((e=>import(f(e).toString()))),o=await Promise.allSettled(n);for(let e=0;e<o.length;e++){const t=o[e];if("fulfilled"===t.status)return void(k=t.value.default)}throw new Error("No Svelte compiler available")}};const D={js:"JavaScript Files",cjs:"CommonJS Files",mjs:"ESModule Files",jsx:"JavaScript Extended Files",ts:"TypeScript Files",tsx:"TypeScript Extended Files",vue:"Vue's Single File Component",svelte:"Svelte's Single File Component"};function _(e){return e.name.split(".").pop()}let C,L;async function N(){if(C)return C;const e=await g(/^win/.test(process.platform)?"npm.cmd":"npm",["root","--global"]);return C=e.toString().trim(),C}async function I(){if(L)return L;const e=await g(/^win/.test(process.platform)?"yarn.cmd":"yarn",["global","dir"]);return L=r(e.toString().trim(),"node_modules"),L}async function B(e,n,{silent:r}){await async function(e){const t=(await Promise.allSettled([N(),I(),I()])).map((e=>"fulfilled"===e.status?e.value:"")).filter(Boolean),n=[...new Set(e.map((e=>_(e))).filter((e=>!["js","cjs","mjs","jsx"].includes(e))))].map((e=>{try{return function(e){if(!(e in P))throw new Error(`.${e} files are currently not supported`);return P[e]}(e)(t)}catch(t){throw new Error(`Failed to load compiler for ${D[e]}: ${t.message}`)}}));await Promise.all(n)}(e);const o=e.map((async e=>{try{const t=function(e){if(!(e in T))throw new Error(`.${e} files are currently not supported`);return T[e]}(_(e)),r=await t(e.content,n);return r.length?{name:e.name,path:e.path,lineNumbers:r}:null}catch(t){const n=t;throw new Error(`Failed to parse ${e.path}: ${n.message}`)}}));if(!r){return(await Promise.all(o)).filter((e=>null!==e))}const s=await Promise.allSettled(o),i=[];for(const e of s)"rejected"===e.status?console.log(t.yellow(e.reason)):e.value&&i.push(e.value);return i}function J(e){const{scripts:t}=v(),{executables:n}=function(e){var t,n,o,a,c,l;const p=r(process.cwd(),"node_modules",e,"package.json");if(!s(p))throw new Error("The current project directory is not a NodeJS-based project");try{const e=JSON.parse(i(p,"utf-8"));return{name:null!==(t=e.name)&&void 0!==t?t:"",executables:null!==(n=e.bin)&&void 0!==n?n:{},scripts:null!==(o=e.scripts)&&void 0!==o?o:{},dependencies:null!==(a=e.dependencies)&&void 0!==a?a:{},devDependencies:null!==(c=e.devDependencies)&&void 0!==c?c:{},peerDependencies:null!==(l=e.peerDependencies)&&void 0!==l?l:{}}}catch(e){const{message:t}=e;throw new Error(`Failed to read package.json: ${t}`)}}(e),o=[];if(Object.keys(n).length){const e=`(${Object.keys(n).join("|")})`;for(const[n,r]of Object.entries(t))r.match(e)&&o.push(n)}return o}function K(e,t){const n=e.path.split("/").length,r=t.path.split("/").length;return n>r?1:n<r?-1:e.name>t.name?1:-1}function A(e,n,r){return t.cyanBright(`${{files:"📁",scripts:"📜"}[e]} There are ${r} ${e} in this project that depends on '${n}'`)}function z(e){const t=[];for(const[n,r]of Object.entries(e)){const e=D[n];if(r.length){const n=`📜 ${e}`,o=r.map((e=>[e.name,e.path,e.lineNumbers.join(", ")])),s=m([["Filename","Path","Line Number"],...o]);t.push(n+"\n"+s)}}return t.join("\n").slice(0,-1)}function V(e){const n=[];for(const[r,o]of Object.entries(e)){const e=D[r];if(o.length){const r=`📜 ${e}`,s=o.map((({name:e,path:n,lineNumbers:r})=>t.cyan(` └── ${e}:${r.join(", ")} → ${n}`)));n.push(r+"\n"+s.join("\n"))}}return n.join("\n\n")}function q(e){return e.map((e=>t.cyan(` └── ${e}`))).join("\n")}function X(e){return m([["Script"],e.map((e=>[e]))]).slice(0,-1)}function H(e,t,{format:n}){const r=[A("files",t,e.length)],o={lines:V,table:z},s=function(e){const t={js:[],cjs:[],mjs:[],jsx:[],ts:[],tsx:[],vue:[],svelte:[]};for(const n of e)t[n.name.split(".").pop()].push(n);for(const e of Object.values(t))e.sort(K);return t}(e);return e.length&&r.push(o[n](s)),r.join("\n\n")}(async()=>{const n=h.parseSync(),r=e().start();try{const e=n.package;r.text=t.greenBright("Scanning project directory...");const{silent:s,table:a,precheck:l,include:p}=n;l&&(r.text=t.greenBright("Checking package installation..."),function(e,t){if(!(Object.keys(t.dependencies||{}).includes(e)||Object.keys(t.devDependencies||{}).includes(e)||Object.keys(t.peerDependencies||{}).includes(e)))throw new Error(`Package ${e} is not defined in this project`)}(e,v()),await w(e));const u=function(e,t){const n=c.sync(`{${e.join(",")}}`,{silent:!0}),r=[];for(const e of n)try{const t=o(e),n=i(e,"utf-8");r.push({name:t,path:e,content:n})}catch(n){if(t)continue;throw new Error(`Failed to read ${e}`)}return r}(n.files,s);r.text=t.greenBright("Analyzing project for dependency...");const d=[];if(p.includes("files")){const t=await B(u,e,{silent:s});d.push(H(t,e,{format:a?"table":"lines"}))}if(p.includes("scripts")){const t=J(e);d.push(function(e,t,{format:n}){const r=[A("scripts",t,e.length)],o={lines:q,table:X};return e.length&&r.push(o[n](e)),r.join("\n")}(t,e,{format:a?"table":"lines"}))}r.succeed(t.greenBright("Analysis completed successfully")),console.log(d.join("\n\n"))}catch(e){const n=e;r.fail(t.redBright(n.message)),console.log(t.cyanBright("Terminating..."))}})();

@@ -0,1 +1,19 @@

# v0.12.0 (Fri Jul 28 2023)
#### 🚀 Enhancement
- feat: add CLI support [#52](https://github.com/Namchee/dependent/pull/52) ([@Namchee](https://github.com/Namchee))
#### 🐛 Bug Fix
- fix(vue): add new compiler spec path for vue 3.2+ [#59](https://github.com/Namchee/dependent/pull/59) ([@Namchee](https://github.com/Namchee))
- Docs/pnpm bug notice [#58](https://github.com/Namchee/dependent/pull/58) ([@Namchee](https://github.com/Namchee))
- fix(cli): add 's' to default cli values for include option [#55](https://github.com/Namchee/dependent/pull/55) ([@Namchee](https://github.com/Namchee))
#### Authors: 1
- Cristopher ([@Namchee](https://github.com/Namchee))
---
# v0.12.0 (Fri Jul 21 2023)

@@ -2,0 +20,0 @@

{
"name": "@namchee/dependent",
"version": "0.13.0",
"version": "0.14.0",
"description": "Simple utility CLI tool to analyze which files are using a Node dependency 🚀",

@@ -5,0 +5,0 @@ "repository": "git@github.com:Namchee/dependent.git",

@@ -28,3 +28,4 @@ import typescript from '@rollup/plugin-typescript';

'acorn-jsx',
'table',
]
}

@@ -22,3 +22,3 @@ import { resolve } from 'path';

const compilerPath = [
const oldCompilerPath = [
'@vue',

@@ -30,5 +30,13 @@ 'compiler-sfc',

// For Vue 3.2+
const newCompilerPath = [
'vue',
'compiler-sfc',
'index.js',
];
const paths = [
resolve(process.cwd(), 'node_modules', ...compilerPath),
...globs.map(path => resolve(path, ...compilerPath)),
resolve(process.cwd(), 'node_modules', ...newCompilerPath),
resolve(process.cwd(), 'node_modules', ...oldCompilerPath),
...globs.map(path => resolve(path, ...oldCompilerPath)),
];

@@ -35,0 +43,0 @@

@@ -10,2 +10,2 @@ import { resolve } from 'path';

}
})
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc