Skip to content

Conversation

@mansona
Copy link
Member

@mansona mansona commented Apr 25, 2025

Description

This PR is starting to split out the work from #2625

This just tries to make sure that there is only one module that is calling requireModule and we can provide alternatives for the different environments isolated to that module 👍

Screenshots

@BlueCutOfficial
Copy link
Contributor

Description

This PR is part of the basic implementation for Vite support. It's a refactoring step that centralizes the call to requireModule in one module when it's used to access the modules coming from ember-source. In other words, ember_debug/utils/ember.js should be responsible for how ember-source things are imported, and any other module that needs these things should import them from ember_debug/utils/ember.js.


@mansona can you explain with more details what you have in mind:

we can provide alternatives for the different environments isolated to that module.

Comment on lines -7 to -13
RSVP = module.default;

// The RSVP module should have named exports for `Promise`, etc,
// but some old versions do not and provide `RSVP.Promise`, etc.
if (!('Promise' in module)) {
module = RSVP;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know what version this code was supporting, nor how the assignment in the if block fixes what the comment says, but with this PR: the RSVP module we import is emberSafeRequire('rsvp')?.default; so the content of this block should probably be cleaned up.

Copy link
Member Author

Choose a reason for hiding this comment

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

I checked this against the oldest version of Ember that we support (3.16) and RSVP.Promise exists so it's safe to remove 👍

Comment on lines 15 to +18
// eslint-disable-next-line ember/new-module-imports
module = Ember?.run || module;
// eslint-disable-next-line ember/new-module-imports
_backburner = Ember?.run?.backburner || _backburner;
Copy link
Contributor

Choose a reason for hiding this comment

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

Just reverted those blocks so module is assigned before _backburner, because it's the order chosen at the top of the file so it eases the reading.

Comment on lines +4 to 7
// it could happen that runloop is available but _backburner is not exported (dead code)
// then we need to use our own.
let module = runloop;
let _backburner = runloop._backburner;
Copy link
Contributor

Choose a reason for hiding this comment

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

I moved the comment from the old try block here because it mentions a fallback on "our own" _backburner, which I assume corresponds to the default assignment at line 7? The one that used to be on line 13 was rather changing _backburner to something other than "our own" if requireModule('@ember/runloop') was not throwing.

@mansona
Copy link
Member Author

mansona commented Jun 11, 2025

@BlueCutOfficial thanks for the updates to this, it all looks good (I just can't approve my own PR 😂)

@mansona mansona merged commit de007c4 into emberjs:main Jun 11, 2025
19 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants