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

Add AutoExtensionImporter #569

Merged
merged 6 commits into from
Jan 16, 2020
Merged

Add AutoExtensionImporter #569

merged 6 commits into from
Jan 16, 2020

Conversation

sebastianbenz
Copy link
Collaborator

No description provided.

Copy link
Collaborator

@fstanis fstanis left a comment

Choose a reason for hiding this comment

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

Left a few comments, mostly around readability. Also, I see the testdata, but no tests? Or am I missing something?

packages/optimizer/lib/RuntimeHostHelper.js Outdated Show resolved Hide resolved
@sebastianbenz
Copy link
Collaborator Author

@fstanis great review! thanks a lot! PTAL

@morsssss
Copy link

@fstanis , yes, this looks so thorough that I don't feel obliged to take a look myself!

As long as you've looked a bit at https://github.com/garanj/amphtml-autoscript to make sure you don't repeat any of our mistakes :)

@morsssss
Copy link

/cc @garanj

Copy link
Collaborator

@fstanis fstanis left a comment

Choose a reason for hiding this comment

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

Final thought: what if the input is in a different format (e.g. story) that doesn't support an extension you're adding? Probably not a big deal, but wanted to bring it up.

packages/optimizer/lib/RuntimeHostHelper.js Outdated Show resolved Hide resolved
async initExtensionSpec_(validatorRules) {
this.extensionSpec = validatorRules.fetch().then((rules) => {
// Map extension names to more info
const extensionsMap = new Map(rules.extensions.map((ext) => [ext.name, {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thinking about this... you may want to take htmlFormat into account. For example, AMP for Email doesn't support amp-carousel 0.2.

More importantly, this assumes there's exactly one extension for a given ext.name which is incorrect because of the above. I'm not sure what the current behavior is, but it will give you an arbitrary amp-carousel that may be the email one (and thus 0.1) or the regular one (and thus 0.1 and 0.2).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yup. That's already on my todo list.

- Support multiple formats
- Add validador-rules dependency to optimizer
Copy link
Collaborator Author

@sebastianbenz sebastianbenz left a comment

Choose a reason for hiding this comment

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

I've added format support. The default is AMP for websites, but other formats can be set via the config. I thought about auto detecting the format, but I don't think it's worth the effort for now.

@fstanis PTAL

@sebastianbenz
Copy link
Collaborator Author

Forgot to mention earlier, the test runner automatically picks up tests (every folder is a separate test with input and expected output).

Copy link
Collaborator

@fstanis fstanis left a comment

Choose a reason for hiding this comment

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

LGTM. Ship it.

const extensionsMap = new Map();
for (const ext of rules.extensions) {
if (ext.htmlFormat.includes(DEFAULT_FORMAT)) {
extensionsMap.set(ext.name, {
Copy link
Collaborator

Choose a reason for hiding this comment

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

While the format check almost certainly ensures uniqueness... I'd urge adding if (extensionsMap.has(ext.name)) { throw ... } just in case.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was actually a bug: DEFAULT_FORMAT needs to be this.format. Throwing an exception here feels like overkill, this would mean if the validation format has a bug it'll mean pages will suddenly start to break which we should avoid if possible.

@sebastianbenz
Copy link
Collaborator Author

Thanks everyone for the feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants