Skip to content

Commit

Permalink
DEV: Rebuild JS app when files change in discourse-markdown-it (#24379)
Browse files Browse the repository at this point in the history
Based on a workaround shared in embroider-build/embroider#1635 (comment)
  • Loading branch information
davidtaylorhq committed Nov 17, 2023
1 parent 0c712ea commit 8c16482
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/assets/javascripts/discourse/ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const generateWorkboxTree = require("./lib/workbox-tree-builder");
const { compatBuild } = require("@embroider/compat");
const { Webpack } = require("@embroider/webpack");
const { StatsWriterPlugin } = require("webpack-stats-plugin");
const withSideWatch = require("./lib/with-side-watch");
const RawHandlebarsCompiler = require("discourse-hbr/raw-handlebars-compiler");

process.env.BROCCOLI_ENABLED_MEMOIZE = true;
Expand Down Expand Up @@ -72,10 +73,10 @@ module.exports = function (defaults) {
"node_modules/@discourse/backburner.js/dist/named-amd/backburner.js",
},

historySupportMiddleware: false,

trees: {
app: RawHandlebarsCompiler("app"),
app: RawHandlebarsCompiler(
withSideWatch("app", { watching: ["../discourse-markdown-it"] })
),
},
});

Expand Down
27 changes: 27 additions & 0 deletions app/assets/javascripts/discourse/lib/with-side-watch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// From https://github.com/cardstack/boxel/blob/d54f834f/packages/host/lib/with-side-watch.js (MIT license)

const mergeTrees = require("broccoli-merge-trees");
const { WatchedDir } = require("broccoli-source");
const Plugin = require("broccoli-plugin");

class BroccoliNoOp extends Plugin {
constructor(path) {
super([new WatchedDir(path)]);
}
build() {}
}

/*
Doesn't change your actualTree, but causes a rebuild when any of opts.watching
trees change.
This is helpful when your build pipeline doesn't naturally watch some
dependencies that you're actively developing. For example, right now
@embroider/webpack doesn't rebuild itself when non-ember libraries change.
*/
module.exports = function withSideWatch(actualTree, opts) {
return mergeTrees([
actualTree,
...opts.watching.map((w) => new BroccoliNoOp(w)),
]);
};

0 comments on commit 8c16482

Please sign in to comment.