Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script to remove passport #42

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
49 changes: 49 additions & 0 deletions src/util/package-json.util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { existsSync, readFileSync, writeFileSync } from "fs";

type Json = {
dependencies?: Record<string, string>;
devDependencies?: Record<string, string>;
};

export class PackageJson {
private path: string;
private json: Json;

constructor(path: string) {
if (!existsSync(path)) {
throw new Error("File does not exist");
}

this.path = path;
this.json = JSON.parse(readFileSync(path, "utf-8"));
}

addDependency(name: string, version: string, dev = false) {
if (dev) {
this.json.devDependencies ??= {};
this.json.devDependencies[name] = version;
} else {
this.json.dependencies ??= {};
this.json.dependencies[name] = version;
}
}

updateDependency(name: string, version: string) {
if (this.json.dependencies?.[name]) {
this.json.dependencies[name] = version;
}

if (this.json.devDependencies?.[name]) {
this.json.devDependencies[name] = version;
}
}

removeDependency(name: string) {
delete this.json.dependencies?.[name];
delete this.json.devDependencies?.[name];
}

save() {
writeFileSync(this.path, JSON.stringify(this.json, null, 4));
}
}
22 changes: 22 additions & 0 deletions src/v8/remove-passport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { existsSync } from "fs";

import { PackageJson } from "../util/package-json.util";

export const stage = "before-install";

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

const packageJson = new PackageJson("api/package.json");
packageJson.updateDependency("@nestjs/jwt", "^10.2.0");
packageJson.removeDependency("@nestjs/passport");
packageJson.removeDependency("passport");
packageJson.removeDependency("passport-http");
packageJson.removeDependency("passport-http-bearer");
packageJson.removeDependency("@types/passport");
packageJson.removeDependency("@types/passport-http");
packageJson.removeDependency("@types/passport-http-bearer");
await packageJson.save();
}
21 changes: 21 additions & 0 deletions src/v8/update-mikro-orm-dependencies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { existsSync } from "fs";

import { PackageJson } from "../util/package-json.util";

export const stage = "before-install";

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

const packageJson = new PackageJson("api/package.json");

packageJson.updateDependency("@mikro-orm/cli", "^6.0.0");
packageJson.updateDependency("@mikro-orm/core", "^6.0.0");
packageJson.updateDependency("@mikro-orm/migrations", "^6.0.0");
packageJson.updateDependency("@mikro-orm/nestjs", "^6.0.2");
packageJson.updateDependency("@mikro-orm/postgresql", "^6.0.0");

packageJson.save();
}
49 changes: 20 additions & 29 deletions src/v8/update-nest-dependencies.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,36 @@
import { existsSync } from "fs";
import { readFile, writeFile } from "fs/promises";

export const stage = "before-install";
import { PackageJson } from "../util/package-json.util";

function updateDependencyIfExists(dependencies: Record<string, string>, name: string, version: string) {
if (dependencies[name]) {
dependencies[name] = version;
}
}
export const stage = "before-install";

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

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

if (packageJson.dependencies) {
packageJson.dependencies["@apollo/server"] = "^4.0.0";
delete packageJson.dependencies["apollo-server-core"];
delete packageJson.dependencies["apollo-server-express"];
packageJson.addDependency("@apollo/server", "^4.0.0");
packageJson.removeDependency("apollo-server-core");
packageJson.removeDependency("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");
packageJson.updateDependency("@nestjs/apollo", "^12.0.0");
packageJson.updateDependency("@nestjs/common", "^10.0.0");
packageJson.updateDependency("@nestjs/core", "^10.0.0");
packageJson.updateDependency("@nestjs/graphql", "^12.0.0");
// TODO remove when https://github.com/vivid-planet/comet/pull/2809 has been merged
packageJson.updateDependency("@nestjs/passport", "^10.0.0");
packageJson.updateDependency("@nestjs/platform-express", "^10.0.0");

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

updateDependencyIfExists(packageJson.dependencies, "nestjs-console", "^9.0.0");
updateDependencyIfExists(packageJson.dependencies, "@golevelup/nestjs-discovery", "^4.0.0");
}
packageJson.updateDependency("nestjs-console", "^9.0.0");
packageJson.updateDependency("@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");
}
packageJson.updateDependency("@nestjs/cli", "^10.0.0");
packageJson.updateDependency("@nestjs/schematics", "^10.0.0");
packageJson.updateDependency("@nestjs/testing", "^10.0.0");

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