What is @pnpm/read-modules-dir?
@pnpm/read-modules-dir is an npm package that allows you to read the contents of the node_modules directory. It provides a simple API to list all the packages installed in a node_modules directory, which can be useful for various tasks such as auditing dependencies, generating reports, or performing custom operations on installed packages.
What are @pnpm/read-modules-dir's main functionalities?
List all packages in node_modules
This feature allows you to list all the packages in a specified node_modules directory. The code sample demonstrates how to use the package to read the contents of the node_modules directory and log the list of packages to the console.
const readModulesDir = require('@pnpm/read-modules-dir');
async function listPackages() {
const packages = await readModulesDir('path/to/node_modules');
console.log(packages);
}
listPackages();
Handle scoped packages
This feature allows you to handle scoped packages specifically. The code sample demonstrates how to filter and list only the scoped packages from the node_modules directory.
const readModulesDir = require('@pnpm/read-modules-dir');
async function listScopedPackages() {
const packages = await readModulesDir('path/to/node_modules');
const scopedPackages = packages.filter(pkg => pkg.startsWith('@'));
console.log(scopedPackages);
}
listScopedPackages();
Other packages similar to @pnpm/read-modules-dir
read-installed
The 'read-installed' package reads the installed packages in a node_modules directory and returns a tree structure of the dependencies. It provides more detailed information about each package, including version, dependencies, and more. Compared to @pnpm/read-modules-dir, 'read-installed' offers a more comprehensive view of the installed packages but may be more complex to use.
npm-ls
The 'npm-ls' package is a command-line tool that lists all the installed packages in a node_modules directory, similar to the 'npm ls' command. It provides a hierarchical view of the dependencies. Compared to @pnpm/read-modules-dir, 'npm-ls' is more focused on providing a command-line interface and may not be as easily integrated into custom scripts.