pax_global_header00006660000000000000000000000064126400231250014505gustar00rootroot0000000000000052 comment=30320c97c112f44ccba02dd73ce5bed1ad4361de vinyl-sourcemaps-apply-0.2.1/000077500000000000000000000000001264002312500161505ustar00rootroot00000000000000vinyl-sourcemaps-apply-0.2.1/.gitignore000066400000000000000000000000261264002312500201360ustar00rootroot00000000000000.DS_Store node_modulesvinyl-sourcemaps-apply-0.2.1/.jshintrc000066400000000000000000000000421264002312500177710ustar00rootroot00000000000000{ "node": true, "strict": true }vinyl-sourcemaps-apply-0.2.1/README.md000066400000000000000000000016531264002312500174340ustar00rootroot00000000000000# vinyl-sourcemaps-apply Apply a source map to a vinyl file, merging it with preexisting source maps. ## Usage: ```javascript var applySourceMap = require('vinyl-sourcemaps-apply'); applySourceMap(vinylFile, sourceMap); ``` ### Example (Gulp plugin): ```javascript var through = require('through2'); var applySourceMap = require('vinyl-sourcemaps-apply'); var myTransform = require('myTransform'); module.exports = function(options) { function transform(file, encoding, callback) { // generate source maps if plugin source-map present if (file.sourceMap) { options.makeSourceMaps = true; } // do normal plugin logic var result = myTransform(file.contents, options); file.contents = new Buffer(result.code); // apply source map to the chain if (file.sourceMap) { applySourceMap(file, result.map); } this.push(file); callback(); } return through.obj(transform); }; ```vinyl-sourcemaps-apply-0.2.1/index.js000066400000000000000000000025351264002312500176220ustar00rootroot00000000000000'use strict'; var SourceMapGenerator = require('source-map').SourceMapGenerator; var SourceMapConsumer = require('source-map').SourceMapConsumer; module.exports = function applySourceMap(file, sourceMap) { if (typeof sourceMap === 'string' || sourceMap instanceof String) { sourceMap = JSON.parse(sourceMap); } if (file.sourceMap && (typeof file.sourceMap === 'string' || file.sourceMap instanceof String)) { file.sourceMap = JSON.parse(file.sourceMap); } // check source map properties assertProperty(sourceMap, "file"); assertProperty(sourceMap, "mappings"); assertProperty(sourceMap, "sources"); // fix paths if Windows style paths sourceMap.file = sourceMap.file.replace(/\\/g, '/'); sourceMap.sources = sourceMap.sources.map(function(filePath) { return filePath.replace(/\\/g, '/'); }); if (file.sourceMap && file.sourceMap.mappings !== '') { var generator = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(sourceMap)); generator.applySourceMap(new SourceMapConsumer(file.sourceMap)); file.sourceMap = JSON.parse(generator.toString()); } else { file.sourceMap = sourceMap; } }; function assertProperty(sourceMap, propertyName) { if (!sourceMap.hasOwnProperty(propertyName)) { var e = new Error('Source map to be applied is missing the \"' + propertyName + '\" property'); throw e; } } vinyl-sourcemaps-apply-0.2.1/package.json000066400000000000000000000011371264002312500204400ustar00rootroot00000000000000{ "name": "vinyl-sourcemaps-apply", "version": "0.2.1", "description": "Apply a source map to a vinyl file, merging it with preexisting source maps", "homepage": "http://github.com/floridoo/vinyl-sourcemaps-apply", "repository": "git://github.com/floridoo/vinyl-sourcemaps-apply.git", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [ "vinyl", "sourcemaps", "source maps", "gulp" ], "author": "Florian Reiterer ", "license": "ISC", "dependencies": { "source-map": "^0.5.1" } }