FEATURE: upgrade to graphviz 2.44 from 2.40

FEATURE: upgrade to graphviz 2.44 from 2.40

This introduces a new script (upgrade-viz-js) which can be used to upgrade graphviz.

It uses a maintained fork of viz.js at: https://github.com/aduh95/viz.js

This new fork ships the old asm.js version of viz js which is easy to bundle and run.

It fork also ships webassembly versions, but there are many security implications of running webassembly in the browser including CSP and CORS. So we avoid webassembly. (despite mini racer being able to run it)

diff --git a/assets/javascripts/initializers/discourse-graphviz.js.es6 b/assets/javascripts/initializers/discourse-graphviz.js.es6
index ce3622a..9b40aa4 100644
--- a/assets/javascripts/initializers/discourse-graphviz.js.es6
+++ b/assets/javascripts/initializers/discourse-graphviz.js.es6
@@ -24,13 +24,13 @@ export default {
     const $spinner = $("<div class='spinner tiny'></div>");
     $container.html($spinner);
 
-    loadScript("/plugins/discourse-graphviz/javascripts/viz-1.8.2.js").then(
+    loadScript("/plugins/discourse-graphviz/javascripts/viz-3.0.1.js").then(
       () => {
         $container.removeClass("is-loading");
 
         try {
-          /* global Viz */
-          const svgChart = Viz(graphDefinition, {
+          /* global vizRenderStringSync */
+          const svgChart = vizRenderStringSync(graphDefinition, {
             format: "svg",
             engine
           });
diff --git a/plugin.rb b/plugin.rb
index 0f6b922..3be1fc5 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -14,7 +14,7 @@ after_initialize do
 
   def context
     context = MiniRacer::Context.new
-    context.load("#{Rails.root}/plugins/discourse-graphviz/public/javascripts/viz-1.8.2.js")
+    context.load("#{Rails.root}/plugins/discourse-graphviz/public/javascripts/viz-3.0.1.js")
     context
   end
 
@@ -27,7 +27,7 @@ after_initialize do
 
       doc.css('div.graphviz').each do |graph|
         engine = graph.attribute('data-engine').value
-        svg_graph = context.eval("Viz(#{graph.children[0].content.inspect}, {engine: '#{engine}'})") rescue nil
+        svg_graph = context.eval("vizRenderStringSync(#{graph.children[0].content.inspect}, {engine: '#{engine}'})") rescue nil
         next if svg_graph.nil?
 
         should_use_svg = SiteSetting.graphviz_default_svg
diff --git a/public/javascripts/viz-1.8.2.js b/public/javascripts/viz-1.8.2.js
deleted file mode 100644
index b9e7a52..0000000
--- a/public/javascripts/viz-1.8.2.js
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
-Viz.js 1.8.2 (Graphviz 2.40.1, Expat 2.2.5, Emscripten 1.37.33)
-Copyright (c) 2014-2018 Michael Daines
-Licensed under MIT license
-
-This distribution contains other software in object code form:
-
-Graphviz
-Licensed under Eclipse Public License - v 1.0
-http://www.graphviz.org
-
-Expat
-Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd and Clark Cooper
-Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006 Expat maintainers.
-Licensed under MIT license
-http://www.libexpat.org
-
-zlib
-Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler
-http://www.zlib.net/zlib_license.html
-*/
-(function(global) {
-var Module = function(Module) {
-  Module = Module || {};

[... diff too long, it was truncated ...]

GitHub sha: 25819543

1 Like