Skip to content

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

@nayeemrmn

Description

@nayeemrmn

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    clirelated to cli/ dirsuggestionsuggestions for new features (yet to be agreed)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions