gulp-community / gulp-concat

Streaming concat middleware for gulp
MIT License
792 stars 126 forks source link

names array not populated when creating sourcemaps using gulp-concat. #59

Closed wayneseymour closed 9 years ago

wayneseymour commented 10 years ago

What I'm experiencing

I was working through this issue and noticed that when I use gulp-concat, the names array is always empty.

This is true even during trivial cases (one file being source-mapped). @floridoo mentioned it was probably gulp-rev causing my issue, but so far that's not what I've found.
btw, thanks to @floridoo for responding expediently.

Snippet

  return gulp.src('source/some-dir/another-dir/one-file-to-be-sourcemapped.js')
    .pipe(sourcemaps.init())
//    .pipe(concat('built.js')) // If I uncomment this line, the names array is empty.
     .pipe(uglify())
    .pipe(rev())
    .pipe(transformFooter())
    .pipe(sourcemaps.write('./', { addComment: false}))
    .pipe(gulp.dest(destination));

My true intention

I want to un-minify the source maps (due to an exception being thrown) at runtime.
so far using mozilla source-map I can still get the line number and column, but not the name.

yocontra commented 10 years ago

The names array?

cc @floridoo

wayneseymour commented 10 years ago

My apologies @contra The names array in the sourcemap object literal.

jmm commented 9 years ago

I'm seeing the same thing (without gulp-rev in play). Where the fault lies, who knows; there seem to be a lot of source map-related issues and bad interactions going on between gulp plugins right now. And further complicating matters, the names feature doesn't even seem to be working for me in Chrome.

A task like this produces source map output like this:

gulp.task('default', function () {
  return gulp
    .src(['./src/script.js'])
    .pipe(sourcemaps.init())
      .pipe(concat('script.js'))
      .pipe(uglify())
    .pipe(sourcemaps.write('./'))
    .pipe(gulp.dest('./dist'));
});
{"version":3,"sources":["script.js"],"names":[],"mappings":"CAAA,SAAA,GAAA,QAAA,IAAA,IAAA","file":"script.js","sourcesContent":["(function (x) { console.log(x); })(\"x\");\n"],"sourceRoot":"/source/"}

While a task like this produces source map output like this:

gulp.task('default', function () {
  return gulp
    .src(['./src/script.js'])
    .pipe(sourcemaps.init())
      // .pipe(concat('script.js'))
      .pipe(uglify())
    .pipe(sourcemaps.write('./'))
    .pipe(gulp.dest('./dist'));
});
{"version":3,"sources":["?"],"names":["x","console","log"],"mappings":"CAAA,SAAWA,GAAKC,QAAQC,IAAIF,IAAO","file":"script.js","sourcesContent":[null],"sourceRoot":"/source/"}
yocontra commented 9 years ago

cc @floridoo

Yeah, there are a lot of problems with gulp-sourcemaps right now. It seems to be extremely fragile and plugins need to be very careful to pass the perfect data into it.

@floridoo Is there any way we can throw errors on missing data, or try to be more lenient on input data to prevent these problems from happening? For example, less updated so gulp-less updated to the new version. sourcemaps broke because the sourcemap less was giving back needed to be massaged to work with the apply sourcemaps stuff, but this was only found out after users reported it was broken.

heikki commented 9 years ago

This seems to work now.

var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');

gulp.task('default', function () {
    return gulp.src(['src/script.js'])
        .pipe(sourcemaps.init())
        .pipe(concat('script.js'))
        .pipe(uglify())
        .pipe(sourcemaps.write('.'))
        .pipe(gulp.dest('dist'));
});

package.json

{
  "dependencies": {
    "gulp": "^3.8.11",
    "gulp-concat": "^2.5.0",
    "gulp-sourcemaps": "^1.3.0",
    "gulp-uglify": "^1.1.0"
  }
}

dist/script.js

function foo(o,n){console.log(o,n)}
//# sourceMappingURL=script.js.map

dist/script.js.map

{"version":3,"sources":["script.js"],"names":["foo","bar","baz","console","log"],"mappings":"AAAA,QAAAA,KAAAC,EAAAC,GACAC,QAAAC,IAAAH,EAAAC","file":"script.js","sourcesContent":["function foo(bar, baz) {\n\tconsole.log(bar, baz);\n}\n"],"sourceRoot":"/source/"}