Skip to content

Commit 3bc9781

Browse files
committed
patch mermaid-isomorphic
1 parent 26b9a1f commit 3bc9781

File tree

3 files changed

+209
-8
lines changed

3 files changed

+209
-8
lines changed

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"packageManager": "[email protected]",
77
"scripts": {
88
"analyze": "ANALYZE=true next build",
9-
"build": "pnpm playwright install-deps && pnpm playwright install chromium --only-shell && next build && next-image-export-optimizer",
9+
"build": "next build && next-image-export-optimizer",
1010
"check:links": "lychee --verbose --no-progress './src/pages/**/*.mdx' --base https://graphql.org",
1111
"dev": "next",
1212
"format": "pnpm format:check --write",
@@ -27,6 +27,7 @@
2727
"@igorkowalczyk/is-browser": "^5.1.0",
2828
"@next/bundle-analyzer": "^15.4.5",
2929
"@radix-ui/react-radio-group": "^1.2.2",
30+
"@sparticuz/chromium": "^138.0.2",
3031
"@tailwindcss/container-queries": "^0.1.1",
3132
"@tailwindcss/nesting": "0.0.0-insiders.565cd3e",
3233
"@tailwindcss/typography": "^0.5.15",
@@ -57,6 +58,7 @@
5758
"numbro": "2.5.0",
5859
"p-limit": "^4.0.0",
5960
"parser-front-matter": "1.6.4",
61+
"playwright-core": "^1.54.2",
6062
"postcss": "^8.4.49",
6163
"postcss-import": "^16.1.1",
6264
"react": "^18.3.1",
@@ -93,7 +95,6 @@
9395
"eslint-plugin-react": "^7.37.5",
9496
"eslint-plugin-react-hooks": "^5.2.0",
9597
"eslint-plugin-tailwindcss": "3.17.5",
96-
"playwright": "^1.54.2",
9798
"prettier": "3.5.3",
9899
"prettier-plugin-pkg": "^0.20.0",
99100
"prettier-plugin-tailwindcss": "^0.6.12",
@@ -103,6 +104,9 @@
103104
"tsx": "^4.19.4",
104105
"typescript": "^5.8.3"
105106
},
107+
"optionalDependencies": {
108+
"playwright": "^1.54.2"
109+
},
106110
"browserslist": [
107111
"chrome >0 and last 2.5 years",
108112
"edge >0 and last 2.5 years",
@@ -115,7 +119,8 @@
115119
"pnpm": {
116120
"patchedDependencies": {
117121
"nextra": "patches/nextra.patch",
118-
"nextra-theme-docs": "patches/nextra-theme-docs.patch"
122+
"nextra-theme-docs": "patches/nextra-theme-docs.patch",
123+
"mermaid-isomorphic": "patches/mermaid-isomorphic.patch"
119124
}
120125
}
121126
}

patches/mermaid-isomorphic.patch

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
diff --git a/dist/mermaid-isomorphic.js b/dist/mermaid-isomorphic.js
2+
index aa5dc09a5dfb58a98d3f12cd2fc473caddd97b0d..588061772d8dad6c5ddcf0794cce93fbb5bfdbe2 100644
3+
--- a/dist/mermaid-isomorphic.js
4+
+++ b/dist/mermaid-isomorphic.js
5+
@@ -1,4 +1,5 @@
6+
-import { chromium } from 'playwright';
7+
+import { chromium as playwright } from 'playwright';
8+
+import chromium from '@sparticuz/chromium';
9+
const html = import.meta.resolve('../index.html');
10+
const mermaidScript = {
11+
url: import.meta.resolve('mermaid/dist/mermaid.js')
12+
@@ -7,6 +8,9 @@ const faStyle = {
13+
// We use url, not path. If we use path, the fonts can’t be resolved.
14+
url: import.meta.resolve('@fortawesome/fontawesome-free/css/all.css')
15+
};
16+
+
17+
+chromium.setGraphicsMode = false;
18+
+
19+
/* c8 ignore start */
20+
/**
21+
* Render mermaid diagrams in the browser.
22+
@@ -122,7 +126,21 @@ async function getBrowser(browserType, launchOptions) {
23+
* A function that renders Mermaid diagrams in the browser.
24+
*/
25+
export function createMermaidRenderer(options = {}) {
26+
- const { browserType = chromium, launchOptions } = options;
27+
+ let { browserType = playwright, launchOptions } = options;
28+
+
29+
+ if (process.env.CI) {
30+
+ if (browserType) {
31+
+ throw new Error('options.browserType is not supported because @hasparus patched it to run on Vercel builds, sorry');
32+
+ }
33+
+ browserType = {
34+
+ launch: async () => playwright.launch({
35+
+ ...launchOptions,
36+
+ args: chromium.args,
37+
+ executablePath: await chromium.executablePath(),
38+
+ })
39+
+ }
40+
+ }
41+
+
42+
let browserPromise;
43+
let count = 0;
44+
return async (diagrams, renderOptions) => {

0 commit comments

Comments
 (0)