Skip to content

Commit

Permalink
Update mermaid to 10.8.0 + fix csp issue in firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
simov committed Mar 14, 2024
1 parent 5fb5673 commit 7a49fe1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
10 changes: 8 additions & 2 deletions build/mermaid/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ cd "$(dirname "$0")"

# before
npm ci 2> /dev/null || npm i
mkdir -p tmp

# mermaid.min.js
node fix-csp-issue.js \
node_modules/mermaid/dist/mermaid.min.js \
tmp/mermaid.min.js

# copy
cp node_modules/mermaid/dist/mermaid.min.js ../../vendor/mermaid.min.js
cp tmp/mermaid.min.js ../../vendor/mermaid.min.js

# after
rm -rf node_modules/
rm -rf node_modules/ tmp/
18 changes: 18 additions & 0 deletions build/mermaid/fix-csp-issue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

var fs = require('fs')
var path = require('path')

// mermaid.min.js
var source = path.resolve(__dirname, process.argv[2])
var target = path.resolve(__dirname, process.argv[3])
fs.writeFileSync(
target,
fs.readFileSync(source, 'utf8')
.replaceAll(
// https://github.com/mermaid-js/mermaid/issues/5378
// https://discourse.mozilla.org/t/cannot-inject-a-javascript-file-because-of-a-csp-limitations/128649
'Function("return this")',
'(() => globalThis)'
),
'utf8'
)
2 changes: 1 addition & 1 deletion build/mermaid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Markdown Viewer / Browser Extension",
"private": true,
"dependencies": {
"mermaid": "10.4.0"
"mermaid": "10.8.0"
},
"engines": {
"node": ">=18.0.0"
Expand Down

0 comments on commit 7a49fe1

Please sign in to comment.