Thanks to visit codestin.com
Credit goes to github.com

Skip to content

(fix): parse tsconfig extends, trailing commas, and comments#489

Merged
agilgur5 merged 1 commit intojaredpalmer:masterfrom
agilgur5:fix-tsconfig-parse
Mar 10, 2020
Merged

(fix): parse tsconfig extends, trailing commas, and comments#489
agilgur5 merged 1 commit intojaredpalmer:masterfrom
agilgur5:fix-tsconfig-parse

Conversation

@agilgur5
Copy link
Collaborator

@agilgur5 agilgur5 commented Feb 4, 2020

  • use ts.readConfigFile to properly parse a commas and comments from
    tsconfig instead of just trying to readJSON

  • use ts.parseJsonConfigFileContent to properly parse extends and
    get recursive compilerOptions

  • add tests for all of the above use cases

    • add them to build-withTsconfig which changes declarationDir;
      should only work if TSDX properly parses the tsconfig

NOTE: this is only necessary for internal, TSDX-specific parsing of
tsconfig.json. rollup-plugin-typescript2 already handles these options,
but internal options like esModuleInterop etc are also used & parsed
independently of rpts2

Fixes #483 with its own suggestion, eventually getting to facebook/create-react-app#7248 as the solution EDIT: that only solved commas and comments, extends needed more work, see below comments.
Also fixes #484 as it's the same parser that does both. Still need to add tests for this case, thinking of just having all test fixtures extend a base fixture and then override it?

This is built on top of #436 , please merge that first.

@agilgur5 agilgur5 marked this pull request as ready for review February 4, 2020 22:15
@jaredpalmer
Copy link
Owner

Fix conflicts

@agilgur5 agilgur5 force-pushed the fix-tsconfig-parse branch 2 times, most recently from d670c4b to 21860c1 Compare February 27, 2020 03:15
@agilgur5
Copy link
Collaborator Author

Done.

@agilgur5
Copy link
Collaborator Author

agilgur5 commented Mar 10, 2020

Welp, so since I merged #468 , I switched to use that fixture, which actually does something different than the default, i.e. sets declarationDir. So if declarationDir works properly, then it means this works... except it didn't 😕

Turns out ts.readConfigFile will handle commas and comments and such, but not extends... 😕 😕 It just returns the JSON with an extends.

Seems like the same issue encountered in kulshekhar/ts-jest#245 (comment) , the solution to which is non-trivial... welppppp. investigating alternatives right now

@agilgur5 agilgur5 force-pushed the fix-tsconfig-parse branch from eede53d to 7758560 Compare March 10, 2020 22:45
@agilgur5
Copy link
Collaborator Author

Ok, some links I went through to figure this out:

So ended up using that last one

- use ts.readConfigFile to properly parse a commas and comments from
  tsconfig instead of just trying to readJSON
- use ts.parseJsonConfigFileContent to properly parse `extends` and
  get recursive compilerOptions

- add tests for all of the above use cases
  - add them to build-withTsconfig which changes declarationDir;
    should only work if TSDX properly parses the tsconfig

NOTE: this is only necessary for internal, TSDX-specific parsing of
tsconfig.json. rollup-plugin-typescript2 already handles these options,
but internal options like esModuleInterop etc are also used & parsed
independently of rpts2
@agilgur5 agilgur5 force-pushed the fix-tsconfig-parse branch from 7758560 to f2ae526 Compare March 10, 2020 22:59
Copy link
Collaborator Author

@agilgur5 agilgur5 left a comment

Choose a reason for hiding this comment

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

LGTM. I reduced the necessary changes for extends to just a few lines, so there wasn't much to review.

I'm still a bit skeptical of the './' for ts.parseJsonConfigFileContent's third argument, basePath, but this passed all of my manual tests too. I'm most concerned about usage with custom tsconfig path #436 especially since we don't have tests for that. Will have to add some soon.

@agilgur5 agilgur5 merged commit ad33c01 into jaredpalmer:master Mar 10, 2020
paul-vd pushed a commit to EezyQuote/tsdx that referenced this pull request Dec 1, 2020
…lmer#489)

- use ts.readConfigFile to properly parse a commas and comments from
  tsconfig instead of just trying to readJSON
- use ts.parseJsonConfigFileContent to properly parse `extends` and
  get recursive compilerOptions

- add tests for all of the above use cases
  - add them to build-withTsconfig which changes declarationDir;
    should only work if TSDX properly parses the tsconfig

NOTE: this is only necessary for internal, TSDX-specific parsing of
tsconfig.json. rollup-plugin-typescript2 already handles these options,
but internal options like esModuleInterop etc are also used & parsed
independently of rpts2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants