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

Graph does not support multiple imports of the same specifier #80

Open
kitsonk opened this issue Dec 14, 2021 · 2 comments
Open

Graph does not support multiple imports of the same specifier #80

kitsonk opened this issue Dec 14, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@kitsonk
Copy link
Contributor

kitsonk commented Dec 14, 2021

When doing something like this:

import a from "./a.js";
import * as b from "./a.js";
const c = await import("./a.js");

The dependencies for the module only include one import site. They should actually be two seperate dependency objects, as they "may" differ in ways (like import assertions or type definitions).

That being said, it still works and adding support for it would make everything related to it fairly complex, as knowing the import location would become essential for accessing information (unless we stored a vec of locations, and associated information, like it being a dynamic import and any import assertions).

@kitsonk kitsonk added the enhancement New feature or request label Jan 10, 2022
@devingfx
Copy link

Yes I had got the issue with https://esm.sh 's redirect packages:

/* esm.sh - [email protected] */
export * from "https://esm.sh/v117/[email protected]/deno/index.mjs"
export { default } from "https://esm.sh/v117/[email protected]/deno/index.mjs"

With a simple custom naive replacer, you are not able to know the existence of other instance in text, so url replacement fail here:

(pseudo code)

graph.modules.map( m=> {
    m.content = load file in cache folder
    for( const dep of m.dependencies )
        replaceBetweenStartEnd( m.content, dep.code.span, makeLocalhost(dep.specfier) )
})

Produces

/* esm.sh - [email protected] */
export * from "http://localhost:8117/cache/deps/https/..."   << only this one is replaced
export { default } from "https://esm.sh/v117/[email protected]/deno/index.mjs"

@dsherret
Copy link
Member

This also matters for doing stuff like:

async function main() {
  const mod1 = require("./a.js");
  const mod2 = await import("./a.js");
}

Or:

import type something from "some-package" with { "resolution-mode": "import" };
import type something from "some-package" with { "resolution-mode": "require" };

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

No branches or pull requests

3 participants