DEV: Remove support for legacy plugin JS compilation pipeline (#18293)

This became the default in b1755137
This commit is contained in:
David Taylor 2022-09-21 12:38:02 +01:00 committed by GitHub
parent ae3a5f6bf0
commit e06b9d4a52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 52 additions and 147 deletions

View File

@ -17,7 +17,7 @@ permissions:
jobs: jobs:
build: build:
name: ${{ matrix.target }} ${{ matrix.build_type }} ${{ ((matrix.ember_cli_plugin_assets == '1') && '(ember-cli-compiled plugin js)') || ''}} name: ${{ matrix.target }} ${{ matrix.build_type }}
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: discourse/discourse_test:slim${{ startsWith(matrix.build_type, 'frontend') && '-browsers' || '' }} container: discourse/discourse_test:slim${{ startsWith(matrix.build_type, 'frontend') && '-browsers' || '' }}
timeout-minutes: 60 timeout-minutes: 60
@ -29,7 +29,6 @@ jobs:
PGUSER: discourse PGUSER: discourse
PGPASSWORD: discourse PGPASSWORD: discourse
USES_PARALLEL_DATABASES: ${{ matrix.build_type == 'backend' }} USES_PARALLEL_DATABASES: ${{ matrix.build_type == 'backend' }}
EMBER_CLI_PLUGIN_ASSETS: ${{ matrix.ember_cli_plugin_assets }}
strategy: strategy:
fail-fast: false fail-fast: false
@ -37,17 +36,11 @@ jobs:
matrix: matrix:
build_type: [backend, frontend, annotations] build_type: [backend, frontend, annotations]
target: [core, plugins] target: [core, plugins]
ember_cli_plugin_assets: ['1', '0']
exclude: exclude:
- build_type: annotations - build_type: annotations
target: plugins target: plugins
- build_type: frontend - build_type: frontend
target: core # Handled by core_frontend_tests job (below) target: core # Handled by core_frontend_tests job (below)
- target: core
ember_cli_plugin_assets: '1'
- target: plugins
build_type: backend
ember_cli_plugin_assets: '1'
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3

View File

@ -1,11 +0,0 @@
<%
DiscoursePluginRegistry.admin_javascripts.each { |js| require_asset(js) }
DiscoursePluginRegistry.each_globbed_asset(admin: true) do |f|
if File.directory?(f)
depend_on(f)
else
require_asset(f)
end
end
%>

View File

@ -145,15 +145,9 @@ module.exports = function (defaults) {
"/app/assets/javascripts/discourse/public/assets/scripts/module-shims.js" "/app/assets/javascripts/discourse/public/assets/scripts/module-shims.js"
); );
let discoursePluginsTree; const discoursePluginsTree = app.project
if (process.env.EMBER_CLI_PLUGIN_ASSETS !== "0") { .findAddonByName("discourse-plugins")
discoursePluginsTree = app.project .generatePluginsTree();
.findAddonByName("discourse-plugins")
.generatePluginsTree();
} else {
// Empty tree - no-op
discoursePluginsTree = mergeTrees([]);
}
const terserPlugin = app.project.findAddonByName("ember-cli-terser"); const terserPlugin = app.project.findAddonByName("ember-cli-terser");
const applyTerser = (tree) => terserPlugin.postprocessTree("all", tree); const applyTerser = (tree) => terserPlugin.postprocessTree("all", tree);

View File

