Coder Social home page Coder Social logo

concat-with-sourcemaps's People

Contributors

floridoo avatar kapouer avatar rpetrich avatar scottweinstein avatar waldyrious avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

concat-with-sourcemaps's Issues

fileName vs sourceMap.file

Hi @floridoo,

thanks for your excellent work on sourcemaps. I stumbled upon a problem where I'm not sure who's to blame.

My gulpfile contains the following snippet:

gulp.src(["js/*.jsx"])
        .pipe(react()) // file.path = gutil.replaceExtension(filePath, '.js');
        .pipe(concat(filename))

After the react() step, file.path ends with .js and file.sourceMap looks like this:

{ version: 3,
  file: 'js/router.jsx',
  names: [],
  mappings: '',
  sources: [ 'js/router.jsx' ],
  sourcesContent: [ '...' ] }

This still looks good to me. Now, gulp-concat gets into play:

{ version: 3,
  file: "app.js",
  names: [],
  mappings : "...",
  sources: ["js\\router.js"],
  sourcesContent: [ '...' ]}

i originally started with a .jsx file, but now I'm left with a .js file in the source mapping. Here's the relevant snippet in gulp-concat calling concat-with-sourcemaps:

concat.add(file.relative, file.contents.toString(), file.sourceMap);

Now, which party is to blame?
Should gulp-concat use

concat.add(file.sourceMap ? file.sourceMap.file : file.relative, file.contents.toString(), file.sourceMap);

or should concat-with-sourcemaps infer the filename from the sourcemap if possible? I'm happy to provide a PR for this.

Thanks!
Max

Missing steps in README

I was able to get this working, but had to figure out that I was supposed to remove the "//# sourceMappingURL=..." statement from the content of each of the files I was passing in (which each had sourcemaps), and then add a single "//# sourceMappingURL=..." back to the concatenated file. Some guidance in the README would have been helpful.

Empty files break sourcemap

Hello,

Please refer to this gulp-community/gulp-concat#66 . concat with sourcemap fails if there is a file with empty content, which is common in typescript if it only contain definitions.

I get exactly the same stack trace as in the linked issue. Please see it for example configuration and context.

