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

Question: What is the point of the typescript option? #252

Closed
brandon-leapyear opened this issue Nov 18, 2020 · 5 comments
Closed

Question: What is the point of the typescript option? #252

brandon-leapyear opened this issue Nov 18, 2020 · 5 comments
Labels
kind: question This is a usage or similar question scope: docs Documentation could be improved. Or changes that only affect docs

Comments

@brandon-leapyear
Copy link
Contributor

This says that if the option isn't set, the plugin will automatically set it to require('typescript').

if (!pluginOptions.typescript) {
pluginOptions.typescript = require("typescript");
}

I'm wondering why you would ever want to manually set the typescript option to require('typescript') then. Wouldn't calling require('typescript') in rollup.config.js always give the same answer as require('typescript') in the plugin?

@ezolenko
Copy link
Owner

You might want to use multiple versions of typescript for example, or have it in a non-standard place.

@brandon-leapyear
Copy link
Contributor Author

brandon-leapyear commented Jan 20, 2021

This is an old work account. Please reference @brandonchinn178 for all future communication


I see. But the docs say

When typescript version installed by the plugin (latest 2.x) is unacceptable, you can import your own typescript module and pass it in as typescript: require("typescript"). Must be 2.0+, things might break if transpiler interfaces changed enough from what the plugin was built against.

You would never literally do typescript: require("typescript"), you'd do typescript: require("path/to/other/typescript"), right? I'm mostly asking about a docs change, here

@ezolenko
Copy link
Owner

Yeah, typescript: require("typescript") is redundant -- the plugin will do that on its own if you don't provide typescript option. I'll change the doc.

ezolenko added a commit that referenced this issue Jan 20, 2021
@agilgur5 agilgur5 added kind: question This is a usage or similar question scope: docs Documentation could be improved. Or changes that only affect docs labels Apr 24, 2022
@agilgur5 agilgur5 changed the title Question: What is the point of the 'typescript' option? Question: What is the point of the typescript option? Apr 24, 2022
@agilgur5
Copy link
Collaborator

agilgur5 commented Apr 24, 2022

Worth noting, require('typescript') from within rpt2 (vs. from within your rollup.config.js) actually could resolve to something different depending on how your node_modules ends up being laid out.

For example, if it somehow ended up like this:

my-project
│   README.md
│   rollup.config.js
└───node_modules
│   └───typescript
│   └───rollup-plugin-typescript2
|       └───node_modules
|           └───typescript

You'd have two different TS versions depending on where require('typescript') was called.

Realistically, that shouldn't really happen unless node_modules is an erroneous state (e.g. need to run npm dedupe etc) since rpt2 sets TS as a peerDep, but it is something to be aware of in the Node ecosystem.

EDIT: actually that seems to have been the original purpose of the tsconfig option, as implemented in #27.
I believe NPM placed things differently in node_modules back then, so this scenario was more common then. Also this package had TS listed as both a peerDep and a dep back then instead of as a peer and devDep.

@agilgur5
Copy link
Collaborator

You can also use this for alternative TS implementations, such as ttypescript, for instance for the purpose of #201 or something else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: question This is a usage or similar question scope: docs Documentation could be improved. Or changes that only affect docs
Projects
None yet
Development

No branches or pull requests

3 participants