Skip to content

Commit 31b5466

Browse files
fix(qwik): migrate-v2 cmd enhancements
1 parent d264a52 commit 31b5466

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

packages/qwik/src/cli/migrate-v2/replace-package.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@ function updateFileContent(path: string, content: string) {
99
log.info(`"${path}" has been updated`);
1010
}
1111

12-
export function replacePackage(oldPackageName: string, newPackageName: string): void {
13-
replacePackageInDependencies(oldPackageName, newPackageName);
12+
export function replacePackage(
13+
oldPackageName: string,
14+
newPackageName: string,
15+
skipDependencies = false
16+
): void {
17+
if (skipDependencies) {
18+
replacePackageInDependencies(oldPackageName, newPackageName);
19+
}
1420

1521
replaceMentions(oldPackageName, newPackageName);
1622
}

packages/qwik/src/cli/migrate-v2/run-migration.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
removeTsMorphFromPackageJson,
99
updateDependencies,
1010
} from './update-dependencies';
11+
import { updateConfigurations } from './update-configurations';
1112

1213
export async function runV2Migration(app: AppCommand) {
1314
intro(
@@ -40,7 +41,12 @@ export async function runV2Migration(app: AppCommand) {
4041
],
4142
'@builder.io/qwik-city'
4243
);
44+
replaceImportInFiles(
45+
[['qwikCityPlan', 'qwikRouterConfig']],
46+
'@qwik-city-plan' // using old name, package name will be updated in the next step
47+
);
4348

49+
replacePackage('@qwik-city-plan', '@qwik-router-config', true);
4450
replacePackage('@builder.io/qwik-city', '@qwik.dev/router');
4551
replacePackage('@builder.io/qwik-react', '@qwik.dev/react');
4652
// "@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) {
5056
await removeTsMorphFromPackageJson();
5157
}
5258

59+
updateConfigurations();
60+
5361
await updateDependencies();
5462
log.success(`${green(`Your application has been successfully migrated to v2!`)}`);
5563
} catch (error) {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { readFileSync, writeFileSync } from 'fs';
2+
import { log } from '@clack/prompts';
3+
4+
export function updateConfigurations() {
5+
try {
6+
updateTsconfig();
7+
} catch (error) {
8+
log.error('Failed to update tsconfig.json configuration.');
9+
}
10+
}
11+
12+
function updateTsconfig() {
13+
const tsConfigPath = 'tsconfig.json';
14+
const tsConfig = JSON.parse(readFileSync(tsConfigPath, 'utf-8'));
15+
if (!tsConfig) {
16+
return;
17+
}
18+
tsConfig.compilerOptions.moduleResolution = 'bundler';
19+
writeFileSync(tsConfigPath, JSON.stringify(tsConfig, null, 2));
20+
}

packages/qwik/src/cli/migrate-v2/update-dependencies.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,5 @@ export async function removeTsMorphFromPackageJson() {
9191
const packageJson = await readPackageJson(process.cwd());
9292
delete packageJson.dependencies?.['ts-morph'];
9393
delete packageJson.devDependencies?.['ts-morph'];
94+
await writePackageJson(process.cwd(), packageJson);
9495
}

0 commit comments

Comments
 (0)