From 888f50543d10dc92d506a02f00a3a3324e7889c2 Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Wed, 15 Jun 2022 19:49:04 +0200 Subject: [PATCH] DEV: Fix `javascript:update` rake task (#17098) * The `javascript:update` rake task failed because recent versions of chart.js use a lowercase filename (`chart.min.js` instead of `Chart.min.js`) * Changed `loadScript()` to use lowercase keys to lookup scripts * `svg-arrow.css` seems to have changed slightly (linebreak at the end of file) --- .../javascripts/discourse/app/lib/load-script.js | 2 +- .../discourse/app/lib/public-js-versions.js | 2 +- .../discourse/tests/unit/lib/load-script-test.js | 11 +++++++++++ app/assets/stylesheets/vendor/svg-arrow.css | 2 +- lib/tasks/javascript.rake | 4 ++-- .../chart.js/3.5.1/{Chart.min.js => chart.min.js} | 0 6 files changed, 16 insertions(+), 5 deletions(-) rename public/javascripts/chart.js/3.5.1/{Chart.min.js => chart.min.js} (100%) diff --git a/app/assets/javascripts/discourse/app/lib/load-script.js b/app/assets/javascripts/discourse/app/lib/load-script.js index 2eb5a52c096..5acbbceac46 100644 --- a/app/assets/javascripts/discourse/app/lib/load-script.js +++ b/app/assets/javascripts/discourse/app/lib/load-script.js @@ -119,7 +119,7 @@ export function cacheBuster(url) { if (PUBLIC_JS_VERSIONS) { let [folder, ...lib] = url.split("/").filter(Boolean); if (folder === "javascripts") { - lib = lib.join("/"); + lib = lib.join("/").toLowerCase(); const versionedPath = PUBLIC_JS_VERSIONS[lib]; if (versionedPath) { return `/javascripts/${versionedPath}`; diff --git a/app/assets/javascripts/discourse/app/lib/public-js-versions.js b/app/assets/javascripts/discourse/app/lib/public-js-versions.js index 393052736cf..a8ced62efaa 100644 --- a/app/assets/javascripts/discourse/app/lib/public-js-versions.js +++ b/app/assets/javascripts/discourse/app/lib/public-js-versions.js @@ -4,7 +4,7 @@ export const PUBLIC_JS_VERSIONS = { "ace/ace.js": "ace.js/1.4.13/ace.js", "jsoneditor.js": "@json-editor/json-editor/2.6.1/jsoneditor.js", - "Chart.min.js": "chart.js/3.5.1/Chart.min.js", + "chart.min.js": "chart.js/3.5.1/chart.min.js", "chartjs-plugin-datalabels.min.js": "chartjs-plugin-datalabels/2.0.0/chartjs-plugin-datalabels.min.js", "diffhtml.min.js": "diffhtml/1.0.0-beta.20/diffhtml.min.js", diff --git a/app/assets/javascripts/discourse/tests/unit/lib/load-script-test.js b/app/assets/javascripts/discourse/tests/unit/lib/load-script-test.js index fe48fbc8584..609b6a931fc 100644 --- a/app/assets/javascripts/discourse/tests/unit/lib/load-script-test.js +++ b/app/assets/javascripts/discourse/tests/unit/lib/load-script-test.js @@ -24,4 +24,15 @@ module("Unit | Utility | load-script", function () { `/javascripts/${jsVersions["ace/ace.js"]}` ); }); + + test("lookups are case-insensitive", (assert) => { + assert.strictEqual( + cacheBuster("/javascripts/Chart.min.js"), + `/javascripts/${jsVersions["chart.min.js"]}` + ); + assert.strictEqual( + cacheBuster("/javascripts/chart.min.js"), + `/javascripts/${jsVersions["chart.min.js"]}` + ); + }); }); diff --git a/app/assets/stylesheets/vendor/svg-arrow.css b/app/assets/stylesheets/vendor/svg-arrow.css index 5e5b389c63c..c2a61ad7ae3 100644 --- a/app/assets/stylesheets/vendor/svg-arrow.css +++ b/app/assets/stylesheets/vendor/svg-arrow.css @@ -1 +1 @@ -.tippy-box[data-placement^=top]>.tippy-svg-arrow{bottom:0}.tippy-box[data-placement^=top]>.tippy-svg-arrow:after,.tippy-box[data-placement^=top]>.tippy-svg-arrow>svg{top:16px;transform:rotate(180deg)}.tippy-box[data-placement^=bottom]>.tippy-svg-arrow{top:0}.tippy-box[data-placement^=bottom]>.tippy-svg-arrow>svg{bottom:16px}.tippy-box[data-placement^=left]>.tippy-svg-arrow{right:0}.tippy-box[data-placement^=left]>.tippy-svg-arrow:after,.tippy-box[data-placement^=left]>.tippy-svg-arrow>svg{transform:rotate(90deg);top:calc(50% - 3px);left:11px}.tippy-box[data-placement^=right]>.tippy-svg-arrow{left:0}.tippy-box[data-placement^=right]>.tippy-svg-arrow:after,.tippy-box[data-placement^=right]>.tippy-svg-arrow>svg{transform:rotate(-90deg);top:calc(50% - 3px);right:11px}.tippy-svg-arrow{width:16px;height:16px;fill:#333;text-align:initial}.tippy-svg-arrow,.tippy-svg-arrow>svg{position:absolute} +.tippy-box[data-placement^=top]>.tippy-svg-arrow{bottom:0}.tippy-box[data-placement^=top]>.tippy-svg-arrow:after,.tippy-box[data-placement^=top]>.tippy-svg-arrow>svg{top:16px;transform:rotate(180deg)}.tippy-box[data-placement^=bottom]>.tippy-svg-arrow{top:0}.tippy-box[data-placement^=bottom]>.tippy-svg-arrow>svg{bottom:16px}.tippy-box[data-placement^=left]>.tippy-svg-arrow{right:0}.tippy-box[data-placement^=left]>.tippy-svg-arrow:after,.tippy-box[data-placement^=left]>.tippy-svg-arrow>svg{transform:rotate(90deg);top:calc(50% - 3px);left:11px}.tippy-box[data-placement^=right]>.tippy-svg-arrow{left:0}.tippy-box[data-placement^=right]>.tippy-svg-arrow:after,.tippy-box[data-placement^=right]>.tippy-svg-arrow>svg{transform:rotate(-90deg);top:calc(50% - 3px);right:11px}.tippy-svg-arrow{width:16px;height:16px;fill:#333;text-align:initial}.tippy-svg-arrow,.tippy-svg-arrow>svg{position:absolute} \ No newline at end of file diff --git a/lib/tasks/javascript.rake b/lib/tasks/javascript.rake index 7f2ceb59059..b632a401b9d 100644 --- a/lib/tasks/javascript.rake +++ b/lib/tasks/javascript.rake @@ -75,7 +75,7 @@ def dependencies package_name: '@json-editor/json-editor', public: true }, { - source: 'chart.js/dist/Chart.min.js', + source: 'chart.js/dist/chart.min.js', public: true }, { source: 'chartjs-plugin-datalabels/dist/chartjs-plugin-datalabels.min.js', @@ -310,7 +310,7 @@ task 'javascript:update' => 'clean_up' do else package_dir_name = public_path_name(f) package_version = JSON.parse(File.read("#{library_src}/#{node_package_name(f)}/package.json"))["version"] - versions[filename] = "#{package_dir_name}/#{package_version}/#{filename}" + versions[filename.downcase] = "#{package_dir_name}/#{package_version}/#{filename}" path = "#{public_js}/#{package_dir_name}/#{package_version}" dest = "#{path}/#{filename}" diff --git a/public/javascripts/chart.js/3.5.1/Chart.min.js b/public/javascripts/chart.js/3.5.1/chart.min.js similarity index 100% rename from public/javascripts/chart.js/3.5.1/Chart.min.js rename to public/javascripts/chart.js/3.5.1/chart.min.js