Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Resolve basePath parameter to prevent errors when loading compiler options #470

Merged
merged 1 commit into from
Oct 1, 2021

Conversation

holmesal
Copy link
Contributor

This PR resolves the relative basePath parameter passed to ts.parseJsonConfigFileContent().

Background

Despite setting the correct target and module versions in tsconfig.json, the replaceRequire option was never being set.

As it turned out, loadCompilerOptions was failing to parse our tsconfig.json correctly - the following error was causing it to return an empty object (despite the parsed config having a valid options property):

{
    file: undefined,
    start: undefined,
    length: undefined,
    messageText: `No inputs were found in config file 'tsconfig.json'. Specified 'include' paths were '["**/*"]' and 'exclude' paths were '["dist"]'.`,
    category: 1,
    code: 18003,
    reportsUnnecessary: undefined,
    reportsDeprecated: undefined
  }

We don't explicitly specify the files or include keys in tsconfig.json, which produces the default behavior of including all files in the current directory and subdirectory. Of course, we don't see the above error in any other circumstance - only relay-compiler-typescript's loadCompilerOptions method.

Passing the relative path string'./' (existing behavior) produces an empty files array. This is because the relative path gets passed all the way through to TS's getNormalizedAbsolutePath(), which seems to expect an absolute path itself. When given a relative path, it produces a path string which causes no files to be resolved.

Resolution

Resolving the path using ts.sys.resolvePath('./') results in our files array being populated correctly, the above error not being (silently) emitted, and things downstream working properly (module numbers being loaded from config, and replaceRequire being set accordingly).

Copy link
Member

@saihaj saihaj left a comment

Choose a reason for hiding this comment

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

LGTM! will wait for one more ✅ then we can merge this.

@n1ru4l n1ru4l added the Version: Patch Increment the patch version when merged label Oct 1, 2021
@n1ru4l n1ru4l merged commit c851766 into relay-tools:master Oct 1, 2021
@github-actions
Copy link

github-actions bot commented Oct 1, 2021

🚀 PR was released in v14.1.3 🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
released Version: Patch Increment the patch version when merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants