Skip to content

Commit

Permalink
Fixes Embroider Usage & ensures tests no longer mutate the global state
Browse files Browse the repository at this point in the history
 
Embroider wants to take over global defines, in-order to give them some specific treatments. Our tests in ember-resolver, where mutating the global loader by declaring it’s own global defines. 

Polluting the global state isn’t best practice, especially if there is a public API abstracting the global state. This PR 1) ensures the classic resolver always uses that abstraction 2) provides a test specific piece of state which implements the abstraction.
  • Loading branch information
stefanpenner committed Sep 9, 2021
1 parent 2e65a9b commit 0452261
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 85 deletions.
6 changes: 3 additions & 3 deletions addon/resolvers/classic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export class ModuleRegistry {
has(moduleName) {
return moduleName in this._entries;
}
get(moduleName) {
return require(moduleName);
get(...args) {
return require(...args);
}
}

Expand Down Expand Up @@ -471,7 +471,7 @@ const Resolver = EmberObject.extend({
},

_extractDefaultExport(normalizedModuleName) {
let module = require(normalizedModuleName, null, null, true /* force sync */);
let module = this._moduleRegistry.get(normalizedModuleName, null, null, true /* force sync */);

if (module && module['default']) {
module = module['default'];
Expand Down
Loading

0 comments on commit 0452261

Please sign in to comment.