-
Notifications
You must be signed in to change notification settings - Fork 752
Expand file tree
/
Copy pathyarn.config.cjs
More file actions
59 lines (49 loc) · 1.68 KB
/
yarn.config.cjs
File metadata and controls
59 lines (49 loc) · 1.68 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
const fs = require('fs');
const {defineConfig} = require(`@yarnpkg/types`);
const {logDebug, logError} = require('./scripts/utils');
const childProcess = require('child_process');
const {getBranchPrefixes} = require('./scripts/release/prReleaseNotesCommon');
const UNWANTED_DEPENDENCIES = 'npm.dev';
function hasUnwantedDependencies(file) {
const fileContent = fs.readFileSync(file, 'utf8');
const matches = fileContent.match(new RegExp(`${UNWANTED_DEPENDENCIES}`, 'g'));
if (matches !== null) {
logError('Unwanted dependencies found in ' + file);
return true;
}
return false;
}
function checkYarnLock() {
if (hasUnwantedDependencies('./yarn.lock')) {
logDebug('You can fix this by running `node scripts/fixYarnLock.js`');
process.exit(1);
}
}
function checkYarnRc() {
if (hasUnwantedDependencies('./.yarnrc.yml')) {
process.exit(1);
}
}
function checkBranchPrefix() {
try {
const currentBranch = childProcess.execSync('git rev-parse --abbrev-ref HEAD', {
encoding: 'utf8'
}).trim();
const hasValidPrefix = getBranchPrefixes().some(prefix => currentBranch.startsWith(prefix)) || currentBranch === 'release';
if (!hasValidPrefix) {
logError(`Branch "${currentBranch}" does not start with a valid prefix.`);
logError(`Valid prefixes are: "${getBranchPrefixes().join('" "')}"`);
logDebug('Please rename your branch to use one of the valid prefixes (e.g., feat/your-feature-name)');
process.exit(1);
}
} catch (error) {
logError(`Error checking branch name: ${error.message}`);
}
}
module.exports = defineConfig({
constraints: async () => {
checkYarnLock();
checkYarnRc();
checkBranchPrefix();
}
});