@nimpl/i18n 2.0.0-canary.1 → 2.0.0-canary.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ throw new Error("Please add the i18n wrapper to your next.config.js");
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
@@ -10,25 +33,26 @@ const CONFIG_PATH = path_1.default.join(process.cwd(), "nimpl-i18n.js");
10
33
  // Crutch bypass of conversion by the assembler to require
11
34
  const dynamicImport = new Function("p", "return import(p)");
12
35
  const getConfig = async () => {
13
- try {
14
- if (fs_1.default.existsSync(CONFIG_PATH)) {
15
- const config = await dynamicImport((0, url_1.pathToFileURL)(CONFIG_PATH).href);
16
- const { load, getLanguage, languages } = config.default;
17
- if (!load) {
18
- throw new Error(`Can't find load method in configuration file - https://github.com/vordgi/nimpl-i18n#configuration`);
19
- }
20
- if (!languages) {
21
- throw new Error(`Can't find languages list in configuration file - https://github.com/vordgi/nimpl-i18n#configuration`);
22
- }
23
- if (!getLanguage) {
24
- throw new Error(`Can't find getLanguage method in configuration file - https://github.com/vordgi/nimpl-i18n#configuration`);
25
- }
26
- return config.default;
27
- }
36
+ let clientConfig;
37
+ if (fs_1.default.existsSync(CONFIG_PATH)) {
38
+ const config = await dynamicImport((0, url_1.pathToFileURL)(CONFIG_PATH).href);
39
+ clientConfig = config.default;
40
+ }
41
+ else {
42
+ // @ts-expect-error will be imported from the alias configuration in webpack
43
+ const config = await Promise.resolve().then(() => __importStar(require("@nimpl/i18n/clientConfig")));
44
+ clientConfig = config.default;
45
+ }
46
+ const { load, getLanguage, languages } = clientConfig;
47
+ if (!load) {
48
+ throw new Error(`Can't find "load" method in configuration file - https://github.com/vordgi/nimpl-i18n#configuration`);
49
+ }
50
+ if (!languages) {
51
+ throw new Error(`Can't find "languages" list in configuration file - https://github.com/vordgi/nimpl-i18n#configuration`);
28
52
  }
29
- catch (err) {
30
- console.error(err);
53
+ if (!getLanguage) {
54
+ throw new Error(`Can't find "getLanguage" method in configuration file - https://github.com/vordgi/nimpl-i18n#configuration`);
31
55
  }
32
- throw new Error("Can't load config - https://github.com/vordgi/nimpl-i18n#configuration");
56
+ return clientConfig;
33
57
  };
34
58
  exports.default = getConfig;
package/dist/i18n.js ADDED
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const fs_1 = require("fs");
7
+ const path_1 = __importDefault(require("path"));
8
+ const CONFIG_PATH = path_1.default.join(process.cwd(), "nimpl-i18n.js");
9
+ const i18n = () => {
10
+ return (nextConfig = {}) => {
11
+ return {
12
+ ...nextConfig,
13
+ webpack: (config, options) => {
14
+ if (!(0, fs_1.existsSync)(CONFIG_PATH))
15
+ throw new Error("Please create and configure nimpl-i18n.js");
16
+ config.resolve ||= {};
17
+ config.resolve.alias = {
18
+ ...config.resolve.alias,
19
+ "@nimpl/i18n/clientConfig": CONFIG_PATH,
20
+ };
21
+ if (typeof nextConfig.webpack === "function") {
22
+ return nextConfig.webpack(config, options);
23
+ }
24
+ return config;
25
+ },
26
+ };
27
+ };
28
+ };
29
+ exports.default = i18n;
package/i18n.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ declare const i18n: () => (nextConfig?: any) => any;
2
+ export default i18n;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nimpl/i18n",
3
- "version": "2.0.0-canary.1",
3
+ "version": "2.0.0-canary.3",
4
4
  "description": "i18n library for working with translations in server and client components",
5
5
  "exports": {
6
6
  "./ClientTranslation": {
@@ -9,6 +9,9 @@
9
9
  "./getTranslation": {
10
10
  "default": "./dist/getTranslation.js"
11
11
  },
12
+ "./i18n": {
13
+ "default": "./dist/i18n.js"
14
+ },
12
15
  "./I18nTransmitter": {
13
16
  "default": "./dist/I18nTransmitter.js"
14
17
  },
@@ -20,6 +23,9 @@
20
23
  },
21
24
  "./useTranslation": {
22
25
  "default": "./dist/useTranslation.js"
26
+ },
27
+ "./clientConfig": {
28
+ "default": "./dist/clientConfig.js"
23
29
  }
24
30
  },
25
31
  "files": [
@@ -54,6 +60,7 @@
54
60
  "@types/node": "16.11.12",
55
61
  "@types/object-path": "0.11.4",
56
62
  "@types/react": "18.2.43",
63
+ "@types/webpack": "5.28.5",
57
64
  "react": "18.2.0",
58
65
  "typescript": "5.3.2"
59
66
  },