Skip to content

Commit 70a03f7

Browse files
committed
Merge branch 'master' of github.com:camerondubas/ember-cli-htmlbars
2 parents 91a94a7 + 29bbbba commit 70a03f7

5 files changed

Lines changed: 118 additions & 17 deletions

File tree

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
## v4.0.6 (2019-10-17)
2+
3+
#### :rocket: Enhancement
4+
* [#334](https://github.com/ember-cli/ember-cli-htmlbars/pull/334) Add parent's name to logging output. ([@rwjblue](https://github.com/rwjblue))
5+
6+
#### :bug: Bug Fix
7+
* [#333](https://github.com/ember-cli/ember-cli-htmlbars/pull/333) Enable colocated component classes to be TypeScript ([@rwjblue](https://github.com/rwjblue))
8+
* [#332](https://github.com/ember-cli/ember-cli-htmlbars/pull/332) Ensure "pods style" templates are compiled properly. ([@rwjblue](https://github.com/rwjblue))
9+
10+
#### :house: Internal
11+
* [#125](https://github.com/ember-cli/ember-cli-htmlbars/pull/125) Add more tests using AST plugins (inline and standalone) ([@stefanpenner](https://github.com/stefanpenner))
12+
13+
#### Committers: 2
14+
- Robert Jackson ([@rwjblue](https://github.com/rwjblue))
15+
- Stefan Penner ([@stefanpenner](https://github.com/stefanpenner))
16+
117
## v4.0.5 (2019-10-04)
218

319
#### :bug: Bug Fix

lib/colocated-broccoli-plugin.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,25 @@ module.exports = class ColocatedTemplateProcessor extends Plugin {
6868
return;
6969
}
7070

71-
// TODO: deal with alternate extensions (e.g. ts)
72-
let possibleJSPath = path.join(filePathParts.dir, filePathParts.name + '.js');
73-
let hasJSFile = fs.existsSync(path.join(this.inputPaths[0], possibleJSPath));
74-
7571
if (filePathParts.name === 'template') {
76-
// TODO: maybe warn?
72+
filesToCopy.push(filePath);
7773
return;
7874
}
7975

76+
let hasBackingClass = false;
77+
let backingClassPath = path.join(filePathParts.dir, filePathParts.name);
78+
79+
if (fs.existsSync(path.join(this.inputPaths[0], backingClassPath + '.js'))) {
80+
backingClassPath += '.js';
81+
hasBackingClass = true;
82+
} else if (fs.existsSync(path.join(this.inputPaths[0], backingClassPath + '.ts'))) {
83+
backingClassPath += '.ts';
84+
hasBackingClass = true;
85+
} else {
86+
backingClassPath += '.js';
87+
hasBackingClass = false;
88+
}
89+
8090
let templateContents = fs.readFileSync(inputPath, { encoding: 'utf8' });
8191
let jsContents = null;
8292

@@ -92,12 +102,14 @@ module.exports = class ColocatedTemplateProcessor extends Plugin {
92102
)})`;
93103
let prefix = `import { hbs } from 'ember-cli-htmlbars';\nconst __COLOCATED_TEMPLATE__ = ${hbsInvocation};\n`;
94104

95-
logger.debug(`processing colocated template: ${filePath} (template-only: ${hasJSFile})`);
105+
logger.debug(
106+
`processing colocated template: ${filePath} (template-only: ${hasBackingClass})`
107+
);
96108

97-
if (hasJSFile) {
109+
if (hasBackingClass) {
98110
// add the template, call setComponentTemplate
99111

100-
jsContents = fs.readFileSync(path.join(this.inputPaths[0], possibleJSPath), {
112+
jsContents = fs.readFileSync(path.join(this.inputPaths[0], backingClassPath), {
101113
encoding: 'utf8',
102114
});
103115

@@ -114,7 +126,7 @@ module.exports = class ColocatedTemplateProcessor extends Plugin {
114126

115127
jsContents = prefix + jsContents;
116128

117-
let outputPath = path.join(this.outputPath, possibleJSPath);
129+
let outputPath = path.join(this.outputPath, backingClassPath);
118130

119131
// TODO: don't speculatively mkdirSync (likely do in a try/catch with ENOENT)
120132
mkdirp.sync(path.dirname(outputPath));

lib/ember-addon-main.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const path = require('path');
44
const utils = require('./utils');
5-
const logger = require('heimdalljs-logger')('ember-cli-htmlbars:addon');
65
const hasEdition = require('@ember/edition-utils').has;
76

87
let registryInvocationCounter = 0;
@@ -12,6 +11,14 @@ module.exports = {
1211

1312
parentRegistry: null,
1413

14+
init() {
15+
this._super.init.apply(this, arguments);
16+
17+
let parentName = typeof this.parent.name === 'function' ? this.parent.name() : this.parent.name;
18+
19+
this.logger = require('heimdalljs-logger')('ember-cli-htmlbars:addon:' + parentName);
20+
},
21+
1522
_shouldColocateTemplates() {
1623
if (this._cachedShouldColocateTemplates) {
1724
return this._cachedShouldColocateTemplates;
@@ -36,9 +43,8 @@ module.exports = {
3643
this._cachedShouldColocateTemplates =
3744
hasOctane && hasValidBabelVersion && hasValidEmberCLIVersion;
3845

39-
logger.info(
40-
`Colocation processing: ${this._cachedShouldColocateTemplates} (hasOctane: ${hasOctane}; hasValidEmberCLIVersion: ${hasValidEmberCLIVersion}; hasVali
41-
dBabelVersion: ${hasValidBabelVersion};`
46+
this.logger.info(
47+
`Colocation processing: ${this._cachedShouldColocateTemplates} (hasOctane: ${hasOctane}; hasValidEmberCLIVersion: ${hasValidEmberCLIVersion}; hasValidBabelVersion: ${hasValidBabelVersion};`
4248
);
4349

4450
return this._cachedShouldColocateTemplates;
@@ -140,7 +146,7 @@ dBabelVersion: ${hasValidBabelVersion};`
140146
let templateCompilerPath = this.templateCompilerPath();
141147

142148
if (pluginInfo.canParallelize) {
143-
logger.debug('using parallel API with for babel inline precompilation plugin');
149+
this.logger.debug('using parallel API with for babel inline precompilation plugin');
144150

145151
let htmlbarsInlinePrecompilePlugin = utils.buildParalleizedBabelPlugin(
146152
pluginInfo,
@@ -149,8 +155,8 @@ dBabelVersion: ${hasValidBabelVersion};`
149155

150156
babelPlugins.push(htmlbarsInlinePrecompilePlugin);
151157
} else {
152-
logger.debug('NOT using parallel API with for babel inline precompilation plugin');
153-
logger.debug('Prevented by these plugins: ' + pluginInfo.unparallelizableWrappers);
158+
this.logger.debug('NOT using parallel API with for babel inline precompilation plugin');
159+
this.logger.debug('Prevented by these plugins: ' + pluginInfo.unparallelizableWrappers);
154160

155161
let htmlBarsPlugin = utils.setup(pluginInfo, {
156162
projectConfig: this.projectConfig(),

node-tests/colocated-plugin-test.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,50 @@ describe('ColocatedTemplateCompiler', function() {
105105
});
106106
});
107107

108+
it('works for typescript component class with template', async function() {
109+
input.write({
110+
'app-name-here': {
111+
components: {
112+
'foo.hbs': `{{yield}}`,
113+
'foo.ts': stripIndent`
114+
import Component from '@glimmer/component';
115+
116+
export default class FooComponent extends Component {}
117+
`,
118+
},
119+
templates: {
120+
'application.hbs': `{{outlet}}`,
121+
},
122+
},
123+
});
124+
125+
let tree = new ColocatedTemplateCompiler(input.path(), {
126+
precompile(template) {
127+
return JSON.stringify({ template });
128+
},
129+
});
130+
131+
output = createBuilder(tree);
132+
await output.build();
133+
134+
assert.deepStrictEqual(output.read(), {
135+
'app-name-here': {
136+
components: {
137+
'foo.ts': stripIndent`
138+
import { hbs } from 'ember-cli-htmlbars';
139+
const __COLOCATED_TEMPLATE__ = hbs("{{yield}}", {"contents":"{{yield}}","moduleName":"app-name-here/components/foo.hbs","parseOptions":{"srcName":"app-name-here/components/foo.hbs"}});
140+
import Component from '@glimmer/component';
141+
142+
export default class FooComponent extends Component {}
143+
`,
144+
},
145+
templates: {
146+
'application.hbs': '{{outlet}}',
147+
},
148+
},
149+
});
150+
});
151+
108152
it('works for scoped addon using template only component', async function() {
109153
input.write({
110154
'@scope-name': {
@@ -227,6 +271,29 @@ describe('ColocatedTemplateCompiler', function() {
227271
assert.deepStrictEqual(output.read(), input.read());
228272
});
229273

274+
it('does nothing for "pod" location templates', async function() {
275+
input.write({
276+
'addon-name-here': {
277+
components: {
278+
foo: {
279+
'template.hbs': `{{yield}}`,
280+
},
281+
},
282+
},
283+
});
284+
285+
let tree = new ColocatedTemplateCompiler(input.path(), {
286+
precompile(template) {
287+
return JSON.stringify({ template });
288+
},
289+
});
290+
291+
output = createBuilder(tree);
292+
await output.build();
293+
294+
assert.deepStrictEqual(output.read(), input.read());
295+
});
296+
230297
it('it works if there are no input files', async function() {
231298
input.write({});
232299

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ember-cli-htmlbars",
3-
"version": "4.0.5",
3+
"version": "4.0.6",
44
"description": "A library for adding htmlbars to ember CLI",
55
"keywords": [
66
"ember-addon",

0 commit comments

Comments
 (0)