X Tutup
Skip to content

Feature/emit host#647

Merged
Perryvw merged 5 commits intomasterfrom
feature/emit-host
Jul 3, 2019
Merged

Feature/emit host#647
Perryvw merged 5 commits intomasterfrom
feature/emit-host

Conversation

@Perryvw
Copy link
Member

@Perryvw Perryvw commented Jun 29, 2019

No description provided.

@Perryvw Perryvw requested a review from ark120202 June 29, 2019 20:14
@ark120202
Copy link
Contributor

I think it would be better to make EmitHost a subset of system, like all other hosts in TS are, so default for that would be just ts.sys and we won't have a direct dependency on fs there.

interface EmitHost {
    readFile(path: string): string | undefined;
    writeFile: ts.WriteFileCallback;
}

The signature of readFile is a bit different and default encoding is utf8, so it might need some changes on usage.

Also, writeFile doesn't seem to be used there.

@Perryvw
Copy link
Member Author

Perryvw commented Jun 30, 2019

I think it would be better to make EmitHost a subset of system, like all other hosts in TS are, so default for that would be just ts.sys and we won't have a direct dependency on fs there.

interface EmitHost {
    readFile(path: string): string | undefined;
    writeFile: ts.WriteFileCallback;
}

The signature of readFile is a bit different and default encoding is utf8, so it might need some changes on usage.

Also, writeFile doesn't seem to be used there.

@ark120202 good call, I changed that. Any idea how to further organize this? I'm not really happy with the multiple definitions of the same default emit host.

@ark120202
Copy link
Contributor

@Perryvw if host it a subset of ts.System, we can just use default system as a default host (= ts.sys).

src/index.ts Outdated
const emitHost = { readFile: ts.sys.readFile };
const { transpiledFiles, diagnostics: transpileDiagnostics } = transpile({ program });
const emitResult = emitTranspiledFiles(program.getCompilerOptions(), transpiledFiles);
const emitResult = emitTranspiledFiles(program.getCompilerOptions(), transpiledFiles, emitHost);
Copy link
Contributor

Choose a reason for hiding this comment

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

Since emitTranspiledFiles has a default host it shouldn't be required there

src/Transpile.ts Outdated
}

export interface EmitHost {
readFile: (path: string, encoding?: string | undefined) => string | undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

If we never specify encoding we can just drop this argument to simplify custom implementations (ts does that with few hosts). Also, it could be a bit more consistent with method syntax:

Suggested change
readFile: (path: string, encoding?: string | undefined) => string | undefined;
readFile(path: string): string | undefined;

@Perryvw Perryvw marked this pull request as ready for review July 2, 2019 20:03
@Perryvw Perryvw merged commit 548fda9 into master Jul 3, 2019
@Perryvw Perryvw deleted the feature/emit-host branch July 3, 2019 19:31
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.

2 participants

X Tutup