From 6136e964c14822983d0e1af8a010360618e4e293 Mon Sep 17 00:00:00 2001 From: jldec Date: Mon, 29 Apr 2024 21:29:43 +0100 Subject: [PATCH 1/3] Error on messages file json parse failures --- .../inlang-message-format/src/plugin.test.ts | 40 +++++++++++++++++++ .../inlang-message-format/src/plugin.ts | 7 +++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/inlang/source-code/plugins/inlang-message-format/src/plugin.test.ts b/inlang/source-code/plugins/inlang-message-format/src/plugin.test.ts index 572db74b67..f0720962de 100644 --- a/inlang/source-code/plugins/inlang-message-format/src/plugin.test.ts +++ b/inlang/source-code/plugins/inlang-message-format/src/plugin.test.ts @@ -164,6 +164,46 @@ test("don't throw if the storage path does not exist. instead, create the file a } }) +test("throws if json has a trailing comma", async () => { + const { plugin } = await import("./plugin.js") + const fs = createNodeishMemoryFs() + + const settings = { + sourceLanguageTag: "en", + languageTags: ["en", "de"], + modules: [], + [pluginId]: { pathPattern: "./messages/{languageTag}.json" } satisfies PluginSettings, + } + + const enInitial = JSON.stringify({ + $schema: "https://inlang.com/schema/inlang-message-format", + first_message: "If this works I will be sad", + second_message: "Let's see if this blows up", + } satisfies StorageSchema) + + let deInitial = JSON.stringify({ + $schema: "https://inlang.com/schema/inlang-message-format", + second_message: "Mal sehen ob das knallt", + } satisfies StorageSchema) + + // inject trailing comma + deInitial = deInitial.slice(0, -1) + ",}" + + await fs.mkdir("./messages") + await fs.writeFile("./messages/en.json", enInitial) + await fs.writeFile("./messages/de.json", deInitial) + + try { + await plugin.loadMessages!({ + settings, + nodeishFs: fs, + }) + throw new Error("loadMessages should have thrown") + } catch (e) { + expect((e as Error).message).not.toBe("loadMessages should have thrown") + } +}) + test("recursively creating a directory should not fail if a subpath already exists", async () => { const { plugin } = await import("./plugin.js") const fs = createNodeishMemoryFs() diff --git a/inlang/source-code/plugins/inlang-message-format/src/plugin.ts b/inlang/source-code/plugins/inlang-message-format/src/plugin.ts index e122bbafc8..cc7fb5d080 100644 --- a/inlang/source-code/plugins/inlang-message-format/src/plugin.ts +++ b/inlang/source-code/plugins/inlang-message-format/src/plugin.ts @@ -53,8 +53,11 @@ export const plugin: Plugin<{ result[key] = parseMessage({ key, value: json[key], languageTag: tag }) } } - } catch { - // file does not exist. likely, no translations for the file exist yet. + } catch (error) { + // ignore if file does not exist => no translations exist yet. + if ((error as any)?.code !== "ENOENT") { + throw error + } } } return Object.values(result) From 732430d56762236d29557a9c2973b6daafc729ad Mon Sep 17 00:00:00 2001 From: jldec Date: Mon, 29 Apr 2024 21:33:39 +0100 Subject: [PATCH 2/3] changeset --- .changeset/cold-balloons-trade.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/cold-balloons-trade.md diff --git a/.changeset/cold-balloons-trade.md b/.changeset/cold-balloons-trade.md new file mode 100644 index 0000000000..5dcb130601 --- /dev/null +++ b/.changeset/cold-balloons-trade.md @@ -0,0 +1,5 @@ +--- +"@inlang/plugin-message-format": minor +--- + +Error on messages file json parse failures From de08410b3d2603a7255671f92a767fec4340bb7c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 30 Apr 2024 07:05:47 +0000 Subject: [PATCH 3/3] Version Packages --- .changeset/cold-balloons-trade.md | 5 ----- .changeset/small-mayflies-care.md | 5 ----- inlang/source-code/ide-extension/CHANGELOG.md | 6 ++++++ inlang/source-code/ide-extension/package.json | 2 +- .../source-code/plugins/inlang-message-format/CHANGELOG.md | 6 ++++++ .../source-code/plugins/inlang-message-format/package.json | 2 +- inlang/source-code/server/CHANGELOG.md | 7 +++++++ 7 files changed, 21 insertions(+), 12 deletions(-) delete mode 100644 .changeset/cold-balloons-trade.md delete mode 100644 .changeset/small-mayflies-care.md diff --git a/.changeset/cold-balloons-trade.md b/.changeset/cold-balloons-trade.md deleted file mode 100644 index 5dcb130601..0000000000 --- a/.changeset/cold-balloons-trade.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@inlang/plugin-message-format": minor ---- - -Error on messages file json parse failures diff --git a/.changeset/small-mayflies-care.md b/.changeset/small-mayflies-care.md deleted file mode 100644 index e43e065988..0000000000 --- a/.changeset/small-mayflies-care.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"vs-code-extension": minor ---- - -add ability to disable inline annotations diff --git a/inlang/source-code/ide-extension/CHANGELOG.md b/inlang/source-code/ide-extension/CHANGELOG.md index e9c3d72cb8..f077ba40fb 100644 --- a/inlang/source-code/ide-extension/CHANGELOG.md +++ b/inlang/source-code/ide-extension/CHANGELOG.md @@ -1,5 +1,11 @@ # inlang-vs-code-extension +## 1.40.0 + +### Minor Changes + +- 1cfdca2: add ability to disable inline annotations + ## 1.39.8 ### Patch Changes diff --git a/inlang/source-code/ide-extension/package.json b/inlang/source-code/ide-extension/package.json index 255601aea7..41aca2fe55 100644 --- a/inlang/source-code/ide-extension/package.json +++ b/inlang/source-code/ide-extension/package.json @@ -10,7 +10,7 @@ "url": "https://github.com/opral/monorepo.git" }, "icon": "assets/sherlock-logo.png", - "version": "1.39.8", + "version": "1.40.0", "engines": { "vscode": "^1.84.2" }, diff --git a/inlang/source-code/plugins/inlang-message-format/CHANGELOG.md b/inlang/source-code/plugins/inlang-message-format/CHANGELOG.md index 75d6a69fad..65fba2e62b 100644 --- a/inlang/source-code/plugins/inlang-message-format/CHANGELOG.md +++ b/inlang/source-code/plugins/inlang-message-format/CHANGELOG.md @@ -1,5 +1,11 @@ # @inlang/plugin-message-format +## 2.2.0 + +### Minor Changes + +- 732430d: Error on messages file json parse failures + ## 2.1.1 ### Patch Changes diff --git a/inlang/source-code/plugins/inlang-message-format/package.json b/inlang/source-code/plugins/inlang-message-format/package.json index 7a8b7729c6..014643fad6 100644 --- a/inlang/source-code/plugins/inlang-message-format/package.json +++ b/inlang/source-code/plugins/inlang-message-format/package.json @@ -1,6 +1,6 @@ { "name": "@inlang/plugin-message-format", - "version": "2.1.1", + "version": "2.2.0", "type": "module", "exports": { "./storage-schema": "./src/storageSchema.ts" diff --git a/inlang/source-code/server/CHANGELOG.md b/inlang/source-code/server/CHANGELOG.md index 6924a54ee7..12f4565304 100644 --- a/inlang/source-code/server/CHANGELOG.md +++ b/inlang/source-code/server/CHANGELOG.md @@ -4,6 +4,13 @@ ### Patch Changes +- Updated dependencies [732430d] + - @inlang/plugin-message-format@2.2.0 + +## null + +### Patch Changes + - @inlang/plugin-message-format@2.1.1 - @inlang/website@null - @inlang/badge@0.7.18