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

Custom tsconfig.json #51

Closed
jednano opened this issue May 31, 2018 · 24 comments · Fixed by #2089
Closed

Custom tsconfig.json #51

jednano opened this issue May 31, 2018 · 24 comments · Fixed by #2089

Comments

@jednano
Copy link

jednano commented May 31, 2018

What happens or should happen if you import a TS file that has different compiler options? Does/will deno look for a separate tsconfig.json somehow?

@qti3e
Copy link
Contributor

qti3e commented May 31, 2018

currently, the ts config is hardcoded in runtime.ts
https://github.com/ry/deno/blob/e3926720118f76e4b1352a75e332026e49154f34/runtime.ts#L183-L191

@ry
Copy link
Member

ry commented May 31, 2018

@jedmao Deno doesn't have that logic yet - it only uses one built in set of tsconfig. Coming soon.

@jednano
Copy link
Author

jednano commented May 31, 2018

Sounds like a roadmap item? Perhaps we can discuss and formalize the requirements in this issue and add it to a milestone?

@jednano jednano changed the title TypeScript compiler options Resolve TypeScript compiler options May 31, 2018
@qti3e qti3e added bug Something isn't working correctly enhancement and removed bug Something isn't working correctly labels Jun 1, 2018
@jednano
Copy link
Author

jednano commented Jun 1, 2018

On the surface, I think these are the problems or scenarios that need to be discussed for this issue:

  1. If you require a file locally (e.g., import foo from './foo';) then it's probably a safe assumption that we don't need to track down a separate configuration; unless, like ESLint, we want to allow people to scatter different tsconfig.json files throughout their folder structure. This could be useful for testing purposes too.
  2. If you require an external file (e.g., import bar from 'http://foo.com/bar.ts';), then this file could be using a separate configuration. The only thing I can imagine working is to look for http://foo.com/tsconfig.json.

Any thoughts on this or better ideas?

@ry
Copy link
Member

ry commented Jun 1, 2018

@jedmao I will deal with it.

@ry ry closed this as completed Jun 1, 2018
@jednano
Copy link
Author

jednano commented Jun 1, 2018

@ry just so you know, I'm willing to help where I can. I'd love to contribute to this project.

@ry
Copy link
Member

ry commented Jun 1, 2018

@ry ry reopened this Jun 1, 2018
@jednano
Copy link
Author

jednano commented Jun 1, 2018

@zheeeng
Copy link

zheeeng commented Jun 4, 2018

Expect on this improvement. I'm wondering how will the module system handle the external code using path alias:

