Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Replace the Bun globals in the yarn.lock alias script to fix the type check (#79650)

Romeo Van Snickbfa63e2a9284
diff --git a/.github/scripts/fix-yarn-lock-aliases.ts b/.github/scripts/fix-yarn-lock-aliases.ts
index 6e01b0e5334..b7ddc2563f0 100644
--- a/.github/scripts/fix-yarn-lock-aliases.ts
+++ b/.github/scripts/fix-yarn-lock-aliases.ts
@@ -7,49 +7,60 @@
* yarn convention and fails to resolve the dependency.
*/
-const packageJsonPath = `${process.cwd()}/package.json`;
-const lockPath = `${process.cwd()}/yarn.lock`;
-
-const packageJson = await Bun.file(packageJsonPath).json();
-
-const dependencies = Object.entries<string>(
- Object.assign(
- {},
- packageJson.dependencies,
- packageJson.devDependencies,
- packageJson.optionalDependencies,
- ),
-);
-
-let lock = await Bun.file(lockPath).text();
-const renamedKeys: string[] = [];
-
-for (const [alias, specifier] of dependencies) {
- if (!specifier.startsWith("npm:")) {
- continue;
- }
+import { readFile, writeFile } from "node:fs/promises";
- const aliasedPackage = specifier.slice("npm:".length).replace(/@[^@]*$/, "");
+async function main() {
+ const packageJsonPath = `${process.cwd()}/package.json`;
+ const lockPath = `${process.cwd()}/yarn.lock`;
- if (aliasedPackage === alias) {
- continue;
- }
+ const packageJson = JSON.parse(await readFile(packageJsonPath, "utf8"));
+
+ const dependencies = Object.entries<string>(
+ Object.assign(
+ {},
+ packageJson.dependencies,
+ packageJson.devDependencies,
+ packageJson.optionalDependencies,
+ ),
+ );
+
+ let lock = await readFile(lockPath, "utf8");
+ const renamedKeys: string[] = [];
+
+ for (const [alias, specifier] of dependencies) {
+ if (!specifier.startsWith("npm:")) {
+ continue;
+ }
- const bunKey = `"${aliasedPackage}@${specifier}"`;
- const yarnKey = `"${alias}@${specifier}"`;
+ const aliasedPackage = specifier
+ .slice("npm:".length)
+ .replace(/@[^@]*$/, "");
- if (lock.includes(bunKey)) {
- lock = lock.replaceAll(bunKey, yarnKey);
- renamedKeys.push(`${bunKey} -> ${yarnKey}`);
+ if (aliasedPackage === alias) {
+ continue;
+ }
+
+ const bunKey = `"${aliasedPackage}@${specifier}"`;
+ const yarnKey = `"${alias}@${specifier}"`;
+
+ if (lock.includes(bunKey)) {
+ lock = lock.replaceAll(bunKey, yarnKey);
+ renamedKeys.push(`${bunKey} -> ${yarnKey}`);
+ }
+ }
+
+ if (renamedKeys.length > 0) {
+ await writeFile(lockPath, lock);
}
-}
-if (renamedKeys.length > 0) {
- await Bun.write(lockPath, lock);
+ process.stdout.write(
+ renamedKeys.length > 0
+ ? `Renamed alias keys in yarn.lock:\n${renamedKeys.join("\n")}\n`
+ : "No alias keys to rename in yarn.lock\n",
+ );
}
-process.stdout.write(
- renamedKeys.length > 0
- ? `Renamed alias keys in yarn.lock:\n${renamedKeys.join("\n")}\n`
- : "No alias keys to rename in yarn.lock\n",
-);
+main().catch((error) => {
+ process.stderr.write(`Failed to rename alias keys in yarn.lock: ${error}\n`);
+ process.exit(1);
+});