From 36d31d4e2a3d1aae9f8e645ae85b6cd67e2db8b1 Mon Sep 17 00:00:00 2001 From: Artem Savchenko Date: Sat, 21 Feb 2026 15:55:34 +0700 Subject: [PATCH] Fix bump with foundation packages Signed-off-by: Artem Savchenko --- common/scripts/bump.js | 47 ++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/common/scripts/bump.js b/common/scripts/bump.js index 56bd8f1a84a..3ef140a9d0e 100755 --- a/common/scripts/bump.js +++ b/common/scripts/bump.js @@ -1,35 +1,51 @@ const fs = require('fs') +const path = require('path') const execSync = require('child_process').execSync const repo = '@hcengineering' const packages = {} const pathes = {} const jsons = {} +const repoRoot = execSync('git rev-parse --show-toplevel', { encoding: 'utf-8' }).trim() function fillPackages (config) { - for (const package of config.projects) { - if (!package.name.startsWith(repo)) continue + for (const project of config.projects) { + const packageName = project.name ?? project.packageName + if (typeof packageName !== 'string' || !packageName.startsWith(repo)) continue + const projectPath = project.path ?? project.projectFolder ?? path.relative(repoRoot, project.fullPath ?? '') + if (typeof projectPath !== 'string' || projectPath.length === 0) continue + const fullProjectPath = path.resolve(repoRoot, projectPath) + + packages[packageName] = { + version: project.version, + path: fullProjectPath + } + pathes[fullProjectPath] = packageName - packages[package.name] = { - version: package.version, - path: package.path + const file = path.join(fullProjectPath, 'package.json') + if (!fs.existsSync(file)) { + console.log('skip, package.json not found:', file) + continue } - pathes[package.path] = package.name - const file = package.path + '/package.json' - const raw = fs.readFileSync(file) - jsons[package.name] = JSON.parse(raw) + const raw = fs.readFileSync(file) + jsons[packageName] = JSON.parse(raw) } } function bumpPackage (name, newVersion) { const json = jsons[name] + if (json === undefined) return json.version = newVersion - if (typeof json.dependencies === 'object') { - for (const [dependency] of Object.entries(json.dependencies)) { + const depTypes = ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'] + for (const depType of depTypes) { + if (typeof json[depType] !== 'object') continue + for (const [dependency, currentVersion] of Object.entries(json[depType])) { if (packages[dependency] !== undefined) { - json.dependencies[dependency] = `^${newVersion}` + json[depType][dependency] = String(currentVersion).startsWith('workspace:') + ? `workspace:^${newVersion}` + : `^${newVersion}` } } } @@ -44,7 +60,7 @@ function publish (name) { const package = packages[name] try { console.log('publishing', name) - execSync(`cd ${package.path} && npm publish && cd ../..`, { encoding: 'utf-8' }) + execSync('npm publish', { encoding: 'utf-8', cwd: package.path }) } catch (err) { console.log(err) } @@ -54,7 +70,7 @@ function fix (name) { const package = packages[name] try { console.log('fixing', name) - execSync(`cd ${package.path} && npm pkg fix && cd ../..`, { encoding: 'utf-8' }) + execSync('npm pkg fix', { encoding: 'utf-8', cwd: package.path }) } catch (err) { console.log(err) } @@ -89,7 +105,8 @@ function main () { for (const packageName of packageNames) { const package = packages[packageName] - const file = package.path + '/package.json' + if (jsons[packageName] === undefined) continue + const file = path.join(package.path, 'package.json') const res = JSON.stringify(jsons[packageName], undefined, 2) fs.writeFileSync(file, res + '\n') }