forked from microsoft/playwright
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist_packages.js
44 lines (38 loc) · 1.39 KB
/
list_packages.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 fs = require('fs');
const path = require('path');
const packageDir = path.join(__dirname, '..', 'packages');
const packages = fs.readdirSync(packageDir)
.filter(packageDir => !packageDir.startsWith('.'))
.map(name => path.join(packageDir, name));
const packagePathToJSON = new Map();
const packageNameToPath = new Map();
const packagePathToDependencies = new Map();
for (const packagePath of packages) {
const packageJSON = require(path.join(packagePath, 'package.json'));
packageNameToPath.set(packageJSON.name, packagePath);
packagePathToJSON.set(packagePath, packageJSON);
}
for (const packagePath of packages)
packagePathToDependencies.set(packagePath, new Set(internalDependencies(packagePath)));
// Sort packages by their interdependence.
packages.sort((a, b) => {
if (packagePathToDependencies.get(a).has(b))
return 1;
if (packagePathToDependencies.get(b).has(a))
return -1;
return 0;
});
function* internalDependencies(packagePath) {
yield packagePath;
for (const dependency of Object.keys(packagePathToJSON.get(packagePath).dependencies || {})) {
const dependencyPath = packageNameToPath.get(dependency);
if (dependencyPath)
yield* internalDependencies(dependencyPath);
}
}
const packagesToPublish = packages.filter(packagePath => !packagePathToJSON.get(packagePath).private);
module.exports = {
packages,
packageNameToPath,
packagesToPublish,
};