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

Bundled dynamic import specifiers should be based onto import.meta.url #10754

Open
nayeemrmn opened this issue May 24, 2021 · 0 comments
Open
Labels
cli related to cli/ dir suggestion suggestions for new features (yet to be agreed)

Comments

@nayeemrmn
Copy link
Collaborator

When a module containing a relative dynamic import is included in a bundle, currently we don't make any modifications to the specifier. The exact resolution should be preserved by hardcoding the original referrer.

// In a module https://example.com/foo.ts:

await import(specifier);

// when bundled should first and foremost be transformed to:

await import(new URL(specifier, import.meta.url));

// which should then go through our existing `import.meta` hardcoding, making it:

const importMeta = {
  url: "https://example.com/foo.ts",
  main: false,
};
await import(new URL("./foo.ts", importMeta.url).href);

However, trying to use the URL global here is vulnerable and doesn't provide import map resolution.

We should wait for something like import.meta.resolve() before fixing this. Any complications are deferred naturally to our handling of that.

// In a module https://example.com/foo.ts:

await import(specifier);

// when bundled should first and foremost be transformed to:

await import(import.meta.resolve(specifier));

// which should then go through our existing `import.meta` hardcoding, making it:

const importMeta = {
  url: "https://example.com/foo.ts",
  main: false,
  resolve(specifier) {
    // Inlined generic resolution, relative to `importMeta.url`, containing a hardcoded import map.
  }
};
await import(importMeta.resolve(specifier));

Ref #7296, whatwg/html#5572.

cc @guybedford

@kitsonk kitsonk added cli related to cli/ dir suggestion suggestions for new features (yet to be agreed) labels May 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli related to cli/ dir suggestion suggestions for new features (yet to be agreed)
Projects
None yet
Development

No branches or pull requests

2 participants