Skip to content
This repository was archived by the owner on Dec 8, 2024. It is now read-only.

Support 'ember-cli-htmlbars' import by default#293

Open
izelnakri wants to merge 4 commits intoember-cli:masterfrom
izelnakri:support-ember-cli-htmlbars
Open

Support 'ember-cli-htmlbars' import by default#293
izelnakri wants to merge 4 commits intoember-cli:masterfrom
izelnakri:support-ember-cli-htmlbars

Conversation

@izelnakri
Copy link

@izelnakri izelnakri commented Nov 1, 2020

This PR adds a performant transpiler support for import { hbs } from 'ember-cli-htmlbars.

Extensive tests are also provided/adjusted for this behavior.

The reasoning behind this PR is described here: #292

Copy link
Member

@rwjblue rwjblue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its totally good to sync the default value for module with the ones provided by ember-cli-htmlbars:

https://github.com/ember-cli/ember-cli-htmlbars/blob/df8ed20cfa06634747bae3098dd292e8d03de49c/lib/utils.js#L11-L15

I'm not sure we need to duplicate the tests, but also seems totally fine.

index.js Outdated
throw path.buildCodeFrameError(msg);
}
} else {
} else if (modulePathExport !== 'hbs') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this change required? ember-cli-htmlbars already configures the modules option for us (and it works just fine without this else if change).

Copy link
Author

@izelnakri izelnakri Nov 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently this PR does that as well on line 96. This line change allows for errors to be thrown if user/developer writes:

import hbs from 'ember-cli-htmlbars';

while it should be:

import { hbs } from 'ember-cli-htmlbars';

We might be able to find a different way to accomplish this. I was kind of satisfied with a single line change considering it passed both versions of tests and performance implications would be minimal(single if check). I'm of course willing to change it if we can find a better way :)

Copy link
Member

@rwjblue rwjblue Nov 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is that we shouldn't hard code the "hbs" name here (the names that are allowed should be based on the modules config)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rwjblue updated the the code, tests passing now. Also did few manual tests just to be sure 😅

@rwjblue
Copy link
Member

rwjblue commented Nov 9, 2020

This PR adds a performant transpiler support for import { hbs } from 'ember-cli-htmlbars.

What does this mean? This PR adds support for transpiling import { hbs } from 'ember-cli-htmlbars' by default but it doesn't change anything regarding performance.

@izelnakri
Copy link
Author

What does this mean? This PR adds support for transpiling import { hbs } from 'ember-cli-htmlbars' by default but it doesn't change anything regarding performance.

Yes, sorry for the wording. I meant the new change wont degrade the performance much since it adds a single if check.


let modules = state.opts.modules || {
'htmlbars-inline-precompile': 'default',
'ember-cli-htmlbars': 'hbs',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#292 claims that ember-cli-htmlbars currently is not supported but due to the state.opts.modules || part of this statement I'm wondering if that's really the case. what's stopping you from passing in a modules option from the outside?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to also throw this error and make sure tests passes with correct imports on both cases: #293 (comment) . Also this results in better defaults, allows any developer to use it without passing that opts, which makes sense because that really should be the default behaviour practically speaking.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's stopping you from passing in a modules option from the outside?

FWIW, I mentioned this somewhere else, but that is exactly what we are doing in ember-cli-htmlbars

https://github.com/ember-cli/ember-cli-htmlbars/blob/df8ed20cfa06634747bae3098dd292e8d03de49c/lib/utils.js#L11-L15

Either way, it seems totally fine to have this package default the configuration to match what we expect folks to actually use in real life.

@izelnakri izelnakri force-pushed the support-ember-cli-htmlbars branch from e434d83 to a170185 Compare November 11, 2020 02:13
@izelnakri
Copy link
Author

@rwjblue thanks for your reviews! Is there anything else blocking this PR? I would like to get it merged otherwise.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants