From 4dc526225d7739407bb44acbe7a5e2618bd603f9 Mon Sep 17 00:00:00 2001 From: Florian Dieminger Date: Fri, 26 Apr 2024 09:45:20 +0200 Subject: [PATCH] rename ssr to build:render and fix ci --- .github/workflows/dev-build.yml | 2 +- .github/workflows/performance.yml | 1 + .github/workflows/prod-build.yml | 3 +++ .github/workflows/stage-build.yml | 2 +- .github/workflows/testing.yml | 1 + .github/workflows/xyz-build.yml | 2 +- README.md | 11 ++++++----- build/ssr.ts | 2 ++ package.json | 2 +- scripts/testing.sh | 1 + testing/README.md | 1 + testing/scripts/functional-test.sh | 1 + 12 files changed, 20 insertions(+), 9 deletions(-) diff --git a/.github/workflows/dev-build.yml b/.github/workflows/dev-build.yml index 023f518411dd..5084e41bcb69 100644 --- a/.github/workflows/dev-build.yml +++ b/.github/workflows/dev-build.yml @@ -160,7 +160,7 @@ jobs: yarn build --sitemap-index # SSR all pages - yarn ssr + yarn build:render # Generate whatsdeployed files. yarn tool whatsdeployed --output client/build/_whatsdeployed/code.json diff --git a/.github/workflows/performance.yml b/.github/workflows/performance.yml index a5b6ea78908e..b70085f1a4da 100644 --- a/.github/workflows/performance.yml +++ b/.github/workflows/performance.yml @@ -55,6 +55,7 @@ jobs: yarn build:prepare # BUILD_FOLDERSEARCH=mdn/kitchensink yarn build BUILD_FOLDERSEARCH=web/javascript/reference/global_objects/array/foreach yarn build + yarn build:render - name: Serve and lhci env: diff --git a/.github/workflows/prod-build.yml b/.github/workflows/prod-build.yml index 3ec0c238c01c..9d2e92a31049 100644 --- a/.github/workflows/prod-build.yml +++ b/.github/workflows/prod-build.yml @@ -283,6 +283,9 @@ jobs: # Build the curriculum yarn build:curriculum + # SSR all pages + yarn build:render + # Generate whatsdeployed files. yarn tool whatsdeployed --output client/build/_whatsdeployed/code.json yarn tool whatsdeployed $CONTENT_ROOT --output client/build/_whatsdeployed/content.json diff --git a/.github/workflows/stage-build.yml b/.github/workflows/stage-build.yml index b70ccf0f7531..47dff28d7d16 100644 --- a/.github/workflows/stage-build.yml +++ b/.github/workflows/stage-build.yml @@ -307,7 +307,7 @@ jobs: yarn build:curriculum # SSR all pages - yarn ssr + yarn build:render # Generate whatsdeployed files. yarn tool whatsdeployed --output client/build/_whatsdeployed/code.json diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index eb04b376531e..40c6f94608e2 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -91,6 +91,7 @@ jobs: run: | yarn build:prepare yarn build + yarn build:render yarn start:static-server > /tmp/stdout.log 2> /tmp/stderr.log & sleep 1 diff --git a/.github/workflows/xyz-build.yml b/.github/workflows/xyz-build.yml index edb256ef09cc..800db4b75581 100644 --- a/.github/workflows/xyz-build.yml +++ b/.github/workflows/xyz-build.yml @@ -191,7 +191,7 @@ jobs: yarn build:curriculum # SSR all pages - yarn ssr + yarn build:render # Generate whatsdeployed files. yarn tool whatsdeployed --output client/build/_whatsdeployed/code.json diff --git a/README.md b/README.md index 252f6c4a051c..4cc12bd2cf42 100644 --- a/README.md +++ b/README.md @@ -221,17 +221,18 @@ pages, but you can pre-emptively build all the content in advance if desired. One potential advantage is that you can get a more complete list of all possible "flaws" across all documents before you even visit them. -The most fundamental CLI command is: +The two most fundamental CLI commands are: yarn build + yarn build:render ### What gets built -Every `index.html` becomes two files: +`yarn build` builds every `index.md` into an `index.json` which contains all +input data for our React client to render a page. -- `index.html` — a fully formed and complete HTML file -- `index.json` — the state information React needs to build the page in the - client +`yarn build:render` renders every of the previously built `index.json` into a +`index.html` which contains the fully formed and complete HTML for the page. ### Flaw checks diff --git a/build/ssr.ts b/build/ssr.ts index 8e6bf0f8e128..a5f2ad1b8407 100644 --- a/build/ssr.ts +++ b/build/ssr.ts @@ -1,6 +1,8 @@ import { fdir } from "fdir"; import { BUILD_OUT_ROOT } from "../libs/env/index.js"; import { readFile, writeFile } from "node:fs/promises"; +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-ignore import { renderHTML } from "../ssr/dist/main.js"; import { HydrationData } from "../libs/types/hydration.js"; diff --git a/package.json b/package.json index f9aba05ba373..c4cf463ce7d1 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "build:dist": "tsc -p tsconfig.dist.json", "build:glean": "cd client && cross-env VIRTUAL_ENV=venv glean translate src/telemetry/metrics.yaml src/telemetry/pings.yaml -f typescript -o src/telemetry/generated", "build:prepare": "yarn build:client && yarn build:ssr && yarn tool popularities && yarn tool spas && yarn tool gather-git-history && yarn tool build-robots-txt", + "build:render": "cross-env NODE_ENV=production NODE_OPTIONS='--no-warnings=ExperimentalWarning --loader ts-node/esm' node build/cli.ts render", "build:ssr": "cross-env NODE_ENV=production NODE_OPTIONS='--no-warnings=ExperimentalWarning --loader ts-node/esm' node ssr/prepare.ts && cd ssr && webpack --mode=production", "build:sw": "cd client/pwa && yarn && yarn build:prod", "build:sw-dev": "cd client/pwa && yarn && yarn build", @@ -38,7 +39,6 @@ "prepare": "(husky || true) && yarn install:all && yarn install:all:npm", "prettier-check": "prettier --check .", "prettier-format": "prettier --write .", - "ssr": "cross-env NODE_ENV=production NODE_OPTIONS='--no-warnings=ExperimentalWarning --loader ts-node/esm' node build/cli.ts render", "start": "(test -f client/build/index.html || yarn build:client) && (test -f ssr/dist/main.js || yarn build:ssr) && (test -f popularities.json || yarn tool popularities) && (test -d client/build/en-us/_spas || yarn tool spas) && nf -j Procfile.start start", "start:client": "cd client && cross-env NODE_ENV=development BABEL_ENV=development BROWSER=none PORT=3000 node scripts/start.js", "start:server": "node-dev --experimental-loader ts-node/esm server/index.ts", diff --git a/scripts/testing.sh b/scripts/testing.sh index 3cefc6f4079e..ed6b6ce6d42e 100755 --- a/scripts/testing.sh +++ b/scripts/testing.sh @@ -24,6 +24,7 @@ export ENV_FILE=".env.testing" yarn build:prepare yarn build +yarn build:render nohup yarn start:static-server > testing.log 2>&1 & PID=$! diff --git a/testing/README.md b/testing/README.md index d284583f6f45..4159de4607b1 100644 --- a/testing/README.md +++ b/testing/README.md @@ -22,6 +22,7 @@ To run these tests, first run: export ENV_FILE=.env.testing yarn build:prepare yarn build +yarn build:render yarn start:static-server ``` diff --git a/testing/scripts/functional-test.sh b/testing/scripts/functional-test.sh index 635115560376..30589c649ed4 100755 --- a/testing/scripts/functional-test.sh +++ b/testing/scripts/functional-test.sh @@ -5,5 +5,6 @@ export ENV_FILE=.env.testing yarn build:prepare yarn build +yarn build:render yarn test:testing $@