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

fix(cli): Don't downgrade variables on migrate #7472

Merged
merged 3 commits into from
Jun 10, 2024
Merged
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
67 changes: 40 additions & 27 deletions cli/src/tasks/migrate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { writeFileSync, readFileSync, existsSync } from '@ionic/utils-fs';
import { join } from 'path';
import rimraf from 'rimraf';
import { coerce, gt, gte } from 'semver';
import { coerce, gt, gte, lt } from 'semver';

import { getAndroidPlugins } from '../android/common';
import c from '../colors';
Expand Down Expand Up @@ -284,35 +284,48 @@ export async function migrateCommand(
for (const variable of Object.keys(
variablesAndClasspaths.variables,
)) {
let replaceStart = `${variable} = '`;
let replaceEnd = `'\n`;
if (
!(await updateFile(
config,
variablesPath,
`${variable} = '`,
`'`,
variablesAndClasspaths.variables[variable].toString(),
true,
))
typeof variablesAndClasspaths.variables[variable] === 'number'
) {
const didWork = await updateFile(
config,
variablesPath,
`${variable} = `,
`\n`,
variablesAndClasspaths.variables[variable].toString(),
true,
replaceStart = `${variable} = `;
replaceEnd = `\n`;
}

if (txt.includes(replaceStart)) {
const first = txt.indexOf(replaceStart) + replaceStart.length;
const value = txt.substring(
first,
txt.indexOf(replaceEnd, first),
);
if (!didWork) {
let file = readFile(variablesPath);
if (file) {
file = file.replace(
'}',
` ${variable} = '${variablesAndClasspaths.variables[
variable
].toString()}'\n}`,
);
writeFileSync(variablesPath, file);
}
if (
(typeof variablesAndClasspaths.variables[variable] ===
'number' &&
value <= variablesAndClasspaths.variables[variable]) ||
(typeof variablesAndClasspaths.variables[variable] ===
'string' &&
lt(value, variablesAndClasspaths.variables[variable]))
) {
await updateFile(
config,
variablesPath,
replaceStart,
replaceEnd,
variablesAndClasspaths.variables[variable].toString(),
true,
);
}
} else {
let file = readFile(variablesPath);
if (file) {
file = file.replace(
'}',
` ${replaceStart}${variablesAndClasspaths.variables[
variable
].toString()}${replaceEnd}}`,
);
writeFileSync(variablesPath, file);
}
}
}
Expand Down