-
-
Notifications
You must be signed in to change notification settings - Fork 104
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
Use loader aliases when using require invocations #634
Open
rajasegar
wants to merge
2
commits into
ember-cli:main
Choose a base branch
from
rajasegar:no-conflict
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* globals requirejs, require */ | ||
/* globals requirejs, require, loader */ | ||
|
||
import Ember from 'ember'; | ||
import { assert, deprecate, warn } from '@ember/debug'; | ||
|
@@ -13,7 +13,11 @@ if (typeof requirejs.entries === 'undefined') { | |
|
||
export class ModuleRegistry { | ||
constructor(entries) { | ||
this._entries = entries || requirejs.entries; | ||
if(loader.__aliases && loader.__aliases.requirejs) { | ||
this._entries = entries || window[loader.__aliases.requirejs].entries; | ||
} else { | ||
this._entries = entries || requirejs.entries; | ||
} | ||
} | ||
moduleNames() { | ||
return Object.keys(this._entries); | ||
|
@@ -466,7 +470,13 @@ const Resolver = EmberObject.extend({ | |
}, | ||
|
||
_extractDefaultExport(normalizedModuleName) { | ||
let module = require(normalizedModuleName, null, null, true /* force sync */); | ||
|
||
let module; | ||
if(loader.__aliases && loader.__aliases.require) { | ||
module = window[loader.__aliases.require](normalizedModuleName, null, null, true /* force sync */); | ||
} else { | ||
module = require(normalizedModuleName, null, null, true /* force sync */); | ||
} | ||
Comment on lines
+474
to
+479
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might be a little more resilient if you extracted a variable: const req = loader.__aliases?.require ? window[loader.__aliases.require] : require
const module = req(normalizedModuleName, null, null, true /* force sync */); |
||
|
||
if (module && module['default']) { | ||
module = module['default']; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should import require from require, then we'd get the one we want automatically
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry @rwjblue I don't get it, can you please elaborate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe he wants to to
import require from 'require'