Skip to content

Commit

Permalink
chore(ssr): delete root index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoMcA committed Aug 23, 2024
1 parent e93d8f6 commit 2db5633
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"build:docs": "cross-env NODE_ENV=production NODE_OPTIONS='--no-warnings=ExperimentalWarning --loader ts-node/esm' node build/cli.ts -n",
"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: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:ssr": "cross-env NODE_ENV=production NODE_OPTIONS='--no-warnings=ExperimentalWarning --loader ts-node/esm' node ssr/prepare.ts && cd ssr && webpack --mode=production && node rm-index.js",
"build:sw": "cd client/pwa && yarn && yarn build:prod",
"build:sw-dev": "cd client/pwa && yarn && yarn build",
"check:tsc": "find . -name 'tsconfig.json' ! -wholename '**/node_modules/**' -print0 | xargs -n1 -P 2 -0 sh -c 'cd `dirname $0` && echo \"🔄 $(pwd)\" && npx tsc --noEmit && echo \"☑️ $(pwd)\" || exit 255'",
Expand All @@ -41,7 +41,7 @@
"prettier-check": "prettier --check .",
"prettier-format": "prettier --write .",
"render:html": "cross-env NODE_ENV=production NODE_OPTIONS='--no-warnings=ExperimentalWarning --loader ts-node/esm' node build/ssr-cli.ts",
"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": "(test -f client/build/asset-manifest.json || 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 PORT=3000 node scripts/start.js",
"start:server": "node-dev --experimental-loader ts-node/esm server/index.ts",
"start:static-server": "cross-env NODE_OPTIONS='--no-warnings=ExperimentalWarning --loader ts-node/esm' node server/static.ts",
Expand Down
1 change: 1 addition & 0 deletions ssr/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
include.ts
!*.js
9 changes: 9 additions & 0 deletions ssr/rm-index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// temporary script to delete root index.html for testing
// seperate from https://github.com/mdn/yari/pull/11672
import fs from "node:fs";
import path from "node:path";

import paths from "../client/config/paths.js";

const indexHtmlFilePath = path.join(paths.appBuild, "index.html");
fs.rmSync(indexHtmlFilePath);
10 changes: 8 additions & 2 deletions testing/tests/csp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@ describe("Content-Security-Policy", () => {
return `'${algo}-${hash}'`;
}

const indexHtmlPath = path.join("client", "build", "index.html");
const indexHtmlPath = path.join("client", "build", "en-us", "index.html");
const indexHtmlContent = fs.readFileSync(indexHtmlPath).toString();

const inlineScriptMatches = [
...indexHtmlContent.matchAll(/(<script.*?>)(.*?)(<\/script>)/gi),
];

const inlineScriptContents = inlineScriptMatches
.filter((match) => !match[1].includes("src="))
.filter(
(match) =>
!(
match[1].includes("src=") ||
match[1].includes(`type="application/json"`)
)
)
.map((match) => match[2]);

// If this assertion fails, an inline script was added to client/public/index.html`.
Expand Down

0 comments on commit 2db5633

Please sign in to comment.