forked from thirdweb-dev/js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre-release.mjs
55 lines (48 loc) · 1.92 KB
/
pre-release.mjs
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
import { getPackagesSync } from "@manypkg/get-packages";
import { writeFileSync } from "fs";
import { join } from "path";
const { packages } = getPackagesSync(process.cwd());
// map of package names to their versions and directories
const packageVersions = packages.reduce((acc, pkg) => {
acc[pkg.packageJson.name] = {
version: pkg.packageJson.version,
dir: pkg.dir,
};
return acc;
}, {});
// loop over each package and update its dependencies if they are set to * and in the map
packages.forEach((pkg) => {
const packageJson = pkg.packageJson;
const dependencies = packageJson.dependencies || {};
const devDependencies = packageJson.devDependencies || {};
const peerDependencies = packageJson.peerDependencies || {};
Object.entries(dependencies).forEach(([dep, version]) => {
if (dep in packageVersions && version === "workspace:*") {
// if it's part of the dependencies directly then ask for the exact version
packageJson.dependencies[dep] = `${packageVersions[dep].version}`;
}
});
Object.entries(devDependencies).forEach(([dep, version]) => {
if (dep in packageVersions && version === "workspace:*") {
// if it's part of the devDependencies directly then ask for a version within range
packageJson.devDependencies[dep] = `^${packageVersions[dep].version}`;
}
});
Object.entries(peerDependencies).forEach(([dep, version]) => {
if (dep in packageVersions && version === "workspace:*") {
// if it's part of the devDependencies directly then ask for a version within range
packageJson.peerDependencies[dep] = `^${packageVersions[dep].version}`;
}
});
if (!process.env.CI) {
console.error(
`Not in CI, skipping writing package.json for: "${pkg.packageJson.name}"`,
);
return;
}
console.info("writing package.json for: ", pkg.packageJson.name);
writeFileSync(
join(pkg.dir, "package.json"),
JSON.stringify(packageJson, null, 2),
);
});