forked from Synthetixio/v3ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepublishOnly.js
executable file
·39 lines (33 loc) · 1.15 KB
/
prepublishOnly.js
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
#!/usr/bin/env node
const cp = require('child_process');
const fs = require('fs');
const BAD_VERSION_REGEX = /(\.\d+\+[0-9a-f]+)$/;
cp.execSync('yarn workspaces list --no-private --json', {
encoding: 'utf-8',
stdio: 'pipe',
})
.split('\n')
.filter(Boolean)
.map((line) => JSON.parse(line))
.forEach(({ location }) => {
const packageJson = require(`./${location}/package.json`);
const cleanVersion = packageJson.version
.replace(BAD_VERSION_REGEX, '')
.replace('.NaN+undefined', '');
packageJson.version = cleanVersion;
if (packageJson.dependencies) {
Object.keys(packageJson.dependencies).forEach((name) => {
if (BAD_VERSION_REGEX.test(packageJson.dependencies[name])) {
packageJson.dependencies[name] = cleanVersion;
}
});
}
if (packageJson.devDependencies) {
Object.keys(packageJson.devDependencies).forEach((name) => {
if (BAD_VERSION_REGEX.test(packageJson.devDependencies[name])) {
packageJson.devDependencies[name] = cleanVersion;
}
});
}
fs.writeFileSync(`./${location}/package.json`, `${JSON.stringify(packageJson, null, 2)}\n`);
});