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

nmc

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nmc - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

78

bin/nmc.js
#! /usr/bin/env node
const fs = require('fs/promises')
const fs = require('fs')
const path = require('path')
const { promisify } = require('util')
const readdir = promisify(fs.readdir)
const stat = promisify(fs.stat)
const unlink = promisify(fs.unlink)
const rmdir = promisify(fs.rmdir)
if (!Promise.allSettled) {
Promise.allSettled = promises =>
Promise.all(
promises.map((promise) =>
promise
.then(value => ({
status: "fulfilled",
value,
}))
.catch(reason => ({
status: "rejected",
reason,
}))
)
);
}
const search = async (name, base, options) => {
base = base ? path.normalize(base) : process.cwd()
let dir = await fs.readdir(base)
let files = await readdir(base)
let results = []
for (let i = 0; i < dir.length; i++) {
let currentPath = path.join(base, dir[i])
if ((await fs.stat(currentPath)).isDirectory()) {
if (dir[i] === name) {
let actions = files.map(async (file) => {
let currentPath = path.join(base, file)
if ((await stat(currentPath)).isDirectory()) {
if (file === name) {
results.push(currentPath)

@@ -19,3 +41,4 @@ } else {

}
}
})
await Promise.allSettled(actions)

@@ -25,6 +48,17 @@ return results

const clean = (dir) => {
return fs.rm(dir, { recursive: true })
const clean = async (dir) => {
let files = await readdir(dir)
let actions = files.map(async (file) => {
let currentPath = path.join(dir, file)
if ((await stat(currentPath)).isDirectory()) {
await clean(currentPath)
} else {
await unlink(currentPath)
}
})
await Promise.allSettled(actions)
await rmdir(dir)
}
const nmc = () => {
const nmc = async () => {
let options = {}

@@ -35,16 +69,16 @@ let args = process.argv.slice(2)

if (options.log) console.log('\x1b[32m', 'Searching...', '\x1b[0m')
search('node_modules').then((results) => {
if (results.length) {
if (options.log) console.log('Directories found:', results)
results.forEach((res) => {
clean(res)
})
} else {
console.error('\x1b[31m', 'No node_modules directories found', '\x1b[0m')
process.exit(1)
}
console.log('\x1b[32m', 'nmc done!', '\x1b[0m')
})
let results = await search('node_modules')
if (results.length) {
if (options.log) console.log('Directories found:', results)
let actions = results.map(async (res) => {
await clean(res)
})
await Promise.allSettled(actions)
} else {
console.error('\x1b[31m', 'No node_modules directories found', '\x1b[0m')
process.exit(1)
}
console.log('\x1b[32m', 'nmc done!', '\x1b[0m')
}
nmc()
{
"name": "nmc",
"version": "0.0.3",
"version": "0.0.4",
"description": "node modules cleaner",

@@ -15,3 +15,3 @@ "main": "bin/nmc.js",

"scripts": {
"start": "node bin/nmc.js"
"start": "node ."
},

@@ -18,0 +18,0 @@ "keywords": [

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