Skip to content

Commit

Permalink
refactor: always patch
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpza committed Aug 19, 2024
1 parent 7567567 commit ed3ed1f
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions test/prepare.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-check
import { existsSync } from "node:fs";
import { symlink } from "node:fs/promises";
import { dirname, join, resolve } from "node:path";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { patch } from "ts-patch";
import { patch as patch1 } from "tsp1";
Expand All @@ -20,27 +20,17 @@ async function symlinkTsNode() {
}

function patchTsModules() {
/* ****************************************************************************************************************** *
* Config
* ****************************************************************************************************************** */
const rootDir = __dirname;
const tsDirs = ["typescript-three", "typescript-four-seven", "typescript"];
/* ****************************************************************************************************************** *
* Patch TS Modules
* ****************************************************************************************************************** */

const baseDirs = new Map();

for (const tsDirName of tsDirs) {
const mainDir = resolve(rootDir, "node_modules", tsDirName);
if (!existsSync(join(mainDir, "lib-backup"))) baseDirs.set(tsDirName, mainDir);
/** @param {string} moduleName */
function patchTypescript(moduleName, tspatch) {
const basedir = resolve(rootDir, "node_modules", moduleName);
tspatch(["tsc.js", "typescript.js"], { basedir, dir: basedir });
}

// Patch discovered modules
for (const [dirName, dir] of baseDirs)
if (dirName === "typescript-three") patch1(["tsc.js", "typescript.js"], { basedir: dir });
else if (dirName === "typescript-four-seven") patch2(["tsc.js", "typescript.js"], { dir });
else patch(["tsc.js", "typescript.js"], { dir });
patchTypescript("typescript-three", patch1);
patchTypescript("typescript-four-seven", patch2);
patchTypescript("typescript", patch);
}

patchTsModules();
Expand Down

0 comments on commit ed3ed1f

Please sign in to comment.