REFACTOR: Sync up master with changes for Ember-CLI (#11671)

The more parallel the branches, the easier the transition will be.
This commit is contained in:
Robin Ward 2021-01-12 10:13:21 -05:00 committed by GitHub
parent 499a594754
commit e80332a2bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 21362 additions and 5 deletions

View File

@ -48,6 +48,6 @@
"node": "8.* || >= 10.*"
},
"ember": {
"edition": "octane"
"edition": "default"
}
}

View File

@ -4,6 +4,7 @@
if (window.unsupportedBrowser) {
throw "Unsupported browser detected";
}
let Discourse = requirejs("discourse/app").default.create();
// required for our template compiler
@ -11,7 +12,7 @@
"discourse-common/lib/raw-templates"
).__DISCOURSE_RAW_TEMPLATES;
// required for select kit to work without Ember CLI
// required for addons to work without Ember CLI
Object.keys(Ember.TEMPLATES).forEach((k) => {
if (k.indexOf("select-kit") === 0) {
let template = Ember.TEMPLATES[k];

View File

@ -11,7 +11,7 @@ export function setEnvironment(e) {
}
export function isTesting() {
return Ember.testing;
return Ember.testing || environment === "testing";
}
export function isDevelopment() {

View File

@ -40,8 +40,8 @@ export function registerRawHelpers(hbs, handlebarsClass) {
}
var list = get(this, contextName);
var output = [];
var innerContext = Object.create(this);
for (var i = 0; i < list.length; i++) {
let innerContext = {};
innerContext[localName] = list[i];
output.push(options.fn(innerContext));
}

View File

@ -0,0 +1,89 @@
"use strict";
const getChannelURL = require("ember-source-channel-url");
module.exports = async function () {
return {
useYarn: true,
scenarios: [
{
name: "ember-lts-3.8",
npm: {
devDependencies: {
"ember-source": "~3.8.0",
},
},
},
{
name: "ember-lts-3.12",
npm: {
devDependencies: {
"ember-source": "~3.12.0",
},
},
},
{
name: "ember-release",
npm: {
devDependencies: {
"ember-source": await getChannelURL("release"),
},
},
},
{
name: "ember-beta",
npm: {
devDependencies: {
"ember-source": await getChannelURL("beta"),
},
},
},
{
name: "ember-canary",
npm: {
devDependencies: {
"ember-source": await getChannelURL("canary"),
},
},
},
// The default `.travis.yml` runs this scenario via `yarn test`,
// not via `ember try`. It's still included here so that running
// `ember try:each` manually or from a customized CI config will run it
// along with all the other scenarios.
{
name: "ember-default",
npm: {
devDependencies: {},
},
},
{
name: "ember-default-with-jquery",
env: {
EMBER_OPTIONAL_FEATURES: JSON.stringify({
"jquery-integration": true,
}),
},
npm: {
devDependencies: {
"@ember/jquery": "^0.5.1",
},
},
},
{
name: "ember-classic",
env: {
EMBER_OPTIONAL_FEATURES: JSON.stringify({
"application-template-wrapper": true,
"default-async-observers": false,
"template-only-glimmer-components": false,
}),
},
npm: {
ember: {
edition: "classic",
},
},
},
],
};
};

View File

@ -0,0 +1,5 @@
"use strict";
module.exports = function (/* environment, appConfig */) {
return {};
};

View File

@ -0,0 +1,11 @@
"use strict";
const rawHandlebarsCompiler = require("./raw-handlebars-compiler");
module.exports = {
name: require("./package").name,
treeForApp() {
return rawHandlebarsCompiler(this.app.trees.app);
},
};

View File

@ -0,0 +1,54 @@
{
"name": "discourse-hbr",
"version": "1.0.0",
"description": "Support for Discourse's raw Handlebars templates (hbr)",
"author": "Discourse",
"license": "GPL-2.0-only",
"keywords": [
"ember-addon"
],
"repository": "",
"scripts": {
"build": "ember build",
"lint:hbs": "ember-template-lint .",
"lint:js": "eslint .",
"start": "ember serve"
},
"dependencies": {
"ember-auto-import": "^1.5.3",
"ember-cli-babel": "^7.13.0",
"ember-cli-htmlbars": "^4.2.0"
},
"devDependencies": {
"@ember/optional-features": "^1.1.0",
"@glimmer/component": "^1.0.0",
"babel-eslint": "^10.0.3",
"broccoli-asset-rev": "^3.0.0",
"broccoli-stew": "^3.0.0",
"ember-cli": "~3.15.2",
"ember-cli-dependency-checker": "^3.2.0",
"ember-cli-eslint": "^5.1.0",
"ember-cli-inject-live-reload": "^2.0.1",
"ember-cli-sri": "^2.1.1",
"ember-cli-template-lint": "^1.0.0-beta.3",
"ember-cli-uglify": "^3.0.0",
"ember-disable-prototype-extensions": "^1.1.3",
"ember-export-application-global": "^2.0.1",
"ember-load-initializers": "^2.1.1",
"ember-maybe-import-regenerator": "^0.1.6",
"ember-resolver": "^7.0.0",
"ember-source": "~3.15.0",
"ember-source-channel-url": "^2.0.1",
"ember-try": "^1.4.0",
"eslint-plugin-ember": "^7.7.1",
"eslint-plugin-node": "^10.0.0",
"handlebars": "^4.7.6",
"loader.js": "^4.7.0"
},
"engines": {
"node": "8.* || >= 10.*"
},
"ember": {
"edition": "octane"
}
}

View File

@ -0,0 +1,155 @@
"use strict";
const Filter = require("broccoli-filter");
const Handlebars = require("handlebars");
const RawHandlebars = Handlebars.create();
function buildPath(blk, args) {
var result = {
type: "PathExpression",
data: false,
depth: blk.path.depth,
loc: blk.path.loc,
};
// Server side precompile doesn't have jquery.extend
Object.keys(args).forEach(function (a) {
result[a] = args[a];
});
return result;
}
function replaceGet(ast) {
var visitor = new Handlebars.Visitor();
visitor.mutating = true;
visitor.MustacheStatement = function (mustache) {
if (!(mustache.params.length || mustache.hash)) {
mustache.params[0] = mustache.path;
mustache.path = buildPath(mustache, {
parts: ["get"],
original: "get",
strict: true,
falsy: true,
});
}
return Handlebars.Visitor.prototype.MustacheStatement.call(this, mustache);
};
// rewrite `each x as |y|` as each y in x`
// This allows us to use the same syntax in all templates
visitor.BlockStatement = function (block) {
if (block.path.original === "each" && block.params.length === 1) {
var paramName = block.program.blockParams[0];
block.params = [
buildPath(block, { original: paramName }),
{ type: "CommentStatement", value: "in" },
block.params[0],
];
delete block.program.blockParams;
}
return Handlebars.Visitor.prototype.BlockStatement.call(this, block);
};
visitor.accept(ast);
}
RawHandlebars.Compiler = function () {};
RawHandlebars.Compiler.prototype = Object.create(Handlebars.Compiler.prototype);
RawHandlebars.Compiler.prototype.compiler = RawHandlebars.Compiler;
RawHandlebars.JavaScriptCompiler = function () {};
RawHandlebars.JavaScriptCompiler.prototype = Object.create(
Handlebars.JavaScriptCompiler.prototype
);
RawHandlebars.JavaScriptCompiler.prototype.compiler =
RawHandlebars.JavaScriptCompiler;
RawHandlebars.JavaScriptCompiler.prototype.namespace = "RawHandlebars";
RawHandlebars.precompile = function (value, asObject) {
var ast = Handlebars.parse(value);
replaceGet(ast);
var options = {
knownHelpers: {
get: true,
},
data: true,
stringParams: true,
};
asObject = asObject === undefined ? true : asObject;
var environment = new RawHandlebars.Compiler().compile(ast, options);
return new RawHandlebars.JavaScriptCompiler().compile(
environment,
options,
undefined,
asObject
);
};
RawHandlebars.compile = function (string) {
var ast = Handlebars.parse(string);
replaceGet(ast);
// this forces us to rewrite helpers
var options = { data: true, stringParams: true };
var environment = new RawHandlebars.Compiler().compile(ast, options);
var templateSpec = new RawHandlebars.JavaScriptCompiler().compile(
environment,
options,
undefined,
true
);
var t = RawHandlebars.template(templateSpec);
t.isMethod = false;
return t;
};
function TemplateCompiler(inputTree, options) {
if (!(this instanceof TemplateCompiler)) {
return new TemplateCompiler(inputTree, options);
}
Filter.call(this, inputTree, options); // this._super()
this.options = options || {};
this.inputTree = inputTree;
}
TemplateCompiler.prototype = Object.create(Filter.prototype);
TemplateCompiler.prototype.constructor = TemplateCompiler;
TemplateCompiler.prototype.extensions = ["hbr"];
TemplateCompiler.prototype.targetExtension = "js";
TemplateCompiler.prototype.registerPlugins = function registerPlugins() {};
TemplateCompiler.prototype.initializeFeatures = function initializeFeatures() {};
TemplateCompiler.prototype.processString = function (string, relativePath) {
let filename = relativePath.replace(/^templates\//, "").replace(/\.hbr$/, "");
return (
'import { template as compiler } from "discourse-common/lib/raw-handlebars";\n' +
'import { addRawTemplate } from "discourse-common/lib/raw-templates";\n\n' +
"let template = compiler(" +
this.precompile(string, false) +
");\n\n" +
'addRawTemplate("' +
filename +
'", template);\n' +
"export default template;"
);
};
TemplateCompiler.prototype.precompile = function (value, asObject) {
return RawHandlebars.precompile(value, asObject);
};
module.exports = TemplateCompiler;

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,11 @@
import { avatarFor as avatar } from "discourse/widgets/post";
import { dateNode } from "discourse/helpers/node";
import { iconNode } from "discourse-common/lib/icon-library";
import rawHtml from "discourse/widgets/raw-html";
export default {
avatar,
dateNode,
iconNode,
rawHtml,
};

View File

@ -0,0 +1,89 @@
"use strict";
const getChannelURL = require("ember-source-channel-url");
module.exports = async function () {
return {
useYarn: true,
scenarios: [
{
name: "ember-lts-3.8",
npm: {
devDependencies: {
"ember-source": "~3.8.0",
},
},
},
{
name: "ember-lts-3.12",
npm: {
devDependencies: {
"ember-source": "~3.12.0",
},
},
},
{
name: "ember-release",
npm: {
devDependencies: {
"ember-source": await getChannelURL("release"),
},
},
},
{
name: "ember-beta",
npm: {
devDependencies: {
"ember-source": await getChannelURL("beta"),
},
},
},
{
name: "ember-canary",
npm: {
devDependencies: {
"ember-source": await getChannelURL("canary"),
},
},
},
// The default `.travis.yml` runs this scenario via `yarn test`,
// not via `ember try`. It's still included here so that running
// `ember try:each` manually or from a customized CI config will run it
// along with all the other scenarios.
{
name: "ember-default",
npm: {
devDependencies: {},
},
},
{
name: "ember-default-with-jquery",
env: {
EMBER_OPTIONAL_FEATURES: JSON.stringify({
"jquery-integration": true,
}),
},
npm: {
devDependencies: {
"@ember/jquery": "^0.5.1",
},
},
},
{
name: "ember-classic",
env: {
EMBER_OPTIONAL_FEATURES: JSON.stringify({
"application-template-wrapper": true,
"default-async-observers": false,
"template-only-glimmer-components": false,
}),
},
npm: {
ember: {
edition: "classic",
},
},
},
],
};
};

View File

@ -0,0 +1,5 @@
"use strict";
module.exports = function (/* environment, appConfig */) {
return {};
};

View File

@ -0,0 +1,30 @@
"use strict";
const WidgetHbsCompiler = require("../../../../lib/javascripts/widget-hbs-compiler")
.WidgetHbsCompiler;
const glimmer = require("@glimmer/syntax");
module.exports = {
name: require("./package").name,
included() {
this._super.included.apply(this, arguments);
let addonOptions = this._getAddonOptions();
addonOptions.babel = addonOptions.babel || {};
addonOptions.babel.plugins = addonOptions.babel.plugins || [];
let babelPlugins = addonOptions.babel.plugins;
WidgetHbsCompiler.cacheKey = () => "discourse-widget-hbs";
WidgetHbsCompiler.glimmer = glimmer;
babelPlugins.push(WidgetHbsCompiler);
},
_getAddonOptions() {
return (
(this.parent && this.parent.options) ||
(this.app && this.app.options) ||
{}
);
},
};

View File

@ -0,0 +1,54 @@
{
"name": "discourse-widget-hbs",
"version": "1.0.0",
"description": "Support for Discourse's inline `hbs` compiler for widgets",
"author": "Discourse",
"license": "GPL-2.0-only",
"keywords": [
"ember-addon"
],
"repository": "",
"scripts": {
"build": "ember build",
"lint:hbs": "ember-template-lint .",
"lint:js": "eslint .",
"start": "ember serve"
},
"dependencies": {
"ember-auto-import": "^1.5.3",
"ember-cli-babel": "^7.13.0",
"ember-cli-htmlbars": "^4.2.0"
},
"devDependencies": {
"@ember/optional-features": "^1.1.0",
"@glimmer/component": "^1.0.0",
"babel-eslint": "^10.0.3",
"broccoli-asset-rev": "^3.0.0",
"broccoli-stew": "^3.0.0",
"ember-cli": "~3.15.2",
"ember-cli-dependency-checker": "^3.2.0",
"ember-cli-eslint": "^5.1.0",
"ember-cli-inject-live-reload": "^2.0.1",
"ember-cli-sri": "^2.1.1",
"ember-cli-template-lint": "^1.0.0-beta.3",
"ember-cli-uglify": "^3.0.0",
"ember-disable-prototype-extensions": "^1.1.3",
"ember-export-application-global": "^2.0.1",
"ember-load-initializers": "^2.1.1",
"ember-maybe-import-regenerator": "^0.1.6",
"ember-resolver": "^7.0.0",
"ember-source": "~3.15.0",
"ember-source-channel-url": "^2.0.1",
"ember-try": "^1.4.0",
"eslint-plugin-ember": "^7.7.1",
"eslint-plugin-node": "^10.0.0",
"handlebars": "^4.7.6",
"loader.js": "^4.7.0"
},
"engines": {
"node": "8.* || >= 10.*"
},
"ember": {
"edition": "octane"
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,9 @@
{
/**
Ember CLI sends analytics information by default. The data is completely
anonymous, but there are times when you might want to disable this behavior.
Setting `disableAnalytics` to true will prevent any data from being sent.
*/
"disableAnalytics": false
}

View File

@ -31,7 +31,7 @@ export default {
const segs = k.split(".");
let node = I18n.translations[I18n.locale];
let node = I18n.translations[I18n.locale] || {};
let i = 0;
for (; i < segs.length - 1; i++) {