Skip to content

Commit

Permalink
Fix RC installation (#678)
Browse files Browse the repository at this point in the history
* Fix RC installation

Fixes #677
See that bug for discussion; it's somewhat complicated, but the fix is:
during RC you have to install the RC as well, just in case.

* add explanatory comment (that is good)
  • Loading branch information
sandersn committed May 19, 2023
1 parent 8eb317e commit 9415899
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions packages/utils/src/typescript-installer.ts
Expand Up @@ -14,22 +14,33 @@ export async function installAllTypeScriptVersions() {
for (const v of TypeScriptVersion.shipped) {
await install(v);
}
// `shipped + [rc, next] == supported` during the RC period. During that time, typescript@rc needs to be installed too.
if (TypeScriptVersion.shipped.length + 2 === TypeScriptVersion.supported.length) {
await install("rc");
}
await installTypeScriptNext();
}

export async function installTypeScriptNext() {
await install("next");
}

async function install(version: TsVersion | "next"): Promise<void> {
async function install(version: TsVersion | "next" | "rc"): Promise<void> {
if (version === "local") {
return;
}
const dir = installDir(version);
if (!(await fs.pathExists(dir))) {
console.log(`Installing to ${dir}...`);
await fs.mkdirp(dir);
await fs.writeJson(path.join(dir, "package.json"), packageJson(version));
await fs.writeJson(path.join(dir, "package.json"), {
description: `Installs typescript@${version}`,
repository: "N/A",
license: "MIT",
dependencies: {
typescript: version,
},
});
await execAndThrowErrors("npm install --ignore-scripts --no-shrinkwrap --no-package-lock --no-bin-links", dir);
console.log("Installed!");
console.log("");
Expand All @@ -47,9 +58,10 @@ export function typeScriptPath(version: TsVersion, tsLocal: string | undefined):
return path.join(installDir(version), "node_modules", "typescript");
}

function installDir(version: TsVersion | "next"): string {
function installDir(version: TsVersion | "next" | "rc"): string {
assert(version !== "local");
if (version === "next") version = TypeScriptVersion.latest;
if (version === "rc") version = TypeScriptVersion.supported[TypeScriptVersion.supported.length - 2];
return path.join(installsDir, version);
}

Expand All @@ -74,14 +86,3 @@ async function execAndThrowErrors(cmd: string, cwd?: string): Promise<void> {
});
});
}

function packageJson(version: TsVersion | "next"): {} {
return {
description: `Installs typescript@${version}`,
repository: "N/A",
license: "MIT",
dependencies: {
typescript: version,
},
};
}

0 comments on commit 9415899

Please sign in to comment.