diff --git a/packages/qwik/src/cli/migrate-v2/replace-package.ts b/packages/qwik/src/cli/migrate-v2/replace-package.ts index 46815cf6f2a..a54fa60b5fd 100644 --- a/packages/qwik/src/cli/migrate-v2/replace-package.ts +++ b/packages/qwik/src/cli/migrate-v2/replace-package.ts @@ -9,8 +9,14 @@ function updateFileContent(path: string, content: string) { log.info(`"${path}" has been updated`); } -export function replacePackage(oldPackageName: string, newPackageName: string): void { - replacePackageInDependencies(oldPackageName, newPackageName); +export function replacePackage( + oldPackageName: string, + newPackageName: string, + skipDependencies = false +): void { + if (!skipDependencies) { + replacePackageInDependencies(oldPackageName, newPackageName); + } replaceMentions(oldPackageName, newPackageName); } diff --git a/packages/qwik/src/cli/migrate-v2/run-migration.ts b/packages/qwik/src/cli/migrate-v2/run-migration.ts index 73b0c66f240..7ded4091a3e 100644 --- a/packages/qwik/src/cli/migrate-v2/run-migration.ts +++ b/packages/qwik/src/cli/migrate-v2/run-migration.ts @@ -8,6 +8,7 @@ import { removeTsMorphFromPackageJson, updateDependencies, } from './update-dependencies'; +import { updateConfigurations } from './update-configurations'; export async function runV2Migration(app: AppCommand) { intro( @@ -40,7 +41,12 @@ export async function runV2Migration(app: AppCommand) { ], '@builder.io/qwik-city' ); + replaceImportInFiles( + [['qwikCityPlan', 'qwikRouterConfig']], + '@qwik-city-plan' // using old name, package name will be updated in the next step + ); + replacePackage('@qwik-city-plan', '@qwik-router-config', true); replacePackage('@builder.io/qwik-city', '@qwik.dev/router'); replacePackage('@builder.io/qwik-react', '@qwik.dev/react'); // "@builder.io/qwik" should be the last one because it's name is a substring of the package names above @@ -50,6 +56,8 @@ export async function runV2Migration(app: AppCommand) { await removeTsMorphFromPackageJson(); } + updateConfigurations(); + await updateDependencies(); log.success(`${green(`Your application has been successfully migrated to v2!`)}`); } catch (error) { diff --git a/packages/qwik/src/cli/migrate-v2/update-configurations.ts b/packages/qwik/src/cli/migrate-v2/update-configurations.ts new file mode 100644 index 00000000000..db8905a7406 --- /dev/null +++ b/packages/qwik/src/cli/migrate-v2/update-configurations.ts @@ -0,0 +1,20 @@ +import { readFileSync, writeFileSync } from 'fs'; +import { log } from '@clack/prompts'; + +export function updateConfigurations() { + try { + updateTsconfig(); + } catch (error) { + log.error('Failed to update tsconfig.json configuration.'); + } +} + +function updateTsconfig() { + const tsConfigPath = 'tsconfig.json'; + const tsConfig = JSON.parse(readFileSync(tsConfigPath, 'utf-8')); + if (!tsConfig) { + return; + } + tsConfig.compilerOptions.moduleResolution = 'bundler'; + writeFileSync(tsConfigPath, JSON.stringify(tsConfig, null, 2)); +} diff --git a/packages/qwik/src/cli/migrate-v2/update-dependencies.ts b/packages/qwik/src/cli/migrate-v2/update-dependencies.ts index 6ab60ecd57d..8e6149bdd06 100644 --- a/packages/qwik/src/cli/migrate-v2/update-dependencies.ts +++ b/packages/qwik/src/cli/migrate-v2/update-dependencies.ts @@ -91,4 +91,5 @@ export async function removeTsMorphFromPackageJson() { const packageJson = await readPackageJson(process.cwd()); delete packageJson.dependencies?.['ts-morph']; delete packageJson.devDependencies?.['ts-morph']; + await writePackageJson(process.cwd(), packageJson); }