Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@namchee/dependent

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@namchee/dependent - npm Package Compare versions

Comparing version 0.6.3 to 0.7.0

rollup.config.js

50

bin/index.js
#!/usr/bin/env node
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const ora_1 = __importDefault(require("ora"));
const chalk_1 = __importDefault(require("chalk"));
const cli_1 = require("./cli");
const package_1 = require("./package");
const file_1 = require("./file");
const import_1 = require("./import");
const logger_1 = require("./logger");
(() => __awaiter(void 0, void 0, void 0, function* () {
const args = cli_1.cli.parseSync();
const spinner = ora_1.default().start();
try {
const dependency = args.package;
spinner.text = chalk_1.default.greenBright('Scanning project directory...');
const projectDef = package_1.resolvePackageJSON();
const module = args.module || args.require || projectDef.isModule;
const silent = args.silent;
const table = args.table;
spinner.text = chalk_1.default.greenBright('Checking package installation...');
package_1.isDefined(dependency, projectDef);
yield package_1.isInstalled(dependency);
spinner.text = chalk_1.default.greenBright('Analyzing package dependency...');
const files = file_1.getProjectFiles(args.files, silent);
const dependant = import_1.getDependantFiles(files, dependency, {
module,
silent,
});
spinner.succeed(chalk_1.default.greenBright('Analysis completed successfully'));
logger_1.showDependantFiles(dependant, dependency, table);
}
catch (err) {
const error = err;
spinner.fail(chalk_1.default.redBright(error.message));
console.log(chalk_1.default.cyanBright('Terminating...'));
}
}))();
"use strict";var e=require("ora"),t=require("chalk"),n=require("yargs"),s=require("fs"),a=require("path"),r=require("child_process"),i=require("glob"),o=require("acorn"),c=require("acorn-walk"),l=require("typescript"),u=require("acorn-jsx");function d(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var p=d(e),f=d(t),g=d(n),m=d(i),h=d(l),y=d(u);function x(e,t,n,s){return new(n||(n=Promise))((function(a,r){function i(e){try{c(s.next(e))}catch(e){r(e)}}function o(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?a(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,o)}c((s=s.apply(e,t||[])).next())}))}const S=g.default.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|__tests__|test)/**/*!(.spec|test).js","!(node_modules|__tests__|test)/**/*!(.spec|test).mjs","!(node_modules|__tests__|test)/**/*!(.spec|test).cjs","!(node_modules|__tests__|test)/**/*!(.spec|test).ts","!(node_modules|__tests__|test)/**/*!(.spec|test).jsx","!(node_modules|__tests__|test)/**/*!(.spec|test).tsx","*!(.spec|test).js","*!(.spec|test).mjs","*!(.spec|test).cjs","*!(.spec|test).ts","*!(.spec|test).jsx","*!(.spec|test).tsx"]}).options({module:{alias:"m",describe:"Parse all files as ES module files",type:"boolean",default:void 0,demandOption:!1,conflicts:"script"},require:{alias:"r",describe:"Parse all files as JS scripts",type:"boolean",default:void 0,demandOption:!1,conflicts:"module"},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}});const b=o.Parser.extend(y.default());const k={cjs:function(e,t){return function(e,t){const n=[];return c.simple(e,{CallExpression(e){const s=e;"Identifier"===s.callee.type&&"require"===s.callee.name&&"Literal"===s.arguments[0].type&&s.arguments[0].value===t&&n.push(e.loc.start.line)}}),n}(o.parse(e,{ecmaVersion:"latest",locations:!0,allowHashBang:!0,sourceType:"module"}),t)},mjs:function(e,t){return function(e,t){const n=[];return c.simple(e,{ImportExpression(e){const s=e;"Literal"===s.source.type&&s.source.value===t&&n.push(e.loc.start.line)},ImportDeclaration(e){const s=e;"Literal"===s.source.type&&s.source.value===t&&n.push(e.loc.start.line)},CallExpression(e){const s=e;"Identifier"===s.callee.type&&"require"===s.callee.name&&"Literal"===s.arguments[0].type&&s.arguments[0].value===t&&n.push(e.loc.start.line)}}),n}(o.parse(e,{ecmaVersion:"latest",locations:!0,allowHashBang:!0,sourceType:"module"}),t)},ts:function(e,t){return function(e,t){const n=[],s=a=>{switch(a.kind){case h.default.SyntaxKind.ImportDeclaration:{const s=a.moduleSpecifier;s.kind===h.default.SyntaxKind.StringLiteral&&s.getText().slice(1,-1)===t&&n.push(e.getLineAndCharacterOfPosition(a.getStart()).line+1);break}case h.default.SyntaxKind.CallExpression:{const s=a,r=s.expression,i=s.arguments,o=r.kind===h.default.SyntaxKind.ImportKeyword&&1===i.length&&i[0].kind===h.default.SyntaxKind.StringLiteral&&i[0].getText().slice(1,-1)===t,c=r.kind===h.default.SyntaxKind.Identifier&&"require"===r.getText()&&1===i.length&&i[0].kind===h.default.SyntaxKind.StringLiteral&&i[0].getText().slice(1,-1)===t;(o||c)&&n.push(e.getLineAndCharacterOfPosition(a.getStart()).line+1);break}}h.default.forEachChild(a,s)};return s(e),n}(h.default.createSourceFile("",e,h.default.ScriptTarget.Latest,!0),t)},jsx:function(e,t){return function(e,t){const n=[];return c.simple(e,{ImportExpression(e){const s=e;"Literal"===s.source.type&&s.source.value===t&&n.push(e.loc.start.line)},ImportDeclaration(e){const s=e;"Literal"===s.source.type&&s.source.value===t&&n.push(e.loc.start.line)},CallExpression(e){const s=e;"Identifier"===s.callee.type&&"require"===s.callee.name&&"Literal"===s.arguments[0].type&&s.arguments[0].value===t&&n.push(e.loc.start.line)}},Object.assign(Object.assign({},c.base),{JSXElement:()=>{}})),n}(b.parse(e,{ecmaVersion:"latest",locations:!0,allowHashBang:!0,sourceType:"module"}),t)},tsx:function(e,t){return function(e,t){const n=[],s=a=>{switch(a.kind){case h.default.SyntaxKind.ImportDeclaration:{const s=a.moduleSpecifier;s.kind===h.default.SyntaxKind.StringLiteral&&s.getText().slice(1,-1)===t&&n.push(e.getLineAndCharacterOfPosition(a.getStart()).line+1);break}case h.default.SyntaxKind.CallExpression:{const s=a,r=s.expression,i=s.arguments,o=r.kind===h.default.SyntaxKind.ImportKeyword&&1===i.length&&i[0].kind===h.default.SyntaxKind.StringLiteral&&i[0].getText().slice(1,-1)===t,c=r.kind===h.default.SyntaxKind.Identifier&&"require"===r.getText()&&1===i.length&&i[0].kind===h.default.SyntaxKind.StringLiteral&&i[0].getText().slice(1,-1)===t;(o||c)&&n.push(e.getLineAndCharacterOfPosition(a.getStart()).line+1);break}}h.default.forEachChild(a,s)};return s(e),n}(h.default.createSourceFile("",e,h.default.ScriptTarget.Latest,!0,h.default.ScriptKind.TSX),t)}};function j(e){if(!(e in k))throw new Error(`.${e} files are currently not supported`);return k[e]}function _(e,t,n){console.log("\n"+f.default.cyanBright(`📦 There are ${e.length} files in this project that depends on '${t}'`)),e.length&&(n?function(e){const t=e.map((e=>({"File name":e.name,"File path":e.path,"Line number":e.lineNumbers.join(", ")})));console.table(t)}(e):function(e){e.forEach((({name:e,path:t,lineNumbers:n})=>{console.log(f.default.cyan(` └── ${e}:${n.join(", ")} → ${t}`))}))}(e))}x(void 0,void 0,void 0,(function*(){const e=S.parseSync(),t=p.default().start();try{const n=e.package;t.text=f.default.greenBright("Scanning project directory...");const i=function(){const e=process.cwd(),t=a.resolve(e,"package.json");if(!s.existsSync(t))throw new Error("The current project directory is not a NodeJS-based project");try{const e=require(t);return{name:e.name,dependencies:e.dependencies,devDependencies:e.devDependencies,peerDependencies:e.peerDependencies,isModule:e.type&&"module"===e.type}}catch(e){throw new Error("Invalid package.json schema")}}(),o=e.module||e.require||i.isModule,c=e.silent,l=e.table;t.text=f.default.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`)}(n,i),yield function(e){return new Promise(((t,n)=>{r.spawn(/^win/.test(process.platform)?"npm.cmd":"npm",["ls",e]).stdout.on("data",(s=>{s.includes(e)&&0!==s.lastIndexOf(e)?t():n(new Error(`Package ${e} is not installed in this project`))}))}))}(n),t.text=f.default.greenBright("Analyzing package dependency...");const u=function(e,t,{module:n,silent:s}){const a=[];for(const r of e){const e=r.name.endsWith("js")?n?"mjs":"cjs":r.name.split(".").pop();try{const n=j(e)(r.content,t);n.length&&a.push({name:r.name,path:r.path,lineNumbers:n})}catch(e){const t=e;if(s)continue;throw new Error(`Failed to parse ${r.path}: ${t.message}`)}}return a}(function(e,t){const n=m.default.sync(`{${e.join(",")}}`,{silent:!0}),r=[];for(const e of n)try{const t=a.basename(e),n=s.readFileSync(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}(e.files,c),n,{module:o,silent:c});t.succeed(f.default.greenBright("Analysis completed successfully")),_(u,n,l)}catch(e){const n=e;t.fail(f.default.redBright(n.message)),console.log(f.default.cyanBright("Terminating..."))}}));

