Skip to content

Commit

Permalink
Add script to update Nest dependencies (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyomair authored Dec 2, 2024
1 parent 4126c27 commit fcfd0d8
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/v8/update-nest-dependencies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { existsSync } from "fs";
import { readFile, writeFile } from "fs/promises";

export const stage = "before-install";

function updateDependencyIfExists(dependencies: Record<string, string>, name: string, version: string) {
if (dependencies[name]) {
dependencies[name] = version;
}
}

export default async function updateNestDependencies() {
if (!existsSync("api/package.json")) {
return;
}

const packageJson = JSON.parse(await readFile("api/package.json", "utf-8"));

if (packageJson.dependencies) {
packageJson.dependencies["@apollo/server"] = "^4.0.0";
delete packageJson.dependencies["apollo-server-core"];
delete packageJson.dependencies["apollo-server-express"];

updateDependencyIfExists(packageJson.dependencies, "@nestjs/apollo", "^12.0.0");
updateDependencyIfExists(packageJson.dependencies, "@nestjs/common", "^10.0.0");
updateDependencyIfExists(packageJson.dependencies, "@nestjs/core", "^10.0.0");
updateDependencyIfExists(packageJson.dependencies, "@nestjs/graphql", "^12.0.0");
// TODO remove when https://github.com/vivid-planet/comet/pull/2809 has been merged
updateDependencyIfExists(packageJson.dependencies, "@nestjs/passport", "^10.0.0");
updateDependencyIfExists(packageJson.dependencies, "@nestjs/platform-express", "^10.0.0");

updateDependencyIfExists(packageJson.dependencies, "graphql", "^16.6.0");

updateDependencyIfExists(packageJson.dependencies, "nestjs-console", "^9.0.0");
updateDependencyIfExists(packageJson.dependencies, "@golevelup/nestjs-discovery", "^4.0.0");
}

if (packageJson.devDependencies) {
updateDependencyIfExists(packageJson.devDependencies, "@nestjs/cli", "^10.0.0");
updateDependencyIfExists(packageJson.devDependencies, "@nestjs/schematics", "^10.0.0");
updateDependencyIfExists(packageJson.devDependencies, "@nestjs/testing", "^10.0.0");
}

await writeFile("api/package.json", JSON.stringify(packageJson, null, 4));
}

0 comments on commit fcfd0d8

Please sign in to comment.