@lingui/loader 4.0.0-next.0 → 4.0.0-next.2

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.
@@ -3,59 +3,23 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = _default;
6
+ exports.default = void 0;
7
7
  var _path = _interopRequireDefault(require("path"));
8
8
  var _conf = require("@lingui/conf");
9
9
  var _api = require("@lingui/cli/api");
10
- var _loaderUtils = _interopRequireDefault(require("loader-utils"));
11
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
- // Check if webpack 5
13
- const isWebpack5 = parseInt(require("webpack").version) === 5;
14
-
15
- // Check if JavascriptParser and JavascriptGenerator exists -> Webpack 4
16
- let JavascriptParser;
17
- let JavascriptGenerator;
18
- try {
19
- JavascriptParser = require("webpack/lib/Parser");
20
- JavascriptGenerator = require("webpack/lib/JavascriptGenerator");
21
- } catch (error) {
22
- if (error.code !== "MODULE_NOT_FOUND") {
23
- throw error;
24
- }
25
- }
26
- const requiredType = "javascript/auto";
27
- function _default(source) {
28
- const options = _loaderUtils.default.getOptions(this) || {};
29
- if (!isWebpack5 && JavascriptParser && JavascriptGenerator) {
30
- // Webpack 4 uses json-loader automatically, which breaks this loader because it
31
- // doesn't return JSON, but JS module. This is a temporary workaround before
32
- // official API is added (https://github.com/webpack/webpack/issues/7057#issuecomment-381883220)
33
- // See https://github.com/webpack/webpack/issues/7057
34
- this._module.type = requiredType;
35
- this._module.parser = new JavascriptParser();
36
- this._module.generator = new JavascriptGenerator();
37
- }
11
+ const loader = async function (source) {
12
+ const options = this.getOptions() || {};
38
13
  const config = (0, _conf.getConfig)({
39
14
  configPath: options.config,
40
15
  cwd: _path.default.dirname(this.resourcePath)
41
16
  });
42
- const EMPTY_EXT = /\.[0-9a-z]+$/.test(this.resourcePath);
43
- const JS_EXT = /\.js+$/.test(this.resourcePath);
44
17
  const catalogRelativePath = _path.default.relative(config.rootDir, this.resourcePath);
45
- if (!EMPTY_EXT || JS_EXT) {
46
- const formats = {
47
- minimal: ".json",
48
- po: ".po",
49
- lingui: ".json"
50
- };
51
- // we replace the .js, because webpack appends automatically the .js on imports without extension
52
- throw new Error(`File extension is mandatory, for ex: import("@lingui/loader!./${catalogRelativePath.replace(".js", formats[config.format])}")`);
53
- }
54
18
  const {
55
19
  locale,
56
20
  catalog
57
21
  } = (0, _api.getCatalogForFile)(catalogRelativePath, (0, _api.getCatalogs)(config));
58
- const messages = catalog.getTranslations(locale, {
22
+ const messages = await catalog.getTranslations(locale, {
59
23
  fallbackLocales: config.fallbackLocales,
60
24
  sourceLocale: config.sourceLocale
61
25
  });
@@ -68,7 +32,9 @@ function _default(source) {
68
32
  const strict = process.env.NODE_ENV !== "production";
69
33
  return (0, _api.createCompiledCatalog)(locale, messages, {
70
34
  strict,
71
- namespace: config.compileNamespace,
35
+ namespace: this._module.type === "json" ? "json" : "es",
72
36
  pseudoLocale: config.pseudoLocale
73
37
  });
74
- }
38
+ };
39
+ var _default = loader;
40
+ exports.default = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingui/loader",
3
- "version": "4.0.0-next.0",
3
+ "version": "4.0.0-next.2",
4
4
  "description": "webpack loader for lingui message catalogs",
5
5
  "types": "./build/index.d.ts",
6
6
  "main": "./build/index.js",
@@ -36,16 +36,14 @@
36
36
  ],
37
37
  "dependencies": {
38
38
  "@babel/runtime": "^7.20.13",
39
- "@lingui/cli": "^4.0.0-next.0",
40
- "@lingui/conf": "^4.0.0-next.0",
41
- "loader-utils": "^2.0.0"
39
+ "@lingui/cli": "^4.0.0-next.2",
40
+ "@lingui/conf": "^4.0.0-next.2"
42
41
  },
43
42
  "devDependencies": {
44
- "memory-fs": "^0.5.0",
45
- "webpack": "^4.44.2"
43
+ "webpack": "^5.76.1"
46
44
  },
47
45
  "peerDependencies": {
48
- "webpack": "^4.0.0 || ^5.0.0"
46
+ "webpack": "^5.0.0"
49
47
  },
50
- "gitHead": "637f5cf6beda9d4ebce4e15cd9fdaa23e404b660"
48
+ "gitHead": "556ab57e20c2ac9d384a22424c6a90c2ba0dd133"
51
49
  }