Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DX request: change the filename comment (// a.js/*** a.js ***/) #2751

Closed
iamakulov opened this issue Dec 15, 2022 · 3 comments
Closed
Labels

Comments

@iamakulov
Copy link

Background

Today, when you generate a bundle with esbuild (with minification disabled), esbuild helpfully generates comments showing which modules are included in the bundle:

$ echo 'export const a = 5' > a.js
$ echo 'import { a } from "./a.js"; console.log(a)' > b.js
$ esbuild --bundle b.js
(() => {
  // a.js
  var a = 5;

  // b.js
  console.log(a);
})();

(Note the // a.js and // b.js comments above.)

Request

I have a minor DX request: could esbuild change these comments to make it easier to ⌘F them? E.g., something like this would make it easy to find all module boundaries (and only them) by searching for /***:

/*** a.js ***/
var a = 5;

/*** b.js ***/
console.log(a);

The /*** characters are inspired by webpack. E.g., here’s how a webpack bundle I’m looking at right now wraps each module:

    /***/
    "./node_modules/react-virtuoso/dist/index.m.js": /***/
    (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

        "use strict";

        // (module code)

        /***/
    }
    ),

However, I’m open to any other combination of symbols that will be uncommon in the bundle.

Why I’m requesting this

As a performance engineer, I often have to work with raw JS bundles. A typical bundle I’m working with will have 100K+ lines and dozens of modules.

When I’m debugging something, and the debugger takes me to line 17658 of the bundle, it’s very useful to figure out which module this is. With webpack, this is quick – I can just search for /*** and press “Enter” a few times. With esbuild, this is very hard – if I searched for //, I’d have hundreds of matches with every comment in the bundle.

I hope a special shape of the comment will make this easier.

@evanw
Copy link
Owner

evanw commented Dec 15, 2022

Unfortunately people are now relying on the current comment syntax, so this would be a breaking change.

With esbuild, this is very hard – if I searched for //, I’d have hundreds of matches with every comment in the bundle.

Most comments shouldn't be present though, right? Since esbuild doesn't preserve comments by default. I was just curious what comments you're hitting.

@evanw evanw added the breaking label Dec 15, 2022
@iamakulov
Copy link
Author

Most comments shouldn't be present though, right? Since esbuild doesn't preserve comments by default. I was just curious what comments you're hitting.

Wait, I must be a dummy :) When I was writing the issue, I remembered esbuild uses // for module comments, and remembered I avoided using ⌘F being afraid of too many false positives. But I’m just now realizing I never actually tried ⌘F-ing for //.

Switching it to /*** would still lower the cognitive load a bit, but it’s pretty subjective and probably not worth the effort given the breakage. I’ll close this, thank you!

@iamakulov iamakulov closed this as not planned Won't fix, can't repro, duplicate, stale Dec 15, 2022
@unphased
Copy link

unphased commented Apr 21, 2024

I'm doing some (questionable) surgery on bundle outputs as part of my build. And the reminder that comments should be stripped in bundles was helpful to me. Thank you.

I hope that the behavior can be relied upon that all comments in bundles can be treated as headers defining which file the code below it is from.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants