utils.js 918 B

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.getModulePathParts = getModulePathParts;
  6. var _lodash = require('lodash');
  7. var _lodash2 = _interopRequireDefault(_lodash);
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  9. var MULTI_MODULE_REGEXP = /^multi /;
  10. function getModulePathParts(moduleData) {
  11. if (MULTI_MODULE_REGEXP.test(moduleData.identifier)) {
  12. return [moduleData.identifier];
  13. }
  14. var parsedPath = _lodash2.default
  15. // Removing loaders from module path: they're joined by `!` and the last part is a raw module path
  16. .last(moduleData.name.split('!'))
  17. // Splitting module path into parts
  18. .split('/')
  19. // Removing first `.`
  20. .slice(1)
  21. // Replacing `~` with `node_modules`
  22. .map(function (part) {
  23. return part === '~' ? 'node_modules' : part;
  24. });
  25. return parsedPath.length ? parsedPath : null;
  26. }