-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
link-glimmer-vm-packages.mjs
47 lines (38 loc) · 1.23 KB
/
link-glimmer-vm-packages.mjs
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
import { readFileSync } from 'node:fs';
import path from 'node:path';
import chalk from 'chalk';
import execa from 'execa';
import glob from 'glob';
const rootDir = new URL('..', import.meta.url).pathname;
const packageJsonPaths = glob.sync('**/package.json', {
cwd: rootDir,
ignore: '**/node_modules/**',
});
function shouldLink(dep) {
return (
dep.startsWith('@glimmer/') &&
dep !== '@glimmer/component' &&
dep !== '@glimmer/env' &&
dep !== '@glimmer/tracking'
);
}
const link = packageJsonPaths.map(async (packageJsonPath) => {
const packagePath = path.dirname(packageJsonPath);
try {
const packageJson = JSON.parse(await readFileSync(packageJsonPath, { encoding: 'utf8' }));
for (const [dep] of Object.entries(packageJson.dependencies ?? {})) {
if (shouldLink(dep)) {
// eslint-disable-next-line no-console
console.log(`Linking ${chalk.yellow(dep)} from ${chalk.grey(packagePath)}`);
await execa('pnpm', ['link', '--global', dep], { cwd: packagePath });
}
}
} catch (error) {
let message = `Failed to link ${packagePath}`;
if (error instanceof Error) {
message += `\n\n${error.stack}`;
}
throw new Error(message);
}
});
await Promise.all(link);