Skip to content

Commit 5d62d79

Browse files
authored
refactor: remove lerna (#336)
1 parent 2492a8d commit 5d62d79

File tree

11 files changed

+4054
-12620
lines changed

11 files changed

+4054
-12620
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010

1111
strategy:
1212
matrix:
13-
node-version: [18, 20, 22]
13+
node-version: [20, 22]
1414

1515
steps:
1616
- uses: actions/checkout@v4

esbuild/common.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Note: this is not a technically a esbuild-related script.
2+
import {execSync, spawnSync} from 'node:child_process'
3+
4+
export const getCommandOutput = (...args) => {
5+
const stdout = execSync(args.join(' '), {
6+
encoding: 'utf8',
7+
})
8+
return stdout.toString()
9+
}
10+
11+
export const getWorkspaces = () => {
12+
const workspacesJSON = getCommandOutput('npm', 'query', '.workspace')
13+
const workspaces = JSON.parse(workspacesJSON)
14+
return workspaces.toSorted((a, b) => {
15+
if (Object.keys(a.dependencies ?? {}).includes(b.name)) {
16+
return 1
17+
}
18+
if (Object.keys(b.dependencies ?? {}).includes(a.name)) {
19+
return -1
20+
}
21+
return 0
22+
})
23+
}
24+
25+
export const executeCommand = (command, args, options) => {
26+
spawnSync(command, args, {
27+
stdio: 'inherit',
28+
...options,
29+
})
30+
}

esbuild/publish.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Note: this is not a technically a esbuild-related script.
2+
3+
import {readFileSync, writeFileSync} from 'node:fs'
4+
import semver from 'semver'
5+
import {executeCommand, getCommandOutput, getWorkspaces} from './common.js'
6+
7+
const main = async () => {
8+
if (process.argv.length < 3) {
9+
console.error('Usage: node publish.js semver')
10+
process.exit(1)
11+
}
12+
const ver = process.argv[2]
13+
if (!semver.valid(ver)) {
14+
console.error(`❌ Invalid semver version: ${ver}`)
15+
process.exit(1)
16+
}
17+
18+
console.log('🔍 Checking if all changes are committed')
19+
const changes = getCommandOutput('git', 'status', '--porcelain')
20+
if (changes !== '') {
21+
console.error('❌ Please commit all changes before publishing')
22+
process.exit(1)
23+
}
24+
25+
console.log('🔍 Checking we are on main')
26+
const branch = getCommandOutput('git', 'branch', '--show-current')
27+
if (branch !== 'main') {
28+
console.error('❌ Please switch to main branch before publishing')
29+
process.exit(1)
30+
}
31+
32+
const pkgs = []
33+
const workspaces = getWorkspaces()
34+
const workspaceNames = workspaces.map((w) => w.name)
35+
for (const workspace of workspaces) {
36+
console.log(`✏️ Updating ${workspace.name} version to: ${ver}`)
37+
const pkgFile = `${workspace.location}/package.json`
38+
const pkg = JSON.parse(readFileSync(pkgFile))
39+
pkg.version = ver
40+
for (const dep of Object.keys(pkg.dependencies ?? {})) {
41+
if (workspaceNames.includes(dep)) {
42+
pkg.dependencies[dep] = `^${ver}`
43+
}
44+
}
45+
console.log(`📝 Writing ${workspace.name} package.json`)
46+
const content = JSON.stringify(pkg, null, 2)
47+
writeFileSync(pkgFile, content)
48+
pkgs.push(pkgFile)
49+
}
50+
51+
console.log('✅ Make sure the package.json are formatted correctly')
52+
executeCommand('npm', ['run', 'format:fix:internal', '--', ...pkgs])
53+
54+
for (const workspace of workspaces) {
55+
console.log(`🔨 Publishing ${workspace.name}`)
56+
executeCommand('npm', ['publish'], {
57+
cwd: workspace.location,
58+
})
59+
}
60+
61+
console.log('↩️ Committing changes')
62+
executeCommand('git', ['commit', '-am', `release: v${ver}`])
63+
64+
console.log('🏷️ Tagging')
65+
executeCommand('git', ['tag', `v${ver}`])
66+
executeCommand('git', ['push', '--tags'])
67+
executeCommand('gh', ['release', 'create', `v${ver}`, '--generate-notes'])
68+
}
69+
70+
main()

esbuild/run-all.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import {executeCommand, getWorkspaces} from './common.js'
2+
3+
// Note: this is not a technically a esbuild-related script.
4+
const main = async () => {
5+
if (process.argv.length < 3) {
6+
console.error('Usage: node run-all.js <command...>')
7+
process.exit(1)
8+
}
9+
const workspaces = getWorkspaces()
10+
const args = process.argv.slice(2)
11+
for (const workspace of workspaces) {
12+
console.log(`🔨 Running in ${workspace.name}: ${args.join(' ')}`)
13+
executeCommand(args[0], args.slice(1), {
14+
cwd: workspace.path,
15+
})
16+
}
17+
}
18+
19+
main()

lerna.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)