pax_global_header00006660000000000000000000000064132711117470014516gustar00rootroot0000000000000052 comment=dcfe52f109d10d8a9d18dbd76eada85db6c0534c concat-with-sourcemaps-1.0.7/000077500000000000000000000000001327111174700161225ustar00rootroot00000000000000concat-with-sourcemaps-1.0.7/.gitignore000066400000000000000000000000441327111174700201100ustar00rootroot00000000000000.DS_Store node_modules reports *.tgzconcat-with-sourcemaps-1.0.7/.jshintrc000066400000000000000000000000431327111174700177440ustar00rootroot00000000000000{ "node": true, "strict": true } concat-with-sourcemaps-1.0.7/.travis.yml000066400000000000000000000002431327111174700202320ustar00rootroot00000000000000sudo: false language: node_js node_js: - "10" - "9" - "8" - "6" - "4" - "0.10" after_script: - npm run coveralls branches: except: - /^v[0-9]/ concat-with-sourcemaps-1.0.7/LICENSE.md000066400000000000000000000014101327111174700175220ustar00rootroot00000000000000## ISC License Copyright (c) 2014, Florian Reiterer Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. concat-with-sourcemaps-1.0.7/README.md000066400000000000000000000034531327111174700174060ustar00rootroot00000000000000## Concat with source maps [![NPM version][npm-image]][npm-url] [![build status][travis-image]][travis-url] [![Test coverage][coveralls-image]][coveralls-url] NPM module for concatenating files and generating source maps. ### Usage example ```js var concat = new Concat(true, 'all.js', '\n'); concat.add(null, "// (c) John Doe"); concat.add('file1.js', file1Content); concat.add('file2.js', file2Content, file2SourceMap); var concatenatedContent = concat.content; var sourceMapForContent = concat.sourceMap; ``` ### API #### new Concat(generateSourceMap, outFileName, separator) Initialize a new concat object. Parameters: - generateSourceMap: whether or not to generate a source map (default: false) - outFileName: the file name/path of the output file (for the source map) - separator: the string that should separate files (default: no separator) #### concat.add(fileName, content, sourceMap) Add a file to the output file. Parameters: - fileName: file name of the input file (can be null for content without a file reference, e.g. a license comment) - content: content (Buffer or string) of the input file - sourceMap: optional source map of the input file (string). Will be merged into the output source map. #### concat.content The resulting concatenated file content (Buffer). #### concat.sourceMap The resulting source map of the concatenated files (string). [npm-image]: https://img.shields.io/npm/v/concat-with-sourcemaps.svg [npm-url]: https://www.npmjs.com/package/concat-with-sourcemaps [travis-image]: https://img.shields.io/travis/floridoo/concat-with-sourcemaps.svg [travis-url]: https://travis-ci.org/floridoo/concat-with-sourcemaps [coveralls-image]: https://img.shields.io/coveralls/floridoo/concat-with-sourcemaps.svg [coveralls-url]: https://coveralls.io/r/floridoo/concat-with-sourcemaps?branch=master concat-with-sourcemaps-1.0.7/index.js000066400000000000000000000100261327111174700175660ustar00rootroot00000000000000'use strict'; var SourceMapGenerator = require('source-map').SourceMapGenerator; var SourceMapConsumer = require('source-map').SourceMapConsumer; function unixStylePath(filePath) { return filePath.replace(/\\/g, '/'); } function Concat(generateSourceMap, fileName, separator) { this.lineOffset = 0; this.columnOffset = 0; this.sourceMapping = generateSourceMap; this.contentParts = []; if (separator === undefined) { this.separator = bufferFrom(''); } else { this.separator = bufferFrom(separator); } if (this.sourceMapping) { this._sourceMap = new SourceMapGenerator({file: unixStylePath(fileName)}); this.separatorLineOffset = 0; this.separatorColumnOffset = 0; var separatorString = this.separator.toString(); for (var i = 0; i < separatorString.length; i++) { this.separatorColumnOffset++; if (separatorString[i] === '\n') { this.separatorLineOffset++; this.separatorColumnOffset = 0; } } } } Concat.prototype.add = function(filePath, content, sourceMap) { filePath = filePath && unixStylePath(filePath); if (!Buffer.isBuffer(content)) { content = bufferFrom(content); } if (this.contentParts.length !== 0) { this.contentParts.push(this.separator); } this.contentParts.push(content); if (this.sourceMapping) { var contentString = content.toString(); var lines = contentString.split('\n').length; if (Object.prototype.toString.call(sourceMap) === '[object String]') sourceMap = JSON.parse(sourceMap); if (sourceMap && sourceMap.mappings && sourceMap.mappings.length > 0) { var upstreamSM = new SourceMapConsumer(sourceMap); var _this = this; upstreamSM.eachMapping(function(mapping) { if (mapping.source) { _this._sourceMap.addMapping({ generated: { line: _this.lineOffset + mapping.generatedLine, column: (mapping.generatedLine === 1 ? _this.columnOffset : 0) + mapping.generatedColumn }, original: mapping.originalLine == null ? null : { line: mapping.originalLine, column: mapping.originalColumn }, source: mapping.originalLine != null ? mapping.source : null, name: mapping.name }); } }); if (upstreamSM.sourcesContent) { upstreamSM.sourcesContent.forEach(function(sourceContent, i) { _this._sourceMap.setSourceContent(upstreamSM.sources[i], sourceContent); }); } } else { if (sourceMap && sourceMap.sources && sourceMap.sources.length > 0) filePath = sourceMap.sources[0]; if (filePath) { for (var i = 1; i <= lines; i++) { this._sourceMap.addMapping({ generated: { line: this.lineOffset + i, column: (i === 1 ? this.columnOffset : 0) }, original: { line: i, column: 0 }, source: filePath }); } if (sourceMap && sourceMap.sourcesContent) this._sourceMap.setSourceContent(filePath, sourceMap.sourcesContent[0]); } } if (lines > 1) this.columnOffset = 0; if (this.separatorLineOffset === 0) this.columnOffset += contentString.length - Math.max(0, contentString.lastIndexOf('\n')+1); this.columnOffset += this.separatorColumnOffset; this.lineOffset += lines - 1 + this.separatorLineOffset; } }; Object.defineProperty(Concat.prototype, 'content', { get: function content() { return Buffer.concat(this.contentParts); } }); Object.defineProperty(Concat.prototype, 'sourceMap', { get: function sourceMap() { return this._sourceMap ? this._sourceMap.toString() : undefined; } }); function bufferFrom(content) { try { return Buffer.from(content); } catch(e) { if (Object.prototype.toString.call(content) !== '[object String]') { throw new TypeError("separator must be a string"); } return new Buffer(content); } } Concat.bufferFrom = bufferFrom; module.exports = Concat; concat-with-sourcemaps-1.0.7/package.json000066400000000000000000000020171327111174700204100ustar00rootroot00000000000000{ "name": "concat-with-sourcemaps", "version": "1.0.7", "description": "Concatenate file contents with a custom separator and generate a source map", "homepage": "http://github.com/floridoo/concat-with-sourcemaps", "repository": "git://github.com/floridoo/concat-with-sourcemaps.git", "main": "index.js", "scripts": { "test": "jshint *.js test/*.js && faucet test/*.js", "tap": "tape test/*.js", "cover": "istanbul cover --dir reports/coverage tape test/*.js", "coveralls": "istanbul cover tape test/*.js --report lcovonly && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage" }, "keywords": [ "concat", "source map" ], "author": "Florian Reiterer ", "license": "ISC", "dependencies": { "source-map": "^0.6.1" }, "devDependencies": { "coveralls": "^3.0.0", "faucet": "0.0.1", "istanbul": "^0.4.5", "jshint": "^2.9.5", "tape": "^4.9.0" }, "files": [ "index.js", "package.json", "README.md", "LICENSE.md" ] } concat-with-sourcemaps-1.0.7/test/000077500000000000000000000000001327111174700171015ustar00rootroot00000000000000concat-with-sourcemaps-1.0.7/test/index.js000066400000000000000000000237271327111174700205610ustar00rootroot00000000000000'use strict'; var test = require('tape'); var Concat = require('..'); function testCase(description, options) { test(description, function(t) { // content as Buffer var concat = new Concat(options.sourceMapping, options.outFile, options.separator); options.input.forEach(function(input, i) { concat.add((input.fileName !== undefined ? input.fileName : 'test'+(i+1)), Concat.bufferFrom(input.content), input.sourceMap); }); t.equal(concat.content.toString(), options.output.content, 'should produce the right output'); if (options.output.sourceMap) t.deepEqual(JSON.parse(concat.sourceMap), JSON.parse(options.output.sourceMap), 'should produce the right source map'); else t.equal(concat.sourceMap, undefined, 'should not produce a source map'); // content as string concat = new Concat(options.sourceMapping, options.outFile, options.separator); options.input.forEach(function(input, i) { concat.add((input.fileName !== undefined ? input.fileName : 'test'+(i+1)), input.content, input.sourceMap); }); t.equal(concat.content.toString(), options.output.content, 'should produce the right output'); if (options.output.sourceMap) t.deepEqual(JSON.parse(concat.sourceMap), JSON.parse(options.output.sourceMap), 'should produce the right source map'); else t.equal(concat.sourceMap, undefined, 'should not produce a source map'); t.end(); }); } testCase('should concatenate with "\\n"', { separator: '\n', sourceMapping: false, outFile: 'out.js', input: [ { content: 'AAA' }, { content: 'BBB' }, { content: 'CCC' } ], output: { content: 'AAA\nBBB\nCCC' } }); testCase('should concatenate with "\\n\\n"', { separator: '\n\n', sourceMapping: false, outFile: 'out.js', input: [ { content: 'AAA' }, { content: 'BBB' }, { content: 'CCC' } ], output: { content: 'AAA\n\nBBB\n\nCCC' } }); testCase('should concatenate with "\\nXXXX\\n"', { separator: '\nXXXX\n', sourceMapping: false, outFile: 'out.js', input: [ { content: 'AAA' }, { content: 'BBB' }, { content: 'CCC' } ], output: { content: 'AAA\nXXXX\nBBB\nXXXX\nCCC' } }); testCase('should concatenate with "XXXX"', { separator: 'XXXX', sourceMapping: false, outFile: 'out.js', input: [ { content: 'AAA' }, { content: 'BBB' }, { content: 'CCC' } ], output: { content: 'AAAXXXXBBBXXXXCCC' } }); testCase('should concatenate without separator specified', { separator: undefined, sourceMapping: false, outFile: 'out.js', input: [ { content: 'AAA' }, { content: 'BBB' }, { content: 'CCC' } ], output: { content: 'AAABBBCCC' } }); testCase('should concatenate with "\\n" and produce source map', { separator: '\n', sourceMapping: true, outFile: 'out.js', input: [ { content: 'AAA' }, { content: 'BBB' }, { content: 'CCC' } ], output: { content: 'AAA\nBBB\nCCC', sourceMap: '{"version":3,"file":"out.js","sources":["test1","test2","test3"],"names":[],"mappings":"AAAA;ACAA;ACAA"}' } }); testCase('should concatenate with "\\n\\n" and produce source map', { separator: '\n\n', sourceMapping: true, outFile: 'out.js', input: [ { content: 'AAA' }, { content: 'BBB' }, { content: 'CCC' } ], output: { content: 'AAA\n\nBBB\n\nCCC', sourceMap: '{"version":3,"file":"out.js","sources":["test1","test2","test3"],"names":[],"mappings":"AAAA;;ACAA;;ACAA"}' } }); testCase('should concatenate with "XXXX" and produce source map', { separator: 'XXXX', sourceMapping: true, outFile: 'out.js', input: [ { content: 'AAA' }, { content: 'BBB' }, { content: 'CCC' } ], output: { content: 'AAAXXXXBBBXXXXCCC', sourceMap: '{"version":3,"file":"out.js","sources":["test1","test2","test3"],"names":[],"mappings":"AAAA,OCAA,OCAA"}' } }); testCase('should concatenate with "\\nXXXX" and produce source map', { separator: '\nXXXX', sourceMapping: true, outFile: 'out.js', input: [ { content: 'AAA' }, { content: 'BBB' }, { content: 'CCC' } ], output: { content: 'AAA\nXXXXBBB\nXXXXCCC', sourceMap: '{"version":3,"file":"out.js","sources":["test1","test2","test3"],"names":[],"mappings":"AAAA;ICAA;QCAA"}' } }); testCase('should concatenate with "XXXX\\n" and produce source map', { separator: 'XXXX\n', sourceMapping: true, outFile: 'out.js', input: [ { content: 'AAA' }, { content: 'BBB' }, { content: 'CCC' } ], output: { content: 'AAAXXXX\nBBBXXXX\nCCC', sourceMap: '{"version":3,"file":"out.js","sources":["test1","test2","test3"],"names":[],"mappings":"AAAA;ACAA;ACAA"}' } }); testCase('should concatenate mulitline content with "\\n" and produce source map', { separator: '\n', sourceMapping: true, outFile: 'out.js', input: [ { content: 'AA\nA' }, { content: 'BBB' }, { content: 'CC\nC' } ], output: { content: 'AA\nA\nBBB\nCC\nC', sourceMap: '{"version":3,"file":"out.js","sources":["test1","test2","test3"],"names":[],"mappings":"AAAA;AACA;ACDA;ACAA;AACA"}' } }); testCase('should concatenate content with source maps with "\\n" and produce combined source map', { separator: '\n', sourceMapping: true, outFile: 'out.js', input: [ { content: 'AAA\nBBB\nCCC', sourceMap: '{"version":3,"file":"intermediate.js","sources":["test11","test12","test13"],"names":[],"mappings":"AAAA;ACAA;ACAA"}', fileName: 'intermediate.js' }, { content: 'EEE' }, { content: 'FFF' } ], output: { content: 'AAA\nBBB\nCCC\nEEE\nFFF', sourceMap: '{"version":3,"file":"out.js","sources":["test11","test12","test13","test2","test3"],"names":[],"mappings":"AAAA;ACAA;ACAA;ACAA;ACAA"}' } }); testCase('should pass on source content', { separator: '\n', sourceMapping: true, outFile: 'out.js', input: [ { content: 'AAA\nBBB\nCCC', sourceMap: '{"version":3,"file":"intermediate.js","sources":["test11","test12","test13"], "sourcesContent": ["AAA", "BBB", "CCC"], "names":[],"mappings":"AAAA;ACAA;ACAA"}', fileName: 'intermediate.js' }, { content: 'EEE' }, { content: 'FFF' } ], output: { content: 'AAA\nBBB\nCCC\nEEE\nFFF', sourceMap: '{"version":3,"file":"out.js","sources":["test11","test12","test13","test2","test3"],"names":[],"mappings":"AAAA;ACAA;ACAA;ACAA;ACAA","sourcesContent":["AAA","BBB","CCC",null,null]}' } }); testCase('should pass on source content when mappings is empty', { separator: '\n', sourceMapping: true, outFile: 'out.js', input: [ { content: 'AAA', sourceMap: '{"version":3,"file":"intermediate.js","sources":["test11"], "sourcesContent": ["AAA"], "names":[],"mappings":""}', fileName: 'intermediate.js' }, { content: 'EEE' }, { content: 'FFF' } ], output: { content: 'AAA\nEEE\nFFF', sourceMap: '{"version":3,"file":"out.js","sources":["test11","test2","test3"],"names":[],"mappings":"AAAA;ACAA;ACAA","sourcesContent":["AAA",null,null]}' } }); testCase('should ignore invalid mappings', { separator: '\n', sourceMapping: true, outFile: 'out.js', input: [ { content: 'AAA\nBBB\nCCC', sourceMap: '{"version":3,"file":"intermediate.js","sources":["test11","test12","test13"], "sourcesContent": ["AAA", "BBB", "CCC"], "names":[],"mappings":"A;ACAA;ACAA"}', fileName: 'intermediate.js' }, { content: 'EEE' }, { content: 'FFF' } ], output: { content: 'AAA\nBBB\nCCC\nEEE\nFFF', sourceMap: '{"version":3,"file":"out.js","sources":["test12","test13","test2","test3"],"names":[],"mappings":"A;AAAA;ACAA;ACAA;ACAA","sourcesContent":["BBB","CCC",null,null]}' } }); testCase('should output unix style paths on Windows', { separator: '\n', sourceMapping: true, outFile: 'test\\test\\out.js', input: [ { content: 'AAA', fileName: 'test\\test1' }, { content: 'BBB', fileName: 'test\\test2' }, { content: 'CCC', fileName: 'test\\test3' } ], output: { content: 'AAA\nBBB\nCCC', sourceMap: '{"version":3,"file":"test/test/out.js","sources":["test/test1","test/test2","test/test3"],"names":[],"mappings":"AAAA;ACAA;ACAA"}' } }); testCase('should keep source in sources with empty mappings', { separator: '\n', sourceMapping: true, outFile: 'out.js', input: [ { content: 'AAA', sourceMap: '{"version":3,"file":"test1","sources":["testXXX"], "names":[],"mappings":""}' }, { content: 'BBB' }, { content: 'CCC' } ], output: { content: 'AAA\nBBB\nCCC', sourceMap: '{"version":3,"file":"out.js","sources":["testXXX","test2","test3"],"names":[],"mappings":"AAAA;ACAA;ACAA"}' } }); testCase('should not crash with an input source map with no mappings', { separator: '\n', sourceMapping: true, outFile: 'out.js', input: [ { content: 'AAA\nBBB\nCCC', sourceMap: '{"version":3,"file":"intermediate.js","sources":[],"names":[],"mappings":""}', fileName: 'intermediate.js' }, { content: 'EEE' }, { content: 'FFF' } ], output: { content: 'AAA\nBBB\nCCC\nEEE\nFFF', sourceMap: '{"version":3,"file":"out.js","sources":["intermediate.js", "test2", "test3"],"names":[],"mappings":"AAAA;AACA;AACA;ACFA;ACAA"}' } }); testCase('should allow content without filename and produce no mapping for it', { separator: '\n', sourceMapping: true, outFile: 'out.js', input: [ { content: '// Header', fileName: null }, { content: 'AA\nA' }, { content: 'BBB' }, { content: '// inbetween', fileName: null }, { content: 'CC\nC' }, { content: '// Footer', fileName: null } ], output: { content: '// Header\nAA\nA\nBBB\n// inbetween\nCC\nC\n// Footer', sourceMap: '{"version":3,"file":"out.js","sources":["test2","test3","test5"],"names":[],"mappings":";AAAA;AACA;ACDA;;ACAA;AACA"}' } }); test('should not allocate an uninitialized buffer when passing a number', function(t) { t.throws(function() { new Concat(true, 'all.js', 234); }, "passing a number as separator should throw"); t.end(); });