Skip to content

Commit bcb4259

Browse files
authored
Handle removal of "latestVersion" from extensions bundle configuration (#1272)
* DO NOT SUBMIT * fix auto extension importer to handle removal of "latestVersion" * fix version tests to actually use the latest version the original configuration did not actually update "latestVersion" * lint * revert removed code
1 parent 959e621 commit bcb4259

File tree

5 files changed

+21
-5
lines changed

5 files changed

+21
-5
lines changed

packages/optimizer/lib/extensionConfig.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

packages/optimizer/lib/transformers/AutoExtensionImporter.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,23 @@ class AutoExtensionImporter {
141141
if (!this.componentVersions) {
142142
this.componentVersions = {};
143143
for (const component of params.componentVersions) {
144-
this.componentVersions[component.name] = component.latestVersion;
144+
if (Array.isArray(component.version)) {
145+
// If version is an array then we need to find the highest value.
146+
// Note we need to preserve the "stringy"ness of these versions
147+
// so make sure we don't do any coercion or casting of the value
148+
// we assign.
149+
this.componentVersions[component.name] = component.version.reduce((prev, cur) => {
150+
return Number(prev) > Number(cur) ? prev : cur;
151+
});
152+
} else {
153+
this.componentVersions[component.name] =
154+
Number(component.version) >
155+
// Make sure to guard if the entry doesn't exist yet. We default
156+
// comparing to 0.
157+
Number(this.componentVersions[component.name] || 0)
158+
? component.version
159+
: this.componentVersions[component.name];
160+
}
145161
}
146162
}
147163
if (!this.extensionSpec_) {

packages/optimizer/spec/transformers/valid/AutoExtensionImporter/amp-carousel/expected_output.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<link rel="canonical" href="self.html">
77
<meta name="viewport" content="width=device-width,minimum-scale=1">
88
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
9-
<script async src="https://cdn.ampproject.org/v0.js"></script><script async src="https://cdn.ampproject.org/v0/amp-carousel-0.1.js" custom-element="amp-carousel"></script>
9+
<script async src="https://cdn.ampproject.org/v0.js"></script><script async src="https://cdn.ampproject.org/v0/amp-carousel-0.2.js" custom-element="amp-carousel"></script>
1010
</head>
1111
<body>
1212
<!-- this should only import amp-carousel and not amp-lightbox-gallery -->

packages/optimizer/spec/transformers/valid/AutoExtensionImporter/auto-imports-missing-extensions/expected_output.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<link rel="canonical" href="self.html">
77
<meta name="viewport" content="width=device-width,minimum-scale=1">
88
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
9-
<script async src="https://cdn.ampproject.org/v0.js"></script><script async src="https://cdn.ampproject.org/v0/amp-access-0.1.js" custom-element="amp-access"></script><script async src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js" custom-element="amp-analytics"></script><script async src="https://cdn.ampproject.org/v0/amp-twitter-0.1.js" custom-element="amp-twitter"></script><script async src="https://cdn.ampproject.org/v0/amp-bind-0.1.js" custom-element="amp-bind"></script><script async src="https://cdn.ampproject.org/v0/amp-fx-collection-0.1.js" custom-element="amp-fx-collection"></script><script async src="https://cdn.ampproject.org/v0/amp-video-0.1.js" custom-element="amp-video"></script><script async src="https://cdn.ampproject.org/v0/amp-video-docking-0.1.js" custom-element="amp-video-docking"></script><script async src="https://cdn.ampproject.org/v0/amp-lightbox-gallery-0.1.js" custom-element="amp-lightbox-gallery"></script><script async src="https://cdn.ampproject.org/v0/amp-inputmask-0.1.js" custom-element="amp-inputmask"></script><script async src="https://cdn.ampproject.org/v0/amp-list-0.1.js" custom-element="amp-list"></script><script async src="https://cdn.ampproject.org/v0/amp-mustache-0.2.js" custom-template="amp-mustache"></script>
9+
<script async src="https://cdn.ampproject.org/v0.js"></script><script async src="https://cdn.ampproject.org/v0/amp-access-0.1.js" custom-element="amp-access"></script><script async src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js" custom-element="amp-analytics"></script><script async src="https://cdn.ampproject.org/v0/amp-twitter-0.1.js" custom-element="amp-twitter"></script><script async src="https://cdn.ampproject.org/v0/amp-bind-0.1.js" custom-element="amp-bind"></script><script async src="https://cdn.ampproject.org/v0/amp-fx-collection-0.1.js" custom-element="amp-fx-collection"></script><script async src="https://cdn.ampproject.org/v0/amp-video-0.1.js" custom-element="amp-video"></script><script async src="https://cdn.ampproject.org/v0/amp-video-docking-0.1.js" custom-element="amp-video-docking"></script><script async src="https://cdn.ampproject.org/v0/amp-lightbox-gallery-1.0.js" custom-element="amp-lightbox-gallery"></script><script async src="https://cdn.ampproject.org/v0/amp-inputmask-0.1.js" custom-element="amp-inputmask"></script><script async src="https://cdn.ampproject.org/v0/amp-list-0.1.js" custom-element="amp-list"></script><script async src="https://cdn.ampproject.org/v0/amp-mustache-0.2.js" custom-template="amp-mustache"></script>
1010
<!-- imports amp-access based on JSON config -->
1111
<script id="amp-access" type="application/json">
1212
{

packages/optimizer/spec/transformers/valid/AutoExtensionImporter/uses-non-experimental-versions/expected_output.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<title>My AMP Page</title>
66
<link rel="canonical" href="self.html">
77
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
8-
<script async src="https://cdn.ampproject.org/v0.js"></script><script async src="https://cdn.ampproject.org/v0/amp-timeago-0.1.js" custom-element="amp-timeago"></script><script async src="https://cdn.ampproject.org/v0/amp-youtube-0.1.js" custom-element="amp-youtube"></script><script async src="https://cdn.ampproject.org/v0/amp-date-display-0.1.js" custom-element="amp-date-display"></script><script async src="https://cdn.ampproject.org/v0/amp-mustache-0.2.js" custom-template="amp-mustache"></script>
8+
<script async src="https://cdn.ampproject.org/v0.js"></script><script async src="https://cdn.ampproject.org/v0/amp-timeago-1.0.js" custom-element="amp-timeago"></script><script async src="https://cdn.ampproject.org/v0/amp-youtube-0.1.js" custom-element="amp-youtube"></script><script async src="https://cdn.ampproject.org/v0/amp-date-display-1.0.js" custom-element="amp-date-display"></script><script async src="https://cdn.ampproject.org/v0/amp-mustache-0.2.js" custom-template="amp-mustache"></script>
99
</head>
1010
<body>
1111
<!-- import non-bento component v0.1 instead of experimental bento v1.0 -->

0 commit comments

Comments
 (0)