A platform for community discussion. Free, open, simple.
Revert "DEV: Remove the old non-rollup plugin compiler (#39009)" (#39047)
Jarek Radosz7633f0d0ac97
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.ymlindex b333179826f..d9900f553bf 100644--- a/.github/workflows/tests.yml+++ b/.github/workflows/tests.yml@@ -62,6 +62,7 @@ jobs:LOAD_PLUGINS: ${{ (matrix.target == 'core-plugins' || matrix.target == 'official-plugins' || matrix.target == 'plugins' || matrix.target == 'chat') && '1' || '0' }}ACTIONS_STEP_DEBUG: ${{ secrets.ACTIONS_STEP_DEBUG }}QUNIT_REUSE_BUILD: 1+ ROLLUP_PLUGIN_COMPILER: ${{ matrix.plugin_compiler == 'rollup' && '1' || '0' }}strategy:fail-fast: falsediff --git a/app/models/theme.rb b/app/models/theme.rbindex bf26083820f..778a876f1f4 100644--- a/app/models/theme.rb+++ b/app/models/theme.rb@@ -250,6 +250,7 @@ class Theme < ActiveRecord::BaseGlobalSetting.s3_endpoint,GlobalSetting.s3_bucket,Discourse.current_hostname,+ ENV["ROLLUP_PLUGIN_COMPILER"],]Digest::SHA1.hexdigest(dependencies.join)enddiff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erbindex d915c5cfba1..78559d5d539 100644--- a/app/views/layouts/application.html.erb+++ b/app/views/layouts/application.html.erb@@ -26,7 +26,7 @@include_unofficial: allow_third_party_plugins?,request: request,include_admin_asset: staff?- })+ }) if ENV["ROLLUP_PLUGIN_COMPILER"] != "0"%><%= build_plugin_html 'server:before-script-load' %>@@ -56,6 +56,14 @@<%= preload_script "vendor" %><%= preload_script "discourse" %>+ <%= render("layouts/plugin_js", opts: {+ include_official: allow_plugins?,+ include_unofficial: allow_third_party_plugins?,+ request: request,+ include_admin_asset: staff?+ }) if ENV["ROLLUP_PLUGIN_COMPILER"] == "0"+ %>+<%- if staff? %><% EmberCli.script_chunks["chunk.admin"]&.each do |script_name| %><link rel="preload" href="<%= script_asset_path(script_name) %>" as="script" nonce="<%= csp_nonce_placeholder %>" data-discourse-entrypoint="admin">diff --git a/config/pitchfork.conf.rb b/config/pitchfork.conf.rbindex 012cf1a936d..c8a5bc48ab4 100644--- a/config/pitchfork.conf.rb+++ b/config/pitchfork.conf.rb@@ -123,7 +123,9 @@ before_service_worker_ready do |server, service_worker|demon_class.start(1, logger: server.logger)end- Demon::PluginJsWatcher.start(verbose: true) if Rails.env.development?+ if Rails.env.development? && ENV["ROLLUP_PLUGIN_COMPILER"] != "0"+ Demon::PluginJsWatcher.start(verbose: true)+ endThread.new dowhile truediff --git a/frontend/asset-processor/babel-replace-imports.js b/frontend/asset-processor/babel-replace-imports.jsindex 7536a6fc205..b64ecd52c4a 100644--- a/frontend/asset-processor/babel-replace-imports.js+++ b/frontend/asset-processor/babel-replace-imports.js@@ -16,7 +16,10 @@ export default function (babel) {return;}- if (moduleName.startsWith("discourse/plugins/")) {+ if (+ globalThis.ROLLUP_PLUGIN_COMPILER !== "0" &&+ moduleName.startsWith("discourse/plugins/")+ ) {const parts = moduleName.split("/");path.node.source = t.stringLiteral(`discourse/plugins/${parts[2]}`);diff --git a/frontend/asset-processor/package.json b/frontend/asset-processor/package.jsonindex f2a9e258ff5..b5fdfa34626 100644--- a/frontend/asset-processor/package.json+++ b/frontend/asset-processor/package.json@@ -23,6 +23,7 @@"core-js": "^3.49.0","decorator-transforms": "^2.3.1","discourse": "workspace:0.0.0",+ "discourse-plugins": "workspace:1.0.0","ember-cli-htmlbars": "^7.0.0","ember-source": "~6.10.0","ember-this-fallback": "^0.4.0",diff --git a/frontend/asset-processor/theme-rollup.js b/frontend/asset-processor/theme-rollup.jsindex a4720ccb967..335cdcd00e8 100644--- a/frontend/asset-processor/theme-rollup.js+++ b/frontend/asset-processor/theme-rollup.js@@ -7,6 +7,7 @@ import colocatedBabelPlugin from "ember-cli-htmlbars/lib/colocated-babel-plugin"import { precompile } from "ember-source/ember-template-compiler/index.js";import EmberThisFallback from "ember-this-fallback";import { memfs } from "memfs";+import transformActionSyntax from "discourse-plugins/transform-action-syntax";import { browsers } from "../discourse/config/targets";import babelTransformModuleRenames from "../discourse/lib/babel-transform-module-renames";import AddThemeGlobals from "./add-theme-globals";@@ -19,7 +20,6 @@ import discourseHbs from "./rollup-plugins/discourse-hbs";import discourseTerser from "./rollup-plugins/discourse-terser";import discourseVirtualLoader from "./rollup-plugins/discourse-virtual-loader";import buildEmberTemplateManipulatorPlugin from "./theme-hbs-ast-transforms";-import transformActionSyntax from "./transform-action-syntax";let lastRollupResult;let lastRollupError;diff --git a/frontend/deprecation-silencer/index.js b/frontend/deprecation-silencer/index.jsindex eccfe2102f1..9522a7462d0 100644--- a/frontend/deprecation-silencer/index.js+++ b/frontend/deprecation-silencer/index.js@@ -3,6 +3,7 @@ const SILENCED_WARN_PREFIXES = ['unexpectedly found "', // https://github.com/emberjs/ember.js/issues/19392"The setting 'staticAddonTestSupportTrees'","The setting 'staticAddonTrees'",+ "\n\n--------\n+ Your app is using the legacy ember-template-compiler.js AMD bundle", // Remove when ROLLUP_PLUGIN_COMPILER is promoted];class DeprecationSilencer {diff --git a/frontend/discourse-plugins/colocated-template-compiler.js b/frontend/discourse-plugins/colocated-template-compiler.jsnew file mode 100644index 00000000000..04611e3697d--- /dev/null+++ b/frontend/discourse-plugins/colocated-template-compiler.js@@ -0,0 +1,14 @@+const ColocatedTemplateProcessor = require("ember-cli-htmlbars/lib/colocated-broccoli-plugin");++module.exports = class DiscoursePluginColocatedTemplateProcessor extends (+ ColocatedTemplateProcessor+) {+ constructor(tree, rootName) {+ super(tree);+ this.rootName = rootName;+ }++ detectRootName() {+ return this.rootName;+ }+};diff --git a/frontend/discourse-plugins/index.js b/frontend/discourse-plugins/index.jsnew file mode 100644index 00000000000..20ae85d1015--- /dev/null+++ b/frontend/discourse-plugins/index.js@@ -0,0 +1,276 @@+"use strict";++const path = require("path");+const WatchedDir = require("broccoli-source").WatchedDir;+const Funnel = require("broccoli-funnel");+const mergeTrees = require("broccoli-merge-trees");+const fs = require("fs");+const concat = require("broccoli-concat");+const DiscoursePluginColocatedTemplateProcessor = require("./colocated-template-compiler");+const EmberApp = require("ember-cli/lib/broccoli/ember-app");+const transformActionSyntax = require("./transform-action-syntax");++function fixLegacyExtensions(tree) {+ return new Funnel(tree, {+ getDestinationPath: function (relativePath) {+ if (relativePath.endsWith(".es6")) {+ return relativePath.slice(0, -4);+ }++ return relativePath;+ },+ });+}++const COLOCATED_CONNECTOR_REGEX =+ /^(?<prefix>.*)\/connectors\/(?<outlet>[^\/]+)\/(?<name>[^\/\.]+)\.(?<extension>.+)$/;++// Having connector templates and js in the same directory causes a clash+// when outputting es6 modules. This shim separates colocated connectors+// into separate js / template locations.+function unColocateConnectors(tree) {+ return new Funnel(tree, {+ getDestinationPath: function (relativePath) {+ const match = relativePath.match(COLOCATED_CONNECTOR_REGEX);+ if (+ match &&+ match.groups.extension === "hbs" &&+ match.groups.prefix.split("/").pop() !== "templates"+ ) {+ const { prefix, outlet, name } = match.groups;+ return `${prefix}/templates/connectors/${outlet}/${name}.hbs`;+ }+ if (+ match &&+ match.groups.extension === "js" &&+ match.groups.prefix.split("/").pop() === "templates"+ ) {+ // Some plugins are colocating connector JS under `/templates`+ const { prefix, outlet, name } = match.groups;+ const newPrefix = prefix.slice(0, -"/templates".length);+ return `${newPrefix}/connectors/${outlet}/${name}.js`;+ }+ return relativePath;+ },+ });+}++function namespaceModules(tree, pluginName) {+ return new Funnel(tree, {+ getDestinationPath: function (relativePath) {+ return `discourse/plugins/${pluginName}/${relativePath}`;+ },+ });+}++function parsePluginName(pluginRbPath) {+ const pluginRb = fs.readFileSync(pluginRbPath, "utf8");+ // Match parsing logic in `lib/plugin/metadata.rb`+ for (const line of pluginRb.split("\n")) {+ if (line.startsWith("#")) {+ const [attribute, value] = line.slice(1).split(":", 2);+ if (attribute.trim() === "name") {+ return value.trim();+ }+ }+ }+ throw new Error(+ `Unable to parse plugin name from metadata in ${pluginRbPath}`+ );+}++module.exports = {+ name: require("./package").name,++ options: {+ ...require("../discourse/lib/common-babel-config")(),++ "ember-this-fallback": {+ enableLogging: false,+ },+ },++ setupPreprocessorRegistry(type, registry) {+ if (type === "self") {+ const plugin = this._buildActionPlugin();+ plugin.parallelBabel = {+ requireFile: __filename,+ buildUsing: "_buildActionPlugin",+ params: {},+ };++ registry.add("htmlbars-ast-plugin", plugin);+ }+ },++ _buildActionPlugin() {+ return {+ name: "transform-action-syntax",+ plugin: transformActionSyntax,+ baseDir: transformActionSyntax.baseDir,+ cacheKey: transformActionSyntax.cacheKey,+ };+ },++ pluginInfos() {+ const root = path.resolve("../../plugins");+ const pluginDirectories = fs+ .readdirSync(root, { withFileTypes: true })+ .filter(+ (dirent) =>+ (dirent.isDirectory() || dirent.isSymbolicLink()) &&+ !dirent.name.startsWith(".") &&+ fs.existsSync(path.resolve(root, dirent.name, "plugin.rb"))+ );++ return pluginDirectories.map((directory) => {+ const directoryName = directory.name;+ const pluginName = parsePluginName(+ path.resolve(root, directoryName, "plugin.rb")+ );+ const jsDirectory = path.resolve(+ root,+ directoryName,+ "assets/javascripts"+ );+ const adminJsDirectory = path.resolve(+ root,+ directoryName,+ "admin/assets/javascripts"+ );+ const testDirectory = path.resolve(+ root,+ directoryName,+ "test/javascripts"+ );+ const configDirectory = path.resolve(root, directoryName, "config");+ const hasJs = fs.existsSync(jsDirectory);+ const hasAdminJs = fs.existsSync(adminJsDirectory);+ const hasTests = fs.existsSync(testDirectory);+ const hasConfig = fs.existsSync(configDirectory);++ return {+ pluginName,+ directoryName,+ jsDirectory,+ adminJsDirectory,+ testDirectory,+ configDirectory,+ hasJs,+ hasAdminJs,+ hasTests,+ hasConfig,+ };+ });+ },++ generatePluginsTree(withTests) {+ if (!this.shouldLoadPlugins()) {+ return mergeTrees([]);+ }+ const trees = [+ this._generatePluginAppTree(),+ this._generatePluginAdminTree(),+ ];+ if (withTests) {+ trees.push(this._generatePluginTestTree());+ }+ return mergeTrees(trees);+ },++ _generatePluginAppTree() {+ const trees = this.pluginInfos()+ .filter((p) => p.hasJs)+ .map(({ pluginName, directoryName, jsDirectory }) =>+ this._buildAppTree({+ directory: jsDirectory,+ pluginName,+ outputFile: `assets/plugins/${directoryName}.js`,+ })+ );+ return mergeTrees(trees);+ },++ _generatePluginAdminTree() {+ const trees = this.pluginInfos()+ .filter((p) => p.hasAdminJs)+ .map(({ pluginName, directoryName, adminJsDirectory }) =>+ this._buildAppTree({+ directory: adminJsDirectory,+ pluginName,+ outputFile: `assets/plugins/${directoryName}_admin.js`,+ })+ );+ return mergeTrees(trees);+ },++ _buildAppTree({ directory, pluginName, outputFile }) {+ let tree = new WatchedDir(directory);++ tree = fixLegacyExtensions(tree);+ tree = unColocateConnectors(tree);+ tree = namespaceModules(tree, pluginName);++ const colocateBase = `discourse/plugins/${pluginName}`;+ tree = new DiscoursePluginColocatedTemplateProcessor(+ tree,+ `${colocateBase}/discourse`+ );+ tree = new DiscoursePluginColocatedTemplateProcessor(+ tree,+ `${colocateBase}/admin`+ );+ tree = this.compileTemplates(tree);++ tree = this.processedAddonJsFiles(tree);++ return concat(mergeTrees([tree]), {+ inputFiles: ["**/*.js"],+ outputFile,+ allowNone: true,+ });+ },++ _generatePluginTestTree() {+ const trees = this.pluginInfos()+ .filter((p) => p.hasTests)+ .map(({ pluginName, directoryName, testDirectory }) => {+ let tree = new WatchedDir(testDirectory);++ tree = fixLegacyExtensions(tree);+ tree = namespaceModules(tree, pluginName);+ tree = this.processedAddonJsFiles(tree);++ return concat(mergeTrees([tree]), {+ inputFiles: ["**/*.js"],+ outputFile: `assets/plugins/test/${directoryName}_tests.js`,+ allowNone: true,+ });+ });+ return mergeTrees(trees);+ },++ shouldCompileTemplates() {+ // The base Addon implementation checks for template+ // files in the addon directories. We need to override that+ // check so that the template compiler always runs.+ return true;+ },++ // Matches logic from GlobalSetting.load_plugins? in the ruby app+ shouldLoadPlugins() {+ if (process.env.ROLLUP_PLUGIN_COMPILER !== "0") {+ return false;+ }++ if (process.env.LOAD_PLUGINS === "1") {+ return true;+ } else if (process.env.LOAD_PLUGINS === "0") {+ return false;+ } else if (EmberApp.env() === "test") {+ return false;+ } else {+ return true;+ }+ },+};diff --git a/frontend/discourse-plugins/package.json b/frontend/discourse-plugins/package.jsonnew file mode 100644index 00000000000..1ca0887f9fc--- /dev/null+++ b/frontend/discourse-plugins/package.json@@ -0,0 +1,31 @@+{+ "name": "discourse-plugins",+ "version": "1.0.0",+ "description": "An addon providing a broccoli tree for each Discourse plugin",+ "author": "Discourse",+ "license": "GPL-2.0-only",+ "keywords": [+ "ember-addon"+ ],+ "dependencies": {+ "@babel/core": "^7.28.5",+ "deprecation-silencer": "workspace:1.0.0",+ "ember-cli-babel": "^8.2.0",+ "ember-cli-htmlbars": "^7.0.0",+ "ember-template-imports": "^4.4.0",+ "ember-this-fallback": "^0.4.0"+ },+ "devDependencies": {+ "ember-cli": "~6.11.0",+ "webpack": "5.99.9"+ },+ "engines": {+ "node": ">= 20",+ "npm": "please-use-pnpm",+ "yarn": "please-use-pnpm",+ "pnpm": "^10"+ },+ "ember": {+ "edition": "default"+ }+}diff --git a/frontend/asset-processor/transform-action-syntax.js b/frontend/discourse-plugins/transform-action-syntax.jssimilarity index 100%rename from frontend/asset-processor/transform-action-syntax.jsrename to frontend/discourse-plugins/transform-action-syntax.jsdiff --git a/frontend/discourse/app/lib/source-identifier.js b/frontend/discourse/app/lib/source-identifier.jsindex 5faa1749ea6..3d131454242 100644--- a/frontend/discourse/app/lib/source-identifier.js+++ b/frontend/discourse/app/lib/source-identifier.js@@ -1,3 +1,4 @@+import { DEBUG } from "@glimmer/env";import getURL from "discourse/lib/get-url";import PreloadStore from "discourse/lib/preload-store";@@ -47,7 +48,36 @@ export default function identifySource(error) {}}- const plugin = stack.match(/assets\/(?:js|br|gz)\/plugins\/([\w-]+)_/)?.[1];+ let plugin;++ // Build patterns array dynamically to match plugin files in both development and production+ // Order matters: check more specific patterns (_admin) before general ones+ const patterns = [];++ // legacy+ if (DEBUG) {+ patterns.push(+ /assets\/plugins\/([\w-]+)_admin\.js/, // Admin UI Development (no fingerprinting)+ /assets\/plugins\/([\w-]+)\.js/, // Development (no fingerprinting)+ /assets\/plugins\/test\/([\w-]+)_tests\.js/ // Test files+ );+ }++ // legacy+ patterns.push(+ /assets\/plugins\/_?([\w-]+)-[0-9a-f]+_admin(?:\.(?:br|gz))?\.js/, // Admin UI Production (with fingerprints)+ /assets\/plugins\/_?([\w-]+)-[0-9a-f]+(?:\.(?:br|gz))?\.js/ // Production (with fingerprints)+ );++ // new paths (ROLLUP_PLUGIN_COMPILER)+ patterns.push(/assets\/(?:js|br|gz)\/plugins\/([\w-]+)_/);++ for (const pattern of patterns) {+ plugin = stack.match(pattern)?.[1];+ if (plugin) {+ break;+ }+ }if (plugin) {return {diff --git a/frontend/discourse/ember-cli-build.js b/frontend/discourse/ember-cli-build.jsindex d486eb75c5f..fcfc28e2664 100644--- a/frontend/discourse/ember-cli-build.js+++ b/frontend/discourse/ember-cli-build.js@@ -124,14 +124,25 @@ module.exports = function (defaults) {discourseRoot + "/frontend/discourse/public/assets/scripts/module-shims.js");+ const discoursePluginsTree = app.project+ .findAddonByName("discourse-plugins")+ .generatePluginsTree(app.tests);+app.project.liveReloadFilterPatterns = [/.*\.scss/];const terserPlugin = app.project.findAddonByName("ember-cli-terser");const applyTerser = (tree) => terserPlugin.postprocessTree("all", tree);+ const pluginTrees = applyTerser(discoursePluginsTree);++ if (process.env.SKIP_CORE_BUILD) {+ return pluginTrees;+ }+let extraPublicTrees = [funnel(`${discourseRoot}/public/javascripts`, { destDir: "javascripts" }),applyTerser(generateScriptsTree(app)),+ pluginTrees,];const assetCachebuster = process.env["DISCOURSE_ASSET_URL_SALT"] || "";diff --git a/frontend/discourse/package.json b/frontend/discourse/package.jsonindex 7f2582dbfdc..a66cc178dbf 100644--- a/frontend/discourse/package.json+++ b/frontend/discourse/package.json@@ -116,6 +116,7 @@"deprecation-silencer": "workspace:1.0.0","discourse-i18n": "workspace:1.0.0","discourse-markdown-it": "workspace:1.0.0",+ "discourse-plugins": "workspace:1.0.0","ember-async-data": "^2.0.1","ember-auto-import": "^2.13.0","ember-buffered-proxy": "^2.1.1",diff --git a/frontend/discourse/tests/acceptance/client-error-handler-test.js b/frontend/discourse/tests/acceptance/client-error-handler-test.jsindex c16cca8302b..256e77bf196 100644--- a/frontend/discourse/tests/acceptance/client-error-handler-test.js+++ b/frontend/discourse/tests/acceptance/client-error-handler-test.js@@ -11,7 +11,7 @@ acceptance("client-error-handler service", function (needs) {test("displays route-loading errors caused by themes", async function (assert) {const fakeError = new Error("Something bad happened");- fakeError.stack = "assets/js/plugins/fake-plugin_main-faw0x1gl.digested.js";+ fakeError.stack = "assets/plugins/some-fake-plugin-name.js";const topicRoute = getOwner(this).lookup("route:topic");Sinon.stub(topicRoute, "model").throws(fakeError);@@ -23,6 +23,8 @@ acceptance("client-error-handler service", function (needs) {consoleStub.restore();assert.dom(".broken-theme-alert-banner").exists();- assert.dom(".broken-theme-alert-banner").containsText("fake-plugin");+ assert+ .dom(".broken-theme-alert-banner")+ .containsText("some-fake-plugin-name");});});diff --git a/frontend/discourse/tests/setup-tests.js b/frontend/discourse/tests/setup-tests.jsindex b848cf86b0b..7bc2acb0ec2 100644--- a/frontend/discourse/tests/setup-tests.js+++ b/frontend/discourse/tests/setup-tests.js@@ -396,8 +396,14 @@ export default function setupTests(config) {// core tests run without loading plugins or themesconst isCoreTest = !hasPluginJs && !hasThemeJs;- const isPreinstalledPluginTest = !!document.querySelector(- `link[rel=modulepreload][data-plugin-name="${CSS.escape(target)}"][data-preinstalled="true"]`+ const isPreinstalledPluginTest = !!(+ document.querySelector(+ // TODO (ROLLUP_PLUGIN_COMPILER): drop this legacy script tag check+ `script[data-plugin-name="${CSS.escape(target)}"][data-preinstalled="true"]`+ ) ||+ document.querySelector(+ `link[rel=modulepreload][data-plugin-name="${CSS.escape(target)}"][data-preinstalled="true"]`+ ));if (diff --git a/lib/asset_processor.rb b/lib/asset_processor.rbindex ed354fe2e98..c1495be8d8c 100644--- a/lib/asset_processor.rb+++ b/lib/asset_processor.rb@@ -1,7 +1,7 @@# frozen_string_literal: trueclass AssetProcessor- BASE_COMPILER_VERSION = 108+ BASE_COMPILER_VERSION = 107PROCESSOR_DIR = "tmp/asset-processor"LOCK_FILE = "#{PROCESSOR_DIR}/build.lock"@@ -11,6 +11,7 @@ class AssetProcessorfrontend/asset-processor/**/*.jsfrontend/discourse/lib/babel-transform-module-renames.jsfrontend/discourse/config/targets.js+ frontend/discourse-plugins/transform-action-syntax.js]@mutex = Mutex.new@@ -152,6 +153,7 @@ class AssetProcessorsource = load_or_build_processor_source+ ctx.eval("globalThis.ROLLUP_PLUGIN_COMPILER = #{ENV["ROLLUP_PLUGIN_COMPILER"].to_json}")ctx.eval(source, filename: "asset-processor.js")ctx.low_memory_notification # GC to free up memory used during initdiff --git a/lib/discourse.rb b/lib/discourse.rbindex d7deb9b5120..7950d36f848 100644--- a/lib/discourse.rb+++ b/lib/discourse.rb@@ -465,14 +465,19 @@ module Discourseplugins.each do |plugin|if plugin.js_asset_exists?- if logical_path = Plugin::JsManager.digested_logical_path_for(plugin.directory_name, "main")- assets << {- name: logical_path,- imports: Plugin::JsManager.import_paths_for(plugin.directory_name, "main"),- plugin: plugin,- type_module: true,- importmap_name: "discourse/plugins/#{plugin.name}",- }+ if ENV["ROLLUP_PLUGIN_COMPILER"] != "0"+ if logical_path =+ Plugin::JsManager.digested_logical_path_for(plugin.directory_name, "main")+ assets << {+ name: logical_path,+ imports: Plugin::JsManager.import_paths_for(plugin.directory_name, "main"),+ plugin: plugin,+ type_module: true,+ importmap_name: "discourse/plugins/#{plugin.name}",+ }+ end+ else+ assets << { name: "plugins/#{plugin.directory_name}", plugin: plugin }endend@@ -485,26 +490,35 @@ module Discourseendif args[:include_admin_asset] && plugin.admin_js_asset_exists?- if logical_path =- Plugin::JsManager.digested_logical_path_for(plugin.directory_name, "admin")- assets << {- name: logical_path,- imports: Plugin::JsManager.import_paths_for(plugin.directory_name, "admin"),- plugin: plugin,- type_module: true,- }+ if ENV["ROLLUP_PLUGIN_COMPILER"] != "0"+ if logical_path =+ Plugin::JsManager.digested_logical_path_for(plugin.directory_name, "admin")+ assets << {+ name: logical_path,+ imports: Plugin::JsManager.import_paths_for(plugin.directory_name, "admin"),+ plugin: plugin,+ type_module: true,+ }+ end+ else+ assets << { name: "plugins/#{plugin.directory_name}_admin", plugin: plugin }endendif args[:include_test_assets_for]&.include?(plugin.directory_name) &&plugin.test_js_asset_exists?- if logical_path = Plugin::JsManager.digested_logical_path_for(plugin.directory_name, "test")- assets << {- name: logical_path,- imports: Plugin::JsManager.import_paths_for(plugin.directory_name, "test"),- plugin: plugin,- type_module: true,- }+ if ENV["ROLLUP_PLUGIN_COMPILER"] != "0"+ if logical_path =+ Plugin::JsManager.digested_logical_path_for(plugin.directory_name, "test")+ assets << {+ name: logical_path,+ imports: Plugin::JsManager.import_paths_for(plugin.directory_name, "test"),+ plugin: plugin,+ type_module: true,+ }+ end+ else+ assets << { name: "plugins/test/#{plugin.directory_name}_tests", plugin: plugin }endendenddiff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rakeindex 67bec8c3e5d..e97765b81c2 100644--- a/lib/tasks/assets.rake+++ b/lib/tasks/assets.rake@@ -24,7 +24,11 @@ task "assets:precompile:build" doendtask "assets:precompile:build_plugins": "environment" do- Plugin::JsManager.new.compile!+ if ENV["ROLLUP_PLUGIN_COMPILER"] != "0"+ Plugin::JsManager.new.compile!+ else+ puts "Skipping plugin JS compilation, set ROLLUP_PLUGIN_COMPILER=1 to enable"+ endendtask "assets:precompile:before": %w[environment assets:precompile:build]diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex ae1b119e8e9..9fb452cc584 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -160,6 +160,9 @@ importers:discourse:specifier: workspace:0.0.0version: link:../discourse+ discourse-plugins:+ specifier: workspace:1.0.0+ version: link:../discourse-pluginsember-cli-htmlbars:specifier: ^7.0.0version: 7.0.0(@babel/[email protected])([email protected](patch_hash=85ff9a16d08431e3bdc9aea8d55280e14f437f1c2a7d8e461de56c614ad48926)(@glimmer/[email protected])([email protected]))@@ -503,6 +506,9 @@ importers:discourse-markdown-it:specifier: workspace:1.0.0version: link:../discourse-markdown-it+ discourse-plugins:+ specifier: workspace:1.0.0+ version: link:../discourse-pluginsember-async-data:specifier: ^2.0.1version: 2.0.1(@babel/[email protected])(@glint/[email protected])@@ -657,6 +663,34 @@ importers:specifier: ^1.0.15version: 1.0.15+ frontend/discourse-plugins:+ dependencies:+ '@babel/core':+ specifier: ^7.28.5+ version: 7.29.0([email protected])+ deprecation-silencer:+ specifier: workspace:1.0.0+ version: link:../deprecation-silencer+ ember-cli-babel:+ specifier: ^8.2.0+ version: 8.3.1(@babel/[email protected])+ ember-cli-htmlbars:+ specifier: ^7.0.0+ version: 7.0.0(@babel/[email protected])([email protected](patch_hash=85ff9a16d08431e3bdc9aea8d55280e14f437f1c2a7d8e461de56c614ad48926)(@glimmer/[email protected])([email protected]))+ ember-template-imports:+ specifier: ^4.4.0+ version: 4.4.0+ ember-this-fallback:+ specifier: ^0.4.0+ version: 0.4.0(patch_hash=31c150a292037db2b05d9030a75069bb0a9518a4a7e0969b9b4e14d957134e45)([email protected](@babel/[email protected])([email protected](patch_hash=85ff9a16d08431e3bdc9aea8d55280e14f437f1c2a7d8e461de56c614ad48926)(@glimmer/[email protected])([email protected])))([email protected](patch_hash=85ff9a16d08431e3bdc9aea8d55280e14f437f1c2a7d8e461de56c614ad48926)(@glimmer/[email protected])([email protected]))+ devDependencies:+ ember-cli:+ specifier: ~6.11.0+ version: 6.11.0(@types/[email protected])([email protected])([email protected])([email protected])+ webpack:+ specifier: 5.99.9+ version: 5.99.9(@swc/[email protected])([email protected])+frontend/discourse-types:devDependencies:'@types/node':diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yamlindex 6073d7bed43..5260eceac94 100644--- a/pnpm-workspace.yaml+++ b/pnpm-workspace.yaml@@ -6,6 +6,7 @@ packages:- "frontend/discourse"- "frontend/discourse-i18n"- "frontend/discourse-markdown-it"+- "frontend/discourse-plugins"- "frontend/ember-cli-progress-ci"- "frontend/pretty-text"- "frontend/asset-processor"diff --git a/script/assemble_ember_build.rb b/script/assemble_ember_build.rbindex d6cc1a3f75c..a7c1b4c1dca 100755--- a/script/assemble_ember_build.rb+++ b/script/assemble_ember_build.rb@@ -156,16 +156,41 @@ build_cmd << "-prod" if resolved_ember_env == "production"core_build_reusable =existing_core_build_usable? || (download_prebuild_assets! && existing_core_build_usable?)-if core_build_reusable- log "Reusing existing core ember build. All done."+if ENV["ROLLUP_PLUGIN_COMPILER"] != "0"+ if core_build_reusable+ log "Reusing existing core ember build. All done."+ else+ log "Running full core build..."+ system(build_env, *build_cmd, exception: true, chdir: EMBER_APP_DIR)+ File.write(BUILD_INFO_FILE, JSON.pretty_generate(build_info))+ end+ system("bin/rake", "assets:precompile:build_plugins", exception: true)else- log "Running full core build..."- system(build_env, *build_cmd, exception: true, chdir: EMBER_APP_DIR)- File.write(BUILD_INFO_FILE, JSON.pretty_generate(build_info))+ if core_build_reusable && ENV["LOAD_PLUGINS"] == "0"+ log "Reusing existing core ember build. Plugins not loaded. All done."+ elsif core_build_reusable+ log "Reusing existing core ember build. Only building plugins..."+ build_env["SKIP_CORE_BUILD"] = "1"+ build_cmd << "-o" << "dist/_plugin_only_build"+ begin+ system(build_env, *build_cmd, exception: true, chdir: EMBER_APP_DIR)+ FileUtils.rm_rf("#{EMBER_APP_DIR}/dist/assets/plugins")+ FileUtils.mv(+ "#{EMBER_APP_DIR}/dist/_plugin_only_build/assets/plugins",+ "#{EMBER_APP_DIR}/dist/assets/plugins",+ )+ ensure+ FileUtils.rm_rf("#{EMBER_APP_DIR}/dist/_plugin_only_build")+ end++ log "Plugin build successfully integrated into dist"+ else+ log "Running full core build..."+ system(build_env, *build_cmd, exception: true, chdir: EMBER_APP_DIR)+ File.write(BUILD_INFO_FILE, JSON.pretty_generate(build_info))+ endend-system("bin/rake", "assets:precompile:build_plugins", exception: true)-if ARGV.include?("--compress")files = [*Dir.glob("#{EMBER_APP_DIR}/dist/**/*.js"), *Dir.glob("app/assets/generated/**/*.js")]Parallel.map(files, in_threads: 4) do |file|diff --git a/script/publish_built_assets.rb b/script/publish_built_assets.rbindex e7709311374..b940a7fb421 100755--- a/script/publish_built_assets.rb+++ b/script/publish_built_assets.rb@@ -24,6 +24,7 @@ endCOMMON_ENV = {"DISCOURSE_DOWNLOAD_PRE_BUILT_ASSETS" => "0","LOAD_PLUGINS" => "1",+ "ROLLUP_PLUGIN_COMPILER" => "1","SKIP_DB_AND_REDIS" => "1",}