From d6332d2bc723f9aa60f2c886564bef49a6b91b84 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 14 Feb 2021 20:25:41 -0500 Subject: [PATCH] Test html script ordering (#1396) * Simplify getAllFiles * Add test to validate script order * Update script include order * Update content script order * Update sw.js and corresponding lint * Update manifest --- .eslintrc.json | 36 +++++------ dev/build.js | 2 +- dev/data/manifest-variants.json | 26 ++++---- dev/lint/global-declarations.js | 6 +- dev/lint/html-scripts.js | 102 ++++++++++++++++++++++++++++++-- dev/util.js | 6 +- ext/action-popup.html | 10 ++-- ext/background.html | 49 ++++++++------- ext/info.html | 11 ++-- ext/manifest.json | 26 ++++---- ext/permissions.html | 9 +-- ext/pitch-accents-preview.html | 7 ++- ext/popup-preview.html | 27 +++++---- ext/popup.html | 41 +++++++------ ext/search.html | 43 +++++++------- ext/settings-old.html | 51 ++++++++-------- ext/settings.html | 65 ++++++++++---------- ext/sw.js | 36 +++++------ ext/template-renderer.html | 18 +++--- ext/welcome.html | 24 ++++---- 20 files changed, 343 insertions(+), 252 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index e17c63df..8f8dc4e9 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -166,30 +166,30 @@ "files": [ "ext/js/core.js", "ext/js/yomichan.js", + "ext/js/background/backend.js", "ext/js/background/environment.js", - "ext/js/language/japanese-util.js", - "ext/js/general/cache-map.js", - "ext/js/language/dictionary-data-util.js", - "ext/js/general/object-property-accessor.js", - "ext/js/comm/anki.js", - "ext/js/media/audio-downloader.js", - "ext/js/comm/clipboard-monitor.js", - "ext/js/comm/clipboard-reader.js", - "ext/js/data/database.js", - "ext/js/language/deinflector.js", - "ext/js/language/dictionary-database.js", - "ext/js/data/json-schema.js", - "ext/js/comm/mecab.js", - "ext/js/media/media-util.js", - "ext/js/data/options-util.js", - "ext/js/data/permissions-util.js", "ext/js/background/profile-conditions-util.js", "ext/js/background/request-builder.js", + "ext/js/comm/anki.js", + "ext/js/comm/clipboard-monitor.js", + "ext/js/comm/clipboard-reader.js", + "ext/js/comm/mecab.js", + "ext/js/data/database.js", + "ext/js/data/json-schema.js", + "ext/js/data/options-util.js", + "ext/js/data/permissions-util.js", "ext/js/dom/simple-dom-parser.js", - "ext/js/templates/template-patcher.js", + "ext/js/general/cache-map.js", + "ext/js/general/object-property-accessor.js", "ext/js/general/text-source-map.js", + "ext/js/language/deinflector.js", + "ext/js/language/dictionary-data-util.js", + "ext/js/language/dictionary-database.js", + "ext/js/language/japanese-util.js", "ext/js/language/translator.js", - "ext/js/background/backend.js", + "ext/js/media/audio-downloader.js", + "ext/js/media/media-util.js", + "ext/js/templates/template-patcher.js", "ext/js/background/background-main.js" ], "env": { diff --git a/dev/build.js b/dev/build.js index 9cbbd518..55358e59 100644 --- a/dev/build.js +++ b/dev/build.js @@ -62,7 +62,7 @@ async function createZip(directory, excludeFiles, outputFileName, sevenZipExes, async function createJSZip(directory, excludeFiles, outputFileName, onUpdate, dryRun) { const JSZip = util.JSZip; - const files = getAllFiles(directory, directory); + const files = getAllFiles(directory); removeItemsFromArray(files, excludeFiles); const zip = new JSZip(); for (const fileName of files) { diff --git a/dev/data/manifest-variants.json b/dev/data/manifest-variants.json index 178f1395..3b50b0f3 100644 --- a/dev/data/manifest-variants.json +++ b/dev/data/manifest-variants.json @@ -41,23 +41,23 @@ "js": [ "js/core.js", "js/yomichan.js", - "js/comm/cross-frame-api.js", - "js/comm/api.js", - "js/script/dynamic-loader.js", - "js/comm/frame-client.js", - "js/language/text-scanner.js", - "js/dom/document-util.js", - "js/input/hotkey-handler.js", - "js/dom/dom-text-scanner.js", + "js/app/frontend.js", "js/app/popup.js", - "js/dom/text-source-range.js", - "js/dom/text-source-element.js", "js/app/popup-factory.js", - "js/comm/frame-ancestry-handler.js", - "js/comm/frame-offset-forwarder.js", "js/app/popup-proxy.js", "js/app/popup-window.js", - "js/app/frontend.js", + "js/comm/api.js", + "js/comm/cross-frame-api.js", + "js/comm/frame-ancestry-handler.js", + "js/comm/frame-client.js", + "js/comm/frame-offset-forwarder.js", + "js/dom/dom-text-scanner.js", + "js/dom/document-util.js", + "js/dom/text-source-element.js", + "js/dom/text-source-range.js", + "js/input/hotkey-handler.js", + "js/language/text-scanner.js", + "js/script/dynamic-loader.js", "js/app/content-script-main.js" ], "match_about_blank": true, diff --git a/dev/lint/global-declarations.js b/dev/lint/global-declarations.js index 61739c42..914d1266 100644 --- a/dev/lint/global-declarations.js +++ b/dev/lint/global-declarations.js @@ -117,10 +117,10 @@ function main() { const fix = (process.argv.length >= 2 && process.argv[2] === '--fix'); const directory = path.resolve(__dirname, '..', '..', 'ext'); const pattern = /\.js$/; - const ignorePattern = /[\\/]ext[\\/]lib[\\/]/; - const fileNames = getAllFiles(directory, null, (f) => pattern.test(f) && !ignorePattern.test(f)); + const ignorePattern = /^lib[\\/]/; + const fileNames = getAllFiles(directory, (f) => pattern.test(f) && !ignorePattern.test(f)); for (const fileName of fileNames) { - if (!validateGlobals(fileName, fix)) { + if (!validateGlobals(path.join(directory, fileName), fix)) { process.exit(-1); return; } diff --git a/dev/lint/html-scripts.js b/dev/lint/html-scripts.js index dec8a3dd..41263d96 100644 --- a/dev/lint/html-scripts.js +++ b/dev/lint/html-scripts.js @@ -41,18 +41,110 @@ function validatePath(src, fileName, extDir) { assert.ok(stats.isFile(), ` - - - - - + + + + + diff --git a/ext/background.html b/ext/background.html index 6818db23..a801aae7 100644 --- a/ext/background.html +++ b/ext/background.html @@ -18,34 +18,33 @@ + - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ext/info.html b/ext/info.html index aa00b103..3000070a 100644 --- a/ext/info.html +++ b/ext/info.html @@ -59,15 +59,16 @@ - - - + + + + + - - + diff --git a/ext/manifest.json b/ext/manifest.json index 85aecc9c..55fd54e8 100644 --- a/ext/manifest.json +++ b/ext/manifest.json @@ -40,23 +40,23 @@ "js": [ "js/core.js", "js/yomichan.js", - "js/comm/cross-frame-api.js", - "js/comm/api.js", - "js/script/dynamic-loader.js", - "js/comm/frame-client.js", - "js/language/text-scanner.js", - "js/dom/document-util.js", - "js/input/hotkey-handler.js", - "js/dom/dom-text-scanner.js", + "js/app/frontend.js", "js/app/popup.js", - "js/dom/text-source-range.js", - "js/dom/text-source-element.js", "js/app/popup-factory.js", - "js/comm/frame-ancestry-handler.js", - "js/comm/frame-offset-forwarder.js", "js/app/popup-proxy.js", "js/app/popup-window.js", - "js/app/frontend.js", + "js/comm/api.js", + "js/comm/cross-frame-api.js", + "js/comm/frame-ancestry-handler.js", + "js/comm/frame-client.js", + "js/comm/frame-offset-forwarder.js", + "js/dom/dom-text-scanner.js", + "js/dom/document-util.js", + "js/dom/text-source-element.js", + "js/dom/text-source-range.js", + "js/input/hotkey-handler.js", + "js/language/text-scanner.js", + "js/script/dynamic-loader.js", "js/app/content-script-main.js" ], "match_about_blank": true, diff --git a/ext/permissions.html b/ext/permissions.html index 23d3412a..fc4d2f8d 100644 --- a/ext/permissions.html +++ b/ext/permissions.html @@ -162,13 +162,14 @@ - - - + + + + + - diff --git a/ext/pitch-accents-preview.html b/ext/pitch-accents-preview.html index 38ee2363..a3c6f875 100644 --- a/ext/pitch-accents-preview.html +++ b/ext/pitch-accents-preview.html @@ -50,10 +50,11 @@ - - - + + + + diff --git a/ext/popup-preview.html b/ext/popup-preview.html index a331017d..3ca46232 100644 --- a/ext/popup-preview.html +++ b/ext/popup-preview.html @@ -37,23 +37,24 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/ext/popup.html b/ext/popup.html index 1d950930..88648809 100644 --- a/ext/popup.html +++ b/ext/popup.html @@ -90,42 +90,41 @@ - - - - - - - - - - + + + + + + + - - - - - - + + + + + + + + + + - + + - - + - - diff --git a/ext/search.html b/ext/search.html index d403effb..d1c28fc8 100644 --- a/ext/search.html +++ b/ext/search.html @@ -76,41 +76,40 @@ - - - - - - - - - - - + + + + + + - + + + + + + + + + + - - - + + - + + - - + - - - - diff --git a/ext/settings-old.html b/ext/settings-old.html index 697b95dc..4c35218f 100644 --- a/ext/settings-old.html +++ b/ext/settings-old.html @@ -1274,60 +1274,59 @@ + - - - - - - - - + + + + + + + + + + + - - + + - - - - - - + + - + + - - - - - - - - + - + + + + + + diff --git a/ext/settings.html b/ext/settings.html index b37507ed..1b7fa02d 100644 --- a/ext/settings.html +++ b/ext/settings.html @@ -3190,69 +3190,66 @@ - - - - - - - - + + + + + + + + + + + - - + + - - - - - - + + - + + - - - - - - - + - + + + + + + + + - - - - - - - - - + + + + + diff --git a/ext/sw.js b/ext/sw.js index 6e9952d6..802f3ba3 100644 --- a/ext/sw.js +++ b/ext/sw.js @@ -20,29 +20,29 @@ self.importScripts( '/lib/wanakana.min.js', '/js/core.js', '/js/yomichan.js', + '/js/background/backend.js', '/js/background/environment.js', - '/js/language/japanese-util.js', - '/js/general/cache-map.js', - '/js/language/dictionary-data-util.js', - '/js/general/object-property-accessor.js', - '/js/comm/anki.js', - '/js/media/audio-downloader.js', - '/js/comm/clipboard-monitor.js', - '/js/comm/clipboard-reader.js', - '/js/data/database.js', - '/js/language/deinflector.js', - '/js/language/dictionary-database.js', - '/js/data/json-schema.js', - '/js/comm/mecab.js', - '/js/media/media-util.js', - '/js/data/options-util.js', - '/js/data/permissions-util.js', '/js/background/profile-conditions-util.js', '/js/background/request-builder.js', + '/js/comm/anki.js', + '/js/comm/clipboard-monitor.js', + '/js/comm/clipboard-reader.js', + '/js/comm/mecab.js', + '/js/data/database.js', + '/js/data/json-schema.js', + '/js/data/options-util.js', + '/js/data/permissions-util.js', '/js/dom/simple-dom-parser.js', - '/js/templates/template-patcher.js', + '/js/general/cache-map.js', + '/js/general/object-property-accessor.js', '/js/general/text-source-map.js', + '/js/language/deinflector.js', + '/js/language/dictionary-data-util.js', + '/js/language/dictionary-database.js', + '/js/language/japanese-util.js', '/js/language/translator.js', - '/js/background/backend.js', + '/js/media/audio-downloader.js', + '/js/media/media-util.js', + '/js/templates/template-patcher.js', '/js/background/background-main.js' ); diff --git a/ext/template-renderer.html b/ext/template-renderer.html index 7245ed62..eb3695e1 100644 --- a/ext/template-renderer.html +++ b/ext/template-renderer.html @@ -13,12 +13,16 @@ - - - - - - - + + + + + + + + + + + diff --git a/ext/welcome.html b/ext/welcome.html index 0ea2020f..88eb5683 100644 --- a/ext/welcome.html +++ b/ext/welcome.html @@ -315,29 +315,28 @@ - - - - + + + + + + + - - + + - - + - - - @@ -345,9 +344,8 @@ - - +