diff --git a/app/assets/javascripts/discourse/ember-cli-build.js b/app/assets/javascripts/discourse/ember-cli-build.js index bdc90104bdc..c981472629d 100644 --- a/app/assets/javascripts/discourse/ember-cli-build.js +++ b/app/assets/javascripts/discourse/ember-cli-build.js @@ -4,7 +4,6 @@ const EmberApp = require("ember-cli/lib/broccoli/ember-app"); const resolve = require("path").resolve; const mergeTrees = require("broccoli-merge-trees"); const concat = require("broccoli-concat"); -const prettyTextEngine = require("./lib/pretty-text-engine"); const { createI18nTree } = require("./lib/translation-plugin"); const { parsePluginClientSettings } = require("./lib/site-settings-plugin"); const discourseScss = require("./lib/discourse-scss"); @@ -186,6 +185,10 @@ module.exports = function (defaults) { const wizardTree = app.project.findAddonByName("wizard").treeForAddonBundle(); + const markdownItBundleTree = app.project + .findAddonByName("pretty-text") + .treeForMarkdownItBundle(); + const terserPlugin = app.project.findAddonByName("ember-cli-terser"); const applyTerser = (tree) => terserPlugin.postprocessTree("all", tree); @@ -211,7 +214,12 @@ module.exports = function (defaults) { outputFile: `assets/wizard.js`, }) ), - applyTerser(prettyTextEngine(app)), + applyTerser( + concat(markdownItBundleTree, { + inputFiles: ["**/*.js"], + outputFile: `assets/markdown-it-bundle.js`, + }) + ), generateScriptsTree(app), applyTerser(discoursePluginsTree), ]); diff --git a/app/assets/javascripts/discourse/lib/pretty-text-engine.js b/app/assets/javascripts/discourse/lib/pretty-text-engine.js deleted file mode 100644 index 08d91f1877a..00000000000 --- a/app/assets/javascripts/discourse/lib/pretty-text-engine.js +++ /dev/null @@ -1,28 +0,0 @@ -const mergeTrees = require("broccoli-merge-trees"); -const funnel = require("broccoli-funnel"); -const concat = require("broccoli-concat"); -const WatchedDir = require("broccoli-source").WatchedDir; -const Funnel = require("broccoli-funnel"); - -module.exports = function prettyTextEngine(app) { - let babelAddon = app.project.findAddonByName("ember-cli-babel"); - - const sourceTree = new WatchedDir( - "../pretty-text/engines/discourse-markdown" - ); - const namespacedTree = new Funnel(sourceTree, { - getDestinationPath: function (relativePath) { - return `pretty-text/engines/discourse-markdown/${relativePath}`; - }, - }); - - const engineTree = babelAddon.transpileTree(namespacedTree); - - let markdownIt = funnel("../node_modules/markdown-it/dist", { - files: ["markdown-it.js"], - }); - return concat(mergeTrees([engineTree, markdownIt]), { - inputFiles: ["**/*.js"], - outputFile: `assets/markdown-it-bundle.js`, - }); -}; diff --git a/app/assets/javascripts/discourse/package.json b/app/assets/javascripts/discourse/package.json index 6e373f4b0f9..5a1168cde1f 100644 --- a/app/assets/javascripts/discourse/package.json +++ b/app/assets/javascripts/discourse/package.json @@ -21,7 +21,6 @@ "discourse-widget-hbs": "1.0.0", "ember-source": "~3.28.12", "handlebars": "^4.7.7", - "markdown-it": "^13.0.1", "pretty-text": "1.0.0" }, "devDependencies": { diff --git a/app/assets/javascripts/pretty-text/index.js b/app/assets/javascripts/pretty-text/index.js index d4a9ef20380..7b77a4dfbf6 100644 --- a/app/assets/javascripts/pretty-text/index.js +++ b/app/assets/javascripts/pretty-text/index.js @@ -1,7 +1,44 @@ "use strict"; +const Funnel = require("broccoli-funnel"); +const mergeTrees = require("broccoli-merge-trees"); +const path = require("path"); + module.exports = { name: require("./package").name, + + // custom method to produce the tree for markdown-it-bundle.js + // called by ember-cli-build.js in discourse core + // + // code in here is only needed by the editor and we do not want them included + // into the main addon/vendor bundle; instead, it'll be included via a script + // tag as needed + treeForMarkdownItBundle() { + return mergeTrees([this._treeForEngines(), this._treeForMarkdownIt()]); + }, + + // treat the JS code in /engines like any other JS code in the /addon folder + _treeForEngines() { + let enginesTreePath = path.resolve(this.root, "engines"); + let enginesTree = this.treeGenerator(enginesTreePath); + + // we started at /engines, if we just call treeForAddon, the modules will + // be under pretty-text/*, but we want pretty-text/engines/* + let namespacedTree = new Funnel(enginesTree, { + destDir: "engines", + }); + + return this.treeForAddon.call(this, namespacedTree); + }, + + _treeForMarkdownIt() { + let markdownIt = require.resolve("markdown-it/dist/markdown-it.js"); + + return new Funnel(path.dirname(markdownIt), { + files: ["markdown-it.js"], + }); + }, + isDevelopingAddon() { return true; }, diff --git a/app/assets/javascripts/pretty-text/package.json b/app/assets/javascripts/pretty-text/package.json index e5ad0547d5b..8f310b7ce28 100644 --- a/app/assets/javascripts/pretty-text/package.json +++ b/app/assets/javascripts/pretty-text/package.json @@ -37,6 +37,7 @@ "ember-source": "~3.28.12", "ember-source-channel-url": "^3.0.0", "loader.js": "^4.7.0", + "markdown-it": "^13.0.1", "webpack": "^5.88.1" }, "engines": {