Skip to content

Refactor the internal Ember loader to use the standard Ember CLI loader#19390

Merged
rwjblue merged 2 commits intomasterfrom
refactor-internal-loader
Feb 10, 2021
Merged

Refactor the internal Ember loader to use the standard Ember CLI loader#19390
rwjblue merged 2 commits intomasterfrom
refactor-internal-loader

Conversation

@pzuraq
Copy link
Contributor

@pzuraq pzuraq commented Feb 9, 2021

This PR refactors the internal Ember loader so that it uses the standard
Ember CLI loader instead for modules. This means that modules will be
defined in the main namespace, and importable from there, instead of in
a hidden namespace that only Ember can use.

Notes:

  • Code is still loaded and built via treeForVendor and included as a
    vendor file. This needs to be the case for the time being for
    bootstrapping.
  • Loader code is still included for Node support. If define and
    require are not already defined, then a backup shim is used instead.
  • Modules are now exposed from Ember, but ember-cli-babel still
    transpiles them to global references. This unblocks us from being able
    to make all modules work normally, however.
  • require shim module is no longer defined, we reference define and
    require as globals instead (which is more accurate). In the future
    we should update this to use Embroider's conventions.
  • __loader is still exposed on the Ember object, referencing the same
    values as before.

@pzuraq pzuraq force-pushed the refactor-internal-loader branch 2 times, most recently from b059b42 to b99fa0f Compare February 9, 2021 20:19
This PR refactors the internal Ember loader so that it uses the standard
Ember CLI loader instead for modules. This means that modules will be
defined in the main namespace, and importable from there, instead of in
a hidden namespace that only Ember can use.

Notes:

- Code is still loaded and built via `treeForVendor` and included as a
  vendor file. This needs to be the case for the time being for
  bootstrapping.
- Loader code is still included for Node support. If `define` and
  `require` are not already defined, then a backup shim is used instead.
- Modules are now exposed from Ember, but `ember-cli-babel` still
  transpiles them to global references. This unblocks us from being able
  to make all modules work normally, however.
- `require` shim module is no longer defined, we reference `define` and
  `require` as globals instead (which is more accurate). In the future
  we should update this to use Embroider's conventions.
- `__loader` is still exposed on the Ember object, referencing the same
  values as before.
@pzuraq pzuraq force-pushed the refactor-internal-loader branch from b99fa0f to be324d1 Compare February 9, 2021 23:10
Comment on lines +21 to +24
if (typeof globalObj.define === 'function' && typeof globalObj.require === 'function') {
define = globalObj.define;
require = globalObj.require;

Copy link
Member

Choose a reason for hiding this comment

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

I think we might need to accommodate the no conflict APIs for loader.js here

https://github.com/ember-cli/loader.js#no-conflict

Since loader doesn't expose loader.require/loader.define or a way to access what the "new" aliases are we can't do this just yet.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants