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

🏗 Share dependencies in bento.js #36432

Merged
merged 37 commits into from
Dec 9, 2021

Conversation

alanorozco
Copy link
Member

@alanorozco alanorozco commented Oct 20, 2021

Partial for #36421

bento-*.js files now use shared modules from a global BENTO.

Shared modules are listed on shared-bento-symbols.js.

  • We generate bento.js to import and provide the dependencies based on this list. We also generate bento-shared.js to use the dependencies from the global.

  • bento-*.js binaries use module-resolver so that the listed imports are replaced with bento-shared.js.

Also adds the flag --bento_runtime_only.

@alanorozco alanorozco force-pushed the bento-runtime branch 7 times, most recently from 88908f1 to a8ba389 Compare October 20, 2021 23:34
@alanorozco alanorozco marked this pull request as ready for review October 21, 2021 17:25
@amp-owners-bot
Copy link

amp-owners-bot bot commented Oct 21, 2021

Hey @erwinmombay, @jridgewell! These files were changed:

build-system/babel-plugins/babel-plugin-bento-imports/index.js
build-system/babel-plugins/babel-plugin-bento-imports/test/fixtures/transform-assertions/ignored/input.mjs
build-system/babel-plugins/babel-plugin-bento-imports/test/fixtures/transform-assertions/ignored/output.mjs
build-system/babel-plugins/babel-plugin-bento-imports/test/fixtures/transform-assertions/local-name/input.mjs
build-system/babel-plugins/babel-plugin-bento-imports/test/fixtures/transform-assertions/local-name/output.mjs
build-system/babel-plugins/babel-plugin-bento-imports/test/fixtures/transform-assertions/mixed/input.mjs
build-system/babel-plugins/babel-plugin-bento-imports/test/fixtures/transform-assertions/mixed/output.mjs
build-system/babel-plugins/babel-plugin-bento-imports/test/fixtures/transform-assertions/namespace/input.mjs
build-system/babel-plugins/babel-plugin-bento-imports/test/fixtures/transform-assertions/namespace/output.mjs
build-system/babel-plugins/babel-plugin-bento-imports/test/fixtures/transform-assertions/options.json
build-system/babel-plugins/babel-plugin-bento-imports/test/fixtures/transform-assertions/preserved/input.mjs
build-system/babel-plugins/babel-plugin-bento-imports/test/fixtures/transform-assertions/preserved/output.mjs
+1 more

@alanorozco alanorozco force-pushed the bento-runtime branch 2 times, most recently from 0669e0f to fde7238 Compare October 25, 2021 21:16
@alanorozco alanorozco marked this pull request as draft October 25, 2021 21:24
@alanorozco alanorozco force-pushed the bento-runtime branch 4 times, most recently from 84708c9 to 46d9798 Compare October 27, 2021 18:47
@alanorozco alanorozco force-pushed the bento-runtime branch 2 times, most recently from bab442a to b628cc1 Compare November 16, 2021 01:18
@alanorozco alanorozco marked this pull request as ready for review November 16, 2021 17:11
Copy link
Member

@samouri samouri left a comment

Choose a reason for hiding this comment

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

Did we ever discuss why we are pursuing this approach vs. the naive way?

My impression is that naively we could manually add all of the imports into bento.js like so:

// bento.js
import {PreactBaseElement} from '#preact/base-element';
window.BENTO['PreactBaseElement'] = PreactBaseElement;

// amp-fit-text/1.0/base-element.js
class FitText extends window.BENTO.PreactBaseElement {
 ...
}

I think what you've written in this PR is a babel transform which automatically performs the same translation right? That means we don't need to modify the source and can easily update which modules are included in bento.js over time.

@alanorozco
Copy link
Member Author

@samouri

  • Adding them to bento.js source manually would be fine, just somewhat tedious.
  • The AMP layer bundles the dependencies, so we can't change the extension source to use self.BENTO.
  • We can get rid of the transform if we restructure the packages so they only include what we'd like share. If so, we can use an early module-resolver

@samouri
Copy link
Member

samouri commented Dec 8, 2021

@alanorozco: are there any blockers for this PR?

@alanorozco alanorozco merged commit faf69c4 into ampproject:main Dec 9, 2021
@alanorozco alanorozco deleted the bento-runtime branch December 9, 2021 19:56
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.

5 participants