-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmake-linkable.js
More file actions
28 lines (26 loc) · 884 Bytes
/
make-linkable.js
File metadata and controls
28 lines (26 loc) · 884 Bytes
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
import childProcess from "child_process";
import fs from "fs";
import path from "path";
const dir = new URL(".", import.meta.url).pathname;
for (const pkg of fs.readdirSync(path.join(dir, "packages"))) {
const jsonPath = path.join(dir, "packages", pkg, "package.json");
try {
const text = fs.readFileSync(jsonPath);
const obj = JSON.parse(text);
fixDeps(obj.dependencies);
fixDeps(obj.devDependencies);
fixDeps(obj.peerDependencies);
const newText = JSON.stringify(obj, null, 2) + "\n";
if (text !== newText) fs.writeFileSync(jsonPath, newText, "utf-8");
} catch (e) {
if (e.code !== "ENOENT" && e.code !== "ENOTDIR") throw e;
}
}
function fixDeps(deps) {
if (!deps) return;
for (const key of Object.keys(deps)) {
if (deps[key] === "workspace:*") {
deps[key] = "portal:../" + key.replace("@", "").replace("/", "-");
}
}
}