swc-project / swc

Rust-based platform for the Web
https://swc.rs
Apache License 2.0
31.24k stars 1.23k forks source link

Omitting the `sourcesContent` property from the sourcemaps breaks Browserify and ESBuild #2244

Closed djalbat closed 3 years ago

djalbat commented 3 years ago

SWC has always added a sourcesContent property to source maps in the past. For example:

https://github.com/djalbat/necessary/blob/master/lib/utilities/shell.js

This project is transpiled with SWC version 1.2.52.

If you un-encode and format the source map in this file you will get:

{
   "version":3,
   "sources":[
      "../../src/utilities/shell.js"
   ],
   "sourcesContent":[
      "\"use strict\";\n\nimport { whilst } from \"../utilities/asynchronous\";\n\nimport { DATA_EVENT_TYPE } from \"../eventTypes\";\nimport { UTF8, CTRL_C, EMPTY_STRING } from \"../constants\";\nimport { DEFAULT_ENCODING, DEFAULT_ATTEMPTS, DEFAULT_INITIAL_ANSWER } from \"../defaults\";\nimport { ETX_CHARACTER, BACKSPACE_CHARACTER, LINE_FEED_CHARACTER, CARRIAGE_RETURN_CHARACTER } from \"../characters\";\n\nexport function onETX(handler) {\n  if (process.stdin.setRawMode) {\n    const rawMode = true,\n          encoding = UTF8;\n\n    process.stdin.setRawMode(rawMode);\n\n    process.stdin.setEncoding(encoding);\n\n    process.stdin.addListener(DATA_EVENT_TYPE, dataHandler);\n\n    process.stdin.resume();\n\n    return offExt;\n  }\n\n  function offExt() {\n    process.stdin.removeListener(DATA_EVENT_TYPE, dataHandler);\n  }\n\n  function dataHandler(character) {\n    if (character === ETX_CHARACTER) {\n      handler();\n    }\n  }\n}\n\nexport function prompt(options, callback) {\n  let { answer = null } = options;\n\n  if (answer !== null) {\n    callback(answer);\n\n    return;\n  }\n\n  const { attempts = DEFAULT_ATTEMPTS } = options,\n        context = {\n          answer,\n          options,\n          attempts\n        };\n\n  whilst(attempt, () => {\n    const { answer } = context;\n    \n    callback(answer);\n  }, context);\n}\n\nexport default {\n  onETX,\n  prompt\n}\n\nfunction attempt(next, done, context) {\n  let { attempts } = context;\n\n  const terminate = (attempts-- === 0);\n  \n  if (terminate) {\n    done();\n    \n    return;\n  }\n\n  const { options } = context,\n        { hidden = false,\n          encoding = DEFAULT_ENCODING,\n          description,\n          errorMessage,\n          initialAnswer = DEFAULT_INITIAL_ANSWER,\n          validationPattern = null,\n          validationFunction = null } = options;\n\n  input(initialAnswer, hidden, description, encoding, callback);\n\n  function callback(answer) {\n    const valid = validationFunction ?  ///\n                    validationFunction(answer) :\n                      validationPattern.test(answer);\n\n    if (valid) {\n      Object.assign(context, {\n        answer\n      });\n\n      done();\n    } else {\n      console.log(errorMessage);\n\n      Object.assign(context, {\n        attempts\n      });\n\n      next();\n    }\n  }\n}\n\nfunction input(initialAnswer, hidden, description, encoding, callback) {\n  const answer = initialAnswer; ///\n\n  hidden ?\n    hiddenInput(answer, description, encoding, callback) :\n      visibleInput(answer, description, encoding, callback);\n}\n\nfunction hiddenInput(answer, description, encoding, callback) {\n  const rawMode = true;\n\n  process.stdout.write(description);\n\n  process.stdin.setEncoding(encoding);\n\n  process.stdin.setRawMode(rawMode);\n\n  process.stdin.on(DATA_EVENT_TYPE, listener);\n\n  process.stdin.resume();\n\n  function listener(data) {\n    const character = data.toString(encoding);\n\n    switch (character) {\n      case LINE_FEED_CHARACTER :\n      case CARRIAGE_RETURN_CHARACTER :\n        process.stdout.write(LINE_FEED_CHARACTER);\n\n        process.stdin.removeListener(DATA_EVENT_TYPE, listener);\n\n        process.stdin.pause();\n\n        callback(answer);\n\n        break;\n\n      case BACKSPACE_CHARACTER :\n        answer = answer.slice(0, answer.length - 1);\n\n        break;\n\n      default:\n        answer += character;\n\n        break;\n\n      case ETX_CHARACTER :\n        console.log(CTRL_C);\n\n        process.exit();\n    }\n  }\n}\n\nfunction visibleInput(answer, description, encoding, callback) {\n  process.stdout.write(description);\n\n  process.stdout.write(answer);\n\n  process.stdin.setEncoding(encoding);\n\n  process.stdin.once(DATA_EVENT_TYPE, listener);\n\n  process.stdin.resume();\n\n  function listener(data) {\n    const answer = data.replace(/\\n$/, EMPTY_STRING);\n\n    process.stdin.pause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AAC;;;gBAK1C,MAAM,IAAI,SAAS;;iBAjJwE,WAAe;gBAsJ1G,OAAO,CAAC,GAAG,CAxJwB,UAAc;gBA0JjD,OAAO,CAAC,IAAI;;IAElB,CAAC;AACH,CAAC;SAEQ,YAAY,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC;QAWrD,QAAQ,YAAR,QAAQ,CAAC,IAAI,EAAE,CAAC;QACvB,GAAK,CAAC,OAAM,GAAG,IAAI,CAAC,OAAO,QA3KY,UAAc;QA6KrD,OAAO,CAAC,KAAK,CAAC,KAAK;QAEnB,QAAQ,CAAC,OAAM;IACjB,CAAC;IAhBD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW;IAEhC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM;IAE3B,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,QAAQ;IAElC,OAAO,CAAC,KAAK,CAAC,IAAI,CAvKY,WAAe,kBAuKT,QAAQ;IAE5C,OAAO,CAAC,KAAK,CAAC,MAAM;AAStB,CAAC"
}

You can clearly see the sourcesContent property.

If I now transpile this project with the latest version 1.2.86 of SWC, I get the following source map:

{
   "version":3,
   "sources":[
      "../../src/utilities/shell.js"
   ],
   "names":[
      "whilst",
      "DATA_EVENT_TYPE",
      "UTF8",
      "CTRL_C",
      "EMPTY_STRING",
      "DEFAULT_ENCODING",
      "DEFAULT_ATTEMPTS",
      "DEFAULT_INITIAL_ANSWER",
      "ETX_CHARACTER",
      "BACKSPACE_CHARACTER",
      "LINE_FEED_CHARACTER",
      "CARRIAGE_RETURN_CHARACTER",
      "onETX",
      "handler",
      "process",
      "stdin",
      "setRawMode",
      "rawMode",
      "encoding",
      "setEncoding",
      "addListener",
      "dataHandler",
      "resume",
      "offExt",
      "removeListener",
      "character",
      "prompt",
      "options",
      "callback",
      "answer",
      "attempts",
      "context",
      "attempt",
      "next",
      "done",
      "terminate",
      "hidden",
      "description",
      "errorMessage",
      "initialAnswer",
      "validationPattern",
      "validationFunction",
      "input",
      "valid",
      "test",
      "Object",
      "assign",
      "console",
      "log",
      "hiddenInput",
      "visibleInput",
      "stdout",
      "write",
      "on",
      "listener",
      "data",
      "toString",
      "pause",
      "slice",
      "length",
      "exit",
      "once",
      "replace"
   ],
   "mappings":"CAAA,UAAY;;;;QASI,KAAK,GAAL,KAAK;QA2BL,MAAM,GAAN,MAAM;;AAlCC,GAA2B,CAA3B,aAA2B;AAElB,GAAe,CAAf,WAAe;AACJ,GAAc,CAAd,UAAc;AACkB,GAAa,CAAb,SAAa;AACW,GAAe,CAAf,WAAe;SAElG,KAAK,CAAC,OAAO,EAAE,CAAC;QAgBrB,MAAM,GAAf,QAAQ,CAAC,MAAM,GAAG,CAAC;QACjB,OAAO,CAAC,KAAK,CAAC,cAAc,CAtBA,WAAe,kBAsBG,WAAW;IAC3D,CAAC;QAEQ,WAAW,GAApB,QAAQ,CAAC,WAAW,CAAC,SAAS,EAAE,CAAC;QAC/B,EAAE,EAAE,SAAS,KAvBkF,WAAe,gBAuB7E,CAAC;YAChC,OAAO;QACT,CAAC;IACH,CAAC;IAvBD,EAAE,EAAE,OAAO,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;QAC7B,GAAK,CAAC,OAAO,GAAG,IAAI,EACd,QAAQ,GAPyB,UAAc;QASrD,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,OAAO;QAEhC,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,QAAQ;QAElC,OAAO,CAAC,KAAK,CAAC,WAAW,CAdG,WAAe,kBAcA,WAAW;QAEtD,OAAO,CAAC,KAAK,CAAC,MAAM;QAEpB,MAAM,CAAC,MAAM;IACf,CAAC;AAWH,CAAC;SAEe,MAAM,CAAC,OAAO,EAAE,QAAQ,EAAE,CAAC;IACzC,GAAG,WAAqB,OAAO,CAAzB,MAAM,EAAN,MAAM,wBAAG,IAAI;IAEnB,EAAE,EAAE,MAAM,KAAK,IAAI,EAAE,CAAC;Q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YACf,IAAI,CA/HyF,WAAe;YAgI5G,IAAI,CAhIyF,WAAe;gBAiI1G,OAAO,CAAC,MAAM,CAAC,KAAK,CAjIuE,WAAe;gBAmI1G,OAAO,CAAC,KAAK,CAAC,cAAc,CAtIJ,WAAe,kBAsIO,QAAQ;gBAEtD,OAAO,CAAC,KAAK,CAAC,KAAK;gBAEnB,QAAQ,CAAC,MAAM;gBAEf,KAAK;YAEP,IAAI,CA3IyF,WAAe;gBA4I1G,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC;gBAE1C,KAAK;;gBAGL,MAAM,IAAI,SAAS;gBAEnB,KAAK;YAEP,IAAI,CArJyF,WAAe;gBAsJ1G,OAAO,CAAC,GAAG,CAxJwB,UAAc;gBA0JjD,OAAO,CAAC,IAAI;;IAElB,CAAC;AACH,CAAC;SAEQ,YAAY,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC;QAWrD,QAAQ,GAAjB,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;QACvB,GAAK,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,QA3KY,UAAc;QA6KrD,OAAO,CAAC,KAAK,CAAC,KAAK;QAEnB,QAAQ,CAAC,MAAM;IACjB,CAAC;IAhBD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW;IAEhC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM;IAE3B,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,QAAQ;IAElC,OAAO,CAAC,KAAK,CAAC,IAAI,CAvKY,WAAe,kBAuKT,QAAQ;IAE5C,OAAO,CAAC,KAAK,CAAC,MAAM;AAStB,CAAC"
}

You can clearly see that the sourcesContent property is now missing.

So between versions 1.2.52 and 1.2.86 of SWC you have stopped adding the sourcesContent property to source maps.

The .swcrc file is:

{
    "jsc": {
        "parser": {
            "syntax": "ecmascript",
            "jsx": true
        }
    },
    "module": {
        "type": "commonjs"
    }
}
kdy1 commented 3 years ago

Yes, I stopped adding contents because there's sources

djalbat commented 3 years ago

So you are aware that this breaks Browserify and ESBuild?

Even if sources are available for the project files being bundled they will not be available for the packages in the bundle. So users cannot debug package code.

kdy1 commented 3 years ago

Yes. I'm aware of it. Why do they not use sources? I think they should handle sources.

djalbat commented 3 years ago

Because, as I point out above, the source files referenced in sources are not necessarily available, even for project files, and almost certainly not available for package files. Both presuppose that the development server is able to serve them and in practice this is almost never the case.

kdy1 commented 3 years ago

So they does not handle even if it's possible to do so? What you said can be correct for browsers, but it's not correct for bundlers.

kdy1 commented 3 years ago

Actually I removed sourcesContent because I got a request from webpack developer. Webpack handles it correctly, and there's nothing blocking browserify or esbuild from handling sources, like webpack.

djalbat commented 3 years ago

If you only set the sources property rather than provide the source file by way of the sourcesContent property, the browser has no choice but to request the source file from the development server, unless the source file is contained in the bundle itself. This, as I understand it, is never the case for any bundler. The Webpack bundler typically runs in tandem with its own development server, in fact it is difficult to differentiate the two and most developers don't even appreciate the difference. But other bundlers work standalone, so to speak, and therefore to presuppose that a browser debugging a bundle that they have created has access to the source files by way of a development server is a little mistaken, shall we say.

kdy1 commented 3 years ago

I agree that swc should support configuring it, but it's for users who directly uses it.

djalbat commented 3 years ago

You write:

I agree that swc should support configuring it...

Does that mean you would consider putting it back? If so, I would be very grateful.

You then write:

but it's for users who directly uses it.

Forgive me but I am not quite sure what you mean here. If you mean that users will need to explicitly instruct SWC to include the sourcesContent property then I have absolutely no problem with that.

With this in mind, currently I pass an options object to SWC with the following properties:

{
  fileName,
  sourceMaps
}

I could pass in something like this instead:

{
  fileName,
  sourceMaps,
  includeSourcesContent
}

Is this along the lines of what you are suggesting?

kdy1 commented 3 years ago

Yes, and I expect the name of option to be inlineSourceContents.

djalbat commented 3 years ago

Okay, great. Thank you very much and thank you for all of your hard work on SWC.

By the way, it is easy for me to fix this problem for anyone using SWC with my tool. See here:

https://github.com/djalbat/watchful-cli/blob/master/bin/utilities/transpile.js#L91-L127

I call your transformFile() API function and get an object with code and map properties back. So I could simply open the file myself, call transform() instead of transformFile() and add the source content to the map myself. But this would only fix it for my users, not everyone else.

I had to manually adjust the source map by the way to get the sources property to work will different platforms.

djalbat commented 3 years ago

Your option should probably be inlineSourcesContents to mirror sourcesContent.

swc-bot commented 2 years ago

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.