@ -381,44 +381,36 @@ module.exports = {
if (shouldLoadPluginTestJs() && type === "test-plugin-js") { if (shouldLoadPluginTestJs() && type === "test-plugin-js") {
const scripts = []; const scripts = [];
if (process.env.EMBER_CLI_PLUGIN_ASSETS !== "0") { const pluginInfos = this.app.project
const pluginInfos = this.app.project .findAddonByName("discourse-plugins")
.findAddonByName("discourse-plugins") .pluginInfos();
.pluginInfos();
for (const { for (const {
pluginName, pluginName,
directoryName, directoryName,
hasJs, hasJs,
hasAdminJs, hasAdminJs,
} of pluginInfos) { } of pluginInfos) {
if (hasJs) { if (hasJs) {
scripts.push({ scripts.push({
src: `plugins/${directoryName}.js`, src: `plugins/${directoryName}.js`,
name: pluginName, name: pluginName,
}); });
} }
if (fs.existsSync(`../plugins/${directoryName}_extras.js.erb`)) { if (fs.existsSync(`../plugins/${directoryName}_extras.js.erb`)) {
scripts.push({ scripts.push({
src: `plugins/${directoryName}_extras.js`, src: `plugins/${directoryName}_extras.js`,
name: pluginName, name: pluginName,
}); });
} }
if (hasAdminJs) { if (hasAdminJs) {
scripts.push({ scripts.push({
src: `plugins/${directoryName}_admin.js`, src: `plugins/${directoryName}_admin.js`,
name: pluginName, name: pluginName,
}); });
}
} }
} else {
scripts.push({
src: "discourse/tests/active-plugins.js",
name: "_all",
});
scripts.push({ src: "admin-plugins.js", name: "_admin" });
} }
return scripts return scripts
@ -428,19 +420,15 @@ module.exports = {
) )
.join("\n"); .join("\n");
} else if (shouldLoadPluginTestJs() && type === "test-plugin-tests-js") { } else if (shouldLoadPluginTestJs() && type === "test-plugin-tests-js") {
if (process.env.EMBER_CLI_PLUGIN_ASSETS !== "0") { return this.app.project
return this.app.project .findAddonByName("discourse-plugins")
.findAddonByName("discourse-plugins") .pluginInfos()
.pluginInfos() .filter(({ hasTests }) => hasTests)
.filter(({ hasTests }) => hasTests) .map(
.map( ({ directoryName, pluginName }) =>
({ directoryName, pluginName }) => `<script src="${config.rootURL}assets/plugins/test/${directoryName}_tests.js" data-discourse-plugin="${pluginName}"></script>`
`<script src="${config.rootURL}assets/plugins/test/${directoryName}_tests.js" data-discourse-plugin="${pluginName}"></script>` )
) .join("\n");
.join("\n");
} else {
return `<script id="plugin-test-script" src="${config.rootURL}assets/discourse/tests/plugin-tests.js" data-discourse-plugin="_all"></script>`;
}
} }
}, },

View File

@ -98,15 +98,6 @@ if (process.argv.includes("-t")) {
"/assets/plugins/*_extra.js": { "/assets/plugins/*_extra.js": {
target, target,
}, },
"/assets/discourse/tests/active-plugins.js": {
target,
},
"/assets/admin-plugins.js": {
target,
},
"/assets/discourse/tests/plugin-tests.js": {
target,
},
"/plugins/": { "/plugins/": {
target, target,
}, },

View File

@ -1,11 +0,0 @@
<%
DiscoursePluginRegistry.javascripts.each { |js| require_asset(js) }
DiscoursePluginRegistry.handlebars.each { |hb| require_asset(hb) }
DiscoursePluginRegistry.each_globbed_asset do |f|
if File.directory?(f)
depend_on(f)
else
require_asset(f)
end
end
%>

View File

@ -1,3 +0,0 @@
//= require_tree ./acceptance
//= require_tree ./integration
//= require_tree ./unit

View File

@ -1,10 +0,0 @@
<%
Discourse.plugins.each do |p|
root_path = "#{File.dirname(p.path)}/test/javascripts"
to_glob = [root_path + '/**/**.es6']
to_glob << (root_path + '/**/**.js')
Dir.glob(to_glob) { |f| require_asset(f) }
end
%>

View File

@ -11,7 +11,6 @@
<%- Discourse.find_plugin_js_assets(include_disabled: true).each do |file| %> <%- Discourse.find_plugin_js_assets(include_disabled: true).each do |file| %>
<%= preload_script file %> <%= preload_script file %>
<%- end %> <%- end %>
<%= preload_script "admin-plugins" %>
<%= preload_script "test-support" %> <%= preload_script "test-support" %>
<%= preload_script "test-helpers" %> <%= preload_script "test-helpers" %>
<%= theme_translations_lookup %> <%= theme_translations_lookup %>

View File

@ -46,8 +46,6 @@ Rails.application.config.assets.precompile += %w{
confirm-new-email/bootstrap.js confirm-new-email/bootstrap.js
onpopstate-handler.js onpopstate-handler.js
embed-application.js embed-application.js
discourse/tests/active-plugins.js
admin-plugins.js
scripts/discourse-test-listen-boot scripts/discourse-test-listen-boot
scripts/discourse-boot scripts/discourse-boot
} }

