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

Commit

Permalink
Ensure TypeScript is installed before starting
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbranch committed May 6, 2020
1 parent d5a73ab commit b418574
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,21 @@ async function main(): Promise<void> {
}

if (shouldListen) {
listen(dirPath, tsLocal);
// Do this *after* to ensure messages sent during installation aren't dropped.
if (!tsLocal) {
await installAllTypeScriptVersions();
}
listen(dirPath, tsLocal, onlyTestTsNext);
} else {
if (!tsLocal) {
if (onlyTestTsNext) {
await installTypeScriptNext();
} else {
await installAllTypeScriptVersions();
}
}
await installTypeScriptAsNeeded(tsLocal, onlyTestTsNext);
await runTests(dirPath, onlyTestTsNext, expectOnly, tsLocal);
}
}

async function installTypeScriptAsNeeded(tsLocal: string | undefined, onlyTestTsNext: boolean): Promise<void> {
if (tsLocal) return;
if (onlyTestTsNext) {
return installTypeScriptNext();
}
return installAllTypeScriptVersions();
}

function usage(): void {
console.error("Usage: dtslint [--version] [--installAll] [--onlyTestTsNext] [--expectOnly] [--localTs path]");
console.error("Args:");
Expand All @@ -101,9 +99,13 @@ function usage(): void {
console.error("onlyTestTsNext and localTs are (1) mutually exclusive and (2) test a single version of TS");
}

function listen(dirPath: string, tsLocal: string | undefined): void {
process.on("message", (message: {}) => {
function listen(dirPath: string, tsLocal: string | undefined, onlyTestTsNext: boolean): void {
// Don't await this here to ensure that messages sent during installation aren't dropped.
const installationPromise = installTypeScriptAsNeeded(tsLocal, onlyTestTsNext);
process.on("message", async (message: {}) => {
const { path, onlyTestTsNext, expectOnly } = message as { path: string, onlyTestTsNext: boolean, expectOnly?: boolean };

await installationPromise;
runTests(joinPaths(dirPath, path), onlyTestTsNext, !!expectOnly, tsLocal)
.catch(e => e.stack)
.then(maybeError => {
Expand Down

0 comments on commit b418574

Please sign in to comment.