-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(compartment-mapper): Defer all importHook errors when importing a… (
#2610) … dependency if they're intended to be deferred ## Description When importHook is used to load dependencies, they might be coming from `imports` that were identified by a parser that uses heuristics to find them. (e.g. cjs parser implementation uses a lexer to find all `require` calls even if they're not _the_ require function but a local require function) In such cases we want to defer loading errors to runtime, so the error doesn't happen until actual `require` is _actually_ called to get it. That was true for loading known dependency, but exit modules (via exitModuleImportHook) were not covered. ### Security Considerations no changes security-wise ### Scaling Considerations The way this is currently implemented - one big try-catch instead of returning the deferred error without throwing and catching, might be less performant. Should we consider trading aesthetics for a tiny performance gain here? Note this only makes a difference for cases where non-dynamic `require` is called on a specifier that causes an error. ### Documentation Considerations It's a fix of unintended behavior. No changes to what needs to be documented. ### Testing Considerations Fix was added test-first ### Compatibility Considerations Compatibility is improved. Packages can now do: ```js try { require('my-dev-dependency') } catch(){} ``` to silently attempt to load something that is only useful in their own development process. (typescript does that) ### Upgrade Considerations While it's a fix, not a breaking change, it does change one specific behavior - an error resulting from calling exitModuleImportHook (the `importHook` passed to compartment-mapper, not the one in Compartment options) is now thrown at runtime, not during loading, which could be noteworthy for the Archive use-case. [(insert mandatory xkcd about breaking changes)](https://xkcd.com/1172/) --------- Co-authored-by: Christopher Hiller <boneskull@boneskull.com>
- Loading branch information
Showing
3 changed files
with
89 additions
and
67 deletions.
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
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
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