mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 03:36:18 +08:00
DEV: Upgrade babel & remove vendored safari-bugfix transformation (#28208)
The Safari 15 bugfix has been rolled into @babel/preset-env in the most recent version, so we no longer need to carry our vendored copy. This commit updates @babel/preset-env, runs npx yarn-deduplicate yarn.lock, and removes the vendored transform. This commit also refactors our theme transpiler to use @babel/preset-env, with the same list of target browsers as our ember-cli build uses. This means we no longer need to maintain a separate list of babel transforms for themes.
This commit is contained in:
@ -14,7 +14,7 @@
|
|||||||
"start": "ember serve"
|
"start": "ember serve"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/core": "^7.24.9",
|
"@babel/core": "^7.25.2",
|
||||||
"discourse-common": "1.0.0",
|
"discourse-common": "1.0.0",
|
||||||
"ember-cli-babel": "^8.2.0",
|
"ember-cli-babel": "^8.2.0",
|
||||||
"ember-cli-htmlbars": "^6.3.0",
|
"ember-cli-htmlbars": "^6.3.0",
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
"start": "ember serve"
|
"start": "ember serve"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/core": "^7.24.9",
|
"@babel/core": "^7.25.2",
|
||||||
"@uppy/aws-s3": "3.0.6",
|
"@uppy/aws-s3": "3.0.6",
|
||||||
"@uppy/aws-s3-multipart": "3.1.3",
|
"@uppy/aws-s3-multipart": "3.1.3",
|
||||||
"@uppy/core": "3.0.4",
|
"@uppy/core": "3.0.4",
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
"ember-addon"
|
"ember-addon"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/core": "^7.24.9",
|
"@babel/core": "^7.25.2",
|
||||||
"deprecation-silencer": "1.0.0",
|
"deprecation-silencer": "1.0.0",
|
||||||
"discourse-widget-hbs": "1.0.0",
|
"discourse-widget-hbs": "1.0.0",
|
||||||
"ember-cli-babel": "^8.2.0",
|
"ember-cli-babel": "^8.2.0",
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
"start": "ember serve"
|
"start": "ember serve"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/core": "^7.24.9",
|
"@babel/core": "^7.25.2",
|
||||||
"ember-auto-import": "^2.7.4",
|
"ember-auto-import": "^2.7.4",
|
||||||
"ember-cli-babel": "^8.2.0",
|
"ember-cli-babel": "^8.2.0",
|
||||||
"ember-cli-htmlbars": "^6.3.0",
|
"ember-cli-htmlbars": "^6.3.0",
|
||||||
|
@ -1,97 +0,0 @@
|
|||||||
function wrapInitializer(path, babel) {
|
|
||||||
function needsWrapping(node) {
|
|
||||||
if (t.isLiteral(node) && !t.isTemplateLiteral(node)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
t.isCallExpression(node) ||
|
|
||||||
t.isOptionalCallExpression(node) ||
|
|
||||||
t.isNewExpression(node)
|
|
||||||
) {
|
|
||||||
return needsWrapping(node.callee) || node.arguments.some(needsWrapping);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (t.isTemplateLiteral(node)) {
|
|
||||||
return node.expressions.some(needsWrapping);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (t.isTaggedTemplateExpression(node)) {
|
|
||||||
return needsWrapping(node.tag) || needsWrapping(node.quasi);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (t.isArrayExpression(node)) {
|
|
||||||
return node.elements.some(needsWrapping);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (t.isObjectExpression(node)) {
|
|
||||||
return node.properties.some((prop) => {
|
|
||||||
if (t.isObjectProperty(prop)) {
|
|
||||||
return (
|
|
||||||
needsWrapping(prop.value) ||
|
|
||||||
(prop.computed && needsWrapping(prop.key))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (t.isObjectMethod(prop)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (t.isMemberExpression(node) || t.isOptionalMemberExpression(node)) {
|
|
||||||
return (
|
|
||||||
needsWrapping(node.object) ||
|
|
||||||
(node.computed && needsWrapping(node.property))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
t.isFunctionExpression(node) ||
|
|
||||||
t.isArrowFunctionExpression(node) ||
|
|
||||||
t.isClassExpression(node)
|
|
||||||
) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (t.isThisExpression(node)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (t.isSequenceExpression(node)) {
|
|
||||||
return node.expressions.some(needsWrapping);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Is an identifier, or anything else not covered above
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { types: t } = babel;
|
|
||||||
const { value } = path.node;
|
|
||||||
|
|
||||||
if (value && needsWrapping(value)) {
|
|
||||||
path.node.value = t.callExpression(
|
|
||||||
t.arrowFunctionExpression([], value),
|
|
||||||
[]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function makeVisitor(babel) {
|
|
||||||
return {
|
|
||||||
ClassProperty(path) {
|
|
||||||
wrapInitializer(path, babel);
|
|
||||||
},
|
|
||||||
ClassPrivateProperty(path) {
|
|
||||||
wrapInitializer(path, babel);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = function wrapClassFields(babel) {
|
|
||||||
return {
|
|
||||||
post(file) {
|
|
||||||
babel.traverse(file.ast, makeVisitor(babel), file.scope, this);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
};
|
|
@ -15,7 +15,6 @@ module.exports = function generateCommonBabelConfig() {
|
|||||||
runEarly: true,
|
runEarly: true,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
require.resolve("./babel-plugin-safari-class-fields-bugfix"),
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -37,8 +37,8 @@
|
|||||||
"pretty-text": "1.0.0"
|
"pretty-text": "1.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.24.9",
|
"@babel/core": "^7.25.2",
|
||||||
"@babel/standalone": "^7.24.10",
|
"@babel/standalone": "^7.25.3",
|
||||||
"@colors/colors": "^1.6.0",
|
"@colors/colors": "^1.6.0",
|
||||||
"@discourse/backburner.js": "^2.7.1-0",
|
"@discourse/backburner.js": "^2.7.1-0",
|
||||||
"@discourse/itsatrap": "^2.0.10",
|
"@discourse/itsatrap": "^2.0.10",
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
"start": "ember serve"
|
"start": "ember serve"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/core": "^7.24.9",
|
"@babel/core": "^7.25.2",
|
||||||
"ember-auto-import": "^2.7.4",
|
"ember-auto-import": "^2.7.4",
|
||||||
"ember-cli-babel": "^8.2.0",
|
"ember-cli-babel": "^8.2.0",
|
||||||
"ember-cli-htmlbars": "^6.3.0",
|
"ember-cli-htmlbars": "^6.3.0",
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
"start": "ember serve"
|
"start": "ember serve"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/core": "^7.24.9",
|
"@babel/core": "^7.25.2",
|
||||||
"discourse-common": "1.0.0",
|
"discourse-common": "1.0.0",
|
||||||
"ember-auto-import": "^2.7.4",
|
"ember-auto-import": "^2.7.4",
|
||||||
"ember-cli-babel": "^8.2.0",
|
"ember-cli-babel": "^8.2.0",
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
"start": "ember serve"
|
"start": "ember serve"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/core": "^7.24.9",
|
"@babel/core": "^7.25.2",
|
||||||
"ember-auto-import": "^2.7.4",
|
"ember-auto-import": "^2.7.4",
|
||||||
"ember-cli-babel": "^8.2.0",
|
"ember-cli-babel": "^8.2.0",
|
||||||
"ember-cli-htmlbars": "^6.3.0",
|
"ember-cli-htmlbars": "^6.3.0",
|
||||||
|
@ -52,7 +52,7 @@ esbuild
|
|||||||
util: "./node_modules/@zxing/text-encoding",
|
util: "./node_modules/@zxing/text-encoding",
|
||||||
},
|
},
|
||||||
define: {
|
define: {
|
||||||
process: `{ "env": {} }`,
|
process: `{ "env": { "EMBER_ENV": "production" } }`,
|
||||||
},
|
},
|
||||||
external: ["fs", "path"],
|
external: ["fs", "path"],
|
||||||
entryPoints: ["./app/assets/javascripts/theme-transpiler/transpiler.js"],
|
entryPoints: ["./app/assets/javascripts/theme-transpiler/transpiler.js"],
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
"license": "GPL-2.0-only",
|
"license": "GPL-2.0-only",
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/standalone": "^7.24.10",
|
"@babel/standalone": "^7.25.3",
|
||||||
"@zxing/text-encoding": "^0.9.0",
|
"@zxing/text-encoding": "^0.9.0",
|
||||||
"babel-plugin-ember-template-compilation": "^2.2.5",
|
"babel-plugin-ember-template-compilation": "^2.2.5",
|
||||||
"content-tag": "^2.0.1",
|
"content-tag": "^2.0.1",
|
||||||
|
@ -30,8 +30,8 @@ import getRandomValues from "polyfill-crypto.getrandomvalues";
|
|||||||
import { minify as terserMinify } from "terser";
|
import { minify as terserMinify } from "terser";
|
||||||
import RawHandlebars from "discourse-common/addon/lib/raw-handlebars";
|
import RawHandlebars from "discourse-common/addon/lib/raw-handlebars";
|
||||||
import { WidgetHbsCompiler } from "discourse-widget-hbs/lib/widget-hbs-compiler";
|
import { WidgetHbsCompiler } from "discourse-widget-hbs/lib/widget-hbs-compiler";
|
||||||
import BabelPluginSafariClassFieldsBugfix from "../discourse/lib/babel-plugin-safari-class-fields-bugfix";
|
|
||||||
globalThis.crypto = { getRandomValues };
|
globalThis.crypto = { getRandomValues };
|
||||||
|
import { browsers } from "../discourse/config/targets";
|
||||||
|
|
||||||
const thisFallbackPlugin = EmberThisFallback._buildPlugin({
|
const thisFallbackPlugin = EmberThisFallback._buildPlugin({
|
||||||
enableLogging: false,
|
enableLogging: false,
|
||||||
@ -127,8 +127,7 @@ globalThis.compileRawTemplate = function (source, themeId) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
globalThis.transpile = function (source, options = {}) {
|
globalThis.transpile = function (source, options = {}) {
|
||||||
const { moduleId, filename, extension, skipModule, themeId, commonPlugins } =
|
const { moduleId, filename, extension, skipModule, themeId } = options;
|
||||||
options;
|
|
||||||
|
|
||||||
if (extension === "gjs") {
|
if (extension === "gjs") {
|
||||||
const preprocessor = new Preprocessor();
|
const preprocessor = new Preprocessor();
|
||||||
@ -140,10 +139,7 @@ globalThis.transpile = function (source, options = {}) {
|
|||||||
if (moduleId && !skipModule) {
|
if (moduleId && !skipModule) {
|
||||||
plugins.push(["transform-modules-amd", { noInterop: true }]);
|
plugins.push(["transform-modules-amd", { noInterop: true }]);
|
||||||
}
|
}
|
||||||
commonPlugins.find((p) => p[0] === "decorator-transforms")[0] =
|
plugins.push([DecoratorTransforms, { runEarly: true }]);
|
||||||
DecoratorTransforms;
|
|
||||||
plugins.push(...commonPlugins);
|
|
||||||
plugins.unshift(BabelPluginSafariClassFieldsBugfix);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return babelTransform(source, {
|
return babelTransform(source, {
|
||||||
@ -151,6 +147,17 @@ globalThis.transpile = function (source, options = {}) {
|
|||||||
filename,
|
filename,
|
||||||
ast: false,
|
ast: false,
|
||||||
plugins,
|
plugins,
|
||||||
|
presets: [
|
||||||
|
[
|
||||||
|
"env",
|
||||||
|
{
|
||||||
|
modules: false,
|
||||||
|
targets: {
|
||||||
|
browsers,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
],
|
||||||
}).code;
|
}).code;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Workaround for https://github.com/rubyjs/mini_racer/issues/262
|
// Workaround for https://github.com/rubyjs/mini_racer/issues/262
|
||||||
|
@ -6,15 +6,6 @@ class DiscourseJsProcessor
|
|||||||
class TranspileError < StandardError
|
class TranspileError < StandardError
|
||||||
end
|
end
|
||||||
|
|
||||||
# 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 = [
|
|
||||||
["decorator-transforms", { runEarly: true }],
|
|
||||||
"proposal-class-static-block",
|
|
||||||
"transform-parameters",
|
|
||||||
"proposal-export-namespace-from",
|
|
||||||
]
|
|
||||||
|
|
||||||
def self.ember_cli?(filename)
|
def self.ember_cli?(filename)
|
||||||
filename.include?("/app/assets/javascripts/discourse/dist/")
|
filename.include?("/app/assets/javascripts/discourse/dist/")
|
||||||
end
|
end
|
||||||
@ -161,7 +152,6 @@ class DiscourseJsProcessor
|
|||||||
filename: logical_path || "unknown",
|
filename: logical_path || "unknown",
|
||||||
extension: extension,
|
extension: extension,
|
||||||
themeId: theme_id,
|
themeId: theme_id,
|
||||||
commonPlugins: DISCOURSE_COMMON_BABEL_PLUGINS,
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user