@@ -0,1 +1,13 @@

# v0.7.0 (Fri Aug 06 2021)
#### 🚀 Enhancement
- feat: Add minification process [#24](https://github.com/Namchee/dependent/pull/24) ([@Namchee](https://github.com/Namchee))
#### Authors: 1
- Cristopher ([@Namchee](https://github.com/Namchee))
---
# v0.6.3 (Fri Aug 06 2021)

@@ -2,0 +14,0 @@

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

@@ -19,4 +19,4 @@ "repository": "git@github.com:Namchee/dependent.git",

"lint:fix": "eslint src/**/*.ts --fix",
"build": "tsc",
"build:watch": "tsc --watch",
"build": "rollup -c rollup.config.js",
"build:watch": "rollup -c rollup.config.js -w",
"test": "jest",

@@ -53,2 +53,6 @@ "test:watch": "jest --watch"

"prettier": "^2.3.2",
"rollup": "^2.56.0",
"rollup-plugin-preserve-shebang": "^1.0.1",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.30.0",
"stylelint": "^13.13.1",

@@ -55,0 +59,0 @@ "stylelint-config-standard": "^22.0.0",

@@ -23,6 +23,8 @@ import yargs from 'yargs';

default: [
'!(node_modules|__tests__)/**/*!(.spec|test).js',
'!(node_modules|__tests__)/**/*!(.spec|test).mjs',
'!(node_modules|__tests__)/**/*!(.spec|test).cjs',
'!(node_modules|__tests__)/**/*!(.spec|test).ts',
'!(node_modules|__tests__|test)/**/*!(.spec|test).js',
'!(node_modules|__tests__|test)/**/*!(.spec|test).mjs',
'!(node_modules|__tests__|test)/**/*!(.spec|test).cjs',
'!(node_modules|__tests__|test)/**/*!(.spec|test).ts',
'!(node_modules|__tests__|test)/**/*!(.spec|test).jsx',
'!(node_modules|__tests__|test)/**/*!(.spec|test).tsx',
'*!(.spec|test).js',

@@ -32,2 +34,4 @@ '*!(.spec|test).mjs',

'*!(.spec|test).ts',
'*!(.spec|test).jsx',
'*!(.spec|test).tsx',
],

@@ -34,0 +38,0 @@ })

@@ -1,2 +0,2 @@

import { cyan, cyanBright } from 'chalk';
import chalk from 'chalk';

@@ -32,3 +32,3 @@ import { DependantFile } from './types';

console.log(
cyan(
chalk.cyan(
` └── ${name}:${lineNumbers.join(', ')} → ${path}`,

@@ -53,5 +53,4 @@ ),

): void {
console.log();
console.log(
cyanBright(
console.log('\n' +
chalk.cyanBright(
// eslint-disable-next-line max-len

@@ -58,0 +57,0 @@ `📦 There are ${files.length} files in this project that depends on '${dependency}'`,

@@ -5,3 +5,3 @@ {

"outDir": "./bin",
"module": "commonjs",
"module": "esnext"
},

@@ -8,0 +8,0 @@ "include": [

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc