From 4efe0acbcf1bd3605985b2e76022fe3ae6ba19ea Mon Sep 17 00:00:00 2001 From: Dmitriy Stepanenko Date: Sun, 18 Aug 2024 17:54:47 +0300 Subject: [PATCH] feat: update depenencies WIP --- .../qwik/src/cli/migrate-v2/run-migration.ts | 11 ++++++----- .../src/cli/migrate-v2/update-dependencies.ts | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 packages/qwik/src/cli/migrate-v2/update-dependencies.ts diff --git a/packages/qwik/src/cli/migrate-v2/run-migration.ts b/packages/qwik/src/cli/migrate-v2/run-migration.ts index cecebd59383c..a7e28873bf5e 100644 --- a/packages/qwik/src/cli/migrate-v2/run-migration.ts +++ b/packages/qwik/src/cli/migrate-v2/run-migration.ts @@ -3,12 +3,13 @@ import type { AppCommand } from '../utils/app-command'; import { bgMagenta } from 'kleur/colors'; import { bye } from '../utils/utils'; import { replacePackage } from './replace-package'; +import { updateDependencies } from './update-dependencies'; export async function runV2Migration(app: AppCommand) { intro( `✨ ${bgMagenta(' This command will migrate your Qwik application from v1 to v2 \n')}` + `This includes the following: \n` + - // TODO: package names + // TODO: package names ` - "@builder.io/qwik", "@builder.io/qwik-city" packages will be rescoped to "@qwik.dev/core" and "@qwik.dev/qwik-city" \n` + ` - related dependencies will be updated \n` ); @@ -22,11 +23,11 @@ export async function runV2Migration(app: AppCommand) { } try { - replacePackage('@builder.io/qwik', '@qwik.dev/qwik'); - replacePackage('@builder.io/qwik-city', '@qwik.dev/city'); + replacePackage('@builder.io/qwik', '@qwik.dev/qwik'); + replacePackage('@builder.io/qwik-city', '@qwik.dev/city'); + await updateDependencies(); } catch (error) { console.log(error); - throw error + throw error; } - } diff --git a/packages/qwik/src/cli/migrate-v2/update-dependencies.ts b/packages/qwik/src/cli/migrate-v2/update-dependencies.ts new file mode 100644 index 000000000000..ecd444fa3b68 --- /dev/null +++ b/packages/qwik/src/cli/migrate-v2/update-dependencies.ts @@ -0,0 +1,18 @@ +import { getPackageManager, readPackageJson } from './../utils/utils'; +import { installDeps } from '../utils/install-deps'; + +export async function updateDependencies() { + // TODO: workspaceRoot + const packageJson = await readPackageJson(process.cwd()); + // TODO: should come from elsewhere? + const newVersion = '2.0.0'; + (packageJson.devDependencies ??= {})['@qwik.dev/qwik'] = newVersion; + (packageJson.devDependencies ??= {})['@qwik.dev/city'] = newVersion; + delete packageJson.dependencies?.['@builder.io/qwik']; + delete packageJson.dependencies?.['@builder.io/qwik-city']; + const { install } = installDeps(getPackageManager(), process.cwd()); + const passed = await install; + if (!passed) { + throw new Error('Failed to install dependencies'); + } +}