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

🏗 custom-elements-polyfill.js is now bento.js, and async #36431

Merged
merged 7 commits into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 5 additions & 5 deletions build-system/compile/bundles.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ exports.jsBundles = {
destDir: './build/',
minifiedDestDir: './build/',
},
'custom-elements-polyfill.js': {
srcDir: 'src/polyfills/',
srcFilename: 'custom-elements-entrypoint.js',
'bento.js': {
srcDir: './src/',
srcFilename: 'bento.js',
destDir: './dist',
minifiedDestDir: './dist',
options: {
toName: 'custom-elements-polyfill.max.js',
toName: 'bento.max.js',
includePolyfills: false,
minifiedName: 'custom-elements-polyfill.js',
minifiedName: 'bento.js',
},
},
'alp.max.js': {
Expand Down
2 changes: 2 additions & 0 deletions build-system/compile/compile-wrappers.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,6 @@ function extensionPayload(name, version, latest, isModule, loadPriority) {
);
}

exports.bento = '(self.BENTO=self.BENTO||[]).push(function(){<%= contents %>})';

exports.none = '<%= contents %>';
2 changes: 1 addition & 1 deletion build-system/tasks/extension-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ async function buildBentoExtensionJs(dir, name, options) {
const bentoName = getBentoName(name);
return buildExtensionJs(dir, bentoName, {
...options,
wrapper: 'none',
wrapper: 'bento',
filename: await getBentoFilename(dir, bentoName, options),
// Include extension directory since our entrypoint may be elsewhere.
extraGlobs: [...(options.extraGlobs || []), `${dir}/**/*.js`],
Expand Down
9 changes: 8 additions & 1 deletion build-system/tasks/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const esbuild = require('esbuild');
/** @type {Object} */
const experimentDefines = require('../global-configs/experiments-const.json');
const fs = require('fs-extra');
const globby = require('globby');
const magicstring = require('magic-string');
const open = require('open');
const path = require('path');
Expand Down Expand Up @@ -148,7 +149,7 @@ async function compileAllJs(options) {
const startTime = Date.now();
await Promise.all([
minify ? Promise.resolve() : doBuildJs(jsBundles, 'polyfills.js', options),
doBuildJs(jsBundles, 'custom-elements-polyfill.js', options),
doBuildJs(jsBundles, 'bento.js', options),
doBuildJs(jsBundles, 'alp.max.js', options),
doBuildJs(jsBundles, 'integration.js', options),
doBuildJs(jsBundles, 'ampcontext-lib.js', options),
Expand All @@ -163,6 +164,12 @@ async function compileAllJs(options) {
doBuildJs(jsBundles, 'amp-inabox.js', options),
]);
await compileCoreRuntime(options);

alanorozco marked this conversation as resolved.
Show resolved Hide resolved
// TODO(alanorozco): Is there a cleaner way to create this alias?
alanorozco marked this conversation as resolved.
Show resolved Hide resolved
for (const file of await globby('dist/bento.*js')) {
await fs.copy(file, file.replace('/bento.', '/custom-elements-polyfill.'));
}
alanorozco marked this conversation as resolved.
Show resolved Hide resolved

endBuildStep(
minify ? 'Minified' : 'Compiled',
'all runtime JS files',
Expand Down
7 changes: 5 additions & 2 deletions examples/bento/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
name="viewport"
content="width=device-width,minimum-scale=1,initial-scale=1"
/>
<script src="https://cdn.ampproject.org/custom-elements-polyfill.js"></script>
<script async src="https://cdn.ampproject.org/v0/bento-video-1.0.js"></script>
<script async src="https://cdn.ampproject.org/bento.js"></script>
<script
async
src="https://cdn.ampproject.org/v0/bento-video-1.0.js"
></script>
</head>
<body>
<bento-video
Expand Down
2 changes: 1 addition & 1 deletion examples/bento/no-v0.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
border: 1px solid black;
}
</style>
<script src="https://cdn.ampproject.org/custom-elements-polyfill.js"></script>
<script async src="https://cdn.ampproject.org/bento.js"></script>
<script
async
src="https://cdn.ampproject.org/v0/bento-timeago-1.0.js"
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-accordion/1.0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ The example below contains an `bento-accordion` with three sections. The

```html
<head>
<script src="https://cdn.ampproject.org/custom-elements-polyfill.js"></script>
<script async src="https://cdn.ampproject.org/bento.js"></script>
<script async src="https://cdn.ampproject.org/v0/bento-accordion-1.0.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.ampproject.org/v0/amp-accordion-1.0.css">
</head>
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-base-carousel/1.0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import '@ampproject/bento-base-carousel';

```html
<head>
<script src="https://cdn.ampproject.org/custom-elements-polyfill.js"></script>
<script async src="https://cdn.ampproject.org/bento.js"></script>
<!-- These styles prevent Cumulative Layout Shift on the unupgraded custom element -->
<style data-bento-boilerplate>
bento-base-carousel {
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-date-countdown/1.0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ The example below contains an `bento-date-countdown` with three sections. The

```html
<head>
<script src="https://cdn.ampproject.org/custom-elements-polyfill.js"></script>
<script async src="https://cdn.ampproject.org/bento.js"></script>
<script async src="https://cdn.ampproject.org/v0/bento-date-countdown-1.0.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.ampproject.org/v0/bento-date-countdown-1.0.css">
</head>
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-date-display/1.0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The example below contains an `bento-date-display` with three sections. The

```html
<head>
<script src="https://cdn.ampproject.org/custom-elements-polyfill.js"></script>
<script async src="https://cdn.ampproject.org/bento.js"></script>
<script async src="https://cdn.ampproject.org/v0/bento-date-display-1.0.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.ampproject.org/v0/bento-date-display-1.0.css">
</head>
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-embedly-card/1.0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import '@ampproject/bento-embedly-card';

```html
<head>
<script src="https://cdn.ampproject.org/custom-elements-polyfill.js"></script>
<script async src="https://cdn.ampproject.org/bento.js"></script>
<!-- These styles prevent Cumulative Layout Shift on the unupgraded custom element -->
<style data-bento-boilerplate>
bento-embedly-card {
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-facebook/1.0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import '@ampproject/bento-facebook';

```html
<head>
<script src="https://cdn.ampproject.org/custom-elements-polyfill.js"></script>
<script async src="https://cdn.ampproject.org/bento.js"></script>
<!-- These styles prevent Cumulative Layout Shift on the unupgraded custom element -->
<style data-bento-boilerplate>
bento-facebook {
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-fit-text/1.0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import '@ampproject/bento-fit-text';

```html
<head>
<script src="https://cdn.ampproject.org/custom-elements-polyfill.js"></script>
<script async src="https://cdn.ampproject.org/bento.js"></script>
<!-- These styles prevent Cumulative Layout Shift on the unupgraded custom element -->
<script async custom-element="bento-fit-text" src="https://cdn.ampproject.org/v0/bento-fit-text-1.0.js"></script>
<style data-bento-boilerplate>
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-inline-gallery/1.0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The example below contains a `bento-inline-gallery` consisting of three slides w

```html
<head>
<script src="https://cdn.ampproject.org/custom-elements-polyfill.js"></script>
<script async src="https://cdn.ampproject.org/bento.js"></script>
<script async src="https://cdn.ampproject.org/v0/bento-inline-gallery-1.0.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.ampproject.org/v0/amp-inline-gallery-1.0.css">
</head>
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-jwplayer/1.0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ The example below contains an `bento-jwplayer` with three sections. The

```html
<head>
<script src="https://cdn.ampproject.org/custom-elements-polyfill.js"></script>
<script async src="https://cdn.ampproject.org/bento.js"></script>
<script async src="https://cdn.ampproject.org/v0/bento-jwplayer-1.0.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.ampproject.org/v0/bento-jwplayer-1.0.css">
</head>
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-lightbox-gallery/1.0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import '@ampproject/bento-lightbox-gallery';

```html
<head>
<script src="https://cdn.ampproject.org/custom-elements-polyfill.js"></script>
<script async src="https://cdn.ampproject.org/bento.js"></script>
<!-- These styles prevent Cumulative Layout Shift on the unupgraded custom element -->
<style data-bento-boilerplate>
bento-lightbox-gallery[hidden] {
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-mathml/1.0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ The example below contains an `bento-mathml` with three sections. The

```html
<head>
<script src="https://cdn.ampproject.org/custom-elements-polyfill.js"></script>
<script async src="https://cdn.ampproject.org/bento.js"></script>
<script async src="https://cdn.ampproject.org/v0/bento-mathml-1.0.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.ampproject.org/v0/bento-mathml-1.0.css">
</head>
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-selector/1.0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import '@ampproject/bento-selector';

```html
<head>
<script src="https://cdn.ampproject.org/custom-elements-polyfill.js"></script>
<script async src="https://cdn.ampproject.org/bento.js"></script>
<!-- These styles prevent Cumulative Layout Shift on the unupgraded custom element -->
<style data-bento-boilerplate>
bento-selector {
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-soundcloud/1.0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import '@ampproject/bento-soundcloud';

```html
<head>
<script src="https://cdn.ampproject.org/custom-elements-polyfill.js"></script>
<script async src="https://cdn.ampproject.org/bento.js"></script>
<!-- These styles prevent Cumulative Layout Shift on the unupgraded custom element -->
<style data-bento-boilerplate>
bento-soundcloud {
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-stream-gallery/1.0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ The example below contains an `bento-stream-gallery` with three sections. The

```html
<head>
<script src="https://cdn.ampproject.org/custom-elements-polyfill.js"></script>
<script async src="https://cdn.ampproject.org/bento.js"></script>
<script async src="https://cdn.ampproject.org/v0/bento-stream-gallery-1.0.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.ampproject.org/v0/amp-streamGallery-1.0.css">

Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-twitter/1.0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import '@ampproject/bento-twitter';

```html
<head>
<script src="https://cdn.ampproject.org/custom-elements-polyfill.js"></script>
<script async src="https://cdn.ampproject.org/bento.js"></script>
<!-- These styles prevent Cumulative Layout Shift on the unupgraded custom element -->
<style data-bento-boilerplate>
bento-twitter {
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-wordpress-embed/1.0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import '@ampproject/bento-wordpress-embed';

```html
<head>
<script src="https://cdn.ampproject.org/custom-elements-polyfill.js"></script>
<script async src="https://cdn.ampproject.org/bento.js"></script>
<!-- These styles prevent Cumulative Layout Shift on the unupgraded custom element -->
<style data-bento-boilerplate>
bento-wordpress-embed {
Expand Down
21 changes: 21 additions & 0 deletions src/bento.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @fileoverview
* Entry point for `bento.js`
*/

import {install as installCustomElements} from './polyfills/custom-elements';

installCustomElements(self);

const BENTO = self.BENTO || [];

BENTO.push = (fn) => {
fn();
};

// eslint-disable-next-line local/window-property-name
self.BENTO = BENTO;

for (let i = 0; i < BENTO.length; i++) {
BENTO.push(BENTO[i]);
alanorozco marked this conversation as resolved.
Show resolved Hide resolved
}
8 changes: 0 additions & 8 deletions src/polyfills/custom-elements-entrypoint.js

This file was deleted.

22 changes: 9 additions & 13 deletions test/e2e/test-bento.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
const attachesShadowRoot = {
'without v0.js': 'bento/minimal.html',
'without v0.js nor custom-elements-polyfill.js': 'bento/no-ce-polyfill.html',
};

for (const [name, fixture] of Object.entries(attachesShadowRoot)) {
const config = {
describes.endtoend(
'Bento',
{
environments: ['single'],
fixture,
};
describes.endtoend('Bento', config, async function (env) {
it(`attaches shadow root ${name}`, async () => {
fixture: 'bento/minimal.html',
},
async function (env) {
it('attaches shadow root without v0.js', async () => {
// Set timeout lower than default in order to fail early, since the root
// is attached as soon as possible.
// (Feel free to increase if flaky.)
Expand All @@ -31,5 +27,5 @@ for (const [name, fixture] of Object.entries(attachesShadowRoot)) {
);
await expect(shadowRoot).ok;
});
});
}
}
);
2 changes: 1 addition & 1 deletion test/fixtures/e2e/bento/minimal.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
name="viewport"
content="width=device-width,minimum-scale=1,initial-scale=1"
/>
<script src="https://cdn.ampproject.org/custom-elements-polyfill.js"></script>
<script async src="https://cdn.ampproject.org/bento.js"></script>
<script
async
src="https://cdn.ampproject.org/v0/bento-timeago-1.0.js"
Expand Down
26 changes: 0 additions & 26 deletions test/fixtures/e2e/bento/no-ce-polyfill.html

This file was deleted.