diff --git a/.github/scripts/clean-tracked-rescript-output.sh b/.github/scripts/clean-tracked-rescript-output.sh new file mode 100644 index 000000000..fe3ba5edf --- /dev/null +++ b/.github/scripts/clean-tracked-rescript-output.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +set -euo pipefail + +# rescript clean only knows sources that still belong to the build. Identify +# tracked compiler output from the index so deleted/excluded sources are covered, +# while handwritten JavaScript and configuration remain untouched. +git ls-files -z -- '*.jsx' '*.mjs' | + while IFS= read -r -d '' output; do + committed=$(git show ":$output") + if [[ "$committed" == "// Generated by ReScript,"* ]]; then + rm -f -- "$output" + fi + done diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index cdea97b7e..3bc1319f6 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -17,7 +17,7 @@ jobs: cache: yarn - name: Install dependencies run: yarn - - name: Format check + - name: Check formatting (Oxfmt and ReScript) run: yarn ci:format Site_Checks: runs-on: ubuntu-latest @@ -39,6 +39,8 @@ jobs: run: | yarn check:routes git diff --exit-code -- packages/shared/src/Path.res + - name: Check committed ReScript output + run: yarn ci:generated - name: Test examples and hrefs run: yarn test # Check the built Docs Pages routes and the Guide local dev server. diff --git a/README.md b/README.md index bbd6c6718..361960195 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,21 @@ ReScript builds and when starting the ReScript watcher. After changing routes, adding or removing MDX pages, or updating API data during a watch session, run `yarn build:routes` again. CI rejects a stale generated file. +### Formatting and Generated Output + +`yarn ci:format` checks Oxfmt formatting and ReScript formatting across all four +workspaces. Run `yarn format` to apply both formatters. + +`yarn ci:generated` cleans ReScript artifacts, removes tracked compiler output, +and rebuilds, then fails if any tracked `.jsx` or `.mjs` file differs from the +committed version. Most compiler output is ignored by Git; the guide's +`app/root.jsx` and `app/routes.jsx` are currently tracked. After changing their +ReScript sources or updating the compiler, run `yarn build:res` and commit the +regenerated output alongside the sources. + +Both checks run on pull requests. Removing tracked output before rebuilding also +catches orphaned output whose source was deleted or excluded from the build. + ### Vitest Browser Tests We use [Vitest](https://vitest.dev/) in browser mode with Playwright for component-level tests. Test files live in `__tests__/` and are written in ReScript. diff --git a/apps/docs/package.json b/apps/docs/package.json index 22b6ccdf6..761b69db1 100644 --- a/apps/docs/package.json +++ b/apps/docs/package.json @@ -26,7 +26,7 @@ "dev:vite": "react-router dev --host", "dev:wrangler": "yarn build:vite && yarn wrangler pages dev build/client", "dev": "yarn prepare && yarn dev:res & yarn dev:vite & yarn dev:wrangler", - "format": "cd ../.. && oxfmt && cd apps/docs && rescript format", + "format": "cd ../.. && yarn format", "prepare": "yarn build:res && yarn build:scripts && yarn check:algolia-public-env && yarn build:update-index", "preview": "yarn build && static-server build/client", "serve:build": "static-server --host 127.0.0.1 --port 4173 build/client", diff --git a/apps/guide/app/routes.jsx b/apps/guide/app/routes.jsx index c22c7185b..e793a07bf 100644 --- a/apps/guide/app/routes.jsx +++ b/apps/guide/app/routes.jsx @@ -4,5 +4,7 @@ import * as Routes from "@react-router/dev/routes"; let $$default = [Routes.index("./GuideHomeRoute.jsx")]; -export { $$default as default }; +export { + $$default as default, +} /* default Not a pure module */ diff --git a/package.json b/package.json index bd5bcbe2a..30c76f813 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,8 @@ "build:update-index": "yarn workspace @rescript-lang/docs build:update-index", "build:vite": "yarn workspace @rescript-lang/docs build:vite", "build": "yarn workspace @rescript-lang/docs build", - "ci:format": "oxfmt --check", + "ci:format": "oxfmt --check && rescript format --check", + "ci:generated": "yarn clean:res && bash .github/scripts/clean-tracked-rescript-output.sh && yarn build:res && git diff --exit-code -- '*.jsx' '*.mjs'", "ci:test": "yarn workspace @rescript-lang/docs ci:test && yarn workspace @rescript-lang/guide ci:test", "ci:test:visual": "yarn workspace @rescript-lang/docs ci:test:visual", "clean:res": "rescript clean", @@ -27,7 +28,7 @@ "dev:res": "yarn build:routes && rescript watch", "dev:guide": "yarn workspace @rescript-lang/guide dev:vite", "dev": "yarn workspace @rescript-lang/docs dev", - "format": "yarn workspace @rescript-lang/docs format", + "format": "oxfmt && rescript format", "preview": "yarn workspace @rescript-lang/docs preview", "reanalyze": "yarn workspace @rescript-lang/docs reanalyze", "test": "yarn workspace @rescript-lang/docs test",