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:
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
container: discourse/discourse_test:slim${{ startsWith(matrix.build_type, 'frontend') && '-browsers' || '' }}
timeout-minutes: 60
@ -29,7 +29,6 @@ jobs:
PGUSER: discourse
PGPASSWORD: discourse
USES_PARALLEL_DATABASES: ${{ matrix.build_type == 'backend' }}
EMBER_CLI_PLUGIN_ASSETS: ${{ matrix.ember_cli_plugin_assets }}
strategy:
fail-fast: false
@ -37,17 +36,11 @@ jobs:
matrix:
build_type: [backend, frontend, annotations]
target: [core, plugins]
ember_cli_plugin_assets: ['1', '0']
exclude:
- build_type: annotations
target: plugins
- build_type: frontend
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:
- 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"
);
let discoursePluginsTree;
if (process.env.EMBER_CLI_PLUGIN_ASSETS !== "0") {
discoursePluginsTree = app.project
.findAddonByName("discourse-plugins")
.generatePluginsTree();
} else {
// Empty tree - no-op
discoursePluginsTree = mergeTrees([]);
}
const discoursePluginsTree = app.project
.findAddonByName("discourse-plugins")
.generatePluginsTree();
const terserPlugin = app.project.findAddonByName("ember-cli-terser");
const applyTerser = (tree) => terserPlugin.postprocessTree("all", tree);

View File

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

View File

@ -98,15 +98,6 @@ if (process.argv.includes("-t")) {
"/assets/plugins/*_extra.js": {
target,
},
"/assets/discourse/tests/active-plugins.js": {
target,
},
"/assets/admin-plugins.js": {
target,
},
"/assets/discourse/tests/plugin-tests.js": {
target,
},
"/plugins/": {
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| %>
<%= preload_script file %>
<%- end %>
<%= preload_script "admin-plugins" %>
<%= preload_script "test-support" %>
<%= preload_script "test-helpers" %>
<%= theme_translations_lookup %>

View File

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

View File

@ -1,10 +1,6 @@
# frozen_string_literal: true
module EmberCli
def self.plugin_assets?
ENV["EMBER_CLI_PLUGIN_ASSETS"] != "0"
end
def self.assets
@assets ||= begin
assets = %w(
@ -18,11 +14,9 @@ module EmberCli
)
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|
next if file.ends_with?("_extra") # these are still handled by sprockets
assets << "#{file}.js"
end
Discourse.find_plugin_js_assets(include_disabled: true).each do |file|
next if file.ends_with?("_extra") # these are still handled by sprockets
assets << "#{file}.js"
end
assets

View File

@ -715,12 +715,6 @@ class Plugin::Instance
handlebars_includes.each { |hb| contents << "require_asset('#{hb}')" }
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?
[js_file_path, extra_js_file_path].each do |f|
File.delete(f)
@ -732,13 +726,10 @@ class Plugin::Instance
contents.insert(0, "<%")
contents << "%>"
write_path = EmberCli.plugin_assets? ? extra_js_file_path : js_file_path
delete_path = EmberCli.plugin_assets? ? js_file_path : extra_js_file_path
Discourse::Utils.atomic_write_file(write_path, contents.join("\n"))
Discourse::Utils.atomic_write_file(extra_js_file_path, contents.join("\n"))
begin
File.delete(delete_path)
File.delete(js_file_path)
rescue Errno::ENOENT
end
end
@ -850,25 +841,17 @@ class Plugin::Instance
end
def js_asset_exists?
if EmberCli.plugin_assets?
# If assets/javascripts exists, ember-cli will output a .js file
File.exist?("#{File.dirname(@path)}/assets/javascripts")
else
File.exist?(js_file_path)
end
# If assets/javascripts exists, ember-cli will output a .js file
File.exist?("#{File.dirname(@path)}/assets/javascripts")
end
def extra_js_asset_exists?
EmberCli.plugin_assets? && File.exist?(extra_js_file_path)
File.exist?(extra_js_file_path)
end
def admin_js_asset_exists?
if EmberCli.plugin_assets?
# If this directory exists, ember-cli will output a .js file
File.exist?("#{File.dirname(@path)}/admin/assets/javascripts")
else
false
end
# If this directory exists, ember-cli will output a .js file
File.exist?("#{File.dirname(@path)}/admin/assets/javascripts")
end
# 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
require 'net/http'
warmup_path = "/assets/discourse/tests/active-plugins.js"
warmup_path = "/srv/status"
uri = URI("http://localhost:#{unicorn_port}/#{warmup_path}")
puts "Warming up Rails server"