forked from OKEAMAH/bolt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidateProject.js
More file actions
61 lines (53 loc) · 1.65 KB
/
validateProject.js
File metadata and controls
61 lines (53 loc) · 1.65 KB
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
// @flow
import semver from 'semver';
import Project from '../Project';
import Config from '../Config';
import Package from '../Package';
import * as messages from './messages';
import { BoltError } from './errors';
import * as logger from './logger';
import { BOLT_VERSION } from '../constants';
export default async function validateProject(project: Project) {
let packages = await project.getPackages();
let projectDependencies = project.pkg.getAllDependencies();
let projectConfig = project.pkg.config;
let { graph: depGraph } = await project.getDependencyGraph(packages);
let projectIsValid = true;
// If the project has an engines.bolt field we must respect it
let boltConfigVersion = projectConfig.getBoltConfigVersion();
if (boltConfigVersion) {
if (!semver.satisfies(BOLT_VERSION, boltConfigVersion)) {
logger.error(
messages.invalidBoltVersion(BOLT_VERSION, boltConfigVersion)
);
projectIsValid = false;
}
}
// Workspaces always have a name and a version in their configs
for (let pkg of packages) {
try {
pkg.getName();
} catch (err) {
logger.error(err.message);
projectIsValid = false;
}
try {
pkg.getVersion();
} catch (err) {
logger.error(err.message);
projectIsValid = false;
}
}
// Workspaces should never appear as dependencies in the Project config
for (let pkg of packages) {
let depName = pkg.getName();
if (projectDependencies.has(depName)) {
logger.error(messages.projectCannotDependOnWorkspace(depName));
projectIsValid = false;
}
}
/**
* <More Project checks here>
*/
return projectIsValid;
}