View File

@ -1,10 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module EmberCli module EmberCli
def self.plugin_assets?
ENV["EMBER_CLI_PLUGIN_ASSETS"] != "0"
end
def self.assets def self.assets
@assets ||= begin @assets ||= begin
assets = %w( assets = %w(
@ -18,11 +14,9 @@ module EmberCli
) )
assets += Dir.glob("app/assets/javascripts/discourse/scripts/*.js").map { |f| File.basename(f) } assets += Dir.glob("app/assets/javascripts/discourse/scripts/*.js").map { |f| File.basename(f) }
if plugin_assets? Discourse.find_plugin_js_assets(include_disabled: true).each do |file|
Discourse.find_plugin_js_assets(include_disabled: true).each do |file| next if file.ends_with?("_extra") # these are still handled by sprockets
next if file.ends_with?("_extra") # these are still handled by sprockets assets << "#{file}.js"
assets << "#{file}.js"
end
end end
assets assets

View File

@ -715,12 +715,6 @@ class Plugin::Instance
handlebars_includes.each { |hb| contents << "require_asset('#{hb}')" } handlebars_includes.each { |hb| contents << "require_asset('#{hb}')" }
javascript_includes.each { |js| contents << "require_asset('#{js}')" } javascript_includes.each { |js| contents << "require_asset('#{js}')" }
if !EmberCli.plugin_assets?
each_globbed_asset do |f, is_dir|
contents << (is_dir ? "depend_on('#{f}')" : "require_asset('#{f}')")
end
end
if !contents.present? if !contents.present?
[js_file_path, extra_js_file_path].each do |f| [js_file_path, extra_js_file_path].each do |f|
File.delete(f) File.delete(f)
@ -732,13 +726,10 @@ class Plugin::Instance
contents.insert(0, "<%") contents.insert(0, "<%")
contents << "%>" contents << "%>"
write_path = EmberCli.plugin_assets? ? extra_js_file_path : js_file_path Discourse::Utils.atomic_write_file(extra_js_file_path, contents.join("\n"))
delete_path = EmberCli.plugin_assets? ? js_file_path : extra_js_file_path
Discourse::Utils.atomic_write_file(write_path, contents.join("\n"))
begin begin
File.delete(delete_path) File.delete(js_file_path)
rescue Errno::ENOENT rescue Errno::ENOENT
end end
end end
@ -850,25 +841,17 @@ class Plugin::Instance
end end
def js_asset_exists? def js_asset_exists?
if EmberCli.plugin_assets? # If assets/javascripts exists, ember-cli will output a .js file
# If assets/javascripts exists, ember-cli will output a .js file File.exist?("#{File.dirname(@path)}/assets/javascripts")
File.exist?("#{File.dirname(@path)}/assets/javascripts")
else
File.exist?(js_file_path)
end
end end
def extra_js_asset_exists? def extra_js_asset_exists?
EmberCli.plugin_assets? && File.exist?(extra_js_file_path) File.exist?(extra_js_file_path)
end end
def admin_js_asset_exists? def admin_js_asset_exists?
if EmberCli.plugin_assets? # If this directory exists, ember-cli will output a .js file
# If this directory exists, ember-cli will output a .js file File.exist?("#{File.dirname(@path)}/admin/assets/javascripts")
File.exist?("#{File.dirname(@path)}/admin/assets/javascripts")
else
false
end
end end
# Receives an array with two elements: # Receives an array with two elements:

View File

@ -85,7 +85,7 @@ task "qunit:test", [:timeout, :qunit_path] do |_, args|
# wait for server to accept connections # wait for server to accept connections
require 'net/http' require 'net/http'
warmup_path = "/assets/discourse/tests/active-plugins.js" warmup_path = "/srv/status"
uri = URI("http://localhost:#{unicorn_port}/#{warmup_path}") uri = URI("http://localhost:#{unicorn_port}/#{warmup_path}")
puts "Warming up Rails server" puts "Warming up Rails server"