Fix bump with foundation packages (#10536)

Signed-off-by: Artem Savchenko <armisav@gmail.com>
This commit is contained in:
Artyom Savchenko
2026-02-21 21:57:35 +07:00
committed by GitHub
parent 5f7f712be3
commit 25bafb5d13
+32 -15
View File
@@ -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[package.name] = {
version: package.version,
path: package.path
packages[packageName] = {
version: project.version,
path: fullProjectPath
}
pathes[package.path] = package.name
pathes[fullProjectPath] = packageName
const file = package.path + '/package.json'
const raw = fs.readFileSync(file)
jsons[package.name] = JSON.parse(raw)
const file = path.join(fullProjectPath, 'package.json')
if (!fs.existsSync(file)) {
console.log('skip, package.json not found:', file)
continue
}
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')
}