mariusGundersen / gulp-amd-optimizer

Emits the entire dependency tree of one or more AMD modules, from leaves to root, and names anonymous modules
22 stars 4 forks source link

Sourcemaps Not Playing Nice with Sourcemaps from earlier in the pipeline #10

Closed ijabit closed 8 years ago

ijabit commented 8 years ago

I have a task that runs a TypeScript compiler first to get the resulting JS. Then I run it through this plugin to get an amd-optimized module for bundling purposes. The TS -> JS transpile operation generates it's own sourcemaps, which aren't passed through this plugin. As soon as I hit this plugin, it only outputs the maps that gulp-amd-optimizer generates and seems to throw away the previous maps. Am I doing something wrong, or is this a missing feature?

Thanks!

mariusGundersen commented 8 years ago

That's strange, it should be working with sourcemap, as per the example in the Readme. Note that you have to load the sourcemaps into the gulp pipeline for it to work. Have a look at the gulp-sourcemaps package for how to load existing sourcemaps into the gulp pipeline.

ijabit commented 8 years ago

The entire process happens in one task. Here is the abbreviated task: gulp.src([paths.typeScriptFiles, paths.typeScriptDefinitionFiles], { base: paths.typescriptSrcFolder }) ... .pipe(sourcemaps.init()) ... .pipe(ts(tsProject, {}, visualStudioReporter())) ... // everything is fine here and sourcemaps.write(...) will output the correct TypeScript sourcemaps .pipe(gAmdOptimize({ baseUrl: paths.typescriptSrcFolder, exclude: ["require", "exports"], preserveFiles: true })) // now the only sourcemaps that will be output are the ones that got translated during the gAmdOptimize plugin

Are you saying I'd have to dump the .js and .map files out and then reload them for the plugin to recognize them?

mariusGundersen commented 8 years ago

That looks like the correct way to do it. A good way to debug this is to use gulp-tap between ts and gAO to see what files you have and what properties they have. The way gulp-sourcemaps works is that the sourcemap is a property on the file, instead of being a separate file in the pipeline. It might be that the ts compiler isn't outputting it in this format. I'm not familiar with how ts and gulp work together, but that would be my guess

ijabit commented 8 years ago

Okay, I output the contents of the sourcemap property on the file and the map definitely exists after being output from the gulp-typescript plugin. It is in this format: { "version":3, "sources":["shared/NotificationsVm.js","shared/NotificationsVm.ts"], "names":[], "mappings":"...", "file":"shared/NotificationsVm.js","sourcesContent":[...] }

ijabit commented 8 years ago

Hi Marius, so given the fact that the files do have the .sourcemap property set to the above object, how can I get this plugin to stop resetting the sourcemap?

Thanks!

mariusGundersen commented 8 years ago

You don't happen to have this code on github somewhere? So I can try it? Or else I need to create a simple test case to see if I can reproduce it.

ijabit commented 8 years ago

I stripped out as much stuff as I could to make a basic repro. See here: SourcemapRepro.zip

Just download, extract, restore packages, and run the index.html file. It's currently setup to use your plugin, bundle the modules, and then load the modules bundle. You can toggle the requirejs calls to pull in the non-optimized and non-bundled versions and see that the sourcemaps are fine. before after

ijabit commented 8 years ago

Marius, do you have everything you need to look at this? Does the reproducible project work? Thanks.

ijabit commented 8 years ago

Bump

mariusGundersen commented 8 years ago

Sorry, I've been very busy lately.

Try using the 0.5.0 version of gulp-amd-optimizer, and see if that helps

ijabit commented 8 years ago

Nope, no difference in amd-optimizer 0.5.0. I tried it in my project and the previously attached sample project. Thanks.

mariusGundersen commented 8 years ago

Small bugfix, and I can now get it to work here: https://github.com/mariusGundersen/test-gulp-amd-optimizer

ijabit commented 8 years ago

Yes! Thank you so much! It's working great now.