get-module-name.js 1.7 KB

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