Skip to content

Commit 904e926

Browse files
Merge remote-tracking branch 'origin/alpha' into chunk-file-names
2 parents 1bb6606 + 6875919 commit 904e926

File tree

5 files changed

+75
-65
lines changed

5 files changed

+75
-65
lines changed

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,15 @@
4444
"@testing-library/react": "^14.0.0",
4545
"@testing-library/react-hooks": "^8.0.1",
4646
"@testing-library/user-event": "^14.4.3",
47+
"@types/current-git-branch": "^1.1.3",
4748
"@types/eslint": "^8.34.0",
49+
"@types/jsonfile": "^6.1.1",
4850
"@types/luxon": "^3.3.0",
4951
"@types/node": "^18.13.0",
5052
"@types/react": "^18.2.4",
5153
"@types/react-dom": "^18.2.4",
5254
"@types/semver": "^7.5.0",
55+
"@types/stream-to-array": "^2.3.0",
5356
"@types/testing-library__jest-dom": "^5.14.5",
5457
"@typescript-eslint/eslint-plugin": "^5.54.0",
5558
"@typescript-eslint/parser": "^5.54.0",

pnpm-lock.yaml

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/config.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,25 +80,22 @@ export const packages = [
8080
},
8181
]
8282

83-
export const latestBranch = 'main'
84-
85-
/** @type {Record<string, import('./types').BranchConfig>} */
83+
/**
84+
* Contains config for publishable branches.
85+
* @type {Record<string, import('./types').BranchConfig>}
86+
*/
8687
export const branchConfigs = {
8788
main: {
8889
prerelease: false,
89-
ghRelease: true,
9090
},
9191
next: {
9292
prerelease: true,
93-
ghRelease: true,
9493
},
9594
beta: {
9695
prerelease: true,
97-
ghRelease: true,
9896
},
9997
alpha: {
10098
prerelease: true,
101-
ghRelease: true,
10299
},
103100
}
104101

scripts/publish.js

Lines changed: 43 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import log from 'git-log-parser'
1212
import streamToArray from 'stream-to-array'
1313
import axios from 'axios'
1414
import { DateTime } from 'luxon'
15-
import { branchConfigs, latestBranch, packages, rootDir } from './config.js'
15+
import { branchConfigs, packages, rootDir } from './config.js'
1616

1717
/** @param {string} version */
1818
const releaseCommitMsg = (version) => `release: v${version}`
@@ -22,17 +22,8 @@ async function run() {
2222
process.env.BRANCH ?? currentGitBranch()
2323
)
2424

25-
/** @type {import('./types.js').BranchConfig | undefined} */
26-
const branchConfig = branchConfigs[branchName]
27-
28-
if (!branchConfig) {
29-
console.log(`No publish config found for branch: ${branchName}`)
30-
console.log('Exiting...')
31-
process.exit(0)
32-
}
33-
34-
const isLatestBranch = branchName === latestBranch
35-
const npmTag = isLatestBranch ? 'latest' : branchName
25+
const isMainBranch = branchName === 'main'
26+
const npmTag = isMainBranch ? 'latest' : branchName
3627

3728
// Get tags
3829
/** @type {string[]} */
@@ -42,11 +33,11 @@ async function run() {
4233
tags = tags
4334
.filter((tag) => semver.valid(tag))
4435
.filter((tag) => {
45-
if (isLatestBranch) {
46-
return semver.prerelease(tag) == null
36+
if (semver.prerelease(tag) === null) {
37+
return isMainBranch
38+
} else {
39+
return !isMainBranch
4740
}
48-
49-
return tag.includes(`-${branchName}`)
5041
})
5142
// sort by latest
5243
.sort(semver.compare)
@@ -95,6 +86,7 @@ async function run() {
9586
*/
9687
const commitsSinceLatestTag = (
9788
await new Promise((resolve, reject) => {
89+
/** @type {NodeJS.ReadableStream} */
9890
const strm = log.parse({
9991
_: range,
10092
})
@@ -126,6 +118,10 @@ async function run() {
126118

127119
/**
128120
* Parses the commit messsages, log them, and determine the type of release needed
121+
* -1 means no release is necessary
122+
* 0 means patch release is necessary
123+
* 1 means minor release is necessary
124+
* 2 means major release is necessary
129125
* @type {number}
130126
*/
131127
let recommendedReleaseLevel = commitsSinceLatestTag.reduce(
@@ -304,6 +300,15 @@ async function run() {
304300
recommendedReleaseLevel = 0
305301
}
306302

303+
/** @type {import('./types.js').BranchConfig | undefined} */
304+
const branchConfig = branchConfigs[branchName]
305+
306+
if (!branchConfig) {
307+
console.log(`No publish config found for branch: ${branchName}`)
308+
console.log('Exiting...')
309+
process.exit(0)
310+
}
311+
307312
const releaseType = branchConfig.prerelease
308313
? 'prerelease'
309314
: /** @type {const} */ ({ 0: 'patch', 1: 'minor', 2: 'major' })[
@@ -368,17 +373,6 @@ async function run() {
368373
return
369374
}
370375

371-
// Tag and commit
372-
console.info(`Creating new git tag v${version}`)
373-
execSync(`git tag -a -m "v${version}" v${version}`)
374-
375-
const taggedVersion = getTaggedVersion()
376-
if (!taggedVersion) {
377-
throw new Error(
378-
'Missing the tagged release version. Something weird is afoot!',
379-
)
380-
}
381-
382376
console.info()
383377
console.info(`Publishing all packages to npm with tag "${npmTag}"`)
384378

@@ -396,36 +390,33 @@ async function run() {
396390

397391
console.info()
398392

399-
console.info(`Pushing new tags to branch.`)
400-
execSync(`git push --tags`)
401-
console.info(` Pushed tags to branch.`)
402-
403-
if (branchConfig.ghRelease) {
404-
console.info(`Creating github release...`)
405-
// Stringify the markdown to excape any quotes
406-
execSync(
407-
`gh release create v${version} ${
408-
!isLatestBranch ? '--prerelease' : ''
409-
} --notes '${changelogMd.replace(/'/g, '"')}'`,
410-
)
411-
console.info(` Github release created.`)
412-
413-
console.info(`Committing changes...`)
414-
execSync(`git add -A && git commit -m "${releaseCommitMsg(version)}"`)
415-
console.info()
416-
console.info(` Committed Changes.`)
417-
console.info(`Pushing changes...`)
418-
execSync(`git push`)
419-
console.info()
420-
console.info(` Changes pushed.`)
421-
} else {
422-
console.info(`Skipping github release and change commit.`)
423-
}
393+
console.info(`Committing changes...`)
394+
execSync(`git add -A && git commit -m "${releaseCommitMsg(version)}"`)
395+
console.info()
396+
console.info(` Committed Changes.`)
397+
398+
console.info(`Pushing changes...`)
399+
execSync(`git push`)
400+
console.info()
401+
console.info(` Changes pushed.`)
402+
403+
console.info(`Creating new git tag v${version}`)
404+
execSync(`git tag -a -m "v${version}" v${version}`)
424405

425406
console.info(`Pushing tags...`)
426407
execSync(`git push --tags`)
427408
console.info()
428409
console.info(` Tags pushed.`)
410+
411+
console.info(`Creating github release...`)
412+
// Stringify the markdown to excape any quotes
413+
execSync(
414+
`gh release create v${version} ${
415+
!isMainBranch ? '--prerelease' : ''
416+
} --notes '${changelogMd.replace(/'/g, '"')}'`,
417+
)
418+
console.info(` Github release created.`)
419+
429420
console.info(`All done!`)
430421
}
431422

@@ -459,11 +450,6 @@ async function updatePackageJson(pathName, transform) {
459450
})
460451
}
461452

462-
function getTaggedVersion() {
463-
const output = execSync('git tag --list --points-at HEAD').toString()
464-
return output.replace(/^v|\n+$/g, '')
465-
}
466-
467453
/**
468454
* @template TItem
469455
* @param {((d: TItem) => any)[]} sorters

scripts/types.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,4 @@ export type Package = {
4444

4545
export type BranchConfig = {
4646
prerelease: boolean
47-
ghRelease: boolean
4847
}

0 commit comments

Comments
 (0)