Skip to content

Commit 1764a3e

Browse files
committed
fix: handle undefined languageMappings property in migration
1 parent 2557b89 commit 1764a3e

2 files changed

Lines changed: 27 additions & 9 deletions

File tree

src/model.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { isNullish, isPlainObject } from "remeda";
22

33
import type { Options } from "prettier";
4-
import type { ReadonlyTuple } from "type-fest";
4+
import { versionStrToNum } from "./utils/version";
55

66
export interface Data {
77
version: number;
@@ -37,13 +37,9 @@ export const getDefaultIgnorePatterns = (): string =>
3737
`.trim();
3838

3939
export const getCurrentVersion = () => {
40-
const { version } = manifest;
41-
const [major, minor, patch] = version.split(".").map(Number) as unknown as ReadonlyTuple<
42-
number,
43-
3
44-
>;
40+
const version = versionStrToNum(manifest.version);
4541

46-
return major * 10000 + minor * 100 + patch;
42+
return version;
4743
};
4844

4945
export const getDefaultSettings = (): Settings => ({
@@ -70,13 +66,28 @@ export const migrate = (data: unknown): Data => {
7066
if (!Object.hasOwn(data, "version")) {
7167
const dataV1 = data as unknown as Settings;
7268
const dataV2: Data = {
73-
version: 20000,
69+
version: versionStrToNum("2.0.0"),
7470
settings: { ...dataV1, removeExtraSpaces: false },
7571
};
7672

7773
return migrate(dataV2);
7874
}
7975

80-
// 2.0.0
76+
// 2.0.0 -> 2.0.1
77+
if (data.version === versionStrToNum("2.0.0")) {
78+
const dataV2 = data as unknown as Data;
79+
const dataV2_0_1: Data = {
80+
version: versionStrToNum("2.0.1"),
81+
settings: {
82+
// @ts-expect-error
83+
languageMappings: {},
84+
...dataV2.settings,
85+
},
86+
};
87+
88+
return migrate(dataV2_0_1);
89+
}
90+
91+
// 2.0.1
8192
return data as unknown as Data;
8293
};

src/utils/version.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { ReadonlyTuple } from "type-fest";
2+
3+
export const versionStrToNum = (str: string) => {
4+
const [major, minor, patch] = str.split(".").map(Number) as unknown as ReadonlyTuple<number, 3>;
5+
6+
return major * 10000 + minor * 100 + patch;
7+
};

0 commit comments

Comments
 (0)