discourse/app/assets/javascripts/admin/index.js
Godfrey Chan 3d7cca5911
DEV: invert admin/wizard build logic (#22520)
Currently, the admin/wizard build relies on the addon build getting
triggered first, so that its `treeForAddon()` hook will be called,
and then it can stash the result on the app's options, which is
super fragile. In Embroider the timing works differently so the
trees end up being `undefined`.

This inverts the logic so that it will be discourse core's build
calling these hooks at a specific timing and return the result
rather than coordinating through the options bag.

```
$ diff dist/assets/admin.js dist-after/assets/admin.js
$ diff dist/assets/wizard.js dist-after/assets/wizard.js
```
2023-07-10 22:07:21 +01:00

32 lines
866 B
JavaScript

"use strict";
const calculateCacheKeyForTree = require("calculate-cache-key-for-tree");
const path = require("path");
module.exports = {
name: require("./package").name,
// return an empty tree here as we do not want the addon modules to be
// included into vendor.js; instead, we will produce a separate bundle
// (admin.js) to be included via a script tag as needed
treeForAddon() {
return;
},
// custom method to produce the tree for admin.js
// called by ember-cli-build.js in discourse core
treeForAddonBundle() {
let addonTreePath = path.resolve(this.root, this.treePaths.addon);
let addonTree = this.treeGenerator(addonTreePath);
return this._super.treeForAddon.call(this, addonTree);
},
cacheKeyForTree(tree) {
return calculateCacheKeyForTree(tree, this);
},
isDevelopingAddon() {
return true;
},
};