-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
44 lines (38 loc) · 1.12 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const os = require("os");
const fs = require("fs");
const path = require("path");
const ini = require("ini");
const carve = require("@boyeborg/carve");
const npmFetch = require("npm-registry-fetch");
const getNpmConfig = () => {
const configPath = path.join(os.homedir(), ".npmrc");
const configFile = fs.readFileSync(configPath, "utf-8");
return ini.parse(configFile);
};
const getAllPackagesByName = async npmConfig => {
const results = await npmFetch.json("/-/all", npmConfig);
return Object.values(results)
.splice(1)
.map(pkg => pkg.name);
};
const getPackagesAndDependenciesByName = async (packages, npmConfig) => {
const registry = npmConfig.registry;
const carvedPackages = await carve(packages, { registry });
const packageNames = Object.keys(carvedPackages);
// Remove version tag
return packageNames.map(pkg =>
pkg
.split("@")
.slice(0, -1)
.join("@")
);
};
const noop = () => {};
const noopLogger = { verbose: noop, info: noop, warn: noop, error: noop };
module.exports = {
getNpmConfig,
getAllPackagesByName,
getPackagesAndDependenciesByName,
noop,
noopLogger
};