-
Notifications
You must be signed in to change notification settings - Fork 2.1k
add support for dynamic requests in require() and import() #7153
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
Changes from all commits
551d591
57c2391
f7a7a93
93463b7
a3d5b7c
eab19ee
1d3222b
b709cb0
8e565b6
bb8429b
6bae84a
1cf7872
b71353f
c711bdc
7fab83a
be023cf
b20d452
fc36d65
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -142,6 +142,28 @@ function dynamicExport( | |||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Access one entry from a mapping from name to functor. | ||||||||||
| */ | ||||||||||
| function moduleLookup( | ||||||||||
|
Contributor
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. maybe we can actually just combine this with just need to copy the generic error from here and maybe expand
Member
Author
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. Yeah we should combine them. In a followup PR?
Contributor
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. I guess we can do that, will change all the snapshots again I guess |
||||||||||
| map: Record<string, () => any>, | ||||||||||
| name: string, | ||||||||||
| returnPromise: boolean = false | ||||||||||
| ) { | ||||||||||
| if (hasOwnProperty.call(map, name)) { | ||||||||||
| return map[name](); | ||||||||||
| } | ||||||||||
| const e = new Error(`Cannot find module '${name}'`); | ||||||||||
| (e as any).code = "MODULE_NOT_FOUND"; | ||||||||||
| if (returnPromise) { | ||||||||||
| return Promise.resolve().then(() => { | ||||||||||
| throw e; | ||||||||||
| }); | ||||||||||
|
Comment on lines
+159
to
+161
Contributor
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.
Suggested change
Member
Author
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. That's different. Promise.reject causes an unhandled rejection, but promise resolve throw allows to register a catch before the promise is rejected
Contributor
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 doesn't seem to be the case? You can try running this in node.js: |
||||||||||
| } else { | ||||||||||
| throw e; | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| function exportValue(module: Module, value: any) { | ||||||||||
| module.exports = value; | ||||||||||
| } | ||||||||||
|
|
||||||||||
Uh oh!
There was an error while loading. Please reload this page.