From 2ccd2989f0ca73959ae0a4f22a188a848b9504e4 Mon Sep 17 00:00:00 2001 From: Karoun Kasraie Date: Sun, 2 Apr 2023 21:42:35 +0000 Subject: [PATCH 1/4] Making i18next a dev-only dependency --- package.json | 6 +++--- src/backend-plugin.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 9cd2385..f467eda 100644 --- a/package.json +++ b/package.json @@ -36,15 +36,15 @@ "@types/lodash.set": "^4.3.6", "@types/webpack-env": "^1.15.1", "eslint": "^6.8.0", + "i18next": "^19.3.3", + "prettier": "^1.19.1", "ts-node": "^8.7.0", - "typescript": "^3.8.3", - "prettier": "^1.19.1" + "typescript": "^3.8.3" }, "peerDependencies": { "@types/webpack-env": "^1.15.1" }, "dependencies": { - "i18next": "^19.3.3", "lodash.set": "^4.3.2", "tslib": "^1.11.1" } diff --git a/src/backend-plugin.ts b/src/backend-plugin.ts index 8cd8c23..149b1e5 100644 --- a/src/backend-plugin.ts +++ b/src/backend-plugin.ts @@ -1,4 +1,4 @@ -import { ReadCallback, Services, Module, MultiReadCallback } from "i18next"; +import type { ReadCallback, Services, Module, MultiReadCallback } from "i18next"; import set from "lodash.set"; export interface WebpackBackendOptions { From 25a8d4e02f3aa97008d69895364fdc031f496556 Mon Sep 17 00:00:00 2001 From: Karoun Kasraie Date: Sun, 2 Apr 2023 21:42:53 +0000 Subject: [PATCH 2/4] Making console error into actual one --- src/backend-plugin.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend-plugin.ts b/src/backend-plugin.ts index 149b1e5..429dc75 100644 --- a/src/backend-plugin.ts +++ b/src/backend-plugin.ts @@ -65,7 +65,7 @@ export class WebpackBackend implements Module { return; } if (this.keys.includes(builtKey) === false) { - console.error(new Error(`Namespace "${namespace}" for language "${lang}" was not found!`)); + callback(new Error(`Namespace "${namespace}" for language "${lang}" was not found!`), null); return; } const json = await this.jsons(builtKey); From bde74974c426b768432408b8bd004edb8d9b4d72 Mon Sep 17 00:00:00 2001 From: Karoun Kasraie Date: Sun, 2 Apr 2023 21:48:14 +0000 Subject: [PATCH 3/4] Fixes #9; adds module type --- src/backend-plugin.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/backend-plugin.ts b/src/backend-plugin.ts index 429dc75..a2b7350 100644 --- a/src/backend-plugin.ts +++ b/src/backend-plugin.ts @@ -6,6 +6,7 @@ export interface WebpackBackendOptions { } export class WebpackBackend implements Module { + public static readonly type = "backend"; public readonly type = "backend"; private jsons: __WebpackModuleApi.RequireContext | null = null; private keys: string[] = []; @@ -65,7 +66,13 @@ export class WebpackBackend implements Module { return; } if (this.keys.includes(builtKey) === false) { - callback(new Error(`Namespace "${namespace}" for language "${lang}" was not found!`), null); + callback( + new Error(`Namespace "${namespace}" for language "${lang}" was not found!`), + // TODO: Fix this when types are up to date with newest implementation. + // eslint-disable-next-line @typescript-eslint/ban-ts-ignore + // @ts-ignore + null + ); return; } const json = await this.jsons(builtKey); From bbe7f006b0ad82aee4c1dc79d263f14d0b561d4d Mon Sep 17 00:00:00 2001 From: Karoun Kasraie Date: Mon, 3 Apr 2023 21:07:07 +0000 Subject: [PATCH 4/4] Removing unnecessary async --- src/backend-plugin.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/backend-plugin.ts b/src/backend-plugin.ts index a2b7350..885d0bc 100644 --- a/src/backend-plugin.ts +++ b/src/backend-plugin.ts @@ -51,8 +51,8 @@ export class WebpackBackend implements Module { const translations = {}; await Promise.all( - namespaces.map(async namespace => { - return Promise.all( + namespaces.map(namespace => + Promise.all( languages.map(async lang => { const builtKey = `./${lang}/${namespace}.json`; if (this.jsons == null) { @@ -78,8 +78,8 @@ export class WebpackBackend implements Module { const json = await this.jsons(builtKey); set(translations, `${lang}.${namespace}`, json); }) - ); - }) + ) + ) ); if (Object.keys(translations).length === 0) {