Skip to content

Commit

Permalink
fix(zcloak-dev-version): fix the script will update dependencies with…
Browse files Browse the repository at this point in the history
… workspace protocol.
  • Loading branch information
actions-user committed Feb 6, 2023
1 parent 88f3bc4 commit 8cdf3e7
Showing 1 changed file with 4 additions and 30 deletions.
34 changes: 4 additions & 30 deletions packages/dev/scripts/zcloak-dev-version.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,6 @@ if (!TYPES.includes(type)) {
throw new Error(`Invalid version bump "${type}", expected one of ${TYPES.join(', ')}`);
}

function updateDependencies(dependencies, others, version) {
return Object.entries(dependencies)
.sort((a, b) => a[0].localeCompare(b[0]))
.reduce((result, [key, value]) => {
result[key] =
others.includes(key) && value !== '*'
? value.startsWith('^')
? `^${version}`
: version
: value;

return result;
}, {});
}

function readRootPkgJson() {
const rootPath = path.join(process.cwd(), 'package.json');
const rootJson = JSON.parse(fs.readFileSync(rootPath, 'utf8'));
Expand All @@ -42,21 +27,11 @@ function writePkgJson(path, json) {
fs.writeFileSync(path, `${JSON.stringify(json, null, 2)}\n`);
}

function updatePackage(version, others, pkgPath, json) {
function updatePackage(version, pkgPath, json) {
const updated = Object.keys(json).reduce((result, key) => {
if (key === 'version') {
result[key] = version;
} else if (
[
'dependencies',
'devDependencies',
'peerDependencies',
'optionalDependencies',
'resolutions'
].includes(key)
) {
result[key] = updateDependencies(json[key], others, version);
} else if (key !== 'stableVersion') {
} else {
result[key] = json[key];
}

Expand All @@ -72,7 +47,7 @@ execSync(`yarn version ${type === 'pre' ? 'prerelease' : type}`);

const [rootPath, rootJson] = readRootPkgJson();

updatePackage(rootJson.version, [], rootPath, rootJson);
updatePackage(rootJson.version, rootPath, rootJson);

// yarn workspaces does an OOM, manual looping takes ages
if (fs.existsSync('packages')) {
Expand All @@ -81,10 +56,9 @@ if (fs.existsSync('packages')) {
.map((dir) => path.join(process.cwd(), 'packages', dir, 'package.json'))
.filter((pkgPath) => fs.existsSync(pkgPath))
.map((pkgPath) => [pkgPath, JSON.parse(fs.readFileSync(pkgPath, 'utf8'))]);
const others = packages.map(([, json]) => json.name);

packages.forEach(([pkgPath, json]) => {
updatePackage(rootJson.version, others, pkgPath, json);
updatePackage(rootJson.version, pkgPath, json);
});
}

Expand Down

0 comments on commit 8cdf3e7

Please sign in to comment.