This repository has been archived by the owner on Apr 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 117
/
packages.ts
118 lines (107 loc) 路 3.4 KB
/
packages.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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { matchersWithOptions } from "jest-json-schema";
import glob from "glob";
import fs from "fs";
import path from "path";
import { allPackageFiles } from "../tools/shared/packages";
import childProcess from "child_process";
describe("monorepo content validation", () => {
test("the monorepo does not contain banned words", async () => {
const checkBannedWords = await new Promise<void>((res, reject) => {
childProcess.exec(
"./wordCheck",
{ cwd: path.resolve(__dirname) },
(error, _stuff, stderr) => {
if (error || stderr) {
return reject(error || stderr);
}
return res();
}
);
});
expect(checkBannedWords).resolves;
});
});
describe("package.json validation", () => {
const packageFiles: string[] = allPackageFiles(glob);
const genericSchema = require("./schemaGeneric.json");
const publicSchema = require("./schemaPublic.json");
const restrictedSchema = require("./schemaRestricted");
expect.extend(
matchersWithOptions({
schemas: [genericSchema, publicSchema, restrictedSchema],
})
);
//used for license checker, but should be generated ahead of time with a fully populated list
const excludedPackages = [
"@newrelic/aws-sdk@1.1.3",
"@newrelic/koa@3.0.0",
"@newrelic/native-metrics@5.1.0",
"@newrelic/native-metrics@5.2.0",
"@newrelic/superagent@2.0.1",
"emitter-component@1.1.1",
"facebook-nodejs-business-sdk@12.0.1",
];
packageFiles.forEach((pkgFile) => {
const pkgJson = JSON.parse(fs.readFileSync(pkgFile, "utf-8"));
const nameAndVersion = `${pkgJson.name}@${pkgJson.version}`;
excludedPackages.push(nameAndVersion);
});
describe.each(packageFiles)(`%s`, (pkgFile) => {
const pkgJson = JSON.parse(fs.readFileSync(pkgFile, "utf-8"));
test("it follows Grouparoo's package json schema rules", () => {
/**
* Schema checks:
* - That Author, name, description, version, license, and private exist
* - No dependencies contain a version number with a ~ or ^
* - Values match expected types
*/
const schema =
pkgFile.includes("apps") ||
pkgFile.includes("tools") ||
pkgJson.name === "@grouparoo/grouparoo"
? genericSchema
: pkgJson.name === "@grouparoo/ui-enterprise"
? restrictedSchema
: publicSchema;
expect(pkgJson).toMatchSchema(schema);
});
test("Dependencies use a permitted license", (done) => {
const allowedLicenses = [
"MPL-2.0",
"MIT",
"Artistic-2.0",
"Apache",
"ISC",
"BSD",
"BSD*",
"BSD-3-Clause",
"BSD-2-Clause",
"CC0-1.0",
"CC-BY-3.0",
"CC-BY-4.0",
"Unlicense",
"WTFPL",
];
childProcess.exec(
`./node_modules/.bin/license-checker --excludePackages '${excludedPackages.join(
";"
)}' --start '${path.dirname(
pkgFile
)}' --onlyAllow '${allowedLicenses.join(";")}'`,
{ cwd: path.resolve(__dirname + "/../") },
(err, stdout, stderr) => {
done(stderr);
}
);
});
});
test("packages match across the monorepo", (done) => {
childProcess.exec(
`./node_modules/.bin/syncpack list-mismatches`,
{ cwd: path.resolve(__dirname + "/../") },
(err, stdout) => {
done(stdout);
}
);
});
});