-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathcommons.ts
More file actions
78 lines (67 loc) · 2.17 KB
/
commons.ts
File metadata and controls
78 lines (67 loc) · 2.17 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { getExecOutput } from '@actions/exec';
import memoize from 'lodash/memoize.js';
export interface RawPackageRecord {
directory: string;
hasChanges: boolean;
package: {
name: string;
devDependencies: Record<string, string>;
dependencies: Record<string, string>;
};
}
interface BasePackageRecord {
/**
* Directory within which the `package.json` file was found
*/
directory: string;
/**
* Full scoped package name
*/
name: string;
/**
* `true` if git detected changes from within the package's subdirectories,
* `false` otherwise
*/
changes: boolean;
/**
* `true` if playwright is present under devDependencies. This means that the package
* might need playwright for its tests
*/
needsPlaywright: boolean;
}
export interface BundlePackageRecord extends BasePackageRecord {
bundleName: string;
}
export interface TabPackageRecord extends BasePackageRecord {
tabName: string;
}
export type PackageRecord = BundlePackageRecord | TabPackageRecord | BasePackageRecord;
export function isPackageRecord(obj: unknown): obj is PackageRecord {
if (typeof obj !== 'object' || obj === null) return false;
if (!('directory' in obj) || typeof obj.directory !== 'string') return false;
if (!('name' in obj) || typeof obj.name !== 'string') return false;
if (!('changes' in obj) || typeof obj.changes !== 'boolean') return false;
if (!('needsPlaywright' in obj) || typeof obj.needsPlaywright !== 'boolean') return false;
if ('bundleName' in obj) {
if ('tabName' in obj || typeof obj.bundleName !== 'string') return false;
} else if ('tabName' in obj) {
if (typeof obj.tabName !== 'string') return false;
}
return true;
}
/**
* Returns `true` if there are changes present in the given directory relative to
* the master branch\
* Used to determine, particularly for libraries, if running tests and tsc are necessary
*/
export const checkDirForChanges = memoize(async (directory: string) => {
const { exitCode } = await getExecOutput(
'git',
['--no-pager', 'diff', '--quiet', 'origin/master', '--', directory],
{
failOnStdErr: false,
ignoreReturnCode: true
}
);
return exitCode !== 0;
});