From 70f1cc55529d6446a1751989a1d9663db26c00df Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Thu, 24 Aug 2023 16:36:22 +0200 Subject: [PATCH] DEV: Use esbuild to make DiscourseJsProcessor (#23223) Reverts e2705df and re-lands #23187 and #23219. The issue was incorrect order of execution of Rails' `assets:precompile` task in our own precompilation stack. Co-authored-by: David Taylor --- .gitignore | 1 + .../lib/widget-hbs-compiler.js | 5 +- app/assets/javascripts/discourse/package.json | 2 +- ...course-js-processor.js => js-processor.js} | 53 +++-- app/assets/javascripts/package.json | 1 - app/assets/javascripts/yarn.lock | 190 +++--------------- app/models/theme.rb | 2 +- lib/discourse_js_processor.rb | 139 ++----------- lib/tasks/assets.rake | 40 ++-- package.json | 7 +- spec/lib/discourse_js_processor_spec.rb | 2 +- yarn.lock | 138 +++++++++++++ 12 files changed, 253 insertions(+), 327 deletions(-) rename app/assets/javascripts/{discourse-js-processor.js => js-processor.js} (69%) diff --git a/.gitignore b/.gitignore index 3c7b1482942..4a1b8e1fb68 100644 --- a/.gitignore +++ b/.gitignore @@ -75,3 +75,4 @@ openapi/* # Cached License Data Files /.licenses +/app/assets/javascripts/compiled-js-processor.js diff --git a/app/assets/javascripts/discourse-widget-hbs/lib/widget-hbs-compiler.js b/app/assets/javascripts/discourse-widget-hbs/lib/widget-hbs-compiler.js index 9efebf16ec6..9477da921ca 100644 --- a/app/assets/javascripts/discourse-widget-hbs/lib/widget-hbs-compiler.js +++ b/app/assets/javascripts/discourse-widget-hbs/lib/widget-hbs-compiler.js @@ -281,12 +281,11 @@ class Compiler { } } -// eslint-disable-next-line no-undef -const loader = typeof Ember !== "undefined" ? Ember.__loader.require : require; +const defaultGlimmer = require("@glimmer/syntax"); function compile(template, glimmer) { if (!glimmer) { - glimmer = loader("@glimmer/syntax"); + glimmer = defaultGlimmer; } const compiled = glimmer.preprocess(template); const compiler = new Compiler(compiled); diff --git a/app/assets/javascripts/discourse/package.json b/app/assets/javascripts/discourse/package.json index a3be832f0d0..4470c80c432 100644 --- a/app/assets/javascripts/discourse/package.json +++ b/app/assets/javascripts/discourse/package.json @@ -48,7 +48,7 @@ "a11y-dialog": "8.0.1", "admin": "1.0.0", "babel-import-util": "^1.4.1", - "babel-plugin-ember-template-compilation": "^2.0.0", + "babel-plugin-ember-template-compilation": "^2.2.0", "bootstrap": "3.4.1", "bootstrap-json": "1.0.0", "broccoli-asset-rev": "^3.0.0", diff --git a/app/assets/javascripts/discourse-js-processor.js b/app/assets/javascripts/js-processor.js similarity index 69% rename from app/assets/javascripts/discourse-js-processor.js rename to app/assets/javascripts/js-processor.js index e642b5cacaf..093306ab073 100644 --- a/app/assets/javascripts/discourse-js-processor.js +++ b/app/assets/javascripts/js-processor.js @@ -1,12 +1,29 @@ -/* global Babel:true Terser:true */ - // This is executed in mini_racer to provide the JS logic for lib/discourse_js_processor.rb -const HTMLBarsInlinePrecompile = - require("babel-plugin-ember-template-compilation").default; -const colocatedBabelPlugin = require("colocated-babel-plugin").default; -const precompile = require("ember-template-compiler").precompile; -const Handlebars = require("handlebars").default; +/* global rails */ + +const CONSOLE_PREFIX = "[DiscourseJsProcessor] "; +globalThis.window = {}; +globalThis.console = { + log(...args) { + rails.logger.info(CONSOLE_PREFIX + args.join(" ")); + }, + warn(...args) { + rails.logger.warn(CONSOLE_PREFIX + args.join(" ")); + }, + error(...args) { + rails.logger.error(CONSOLE_PREFIX + args.join(" ")); + }, +}; + +import HTMLBarsInlinePrecompile from "babel-plugin-ember-template-compilation"; +import colocatedBabelPlugin from "ember-cli-htmlbars/lib/colocated-babel-plugin"; +import { precompile } from "ember-source/dist/ember-template-compiler"; +import Handlebars from "handlebars"; +import { transform as babelTransform } from "@babel/standalone"; +import { minify as terserMinify } from "terser"; +import RawHandlebars from "discourse-common/addon/lib/raw-handlebars"; +import { WidgetHbsCompiler } from "discourse-widget-hbs/lib/widget-hbs-compiler"; function manipulateAstNodeForTheme(node, themeId) { // Magically add theme id as the first param for each of these helpers) @@ -53,7 +70,7 @@ function buildTemplateCompilerBabelPlugins({ themeId }) { return [ colocatedBabelPlugin, - require("widget-hbs-compiler").WidgetHbsCompiler, + WidgetHbsCompiler, [ HTMLBarsInlinePrecompile, { @@ -67,7 +84,7 @@ function buildTemplateCompilerBabelPlugins({ themeId }) { function buildThemeRawHbsTemplateManipulatorPlugin(themeId) { return function (ast) { ["SubExpression", "MustacheStatement"].forEach((pass) => { - let visitor = new Handlebars.Visitor(); + const visitor = new Handlebars.Visitor(); visitor.mutating = true; visitor[pass] = (node) => manipulateAstNodeForTheme(node, themeId); visitor.accept(ast); @@ -75,9 +92,8 @@ function buildThemeRawHbsTemplateManipulatorPlugin(themeId) { }; } -exports.compileRawTemplate = function (source, themeId) { +globalThis.compileRawTemplate = function (source, themeId) { try { - const RawHandlebars = require("raw-handlebars").default; const plugins = []; if (themeId) { plugins.push(buildThemeRawHbsTemplateManipulatorPlugin(themeId)); @@ -90,11 +106,10 @@ exports.compileRawTemplate = function (source, themeId) { } }; -exports.transpile = function ( - source, - { moduleId, filename, skipModule, themeId, commonPlugins } = {} -) { +globalThis.transpile = function (source, options = {}) { + const { moduleId, filename, skipModule, themeId, commonPlugins } = options; const plugins = []; + plugins.push(...buildTemplateCompilerBabelPlugins({ themeId })); if (moduleId && !skipModule) { plugins.push(["transform-modules-amd", { noInterop: true }]); @@ -102,7 +117,7 @@ exports.transpile = function ( plugins.push(...commonPlugins); try { - return Babel.transform(source, { + return babelTransform(source, { moduleId, filename, ast: false, @@ -120,16 +135,16 @@ exports.transpile = function ( // in a followup method call. let lastMinifyError, lastMinifyResult; -exports.minify = async function (sources, options) { +globalThis.minify = async function (sources, options) { lastMinifyError = lastMinifyResult = null; try { - lastMinifyResult = await Terser.minify(sources, options); + lastMinifyResult = await terserMinify(sources, options); } catch (e) { lastMinifyError = e; } }; -exports.getMinifyResult = function () { +globalThis.getMinifyResult = function () { const error = lastMinifyError; const result = lastMinifyResult; diff --git a/app/assets/javascripts/package.json b/app/assets/javascripts/package.json index c896264ae4b..e4851b7dd98 100644 --- a/app/assets/javascripts/package.json +++ b/app/assets/javascripts/package.json @@ -22,7 +22,6 @@ ], "resolutions": { "**/babel-plugin-debug-macros": "npm:@discourse/babel-plugin-debug-macros@0.4.0-pre1", - "**/babel-plugin-ember-template-compilation": "2.0.0", "**/unset-value": "2.0.1" }, "devDependencies": { diff --git a/app/assets/javascripts/yarn.lock b/app/assets/javascripts/yarn.lock index ebf03c193ad..8348cebbc35 100644 --- a/app/assets/javascripts/yarn.lock +++ b/app/assets/javascripts/yarn.lock @@ -23,7 +23,7 @@ "@babel/highlight" "^7.22.10" chalk "^2.4.2" -"@babel/compat-data@^7.17.7", "@babel/compat-data@^7.22.5", "@babel/compat-data@^7.22.6", "@babel/compat-data@^7.22.9": +"@babel/compat-data@^7.22.5", "@babel/compat-data@^7.22.6", "@babel/compat-data@^7.22.9": version "7.22.9" resolved "https://registry.yarnpkg.com/@babel/compat-data/-/compat-data-7.22.9.tgz#71cdb00a1ce3a329ce4cbec3a44f9fef35669730" integrity sha512-5UamI7xkUcJ3i9qVDS+KFDEK8/7oJ55/sJMB1Ge7IEapr7KfdfV/HErR+koZwOfd+SgtFKOKRhRakdg++DcJpQ== @@ -73,7 +73,7 @@ dependencies: "@babel/types" "^7.22.5" -"@babel/helper-compilation-targets@^7.12.0", "@babel/helper-compilation-targets@^7.17.7", "@babel/helper-compilation-targets@^7.20.7", "@babel/helper-compilation-targets@^7.22.10", "@babel/helper-compilation-targets@^7.22.5", "@babel/helper-compilation-targets@^7.22.6": +"@babel/helper-compilation-targets@^7.12.0", "@babel/helper-compilation-targets@^7.20.7", "@babel/helper-compilation-targets@^7.22.10", "@babel/helper-compilation-targets@^7.22.5", "@babel/helper-compilation-targets@^7.22.6": version "7.22.10" resolved "https://registry.yarnpkg.com/@babel/helper-compilation-targets/-/helper-compilation-targets-7.22.10.tgz#01d648bbc25dd88f513d862ee0df27b7d4e67024" integrity sha512-JMSwHD4J7SLod0idLq5PKgI+6g/hLD/iuWBq08ZX49xE14VpVEojJ5rHWptpirV2j020MvypRLAXAO50igCJ5Q== @@ -84,22 +84,7 @@ lru-cache "^5.1.1" semver "^6.3.1" -"@babel/helper-create-class-features-plugin@^7.18.6", "@babel/helper-create-class-features-plugin@^7.21.0", "@babel/helper-create-class-features-plugin@^7.22.5", "@babel/helper-create-class-features-plugin@^7.5.5": - version "7.22.5" - resolved "https://registry.yarnpkg.com/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.22.5.tgz#2192a1970ece4685fbff85b48da2c32fcb130b7c" - integrity sha512-xkb58MyOYIslxu3gKmVXmjTtUPvBU4odYzbiIQbWwLKIHCsx6UGZGX6F1IznMFVnDdirseUZopzN+ZRt8Xb33Q== - dependencies: - "@babel/helper-annotate-as-pure" "^7.22.5" - "@babel/helper-environment-visitor" "^7.22.5" - "@babel/helper-function-name" "^7.22.5" - "@babel/helper-member-expression-to-functions" "^7.22.5" - "@babel/helper-optimise-call-expression" "^7.22.5" - "@babel/helper-replace-supers" "^7.22.5" - "@babel/helper-skip-transparent-expression-wrappers" "^7.22.5" - "@babel/helper-split-export-declaration" "^7.22.5" - semver "^6.3.0" - -"@babel/helper-create-class-features-plugin@^7.22.10": +"@babel/helper-create-class-features-plugin@^7.18.6", "@babel/helper-create-class-features-plugin@^7.21.0", "@babel/helper-create-class-features-plugin@^7.22.10", "@babel/helper-create-class-features-plugin@^7.22.5", "@babel/helper-create-class-features-plugin@^7.5.5": version "7.22.10" resolved "https://registry.yarnpkg.com/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.22.10.tgz#dd2612d59eac45588021ac3d6fa976d08f4e95a3" integrity sha512-5IBb77txKYQPpOEdUdIhBx8VrZyDCQ+H82H0+5dX1TmuscP5vJKEE3cKurjtIw/vFwzbVH48VweE78kVDBrqjA== @@ -123,18 +108,6 @@ regexpu-core "^5.3.1" semver "^6.3.0" -"@babel/helper-define-polyfill-provider@^0.4.0": - version "0.4.0" - resolved "https://registry.yarnpkg.com/@babel/helper-define-polyfill-provider/-/helper-define-polyfill-provider-0.4.0.tgz#487053f103110f25b9755c5980e031e93ced24d8" - integrity sha512-RnanLx5ETe6aybRi1cO/edaRH+bNYWaryCEmjDDYyNr4wnSzyOp8T0dWipmqVHKEY3AbVKUom50AKSlj1zmKbg== - dependencies: - "@babel/helper-compilation-targets" "^7.17.7" - "@babel/helper-plugin-utils" "^7.16.7" - debug "^4.1.1" - lodash.debounce "^4.0.8" - resolve "^1.14.2" - semver "^6.1.2" - "@babel/helper-define-polyfill-provider@^0.4.2": version "0.4.2" resolved "https://registry.yarnpkg.com/@babel/helper-define-polyfill-provider/-/helper-define-polyfill-provider-0.4.2.tgz#82c825cadeeeee7aad237618ebbe8fa1710015d7" @@ -198,22 +171,12 @@ dependencies: "@babel/types" "^7.22.5" -"@babel/helper-plugin-utils@^7.0.0", "@babel/helper-plugin-utils@^7.10.4", "@babel/helper-plugin-utils@^7.12.13", "@babel/helper-plugin-utils@^7.14.5", "@babel/helper-plugin-utils@^7.16.7", "@babel/helper-plugin-utils@^7.18.6", "@babel/helper-plugin-utils@^7.20.2", "@babel/helper-plugin-utils@^7.22.5", "@babel/helper-plugin-utils@^7.8.0", "@babel/helper-plugin-utils@^7.8.3": +"@babel/helper-plugin-utils@^7.0.0", "@babel/helper-plugin-utils@^7.10.4", "@babel/helper-plugin-utils@^7.12.13", "@babel/helper-plugin-utils@^7.14.5", "@babel/helper-plugin-utils@^7.18.6", "@babel/helper-plugin-utils@^7.20.2", "@babel/helper-plugin-utils@^7.22.5", "@babel/helper-plugin-utils@^7.8.0", "@babel/helper-plugin-utils@^7.8.3": version "7.22.5" resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.22.5.tgz#dd7ee3735e8a313b9f7b05a773d892e88e6d7295" integrity sha512-uLls06UVKgFG9QD4OeFYLEGteMIAa5kpTPcFL28yuCIIzsf6ZyKZMllKVOCZFhiZ5ptnwX4mtKdWCBE/uT4amg== -"@babel/helper-remap-async-to-generator@^7.22.5": - version "7.22.5" - resolved "https://registry.yarnpkg.com/@babel/helper-remap-async-to-generator/-/helper-remap-async-to-generator-7.22.5.tgz#14a38141a7bf2165ad38da61d61cf27b43015da2" - integrity sha512-cU0Sq1Rf4Z55fgz7haOakIyM7+x/uCFwXpLPaeRzfoUtAEAuUZjZvFPjL/rk5rW693dIgn2hng1W7xbT7lWT4g== - dependencies: - "@babel/helper-annotate-as-pure" "^7.22.5" - "@babel/helper-environment-visitor" "^7.22.5" - "@babel/helper-wrap-function" "^7.22.5" - "@babel/types" "^7.22.5" - -"@babel/helper-remap-async-to-generator@^7.22.9": +"@babel/helper-remap-async-to-generator@^7.22.5", "@babel/helper-remap-async-to-generator@^7.22.9": version "7.22.9" resolved "https://registry.yarnpkg.com/@babel/helper-remap-async-to-generator/-/helper-remap-async-to-generator-7.22.9.tgz#53a25b7484e722d7efb9c350c75c032d4628de82" integrity sha512-8WWC4oR4Px+tr+Fp0X3RHDVfINGpF3ad1HIbrc8A77epiR6eMMc6jsgozkzT2uDiOOdoS9cLIQ+XD2XvI2WSmQ== @@ -222,19 +185,7 @@ "@babel/helper-environment-visitor" "^7.22.5" "@babel/helper-wrap-function" "^7.22.9" -"@babel/helper-replace-supers@^7.22.5": - version "7.22.5" - resolved "https://registry.yarnpkg.com/@babel/helper-replace-supers/-/helper-replace-supers-7.22.5.tgz#71bc5fb348856dea9fdc4eafd7e2e49f585145dc" - integrity sha512-aLdNM5I3kdI/V9xGNyKSF3X/gTyMUBohTZ+/3QdQKAA9vxIiy12E+8E2HoOP1/DjeqU+g6as35QHJNMDDYpuCg== - dependencies: - "@babel/helper-environment-visitor" "^7.22.5" - "@babel/helper-member-expression-to-functions" "^7.22.5" - "@babel/helper-optimise-call-expression" "^7.22.5" - "@babel/template" "^7.22.5" - "@babel/traverse" "^7.22.5" - "@babel/types" "^7.22.5" - -"@babel/helper-replace-supers@^7.22.9": +"@babel/helper-replace-supers@^7.22.5", "@babel/helper-replace-supers@^7.22.9": version "7.22.9" resolved "https://registry.yarnpkg.com/@babel/helper-replace-supers/-/helper-replace-supers-7.22.9.tgz#cbdc27d6d8d18cd22c81ae4293765a5d9afd0779" integrity sha512-LJIKvvpgPOPUThdYqcX6IXRuIcTkcAub0IaDRGCZH0p5GPUp7PhRU9QVgFcDDd51BaPkk77ZjqFwh6DZTAEmGg== @@ -257,7 +208,7 @@ dependencies: "@babel/types" "^7.22.5" -"@babel/helper-split-export-declaration@^7.22.5", "@babel/helper-split-export-declaration@^7.22.6": +"@babel/helper-split-export-declaration@^7.22.6": version "7.22.6" resolved "https://registry.yarnpkg.com/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.22.6.tgz#322c61b7310c0997fe4c323955667f18fcefb91c" integrity sha512-AsUnxuLhRYsisFiaJwvp1QF+I3KjD5FOxut14q/GzovUe6orHLesW2C7d754kRm53h5gqrz6sFl6sxc4BVtE/g== @@ -279,16 +230,6 @@ resolved "https://registry.yarnpkg.com/@babel/helper-validator-option/-/helper-validator-option-7.22.5.tgz#de52000a15a177413c8234fa3a8af4ee8102d0ac" integrity sha512-R3oB6xlIVKUnxNUxbmgq7pKjxpru24zlimpE8WK47fACIlM0II/Hm1RS8IaOI7NgCr6LNS+jl5l75m20npAziw== -"@babel/helper-wrap-function@^7.22.5": - version "7.22.5" - resolved "https://registry.yarnpkg.com/@babel/helper-wrap-function/-/helper-wrap-function-7.22.5.tgz#44d205af19ed8d872b4eefb0d2fa65f45eb34f06" - integrity sha512-bYqLIBSEshYcYQyfks8ewYA8S30yaGSeRslcvKMvoUk6HHPySbxHq9YRi6ghhzEU+yhQv9bP/jXnygkStOcqZw== - dependencies: - "@babel/helper-function-name" "^7.22.5" - "@babel/template" "^7.22.5" - "@babel/traverse" "^7.22.5" - "@babel/types" "^7.22.5" - "@babel/helper-wrap-function@^7.22.9": version "7.22.10" resolved "https://registry.yarnpkg.com/@babel/helper-wrap-function/-/helper-wrap-function-7.22.10.tgz#d845e043880ed0b8c18bd194a12005cb16d2f614" @@ -400,14 +341,7 @@ dependencies: "@babel/helper-plugin-utils" "^7.14.5" -"@babel/plugin-syntax-decorators@^7.16.7": - version "7.22.5" - resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-decorators/-/plugin-syntax-decorators-7.22.5.tgz#329fe2907c73de184033775637dbbc507f09116a" - integrity sha512-avpUOBS7IU6al8MmF1XpAyj9QYeLPuSDJI5D4pVMSMdL7xQokKqJPYQC67RCT0aCTashUXPiGwMJ0DEXXCEmMA== - dependencies: - "@babel/helper-plugin-utils" "^7.22.5" - -"@babel/plugin-syntax-decorators@^7.22.10": +"@babel/plugin-syntax-decorators@^7.16.7", "@babel/plugin-syntax-decorators@^7.22.10": version "7.22.10" resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-decorators/-/plugin-syntax-decorators-7.22.10.tgz#7d83ea04d893c442b78ebf4c3cbac59a7211deff" integrity sha512-z1KTVemBjnz+kSEilAsI4lbkPOl5TvJH7YDSY1CTIzvLWJ+KHXp+mRe8VPmfnyvqOPqar1V2gid2PleKzRUstQ== @@ -560,20 +494,13 @@ dependencies: "@babel/helper-plugin-utils" "^7.22.5" -"@babel/plugin-transform-block-scoping@^7.22.10": +"@babel/plugin-transform-block-scoping@^7.22.10", "@babel/plugin-transform-block-scoping@^7.8.3": version "7.22.10" resolved "https://registry.yarnpkg.com/@babel/plugin-transform-block-scoping/-/plugin-transform-block-scoping-7.22.10.tgz#88a1dccc3383899eb5e660534a76a22ecee64faa" integrity sha512-1+kVpGAOOI1Albt6Vse7c8pHzcZQdQKW+wJH+g8mCaszOdDVwRXa/slHPqIw+oJAJANTKDMuM2cBdV0Dg618Vg== dependencies: "@babel/helper-plugin-utils" "^7.22.5" -"@babel/plugin-transform-block-scoping@^7.8.3": - version "7.22.5" - resolved "https://registry.yarnpkg.com/@babel/plugin-transform-block-scoping/-/plugin-transform-block-scoping-7.22.5.tgz#8bfc793b3a4b2742c0983fadc1480d843ecea31b" - integrity sha512-EcACl1i5fSQ6bt+YGuU/XGCeZKStLmyVGytWkpyhCLeQVA0eu6Wtiw92V+I1T/hnezUv7j74dA/Ro69gWcU+hg== - dependencies: - "@babel/helper-plugin-utils" "^7.22.5" - "@babel/plugin-transform-class-properties@^7.22.5": version "7.22.5" resolved "https://registry.yarnpkg.com/@babel/plugin-transform-class-properties/-/plugin-transform-class-properties-7.22.5.tgz#97a56e31ad8c9dc06a0b3710ce7803d5a48cca77" @@ -806,7 +733,7 @@ "@babel/helper-plugin-utils" "^7.22.5" "@babel/plugin-syntax-optional-catch-binding" "^7.8.3" -"@babel/plugin-transform-optional-chaining@^7.22.10": +"@babel/plugin-transform-optional-chaining@^7.22.10", "@babel/plugin-transform-optional-chaining@^7.22.5": version "7.22.10" resolved "https://registry.yarnpkg.com/@babel/plugin-transform-optional-chaining/-/plugin-transform-optional-chaining-7.22.10.tgz#076d28a7e074392e840d4ae587d83445bac0372a" integrity sha512-MMkQqZAZ+MGj+jGTG3OTuhKeBpNcO+0oCEbrGNEaOmiEn+1MzRyQlYsruGiU8RTK3zV6XwrVJTmwiDOyYK6J9g== @@ -815,15 +742,6 @@ "@babel/helper-skip-transparent-expression-wrappers" "^7.22.5" "@babel/plugin-syntax-optional-chaining" "^7.8.3" -"@babel/plugin-transform-optional-chaining@^7.22.5": - version "7.22.5" - resolved "https://registry.yarnpkg.com/@babel/plugin-transform-optional-chaining/-/plugin-transform-optional-chaining-7.22.5.tgz#1003762b9c14295501beb41be72426736bedd1e0" - integrity sha512-AconbMKOMkyG+xCng2JogMCDcqW8wedQAqpVIL4cOSescZ7+iW8utC6YDZLMCSUIReEA733gzRSaOSXMAt/4WQ== - dependencies: - "@babel/helper-plugin-utils" "^7.22.5" - "@babel/helper-skip-transparent-expression-wrappers" "^7.22.5" - "@babel/plugin-syntax-optional-chaining" "^7.8.3" - "@babel/plugin-transform-parameters@^7.22.5": version "7.22.5" resolved "https://registry.yarnpkg.com/@babel/plugin-transform-parameters/-/plugin-transform-parameters-7.22.5.tgz#c3542dd3c39b42c8069936e48717a8d179d63a18" @@ -1113,7 +1031,7 @@ "@babel/parser" "^7.22.5" "@babel/types" "^7.22.5" -"@babel/traverse@^7.22.10", "@babel/traverse@^7.22.5", "@babel/traverse@^7.4.5": +"@babel/traverse@^7.22.10", "@babel/traverse@^7.4.5": version "7.22.10" resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.22.10.tgz#20252acb240e746d27c2e82b4484f199cf8141aa" integrity sha512-Q/urqV4pRByiNNpb/f5OSv28ZlGJiFiiTh+GAHktbIrkPhPbl90+uW6SmpoLyZqutrg9AEaEf3Q/ZBRHBXgxig== @@ -2328,7 +2246,7 @@ babel-import-util@^0.2.0: resolved "https://registry.yarnpkg.com/babel-import-util/-/babel-import-util-0.2.0.tgz#b468bb679919601a3570f9e317536c54f2862e23" integrity sha512-CtWYYHU/MgK88rxMrLfkD356dApswtR/kWZ/c6JifG1m10e7tBBrs/366dFzWMAoqYmG5/JSh+94tUSpIwh+ag== -babel-import-util@^1.2.2, babel-import-util@^1.3.0, babel-import-util@^1.4.1: +babel-import-util@^1.2.2, babel-import-util@^1.4.1: version "1.4.1" resolved "https://registry.yarnpkg.com/babel-import-util/-/babel-import-util-1.4.1.tgz#1df6fd679845df45494bac9ca12461d49497fdd4" integrity sha512-TNdiTQdPhXlx02pzG//UyVPSKE7SNWjY0n4So/ZnjQpWwaM5LvWBLkWa1JKll5u06HNscHD91XZPuwrMg1kadQ== @@ -2369,12 +2287,13 @@ babel-plugin-ember-modules-api-polyfill@^3.5.0: dependencies: ember-rfc176-data "^0.3.17" -babel-plugin-ember-template-compilation@2.0.0, babel-plugin-ember-template-compilation@^2.0.0, babel-plugin-ember-template-compilation@^2.0.1: - version "2.0.0" - resolved "https://registry.yarnpkg.com/babel-plugin-ember-template-compilation/-/babel-plugin-ember-template-compilation-2.0.0.tgz#41d895874ba6119dd461f61993c16d1154bf8a57" - integrity sha512-d+4jaB2ik0rt9TH0K9kOlKJeRBHEb373FgFMcU9ZaJL2zYuVXe19bqy+cWlLpLf1tpOBcBG9QTlFBCoImlOt1g== +babel-plugin-ember-template-compilation@^2.0.0, babel-plugin-ember-template-compilation@^2.0.1, babel-plugin-ember-template-compilation@^2.2.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/babel-plugin-ember-template-compilation/-/babel-plugin-ember-template-compilation-2.2.0.tgz#b119fadcd5c831299fbd706420d2ea742848a659" + integrity sha512-1I7f5gf06h5wKdKUvaYEIaoSFur5RLUvTMQG4ak0c5Y11DWUxcoX9hrun1xe9fqfY2dtGFK+ZUM6sn6z8sqK/w== dependencies: - babel-import-util "^1.3.0" + "@glimmer/syntax" "^0.84.3" + babel-import-util "^2.0.0" babel-plugin-filter-imports@^4.0.0: version "4.0.0" @@ -2417,16 +2336,7 @@ babel-plugin-module-resolver@^5.0.0: reselect "^4.1.7" resolve "^1.22.1" -babel-plugin-polyfill-corejs2@^0.4.3: - version "0.4.3" - resolved "https://registry.yarnpkg.com/babel-plugin-polyfill-corejs2/-/babel-plugin-polyfill-corejs2-0.4.3.tgz#75044d90ba5043a5fb559ac98496f62f3eb668fd" - integrity sha512-bM3gHc337Dta490gg+/AseNB9L4YLHxq1nGKZZSHbhXv4aTYU2MD2cjza1Ru4S6975YLTaL1K8uJf6ukJhhmtw== - dependencies: - "@babel/compat-data" "^7.17.7" - "@babel/helper-define-polyfill-provider" "^0.4.0" - semver "^6.1.1" - -babel-plugin-polyfill-corejs2@^0.4.5: +babel-plugin-polyfill-corejs2@^0.4.3, babel-plugin-polyfill-corejs2@^0.4.5: version "0.4.5" resolved "https://registry.yarnpkg.com/babel-plugin-polyfill-corejs2/-/babel-plugin-polyfill-corejs2-0.4.5.tgz#8097b4cb4af5b64a1d11332b6fb72ef5e64a054c" integrity sha512-19hwUH5FKl49JEsvyTcoHakh6BE0wgXLLptIyKZ3PijHc/Ci521wygORCUCCred+E/twuqRyAkE02BAWPmsHOg== @@ -2435,15 +2345,7 @@ babel-plugin-polyfill-corejs2@^0.4.5: "@babel/helper-define-polyfill-provider" "^0.4.2" semver "^6.3.1" -babel-plugin-polyfill-corejs3@^0.8.1: - version "0.8.1" - resolved "https://registry.yarnpkg.com/babel-plugin-polyfill-corejs3/-/babel-plugin-polyfill-corejs3-0.8.1.tgz#39248263c38191f0d226f928d666e6db1b4b3a8a" - integrity sha512-ikFrZITKg1xH6pLND8zT14UPgjKHiGLqex7rGEZCH2EvhsneJaJPemmpQaIZV5AL03II+lXylw3UmddDK8RU5Q== - dependencies: - "@babel/helper-define-polyfill-provider" "^0.4.0" - core-js-compat "^3.30.1" - -babel-plugin-polyfill-corejs3@^0.8.3: +babel-plugin-polyfill-corejs3@^0.8.1, babel-plugin-polyfill-corejs3@^0.8.3: version "0.8.3" resolved "https://registry.yarnpkg.com/babel-plugin-polyfill-corejs3/-/babel-plugin-polyfill-corejs3-0.8.3.tgz#b4f719d0ad9bb8e0c23e3e630c0c8ec6dd7a1c52" integrity sha512-z41XaniZL26WLrvjy7soabMXrfPWARN25PZoriDEiLMxAp50AUW3t35BGQUMg5xK3UrpVTtagIDklxYa+MhiNA== @@ -2451,14 +2353,7 @@ babel-plugin-polyfill-corejs3@^0.8.3: "@babel/helper-define-polyfill-provider" "^0.4.2" core-js-compat "^3.31.0" -babel-plugin-polyfill-regenerator@^0.5.0: - version "0.5.0" - resolved "https://registry.yarnpkg.com/babel-plugin-polyfill-regenerator/-/babel-plugin-polyfill-regenerator-0.5.0.tgz#e7344d88d9ef18a3c47ded99362ae4a757609380" - integrity sha512-hDJtKjMLVa7Z+LwnTCxoDLQj6wdc+B8dun7ayF2fYieI6OzfuvcLMB32ihJZ4UhCBwNYGl5bg/x/P9cMdnkc2g== - dependencies: - "@babel/helper-define-polyfill-provider" "^0.4.0" - -babel-plugin-polyfill-regenerator@^0.5.2: +babel-plugin-polyfill-regenerator@^0.5.0, babel-plugin-polyfill-regenerator@^0.5.2: version "0.5.2" resolved "https://registry.yarnpkg.com/babel-plugin-polyfill-regenerator/-/babel-plugin-polyfill-regenerator-0.5.2.tgz#80d0f3e1098c080c8b5a65f41e9427af692dc326" integrity sha512-tAlOptU0Xj34V1Y2PNTL4Y0FOJMDB6bZmoW39FeCQIhigGLkqu3Fj6uiXpxIf6Ij274ENdYx64y6Au+ZKlb1IA== @@ -3077,17 +2972,7 @@ browser-split@0.0.1: resolved "https://registry.yarnpkg.com/browser-split/-/browser-split-0.0.1.tgz#7b097574f8e3ead606fb4664e64adfdda2981a93" integrity sha512-JhvgRb2ihQhsljNda3BI8/UcRHVzrVwo3Q+P8vDtSiyobXuFpuZ9mq+MbRGMnC22CjW3RrfXdg6j6ITX8M+7Ow== -browserslist@^4.14.5, browserslist@^4.21.5, browserslist@^4.21.9: - version "4.21.9" - resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.21.9.tgz#e11bdd3c313d7e2a9e87e8b4b0c7872b13897635" - integrity sha512-M0MFoZzbUrRU4KNfCrDLnvyE7gub+peetoTid3TBIqtunaDJyXlwhakT+/VkvSXcfIzFfK/nkCs4nmyTmxdNSg== - dependencies: - caniuse-lite "^1.0.30001503" - electron-to-chromium "^1.4.431" - node-releases "^2.0.12" - update-browserslist-db "^1.0.11" - -browserslist@^4.21.10: +browserslist@^4.14.5, browserslist@^4.21.10, browserslist@^4.21.9: version "4.21.10" resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.21.10.tgz#dbbac576628c13d3b2231332cb2ec5a46e015bb0" integrity sha512-bipEBdZfVH5/pwrvqc+Ub0kUPVfGUhlKxbvfD+z1BDnPEO/X98ruXGA1WP5ASpAFKan7Qr6j736IacbZQuAlKQ== @@ -3186,11 +3071,6 @@ can-symlink@^1.0.0: dependencies: tmp "0.0.28" -caniuse-lite@^1.0.30001503: - version "1.0.30001509" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001509.tgz#2b7ad5265392d6d2de25cd8776d1ab3899570d14" - integrity sha512-2uDDk+TRiTX5hMcUYT/7CSyzMZxjfGu0vAUjS2g0LSD8UoXOv0LtpH4LxGMemsiPq6LCVIUjNwVM0erkOkGCDA== - caniuse-lite@^1.0.30001517: version "1.0.30001522" resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001522.tgz#44b87a406c901269adcdb834713e23582dd71856" @@ -3556,13 +3436,6 @@ copy-descriptor@^0.1.0: resolved "https://registry.yarnpkg.com/copy-descriptor/-/copy-descriptor-0.1.1.tgz#676f6eb3c39997c2ee1ac3a924fd6124748f578d" integrity sha512-XgZ0pFcakEUlbwQEVNg3+QAis1FyTL3Qel9FYy8pSkQqoG3PNoT0bOCQtOXcOkur21r2Eq2kI+IE+gsmAEVlYw== -core-js-compat@^3.30.1: - version "3.31.0" - resolved "https://registry.yarnpkg.com/core-js-compat/-/core-js-compat-3.31.0.tgz#4030847c0766cc0e803dcdfb30055d7ef2064bf1" - integrity sha512-hM7YCu1cU6Opx7MXNu0NuumM0ezNeAeRKadixyiQELWY3vT3De9S4J5ZBMraWV2vZnrE1Cirl0GtFtDtMUXzPw== - dependencies: - browserslist "^4.21.5" - core-js-compat@^3.31.0: version "3.32.1" resolved "https://registry.yarnpkg.com/core-js-compat/-/core-js-compat-3.32.1.tgz#55f9a7d297c0761a8eb1d31b593e0f5b6ffae964" @@ -3846,11 +3719,6 @@ ee-first@1.1.1: resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d" integrity sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow== -electron-to-chromium@^1.4.431: - version "1.4.445" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.445.tgz#058d2c5f3a2981ab1a37440f5a5e42d15672aa6d" - integrity sha512-++DB+9VK8SBJwC+X1zlMfJ1tMA3F0ipi39GdEp+x3cV2TyBihqAgad8cNMWtLDEkbH39nlDQP7PfGrDr3Dr7HA== - electron-to-chromium@^1.4.477: version "1.4.496" resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.496.tgz#a57534b70d2bdee7e1ad7dbd4c91e560cbd08db1" @@ -7532,11 +7400,6 @@ node-notifier@^10.0.0: uuid "^8.3.2" which "^2.0.2" -node-releases@^2.0.12: - version "2.0.12" - resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.12.tgz#35627cc224a23bfb06fb3380f2b3afaaa7eb1039" - integrity sha512-QzsYKWhXTWx8h1kIvqfnC++o0pEmpRQA/aenALsL2F4pqNVr7YzcdMlDij5WBnwftRbJCNJL/O7zdKaxKPHqgQ== - node-releases@^2.0.13: version "2.0.13" resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.13.tgz#d5ed1627c23e3461e819b02e57b75e4899b1c81d" @@ -8691,7 +8554,7 @@ semver@^5.3.0, semver@^5.4.1, semver@^5.5.0, semver@^5.6.0: resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.2.tgz#48d55db737c3287cd4835e17fa13feace1c41ef8" integrity sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g== -semver@^6.0.0, semver@^6.1.1, semver@^6.1.2, semver@^6.3.0, semver@^6.3.1: +semver@^6.0.0, semver@^6.3.0, semver@^6.3.1: version "6.3.1" resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.1.tgz#556d2ef8689146e46dcea4bfdd095f3434dffcb4" integrity sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA== @@ -10048,12 +9911,7 @@ workerpool@^3.1.1: object-assign "4.1.1" rsvp "^4.8.4" -workerpool@^6.0.0, workerpool@^6.4.0: - version "6.4.0" - resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.4.0.tgz#f8d5cfb45fde32fa3b7af72ad617c3369567a462" - integrity sha512-i3KR1mQMNwY2wx20ozq2EjISGtQWDIfV56We+yGJ5yDs8jTwQiLLaqHlkBHITlCuJnYlVRmXegxFxZg7gqI++A== - -workerpool@^6.0.2: +workerpool@^6.0.0, workerpool@^6.0.2, workerpool@^6.4.0: version "6.4.1" resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.4.1.tgz#1398eb5f8f44fb2d21ed9225cf34bb0131504c1d" integrity sha512-zIK7qRgM1Mk+ySxOJl7ZpjX6SlKt5gugxzl8eXHPdbpXX8iDAaVIxYJz4Apn6JdDxP2buY/Ekqg0bOLNSf0u0g== diff --git a/app/models/theme.rb b/app/models/theme.rb index ca78a433d77..347a3a609fb 100644 --- a/app/models/theme.rb +++ b/app/models/theme.rb @@ -6,7 +6,7 @@ require "json_schemer" class Theme < ActiveRecord::Base include GlobalPath - BASE_COMPILER_VERSION = 73 + BASE_COMPILER_VERSION = 74 attr_accessor :child_components diff --git a/lib/discourse_js_processor.rb b/lib/discourse_js_processor.rb index d9c16de74f9..cb1eee6c9d1 100644 --- a/lib/discourse_js_processor.rb +++ b/lib/discourse_js_processor.rb @@ -6,6 +6,9 @@ class DiscourseJsProcessor class TranspileError < StandardError end + JS_PROCESSOR_PATH = + Rails.env.production? ? "tmp/js-processor.js" : "tmp/js-processor/#{Process.pid}.js" + # To generate a list of babel plugins used by ember-cli, set # babel: { debug: true } in ember-cli-build.js, then run `yarn ember build -prod` DISCOURSE_COMMON_BABEL_PLUGINS = [ @@ -100,19 +103,24 @@ class DiscourseJsProcessor class Transpiler @mutex = Mutex.new @ctx_init = Mutex.new + @processor_mutex = Mutex.new def self.mutex @mutex end - def self.load_file_in_context(ctx, path, wrap_in_module: nil) - contents = File.read("#{Rails.root}/app/assets/javascripts/#{path}") - contents = <<~JS if wrap_in_module - define(#{wrap_in_module.to_json}, ["exports", "require", "module"], function(exports, require, module){ - #{contents} - }); - JS - ctx.eval(contents, filename: path) + def self.generate_js_processor + Discourse::Utils.execute_command( + "yarn", + "--silent", + "esbuild", + "--log-level=warning", + "--bundle", + "--external:fs", + "--define:process='{\"env\":{}}'", + "app/assets/javascripts/js-processor.js", + "--outfile=#{JS_PROCESSOR_PATH}", + ) end def self.create_new_context @@ -123,120 +131,13 @@ class DiscourseJsProcessor ctx.attach("rails.logger.info", proc { |err| Rails.logger.info(err.to_s) }) ctx.attach("rails.logger.warn", proc { |err| Rails.logger.warn(err.to_s) }) ctx.attach("rails.logger.error", proc { |err| Rails.logger.error(err.to_s) }) - ctx.eval(<<~JS, filename: "environment-setup.js") - window = {}; - console = { - prefix: "[DiscourseJsProcessor] ", - log: function(...args){ rails.logger.info(console.prefix + args.join(" ")); }, - warn: function(...args){ rails.logger.warn(console.prefix + args.join(" ")); }, - error: function(...args){ rails.logger.error(console.prefix + args.join(" ")); } - }; - JS - - # define/require support - load_file_in_context(ctx, "node_modules/loader.js/dist/loader/loader.js") - - # Babel - load_file_in_context(ctx, "node_modules/@babel/standalone/babel.js") - ctx.eval <<~JS - globalThis.rawBabelTransform = function(){ - return Babel.transform(...arguments).code; - } - JS - - # Terser - load_file_in_context(ctx, "node_modules/source-map/dist/source-map.js") - load_file_in_context(ctx, "node_modules/terser/dist/bundle.min.js") - - # Template Compiler - load_file_in_context(ctx, "node_modules/ember-source/dist/ember-template-compiler.js") - load_file_in_context( - ctx, - "node_modules/babel-plugin-ember-template-compilation/src/plugin.js", - wrap_in_module: "babel-plugin-ember-template-compilation/index", - ) - load_file_in_context( - ctx, - "node_modules/babel-plugin-ember-template-compilation/src/expression-parser.js", - wrap_in_module: "babel-plugin-ember-template-compilation/expression-parser", - ) - load_file_in_context( - ctx, - "node_modules/babel-plugin-ember-template-compilation/src/js-utils.js", - wrap_in_module: "babel-plugin-ember-template-compilation/js-utils", - ) - load_file_in_context( - ctx, - "node_modules/babel-plugin-ember-template-compilation/src/public-types.js", - wrap_in_module: "babel-plugin-ember-template-compilation/public-types", - ) - load_file_in_context( - ctx, - "node_modules/babel-import-util/src/index.js", - wrap_in_module: "babel-import-util", - ) - load_file_in_context( - ctx, - "node_modules/ember-cli-htmlbars/lib/colocated-babel-plugin.js", - wrap_in_module: "colocated-babel-plugin", - ) - - # Widget HBS compiler - widget_hbs_compiler_source = - File.read( - "#{Rails.root}/app/assets/javascripts/discourse-widget-hbs/lib/widget-hbs-compiler.js", - ) - widget_hbs_compiler_source = <<~JS - define("widget-hbs-compiler", ["exports"], function(exports){ - #{widget_hbs_compiler_source} - }); - JS - widget_hbs_compiler_transpiled = - ctx.call( - "rawBabelTransform", - widget_hbs_compiler_source, - { ast: false, moduleId: "widget-hbs-compiler", plugins: DISCOURSE_COMMON_BABEL_PLUGINS }, - ) - ctx.eval(widget_hbs_compiler_transpiled, filename: "widget-hbs-compiler.js") - - # Raw HBS compiler - load_file_in_context( - ctx, - "node_modules/handlebars/dist/handlebars.js", - wrap_in_module: "handlebars", - ) - - raw_hbs_transpiled = - ctx.call( - "rawBabelTransform", - File.read( - "#{Rails.root}/app/assets/javascripts/discourse-common/addon/lib/raw-handlebars.js", - ), - { - ast: false, - moduleId: "raw-handlebars", - plugins: [ - ["transform-modules-amd", { noInterop: true }], - *DISCOURSE_COMMON_BABEL_PLUGINS, - ], - }, - ) - ctx.eval(raw_hbs_transpiled, filename: "raw-handlebars.js") # Theme template AST transformation plugins - load_file_in_context( - ctx, - "discourse-js-processor.js", - wrap_in_module: "discourse-js-processor", - ) + if Rails.env.development? || Rails.env.test? + @processor_mutex.synchronize { generate_js_processor } + end - # Make interfaces available via `v8.call` - ctx.eval <<~JS - globalThis.compileRawTemplate = require('discourse-js-processor').compileRawTemplate; - globalThis.transpile = require('discourse-js-processor').transpile; - globalThis.minify = require('discourse-js-processor').minify; - globalThis.getMinifyResult = require('discourse-js-processor').getMinifyResult; - JS + ctx.eval(File.read(JS_PROCESSOR_PATH), filename: "js-processor.js") ctx end diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake index 8c7f852cb00..30798c9003e 100644 --- a/lib/tasks/assets.rake +++ b/lib/tasks/assets.rake @@ -1,6 +1,6 @@ # frozen_string_literal: true -task "assets:precompile:before" do +task "assets:precompile:before": "environment" do require "uglifier" require "open3" @@ -59,6 +59,18 @@ task "assets:precompile:before" do end task "assets:precompile:css" => "environment" do + class Sprockets::Manifest + def reload + @filename = find_directory_manifest(@directory) + @data = json_decode(File.read(@filename)) + end + end + + # cause on boot we loaded a blank manifest, + # we need to know where all the assets are to precompile CSS + # cause CSS uses asset_path + Rails.application.assets_manifest.reload + if ENV["DONT_PRECOMPILE_CSS"] == "1" STDERR.puts "Skipping CSS precompilation, ensure CSS lives in a shared directory across hosts" else @@ -226,7 +238,7 @@ def log_task_duration(task_description, &task) STDERR.puts end -task "assets:precompile" => %w[assets:precompile:before maxminddb:refresh] do +task "assets:precompile:compress_js": "environment" do if $bypass_sprockets_uglify puts "Compressing Javascript and Generating Source Maps" manifest = Sprockets::Manifest.new(assets_path) @@ -288,17 +300,19 @@ task "assets:precompile" => %w[assets:precompile:before maxminddb:refresh] do end end -Rake::Task["assets:precompile"].enhance do - class Sprockets::Manifest - def reload - @filename = find_directory_manifest(@directory) - @data = json_decode(File.read(@filename)) - end - end +task "assets:precompile:js_processor": "environment" do + DiscourseJsProcessor::Transpiler.generate_js_processor +end - # cause on boot we loaded a blank manifest, - # we need to know where all the assets are to precompile CSS - # cause CSS uses asset_path - Rails.application.assets_manifest.reload +# Run these tasks **before** Rails' "assets:precompile" task +task "assets:precompile": %w[ + assets:precompile:before + maxminddb:refresh + assets:precompile:js_processor + ] + +# Run these tasks **after** Rails' "assets:precompile" task +Rake::Task["assets:precompile"].enhance do + Rake::Task["assets:precompile:compress_js"].invoke Rake::Task["assets:precompile:css"].invoke end diff --git a/package.json b/package.json index 6132a46a39f..4896228d156 100644 --- a/package.json +++ b/package.json @@ -5,12 +5,12 @@ "author": "Discourse", "license": "GPL-2.0-only", "devDependencies": { + "@discourse/moment-timezone-names-translations": "^1.0.0", + "@fortawesome/fontawesome-free": "5.15.4", "@glint/core": "^1.0.2", "@glint/environment-ember-loose": "^1.0.2", "@glint/environment-ember-template-imports": "^1.0.2", "@glint/template": "^1.0.2", - "@discourse/moment-timezone-names-translations": "^1.0.0", - "@fortawesome/fontawesome-free": "5.15.4", "@highlightjs/cdn-assets": "11.8.0", "@json-editor/json-editor": "2.10.0", "@mixer/parallel-prettier": "^2.0.3", @@ -22,6 +22,7 @@ "concurrently": "^8.0.1", "diffhtml": "1.0.0-beta.20", "ember-template-lint": "5.10.3", + "esbuild": "^0.19.2", "eslint": "^8.37.0", "eslint-config-discourse": "^3.6.0", "eslint-plugin-ember": "11.8.0", @@ -34,8 +35,8 @@ "magnific-popup": "1.1.0", "moment": "2.29.4", "moment-timezone": "0.5.43", - "prettier-plugin-ember-template-tag": "^0.3.2", "pikaday": "1.8.2", + "prettier-plugin-ember-template-tag": "^0.3.2", "puppeteer-core": "^21.0.3", "squoosh": "discourse/squoosh#dc9649d", "tidy-jsdoc": "^1.4.1", diff --git a/spec/lib/discourse_js_processor_spec.rb b/spec/lib/discourse_js_processor_spec.rb index 24fd32d735b..3928d1f92d3 100644 --- a/spec/lib/discourse_js_processor_spec.rb +++ b/spec/lib/discourse_js_processor_spec.rb @@ -155,7 +155,7 @@ RSpec.describe DiscourseJsProcessor do Handlebars.registerHelper('dummy-helper', function(string) { return `dummy(${string})` }) - JS + JS let(:mini_racer) do ctx = MiniRacer::Context.new diff --git a/yarn.lock b/yarn.lock index 8ed923a49b7..ed4b9e675d8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -435,6 +435,116 @@ resolved "https://registry.yarnpkg.com/@ember/edition-utils/-/edition-utils-1.2.0.tgz#a039f542dc14c8e8299c81cd5abba95e2459cfa6" integrity sha512-VmVq/8saCaPdesQmftPqbFtxJWrzxNGSQ+e8x8LLe3Hjm36pJ04Q8LeORGZkAeOhldoUX9seLGmSaHeXkIqoog== +"@esbuild/android-arm64@0.19.2": + version "0.19.2" + resolved "https://registry.yarnpkg.com/@esbuild/android-arm64/-/android-arm64-0.19.2.tgz#bc35990f412a749e948b792825eef7df0ce0e073" + integrity sha512-lsB65vAbe90I/Qe10OjkmrdxSX4UJDjosDgb8sZUKcg3oefEuW2OT2Vozz8ef7wrJbMcmhvCC+hciF8jY/uAkw== + +"@esbuild/android-arm@0.19.2": + version "0.19.2" + resolved "https://registry.yarnpkg.com/@esbuild/android-arm/-/android-arm-0.19.2.tgz#edd1c8f23ba353c197f5b0337123c58ff2a56999" + integrity sha512-tM8yLeYVe7pRyAu9VMi/Q7aunpLwD139EY1S99xbQkT4/q2qa6eA4ige/WJQYdJ8GBL1K33pPFhPfPdJ/WzT8Q== + +"@esbuild/android-x64@0.19.2": + version "0.19.2" + resolved "https://registry.yarnpkg.com/@esbuild/android-x64/-/android-x64-0.19.2.tgz#2dcdd6e6f1f2d82ea1b746abd8da5b284960f35a" + integrity sha512-qK/TpmHt2M/Hg82WXHRc/W/2SGo/l1thtDHZWqFq7oi24AjZ4O/CpPSu6ZuYKFkEgmZlFoa7CooAyYmuvnaG8w== + +"@esbuild/darwin-arm64@0.19.2": + version "0.19.2" + resolved "https://registry.yarnpkg.com/@esbuild/darwin-arm64/-/darwin-arm64-0.19.2.tgz#55b36bc06d76f5c243987c1f93a11a80d8fc3b26" + integrity sha512-Ora8JokrvrzEPEpZO18ZYXkH4asCdc1DLdcVy8TGf5eWtPO1Ie4WroEJzwI52ZGtpODy3+m0a2yEX9l+KUn0tA== + +"@esbuild/darwin-x64@0.19.2": + version "0.19.2" + resolved "https://registry.yarnpkg.com/@esbuild/darwin-x64/-/darwin-x64-0.19.2.tgz#982524af33a6424a3b5cb44bbd52559623ad719c" + integrity sha512-tP+B5UuIbbFMj2hQaUr6EALlHOIOmlLM2FK7jeFBobPy2ERdohI4Ka6ZFjZ1ZYsrHE/hZimGuU90jusRE0pwDw== + +"@esbuild/freebsd-arm64@0.19.2": + version "0.19.2" + resolved "https://registry.yarnpkg.com/@esbuild/freebsd-arm64/-/freebsd-arm64-0.19.2.tgz#8e478a0856645265fe79eac4b31b52193011ee06" + integrity sha512-YbPY2kc0acfzL1VPVK6EnAlig4f+l8xmq36OZkU0jzBVHcOTyQDhnKQaLzZudNJQyymd9OqQezeaBgkTGdTGeQ== + +"@esbuild/freebsd-x64@0.19.2": + version "0.19.2" + resolved "https://registry.yarnpkg.com/@esbuild/freebsd-x64/-/freebsd-x64-0.19.2.tgz#01b96604f2540db023c73809bb8ae6cd1692d6f3" + integrity sha512-nSO5uZT2clM6hosjWHAsS15hLrwCvIWx+b2e3lZ3MwbYSaXwvfO528OF+dLjas1g3bZonciivI8qKR/Hm7IWGw== + +"@esbuild/linux-arm64@0.19.2": + version "0.19.2" + resolved "https://registry.yarnpkg.com/@esbuild/linux-arm64/-/linux-arm64-0.19.2.tgz#7e5d2c7864c5c83ec789b59c77cd9c20d2594916" + integrity sha512-ig2P7GeG//zWlU0AggA3pV1h5gdix0MA3wgB+NsnBXViwiGgY77fuN9Wr5uoCrs2YzaYfogXgsWZbm+HGr09xg== + +"@esbuild/linux-arm@0.19.2": + version "0.19.2" + resolved "https://registry.yarnpkg.com/@esbuild/linux-arm/-/linux-arm-0.19.2.tgz#c32ae97bc0246664a1cfbdb4a98e7b006d7db8ae" + integrity sha512-Odalh8hICg7SOD7XCj0YLpYCEc+6mkoq63UnExDCiRA2wXEmGlK5JVrW50vZR9Qz4qkvqnHcpH+OFEggO3PgTg== + +"@esbuild/linux-ia32@0.19.2": + version "0.19.2" + resolved "https://registry.yarnpkg.com/@esbuild/linux-ia32/-/linux-ia32-0.19.2.tgz#3fc4f0fa026057fe885e4a180b3956e704f1ceaa" + integrity sha512-mLfp0ziRPOLSTek0Gd9T5B8AtzKAkoZE70fneiiyPlSnUKKI4lp+mGEnQXcQEHLJAcIYDPSyBvsUbKUG2ri/XQ== + +"@esbuild/linux-loong64@0.19.2": + version "0.19.2" + resolved "https://registry.yarnpkg.com/@esbuild/linux-loong64/-/linux-loong64-0.19.2.tgz#633bcaea443f3505fb0ed109ab840c99ad3451a4" + integrity sha512-hn28+JNDTxxCpnYjdDYVMNTR3SKavyLlCHHkufHV91fkewpIyQchS1d8wSbmXhs1fiYDpNww8KTFlJ1dHsxeSw== + +"@esbuild/linux-mips64el@0.19.2": + version "0.19.2" + resolved "https://registry.yarnpkg.com/@esbuild/linux-mips64el/-/linux-mips64el-0.19.2.tgz#e0bff2898c46f52be7d4dbbcca8b887890805823" + integrity sha512-KbXaC0Sejt7vD2fEgPoIKb6nxkfYW9OmFUK9XQE4//PvGIxNIfPk1NmlHmMg6f25x57rpmEFrn1OotASYIAaTg== + +"@esbuild/linux-ppc64@0.19.2": + version "0.19.2" + resolved "https://registry.yarnpkg.com/@esbuild/linux-ppc64/-/linux-ppc64-0.19.2.tgz#d75798da391f54a9674f8c143b9a52d1dbfbfdde" + integrity sha512-dJ0kE8KTqbiHtA3Fc/zn7lCd7pqVr4JcT0JqOnbj4LLzYnp+7h8Qi4yjfq42ZlHfhOCM42rBh0EwHYLL6LEzcw== + +"@esbuild/linux-riscv64@0.19.2": + version "0.19.2" + resolved "https://registry.yarnpkg.com/@esbuild/linux-riscv64/-/linux-riscv64-0.19.2.tgz#012409bd489ed1bb9b775541d4a46c5ded8e6dd8" + integrity sha512-7Z/jKNFufZ/bbu4INqqCN6DDlrmOTmdw6D0gH+6Y7auok2r02Ur661qPuXidPOJ+FSgbEeQnnAGgsVynfLuOEw== + +"@esbuild/linux-s390x@0.19.2": + version "0.19.2" + resolved "https://registry.yarnpkg.com/@esbuild/linux-s390x/-/linux-s390x-0.19.2.tgz#ece3ed75c5a150de8a5c110f02e97d315761626b" + integrity sha512-U+RinR6aXXABFCcAY4gSlv4CL1oOVvSSCdseQmGO66H+XyuQGZIUdhG56SZaDJQcLmrSfRmx5XZOWyCJPRqS7g== + +"@esbuild/linux-x64@0.19.2": + version "0.19.2" + resolved "https://registry.yarnpkg.com/@esbuild/linux-x64/-/linux-x64-0.19.2.tgz#dea187019741602d57aaf189a80abba261fbd2aa" + integrity sha512-oxzHTEv6VPm3XXNaHPyUTTte+3wGv7qVQtqaZCrgstI16gCuhNOtBXLEBkBREP57YTd68P0VgDgG73jSD8bwXQ== + +"@esbuild/netbsd-x64@0.19.2": + version "0.19.2" + resolved "https://registry.yarnpkg.com/@esbuild/netbsd-x64/-/netbsd-x64-0.19.2.tgz#bbfd7cf9ab236a23ee3a41b26f0628c57623d92a" + integrity sha512-WNa5zZk1XpTTwMDompZmvQLHszDDDN7lYjEHCUmAGB83Bgs20EMs7ICD+oKeT6xt4phV4NDdSi/8OfjPbSbZfQ== + +"@esbuild/openbsd-x64@0.19.2": + version "0.19.2" + resolved "https://registry.yarnpkg.com/@esbuild/openbsd-x64/-/openbsd-x64-0.19.2.tgz#fa5c4c6ee52a360618f00053652e2902e1d7b4a7" + integrity sha512-S6kI1aT3S++Dedb7vxIuUOb3oAxqxk2Rh5rOXOTYnzN8JzW1VzBd+IqPiSpgitu45042SYD3HCoEyhLKQcDFDw== + +"@esbuild/sunos-x64@0.19.2": + version "0.19.2" + resolved "https://registry.yarnpkg.com/@esbuild/sunos-x64/-/sunos-x64-0.19.2.tgz#52a2ac8ac6284c02d25df22bb4cfde26fbddd68d" + integrity sha512-VXSSMsmb+Z8LbsQGcBMiM+fYObDNRm8p7tkUDMPG/g4fhFX5DEFmjxIEa3N8Zr96SjsJ1woAhF0DUnS3MF3ARw== + +"@esbuild/win32-arm64@0.19.2": + version "0.19.2" + resolved "https://registry.yarnpkg.com/@esbuild/win32-arm64/-/win32-arm64-0.19.2.tgz#719ed5870855de8537aef8149694a97d03486804" + integrity sha512-5NayUlSAyb5PQYFAU9x3bHdsqB88RC3aM9lKDAz4X1mo/EchMIT1Q+pSeBXNgkfNmRecLXA0O8xP+x8V+g/LKg== + +"@esbuild/win32-ia32@0.19.2": + version "0.19.2" + resolved "https://registry.yarnpkg.com/@esbuild/win32-ia32/-/win32-ia32-0.19.2.tgz#24832223880b0f581962c8660f8fb8797a1e046a" + integrity sha512-47gL/ek1v36iN0wL9L4Q2MFdujR0poLZMJwhO2/N3gA89jgHp4MR8DKCmwYtGNksbfJb9JoTtbkoe6sDhg2QTA== + +"@esbuild/win32-x64@0.19.2": + version "0.19.2" + resolved "https://registry.yarnpkg.com/@esbuild/win32-x64/-/win32-x64-0.19.2.tgz#1205014625790c7ff0e471644a878a65d1e34ab0" + integrity sha512-tcuhV7ncXBqbt/Ybf0IyrMcwVOAPDckMK9rXNHtF17UTK18OKLpg08glminN06pt2WCoALhXdLfSPbVvK/6fxw== + "@eslint-community/eslint-utils@^4.2.0": version "4.4.0" resolved "https://registry.yarnpkg.com/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz#a23514e8fb9af1269d5f7788aa556798d61c6b59" @@ -1784,6 +1894,34 @@ es-to-primitive@^1.2.1: is-date-object "^1.0.1" is-symbol "^1.0.2" +esbuild@^0.19.2: + version "0.19.2" + resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.19.2.tgz#b1541828a89dfb6f840d38538767c6130dca2aac" + integrity sha512-G6hPax8UbFakEj3hWO0Vs52LQ8k3lnBhxZWomUJDxfz3rZTLqF5k/FCzuNdLx2RbpBiQQF9H9onlDDH1lZsnjg== + optionalDependencies: + "@esbuild/android-arm" "0.19.2" + "@esbuild/android-arm64" "0.19.2" + "@esbuild/android-x64" "0.19.2" + "@esbuild/darwin-arm64" "0.19.2" + "@esbuild/darwin-x64" "0.19.2" + "@esbuild/freebsd-arm64" "0.19.2" + "@esbuild/freebsd-x64" "0.19.2" + "@esbuild/linux-arm" "0.19.2" + "@esbuild/linux-arm64" "0.19.2" + "@esbuild/linux-ia32" "0.19.2" + "@esbuild/linux-loong64" "0.19.2" + "@esbuild/linux-mips64el" "0.19.2" + "@esbuild/linux-ppc64" "0.19.2" + "@esbuild/linux-riscv64" "0.19.2" + "@esbuild/linux-s390x" "0.19.2" + "@esbuild/linux-x64" "0.19.2" + "@esbuild/netbsd-x64" "0.19.2" + "@esbuild/openbsd-x64" "0.19.2" + "@esbuild/sunos-x64" "0.19.2" + "@esbuild/win32-arm64" "0.19.2" + "@esbuild/win32-ia32" "0.19.2" + "@esbuild/win32-x64" "0.19.2" + escalade@^3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.1.1.tgz#d8cfdc7000965c5a0174b4a82eaa5c0552742e40"