DEV: Compile markdown-it-bundle with ember-cli (#18104)
We were already compiling the markdown bundle via ember-cli, but that version was only being used in the test environment. This commit improves the implementation, and updates the filename so it's also used in production. This commit also - Removes the vendored copy of `markdown-it.js` and fetches from node_modules instead - Updates `pretty_text.rb` to remove the custom sprockets-manifest-parsing - Removes `pretty-text-bundle.js`, which was only being used by `pretty_text.rb`
This commit is contained in:
parent
4116bce902
commit
1bd1664ae0
|
@ -178,7 +178,7 @@ module.exports = function (defaults) {
|
|||
outputFile: `assets/wizard.js`,
|
||||
})
|
||||
),
|
||||
prettyTextEngine(vendorJs, "discourse-markdown"),
|
||||
applyTerser(prettyTextEngine(app)),
|
||||
concat("public/assets/scripts", {
|
||||
outputFile: `assets/start-discourse.js`,
|
||||
headerFiles: [`start-app.js`],
|
||||
|
|
|
@ -1,21 +1,28 @@
|
|||
const babel = require("broccoli-babel-transpiler");
|
||||
const mergeTrees = require("broccoli-merge-trees");
|
||||
const funnel = require("broccoli-funnel");
|
||||
const path = require("path");
|
||||
const concat = require("broccoli-concat");
|
||||
const WatchedDir = require("broccoli-source").WatchedDir;
|
||||
const Funnel = require("broccoli-funnel");
|
||||
|
||||
module.exports = function prettyTextEngine(vendorJs, engine) {
|
||||
let engineTree = babel(`../pretty-text/engines/${engine}`, {
|
||||
plugins: ["@babel/plugin-transform-modules-amd"],
|
||||
moduleIds: true,
|
||||
module.exports = function prettyTextEngine(app) {
|
||||
let babelAddon = app.project.findAddonByName("ember-cli-babel");
|
||||
|
||||
getModuleId(name) {
|
||||
return `pretty-text/engines/${engine}/${path.basename(name)}`;
|
||||
const sourceTree = new WatchedDir(
|
||||
"../pretty-text/engines/discourse-markdown"
|
||||
);
|
||||
const namespacedTree = new Funnel(sourceTree, {
|
||||
getDestinationPath: function (relativePath) {
|
||||
return `pretty-text/engines/discourse-markdown/${relativePath}`;
|
||||
},
|
||||
});
|
||||
|
||||
let markdownIt = funnel(vendorJs, { files: ["markdown-it.js"] });
|
||||
const engineTree = babelAddon.transpileTree(namespacedTree);
|
||||
|
||||
let markdownIt = funnel("../node_modules/markdown-it/dist", {
|
||||
files: ["markdown-it.js"],
|
||||
});
|
||||
return concat(mergeTrees([engineTree, markdownIt]), {
|
||||
outputFile: `assets/${engine}.js`,
|
||||
inputFiles: ["**/*.js"],
|
||||
outputFile: `assets/markdown-it-bundle.js`,
|
||||
});
|
||||
};
|
||||
|
|
|
@ -72,6 +72,7 @@
|
|||
"js-yaml": "^4.1.0",
|
||||
"jsdom": "^20.0.0",
|
||||
"loader.js": "^4.7.0",
|
||||
"markdown-it": "^13.0.1",
|
||||
"message-bus-client": "^4.2.0",
|
||||
"messageformat": "0.1.5",
|
||||
"node-fetch": "^2.6.6",
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
<script src="{{rootURL}}assets/test-support.js"></script>
|
||||
<ember-auto-import-scripts entrypoint="tests"></ember-auto-import-scripts>
|
||||
<script src="{{rootURL}}assets/discourse.js"></script>
|
||||
<script src="{{rootURL}}assets/discourse-markdown.js"></script>
|
||||
<script src="{{rootURL}}assets/markdown-it-bundle.js"></script>
|
||||
<script src="{{rootURL}}assets/admin.js"></script>
|
||||
<script src="{{rootURL}}assets/wizard.js"></script>
|
||||
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
//= require markdown-it.js
|
||||
//= require_tree ./pretty-text/engines/discourse-markdown
|
|
@ -1,14 +0,0 @@
|
|||
//= require ./pretty-text/addon/pretty-text
|
||||
//= require ./pretty-text/addon/guid
|
||||
//= require ./pretty-text/addon/censored-words
|
||||
//= require ./pretty-text/addon/emoji/data
|
||||
//= require ./pretty-text/addon/emoji/version
|
||||
//= require ./pretty-text/addon/emoji
|
||||
//= require ./pretty-text/addon/engines/discourse-markdown-it
|
||||
//= require ./node_modules/xss/dist/xss.min
|
||||
//= require ./pretty-text/addon/allow-lister
|
||||
//= require ./pretty-text/addon/sanitizer
|
||||
//= require ./pretty-text/addon/oneboxer
|
||||
//= require ./pretty-text/addon/oneboxer-cache
|
||||
//= require ./pretty-text/addon/inline-oneboxer
|
||||
//= require ./pretty-text/addon/upload-short-url
|
|
@ -5043,6 +5043,11 @@ entities@~2.1.0:
|
|||
resolved "https://registry.yarnpkg.com/entities/-/entities-2.1.0.tgz#992d3129cf7df6870b96c57858c249a120f8b8b5"
|
||||
integrity sha512-hCx1oky9PFrJ611mf0ifBLBRW8lUUVRlFolb5gWRfIELabBlbp9xZvrqZLZAs+NxFnbfQoeGd8wDkygjg7U85w==
|
||||
|
||||
entities@~3.0.1:
|
||||
version "3.0.1"
|
||||
resolved "https://registry.yarnpkg.com/entities/-/entities-3.0.1.tgz#2b887ca62585e96db3903482d336c1006c3001d4"
|
||||
integrity sha512-WiyBqoomrwMdFG1e0kqvASYfnlb0lp8M5o5Fw2OFq1hNZxxcNk8Ik0Xm7LxzBhuidnZB/UtBqVCgUz3kBOP51Q==
|
||||
|
||||
errlop@^2.0.0:
|
||||
version "2.2.0"
|
||||
resolved "https://registry.yarnpkg.com/errlop/-/errlop-2.2.0.tgz#1ff383f8f917ae328bebb802d6ca69666a42d21b"
|
||||
|
@ -7278,6 +7283,13 @@ linkify-it@^3.0.1:
|
|||
dependencies:
|
||||
uc.micro "^1.0.1"
|
||||
|
||||
linkify-it@^4.0.1:
|
||||
version "4.0.1"
|
||||
resolved "https://registry.yarnpkg.com/linkify-it/-/linkify-it-4.0.1.tgz#01f1d5e508190d06669982ba31a7d9f56a5751ec"
|
||||
integrity sha512-C7bfi1UZmoj8+PQx22XyeXCuBlokoyWQL5pWSP+EI6nzRylyThouddufc2c1NDIcP9k5agmN9fLpA7VNJfIiqw==
|
||||
dependencies:
|
||||
uc.micro "^1.0.1"
|
||||
|
||||
livereload-js@^3.3.1:
|
||||
version "3.3.2"
|
||||
resolved "https://registry.yarnpkg.com/livereload-js/-/livereload-js-3.3.2.tgz#c88b009c6e466b15b91faa26fd7c99d620e12651"
|
||||
|
@ -7637,6 +7649,17 @@ markdown-it@^12.0.4:
|
|||
mdurl "^1.0.1"
|
||||
uc.micro "^1.0.5"
|
||||
|
||||
markdown-it@^13.0.1:
|
||||
version "13.0.1"
|
||||
resolved "https://registry.yarnpkg.com/markdown-it/-/markdown-it-13.0.1.tgz#c6ecc431cacf1a5da531423fc6a42807814af430"
|
||||
integrity sha512-lTlxriVoy2criHP0JKRhO2VDG9c2ypWCsT237eDiLqi09rmbKoUetyGHq2uOIRoRS//kfoJckS0eUzzkDR+k2Q==
|
||||
dependencies:
|
||||
argparse "^2.0.1"
|
||||
entities "~3.0.1"
|
||||
linkify-it "^4.0.1"
|
||||
mdurl "^1.0.1"
|
||||
uc.micro "^1.0.5"
|
||||
|
||||
markdown-it@^8.3.1:
|
||||
version "8.4.2"
|
||||
resolved "https://registry.yarnpkg.com/markdown-it/-/markdown-it-8.4.2.tgz#386f98998dc15a37722aa7722084f4020bdd9b54"
|
||||
|
|
|
@ -31,7 +31,6 @@ Rails.application.config.assets.precompile += %w{
|
|||
browser-detect.js
|
||||
browser-update.js
|
||||
break_string.js
|
||||
pretty-text-bundle.js
|
||||
markdown-it-bundle.js
|
||||
service-worker.js
|
||||
google-tag-manager.js
|
||||
|
|
|
@ -12,7 +12,7 @@ module EmberCli
|
|||
admin.js
|
||||
wizard.js
|
||||
ember_jquery.js
|
||||
pretty-text-bundle.js
|
||||
markdown-it-bundle.js
|
||||
start-discourse.js
|
||||
vendor.js
|
||||
)
|
||||
|
|
|
@ -63,20 +63,10 @@ module PrettyText
|
|||
end
|
||||
end
|
||||
|
||||
def self.ctx_load_manifest(ctx, name)
|
||||
manifest = File.read("#{Rails.root}/app/assets/javascripts/#{name}")
|
||||
def self.ctx_load_directory(ctx, path)
|
||||
root_path = "#{Rails.root}/app/assets/javascripts/"
|
||||
|
||||
manifest.each_line do |l|
|
||||
l = l.chomp
|
||||
if l =~ /\/\/= require (\.\/)?(.*)$/
|
||||
apply_es6_file(ctx, root_path, Regexp.last_match[2])
|
||||
elsif l =~ /\/\/= require_tree (\.\/)?(.*)$/
|
||||
path = Regexp.last_match[2]
|
||||
Dir["#{root_path}/#{path}/**"].sort.each do |f|
|
||||
apply_es6_file(ctx, root_path, f.sub(root_path, '')[1..-1].sub(/\.js(.es6)?$/, ''))
|
||||
end
|
||||
end
|
||||
Dir["#{root_path}#{path}/**/*"].sort.each do |f|
|
||||
apply_es6_file(ctx, root_path, f.sub(root_path, '').sub(/\.js(.es6)?$/, ''))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -103,13 +93,14 @@ module PrettyText
|
|||
ctx.attach("__helpers.#{method}", PrettyText::Helpers.method(method))
|
||||
end
|
||||
|
||||
ctx_load(ctx, "#{Rails.root}/app/assets/javascripts/mini-loader.js")
|
||||
ctx_load(ctx, "#{Rails.root}/app/assets/javascripts/handlebars-shim.js")
|
||||
ctx_load(ctx, "#{Rails.root}/app/assets/javascripts/node_modules/xss/dist/xss.min.js")
|
||||
ctx.load("#{Rails.root}/lib/pretty_text/vendor-shims.js")
|
||||
ctx_load_manifest(ctx, "pretty-text-bundle.js")
|
||||
ctx_load_manifest(ctx, "markdown-it-bundle.js")
|
||||
root_path = "#{Rails.root}/app/assets/javascripts/"
|
||||
ctx_load(ctx, "#{root_path}/mini-loader.js")
|
||||
ctx_load(ctx, "#{root_path}/handlebars-shim.js")
|
||||
ctx_load(ctx, "#{root_path}/node_modules/xss/dist/xss.js")
|
||||
ctx.load("#{Rails.root}/lib/pretty_text/vendor-shims.js")
|
||||
ctx_load_directory(ctx, "pretty-text/addon")
|
||||
ctx_load_directory(ctx, "pretty-text/engines/discourse-markdown")
|
||||
ctx_load(ctx, "#{root_path}/node_modules/markdown-it/dist/markdown-it.js")
|
||||
|
||||
apply_es6_file(ctx, root_path, "discourse-common/addon/lib/get-url")
|
||||
apply_es6_file(ctx, root_path, "discourse-common/addon/lib/object")
|
||||
|
|
|
@ -89,8 +89,6 @@ def dependencies
|
|||
}, {
|
||||
source: '@highlightjs/cdn-assets/.',
|
||||
destination: 'highlightjs'
|
||||
}, {
|
||||
source: 'markdown-it/dist/markdown-it.js'
|
||||
}, {
|
||||
source: 'moment/moment.js'
|
||||
}, {
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
"diffhtml": "^1.0.0-beta.20",
|
||||
"eslint-config-discourse": "^3.3.0",
|
||||
"magnific-popup": "1.1.0",
|
||||
"markdown-it": "13.0.1",
|
||||
"moment": "2.29.2",
|
||||
"moment-timezone": "0.5.31",
|
||||
"pikaday": "1.8.0",
|
||||
|
|
File diff suppressed because it is too large
Load Diff
33
yarn.lock
33
yarn.lock
|
@ -979,11 +979,6 @@ end-of-stream@^1.0.0, end-of-stream@^1.1.0, end-of-stream@^1.4.1:
|
|||
dependencies:
|
||||
once "^1.4.0"
|
||||
|
||||
entities@~3.0.1:
|
||||
version "3.0.1"
|
||||
resolved "https://registry.yarnpkg.com/entities/-/entities-3.0.1.tgz#2b887ca62585e96db3903482d336c1006c3001d4"
|
||||
integrity sha512-WiyBqoomrwMdFG1e0kqvASYfnlb0lp8M5o5Fw2OFq1hNZxxcNk8Ik0Xm7LxzBhuidnZB/UtBqVCgUz3kBOP51Q==
|
||||
|
||||
escalade@^3.1.1:
|
||||
version "3.1.1"
|
||||
resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.1.1.tgz#d8cfdc7000965c5a0174b4a82eaa5c0552742e40"
|
||||
|
@ -1676,13 +1671,6 @@ lighthouse-logger@^1.0.0:
|
|||
debug "^2.6.8"
|
||||
marky "^1.2.0"
|
||||
|
||||
linkify-it@^4.0.1:
|
||||
version "4.0.1"
|
||||
resolved "https://registry.yarnpkg.com/linkify-it/-/linkify-it-4.0.1.tgz#01f1d5e508190d06669982ba31a7d9f56a5751ec"
|
||||
integrity sha512-C7bfi1UZmoj8+PQx22XyeXCuBlokoyWQL5pWSP+EI6nzRylyThouddufc2c1NDIcP9k5agmN9fLpA7VNJfIiqw==
|
||||
dependencies:
|
||||
uc.micro "^1.0.1"
|
||||
|
||||
locate-path@^5.0.0:
|
||||
version "5.0.0"
|
||||
resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-5.0.0.tgz#1afba396afd676a6d42504d0a67a3a7eb9f62aa0"
|
||||
|
@ -1739,17 +1727,6 @@ magnific-popup@1.1.0:
|
|||
resolved "https://registry.yarnpkg.com/magnific-popup/-/magnific-popup-1.1.0.tgz#3e7362c5bd18f6785fe99e59d013e20af33d3049"
|
||||
integrity sha1-PnNixb0Y9nhf6Z5Z0BPiCvM9MEk=
|
||||
|
||||
markdown-it@13.0.1:
|
||||
version "13.0.1"
|
||||
resolved "https://registry.yarnpkg.com/markdown-it/-/markdown-it-13.0.1.tgz#c6ecc431cacf1a5da531423fc6a42807814af430"
|
||||
integrity sha512-lTlxriVoy2criHP0JKRhO2VDG9c2ypWCsT237eDiLqi09rmbKoUetyGHq2uOIRoRS//kfoJckS0eUzzkDR+k2Q==
|
||||
dependencies:
|
||||
argparse "^2.0.1"
|
||||
entities "~3.0.1"
|
||||
linkify-it "^4.0.1"
|
||||
mdurl "^1.0.1"
|
||||
uc.micro "^1.0.5"
|
||||
|
||||
marky@^1.2.0:
|
||||
version "1.2.1"
|
||||
resolved "https://registry.yarnpkg.com/marky/-/marky-1.2.1.tgz#a3fcf82ffd357756b8b8affec9fdbf3a30dc1b02"
|
||||
|
@ -1760,11 +1737,6 @@ mdn-data@2.0.27:
|
|||
resolved "https://registry.yarnpkg.com/mdn-data/-/mdn-data-2.0.27.tgz#1710baa7b0db8176d3b3d565ccb7915fc69525ab"
|
||||
integrity sha512-kwqO0I0jtWr25KcfLm9pia8vLZ8qoAKhWZuZMbneJq3jjBD3gl5nZs8l8Tu3ZBlBAHVQtDur9rdDGyvtfVraHQ==
|
||||
|
||||
mdurl@^1.0.1:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/mdurl/-/mdurl-1.0.1.tgz#fe85b2ec75a59037f2adfec100fd6c601761152e"
|
||||
integrity sha1-/oWy7HWlkDfyrf7BAP1sYBdhFS4=
|
||||
|
||||
merge2@^1.3.0, merge2@^1.4.1:
|
||||
version "1.4.1"
|
||||
resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.4.1.tgz#4368892f885e907455a6fd7dc55c0c9d404990ae"
|
||||
|
@ -2412,11 +2384,6 @@ type-fest@^0.20.2:
|
|||
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.20.2.tgz#1bf207f4b28f91583666cb5fbd327887301cd5f4"
|
||||
integrity sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==
|
||||
|
||||
uc.micro@^1.0.1, uc.micro@^1.0.5:
|
||||
version "1.0.6"
|
||||
resolved "https://registry.yarnpkg.com/uc.micro/-/uc.micro-1.0.6.tgz#9c411a802a409a91fc6cf74081baba34b24499ac"
|
||||
integrity sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA==
|
||||
|
||||
unbzip2-stream@1.4.3:
|
||||
version "1.4.3"
|
||||
resolved "https://registry.yarnpkg.com/unbzip2-stream/-/unbzip2-stream-1.4.3.tgz#b0da04c4371311df771cdc215e87f2130991ace7"
|
||||
|
|
Loading…
Reference in New Issue