// https://example.com/ext-pkg/tsconfig.json
{
  "compilerOptions": {
    "paths": {
      "~src/*": ["src/*"]
    }
}

// https://example.com/ext-pkg/index.ts
import foo from '~src/util/b'

@jednano
Copy link
Author

jednano commented Jun 4, 2018

@zheeeng if you're publishing a TypeScript library I think you would make sure not to use paths like that.

@zheeeng
Copy link

zheeeng commented Jun 4, 2018

@jedmao For not import module importer(e.g. require.js) in the browser env, developers often use Rollup/Webpack to bundle modules and provide a .d.ts declarations entry. The downstream lib could use the lib as js lib + .d.ts. These two pack tools all support path alias. Plz consider this usage and not force modification on them.

@playerx
Copy link

playerx commented Jun 7, 2018

@zheeeng I was thinking how to write module imports that will support both, node & deno, and thats brilliant idea using tscofnig paths it can be done very easily, in future I already plan to organize code so to support both platforms (until there will be stable version of deno) and I think supporting paths is very important

@jednano
Copy link
Author

jednano commented Jun 7, 2018

The thing that concerns me is that tsconfig.json doesn't work the same as package.json in that you can have a tsconfig.json in a totally different directory and use that one to compile project files, even if a tsconfig.json file exists in their own respective directories. As such, we can't assume that a tsconfig.json file in the same folder as foo.ts is actually the right tsconfig.json file.

@Bnaya
Copy link

Bnaya commented Jun 29, 2018

There's upcoming typescript features (3.0ish) to handle build "nested" typescript projects
microsoft/TypeScript#3469 (comment)
microsoft/TypeScript#21706 (comment)

@jednano
Copy link
Author

jednano commented Jun 29, 2018

@Bnaya I read that first lengthy post and I'm still not seeing anything that allows you to import a TS file and that TS file tells you where to find the tsconfig.json. Remember that you can have two separate tsconfig.json files that build the same TS file. The only solution I can think of is to put some kind of comment at the top of the TS file, but I'm not loving that idea.

@Bnaya
Copy link

Bnaya commented Jul 1, 2018

importing single ts file, without any metadata, is not a good idea imo.
you must have any manifest file, preferably in the package level

@jednano
Copy link
Author

jednano commented Jul 1, 2018

@Bnaya, I agree. That's what I'm trying to figure out here in this thread. Do you have any suggestions that would work? Because currently, it looks like Deno will support single-file imports. I don't think the links you shared solve this problem.

@ry ry added this to the future milestone Aug 7, 2018
@ry ry removed the enhancement label Oct 5, 2018
@kitsonk
Copy link
Contributor

kitsonk commented Oct 29, 2018

I am going to take a look at this now. The compiler has settled down to a point where I think we can start to deal with this.

There are a few approaches that could be taken, and I am not sure which is best:

  • We resolve tsconfig.json. If we do this, it will be a little bit problematic, as we will need not allow certain options to be passed to the compiler, as they would cause issues with how the compiler works. So there is a subset of options we can support and maybe even a smaller subset we want to support, so we can test them and make sure they work as expected.
  • We create some sort of configuration file, which can operate in lieu of command line arguments and allow us to support the subset of TypeScript compiler options more cleanly. We could try to resolve this file by default at startup (e.g. ${cwd}/deno.json). This could be used for more complex configuration of Deno in the future as well.
  • We create individual flags that we pass through to the TypeScript compiler that we would wish to support.

I would want to put the restriction that all modules will be transpiled with the same set of options for that programme. Adjusting it for each one is going to be problematic and confusing to the user.

My feeling at the moment of the only TypeScript compiler options we would want to support are:

Flag Current Setting Notes
--allowJs true Turning this false would mean that any modules that are JavaScript would throw
--checkJs true Turning this false would mean JS would not be type checked and simply "passed through" only transforming the module format if required. Individual modules could opt in via // @ts-check. Currently individual modules can opt out via // @ts-nocheck. This requires --allowJs to be true.
--experimentalDecorators false Not sure if we want to support this. It is common in a lot of code, but the current format TypeScript supports does not align with the current TC39 proposal and will be a breaking change when the proposal eventually reaches ratification.
--locale en-us The locale to display TypeScript diagnostics in. (Maybe not if the rest of Deno is going to be English at the moment.)
--resolveJsonModule true once #1065 is resolved Setting this to false would disallow JSON to be resolved as a module import
--strict false While the TypeScript in Deno adheres to the strict module, currently TypeScript code is evaluated in a more "loose" mode. There are a whole set of flags that relate to individual features of strict, but I would suggest we only support --strict.

So that is 6 options we can realistically support out of about 75 options that can be specified in the tsconfig.json (plus also files, excludes, includes which should have no impact on Deno). So I don't think supporting tsconfig.json would be very useful. Considering it is only 6 flags, and if we take out --locale and maybe --experimentalDecorators then that is only 4 flags we need, which makes adding them a bit more realistic.

Also, since we have a default behaviour of true for everything than --strict of the remaining 4, it might make sense to turn them to negatives, like --disallowJs, --noCheckJs, and --noResolveJsonModule.

@ry thoughts?

@kitsonk
Copy link
Contributor

kitsonk commented Oct 30, 2018

Talking to @ry, we discussed that option 1 listed above is a better approach. Deno will support the tsconfig.json. There are certain compiler options which we cannot support or allow to be modified that have to deal with how code is emitted. When a tsconfig.json provides one of these, we will ignore it, but log out a warning that the option is ignored.

@ry ry changed the title Resolve TypeScript compiler options Custom tsconfig.json Jan 3, 2019
@ry
Copy link
Member

ry commented Jan 3, 2019

Just an update on this issue: We are still heavily refactoring the core compilation infrastructure, so we're putting off adding stuff like that until it solidifies. In particular, we won't attempt address this until #975 is done.

@bartlomieju
Copy link
Member

CC @kitsonk can you give an update on this issue?

@kitsonk
Copy link
Contributor

kitsonk commented Feb 12, 2019

There is still some refactoring churn on the compiler. It is in the queue after that.

@irustm
Copy link

irustm commented Mar 22, 2019

@kitsonk what is the status this issue?

@kitsonk
Copy link
Contributor

kitsonk commented Mar 23, 2019

It is being worked on.

@ry ry closed this as completed in #2089 Apr 29, 2019
piscisaureus pushed a commit to piscisaureus/deno that referenced this issue Oct 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants