/
defaultCompilePackages.js
85 lines (69 loc) · 2.35 KB
/
defaultCompilePackages.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const { posix: path } = require('node:path');
const chalk = require('chalk');
const { fdir: Fdir } = require('fdir');
const { cwd } = require('../lib/cwd');
const toPosixPath = require('../lib/toPosixPath');
const { rootDir, isPnpm } = require('../lib/packageManager');
const debug = require('debug')('sku:compilePackages');
/** @type {string[]} */
let detectedCompilePackages = [];
// If there's no rootDir, we're either inside `sku init`, or we can't determine the user's
// package manager. In either case, we can't correctly detect compile packages.
if (rootDir) {
try {
let crawler = new Fdir();
if (isPnpm) {
// Follow symlinks inside node_modules into the pnpm virtual store
crawler = crawler.withSymlinks().withRelativePaths();
} else {
crawler = crawler.withBasePath();
}
const seekDependencyGlob = '**/@seek/*/package.json';
let results = crawler
.glob(seekDependencyGlob)
.crawl('./node_modules/@seek')
.sync();
if (isPnpm) {
const pnpmVirtualStorePath = path.join(
toPosixPath(rootDir),
'node_modules/.pnpm',
);
const pnpmVirtualStoreRelativePath = path.relative(
'.',
pnpmVirtualStorePath,
);
const pnpmVirtualStoreResults = new Fdir()
.withRelativePaths()
.glob(seekDependencyGlob)
.crawl(pnpmVirtualStoreRelativePath)
.sync();
results.push(...pnpmVirtualStoreResults);
// All results will be relative to the virtual store directory, so we need
// to prepend the relative path from the current directory to the virtual store
results = results.map((file) =>
path.join(pnpmVirtualStoreRelativePath, file),
);
}
detectedCompilePackages = results
.map((packagePath) => {
const packageJson = require(path.join(cwd(), packagePath));
return {
isCompilePackage: Boolean(packageJson.skuCompilePackage),
packageName: packageJson.name,
};
})
.filter(({ isCompilePackage }) => isCompilePackage)
.map(({ packageName }) => packageName);
} catch (e) {
console.log(
chalk.red`Warning: Failed to detect compile packages. Contact #sku-support.`,
);
console.error(e);
}
}
debug(detectedCompilePackages);
module.exports = [
'sku',
'braid-design-system',
...new Set(detectedCompilePackages),
];