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 system argument to readConfigFile #4497

Merged
merged 3 commits into from
Sep 5, 2015

Conversation

weswigham
Copy link
Member

Which allows the caller to specify the System used to read the file.

Which allows the caller to specify the `System` used to read the file.
@@ -374,10 +374,10 @@ namespace ts {
* Read tsconfig.json file
* @param fileName The path to the config file
*/
export function readConfigFile(fileName: string): { config?: any; error?: Diagnostic } {
export function readConfigFile(fileName: string, system: System = sys): { config?: any; error?: Diagnostic } {
Copy link
Member

Choose a reason for hiding this comment

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

Given that it's only used once in the compiler, I'd make this non-optional.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree completely (and have followed up by doing so). But we should acknowledge this is a breaking change to a public API. (exported in the ts namespace without a /* @internal */ annotation)

Copy link
Contributor

Choose a reason for hiding this comment

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

Keep it optional so this is not a breaking change.

@weswigham weswigham changed the title Add optional argument to readConfigFile Add system argument to readConfigFile Aug 27, 2015
@@ -374,10 +374,10 @@ namespace ts {
* Read tsconfig.json file
* @param fileName The path to the config file
*/
export function readConfigFile(fileName: string): { config?: any; error?: Diagnostic } {
export function readConfigFile(fileName: string, system: System): { config?: any; error?: Diagnostic } {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would use readFile: (path: string) => string instead of full-blown sys as an optional argument. For consumers that does not have sys it will be simpler then supplying implementation of System where everything but readFile throws Error("Unsupported") or something like that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fair. It is really all it cares about.

@mhegazy
Copy link
Contributor

mhegazy commented Aug 28, 2015

why is this needed?

@vladima
Copy link
Contributor

vladima commented Aug 28, 2015

I'd say this is a cleanup work that will our API more transparent and easy to use on environments where sys is not defined.

@weswigham
Copy link
Member Author

Less needed, more for consistency. Up until 8 days ago the language service server called ts.readConfigFile and wasn't even aware that it called into sys (meaning if you actually wanted to use your host you had to override sys, too!). If ts.sys is an implementation detail of the default host, then we should clearly mark when public functions use it - or remove public functions' dependencies on it. @vladima has an open PR which removes the remaining sys dependencies in commandLineParser.ts.

@mhegazy
Copy link
Contributor

mhegazy commented Aug 28, 2015

thanks for the explanation. 👍

DanielRosenwasser added a commit that referenced this pull request Sep 5, 2015
Add system argument to readConfigFile
@DanielRosenwasser DanielRosenwasser merged commit 4a85546 into microsoft:master Sep 5, 2015
@vladima
Copy link
Contributor

vladima commented Sep 5, 2015

Why it was merged? Currently it is a breaking change because new argument is non optional?

@weswigham
Copy link
Member Author

You're right, and nobody picked up on it because continuing commenting on outdated diffs is odd. >.>

Would we like to fix it?

@vladima
Copy link
Contributor

vladima commented Sep 5, 2015

I would say yes, there is no compelling reason for this to be a breaking change

jbrantly added a commit to TypeStrong/ts-loader that referenced this pull request Sep 8, 2015
@weswigham weswigham deleted the patch-4 branch August 17, 2017 23:02
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants