Skip to content

Commit eaffede

Browse files
EimantasZubaviciusMartynas Žilinskas
andauthored
Hotfix: Initial webpack context load. (#2)
* Set up CI with Azure Pipelines [skip ci] * Remove initial local file loading. * Bump version. Co-authored-by: Martynas Žilinskas <martiogalaltu@gmail.com>
1 parent 46803fc commit eaffede

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

.eslintrc.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
{
2-
"extends": ["@reactway"],
3-
"ignorePatterns": ["src/shared/locale/translations/translations.d.ts"]
2+
"extends": ["@reactway"]
43
}

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "i18next-webpack-backend",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "Backend JSON loader for webpack applications.",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
@@ -32,20 +32,20 @@
3232
},
3333
"homepage": "https://github.com/reactway/i18next-webpack-backend#readme",
3434
"devDependencies": {
35-
"@reactway/eslint-config": "^1.0.1",
35+
"@reactway/eslint-config": "^1.0.3",
3636
"@types/lodash.set": "^4.3.6",
3737
"@types/webpack-env": "^1.15.1",
3838
"eslint": "^6.8.0",
39-
"ts-node": "^8.6.2",
40-
"typescript": "^3.8.2",
39+
"ts-node": "^8.7.0",
40+
"typescript": "^3.8.3",
4141
"prettier": "^1.19.1"
4242
},
4343
"peerDependencies": {
4444
"@types/webpack-env": "^1.15.1"
4545
},
4646
"dependencies": {
47-
"i18next": "^19.3.2",
47+
"i18next": "^19.3.3",
4848
"lodash.set": "^4.3.2",
49-
"tslib": "^1.11.0"
49+
"tslib": "^1.11.1"
5050
}
5151
}

src/backend-plugin.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export interface WebpackBackendOptions {
77

88
export class WebpackBackend implements Module {
99
public readonly type = "backend";
10-
private jsons: __WebpackModuleApi.RequireContext = require.context("");
10+
private jsons: __WebpackModuleApi.RequireContext | null = null;
1111
private keys: string[] = [];
1212
constructor(services: Services, options: WebpackBackendOptions = { context: undefined }) {
1313
this.init(services, options);
@@ -22,6 +22,16 @@ export class WebpackBackend implements Module {
2222

2323
public async read(language: string, namespace: string, callback: ReadCallback): Promise<void> {
2424
const builtKey = `./${language}/${namespace}.json`;
25+
if (this.jsons == null) {
26+
callback(
27+
new Error(`No context given!`),
28+
// TODO: Fix this when types are up to date with newest implementation.
29+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
30+
// @ts-ignore
31+
null
32+
);
33+
return;
34+
}
2535
if (this.keys.includes(builtKey) === false) {
2636
callback(
2737
new Error(`Namespace "${namespace}" for language "${language}" was not found!`),
@@ -44,6 +54,16 @@ export class WebpackBackend implements Module {
4454
return Promise.all(
4555
languages.map(async lang => {
4656
const builtKey = `./${lang}/${namespace}.json`;
57+
if (this.jsons == null) {
58+
callback(
59+
new Error(`No context given!`),
60+
// TODO: Fix this when types are up to date with newest implementation.
61+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
62+
// @ts-ignore
63+
null
64+
);
65+
return;
66+
}
4767
if (this.keys.includes(builtKey) === false) {
4868
console.error(new Error(`Namespace "${namespace}" for language "${lang}" was not found!`));
4969
return;

0 commit comments

Comments
 (0)