Skip to content

Commit 1e7aeb5

Browse files
authored
fix(cli): Don't downgrade variables on migrate (#7472)
1 parent f27786e commit 1e7aeb5

File tree

1 file changed

+40
-27
lines changed

1 file changed

+40
-27
lines changed

cli/src/tasks/migrate.ts

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { writeFileSync, readFileSync, existsSync } from '@ionic/utils-fs';
22
import { join } from 'path';
33
import rimraf from 'rimraf';
4-
import { coerce, gt, gte } from 'semver';
4+
import { coerce, gt, gte, lt } from 'semver';
55

66
import { getAndroidPlugins } from '../android/common';
77
import c from '../colors';
@@ -284,35 +284,48 @@ export async function migrateCommand(
284284
for (const variable of Object.keys(
285285
variablesAndClasspaths.variables,
286286
)) {
287+
let replaceStart = `${variable} = '`;
288+
let replaceEnd = `'\n`;
287289
if (
288-
!(await updateFile(
289-
config,
290-
variablesPath,
291-
`${variable} = '`,
292-
`'`,
293-
variablesAndClasspaths.variables[variable].toString(),
294-
true,
295-
))
290+
typeof variablesAndClasspaths.variables[variable] === 'number'
296291
) {
297-
const didWork = await updateFile(
298-
config,
299-
variablesPath,
300-
`${variable} = `,
301-
`\n`,
302-
variablesAndClasspaths.variables[variable].toString(),
303-
true,
292+
replaceStart = `${variable} = `;
293+
replaceEnd = `\n`;
294+
}
295+
296+
if (txt.includes(replaceStart)) {
297+
const first = txt.indexOf(replaceStart) + replaceStart.length;
298+
const value = txt.substring(
299+
first,
300+
txt.indexOf(replaceEnd, first),
304301
);
305-
if (!didWork) {
306-
let file = readFile(variablesPath);
307-
if (file) {
308-
file = file.replace(
309-
'}',
310-
` ${variable} = '${variablesAndClasspaths.variables[
311-
variable
312-
].toString()}'\n}`,
313-
);
314-
writeFileSync(variablesPath, file);
315-
}
302+
if (
303+
(typeof variablesAndClasspaths.variables[variable] ===
304+
'number' &&
305+
value <= variablesAndClasspaths.variables[variable]) ||
306+
(typeof variablesAndClasspaths.variables[variable] ===
307+
'string' &&
308+
lt(value, variablesAndClasspaths.variables[variable]))
309+
) {
310+
await updateFile(
311+
config,
312+
variablesPath,
313+
replaceStart,
314+
replaceEnd,
315+
variablesAndClasspaths.variables[variable].toString(),
316+
true,
317+
);
318+
}
319+
} else {
320+
let file = readFile(variablesPath);
321+
if (file) {
322+
file = file.replace(
323+
'}',
324+
` ${replaceStart}${variablesAndClasspaths.variables[
325+
variable
326+
].toString()}${replaceEnd}}`,
327+
);
328+
writeFileSync(variablesPath, file);
316329
}
317330
}
318331
}

0 commit comments

Comments
 (0)