previous-map.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 = /*#__PURE__*/function () {
  27. /**
  28. * @param {string} css Input CSS source.
  29. * @param {processOptions} [opts] {@link Processor#process} options.
  30. */
  31. function PreviousMap(css, opts) {
  32. this.loadAnnotation(css);
  33. /**
  34. * Was source map inlined by data-uri to input CSS.
  35. *
  36. * @type {boolean}
  37. */
  38. this.inline = this.startWith(this.annotation, 'data:');
  39. var prev = opts.map ? opts.map.prev : undefined;
  40. var text = this.loadMap(opts.from, prev);
  41. if (text) this.text = text;
  42. }
  43. /**
  44. * Create a instance of `SourceMapGenerator` class
  45. * from the `source-map` library to work with source map information.
  46. *
  47. * It is lazy method, so it will create object only on first call
  48. * and then it will use cache.
  49. *
  50. * @return {SourceMapGenerator} Object with source map information.
  51. */
  52. var _proto = PreviousMap.prototype;
  53. _proto.consumer = function consumer() {
  54. if (!this.consumerCache) {
  55. this.consumerCache = new _sourceMap.default.SourceMapConsumer(this.text);
  56. }
  57. return this.consumerCache;
  58. }
  59. /**
  60. * Does source map contains `sourcesContent` with input source text.
  61. *
  62. * @return {boolean} Is `sourcesContent` present.
  63. */
  64. ;
  65. _proto.withContent = function withContent() {
  66. return !!(this.consumer().sourcesContent && this.consumer().sourcesContent.length > 0);
  67. };
  68. _proto.startWith = function startWith(string, start) {
  69. if (!string) return false;
  70. return string.substr(0, start.length) === start;
  71. };
  72. _proto.getAnnotationURL = function getAnnotationURL(sourceMapString) {
  73. return sourceMapString.match(/\/\*\s*# sourceMappingURL=((?:(?!sourceMappingURL=).)*)\*\//)[1].trim();
  74. };
  75. _proto.loadAnnotation = function loadAnnotation(css) {
  76. var annotations = css.match(/\/\*\s*# sourceMappingURL=(?:(?!sourceMappingURL=).)*\*\//gm);
  77. if (annotations && annotations.length > 0) {
  78. // Locate the last sourceMappingURL to avoid picking up
  79. // sourceMappingURLs from comments, strings, etc.
  80. var lastAnnotation = annotations[annotations.length - 1];
  81. if (lastAnnotation) {
  82. this.annotation = this.getAnnotationURL(lastAnnotation);
  83. }
  84. }
  85. };
  86. _proto.decodeInline = function decodeInline(text) {
  87. var baseCharsetUri = /^data:application\/json;charset=utf-?8;base64,/;
  88. var baseUri = /^data:application\/json;base64,/;
  89. var uri = 'data:application/json,';
  90. if (this.startWith(text, uri)) {
  91. return decodeURIComponent(text.substr(uri.length));
  92. }
  93. if (baseCharsetUri.test(text) || baseUri.test(text)) {
  94. return fromBase64(text.substr(RegExp.lastMatch.length));
  95. }
  96. var encoding = text.match(/data:application\/json;([^,]+),/)[1];
  97. throw new Error('Unsupported source map encoding ' + encoding);
  98. };
  99. _proto.loadMap = function loadMap(file, prev) {
  100. if (prev === false) return false;
  101. if (prev) {
  102. if (typeof prev === 'string') {
  103. return prev;
  104. } else if (typeof prev === 'function') {
  105. var prevPath = prev(file);
  106. if (prevPath && _fs.default.existsSync && _fs.default.existsSync(prevPath)) {
  107. return _fs.default.readFileSync(prevPath, 'utf-8').toString().trim();
  108. } else {
  109. throw new Error('Unable to load previous source map: ' + prevPath.toString());
  110. }
  111. } else if (prev instanceof _sourceMap.default.SourceMapConsumer) {
  112. return _sourceMap.default.SourceMapGenerator.fromSourceMap(prev).toString();
  113. } else if (prev instanceof _sourceMap.default.SourceMapGenerator) {
  114. return prev.toString();
  115. } else if (this.isMap(prev)) {
  116. return JSON.stringify(prev);
  117. } else {
  118. throw new Error('Unsupported previous source map format: ' + prev.toString());
  119. }
  120. } else if (this.inline) {
  121. return this.decodeInline(this.annotation);
  122. } else if (this.annotation) {
  123. var map = this.annotation;
  124. if (file) map = _path.default.join(_path.default.dirname(file), map);
  125. this.root = _path.default.dirname(map);
  126. if (_fs.default.existsSync && _fs.default.existsSync(map)) {
  127. return _fs.default.readFileSync(map, 'utf-8').toString().trim();
  128. } else {
  129. return false;
  130. }
  131. }
  132. };
  133. _proto.isMap = function isMap(map) {
  134. if (typeof map !== 'object') return false;
  135. return typeof map.mappings === 'string' || typeof map._mappings === 'string';
  136. };
  137. return PreviousMap;
  138. }();
  139. var _default = PreviousMap;
  140. exports.default = _default;
  141. module.exports = exports.default;
  142. //# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInByZXZpb3VzLW1hcC5lczYiXSwibmFtZXMiOlsiZnJvbUJhc2U2NCIsInN0ciIsIkJ1ZmZlciIsImZyb20iLCJ0b1N0cmluZyIsIndpbmRvdyIsImF0b2IiLCJQcmV2aW91c01hcCIsImNzcyIsIm9wdHMiLCJsb2FkQW5ub3RhdGlvbiIsImlubGluZSIsInN0YXJ0V2l0aCIsImFubm90YXRpb24iLCJwcmV2IiwibWFwIiwidW5kZWZpbmVkIiwidGV4dCIsImxvYWRNYXAiLCJjb25zdW1lciIsImNvbnN1bWVyQ2FjaGUiLCJtb3ppbGxhIiwiU291cmNlTWFwQ29uc3VtZXIiLCJ3aXRoQ29udGVudCIsInNvdXJjZXNDb250ZW50IiwibGVuZ3RoIiwic3RyaW5nIiwic3RhcnQiLCJzdWJzdHIiLCJn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lvblxcL2pzb247KFteLF0rKSwvKVsxXVxuICAgIHRocm93IG5ldyBFcnJvcignVW5zdXBwb3J0ZWQgc291cmNlIG1hcCBlbmNvZGluZyAnICsgZW5jb2RpbmcpXG4gIH1cblxuICBsb2FkTWFwIChmaWxlLCBwcmV2KSB7XG4gICAgaWYgKHByZXYgPT09IGZhbHNlKSByZXR1cm4gZmFsc2VcblxuICAgIGlmIChwcmV2KSB7XG4gICAgICBpZiAodHlwZW9mIHByZXYgPT09ICdzdHJpbmcnKSB7XG4gICAgICAgIHJldHVybiBwcmV2XG4gICAgICB9IGVsc2UgaWYgKHR5cGVvZiBwcmV2ID09PSAnZnVuY3Rpb24nKSB7XG4gICAgICAgIGxldCBwcmV2UGF0aCA9IHByZXYoZmlsZSlcbiAgICAgICAgaWYgKHByZXZQYXRoICYmIGZzLmV4aXN0c1N5bmMgJiYgZnMuZXhpc3RzU3luYyhwcmV2UGF0aCkpIHtcbiAgICAgICAgICByZXR1cm4gZnMucmVhZEZpbGVTeW5jKHByZXZQYXRoLCAndXRmLTgnKS50b1N0cmluZygpLnRyaW0oKVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIHRocm93IG5ldyBFcnJvcihcbiAgICAgICAgICAgICdVbmFibGUgdG8gbG9hZCBwcmV2aW91cyBzb3VyY2UgbWFwOiAnICsgcHJldlBhdGgudG9TdHJpbmcoKSlcbiAgICAgICAgfVxuICAgICAgfSBlbHNlIGlmIChwcmV2IGluc3RhbmNlb2YgbW96aWxsYS5Tb3VyY2VNYXBDb25zdW1lcikge1xuICAgICAgICByZXR1cm4gbW96aWxsYS5Tb3VyY2VNYXBHZW5lcmF0b3IuZnJvbVNvdXJjZU1hcChwcmV2KS50b1N0cmluZygpXG4gICAgICB9IGVsc2UgaWYgKHByZXYgaW5zdGFuY2VvZiBtb3ppbGxhLlNvdXJjZU1hcEdlbmVyYXRvcikge1xuICAgICAgICByZXR1cm4gcHJldi50b1N0cmluZygpXG4gICAgICB9IGVsc2Uga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