<root>/applications/gulp-tools/node_modules/gulp-concat/node_modules/concat-with-sourcemaps/node_modules/source-map/lib/source-map/source-map-generator.js:273
        throw new Error('Invalid mapping: ' + JSON.stringify({
              ^
Error: Invalid mapping: {"generated":{"line":1,"column":0},"original":{"line":1,"column":0},"name":null}
    at SourceMapGenerator_validateMapping [as _validateMapping] (<root>/applications/gulp-tools/node_modules/gulp-concat/node_modules/concat-with-sourcemaps/node_modules/source-map/lib/source-map/source-map-generator.js:273:15)
    at SourceMapGenerator_addMapping [as addMapping] (<root>/applications/gulp-tools/node_modules/gulp-concat/node_modules/concat-with-sourcemaps/node_modules/source-map/lib/source-map/source-map-generator.js:102:12)
    at Concat.add (<root>/applications/gulp-tools/node_modules/gulp-concat/node_modules/concat-with-sourcemaps/index.js:75:25)
    at Stream.bufferContents (<root>/applications/gulp-tools/node_modules/gulp-concat/index.js:35:12)
    at Stream.stream.write (<root>/applications/gulp-tools/node_modules/gulp-concat/node_modules/through/index.js:26:11)
    at write (_stream_readable.js:583:24)
    at flow (_stream_readable.js:592:7)
    at CompileStream.pipeOnReadable (_stream_readable.js:624:5)
    at CompileStream.EventEmitter.emit (events.js:92:17)
    at emitReadable_ (_stream_readable.js:408:10)
    at emitReadable (_stream_readable.js:404:5)
    at readableAddChunk (_stream_readable.js:165:9)
    at CompileStream.Readable.push (_stream_readable.js:127:10)
    at emit (<root>/applications/gulp-tools/node_modules/gulp-typescript/release/project.js:245:22)
    at sortedEmit (<root>/applications/gulp-tools/node_modules/gulp-typescript/release/project.js:267:17)
    at Project.compile (<root>/applications/gulp-tools/node_modules/gulp-typescript/release/project.js:273:17)
    at CompileStream.compile (<root>/applications/gulp-tools/node_modules/gulp-typescript/release/main.js:53:23)
    at CompileStream.end (<root>/applications/gulp-tools/node_modules/gulp-typescript/release/main.js:63:14)
    at DestroyableTransform.onend (<root>/applications/gulp-tools/node_modules/gulp-sourcemaps/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:523:10)
    at DestroyableTransform.g (events.js:180:16)
    at DestroyableTransform.EventEmitter.emit (events.js:117:20)
    at <root>/applications/gulp-tools/node_modules/gulp-sourcemaps/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:965:16
    at process._tickDomainCallback (node.js:459:13)

Generates a blank sourcemap

I've tried working with webpack-concat-plugin that relies on this library and got the following broken sourcemap:

{"version":3,"sources":["/app/legacy/js/communicator.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"legacy.522b8504.js"}

I've tried to debug the issue by running this package directly, like so.

I am concatenating the following:

test1.js
console.log("I am test 1")

test2.js
console.log("I am test 2")

Using this code:

var fs = require('fs');
var Concat = require('concat-with-sourcemaps')

var file1Content = fs.readFileSync("./test1.js");
var file2Content = fs.readFileSync("./test2.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);

var concatenatedContent = concat.content;
var sourceMapForContent = concat.sourceMap;

console.log(concatenatedContent.toString('utf8'))
console.log("////")
console.log(sourceMapForContent.toString('utf8'))

Resulting sourcemap
{"version":3,"sources":["file1.js","file2.js"],"names":[],"mappings":";AAAA;ACAA","file":"all.js"}

As expected, since it lacks actual mappings, this sourcemap doesn't work and shows as blank in Chrome. Does anyone know why it's happening?

Here is the repo with the code above:

https://github.com/vitalybe/concat-with-sourcemaps-test

Arbitrarily arrange files position, not just append

Having a use case which requires to concat file based on created dates or names, currently Concat only has a 'push' which appends file.contents to the list. I did a quick fix by adding another function which takes an additional 'fileIndex' argument indicating which position should the file contents go. Not sure if this is on the roadmap and just wondered if this fix can be merged.

Version 1.0.6 Breaks with older version of node.js

Currently on an application with node.js version 0.10.38, and after the latest NPM install, got an error saying
Buffer has no method 'from'.

It appears this is because the Buffer.from method was added in a later version of node.js.

I am using gulp-concat.

Mappings with no source cause a crash

Sort of hard to explain. I am using AngularJS, and they do some particularly weird things with minification (removing long error message strings etc) so I want to start from their minified sources, for which they already provide source maps, which I want to build on.

It looks like the banner comment is not present in the original but mappings are still added with undefined source line and columns to the source map included with the minified distribution. As a result, SourceMapGenerator chokes on

_this._sourceMap.addMapping({
  generated: {
    line: _this.lineOffset + mapping.generatedLine,
    column: (mapping.generatedLine === 1 ? _this.columnOffset : 0) + mapping.generatedColumn
  },
  original: {
    line: mapping.originalLine,
    column: mapping.originalColumn
  },
  source: mapping.source,
  name: mapping.name
});

Saying that original: {} is invalid.

I wrapped that line in the conditional if (typeof mapping.originalLine !== 'undefined' && typeof mapping.originalColumn !== 'undefined') and it seemed to work as expected, but I am not sure if there are other potentially dangerous effects. If this seems like a reasonable fix, I will submit a pull request, but I am also not sure how to reasonably write a test for it that isn't super contrived.

Adding the same file multiple times

Hi,

I would like to be able to make a flow using gulp-watch that would reconcat files each time something changes. I saw an old fork of gulp-concat that instead of contenating files on stream end would concatenate them after a debounce of xms. If a file is emitted twice (because it was modified twice), then it would reconcat properly everything.

I believe one of the right ways of doing this would be to allow to call add twice on the concat method with the same file. The obvious problem is that the concatenation is done right away by your library. Would it be possible to concatenate only when accessing and thus to support swapping the file?

Or is this somehow a very bad design and this should be achieved differently (like write intermediate files with the sourcemaps & reloading them before concat each time, but this seems slow)?

gulp-concat seems to have been broken with the latest update of your package for Visual Studio users

I don't think this is in any way your responsibility, but I figured I would let you know in case you wanted to do anything about it.

I'm not sure how widespread this is, but as of this morning my gulp-concat tasks in visual studio stopped working. I have already reported an issue to the gulp-concat repo, so you can find the details here
gulp-community/gulp-concat#142

I don't know much about this stuff, but it looks to me like your package may now have a higher node dependency than what visual studio installs by default. I'm sure the workaround is to have visual studio users use a more up to date version of node, but most users don't have that. I'm going to also work on figuring out how to address this, but I just wanted to let you know about the issue

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.