sourcemap.js 798 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict';
  2. var through = require('through2');
  3. var sourcemap = require('vinyl-sourcemap');
  4. function sourcemapStream(optResolver) {
  5. function saveSourcemap(file, enc, callback) {
  6. var self = this;
  7. var srcMap = optResolver.resolve('sourcemaps', file);
  8. if (!srcMap) {
  9. return callback(null, file);
  10. }
  11. var srcMapLocation = (typeof srcMap === 'string' ? srcMap : undefined);
  12. sourcemap.write(file, srcMapLocation, onWrite);
  13. function onWrite(sourcemapErr, updatedFile, sourcemapFile) {
  14. if (sourcemapErr) {
  15. return callback(sourcemapErr);
  16. }
  17. self.push(updatedFile);
  18. if (sourcemapFile) {
  19. self.push(sourcemapFile);
  20. }
  21. callback();
  22. }
  23. }
  24. return through.obj(saveSourcemap);
  25. }
  26. module.exports = sourcemapStream;