Skip to content

Commit

Permalink
Copy remix script to remove prereleases from changelogs (#11183)
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 committed Jan 12, 2024
1 parent 6837a11 commit 04d653b
Show file tree
Hide file tree
Showing 7 changed files with 742 additions and 31 deletions.
3 changes: 1 addition & 2 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ You may need to make changes to a pre-release prior to publishing a final stable
- 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.
- Review the updated `CHANGELOG` files and make any adjustments necessary.
- `find packages -name 'CHANGELOG.md' -mindepth 2 -maxdepth 2 -exec code {} \;`
- Remove the changelogs for all pre-releases
- [TODO: We should automate this]
- Our automated release process should have removed prerelease entries
- Finalize the release notes
- This should already be in pretty good shape in the root `CHANGELOG.md` file in the repo
- Do a quick double check that all iterated prerelease changesets got copied over
Expand Down
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"test": "jest",
"test:inspect": "node --inspect-brk ./node_modules/.bin/jest",
"changeset": "changeset",
"version": "changeset version",
"version": "changeset version && node ./scripts/remove-prerelease-changelogs.mjs",
"publish": "node scripts/publish.js",
"postversion": "node scripts/postversion.mjs",
"version:experimental": "node ./scripts/version experimental",
Expand All @@ -50,6 +50,7 @@
"@babel/preset-react": "^7.22.5",
"@babel/preset-typescript": "^7.22.5",
"@changesets/cli": "^2.26.2",
"@manypkg/get-packages": "1.1.3",
"@octokit/core": "^4.2.4",
"@octokit/graphql": "^4.8.0",
"@octokit/plugin-paginate-rest": "^2.21.3",
Expand Down Expand Up @@ -96,14 +97,19 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-test-renderer": "^18.2.0",
"remark-gfm": "3.0.1",
"remark-parse": "^10.0.1",
"remark-stringify": "^10.0.2",
"rollup": "^2.79.1",
"rollup-plugin-copy": "^3.4.0",
"rollup-plugin-extensions": "^0.1.0",
"rollup-plugin-prettier": "^2.3.0",
"rollup-plugin-terser": "^7.0.2",
"semver": "^7.5.4",
"type-fest": "^2.19.0",
"typescript": "^5.1.6"
"typescript": "^5.1.6",
"unified": "^10.1.2",
"unist-util-remove": "^3.1.0"
},
"engines": {
"node": ">=14.0.0"
Expand Down
10 changes: 3 additions & 7 deletions packages/react-router-dom/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@

### Patch Changes

- 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))
- 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))
- Updated dependencies:
- `react-router@6.20.1`
- `@remix-run/router@1.13.1`
Expand Down Expand Up @@ -417,7 +417,7 @@
## 6.12.1
> [!WARNING]
> \[!WARNING]
> 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.
### Patch Changes
Expand Down Expand Up @@ -752,7 +752,7 @@
## 6.4.0
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].
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).
**New APIs**
Expand All @@ -778,7 +778,3 @@ Whoa this is a big one! `6.4.0` brings all the data loading and mutation APIs ov
**Updated Dependencies**
- `react-router@6.4.0`
[rr-docs]: https://reactrouter.com
[rr-feature-overview]: https://reactrouter.com/start/overview
[rr-tutorial]: https://reactrouter.com/start/tutorial
11 changes: 4 additions & 7 deletions packages/react-router/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
### Patch Changes
- 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))
- 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))
- Updated dependencies:
- `@remix-run/router@1.13.1`
Expand Down Expand Up @@ -188,6 +188,7 @@
### Patch Changes

- 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))

- 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))

- ⚠️ 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.
Expand Down Expand Up @@ -300,7 +301,7 @@
## 6.12.1
> [!WARNING]
> \[!WARNING]
> 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.
### Patch Changes
Expand Down Expand Up @@ -632,7 +633,7 @@ function Comp() {
## 6.4.0
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].
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).
**New APIs**
Expand All @@ -650,7 +651,3 @@ Whoa this is a big one! `6.4.0` brings all the data loading and mutation APIs ov
**Updated Dependencies**
- `@remix-run/router@1.0.0`
[rr-docs]: https://reactrouter.com
[rr-feature-overview]: https://reactrouter.com/start/overview
[rr-tutorial]: https://reactrouter.com/start/tutorial
11 changes: 3 additions & 8 deletions packages/router/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
### Patch Changes
- 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))
- 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))
## 1.13.0
Expand Down Expand Up @@ -680,11 +680,6 @@ function Comp() {
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`.
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].
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).
For an overview of the features provided by `@remix-run/router`, please check out the [`README`][remix-router-readme].
[rr-docs]: https://reactrouter.com
[rr-feature-overview]: https://reactrouter.com/start/overview
[rr-tutorial]: https://reactrouter.com/start/tutorial
[remix-router-readme]: https://github.com/remix-run/react-router/blob/main/packages/router/README.md
For an overview of the features provided by `@remix-run/router`, please check out the [`README`](./README.md).
123 changes: 123 additions & 0 deletions scripts/remove-prerelease-changelogs.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import * as fs from "node:fs";
import path from "node:path";
import * as url from "node:url";
import { getPackagesSync } from "@manypkg/get-packages";
import remarkParse from "remark-parse";
import remarkGfm from "remark-gfm";
import rehypeStringify from "remark-stringify";
import { unified } from "unified";
import { remove } from "unist-util-remove";

const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
const rootDir = path.join(__dirname, "..");

main();

async function main() {
if (isPrereleaseMode()) {
console.log("🚫 Skipping changelog removal in prerelease mode");
return;
}
await removePreReleaseChangelogs();
console.log("✅ Removed pre-release changelogs");
}

async function removePreReleaseChangelogs() {
let allPackages = getPackagesSync(rootDir).packages;

/** @type {Promise<any>[]} */
let processes = [];
for (let pkg of allPackages) {
let changelogPath = path.join(pkg.dir, "CHANGELOG.md");
if (!fs.existsSync(changelogPath)) {
continue;
}
let changelogFileContents = fs.readFileSync(changelogPath, "utf-8");
processes.push(
(async () => {
let file = await unified()
// Since we have multiple versions of remark-parse, TS resolves to the
// wrong one
// @ts-expect-error
.use(remarkParse)
.use(remarkGfm)
.use(removePreReleaseSectionFromMarkdown)
// same problem
// @ts-expect-error
.use(rehypeStringify, {
bullet: "-",
emphasis: "_",
listItemIndent: "one",
})
.process(changelogFileContents);

let fileContents = file.toString();
await fs.promises.writeFile(changelogPath, fileContents, "utf-8");
})()
);
}
return Promise.all(processes);
}

function removePreReleaseSectionFromMarkdown() {
/**
* @param {import('./unist').RootNode} tree
* @returns {Promise<void>}
*/
async function transformer(tree) {
remove(
tree,
/**
* @param {import("./unist").Node & { __REMOVE__?: boolean }} node
* @param {number | null | undefined} index
* @param {*} parent
*/
(node, index, parent) => {
if (node.__REMOVE__ === true) return true;
if (
node.type === "heading" &&
node.depth === 2 &&
node.children[0].type === "text" &&
isPrereleaseVersion(node.children[0].value)
) {
if (index == null || parent == null) return false;

let nextIdx = 1;
let nextNode = parent.children[index + 1];
let found = false;

/** @type {import('./unist').FlowNode[]} */
while (nextNode && !found) {
if (nextNode.type === "heading" && nextNode.depth === 2) {
found = true;
break;
}
nextNode.__REMOVE__ = true;
nextNode = parent.children[++nextIdx + index];
}
return true;
}

return false;
}
);
}
return transformer;
}

/**
* @param {string} str
* @returns
*/
function isPrereleaseVersion(str) {
return /^(v?\d+\.){2}\d+-[a-z]+\.\d+$/i.test(str.trim());
}

function isPrereleaseMode() {
try {
let prereleaseFilePath = path.join(rootDir, ".changeset", "pre.json");
return fs.existsSync(prereleaseFilePath);
} catch (err) {
return false;
}
}
Loading

0 comments on commit 04d653b

Please sign in to comment.