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

Add support for loading tsconfig.json #2089

Merged
merged 3 commits into from
Apr 29, 2019
Merged

Add support for loading tsconfig.json #2089

merged 3 commits into from
Apr 29, 2019

Conversation

kitsonk
Copy link
Contributor

@kitsonk kitsonk commented Apr 10, 2019

Resolves #51

This PR supports the command line option -c/--config and a tsconfig.json file to be passed which will then be used by the compiler.

I need to do a couple things, plus any feedback on the PR:

  • finish tests
  • detect "checkjs": true in a configuration and send JS files to the compiler to re-enable the support of CheckJS for Deno.
  • when caching, add the configuration to the fingerprint so that using a different config file settings will invalidate the cache.

js/compiler.ts Outdated Show resolved Hide resolved
@ry
Copy link
Member

ry commented Apr 11, 2019

Cool!

I’m looking at the failure on appveyor and don’t understand why expect != actual

tests/config.test ... FAILED
2619Expected output does not match actual.
2620Expected output:
2621Unsupported compiler options in "[WILDCARD]tests/config.tsconfig.json"
2622 The following options were ignored:
2623 module, target
2624Compiling file://[WILDCARD]tests/config.ts
2625[WILDCARD]tests/config.ts:3:5 - error TS2532: Object is possibly 'undefined'.
2626
26273 if (map.get("bar").foo) {
2628 ~~~~~~~~~~~~~~
2629
2630
2631Actual output:
2632Unsupported compiler options in "\?\C:\deno\tests\config.tsconfig.json"
2633 The following options were ignored:
2634 module, target
2635Compiling file:///C:/deno/tests/config.ts
2636C:/deno/tests/config.ts:3:5 - error TS2532: Object is possibly 'undefined'.
2637
26383 if (map.get("bar").foo) {
2639 ~~~~~~~~~~~~~~
2640
2641
2642

@zekth
Copy link
Contributor

zekth commented Apr 11, 2019

@ry I think the handling of wildcard is not the same in Linux/Windows. Maybe we have to do a workaround for those environment as it's due to tsc behavior and not deno. Or for the moment just only check the exit code (i know it's not perfect :/ )

@hayd
Copy link
Contributor

hayd commented Apr 12, 2019

+     actual_out = actual_out.replace(os.path.sep, '/')

above or before here, should fix, but might be overkill...

@zekth
Copy link
Contributor

zekth commented Apr 12, 2019

+     actual_out = actual_out.replace(os.path.sep, '/')

above or before here, should fix, but might be overkill...

it will be more complex than that look at [WILDCARD] part

@kitsonk
Copy link
Contributor Author

kitsonk commented Apr 14, 2019

Yeah, I caught the appveyor as well. I am changing a couple things in the PR today and updating and fixing the appveyor failure as well.

I think the CheckJS should be another PR after this lands as it would require a lot of infrastructure. Also, I am going to load the configuration differently, in order to facilitate both CheckJS but also the cache invalidation, but that could be a subsequent PR as well.

@kitsonk
Copy link
Contributor Author

kitsonk commented Apr 17, 2019

Sorry it is taking so long, I am travelling with family and don't have as much time as I would expect.

I have moved the loading of the config directly into the thread safe state, which should make it easier to be able to add the config to the hash and detecting if CheckJS is enabled.

cli/compiler.rs Show resolved Hide resolved
js/compiler.ts Show resolved Hide resolved
js/compiler.ts Show resolved Hide resolved
cli/state.rs Outdated Show resolved Hide resolved
js/compiler.ts Show resolved Hide resolved
@kitsonk
Copy link
Contributor Author

kitsonk commented Apr 25, 2019

Sorry, still travelling, but I should get some time over the next couple days to finish this off.

@kitsonk
Copy link
Contributor Author

kitsonk commented Apr 26, 2019

Testing the state changes in isolation is really challenging, because I am not sure of the easiest way to "stub" reading of the file. I haven't added a test for that yet.

I still want to do the cache invalidation as part of this PR, which I should be able to address in the next 24 hours.

@zekth
Copy link
Contributor

zekth commented Apr 26, 2019

Testing the state changes in isolation is really challenging, because I am not sure of the easiest way to "stub" reading of the file. I haven't added a test for that yet.

I still want to do the cache invalidation as part of this PR, which I should be able to address in the next 24 hours.

What about generating a temporary file to be read by the test?

@kitsonk
Copy link
Contributor Author

kitsonk commented Apr 26, 2019

What about generating a temporary file to be read by the test?

Can you point me to any examples of something like that in Rust?

@zekth
Copy link
Contributor

zekth commented Apr 26, 2019

What about generating a temporary file to be read by the test?

Can you point me to any examples of something like that in Rust?

You can use TempirDir: https://docs.rs/tempdir/0.3.7/tempdir/
And pass its path to DenoDir as a customroot ? But as mentionned creates a directory on the file system that is deleted once it goes out of scope so all the test as to be scoped.

Or do the same behaviour by writing your own func in the test.

@kitsonk kitsonk changed the title [WIP] Add support for loading tsconfig.json Add support for loading tsconfig.json Apr 27, 2019
@kitsonk
Copy link
Contributor Author

kitsonk commented Apr 27, 2019

Ok, the cache invalidation is added... This is now ready for a proper review @ry.

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! A few comments...

cli/deno_dir.rs Show resolved Hide resolved
cli/deno_dir.rs Show resolved Hide resolved
cli/state.rs Show resolved Hide resolved
tests/config.test Show resolved Hide resolved
js/compiler.ts Outdated Show resolved Hide resolved
.long("config")
.value_name("FILE")
.help("Load compiler configuration file")
.takes_value(true),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just feed for thought here: If we ever find a need to introduce deno specific config, we'll have trouble with appropriate flag name, how about --ts-config for TS compiler configuration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personal opinion, if we ever need a custom config file for Deno, we are probably doing it wrong. Even if we allowed setting of flags via a configuration file, I would hope we would expand the syntax of the TypeScript format, where "compilerOptions" would still be provided to the compiler and the rest parsed by Deno. In my opinion, Deno and TypeScript should always be synergistic instead of some sort of "adjunct".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deno and TypeScript should always be synergistic instead of some sort of "adjunct".

Fits the Philosphy. Thumb up.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kitsonk thanks for response, I generally agree with your opinion - now looking at #1739 it makes a lot of sense to make it single --config that other compilers can use.

// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.

// TODO(kitsonk) Replace with `deno_std/colors/mod.ts` when we can load modules
// which end in `.ts`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - Thanks @kitsonk - this is a long time coming : )

@ry ry merged commit 1a0f53a into denoland:master Apr 29, 2019
@kitsonk kitsonk deleted the tsconfig branch June 4, 2019 06:37
@rsp rsp mentioned this pull request Jan 15, 2020
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 this pull request may close these issues.

Custom tsconfig.json
7 participants