Skip to content

Commit 74dc0bf

Browse files
committed
Update publish scripts
1 parent 7023429 commit 74dc0bf

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

lib/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
"vitest": "^3.0.4"
4444
},
4545
"peerDependencies": {
46-
"@types/react": "16.8 - 19",
47-
"react": "16.8 - 19"
46+
"@types/react": ">=16.8",
47+
"react": ">=16.8"
4848
},
4949
"funding": [
5050
{

scripts/publish.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/** It is assumed that this is called only from the default branch. */
22
const { execSync } = require("child_process");
33

4+
const BRANCH = process.env.BRANCH;
5+
46
// Apply changesets if any -- e.g., coming from pre-release branches
57
try {
68
execSync("pnpm changeset pre exit");
@@ -10,7 +12,7 @@ try {
1012
try {
1113
execSync("pnpm changeset version");
1214
execSync(
13-
`git add . && git commit -m "Apply changesets and update CHANGELOG" && git push origin ${process.env.BRANCH}`,
15+
`git add . && git commit -m "Apply changesets and update CHANGELOG [skip ci]" && git push origin ${BRANCH}`,
1416
);
1517
} catch {
1618
// no changesets to be applied
@@ -20,7 +22,7 @@ const { version: VERSION, name } = require("../lib/package.json");
2022
let LATEST_VERSION = "0.0.-1";
2123

2224
try {
23-
LATEST_VERSION = execSync(`npm view ${name} version`).toString() ?? "0.0.-1";
25+
LATEST_VERSION = execSync(`npm view ${name} version`).toString().trim() ?? "0.0.-1";
2426
} catch {
2527
// empty
2628
}
@@ -31,21 +33,35 @@ const [newMajor, newMinor] = VERSION.split(".");
3133
const [oldMajor, oldMinor] = LATEST_VERSION.split(".");
3234

3335
const isPatch = newMajor === oldMajor && newMinor === oldMinor;
36+
const releaseBranch = `release-${newMajor}.${newMinor}`;
3437

35-
if (!isPatch) {
38+
if (isPatch) {
39+
// update release branch
40+
try {
41+
execSync(
42+
`git checkout ${releaseBranch} && git merge ${BRANCH} && git push origin ${releaseBranch}`,
43+
);
44+
} catch {}
45+
} else {
3646
require("./update-security-md")(`${newMajor}.${newMinor}`, `${oldMajor}.${oldMinor}`);
3747
/** Create new release branch for every Major or Minor release */
38-
const releaseBranch = `release-${newMajor}.${newMinor}`;
3948
execSync(`git checkout -b ${releaseBranch} && git push origin ${releaseBranch}`);
4049
}
4150

51+
const { visibility } = JSON.parse(execSync("gh repo view --json visibility").toString());
52+
const provenance = visibility.toLowerCase() === "public" ? "--provenance" : "";
53+
4254
/** Create release */
43-
execSync("cd lib && pnpm build && npm publish --provenance --access public");
55+
execSync(`cd lib && pnpm build && npm publish ${provenance} --access public`);
4456

4557
/** Create GitHub release */
46-
execSync(
47-
`gh release create ${VERSION} --generate-notes --latest -n "$(sed '1,/^## /d;/^## /,$d' CHANGELOG.md)" --title "Release v${VERSION}"`,
48-
);
58+
try {
59+
execSync(
60+
`gh release create ${VERSION} --generate-notes --latest -n "$(sed '1,/^## /d;/^## /,$d' CHANGELOG.md)" --title "Release v${VERSION}"`,
61+
);
62+
} catch {
63+
execSync(`gh release create ${VERSION} --generate-notes --latest --title "Release v${VERSION}"`);
64+
}
4965

5066
// Publish canonical packages
5167
execSync("node scripts/publish-canonical.js");

0 commit comments

Comments
 (0)