From 115e78665c40984d9e2cc3af17ca466784282bf4 Mon Sep 17 00:00:00 2001 From: AVVS Date: Mon, 23 Dec 2019 12:06:11 -0800 Subject: [PATCH 1/2] feat: source-map 0.7.x BREAKING CHANGE: addFile is now an async function that returns a promise, thus it is a breaking change. This could not have been avoided due to changes in source-map module --- .gitignore | 2 + .travis.yml | 6 +- README.md | 33 ++++--- example/two-files-short.js | 26 +++--- example/two-files.js | 29 +++--- index.js | 32 +++---- lib/mappings-from-map.js | 12 +-- package.json | 14 +-- test/combine-source-map.js | 178 ++++++++++++++++++------------------- 9 files changed, 167 insertions(+), 165 deletions(-) diff --git a/.gitignore b/.gitignore index de78e27..4958ff8 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,5 @@ results node_modules npm-debug.log tmp +.nyc_output +*.lock diff --git a/.travis.yml b/.travis.yml index 9631dae..5841a45 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ sudo: false language: node_js node_js: - - "0.10" - - "0.12" - - "iojs-v2.4" + - "10" + - "12" + - "13" before_install: - npm install --global npm diff --git a/README.md b/README.md index 92dfc1f..0b0ec8f 100644 --- a/README.md +++ b/README.md @@ -3,29 +3,28 @@ Add source maps of multiple files, offset them and then combine them into one source map. ```js -var convert = require('convert-source-map'); -var combine = require('combine-source-map'); +const convert = require('convert-source-map'); +const combine = require('combine-source-map'); -var fooComment = '//# sourceMappingURL=data:application/json;base64,eyJ2Z [..] pzJylcbiJdfQ=='; -var barComment = '//# sourceMappingURL=data:application/json;base64,eyJ2Z [..] VjaycpXG4iXX0='; +const fooComment = '//# sourceMappingURL=data:application/json;base64,eyJ2Z [..] pzJylcbiJdfQ=='; +const barComment = '//# sourceMappingURL=data:application/json;base64,eyJ2Z [..] VjaycpXG4iXX0='; -var fooFile = { +const fooFile = { source: '(function() {\n\n console.log(require(\'./bar.js\'));\n\n}).call(this);\n' + '\n' + fooComment , sourceFile: 'foo.js' }; -var barFile = { +const barFile = { source: '(function() {\n\n console.log(alert(\'alerts suck\'));\n\n}).call(this);\n' + '\n' + barComment , sourceFile: 'bar.js' }; -var offset = { line: 2 }; -var base64 = combine - .create('bundle.js') - .addFile(fooFile, offset) - .addFile(barFile, { line: offset.line + 8 }) - .base64(); +const offset = { line: 2 }; +const map = combine.create('bundle.js'); +await map.addFile(fooFile, offset) +await map.addFile(barFile, { line: offset.line + 8 }) +const base64 = map.base64(); -var sm = convert.fromBase64(base64).toObject(); +const sm = convert.fromBase64(base64).toObject(); console.log(sm); ``` @@ -66,7 +65,7 @@ console.log(sm); * If source contains a source map comment that has the source of the original file inlined it will offset these * mappings and include them. * If no source map comment is found or it has no source inlined, mappings for the file will be generated and included - * + * * @name addMap * @function * @param opts {Object} { sourceFile: {String}, source: {String} } @@ -100,12 +99,12 @@ console.log(sm); /** * @name removeComments * @function - * @param src + * @param src * @return {String} src with all sourceMappingUrl comments removed */ ``` -## Example +## Example -Read and run the [more elaborate example](https://github.com/thlorenz/combine-source-map/blob/master/example/two-files.js) +Read and run the [more elaborate example](https://github.com/thlorenz/combine-source-map/blob/master/example/two-files.js) in order to get a better idea how things work. diff --git a/example/two-files-short.js b/example/two-files-short.js index 311849c..6dc4578 100644 --- a/example/two-files-short.js +++ b/example/two-files-short.js @@ -1,26 +1,26 @@ 'use strict'; -var convert = require('convert-source-map'); -var combine = require('..'); +const convert = require('convert-source-map'); +const combine = require('..'); -var fooComment = '//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZm9vLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiZm9vLmNvZmZlZSJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7Q0FBQTtDQUFBLENBQUEsQ0FBQSxJQUFPLEdBQUs7Q0FBWiIsInNvdXJjZXNDb250ZW50IjpbImNvbnNvbGUubG9nKHJlcXVpcmUgJy4vYmFyLmpzJylcbiJdfQ=='; -var barComment = '//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmFyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiYmFyLmNvZmZlZSJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7Q0FBQTtDQUFBLENBQUEsQ0FBQSxJQUFPLEdBQUs7Q0FBWiIsInNvdXJjZXNDb250ZW50IjpbImNvbnNvbGUubG9nKGFsZXJ0ICdhbGVydHMgc3VjaycpXG4iXX0='; +const fooComment = '//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZm9vLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiZm9vLmNvZmZlZSJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7Q0FBQTtDQUFBLENBQUEsQ0FBQSxJQUFPLEdBQUs7Q0FBWiIsInNvdXJjZXNDb250ZW50IjpbImNvbnNvbGUubG9nKHJlcXVpcmUgJy4vYmFyLmpzJylcbiJdfQ=='; +const barComment = '//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmFyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiYmFyLmNvZmZlZSJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7Q0FBQTtDQUFBLENBQUEsQ0FBQSxJQUFPLEdBQUs7Q0FBWiIsInNvdXJjZXNDb250ZW50IjpbImNvbnNvbGUubG9nKGFsZXJ0ICdhbGVydHMgc3VjaycpXG4iXX0='; -var fooFile = { +const fooFile = { source: '(function() {\n\n console.log(require(\'./bar.js\'));\n\n}).call(this);\n' + '\n' + fooComment , sourceFile: 'foo.js' }; -var barFile = { +const barFile = { source: '(function() {\n\n console.log(alert(\'alerts suck\'));\n\n}).call(this);\n' + '\n' + barComment , sourceFile: 'bar.js' }; -var offset = { line: 2 }; -var base64 = combine - .create('bundle.js') - .addFile(fooFile, offset) - .addFile(barFile, { line: offset.line + 8 }) - .base64(); +const offset = { line: 2 }; -var sm = convert.fromBase64(base64).toObject(); +const map = combine.create('bundle.js'); +await map.addFile(fooFile, offset) +await map.addFile(barFile, { line: offset.line + 8 }) +var base64 = map.base64(); + +const sm = convert.fromBase64(base64).toObject(); console.log(sm); diff --git a/example/two-files.js b/example/two-files.js index 0a4500b..00a7aa1 100644 --- a/example/two-files.js +++ b/example/two-files.js @@ -1,9 +1,9 @@ 'use strict'; -var convert = require('convert-source-map'); -var combine = require('..'); +const convert = require('convert-source-map'); +const combine = require('..'); -var foo = { +const foo = { version : 3, file : 'foo.js', sourceRoot : '', @@ -12,7 +12,7 @@ var foo = { mappings : ';AAAA;CAAA;CAAA,CAAA,CAAA,IAAO,GAAK;CAAZ', sourcesContent : [ 'console.log(require \'./bar.js\')\n' ] }; -var bar = { +const bar = { version : 3, file : 'bar.js', sourceRoot : '', @@ -22,25 +22,24 @@ var bar = { sourcesContent : [ 'console.log(alert \'alerts suck\')\n' ] }; -var fooComment = convert.fromObject(foo).toComment(); -var barComment = convert.fromObject(bar).toComment(); +const fooComment = convert.fromObject(foo).toComment(); +const barComment = convert.fromObject(bar).toComment(); -var fooFile = { +const fooFile = { source: '(function() {\n\n console.log(require(\'./bar.js\'));\n\n}).call(this);\n' + '\n' + fooComment , sourceFile: 'foo.js' }; -var barFile = { +const barFile = { source: '(function() {\n\n console.log(alert(\'alerts suck\'));\n\n}).call(this);\n' + '\n' + barComment , sourceFile: 'bar.js' }; -var offset = { line: 2 }; -var base64 = combine - .create('bundle.js') - .addFile(fooFile, offset) - .addFile(barFile, { line: offset.line + 8 }) - .base64(); +const offset = { line: 2 }; +const map = combine.create('bundle.js'); +await map.addFile(fooFile, offset); +await map.addFile(barFile, { line: offset.line + 8 }); +const base64 = map.base64(); -var sm = convert.fromBase64(base64).toObject(); +const sm = convert.fromBase64(base64).toObject(); console.log('Combined source maps:\n', sm); console.log('\nMappings:\n', sm.mappings); diff --git a/index.js b/index.js index e2c74fd..59e616d 100644 --- a/index.js +++ b/index.js @@ -1,13 +1,13 @@ 'use strict'; -var path = require('path'); -var convert = require('convert-source-map'); -var memoize = require('lodash.memoize'); -var createGenerator = require('inline-source-map'); -var pathIsAbsolute = require('./lib/path-is-absolute'); -var mappingsFromMap = require('./lib/mappings-from-map'); +const path = require('path'); +const convert = require('convert-source-map'); +const memoize = require('lodash.memoize'); +const createGenerator = require('inline-source-map'); +const pathIsAbsolute = require('./lib/path-is-absolute'); +const mappingsFromMap = require('./lib/mappings-from-map'); -var protocolRx = /^[a-z]+:\/\//; +const protocolRx = /^[a-z]+:\/\//; /** * Rebases a relative path in 'sourceFile' to be relative @@ -26,13 +26,13 @@ var protocolRx = /^[a-z]+:\/\//; * @param relativeRoot {String} sourceRoot in sourceFile's map to combine with relativePath * @param relativePath {String} source path from sourceFile's map */ -var rebaseRelativePath = memoize(function(sourceFile, relativeRoot, relativePath) { +const rebaseRelativePath = memoize(function(sourceFile, relativeRoot, relativePath) { if (!relativePath) { return relativePath; } // join relative path to root (e.g. 'src/' + 'file.js') - var relativeRootedPath = relativeRoot ? path.join(relativeRoot, relativePath) : relativePath; + let relativeRootedPath = relativeRoot ? path.join(relativeRoot, relativePath) : relativePath; relativeRootedPath = relativeRootedPath.replace(/\\/g, '/'); sourceFile = sourceFile.replace(/\\/g, '/'); @@ -49,7 +49,7 @@ var rebaseRelativePath = memoize(function(sourceFile, relativeRoot, relativePath }); function resolveMap(source) { - var gen = convert.fromSource(source); + const gen = convert.fromSource(source); return gen ? gen.toObject() : null; } @@ -68,11 +68,11 @@ Combiner.prototype._addGeneratedMap = function (sourceFile, source, offset) { return this; }; -Combiner.prototype._addExistingMap = function (sourceFile, source, existingMap, offset) { - var mappings = mappingsFromMap(existingMap); +Combiner.prototype._addExistingMap = async function (sourceFile, source, existingMap, offset) { + const mappings = await mappingsFromMap(existingMap); // add all of the sources from the map - for (var i = 0, len = existingMap.sources.length; i < len; i++) { + for (let i = 0, len = existingMap.sources.length; i < len; i++) { if (!existingMap.sourcesContent) continue; this.generator.addSourceContent( @@ -103,16 +103,16 @@ Combiner.prototype._addExistingMap = function (sourceFile, source, existingMap, * @param opts {Object} { sourceFile: {String}, source: {String} } * @param offset {Object} { line: {Number}, column: {Number} } */ -Combiner.prototype.addFile = function (opts, offset) { +Combiner.prototype.addFile = async function (opts, offset) { offset = offset || {}; if (!offset.hasOwnProperty('line')) offset.line = 0; if (!offset.hasOwnProperty('column')) offset.column = 0; - var existingMap = resolveMap(opts.source); + const existingMap = resolveMap(opts.source); return existingMap && hasInlinedSource(existingMap) - ? this._addExistingMap(opts.sourceFile, opts.source, existingMap, offset) + ? await this._addExistingMap(opts.sourceFile, opts.source, existingMap, offset) : this._addGeneratedMap(opts.sourceFile, opts.source, offset); }; diff --git a/lib/mappings-from-map.js b/lib/mappings-from-map.js index e11a69e..6f9f5ed 100644 --- a/lib/mappings-from-map.js +++ b/lib/mappings-from-map.js @@ -1,4 +1,4 @@ -var SMConsumer = require('source-map').SourceMapConsumer; +const SMConsumer = require('source-map').SourceMapConsumer; /** * @name mappingsFromMap @@ -6,11 +6,11 @@ var SMConsumer = require('source-map').SourceMapConsumer; * @param map {Object} the JSON.parse()'ed map * @return {Array} array of mappings */ -module.exports = function (map) { - var consumer = new SMConsumer(map); - var mappings = []; +module.exports = async (map) => { + const consumer = await new SMConsumer(map); + const mappings = []; - consumer.eachMapping(function (mapping) { + consumer.eachMapping((mapping) => { // only set source if we have original position to handle edgecase (see inline-source-map tests) mappings.push({ original: mapping.originalColumn != null ? { @@ -26,5 +26,7 @@ module.exports = function (map) { }); }); + consumer.destroy(); + return mappings; } diff --git a/package.json b/package.json index c2bc088..31c3c77 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "combine-source-map", - "version": "0.8.0", + "name": "@makeomatic/combine-source-map", + "version": "0.9.0", "description": "Add source maps of multiple files, offset them and then combine them into one source map", "main": "index.js", "scripts": { @@ -12,13 +12,13 @@ }, "homepage": "https://github.com/thlorenz/combine-source-map", "dependencies": { - "convert-source-map": "~1.1.0", + "convert-source-map": "~1.7.0", "inline-source-map": "~0.6.0", - "lodash.memoize": "~3.0.3", - "source-map": "~0.5.3" + "lodash.memoize": "~4.1.2", + "source-map": "~0.7.3" }, "devDependencies": { - "tap": "~0.4.3" + "tap": "~14.10.5" }, "keywords": [ "source", @@ -37,6 +37,6 @@ }, "license": "MIT", "engine": { - "node": ">=0.6" + "node": ">=10.15.9" } } diff --git a/test/combine-source-map.js b/test/combine-source-map.js index 3a51e5f..efcd6e9 100644 --- a/test/combine-source-map.js +++ b/test/combine-source-map.js @@ -1,27 +1,27 @@ 'use strict'; /*jshint asi: true */ -var test = require('tap').test; -var convert = require('convert-source-map'); -var commentRegex = require('convert-source-map').commentRegex; -var combine = require('..'); -var mappingsFromMap = require('../lib/mappings-from-map'); +const test = require('tap').test; +const convert = require('convert-source-map'); +const commentRegex = require('convert-source-map').commentRegex; +const combine = require('..'); +const mappingsFromMap = require('../lib/mappings-from-map'); -function checkMappings(foo, sm, lineOffset) { +async function checkMappings(foo, sm, lineOffset) { function inspect(obj, depth) { return require('util').inspect(obj, false, depth || 5, true); } - var fooMappings = mappingsFromMap(foo); - var mappings = mappingsFromMap(sm); + const fooMappings = await mappingsFromMap(foo); + const mappings = await mappingsFromMap(sm); - var genLinesOffset = true; - var origLinesSame = true; - for (var i = 0; i < mappings.length; i++) { - var fooGen = fooMappings[i].generated; - var fooOrig = fooMappings[i].original; - var gen = mappings[i].generated - var orig = mappings[i].original; + const genLinesOffset = true; + const origLinesSame = true; + for (let i = 0; i < mappings.length; i++) { + const fooGen = fooMappings[i].generated; + const fooOrig = fooMappings[i].original; + const gen = mappings[i].generated + const orig = mappings[i].original; if (gen.column !== fooGen.column || gen.line !== (fooGen.line + lineOffset)) { console.error( @@ -46,7 +46,7 @@ function checkMappings(foo, sm, lineOffset) { return { genLinesOffset: genLinesOffset, origLinesSame: origLinesSame }; } -var foo = { +const foo = { version : 3, file : 'foo.js', sourceRoot : '', @@ -55,22 +55,22 @@ var foo = { mappings : ';AAAA;CAAA;CAAA,CAAA,CAAA,IAAO,GAAK;CAAZ', sourcesContent : [ 'console.log(require \'./bar.js\')\n' ] }; -test('add one file with inlined source', function (t) { +test('add one file with inlined source', async function (t) { - var mapComment = convert.fromObject(foo).toComment(); - var file = { + const mapComment = convert.fromObject(foo).toComment(); + const file = { id: 'xyz' , source: '(function() {\n\n console.log(require(\'./bar.js\'));\n\n}).call(this);\n' + '\n' + mapComment , sourceFile: 'foo.js' }; - var lineOffset = 3 - var base64 = combine.create() - .addFile(file, { line: lineOffset }) - .base64() + const lineOffset = 3 + const map = combine.create(); + await map.addFile(file, { line: lineOffset }) + const base64 = map.base64(); - var sm = convert.fromBase64(base64).toObject(); - var res = checkMappings(foo, sm, lineOffset); + const sm = convert.fromBase64(base64).toObject(); + const res = await checkMappings(foo, sm, lineOffset); t.ok(res.genLinesOffset, 'all generated lines are offset properly and columns unchanged') t.ok(res.origLinesSame, 'all original lines and columns are unchanged') @@ -80,26 +80,26 @@ test('add one file with inlined source', function (t) { }); -test('add one file without inlined source', function (t) { +test('add one file without inlined source', async function (t) { - var mapComment = convert + const mapComment = convert .fromObject(foo) .setProperty('sourcesContent', []) .toComment(); - var file = { + const file = { id: 'xyz' , source: '(function() {\n\n console.log(require(\'./bar.js\'));\n\n}).call(this);\n' + '\n' + mapComment , sourceFile: 'foo.js' }; - var lineOffset = 3 - var base64 = combine.create() - .addFile(file, { line: lineOffset }) - .base64() + const lineOffset = 3 + const map = combine.create(); + await map.addFile(file, { line: lineOffset }); + const base64 = map.base64(); - var sm = convert.fromBase64(base64).toObject(); - var mappings = mappingsFromMap(sm); + const sm = convert.fromBase64(base64).toObject(); + const mappings = await mappingsFromMap(sm); t.deepEqual(sm.sourcesContent, [file.source], 'includes the generated source') t.deepEqual(sm.sources, ['foo.js'], 'includes generated filename') @@ -132,8 +132,8 @@ test('add one file without inlined source', function (t) { t.end() }) -test('add one file with inlined sources from multiple files', function(t) { - var gen1Map = { +test('add one file with inlined sources from multiple files', async function(t) { + const gen1Map = { version: 3, sources: [ 'one.js', 'two.js' ], names: [], @@ -141,7 +141,7 @@ test('add one file with inlined sources from multiple files', function(t) { sourcesContent: [ 'console.log(1);', 'console.log(2);' ] }; - var gen2Map = { + const gen2Map = { version: 3, sources: [ 'three.js', 'four.js' ], names: [], @@ -149,18 +149,18 @@ test('add one file with inlined sources from multiple files', function(t) { sourcesContent: [ 'console.log(3);', 'console.log(4);' ] }; - var base64 = combine.create() - .addFile({ - source: 'console.log(1);\nconsole.log(2);\n' + convert.fromObject(gen1Map).toComment(), - sourceFile: 'gen1.js' - }) - .addFile({ - source: 'console.log(3);\nconsole.log(4);\n' + convert.fromObject(gen2Map).toComment(), - sourceFile: 'gen2.js' - }, {line: 2}) - .base64() + const map = combine.create(); + await map.addFile({ + source: 'console.log(1);\nconsole.log(2);\n' + convert.fromObject(gen1Map).toComment(), + sourceFile: 'gen1.js' + }); + await map.addFile({ + source: 'console.log(3);\nconsole.log(4);\n' + convert.fromObject(gen2Map).toComment(), + sourceFile: 'gen2.js' + }, {line: 2}); + const base64 = map.base64() - var sm = convert.fromBase64(base64).toObject(); + const sm = convert.fromBase64(base64).toObject(); t.deepEqual(sm.sources, ['one.js', 'two.js', 'three.js', 'four.js'], 'include the correct source'); @@ -173,7 +173,7 @@ test('add one file with inlined sources from multiple files', function(t) { ], 'include the correct source file content'); t.deepEqual( - mappingsFromMap(sm) + await mappingsFromMap(sm) , [ { original: { column: 0, line: 1 }, generated: { column: 0, line: 1 }, source: 'one.js', @@ -193,7 +193,7 @@ test('add one file with inlined sources from multiple files', function(t) { t.end() }); -test('relative path from multiple files', function(t) { +test('relative path from multiple files', async function(t) { // Folder structure as follows: // // project @@ -215,7 +215,7 @@ test('relative path from multiple files', function(t) { // and 'three.js', 'four.js' were combined to 'gen2.js'. // Now 'gen1.js' and 'gen2.js' are being combined from // the project root folder. - var gen1Map = { + const gen1Map = { version: 3, sources: [ 'sub/one.js', 'sub/two.js' ], names: [], @@ -224,7 +224,7 @@ test('relative path from multiple files', function(t) { sourceRoot: '../src/package1' }; - var gen2Map = { + const gen2Map = { version: 3, sources: [ 'sub/three.js', 'sub/four.js' ], names: [], @@ -233,21 +233,21 @@ test('relative path from multiple files', function(t) { sourceRoot: '../src/package2' }; - var base64 = combine.create() - .addFile({ - source: 'console.log(1);\nconsole.log(2);\n' + convert.fromObject(gen1Map).toComment(), - sourceFile: 'gen/gen1.js' - }) - .addFile({ - source: 'console.log(3);\nconsole.log(4);\n' + convert.fromObject(gen2Map).toComment(), - sourceFile: 'gen/gen2.js' - }, {line: 2}) - .base64() - - var sm = convert.fromBase64(base64).toObject(); - - t.deepEqual(sm.sources, ['src/package1/sub/one.js', 'src/package1/sub/two.js', - 'src/package2/sub/three.js', 'src/package2/sub/four.js'], + const map = combine.create() + await map.addFile({ + source: 'console.log(1);\nconsole.log(2);\n' + convert.fromObject(gen1Map).toComment(), + sourceFile: 'gen/gen1.js' + }); + await map.addFile({ + source: 'console.log(3);\nconsole.log(4);\n' + convert.fromObject(gen2Map).toComment(), + sourceFile: 'gen/gen2.js' + }, {line: 2}); + const base64 = map.base64(); + + const sm = convert.fromBase64(base64).toObject(); + + t.deepEqual(sm.sources, ['src/package1/sub/one.js', 'src/package1/sub/two.js', + 'src/package2/sub/three.js', 'src/package2/sub/four.js'], 'include the correct source'); t.deepEqual(sm.sourcesContent, [ @@ -258,7 +258,7 @@ test('relative path from multiple files', function(t) { ], 'include the correct source file content'); t.deepEqual( - mappingsFromMap(sm) + await mappingsFromMap(sm) , [ { original: { column: 0, line: 1 }, generated: { column: 0, line: 1 }, source: 'src/package1/sub/one.js', @@ -278,8 +278,8 @@ test('relative path from multiple files', function(t) { t.end() }); -test('relative path when source and file name are the same', function(t) { - var gen1Map = { +test('relative path when source and file name are the same', async function(t) { + const gen1Map = { version: 3, sources: [ 'a/b/one.js' ], names: [], @@ -288,7 +288,7 @@ test('relative path when source and file name are the same', function(t) { sourcesContent: [ 'console.log(1);\n' ] }; - var gen2Map = { + const gen2Map = { version: 3, sources: [ 'a/b/two.js' ], names: [], @@ -297,24 +297,24 @@ test('relative path when source and file name are the same', function(t) { sourcesContent: [ 'console.log(2);\n' ] }; - var base64 = combine.create() - .addFile({ - source: 'console.log(1);\n' + convert.fromObject(gen1Map).toComment(), - sourceFile: 'a/b/one.js' - }) - .addFile({ - source: 'console.log(2);\n' + convert.fromObject(gen2Map).toComment(), - sourceFile: 'a/b/two.js' - }, {line: 1}) - .base64() + const map = combine.create(); + await map.addFile({ + source: 'console.log(1);\n' + convert.fromObject(gen1Map).toComment(), + sourceFile: 'a/b/one.js' + }); + await map.addFile({ + source: 'console.log(2);\n' + convert.fromObject(gen2Map).toComment(), + sourceFile: 'a/b/two.js' + }, {line: 1}); + const base64 = map.base64(); - var sm = convert.fromBase64(base64).toObject(); + const sm = convert.fromBase64(base64).toObject(); t.deepEqual(sm.sources, ['a/b/one.js', 'a/b/two.js'], 'include the correct source'); t.deepEqual( - mappingsFromMap(sm) + await mappingsFromMap(sm) , [ { original: { column: 0, line: 1 }, generated: { column: 0, line: 1 }, source: 'a/b/one.js', @@ -327,20 +327,20 @@ test('relative path when source and file name are the same', function(t) { }); test('remove comments', function (t) { - var mapComment = convert.fromObject(foo).toComment(); + const mapComment = convert.fromObject(foo).toComment(); function sourcemapComments(src) { - var matches = src.match(commentRegex); + const matches = src.match(commentRegex); return matches ? matches.length : 0; } - t.equal(sourcemapComments('var a = 1;\n' + mapComment), 1); + t.equal(sourcemapComments('const a = 1;\n' + mapComment), 1); [ '' - , 'var a = 1;\n' + mapComment - , 'var a = 1;\n' + mapComment + '\nvar b = 5;\n' + mapComment + , 'const a = 1;\n' + mapComment + , 'const a = 1;\n' + mapComment + '\nconst b = 5;\n' + mapComment ] .forEach(function (x) { - var removed = combine.removeComments(x) + const removed = combine.removeComments(x) t.equal(sourcemapComments(removed), 0) }) t.end() From 1f6c781bac1ae3d2aff2a8cf19509acec8fb4474 Mon Sep 17 00:00:00 2001 From: AVVS Date: Mon, 23 Dec 2019 12:09:39 -0800 Subject: [PATCH 2/2] chore: revert public name --- package.json | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 31c3c77..7bbd52e 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@makeomatic/combine-source-map", + "name": "combine-source-map", "version": "0.9.0", "description": "Add source maps of multiple files, offset them and then combine them into one source map", "main": "index.js", @@ -38,5 +38,9 @@ "license": "MIT", "engine": { "node": ">=10.15.9" - } + }, + "files": [ + "lib/", + "index.js" + ] }