-
-
Notifications
You must be signed in to change notification settings - Fork 274
/
Copy pathcheck-workspace-resolutions.ts
41 lines (35 loc) · 1.64 KB
/
check-workspace-resolutions.ts
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
import fs from 'fs';
import path from 'path';
import chalk from 'chalk';
import { getWorkspacesList } from './utils/getWorkspacesList';
(() => {
const logLabel = chalk.green('Workspace resolutions checked in');
console.time(logLabel);
const workspaces = getWorkspacesList();
const packageNames = Object.values(workspaces).reduce<Record<string, string>>(
(packages, workspace) => ({ ...packages, [workspace.location]: workspace.name }),
{},
);
Object.keys(workspaces).forEach(workspaceName => {
const workspace = workspaces[workspaceName];
const packageJSON = fs.readFileSync(path.join(workspace.location, 'package.json'), {
encoding: 'utf-8',
});
const { dependencies, devDependencies } = JSON.parse(packageJSON);
const listOfWorkspaceDependencies = { ...dependencies, ...devDependencies };
workspace.workspaceDependencies.forEach(workspaceDependency => {
const dependencyName = packageNames[workspaceDependency];
const dependencyVersion = listOfWorkspaceDependencies[dependencyName];
if (!dependencyVersion.startsWith('workspace:')) {
console.error(
chalk.red(
`${workspaceName} has a dependency on ${dependencyName} with version ${dependencyVersion}.`,
),
chalk.bold.red(`Use "workspace:${dependencyVersion}" instead!`), // see https://yarnpkg.com/features/workspaces#workspace-ranges-workspace for explanation
);
process.exit(1);
}
});
});
console.timeEnd(logLabel);
})();