index.js 602 B

123456789101112131415161718192021222324252627282930
  1. 'use strict';
  2. var through = require('through2');
  3. var normalize = require('normalize-path');
  4. function mapSources(mapFn) {
  5. function transform(file, _, cb) {
  6. if (!file.sourceMap || !file.sourceMap.sources) {
  7. return cb(null, file);
  8. }
  9. function mapper(sourcePath) {
  10. var result = sourcePath;
  11. if (typeof mapFn === 'function') {
  12. result = mapFn(sourcePath, file);
  13. }
  14. return normalize(result);
  15. }
  16. file.sourceMap.sources = file.sourceMap.sources.map(mapper);
  17. cb(null, file);
  18. }
  19. return through.obj(transform);
  20. }
  21. module.exports = mapSources;