-
-
Notifications
You must be signed in to change notification settings - Fork 415
/
.size-limit.cjs
57 lines (51 loc) · 1.5 KB
/
.size-limit.cjs
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
45
46
47
48
49
50
51
52
53
54
55
56
57
const path = require('path');
const fs = require('fs');
const entry = path.resolve(__dirname, 'packages');
function getFoldersWithPackageJson(dir) {
let folders = [];
const items = fs.readdirSync(dir);
for (const item of items) {
if (item.includes('node_modules') || item.includes('src')) {
break;
}
const fullPath = path.join(dir, item);
if (fs.statSync(fullPath).isDirectory()) {
if (fs.existsSync(path.join(fullPath, 'package.json'))) {
folders.push(fullPath);
}
folders = folders.concat(getFoldersWithPackageJson(fullPath));
}
}
return folders;
}
const folders = getFoldersWithPackageJson(entry)
.map(p => {
const packageJson = path.join(p, 'package.json');
const json = require(packageJson);
return { json, path: p };
})
.filter(data => {
return !data.json.private;
})
.filter(data => {
// We only want to include packages that need to be installed by the user
return ['@blocksuite/affine'].includes(data.json.name);
})
.flatMap(data => {
const pathList = Object.entries(data.json.exports).map(([key, p]) => {
return {
path: path.join(data.path, p),
subpath: key,
};
});
const ignore = Object.keys({
...data.json.dependencies,
...data.json.devDependencies,
}).filter(name => !name.startsWith('@blocksuite/'));
return pathList.map(p => ({
name: path.join(data.json.name, p.subpath),
path: p.path,
ignore,
}));
});
module.exports = folders;