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

Should emitFile take an importer? #3436

Closed
jakearchibald opened this issue Mar 11, 2020 · 8 comments · Fixed by #3442
Closed

Should emitFile take an importer? #3436

jakearchibald opened this issue Mar 11, 2020 · 8 comments · Fixed by #3442

Comments

@jakearchibald
Copy link
Contributor

jakearchibald commented Mar 11, 2020

Feature Use Case

Take plugin code like this:

const prefix = 'typescript:';
{
  async resolveId(id, importer) {
    if (!id.startsWith(prefix)) return null;

    const realId = id.slice(prefix.length);
    const resolveResult = await this.resolve(realId, importer);
    if (!resolveResult) {
      throw Error(`Cannot resolve ${realId}`);
    }
    return prefix + resolveResult.id;
  },
}

Which converts typescript:./whatever.ts to typescript:/full/path/to/whatever.ts, based on the importer.

However, another plugin cannot invoke this via emitFile:

this.emitFile({
  type: 'chunk',
  id: 'typescript:./whatever.ts',
});

The other plugin would have to understand the typescript: prefix, and handle resolving itself.

Feature Proposal

this.emitFile({
  type: 'chunk',
  id: 'typescript:./whatever.ts',
  importer: '…',
});

The value of importer would be passed to resolveId.

@jakearchibald jakearchibald changed the title Should emitFile take an importer Should emitFile take an importer? Mar 11, 2020
@lukastaegert
Copy link
Member

However, another plugin cannot invoke this via emitFile

I do not believe this is true. An id from emitFile should run through the whole chain of resolveId, load and transform. Not happy to implement a new mechanism on top of the existing one.

@jakearchibald
Copy link
Contributor Author

An id from emitFile should run through the whole chain of resolveId

Right, but what will importer be?

@lukastaegert

This comment has been minimized.

@lukastaegert

This comment has been minimized.

@lukastaegert
Copy link
Member

Ah, sorry, I totally misunderstood what you meant. You mean the second argument of resolveId. I thought you meant something like a loader.

@lukastaegert
Copy link
Member

Yes, being able to configure the importer would make sense when emitting a file.

@jakearchibald
Copy link
Contributor Author

Yep! Sorry for explaining it badly.

@lukastaegert
Copy link
Member

Please have a look if #3442 would work for you.

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

Successfully merging a pull request may close this issue.

2 participants