Skip to content

Commit

Permalink
improve
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisBrunner committed Dec 12, 2024
1 parent 68e1fd3 commit 4dd1250
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
18 changes: 15 additions & 3 deletions esbuild/publish.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Note: this is not a technically a esbuild-related script.

import {readFileSync} from 'node:fs'
import {readFileSync, writeFileSync} from 'node:fs'
import semver from 'semver'
import {executeCommand, getCommandOutput, getWorkspaces} from './common.js'

Expand All @@ -22,22 +22,34 @@ const main = async () => {
process.exit(1)
}

console.log('🔍 Checking we are on main')
const branch = getCommandOutput('git', 'branch', '--show-current')
if (branch !== 'main') {
console.error('❌ Please switch to main branch before publishing')
process.exit(1)
}

const pkgs = []
const workspaces = getWorkspaces()
const workspaceNames = workspaces.map((w) => w.name)
for (const workspace of workspaces) {
console.log(`✏️ Updating ${workspace.name} version to: ${ver}`)
const pkg = JSON.parse(readFileSync(`${workspace.location}/package.json`))
const pkgFile = `${workspace.location}/package.json`
const pkg = JSON.parse(readFileSync(pkgFile))
pkg.version = ver
for (const dep of Object.keys(pkg.dependencies ?? {})) {
if (workspaceNames.includes(dep)) {
pkg.dependencies[dep] = `^${ver}`
}
}
console.log(`📝 Writing ${workspace.name} package.json`)
const content = JSON.stringify(pkg, null, 2)
writeFileSync(pkgFile, content)
pkgs.push(pkgFile)
}

console.log('✅ Make sure the package.json are formatted correctly')
executeCommand('npm', ['run', 'format:fix'])
executeCommand('npm', ['run', 'format:fix:internal', '--', ...pkgs])

for (const workspace of workspaces) {
console.log(`🔨 Publishing ${workspace.name}`)
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"build:all": "npm run build && npm run build:examples",
"build": "npm run build:esm && npm run build:types",
"typecheck": "tsc --noEmit",
"format:fix": "npx @biomejs/biome format --write .",
"format:fix:internal": "npx @biomejs/biome format --write",
"format:fix": "npm run format:fix:internal -- .",
"vet": "npm run typecheck && npx @biomejs/biome check",
"vet:ci": "npm run typecheck && npx @biomejs/biome ci",
"test": "jest --config jest.config.js",
Expand Down

0 comments on commit 4dd1250

Please sign in to comment.