brunch / brunch

:fork_and_knife: Web applications made easy. Since 2011.
https://brunch.io
MIT License
6.8k stars 433 forks source link

Source maps don't always map back to the original sources. #1635

Closed lydell closed 6 years ago

lydell commented 7 years ago

Description

Source maps don't always map back to the original sources.

Expected/Actual behavior

Example repo: https://github.com/lydell/brunch-sources-content-bug

public/concat.css.map is correct:

{
  "version": 3,
  "sources": [
    "app/concat1.css",
    "app/concat2.css"
  ],
  "names": [],
  "mappings": "AAAA;AACA;AACA;AACA;ACHA;AACA;AACA;AACA",
  "file": "public/concat.css",
  "sourcesContent": [
    "a {\n  color: black;\n}\n",
    "b {\n  font-weight: bold;\n}\n"
  ]
}

public/concat.js.map is correct:

{
  "version": 3,
  "sources": [
    "app/concat1.js",
    "app/concat2.js"
  ],
  "names": [],
  "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AACA;AADA;AAAA;CCAA;AAAA;AACA;AADA;AAAA",
  "file": "public/concat.js",
  "sourcesContent": [
    "console.log('concat1')\n",
    "console.log('concat2')\n"
  ]
}

public/require.js.map is wrong. It misses the "app/_hello.js" source, and the included source content is the contents of public/require.js, not of app/main.js.

{
  "version": 3,
  "sources": [
    "app/main.js"
  ],
  "names": [],
  "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AACA;AACA;AAFA;AAAA",
  "file": "public/require.js",
  "sourcesContent": [
    "var hello = require('./_hello')\nconsole.log(hello)\n"
  ]
}

public/sass.css.map is wrong. It misses the "app/_include.scss" source, and the included source content is the contents of public/sass.css, not of app/main.scss.

{
  "version": 3,
  "sources": [
    "app/main.scss"
  ],
  "names": [],
  "mappings": "AAAA;AACA;AACA;AACA;AACA;AACA;AACA",
  "file": "public/sass.css",
  "sourcesContent": [
    "b {\n  font-weight: bold; }\n\na {\n  color: black; }\n\n"
  ]
}

Environment

  1. Brunch: 2.10.2
  2. Node: 6.9.1
  3. NPM: 3.10.8
  4. Operating system: Ubuntu 16.04

package.json contents

{
  "private": true,
  "devDependencies": {
    "brunch": "^2.10.2",
    "css-brunch": "^2.6.1",
    "javascript-brunch": "^2.0.0",
    "sass-brunch": "^2.9.0"
  }
}

brunch config contents

module.exports = {
  files: {
    stylesheets: {
      joinTo: {
        'concat.css': /\.css$/,
        'sass.css': /\.scss$/,
      }
    },
    javascripts: {
      joinTo: {
        'concat.js': /concat\d\.js$/,
        'require.js': 'app/main.js'
      }
    }
  }
}
kgcreative commented 7 years ago

Can confirm. Having this issue in 2.10.2 as well. Reverting back to 2.9.1 seems to work just fine.

Relevant brunch-config.cofee snippet:

  plugins:
    coffeescript:
      bare: true

    sass:
      # use libsass
      mode: 'native'
      # Add optional includes
      options:
        includePaths: [
          'node_modules/bourbon/core'
        , 'node_modules/bourbon-neat/core'
        , 'node_modules/normalize.css'
        , 'node_modules/font-awesome/scss'
        ]
      # To enable embedded source maps, pass the option `sourceMapEmbed`.
      # This is only supported in _native_ mode; Ruby Sass isn't supported.
      sourceMapEmbed: true
      # Set the precision for arithmetic operations.
      precision: 10
      allowCache: false

    postcss:
      map: true
      processors:
        require('autoprefixer')(['defaults', 'last 3 versions', '> 1%'])

Relevant package.json bits:

{
  "scripts": {
    "start": "brunch watch --server --port 3333",
    "build": "brunch build --production"
  },
  "dependencies": {
    "fastclick": "^1.0.6",
    "jquery": "^3.1.1",
    "normalize.css": "^5.0.0"
  },
  "devDependencies": {
    "auto-reload-brunch": "^2.0.5",
    "autoprefixer": "^6.6.1",
    "bourbon": "^=5.0.0-beta.7",
    "bourbon-neat": "^=2.0.0-beta.2",
    "brunch": "2.9.1",
    "brunch-static": "^1.2.1",
    "clean-css-brunch": "^2.0.0",
    "coffee-script-brunch": "^2.1.0",
    "font-awesome": "^=4.7.0",
    "html-brunch-static": "^1.3.1",
    "javascript-brunch": "^2.0.0",
    "postcss-brunch": "0.5.0",
    "sass-brunch": "^=2.9.0",
    "uglify-js-brunch": "^2.0.0"
  },
  "license": "MIT"
}

edit/update: 2.9.1 seems to work, 2.10, 2.10.1 and 2.10.2 don't properly generate CSS source maps. Or rather, the source map only tracks the root file (i.e. css/all.scss), and not css/site/_pages.scss, for example.

denysdovhan commented 7 years ago

Hi, @kgcreative, could you ensure me that https://github.com/lydell/brunch-sources-content-bug reproduces your bug as well as it does for @lydell.

kgcreative commented 7 years ago

@denysdovhan - Yes, that branch reproduces the same behavior i experience on my build.

millerized commented 7 years ago

@shvaikalesh can you please confirm that https://github.com/babel/babel-brunch/issues/56 is related? If so, I will close it out.

shvaikalesh commented 7 years ago

Yep, it is.

sehcheese commented 7 years ago

Any fixes coming down the pipes for this? Is the temporary fix to use 2.9.1?

silbinarywolf commented 7 years ago

FYI, when I used 2.9.1 I ended up losing compile-time errors so... I'm sticking with 2.10.x

shreeve commented 6 years ago

Does pull request #1756 help at all?

jkruse commented 6 years ago

Something is still off.

2.10.10, dev build (brunch watch): sourcemap contains output from Babel (transpiled code), line numbers on errors are correct.

1756, dev build: sourcemap contains original code, but line numbers are still from Babel output, so they don't match.

2.10.10, prod build (with sourcemap): sourcemap contains original code, but line numbers are from Babel output, so they don't match.

1756, prod build: same as 2.10.10 (original code, but bad line numbers).

I hope someone can confirm. For me this only makes it worse, because with 2.10.10 at least on a dev build I got line numbers matching the (bad) sourcemap.

millerized commented 6 years ago

1756, prod build: same as 2.10.10 (original code, but bad line numbers).

I hope someone can confirm. For me this only makes it worse, because with 2.10.10 at least on a dev build I got line numbers matching the (bad) sourcemap.

I can confirm. I have installed the latest release from today 2.10.11.

/cc @jkruse @shreeve @shvaikalesh

friday commented 6 years ago

I've submitted a PR #1757 that I believe fixes it completely (tested with @jkruse's testing scenarios with source, line numbers and singular or multiple processing steps). I've only tested with my own setup (buble, uglify, postcss and clean-css).

Someone else with a different setup verifying this certainly won't harm.

jkruse commented 6 years ago

Works with Babel too, thanks @friday

viviansteller commented 6 years ago

Confirmed that this issue is fixed with 2.10.12; <= 2.10.11 had trouble

ventaur commented 5 years ago

I'm on Brunch 2.10.16 and the line numbers for sourcemaps are off for npm_modules JS included.