esbuild icon indicating copy to clipboard operation
esbuild copied to clipboard

Add import source in metafile.inputs

Open sanyuan0704 opened this issue 3 years ago • 3 comments

Through the current metafile, we can analyze the module dependency graph, but we do not know how a specific dependency is imported. For example, import React from 'react', then the original import path is react. Of course, there are many submodules imported. Hopefully this information can be included in esbuild's metafile, for example:

interface Metadata {
  inputs: {
    [path: string]: {
      bytes: number
      imports: {
        path: string
        kind: string
        // raw request path
        request: string
      }[]
    }
  }
}

sanyuan0704 avatar May 24 '22 02:05 sanyuan0704

seems same as https://github.com/evanw/esbuild/issues/1694

hardfist avatar May 24 '22 08:05 hardfist

By raw request path it sounds like you're asking for the original (pre-resolve) import path instead of the calculated (post-resolve) import path. Is that correct?

For example, in the following code:

import React1 from 'react'
import React2 from './node_modules/react/index.js'

Right now the metafile contains this:

"index.js": {
  "bytes": 78,
  "imports": [
    {
      "path": "node_modules/react/index.js",
      "kind": "import-statement"
    },
    {
      "path": "node_modules/react/index.js",
      "kind": "import-statement"
    }
  ]
}

Are you asking for something like this?

"index.js": {
  "bytes": 78,
  "imports": [
    {
      "path": "node_modules/react/index.js",
      "kind": "import-statement",
      "request": "react"
    },
    {
      "path": "node_modules/react/index.js",
      "kind": "import-statement",
      "request": "./node_modules/react/index.js"
    }
  ]
}

evanw avatar May 26 '22 19:05 evanw

Yes,that's right.

---Original--- From: "Evan @.> Date: Fri, May 27, 2022 03:30 AM To: @.>; Cc: @.@.>; Subject: Re: [evanw/esbuild] Add import source in metafile.inputs (Issue#2262)

By raw request path it sounds like you're asking for the original (pre-resolve) import path instead of the calculated (post-resolve) import path. Is that correct?

For example, in the following code: import React1 from 'react' import React2 from './node_modules/react/index.js'

Right now the metafile contains this: "index.js": { "bytes": 78, "imports": [ { "path": "node_modules/react/index.js", "kind": "import-statement" }, { "path": "node_modules/react/index.js", "kind": "import-statement" } ] }

Are you asking for something like this? "index.js": { "bytes": 78, "imports": [ { "path": "node_modules/react/index.js", "kind": "import-statement", "request": "react" }, { "path": "node_modules/react/index.js", "kind": "import-statement", "request": "./node_modules/react/index.js" } ] }

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

sanyuan0704 avatar May 26 '22 23:05 sanyuan0704

This has recently been implemented in version 0.16.13. I called it original instead of request but it's otherwise the same.

evanw avatar Jan 14 '23 07:01 evanw