You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.2 KiB

4 years ago
  1. 'use strict';
  2. var projectRelative = require('./project-relative');
  3. /**
  4. * Codec for relative paths with respect to the context directory, preceded by a webpack:// protocol.
  5. * @type {{name:string, decode: function, encode: function, root: function}}
  6. */
  7. module.exports = {
  8. name : 'webpack-protocol',
  9. decode: decode,
  10. encode: encode,
  11. root : root
  12. };
  13. /**
  14. * Decode the given uri.
  15. * @this {{options: object}} A loader or compilation
  16. * @param {string} uri A source uri to decode
  17. * @returns {boolean|string} False where unmatched else the decoded path
  18. */
  19. function decode(uri) {
  20. /* jshint validthis:true */
  21. var analysis = /^webpack:\/{2}(.*)$/.exec(uri);
  22. return !!analysis && projectRelative.decode.call(this, analysis[1]);
  23. }
  24. /**
  25. * Encode the given file path.
  26. * @this {{options: object}} A loader or compilation
  27. * @param {string} absolute An absolute file path to encode
  28. * @returns {string} A uri
  29. */
  30. function encode(absolute) {
  31. /* jshint validthis:true */
  32. return 'webpack://' + projectRelative.encode.call(this, absolute);
  33. }
  34. /**
  35. * The source-map root where relevant.
  36. * @this {{options: object}} A loader or compilation
  37. * @returns {string|undefined} The source-map root applicable to any encoded uri
  38. */
  39. function root() {
  40. }