We created a custom Sprockets directive for the Custom Wizard plugin

AI-generated summary

The Custom Wizard plugin team created a custom Sprockets directive, require_tree_discourse, to mitigate issues with requiring multiple files from the same folder in the Discourse core. Initially, the change was reverted due to production issues, but it has since been re-introduced fzngagan. The directive allows the plugin to look up assets inside the Discourse folder using absolute paths, reducing the likelihood of breakages due to changes in the Discourse core. However, it’s worth noting that Discourse is planning to abandon Sprockets for ember-cli based builds within the next 12 months sam, and any guidance on this transition would be appreciated fzngagan.

The Custom Wizard plugin creates its own Ember app and borrows some of the assets from the discourse core.

For that we use a js file called wizard-custom.js with sprockets directives targetting individual files.

In some cases, we require a lot of files from the same folder and were tempted to use require_tree for a long time but unfortunately, that isn’t possible due to the following reasons.

  • The wizard-custom.js file is located inside the plugin, so its load path is different from discourse and we can only require files inside the load path.
  • Sprockets doesn’t allow absolute paths when using require_tree.

Solving this would also mean that the plugin breaks less often, due to changes in discourse core.

To mitigate this, we created a custom sprockets directive called require_tree_discourse which specifically looks up for assets inside the discourse folder using absolute paths. Here’s the PR containing that code.

Thought it would be interesting for discourse devs and rails devs in general out there.
https://github.com/paviliondev/discourse-custom-wizard/pull/86

Unfortunately, we had to revert this change, as its not working in production.

It seems like the plugins are loaded a bit later on as compared to when the js files are read.

It does work. We’ll re-introduce the change soon.

We’ve introduced this in our code finally.
https://github.com/paviliondev/discourse-custom-wizard/pull/114

Keep in mind, I estimate that within 12 months we will have abandoned sprockets for ember-cli based builds. @eviltrout has already started work investigating the move.

Thanks for the early heads up. Any pointers in that direction will be of great help. cc @angus