-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
add support for dynamic requests in require() and import() #7153
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
9 Ignored Deployments
|
🟢 Turbopack Benchmark CI successful 🟢Thanks |
✅ This change can build |
|
a4b8e3b
to
53f2bef
Compare
53f2bef
to
dd4f59b
Compare
dd4f59b
to
f472811
Compare
f472811
to
0be21e5
Compare
0be21e5
to
541fc3e
Compare
crates/turbopack-ecmascript-runtime/js/src/shared/runtime-utils.ts
Outdated
Show resolved
Hide resolved
}; | ||
match args.into_iter().next() { | ||
Some(ExprOrSpread { spread: None, expr: key_expr }) => { | ||
*expr = pm.create_import(*key_expr, import_externals); |
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.
It would be nice if pm.create_import
could return a CallExpr
so we could still use the visit_mut_call_expr
visitor
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.
Technically possible, but not sure if I want to put so much internal knowledge into the signature...
return Promise.resolve().then(() => { | ||
throw e; | ||
}); |
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.
return Promise.resolve().then(() => { | |
throw e; | |
}); | |
return Promise.reject(e); |
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.
That's different. Promise.reject causes an unhandled rejection, but promise resolve throw allows to register a catch before the promise is rejected
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.
This doesn't seem to be the case?
You can try running this in node.js:
const process = require('node:process');
process.on('unhandledRejection', (reason, promise) => {
console.log('Unhandled Rejection at:', promise, 'reason:', reason);
});
function willReject() {
return Promise.reject(new Error("rejected with error"))
}
async function willCatch() {
try {
await willReject()
} catch(e) {
console.error("caught in try catch", e)
}
}
willReject().catch((err) => console.error("caught in handler", err))
willCatch()
* flags: | ||
* * 1: Error as rejected promise | ||
*/ | ||
function moduleLookup( |
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.
maybe we can actually just combine this with requireContext
?
(for import we could add another property)
just need to copy the generic error from here and maybe expand commonJsRequireContext
in place instead of having it as a separate thing
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.
Yeah we should combine them. In a followup PR?
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 guess we can do that, will change all the snapshots again I guess
541fc3e
to
944df3d
Compare
97acf54
to
b20d452
Compare
Description
Refactors
PatternMatching
to support a map of multiple matches by key. Based on the newRequestKey
support for resolving.Code Generation for
require("./dir/"+ expr)
will emit a map of__turbopack_lookup__({ "./a": () => ..., "./b": () => ... }, "./dir/" + expr)
.The output format isn't really optimized yet, that's work for future PRs.
Testing Instructions
added a test case, enabled one previously skipped test case
Closes PACK-986