source-map-concat
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -0,3 +1,13 @@ | ||
### Version 0.2.0 (2014-06-05) ### | ||
- Allow passing a source map as a string and anything with a `.toJSON()` method | ||
(such as a `SourceMapGenerator`) as well as an object. | ||
- Rename `file.content` to `file.code`, to be consistent with | ||
`SourceNode.toStringWithSourceMap()` and rework (`css.stringify`). After all, | ||
in reality the content is going to be code, so we might just as well call it | ||
that. “code” is also shorter than “content”. (Backwards-incompatible change.) | ||
### Version 0.1.0 (2014-03-22) ### | ||
- Initial release. |
12
index.js
@@ -21,6 +21,10 @@ // Copyright 2014 Simon Lydell | ||
var node | ||
if (file.map) { | ||
var map = file.map | ||
if (map) { | ||
if (typeof map.toJSON === "function") { | ||
map = map.toJSON() | ||
} | ||
node = SourceNode.fromStringWithSourceMap( | ||
file.content, | ||
new SourceMapConsumer(file.map), | ||
file.code, | ||
new SourceMapConsumer(map), | ||
urix(path.relative( | ||
@@ -32,3 +36,3 @@ path.dirname( options.mapPath || "." ), | ||
} else { | ||
node = new SourceNode(null, null, null, file.content) | ||
node = new SourceNode(null, null, null, file.code) | ||
} | ||
@@ -35,0 +39,0 @@ |
{ | ||
"name": "source-map-concat", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"author": "Simon Lydell", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -19,7 +19,7 @@ Overview [![Build Status](https://travis-ci.org/lydell/source-map-concat.png?branch=master)](https://travis-ci.org/lydell/source-map-concat) | ||
source: file, | ||
content: fs.readFileSync(file).toString() | ||
code: fs.readFileSync(file).toString() | ||
} | ||
}) | ||
jsFiles.forEach(function(file) { | ||
var previousMap = resolveSourceMapSync(file.content, file.source, fs.readFileSync) | ||
var previousMap = resolveSourceMapSync(file.code, file.source, fs.readFileSync) | ||
if (previousMap) { | ||
@@ -29,3 +29,3 @@ file.map = previousMap.map | ||
} else { | ||
file.map = createDummySourceMap(file.content, {source: file.source, type: "js"}) | ||
file.map = createDummySourceMap(file.code, {source: file.source, type: "js"}) | ||
} | ||
@@ -76,6 +76,7 @@ }) | ||
- `content`: The content of the file, as a string. | ||
- `map`: The source map of the file, if any, as an object. It could be taken | ||
straight from a compiler, be resolved using [source-map-resolve] or created | ||
using [source-map-dummy]. | ||
- `code`: The contents of the file, as a string. | ||
- `map`: The source map of the file, if any, as an object, a string or anything | ||
with a `.toJSON()` method (such as a [`SourceMapGenerator`]). It could be | ||
taken straight from a compiler, be resolved using [source-map-resolve] or | ||
created using [source-map-dummy]. | ||
- `sourcesRelativeTo`: A path that `file.map.sources` are relative to. Defaults | ||
@@ -101,3 +102,4 @@ to `.`. | ||
[source-map-dummy]: https://github.com/lydell/source-map-dummy | ||
[SourceNode]: https://github.com/mozilla/source-map#sourcenode | ||
[`SourceNode`]: https://github.com/mozilla/source-map#sourcenode | ||
[`SourceMapGenerator`]: https://github.com/mozilla/source-map#sourcemapgenerator | ||
@@ -104,0 +106,0 @@ |
@@ -8,2 +8,3 @@ // Copyright 2014 Simon Lydell | ||
var SourceMapConsumer = sourceMap.SourceMapConsumer | ||
var SourceMapGenerator = sourceMap.SourceMapGenerator | ||
var createDummySourceMap = require("source-map-dummy") | ||
@@ -29,5 +30,5 @@ var expect = require("chai").expect | ||
var concatenated = concat([ | ||
{content: "a"}, | ||
{content: "b"}, | ||
{content: "c"} | ||
{code: "a"}, | ||
{code: "b"}, | ||
{code: "c"} | ||
]).toString() | ||
@@ -40,5 +41,5 @@ expect(concatenated).to.equal("abc") | ||
var concatenated = concat([ | ||
{content: "a\na"}, | ||
{content: "b\rb"}, | ||
{content: "c\r\nc"} | ||
{code: "a\na"}, | ||
{code: "b\rb"}, | ||
{code: "c\r\nc"} | ||
]).toString() | ||
@@ -51,5 +52,5 @@ expect(concatenated).to.equal("a\nab\rbc\r\nc") | ||
var concatenated = concat([ | ||
{content: "a"}, | ||
{content: "b"}, | ||
{content: "c"} | ||
{code: "a"}, | ||
{code: "b"}, | ||
{code: "c"} | ||
], { | ||
@@ -64,5 +65,5 @@ delimiter: "|" | ||
var concatenated = concat([ | ||
{content: "a", foo: "A"}, | ||
{content: "b", foo: "B"}, | ||
{content: "c", foo: "C"} | ||
{code: "a", foo: "A"}, | ||
{code: "b", foo: "B"}, | ||
{code: "c", foo: "C"} | ||
], { | ||
@@ -142,5 +143,5 @@ process: function(node, file, index) { | ||
var node = concat([ | ||
{ content: js.join(""), map: createDummySourceMap(js, {source: "foo.js"}) }, | ||
{ content: "between" }, | ||
{ content: css.join(""), map: createDummySourceMap(css, {source: "foo.css"}) } | ||
{ code: js.join(""), map: createDummySourceMap(js, {source: "foo.js"}) }, | ||
{ code: "between" }, | ||
{ code: css.join(""), map: createDummySourceMap(css, {source: "foo.css"}) } | ||
], { | ||
@@ -204,4 +205,4 @@ delimiter: "\n", | ||
var concatenated1 = concat([ | ||
{ content: foo.code, map: foo.map.toJSON() }, | ||
{ content: bar.code, map: bar.map.toJSON() } | ||
{ code: foo.code, map: foo.map.toJSON() }, | ||
{ code: bar.code, map: bar.map.toJSON() } | ||
], { | ||
@@ -217,4 +218,4 @@ mapPath: "concatenated1.js.map" | ||
var concatenated2 = concat([ | ||
{ content: foo.code, map: foo.map.toJSON() }, | ||
{ content: bar.code, map: bar.map.toJSON() } | ||
{ code: foo.code, map: foo.map.toJSON() }, | ||
{ code: bar.code, map: bar.map.toJSON() } | ||
], { | ||
@@ -230,4 +231,4 @@ mapPath: sep("out/concatenated2.js.map") | ||
var concatenated2Alt = concat([ | ||
{ content: foo.code, map: foo.map.toJSON(), sourcesRelativeTo: sep("../foo.js.map") }, | ||
{ content: bar.code, map: bar.map.toJSON() } | ||
{ code: foo.code, map: foo.map.toJSON(), sourcesRelativeTo: sep("../foo.js.map") }, | ||
{ code: bar.code, map: bar.map.toJSON() } | ||
]).toStringWithSourceMap() | ||
@@ -241,4 +242,4 @@ | ||
var concatenated3 = concat([ | ||
{ content: foo.code, map: foo.map.toJSON(), sourcesRelativeTo: sep("js/foo.js.map") }, | ||
{ content: bar.code, map: bar.map.toJSON() } | ||
{ code: foo.code, map: foo.map.toJSON(), sourcesRelativeTo: sep("js/foo.js.map") }, | ||
{ code: bar.code, map: bar.map.toJSON() } | ||
], { | ||
@@ -255,2 +256,35 @@ mapPath: sep("public/concatenated3.js.map") | ||
it("allows the map to be an object, a string or anything with `.toJSON()`", function() { | ||
var generator = new SourceMapGenerator() | ||
generator.addMapping({ | ||
generated: { | ||
line: 1, | ||
column: 1 | ||
}, | ||
original: { | ||
line: 2, | ||
column: 2 | ||
}, | ||
source: "foo" | ||
}) | ||
var generateMap = function(map) { | ||
return concat([{ code: "bar", map: map }]).toStringWithSourceMap().map.toString() | ||
} | ||
var mapFromObject = generateMap(generator.toJSON()) | ||
var mapFromString = generateMap(generator.toString()) | ||
var mapFromToJSON = generateMap({ toJSON: function() { return generator.toJSON() } }) | ||
var mapFromSourceMapGenerator = generateMap(generator) | ||
expect(mapFromObject).to.equal(mapFromString) | ||
expect(mapFromString).to.equal(mapFromToJSON) | ||
expect(mapFromToJSON).to.equal(mapFromSourceMapGenerator) | ||
expect(mapFromSourceMapGenerator).to.equal(mapFromObject) | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13918
267
107