Skip to content

Commit

Permalink
Merge branch 'main' into 6048_eslint-flag
Browse files Browse the repository at this point in the history
  • Loading branch information
JerryWu1234 authored Dec 11, 2024
2 parents fc93083 + 079e881 commit 07427ad
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/qwik/src/cli/migrate-v2/replace-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
8 changes: 8 additions & 0 deletions packages/qwik/src/cli/migrate-v2/run-migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
removeTsMorphFromPackageJson,
updateDependencies,
} from './update-dependencies';
import { updateConfigurations } from './update-configurations';

export async function runV2Migration(app: AppCommand) {
intro(
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down
20 changes: 20 additions & 0 deletions packages/qwik/src/cli/migrate-v2/update-configurations.ts
Original file line number Diff line number Diff line change
@@ -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));
}
1 change: 1 addition & 0 deletions packages/qwik/src/cli/migrate-v2/update-dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 07427ad

Please sign in to comment.