previous-map.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.default = void 0;
  4. var _sourceMap = _interopRequireDefault(require("source-map"));
  5. var _path = _interopRequireDefault(require("path"));
  6. var _fs = _interopRequireDefault(require("fs"));
  7. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  8. function fromBase64(str) {
  9. if (Buffer) {
  10. return Buffer.from(str, 'base64').toString();
  11. } else {
  12. return window.atob(str);
  13. }
  14. }
  15. /**
  16. * Source map information from input CSS.
  17. * For example, source map after Sass compiler.
  18. *
  19. * This class will automatically find source map in input CSS or in file system
  20. * near input file (according `from` option).
  21. *
  22. * @example
  23. * const root = postcss.parse(css, { from: 'a.sass.css' })
  24. * root.input.map //=> PreviousMap
  25. */
  26. var PreviousMap =
  27. /*#__PURE__*/
  28. function () {
  29. /**
  30. * @param {string} css Input CSS source.
  31. * @param {processOptions} [opts] {@link Processor#process} options.
  32. */
  33. function PreviousMap(css, opts) {
  34. this.loadAnnotation(css);
  35. /**
  36. * Was source map inlined by data-uri to input CSS.
  37. *
  38. * @type {boolean}
  39. */
  40. this.inline = this.startWith(this.annotation, 'data:');
  41. var prev = opts.map ? opts.map.prev : undefined;
  42. var text = this.loadMap(opts.from, prev);
  43. if (text) this.text = text;
  44. }
  45. /**
  46. * Create a instance of `SourceMapGenerator` class
  47. * from the `source-map` library to work with source map information.
  48. *
  49. * It is lazy method, so it will create object only on first call
  50. * and then it will use cache.
  51. *
  52. * @return {SourceMapGenerator} Object with source map information.
  53. */
  54. var _proto = PreviousMap.prototype;
  55. _proto.consumer = function consumer() {
  56. if (!this.consumerCache) {
  57. this.consumerCache = new _sourceMap.default.SourceMapConsumer(this.text);
  58. }
  59. return this.consumerCache;
  60. }
  61. /**
  62. * Does source map contains `sourcesContent` with input source text.
  63. *
  64. * @return {boolean} Is `sourcesContent` present.
  65. */
  66. ;
  67. _proto.withContent = function withContent() {
  68. return !!(this.consumer().sourcesContent && this.consumer().sourcesContent.length > 0);
  69. };
  70. _proto.startWith = function startWith(string, start) {
  71. if (!string) return false;
  72. return string.substr(0, start.length) === start;
  73. };
  74. _proto.loadAnnotation = function loadAnnotation(css) {
  75. var match = css.match(/\/\*\s*# sourceMappingURL=(.*)\s*\*\//);
  76. if (match) this.annotation = match[1].trim();
  77. };
  78. _proto.decodeInline = function decodeInline(text) {
  79. var baseCharsetUri = /^data:application\/json;charset=utf-?8;base64,/;
  80. var baseUri = /^data:application\/json;base64,/;
  81. var uri = 'data:application/json,';
  82. if (this.startWith(text, uri)) {
  83. return decodeURIComponent(text.substr(uri.length));
  84. }
  85. if (baseCharsetUri.test(text) || baseUri.test(text)) {
  86. return fromBase64(text.substr(RegExp.lastMatch.length));
  87. }
  88. var encoding = text.match(/data:application\/json;([^,]+),/)[1];
  89. throw new Error('Unsupported source map encoding ' + encoding);
  90. };
  91. _proto.loadMap = function loadMap(file, prev) {
  92. if (prev === false) return false;
  93. if (prev) {
  94. if (typeof prev === 'string') {
  95. return prev;
  96. } else if (typeof prev === 'function') {
  97. var prevPath = prev(file);
  98. if (prevPath && _fs.default.existsSync && _fs.default.existsSync(prevPath)) {
  99. return _fs.default.readFileSync(prevPath, 'utf-8').toString().trim();
  100. } else {
  101. throw new Error('Unable to load previous source map: ' + prevPath.toString());
  102. }
  103. } else if (prev instanceof _sourceMap.default.SourceMapConsumer) {
  104. return _sourceMap.default.SourceMapGenerator.fromSourceMap(prev).toString();
  105. } else if (prev instanceof _sourceMap.default.SourceMapGenerator) {
  106. return prev.toString();
  107. } else if (this.isMap(prev)) {
  108. return JSON.stringify(prev);
  109. } else {
  110. throw new Error('Unsupported previous source map format: ' + prev.toString());
  111. }
  112. } else if (this.inline) {
  113. return this.decodeInline(this.annotation);
  114. } else if (this.annotation) {
  115. var map = this.annotation;
  116. if (file) map = _path.default.join(_path.default.dirname(file), map);
  117. this.root = _path.default.dirname(map);
  118. if (_fs.default.existsSync && _fs.default.existsSync(map)) {
  119. return _fs.default.readFileSync(map, 'utf-8').toString().trim();
  120. } else {
  121. return false;
  122. }
  123. }
  124. };
  125. _proto.isMap = function isMap(map) {
  126. if (typeof map !== 'object') return false;
  127. return typeof map.mappings === 'string' || typeof map._mappings === 'string';
  128. };
  129. return PreviousMap;
  130. }();
  131. var _default = PreviousMap;
  132. exports.default = _default;
  133. module.exports = exports.default;
  134. //# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInByZXZpb3VzLW1hcC5lczYiXSwibmFtZXMiOlsiZnJvbUJhc2U2NCIsInN0ciIsIkJ1ZmZlciIsImZyb20iLCJ0b1N0cmluZyIsIndpbmRvdyIsImF0b2IiLCJQcmV2aW91c01hcCIsImNzcyIsIm9wdHMiLCJsb2FkQW5ub3RhdGlvbiIsImlubGluZSIsInN0YXJ0V2l0aCIsImFubm90YXRpb24iLCJwcmV2IiwibWFwIiwidW5kZWZpbmVkIiwidGV4dCIsImxvYWRNYXAiLCJjb25zdW1lciIsImNvbnN1bWVyQ2FjaGUiLCJtb3ppbGxhIiwiU291cmNlTWFwQ29uc3VtZXIiLCJ3aXRoQ29udGVudCIsInNvdXJjZXNDb250ZW50IiwibGVuZ3RoIiwic3RyaW5nIiwic3RhcnQiLCJzdWJzdHIiLCJtYXRjaCIsInRyaW0iLCJkZWNvZGVJbmxpbmUiLCJiYXNlQ2hhcnNldFVyaSIsImJhc2VVcmkiLCJ1cmkiLCJkZWNvZGVVUklDb21wb25lbnQiLCJ0ZXN0IiwiUmVnRXhwIiwibGFzdE1hdGNoIiwiZW5jb2RpbmciLCJFcnJvciIsImZpbGUiLCJwcmV2UGF0aCIsImZzIiwiZXhpc3RzU3luYyIsInJlYWRGaWxlU3luYyIsIlNvdXJjZU1hcEdlbm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gcmV0dXJuIHByZXZcbiAgICAgIH0gZWxzZSBpZiAodHlwZW9mIHByZXYgPT09ICdmdW5jdGlvbicpIHtcbiAgICAgICAgbGV0IHByZXZQYXRoID0gcHJldihmaWxlKVxuICAgICAgICBpZiAocHJldlBhdGggJiYgZnMuZXhpc3RzU3luYyAmJiBmcy5leGlzdHNTeW5jKHByZXZQYXRoKSkge1xuICAgICAgICAgIHJldHVybiBmcy5yZWFkRmlsZVN5bmMocHJldlBhdGgsICd1dGYtOCcpLnRvU3RyaW5nKCkudHJpbSgpXG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgdGhyb3cgbmV3IEVycm9yKFxuICAgICAgICAgICAgJ1VuYWJsZSB0byBsb2FkIHByZXZpb3VzIHNvdXJjZSBtYXA6ICcgKyBwcmV2UGF0aC50b1N0cmluZygpKVxuICAgICAgICB9XG4gICAgICB9IGVsc2UgaWYgKHByZXYgaW5zdGFuY2VvZiBtb3ppbGxhLlNvdXJjZU1hcENvbnN1bWVyKSB7XG4gICAgICAgIHJldHVybiBtb3ppbGxhLlNvdXJjZU1hcEdlbmVyYXRvci5mcm9tU291cmNlTWFwKHByZXYpLnRvU3RyaW5nKClcbiAgICAgIH0gZWxzZSBpZiAocHJldiBpbnN0YW5jZW9mIG1vemlsbGEuU291cmNlTWFwR2VuZXJhdG9yKSB7XG4gICAgICAgIHJldHVybiBwcmV2LnRvU3RyaW5nKClcbiAgICAgIH0gZWxzZSBpZiAodGhpcy5pc01hcChwcmV2KSkge1xuICAgICAgICByZXR1cm4gSlNPTi5zdHJpbmdpZnkocHJldilcbiAgICAgIH0gZWxzZSB7XG4gICAgICAgIHRocm93IG5ldyBFcnJvcihcbiAgICAgICAgICAnVW5zdXBwb3J0ZWQgcHJldmlvdXMgc291cmNlIG1hcCBmb3JtYXQ6ICcgKyBwcmV2LnRvU3RyaW5nKCkpXG4gICAgICB9XG4gICAgfSBlbHNlIGlmICh0aGlzLmlubGluZSkge1xuICAgICAgcmV0dXJuIH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