diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d1546e55ed9..a2b71132e43 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -18,7 +18,7 @@ permissions: jobs: build: if: github.event_name == 'pull_request' || github.repository != 'discourse/discourse-private-mirror' - name: ${{ matrix.target }} ${{ matrix.build_type }} ${{ matrix.ruby }} + name: ${{ matrix.target }} ${{ matrix.build_type }} ${{ matrix.ruby }}${{(matrix.embroider == '1') && ' (Embroider)' || ''}} runs-on: ${{ (matrix.build_type == 'annotations') && 'ubuntu-latest' || 'ubuntu-20.04-8core' }} container: discourse/discourse_test:slim${{ (matrix.build_type == 'frontend' || matrix.build_type == 'system') && '-browsers' || '' }}${{ (matrix.ruby == '3.1') && '-ruby-3.1.0' || '' }} timeout-minutes: 20 @@ -28,6 +28,7 @@ jobs: RAILS_ENV: test PGUSER: discourse PGPASSWORD: discourse + USE_EMBROIDER: ${{ matrix.embroider }} USES_PARALLEL_DATABASES: ${{ matrix.build_type == 'backend' || matrix.build_type == 'system' }} CAPYBARA_DEFAULT_MAX_WAIT_TIME: 10 MINIO_RUNNER_LOG_LEVEL: DEBUG @@ -37,13 +38,18 @@ jobs: matrix: build_type: [backend, frontend, system, annotations] + embroider: ["0", "1"] target: [core, plugins] ruby: ["3.2"] exclude: + - build_type: annotations + embroider: "1" - build_type: annotations target: plugins - build_type: frontend target: core # Handled by core_frontend_tests job (below) + - build_type: backend + embroider: "1" steps: - name: Set working directory owner @@ -245,7 +251,7 @@ jobs: core_frontend_tests: if: github.event_name == 'pull_request' || github.repository != 'discourse/discourse-private-mirror' - name: core frontend (${{ matrix.browser }}) + name: core frontend (${{ matrix.browser }})${{(matrix.embroider == '1') && ' (Embroider)' || ''}} runs-on: ubuntu-20.04-8core container: image: discourse/discourse_test:slim-browsers @@ -256,9 +262,17 @@ jobs: strategy: fail-fast: false matrix: + embroider: ["1", "0"] browser: ["Chrome", "Firefox ESR", "Firefox Evergreen"] + exclude: + # Testing Embroider on one browser is good enough for now + - embroider: "1" + browser: Firefox ESR + - embroider: "1" + browser: Firefox Evergreen env: + USE_EMBROIDER: ${{ matrix.embroider }} TESTEM_BROWSER: ${{ (startsWith(matrix.browser, 'Firefox') && 'Firefox') || matrix.browser }} TESTEM_FIREFOX_PATH: ${{ (matrix.browser == 'Firefox Evergreen') && '/opt/firefox-evergreen/firefox' }} diff --git a/app/assets/javascripts/discourse/app/instance-initializers/auth-complete.js b/app/assets/javascripts/discourse/app/instance-initializers/auth-complete.js index 9b2ab1e6410..587e83b316a 100644 --- a/app/assets/javascripts/discourse/app/instance-initializers/auth-complete.js +++ b/app/assets/javascripts/discourse/app/instance-initializers/auth-complete.js @@ -1,6 +1,6 @@ import { next } from "@ember/runloop"; import cookie, { removeCookie } from "discourse/lib/cookie"; -import { getURL } from "discourse/lib/url"; +import DiscourseUrl from "discourse/lib/url"; import EmberObject from "@ember/object"; import showModal from "discourse/lib/show-modal"; import I18n from "I18n"; @@ -106,8 +106,10 @@ export default { // redirect client to the original URL removeCookie("destination_url"); window.location.href = destinationUrl; - } else if (window.location.pathname === getURL("/login")) { - window.location = getURL("/"); + } else if ( + window.location.pathname === DiscourseUrl.getURL("/login") + ) { + window.location = DiscourseUrl.getURL("/"); } else { window.location.reload(); } diff --git a/app/assets/javascripts/discourse/ember-cli-build.js b/app/assets/javascripts/discourse/ember-cli-build.js index 3a21935e0c3..4b4a2f198a5 100644 --- a/app/assets/javascripts/discourse/ember-cli-build.js +++ b/app/assets/javascripts/discourse/ember-cli-build.js @@ -22,9 +22,29 @@ module.exports = function (defaults) { DeprecationSilencer.silence(console, "warn"); DeprecationSilencer.silence(defaults.project.ui, "writeWarnLine"); + const isEmbroider = process.env.USE_EMBROIDER === "1"; const isProduction = EmberApp.env().includes("production"); const isTest = EmberApp.env().includes("test"); + // This is more or less the same as the one in @embroider/test-setup + const maybeEmbroider = (app, options) => { + if (isEmbroider) { + const { compatBuild } = require("@embroider/compat"); + const { Webpack } = require("@embroider/webpack"); + + // https://github.com/embroider-build/embroider/issues/1581 + if (Array.isArray(options?.extraPublicTrees)) { + options.extraPublicTrees = [ + app.addonPostprocessTree("all", mergeTrees(options.extraPublicTrees)), + ]; + } + + return compatBuild(app, Webpack, options); + } else { + return app.toTree(options?.extraPublicTrees); + } + }; + const app = new EmberApp(defaults, { autoRun: false, "ember-qunit": { @@ -137,18 +157,20 @@ module.exports = function (defaults) { .findAddonByName("pretty-text") .treeForMarkdownItBundle(); - let testemStylesheetTree; + const extraPublicTrees = []; + if (isTest) { - testemStylesheetTree = mergeTrees([ + const testemStylesheetTree = mergeTrees([ discourseScss(`${discourseRoot}/app/assets/stylesheets`, "qunit.scss"), discourseScss( `${discourseRoot}/app/assets/stylesheets`, "qunit-custom.scss" ), ]); + extraPublicTrees.push(testemStylesheetTree); } - return app.toTree([ + extraPublicTrees.push( createI18nTree(discourseRoot, vendorJs), parsePluginClientSettings(discourseRoot, vendorJs, app), funnel(`${discourseRoot}/public/javascripts`, { destDir: "javascripts" }), @@ -170,7 +192,38 @@ module.exports = function (defaults) { outputFile: `assets/markdown-it-bundle.js`, }), generateScriptsTree(app), - discoursePluginsTree, - testemStylesheetTree, - ]); + discoursePluginsTree + ); + + return maybeEmbroider(app, { + extraPublicTrees, + packagerOptions: { + webpackConfig: { + externals: [ + function ({ request }, callback) { + if ( + !request.includes("-embroider-implicit") && + (request.startsWith("admin/") || + request.startsWith("wizard/") || + (request.startsWith("pretty-text/engines/") && + request !== "pretty-text/engines/discourse-markdown-it") || + request.startsWith("discourse/plugins/") || + request.startsWith("discourse/theme-")) + ) { + callback(null, request, "commonjs"); + } else { + callback(); + } + }, + ], + module: { + parser: { + javascript: { + exportsPresence: "error", + }, + }, + }, + }, + }, + }); }; diff --git a/app/assets/javascripts/discourse/package.json b/app/assets/javascripts/discourse/package.json index 6b30800dbc2..b66cdd8e1ad 100644 --- a/app/assets/javascripts/discourse/package.json +++ b/app/assets/javascripts/discourse/package.json @@ -36,7 +36,10 @@ "@ember/render-modifiers": "^2.1.0", "@ember/string": "^3.1.1", "@ember/test-helpers": "^2.9.4", + "@embroider/compat": "^3.2.1", + "@embroider/core": "^3.2.1", "@embroider/macros": "^1.13.1", + "@embroider/webpack": "^3.1.5", "@glimmer/component": "^1.1.2", "@glimmer/tracking": "^1.1.2", "@popperjs/core": "^2.11.8", diff --git a/app/assets/javascripts/discourse/tests/index.html b/app/assets/javascripts/discourse/tests/index.html index f51840ddcf2..aef36b86c79 100644 --- a/app/assets/javascripts/discourse/tests/index.html +++ b/app/assets/javascripts/discourse/tests/index.html @@ -20,8 +20,8 @@ - - + + {{content-for "head-footer"}} {{content-for "test-head-footer"}} @@ -55,19 +55,19 @@ - + + - - - + + +