Gathering detailed insights and metrics for clean-modules
Gathering detailed insights and metrics for clean-modules
Gathering detailed insights and metrics for clean-modules
Gathering detailed insights and metrics for clean-modules
@pnpm/modules-cleaner
Exports util functions to clean up node_modules
node-modules-cleanup
Find and delete all node_module folders
clean-node-modules-cli
A command-line tool to recursively delete all node_modules folders in the current directory and subdirectories.
clean-node-modules
if space is a constraint and you want to bundle node_modules, clean them first
🧹 Clean up/prune unnecessary files and reduce the size of your node_modules directory.
npm install clean-modules
Typescript
Module System
Min. Node Version
Node Version
NPM Version
TypeScript (99.77%)
JavaScript (0.23%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
ISC License
124 Stars
127 Commits
4 Forks
1 Watchers
3 Branches
7 Contributors
Updated on Jul 08, 2025
Latest Version
3.1.1
Package Id
clean-modules@3.1.1
Unpacked Size
55.15 kB
Size
13.45 kB
File Count
15
NPM Version
10.7.0
Node Version
18.20.4
Published on
Oct 01, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Clean up/prune unnecessary files and reduce the size of your
node_modules
directory. Useful for CI caches or for reducing the size of serverless functions.
Simply run the command in the directory where your node_modules
are:
1clean-modules
You can also pass any options that you need, like custom globs or a path to a specific
node_modules
directory.
1clean-modules --directory "path/to/node_modules" "extra/included/file/glob.txt" "!extra/excluded/glob.ts
Check out the command section for all available options.
clean-modules
can be installed globally if you only want to use it as a CLI tool. You can also
install it locally if you want to use it in a package command.
1# global 2npm install --global clean-modules 3 4# dev dependency 5npm install --save-dev clean-modules
clean-modules clean
(default command) 🧹The default command, cleans up your node_modules
based on a set of most likely safe glob
patterns and removes empty directories.
1clean-modules [options] <...globs>
Extra glob patterns can be passed as positional arguments. By default they are combined with the globs loaded from the the default globs file and any custom globs file passed through the --glob-file
option.
For information on how the globs are parsed, see the Glob patterns section.
Example:
1# include all TypeScript declaration files and @types folders 2clean-modules "**/*.d.ts" "**/@types/**" 3 4# exclude all sourcemap files and PNG files 5clean-modules "!**/*.map.js" "!**/*.png" 6 7# include .d.ts files but exclude PNG files 8clean-modules "**/*.d.ts" "!**/*.png"
--directory | -D
string
[default: ./node_modules
]
Accepts a path to a directory to run the script on.
Example:
1clean-modules --directory "path/to/custom/node_modules"
--glob-file | -f
string
[default: ./.cleanmodules
]
Accepts a path to a file from which clean-modules should read any custom globs. See the glob patterns section for information about how the glob file works and what patterns work.
--no-defaults | -n
boolean
Excludes all default globs, using only custom globs added through the glob file or by the include or exclude options. Useful if you want complete control over what files to include.
See the .cleanmodules-default
to see what patterns are included by
default by default.
--keep-empty | -k
boolean
Skips removing empty folders after removing files.
--dry-run | -d
boolean
Runs the script and prints the result without actually removing any files. Does not count the number of removed empty directories.
--json | -j
boolean
Only logs a final JSON dump at the end of the script (useful for logs or services).
--yes | -y
boolean
Skips the confirmation prompt at the start of the script.
clean-modules analyze
🔎Compiles a list of all files that would be included by clean-modules
and gives a breakdown of:
picomatch
1clean-modules analyze [options]
Because of the amount of data it can be useful to pipe it somewhere, like:
1clean-modules analyze >> clean-modules-result.json
The analyze
command accepts the same type of positionals as the default command.
The analyze
command accepts several of the default command's options and applies them in the same
way:
1[ 2 { 3 "filePath": "/Users/me/projects/foo/node_modules/dependency/__tests__/test1.js", 4 "includedByDefault": true, 5 "includedByGlobs": [ 6 { 7 "original": "__tests__/", 8 "derived": "/Users/me/projects/foo/node_modules/dependency/**/__tests__/**" 9 } 10 ] 11 } 12 // ... 13]
clean-modules accepts globs from either a configuration file (.cleanmodules
next to
node_modules
by default) or CLI arguments. It uses
.gitignore
-like glob patterns
that are converted to valid picomatch
globs, which is
what is used to match file paths under the hood.
Differences from regular gitignore syntax:
/
, /*
or /**
Like with .gitignore, globs should use forward-slashes as separators on all operative systems (including Windows)!
1# this is a comment (starts with a #) 2 3# to include include directories, end patterns with / or /* or /** 4dep1/ 5dep1/* 6dep2/** 7 8# files are matched in any directory by default 9**/*.test.js 10# is the same as 11*.test.js 12 13# use a leading / to include a file or directory at a specific place 14/dep4/this/specific/directory/** 15/dep4/this/specific/file.js 16 17# to exclude a path, prepend it with a ! 18!/not/this/directory/ 19!not-me.js 20 21# to use leading exclamation marks without excluding, escape them 22\!(*.d).ts
The default globs can be found in the .cleanmodules-default
file. It
only contains inclusions (as exclusions would override custom inclusions) and consists of a large
list of the most common files that are safe to remove.
That said, it's impossible to guarantee that none of the files are needed, and you might need to do custom exclusions depending on what packages you use.
**/*.d.ts
: If you don't use TypeScript. TypeScript declaration files take up a lot of space
in your node_modules
folder, but they are most likely required to build your application. Useful
locally even if you don't use TypeScript since they can be parsed by your IDE.!**/*.map.js
: If you are running clean-modules
locally or need source files in production.
clean-modules
removes sourcemap files by default since they take up a lot of space and does not
break builds when removed. They can be nice to have though, especially while developing.Clean modules can be used programmatically too!
Simply import the corresponding function from the package:
1import { clean, analyze } from 'clean-modules'; 2 3// analyze, all options are optional 4const analyzeResult = await analyze({ 5 directory: '/path/to/node_modules', 6 globFile: '/path/to/.cleanmodules', 7 globs: ['**/*.js'], 8 noDefaults: false, 9}); 10 11// clean, all options are optional 12const cleanResult = await clean({ 13 directory: '/path/to/node_modules', 14 globFile: '/path/to/.cleanmodules', 15 globs: ['**/*.js'], 16 noDefaults: false, 17 keepEmpty: false, 18 dryRun: false, 19});
The most common issues I found with available tools are:
@types/react-native
.*.ts
by default, which breaks TypeScript declaration files on build.yarn clean
.d.ts
files and assets
folder)filepath.Match
.d.ts
files and assets
folder)No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 4/19 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
18 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More