From a252eb956fff280c0d42c6e7f41122ebbdf261c1 Mon Sep 17 00:00:00 2001 From: Mara Date: Thu, 9 Nov 2023 12:54:27 +0100 Subject: [PATCH] fix(settings): allow deep merge of settings, preventing error with nested objet --- package.json | 3 ++- pnpm-lock.yaml | 8 ++++++++ src/main.ts | 14 +++++--------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index a4eb042f..ff4d7f04 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,8 @@ "typescript": "^5.2.2" }, "dependencies": { - "dedent": "^0.7.0" + "dedent": "^0.7.0", + "ts-deepmerge": "^6.2.0" }, "pnpm": { "overrides": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4ceb0316..3d12afd1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12,6 +12,9 @@ dependencies: dedent: specifier: ^0.7.0 version: 0.7.0 + ts-deepmerge: + specifier: ^6.2.0 + version: 6.2.0 devDependencies: '@babel/core': @@ -6737,6 +6740,11 @@ packages: typescript: 5.2.2 dev: true + /ts-deepmerge@6.2.0: + resolution: {integrity: sha512-2qxI/FZVDPbzh63GwWIZYE7daWKtwXZYuyc8YNq0iTmMUwn4mL0jRLsp6hfFlgbdRSR4x2ppe+E86FnvEpN7Nw==} + engines: {node: '>=14.13.1'} + dev: false + /ts-jest@29.1.1(@babel/core@7.23.0)(babel-jest@29.7.0)(esbuild@0.19.4)(jest@29.7.0)(typescript@5.2.2): resolution: {integrity: sha512-D6xjnnbP17cC85nliwGiL+tpoKN0StpgE0TeOjXQTU6MVCfsB4v7aW05CgQ/1OywGb0x/oy9hHFnN+sczTiRaA==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} diff --git a/src/main.ts b/src/main.ts index e02646dd..b22d00da 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,7 @@ import {Octokit} from "@octokit/core"; import i18next from "i18next"; import {FrontMatterCache, Menu, Plugin, TAbstractFile, TFile, TFolder} from "obsidian"; +import merge from "ts-deepmerge"; import { checkRepositoryValidityCallback, @@ -179,6 +180,8 @@ export default class GithubPublisher extends Plugin { */ async onload(): Promise { console.info(`[GITHUB PUBLISHER] v.${this.manifest.version} (lang: ${translationLanguage}) loaded`); + await this.loadSettings(); + await i18next.init({ lng: translationLanguage, fallbackLng: "en", @@ -186,7 +189,6 @@ export default class GithubPublisher extends Plugin { returnNull: false, }); - await this.loadSettings(); const oldSettings = this.settings; @@ -258,15 +260,9 @@ export default class GithubPublisher extends Plugin { console.info("[Github Publisher] unloaded"); } - /** - * Get the settings of the plugin - */ async loadSettings() { - this.settings = Object.assign( - {}, - DEFAULT_SETTINGS, - await this.loadData() - ); + const loadedData = await this.loadData(); + this.settings = merge(DEFAULT_SETTINGS, loadedData) as unknown as GitHubPublisherSettings; } /**