|
| 1 | +/** |
| 2 | + * Resolves workspace:* dependencies to real version numbers in all publishable packages. |
| 3 | + * Run this before `changeset publish` since npm publish doesn't understand workspace protocol. |
| 4 | + */ |
| 5 | +const fs = require("fs"); |
| 6 | +const path = require("path"); |
| 7 | + |
| 8 | +const packages = [ |
| 9 | + "packages/fullstack", |
| 10 | + "packages/react-render-null", |
| 11 | + "packages/wmux", |
| 12 | + "plugins/fullstack/bun-ws-client", |
| 13 | + "plugins/fullstack/bun-ws-server", |
| 14 | + "plugins/fullstack/socket-client", |
| 15 | + "plugins/fullstack/socket-server", |
| 16 | +]; |
| 17 | + |
| 18 | +const versions = new Map(); |
| 19 | +for (const pkgDir of packages) { |
| 20 | + const pkgJson = JSON.parse(fs.readFileSync(path.join(pkgDir, "package.json"), "utf8")); |
| 21 | + versions.set(pkgJson.name, pkgJson.version); |
| 22 | +} |
| 23 | + |
| 24 | +for (const pkgDir of packages) { |
| 25 | + const pkgPath = path.join(pkgDir, "package.json"); |
| 26 | + const pkgJson = JSON.parse(fs.readFileSync(pkgPath, "utf8")); |
| 27 | + let changed = false; |
| 28 | + |
| 29 | + for (const depField of ["dependencies", "devDependencies", "peerDependencies"]) { |
| 30 | + const deps = pkgJson[depField]; |
| 31 | + if (!deps) continue; |
| 32 | + for (const [name, version] of Object.entries(deps)) { |
| 33 | + if (version === "workspace:*" && versions.has(name)) { |
| 34 | + deps[name] = "^" + versions.get(name); |
| 35 | + changed = true; |
| 36 | + } |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + if (changed) { |
| 41 | + fs.writeFileSync(pkgPath, JSON.stringify(pkgJson, null, 2) + "\n"); |
| 42 | + console.log(` resolved workspace deps in ${pkgJson.name}`); |
| 43 | + } |
| 44 | +} |
0 commit comments