Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move template compiler creation to a method on the addon #527

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lib/ember-addon-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ module.exports = {
return this._cachedShouldColocateTemplates;
},

// This method is monkey patched by CSS Blocks,
// Please coordinate with @chriseppstein if you need to change it.
transpileTree(inputTree, htmlbarsOptions) {
const TemplateCompiler = require('./template-compiler-plugin');
return new TemplateCompiler(inputTree, htmlbarsOptions);
},

setupPreprocessorRegistry(type, registry) {
// ensure that broccoli-ember-hbs-template-compiler is not processing hbs files
registry.remove('template', 'broccoli-ember-hbs-template-compiler');
Expand All @@ -83,10 +90,8 @@ module.exports = {

inputTree = debugTree(new ColocatedTemplateProcessor(inputTree), '02-colocated-output');
}

this._addon.logger.debug(`setup *.hbs compiler with ${htmlbarsOptions.pluginNames}`);
const TemplateCompiler = require('./template-compiler-plugin');
return debugTree(new TemplateCompiler(inputTree, htmlbarsOptions), '03-output');
return debugTree(this._addon.transpileTree(inputTree, htmlbarsOptions), '03-output');
},

precompile(string, options) {
Expand Down
94 changes: 94 additions & 0 deletions node-tests/addon-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
'use strict';

const co = require('co');
const expect = require('chai').expect;
const MockUI = require('console-ui/mock');
const CoreObject = require('core-object');
const AddonMixin = require('../lib/ember-addon-main');
const BroccoliTestHelper = require('broccoli-test-helper');
const createBuilder = BroccoliTestHelper.createBuilder;
const createTempDir = BroccoliTestHelper.createTempDir;

let Addon = CoreObject.extend(AddonMixin);

describe('ember-cli-htmlbars addon', function () {
const ORIGINAL_EMBER_ENV = process.env.EMBER_ENV;

beforeEach(function () {
this.ui = new MockUI();
let project = {
isEmberCLIProject: () => true,
_addonsInitialized: true,
root: __dirname,
emberCLIVersion: () => '2.16.2',
dependencies() {
return {};
},
addons: [],
targets: {
browsers: ['ie 11'],
},
};

this.addon = new Addon({
project,
parent: project,
ui: this.ui,
});

project.addons.push(this.addon);
});

afterEach(function () {
if (ORIGINAL_EMBER_ENV === undefined) {
delete process.env.EMBER_ENV;
} else {
process.env.EMBER_ENV = ORIGINAL_EMBER_ENV;
}
});

describe('transpileTree', function () {
this.timeout(0);

let input;
let output;
let subject;

beforeEach(
co.wrap(function* () {
input = yield createTempDir();
})
);

afterEach(
co.wrap(function* () {
yield input.dispose();
yield output.dispose();
})
);

it(
'should build',
co.wrap(function* () {
input.write({
'hello.hbs': `<div>Hello, World!</div>`,
});

let htmlbarsOptions = {
isHTMLBars: true,
templateCompiler: require('ember-source/dist/ember-template-compiler.js'),
};

subject = this.addon.transpileTree(input.path(), htmlbarsOptions);
output = createBuilder(subject);

yield output.build();

expect(output.read()).to.deep.equal({
'hello.js':
'export default Ember.HTMLBars.template({"id":"QumOHSmG","block":"{\\"symbols\\":[],\\"statements\\":[[10,\\"div\\"],[12],[2,\\"Hello, World!\\"],[13]],\\"hasEval\\":false,\\"upvars\\":[]}","meta":{"moduleName":"hello.hbs"}});',
});
})
);
});
});
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@ember/edition-utils": "^1.2.0",
"babel-plugin-htmlbars-inline-precompile": "^4.1.0",
"broccoli-debug": "^0.6.5",
"broccoli-persistent-filter": "^3.0.0",
"broccoli-persistent-filter": "^3.1.0",
"broccoli-plugin": "^4.0.3",
"common-tags": "^1.8.0",
"ember-cli-babel-plugin-helpers": "^1.1.0",
Expand All @@ -62,6 +62,8 @@
"broccoli-test-helper": "^2.0.0",
"chai": "^4.2.0",
"co": "^4.6.0",
"console-ui": "^2.2.2",
"core-object": "^3.1.5",
"ember-cli": "~3.18.0",
"ember-cli-app-version": "^3.2.0",
"ember-cli-babel": "^7.20.4",
Expand Down
Loading