Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env node
- const { promises: fs } = require('fs');
- const path = require('path');
- (async () => {
- const nvmPath = process.env.NVM_DIR;
- if (!nvmPath) {
- console.error('Unable to detect nvm path. Exiting.');
- process.exit(1);
- }
- const onlyNpm = {};
- const nothing = {};
- const apps = await fs.readdir(path.resolve(nvmPath, 'versions'));
- for await (const app of apps) {
- const versions = await fs.readdir(path.resolve(nvmPath, 'versions', app));
- for (const version of versions) {
- const packagesPath = [nvmPath, 'versions', app, version, 'lib', 'node_modules'];
- const packages = await fs.readdir(path.resolve(...packagesPath));
- const hasOnlyNpm = packages.length === 1 && packages[0] === 'npm';
- const hasNothing = !packages.length;
- if (hasOnlyNpm) {
- if (!onlyNpm[app]) {
- onlyNpm[app] = [];
- }
- onlyNpm[app].push(version);
- continue;
- } else if (hasNothing) {
- if (!nothing[app]) {
- nothing[app] = [];
- }
- nothing[app].push(version);
- continue;
- }
- console.log([`Node ${version}`, ...packages].join(`\n - `), '\n');
- }
- }
- if (Object.keys(onlyNpm).length) {
- console.log(`# Only npm:`);
- for (const app in onlyNpm) {
- console.log(` - ${app}: ${onlyNpm[app].join(', ')}`);
- }
- console.log('');
- }
- if (Object.keys(nothing).length) {
- console.log(`# No package:`);
- for (const app in nothing) {
- console.log(` - ${app}: ${nothing[app].join(', ')}`);
- }
- console.log('');
- }
- process.exit(0);
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement