require-hook.js 973 B

12345678910111213141516171819202122232425262728293031
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = loadRequireHook;
  6. function loadRequireHook(aliases = []) {
  7. const hookPropertyMap = new Map([
  8. ...aliases,
  9. // Use `require.resolve` explicitly to make them statically analyzable
  10. [
  11. "styled-jsx",
  12. require.resolve("styled-jsx")
  13. ],
  14. [
  15. "styled-jsx/style",
  16. require.resolve("styled-jsx/style")
  17. ],
  18. ].map(([request, replacement])=>[
  19. request,
  20. replacement
  21. ]));
  22. const mod = require("module");
  23. const resolveFilename = mod._resolveFilename;
  24. mod._resolveFilename = function(request, parent, isMain, options) {
  25. const hookResolved = hookPropertyMap.get(request);
  26. if (hookResolved) request = hookResolved;
  27. return resolveFilename.call(mod, request, parent, isMain, options);
  28. };
  29. }
  30. //# sourceMappingURL=require-hook.js.map