get-module-name.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = getModuleName;
  6. {
  7. const originalGetModuleName = getModuleName;
  8. exports.default = getModuleName = function getModuleName(rootOpts, pluginOpts) {
  9. var _pluginOpts$moduleId, _pluginOpts$moduleIds, _pluginOpts$getModule, _pluginOpts$moduleRoo;
  10. return originalGetModuleName(rootOpts, {
  11. moduleId: (_pluginOpts$moduleId = pluginOpts.moduleId) != null ? _pluginOpts$moduleId : rootOpts.moduleId,
  12. moduleIds: (_pluginOpts$moduleIds = pluginOpts.moduleIds) != null ? _pluginOpts$moduleIds : rootOpts.moduleIds,
  13. getModuleId: (_pluginOpts$getModule = pluginOpts.getModuleId) != null ? _pluginOpts$getModule : rootOpts.getModuleId,
  14. moduleRoot: (_pluginOpts$moduleRoo = pluginOpts.moduleRoot) != null ? _pluginOpts$moduleRoo : rootOpts.moduleRoot
  15. });
  16. };
  17. }
  18. function getModuleName(rootOpts, pluginOpts) {
  19. const {
  20. filename,
  21. filenameRelative = filename,
  22. sourceRoot = pluginOpts.moduleRoot
  23. } = rootOpts;
  24. const {
  25. moduleId,
  26. moduleIds = !!moduleId,
  27. getModuleId,
  28. moduleRoot = sourceRoot
  29. } = pluginOpts;
  30. if (!moduleIds) return null;
  31. if (moduleId != null && !getModuleId) {
  32. return moduleId;
  33. }
  34. let moduleName = moduleRoot != null ? moduleRoot + "/" : "";
  35. if (filenameRelative) {
  36. const sourceRootReplacer = sourceRoot != null ? new RegExp("^" + sourceRoot + "/?") : "";
  37. moduleName += filenameRelative
  38. .replace(sourceRootReplacer, "")
  39. .replace(/\.(\w*?)$/, "");
  40. }
  41. moduleName = moduleName.replace(/\\/g, "/");
  42. if (getModuleId) {
  43. return getModuleId(moduleName) || moduleName;
  44. } else {
  45. return moduleName;
  46. }
  47. }
  48. //# sourceMappingURL=get-module-name.js.map