stealjs / steal

Gets JavaScript
https://stealjs.com
MIT License
1.36k stars 522 forks source link

Import rewrites before npm normalization #1522

Closed bmomberger-bitovi closed 3 years ago

bmomberger-bitovi commented 3 years ago

This is a special case for when:

An example is certain plugins based on jqueryUI, which used to be part of a jquery bundle with exports named like "jquery.ui.widget", but because we're modern and use NPM modules now, that module dependency would now be "jquery-ui/ui/widget". The "map" config option in Steal may experience a race condition where it misunderstands that these two module references should be normalized together.

To fix this, we introduce "importRewrites", a package-namespaced mapping that directly translates the import name a module requires into a different import name.

In package.json this looks like:

"steal": {
  "importRewrites": {
     "some-old-jquery-ui-widget": {
         "jquery.ui.widget": "jquery-ui/ui/widget"
     }
  }
}

and then steal will behave as if any module in some-old-jquery-ui-widget's source tree imported "jquery-ui/ui/widget" if that module imports "jquery.ui.widget".