Skip to content

Commit e15cef2

Browse files
Add check for workspaces (#21)
1 parent 31bed5f commit e15cef2

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ branding:
44
icon: "chevron-right"
55
color: "gray-dark"
66
runs:
7-
using: "node12"
7+
using: "node16"
88
main: "index.js"

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const checkLockVersion = require("./lib/checks/lockVersion");
22
const checkForPreRelease = require("./lib/checks/preReleases");
3+
const checkForWorkspaces = require("./lib/checks/workspaces");
34
const hasYarnLock = require("./lib/checks/yarn");
45
const { FatalError } = require("./lib/errors");
56
const { getPackageLock, getPackage } = require("./lib/utils");
@@ -11,6 +12,7 @@ function lint() {
1112
errors.push(hasYarnLock());
1213
errors.push(checkLockVersion(pkgLock));
1314
errors.push(checkForPreRelease(pkgJson));
15+
errors.push(checkForWorkspaces(pkgJson));
1416
for (const error of errors) {
1517
if (error instanceof FatalError) {
1618
process.stderr.write(`${error.message}\n`);

lib/__tests__/workspaces.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const { FatalError } = require("../errors");
2+
const checkForWorkspaces = require("../checks/workspaces");
3+
4+
describe("Check workspaces", () => {
5+
it("should not return a fatal error when no workspaces are defined", () => {
6+
const result = checkForWorkspaces({
7+
dependencies: {
8+
"@mobsuccess-devops/pre-release": "1.0.0-pr-1.0",
9+
},
10+
});
11+
expect(result).toBeUndefined();
12+
});
13+
it("should not return a fatal error when workspaces are empty", () => {
14+
const result = checkForWorkspaces({ workspaces: [] });
15+
expect(result).toBeUndefined();
16+
});
17+
it("should return a fatal error when workspaces are not empty", () => {
18+
const result = checkForWorkspaces({ workspaces: ["../react-ui"] });
19+
expect(result).toBeInstanceOf(FatalError);
20+
});
21+
});

lib/checks/workspaces.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const { FatalError } = require("../errors");
2+
3+
function checkForWorkspaces(pkgJson = {}) {
4+
const { workspaces = [] } = pkgJson;
5+
if (workspaces.length > 0) {
6+
return new FatalError(`Unexpected workspaces found: ${workspaces}\n`);
7+
}
8+
}
9+
10+
module.exports = checkForWorkspaces;

0 commit comments

Comments
 (0)