Skip to content

Commit 04d653b

Browse files
authored
Copy remix script to remove prereleases from changelogs (#11183)
1 parent 6837a11 commit 04d653b

File tree

7 files changed

+742
-31
lines changed

7 files changed

+742
-31
lines changed

DEVELOPMENT.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ You may need to make changes to a pre-release prior to publishing a final stable
4747
- Wait for the release workflow to finish. The Changesets action in the workflow will open a PR that will increment all versions and generate the changelogs for the stable release.
4848
- Review the updated `CHANGELOG` files and make any adjustments necessary.
4949
- `find packages -name 'CHANGELOG.md' -mindepth 2 -maxdepth 2 -exec code {} \;`
50-
- Remove the changelogs for all pre-releases
51-
- [TODO: We should automate this]
50+
- Our automated release process should have removed prerelease entries
5251
- Finalize the release notes
5352
- This should already be in pretty good shape in the root `CHANGELOG.md` file in the repo
5453
- Do a quick double check that all iterated prerelease changesets got copied over

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"test": "jest",
2424
"test:inspect": "node --inspect-brk ./node_modules/.bin/jest",
2525
"changeset": "changeset",
26-
"version": "changeset version",
26+
"version": "changeset version && node ./scripts/remove-prerelease-changelogs.mjs",
2727
"publish": "node scripts/publish.js",
2828
"postversion": "node scripts/postversion.mjs",
2929
"version:experimental": "node ./scripts/version experimental",
@@ -50,6 +50,7 @@
5050
"@babel/preset-react": "^7.22.5",
5151
"@babel/preset-typescript": "^7.22.5",
5252
"@changesets/cli": "^2.26.2",
53+
"@manypkg/get-packages": "1.1.3",
5354
"@octokit/core": "^4.2.4",
5455
"@octokit/graphql": "^4.8.0",
5556
"@octokit/plugin-paginate-rest": "^2.21.3",
@@ -96,14 +97,19 @@
9697
"react": "^18.2.0",
9798
"react-dom": "^18.2.0",
9899
"react-test-renderer": "^18.2.0",
100+
"remark-gfm": "3.0.1",
101+
"remark-parse": "^10.0.1",
102+
"remark-stringify": "^10.0.2",
99103
"rollup": "^2.79.1",
100104
"rollup-plugin-copy": "^3.4.0",
101105
"rollup-plugin-extensions": "^0.1.0",
102106
"rollup-plugin-prettier": "^2.3.0",
103107
"rollup-plugin-terser": "^7.0.2",
104108
"semver": "^7.5.4",
105109
"type-fest": "^2.19.0",
106-
"typescript": "^5.1.6"
110+
"typescript": "^5.1.6",
111+
"unified": "^10.1.2",
112+
"unist-util-remove": "^3.1.0"
107113
},
108114
"engines": {
109115
"node": ">=14.0.0"

packages/react-router-dom/CHANGELOG.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162

163163
### Patch Changes
164164

165-
- Revert the `useResolvedPath` fix for splat routes due to a large number of applications that were relying on the buggy behavior (see https://github.com/remix-run/react-router/issues/11052#issuecomment-1836589329). We plan to re-introduce this fix behind a future flag in the next minor version. ([#11078](https://github.com/remix-run/react-router/pull/11078))
165+
- Revert the `useResolvedPath` fix for splat routes due to a large number of applications that were relying on the buggy behavior (see <https://github.com/remix-run/react-router/issues/11052#issuecomment-1836589329>). We plan to re-introduce this fix behind a future flag in the next minor version. ([#11078](https://github.com/remix-run/react-router/pull/11078))
166166
- Updated dependencies:
167167
168168
- `@remix-run/[email protected]`
@@ -417,7 +417,7 @@
417417

418418
## 6.12.1
419419

420-
> [!WARNING]
420+
> \[!WARNING]
421421
> Please use version `6.13.0` or later instead of `6.12.1`. This version suffers from a `webpack`/`terser` minification issue resulting in invalid minified code in your resulting production bundles which can cause issues in your application. See [#10579](https://github.com/remix-run/react-router/issues/10579) for more details.
422422
423423
### Patch Changes
@@ -752,7 +752,7 @@
752752

753753
## 6.4.0
754754

755-
Whoa this is a big one! `6.4.0` brings all the data loading and mutation APIs over from Remix. Here's a quick high level overview, but it's recommended you go check out the [docs][rr-docs], especially the [feature overview][rr-feature-overview] and the [tutorial][rr-tutorial].
755+
Whoa this is a big one! `6.4.0` brings all the data loading and mutation APIs over from Remix. Here's a quick high level overview, but it's recommended you go check out the [docs](https://reactrouter.com), especially the [feature overview](https://reactrouter.com/start/overview) and the [tutorial](https://reactrouter.com/start/tutorial).
756756

757757
**New APIs**
758758

@@ -778,7 +778,3 @@ Whoa this is a big one! `6.4.0` brings all the data loading and mutation APIs ov
778778
**Updated Dependencies**
779779

780780
781-
782-
[rr-docs]: https://reactrouter.com
783-
[rr-feature-overview]: https://reactrouter.com/start/overview
784-
[rr-tutorial]: https://reactrouter.com/start/tutorial

packages/react-router/CHANGELOG.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160

161161
### Patch Changes
162162

163-
- Revert the `useResolvedPath` fix for splat routes due to a large number of applications that were relying on the buggy behavior (see https://github.com/remix-run/react-router/issues/11052#issuecomment-1836589329). We plan to re-introduce this fix behind a future flag in the next minor version. ([#11078](https://github.com/remix-run/react-router/pull/11078))
163+
- Revert the `useResolvedPath` fix for splat routes due to a large number of applications that were relying on the buggy behavior (see <https://github.com/remix-run/react-router/issues/11052#issuecomment-1836589329>). We plan to re-introduce this fix behind a future flag in the next minor version. ([#11078](https://github.com/remix-run/react-router/pull/11078))
164164
- Updated dependencies:
165165
- `@remix-run/[email protected]`
166166

@@ -188,6 +188,7 @@
188188
### Patch Changes
189189

190190
- Fix `useActionData` so it returns proper contextual action data and not _any_ action data in the tree ([#11023](https://github.com/remix-run/react-router/pull/11023))
191+
191192
- Fix bug in `useResolvedPath` that would cause `useResolvedPath(".")` in a splat route to lose the splat portion of the URL path. ([#10983](https://github.com/remix-run/react-router/pull/10983))
192193

193194
- ⚠️ This fixes a quite long-standing bug specifically for `"."` paths inside a splat route which incorrectly dropped the splat portion of the URL. If you are relative routing via `"."` inside a splat route in your application you should double check that your logic is not relying on this buggy behavior and update accordingly.
@@ -300,7 +301,7 @@
300301

301302
## 6.12.1
302303

303-
> [!WARNING]
304+
> \[!WARNING]
304305
> Please use version `6.13.0` or later instead of `6.12.1`. This version suffers from a `webpack`/`terser` minification issue resulting in invalid minified code in your resulting production bundles which can cause issues in your application. See [#10579](https://github.com/remix-run/react-router/issues/10579) for more details.
305306
306307
### Patch Changes
@@ -632,7 +633,7 @@ function Comp() {
632633

633634
## 6.4.0
634635

635-
Whoa this is a big one! `6.4.0` brings all the data loading and mutation APIs over from Remix. Here's a quick high level overview, but it's recommended you go check out the [docs][rr-docs], especially the [feature overview][rr-feature-overview] and the [tutorial][rr-tutorial].
636+
Whoa this is a big one! `6.4.0` brings all the data loading and mutation APIs over from Remix. Here's a quick high level overview, but it's recommended you go check out the [docs](https://reactrouter.com), especially the [feature overview](https://reactrouter.com/start/overview) and the [tutorial](https://reactrouter.com/start/tutorial).
636637

637638
**New APIs**
638639

@@ -650,7 +651,3 @@ Whoa this is a big one! `6.4.0` brings all the data loading and mutation APIs ov
650651
**Updated Dependencies**
651652

652653
- `@remix-run/[email protected]`
653-
654-
[rr-docs]: https://reactrouter.com
655-
[rr-feature-overview]: https://reactrouter.com/start/overview
656-
[rr-tutorial]: https://reactrouter.com/start/tutorial

packages/router/CHANGELOG.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@
200200

201201
### Patch Changes
202202

203-
- Revert the `useResolvedPath` fix for splat routes due to a large number of applications that were relying on the buggy behavior (see https://github.com/remix-run/react-router/issues/11052#issuecomment-1836589329). We plan to re-introduce this fix behind a future flag in the next minor version. ([#11078](https://github.com/remix-run/react-router/pull/11078))
203+
- Revert the `useResolvedPath` fix for splat routes due to a large number of applications that were relying on the buggy behavior (see <https://github.com/remix-run/react-router/issues/11052#issuecomment-1836589329>). We plan to re-introduce this fix behind a future flag in the next minor version. ([#11078](https://github.com/remix-run/react-router/pull/11078))
204204

205205
## 1.13.0
206206

@@ -680,11 +680,6 @@ function Comp() {
680680

681681
This is the first stable release of `@remix-run/router`, which provides all the underlying routing and data loading/mutation logic for `react-router`. You should _not_ be using this package directly unless you are authoring a routing library similar to `react-router`.
682682

683-
For an overview of the features provided by `react-router`, we recommend you go check out the [docs][rr-docs], especially the [feature overview][rr-feature-overview] and the [tutorial][rr-tutorial].
683+
For an overview of the features provided by `react-router`, we recommend you go check out the [docs](https://reactrouter.com), especially the [feature overview](https://reactrouter.com/start/overview) and the [tutorial](https://reactrouter.com/start/tutorial).
684684

685-
For an overview of the features provided by `@remix-run/router`, please check out the [`README`][remix-router-readme].
686-
687-
[rr-docs]: https://reactrouter.com
688-
[rr-feature-overview]: https://reactrouter.com/start/overview
689-
[rr-tutorial]: https://reactrouter.com/start/tutorial
690-
[remix-router-readme]: https://github.com/remix-run/react-router/blob/main/packages/router/README.md
685+
For an overview of the features provided by `@remix-run/router`, please check out the [`README`](./README.md).
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import * as fs from "node:fs";
2+
import path from "node:path";
3+
import * as url from "node:url";
4+
import { getPackagesSync } from "@manypkg/get-packages";
5+
import remarkParse from "remark-parse";
6+
import remarkGfm from "remark-gfm";
7+
import rehypeStringify from "remark-stringify";
8+
import { unified } from "unified";
9+
import { remove } from "unist-util-remove";
10+
11+
const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
12+
const rootDir = path.join(__dirname, "..");
13+
14+
main();
15+
16+
async function main() {
17+
if (isPrereleaseMode()) {
18+
console.log("🚫 Skipping changelog removal in prerelease mode");
19+
return;
20+
}
21+
await removePreReleaseChangelogs();
22+
console.log("✅ Removed pre-release changelogs");
23+
}
24+
25+
async function removePreReleaseChangelogs() {
26+
let allPackages = getPackagesSync(rootDir).packages;
27+
28+
/** @type {Promise<any>[]} */
29+
let processes = [];
30+
for (let pkg of allPackages) {
31+
let changelogPath = path.join(pkg.dir, "CHANGELOG.md");
32+
if (!fs.existsSync(changelogPath)) {
33+
continue;
34+
}
35+
let changelogFileContents = fs.readFileSync(changelogPath, "utf-8");
36+
processes.push(
37+
(async () => {
38+
let file = await unified()
39+
// Since we have multiple versions of remark-parse, TS resolves to the
40+
// wrong one
41+
// @ts-expect-error
42+
.use(remarkParse)
43+
.use(remarkGfm)
44+
.use(removePreReleaseSectionFromMarkdown)
45+
// same problem
46+
// @ts-expect-error
47+
.use(rehypeStringify, {
48+
bullet: "-",
49+
emphasis: "_",
50+
listItemIndent: "one",
51+
})
52+
.process(changelogFileContents);
53+
54+
let fileContents = file.toString();
55+
await fs.promises.writeFile(changelogPath, fileContents, "utf-8");
56+
})()
57+
);
58+
}
59+
return Promise.all(processes);
60+
}
61+
62+
function removePreReleaseSectionFromMarkdown() {
63+
/**
64+
* @param {import('./unist').RootNode} tree
65+
* @returns {Promise<void>}
66+
*/
67+
async function transformer(tree) {
68+
remove(
69+
tree,
70+
/**
71+
* @param {import("./unist").Node & { __REMOVE__?: boolean }} node
72+
* @param {number | null | undefined} index
73+
* @param {*} parent
74+
*/
75+
(node, index, parent) => {
76+
if (node.__REMOVE__ === true) return true;
77+
if (
78+
node.type === "heading" &&
79+
node.depth === 2 &&
80+
node.children[0].type === "text" &&
81+
isPrereleaseVersion(node.children[0].value)
82+
) {
83+
if (index == null || parent == null) return false;
84+
85+
let nextIdx = 1;
86+
let nextNode = parent.children[index + 1];
87+
let found = false;
88+
89+
/** @type {import('./unist').FlowNode[]} */
90+
while (nextNode && !found) {
91+
if (nextNode.type === "heading" && nextNode.depth === 2) {
92+
found = true;
93+
break;
94+
}
95+
nextNode.__REMOVE__ = true;
96+
nextNode = parent.children[++nextIdx + index];
97+
}
98+
return true;
99+
}
100+
101+
return false;
102+
}
103+
);
104+
}
105+
return transformer;
106+
}
107+
108+
/**
109+
* @param {string} str
110+
* @returns
111+
*/
112+
function isPrereleaseVersion(str) {
113+
return /^(v?\d+\.){2}\d+-[a-z]+\.\d+$/i.test(str.trim());
114+
}
115+
116+
function isPrereleaseMode() {
117+
try {
118+
let prereleaseFilePath = path.join(rootDir, ".changeset", "pre.json");
119+
return fs.existsSync(prereleaseFilePath);
120+
} catch (err) {
121+
return false;
122+
}
123+
}

0 commit comments

Comments
 (0)