Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions scripts/prepare-variants/addPreReleaseVersionSuffix.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { readFile, writeFile } from "fs/promises";
import { join } from "path";

export const addPreReleaseVersionSuffix = async (workspacePaths, prereleaseTag) => {
for (const workspacePath of workspacePaths) {
const packageJsonPath = join(workspacePath, "package.json");
const packageJsonBuffer = await readFile(packageJsonPath);
const packageJson = JSON.parse(packageJsonBuffer.toString());
const updatedPackageJson = { ...packageJson, version: `${packageJson.version}-${prereleaseTag}` };
await writeFile(packageJsonPath, JSON.stringify(updatedPackageJson, null, 2).concat(`\n`));
}
};
11 changes: 10 additions & 1 deletion scripts/prepare-variants/default.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@
import { getDepToCurrentVersionHash } from "../update-versions/getDepToCurrentVersionHash.mjs";
import { updateVersions } from "../update-versions/updateVersions.mjs";
import { getWorkspacePaths } from "../utils/getWorkspacePaths.mjs";
import { addPreReleaseVersionSuffix } from "./addPreReleaseVersionSuffix.mjs";
import { renameOrgInSrc } from "./renameOrgInSrc.mjs";
import { replaceMarkdown } from "./replaceMarkdown.mjs";
import { updateEsVersionInBrowserConfig } from "./updateEsVersionInBrowserConfig.mjs";

const esVersion = process.argv[2];

const workspacePaths = getWorkspacePaths();
await replaceMarkdown(workspacePaths);

if (esVersion) {
await addPreReleaseVersionSuffix(workspacePaths, esVersion);
await updateEsVersionInBrowserConfig(workspacePaths, esVersion);
}

updateVersions(getDepToCurrentVersionHash());

await replaceMarkdown(workspacePaths);
renameOrgInSrc(workspacePaths, "@trivikr-test");
55 changes: 55 additions & 0 deletions scripts/prepare-variants/updateEsVersionInBrowserConfig.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { readFile, writeFile } from "fs/promises";
import { dirname, join } from "path";
import { fileURLToPath } from "url";

const __dirname = dirname(fileURLToPath(import.meta.url));
const rootDir = join(__dirname, "..", "..");

export const updateEsVersionInBrowserConfig = async (workspacePaths, esVersion) => {
const tsconfigPath = join(rootDir, "tsconfig.es.json");

// Update ES Version in root TSConfig
const tsConfigBuffer = await readFile(tsconfigPath);
const tsConfig = JSON.parse(tsConfigBuffer.toString());
const updatedTsConfig = {
...tsConfig,
compilerOptions: {
...tsConfig.compilerOptions,
target: esVersion,
},
};
await writeFile(tsconfigPath, JSON.stringify(updatedTsConfig, null, 2).concat(`\n`));

// Remove lib from package TSConfig
for (const workspacePath of workspacePaths) {
const tsconfigPath = join(workspacePath, "tsconfig.es.json");
const tsConfigBuffer = await readFile(tsconfigPath);
const tsConfig = JSON.parse(tsConfigBuffer.toString());
const { compilerOptions } = tsConfig;
const updatedTsConfig = {
...tsConfig,
compilerOptions: {
...compilerOptions,
...(compilerOptions.lib && { lib: getUpdatedLib(compilerOptions.lib, esVersion) }),
},
};
await writeFile(tsconfigPath, JSON.stringify(updatedTsConfig, null, 2).concat(`\n`));
}
};

/**
* Remove libs equal or prior to the target ES version
*/
const getUpdatedLib = (lib, esVersion) =>
lib.filter((libEntry) => {
if (libEntry === "es5") {
return false;
}
if (!libEntry.toLowerCase().startsWith("es20")) {
return true;
}
const libVersion = libEntry.split(".")[0];
return getEsYear(libVersion) > getEsYear(esVersion);
});

const getEsYear = (esVersion) => Number(esVersion.substring(2));