@lingui/vite-plugin 4.0.0-next.2 → 4.0.0-next.4

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.
package/dist/index.cjs ADDED
@@ -0,0 +1,59 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const conf = require('@lingui/conf');
6
+ const api = require('@lingui/cli/api');
7
+ const path = require('path');
8
+
9
+ const fileRegex = /(\.po|\?lingui)$/;
10
+ function lingui(linguiConfig = {}) {
11
+ const config = conf.getConfig(linguiConfig);
12
+ return {
13
+ name: "vite-plugin-lingui",
14
+ config: (config2) => {
15
+ config2.optimizeDeps.exclude = config2.optimizeDeps.exclude || [];
16
+ config2.optimizeDeps.exclude.push("@lingui/macro");
17
+ },
18
+ async transform(src, id) {
19
+ if (fileRegex.test(id)) {
20
+ id = id.split("?")[0];
21
+ const catalogRelativePath = path.relative(config.rootDir, id);
22
+ const fileCatalog = api.getCatalogForFile(
23
+ catalogRelativePath,
24
+ await api.getCatalogs(config)
25
+ );
26
+ if (!fileCatalog) {
27
+ throw new Error(
28
+ `Requested resource ${catalogRelativePath} is not matched to any of your catalogs paths specified in "lingui.config".
29
+
30
+ Resource: ${id}
31
+
32
+ Your catalogs:
33
+ ${config.catalogs.map((c) => c.path).join("\n")}
34
+ Please check that catalogs.path is filled properly.
35
+ `
36
+ );
37
+ }
38
+ const { locale, catalog } = fileCatalog;
39
+ const messages = await catalog.getTranslations(locale, {
40
+ fallbackLocales: config.fallbackLocales,
41
+ sourceLocale: config.sourceLocale
42
+ });
43
+ const compiled = api.createCompiledCatalog(locale, messages, {
44
+ strict: false,
45
+ namespace: "es",
46
+ pseudoLocale: config.pseudoLocale
47
+ });
48
+ return {
49
+ code: compiled,
50
+ map: null
51
+ // provide source map if available
52
+ };
53
+ }
54
+ }
55
+ };
56
+ }
57
+
58
+ exports.default = lingui;
59
+ exports.lingui = lingui;
@@ -0,0 +1,10 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ type LinguiConfigOpts = {
4
+ cwd?: string;
5
+ configPath?: string;
6
+ skipValidation?: boolean;
7
+ };
8
+ declare function lingui(linguiConfig?: LinguiConfigOpts): Plugin;
9
+
10
+ export { lingui as default, lingui };
package/dist/index.mjs ADDED
@@ -0,0 +1,54 @@
1
+ import { getConfig } from '@lingui/conf';
2
+ import { getCatalogForFile, getCatalogs, createCompiledCatalog } from '@lingui/cli/api';
3
+ import path from 'path';
4
+
5
+ const fileRegex = /(\.po|\?lingui)$/;
6
+ function lingui(linguiConfig = {}) {
7
+ const config = getConfig(linguiConfig);
8
+ return {
9
+ name: "vite-plugin-lingui",
10
+ config: (config2) => {
11
+ config2.optimizeDeps.exclude = config2.optimizeDeps.exclude || [];
12
+ config2.optimizeDeps.exclude.push("@lingui/macro");
13
+ },
14
+ async transform(src, id) {
15
+ if (fileRegex.test(id)) {
16
+ id = id.split("?")[0];
17
+ const catalogRelativePath = path.relative(config.rootDir, id);
18
+ const fileCatalog = getCatalogForFile(
19
+ catalogRelativePath,
20
+ await getCatalogs(config)
21
+ );
22
+ if (!fileCatalog) {
23
+ throw new Error(
24
+ `Requested resource ${catalogRelativePath} is not matched to any of your catalogs paths specified in "lingui.config".
25
+
26
+ Resource: ${id}
27
+
28
+ Your catalogs:
29
+ ${config.catalogs.map((c) => c.path).join("\n")}
30
+ Please check that catalogs.path is filled properly.
31
+ `
32
+ );
33
+ }
34
+ const { locale, catalog } = fileCatalog;
35
+ const messages = await catalog.getTranslations(locale, {
36
+ fallbackLocales: config.fallbackLocales,
37
+ sourceLocale: config.sourceLocale
38
+ });
39
+ const compiled = createCompiledCatalog(locale, messages, {
40
+ strict: false,
41
+ namespace: "es",
42
+ pseudoLocale: config.pseudoLocale
43
+ });
44
+ return {
45
+ code: compiled,
46
+ map: null
47
+ // provide source map if available
48
+ };
49
+ }
50
+ }
51
+ };
52
+ }
53
+
54
+ export { lingui as default, lingui };
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@lingui/vite-plugin",
3
- "version": "4.0.0-next.2",
3
+ "version": "4.0.0-next.4",
4
4
  "description": "Vite plugin for Lingui message catalogs",
5
- "main": "./build/index.js",
6
- "types": "./build/index.d.ts",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
7
8
  "license": "MIT",
8
9
  "keywords": [
9
10
  "vite-plugin",
@@ -17,7 +18,8 @@
17
18
  "translation"
18
19
  ],
19
20
  "scripts": {
20
- "build": "rimraf ./build && tsc"
21
+ "build": "rimraf ./dist && unbuild",
22
+ "stub": "unbuild --stub"
21
23
  },
22
24
  "repository": {
23
25
  "type": "git",
@@ -32,14 +34,19 @@
32
34
  "files": [
33
35
  "LICENSE",
34
36
  "README.md",
35
- "build/"
37
+ "dist/"
36
38
  ],
37
39
  "dependencies": {
38
- "@lingui/cli": "^4.0.0-next.2",
39
- "@lingui/conf": "^4.0.0-next.2"
40
+ "@lingui/cli": "^4.0.0-next.4",
41
+ "@lingui/conf": "^4.0.0-next.4"
42
+ },
43
+ "peerDependencies": {
44
+ "vite": "3 - 4"
40
45
  },
41
46
  "devDependencies": {
47
+ "@lingui/format-json": "^4.0.0-next.4",
48
+ "unbuild": "^1.1.2",
42
49
  "vite": "4.1.4"
43
50
  },
44
- "gitHead": "556ab57e20c2ac9d384a22424c6a90c2ba0dd133"
51
+ "gitHead": "3b999e35d26e67dec7cf0591f794be782e11022c"
45
52
  }
package/build/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2017-2022 Tomáš Ehrlich, (c) 2022-2023 Crowdin.
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
package/build/index.d.ts DELETED
@@ -1,8 +0,0 @@
1
- import type { Plugin } from "vite";
2
- type LinguiConfigOpts = {
3
- cwd?: string;
4
- configPath?: string;
5
- skipValidation?: boolean;
6
- };
7
- export declare function lingui(linguiConfig?: LinguiConfigOpts): Plugin;
8
- export default lingui;
package/build/index.js DELETED
@@ -1,54 +0,0 @@
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
- exports.lingui = void 0;
7
- const conf_1 = require("@lingui/conf");
8
- const api_1 = require("@lingui/cli/api");
9
- const path_1 = __importDefault(require("path"));
10
- const fileRegex = /(\.po|\?lingui)$/;
11
- function lingui(linguiConfig = {}) {
12
- const config = (0, conf_1.getConfig)(linguiConfig);
13
- return {
14
- name: "vite-plugin-lingui",
15
- config: (config) => {
16
- // https://github.com/lingui/js-lingui/issues/1464
17
- config.optimizeDeps.exclude = config.optimizeDeps.exclude || [];
18
- config.optimizeDeps.exclude.push("@lingui/macro");
19
- },
20
- async transform(src, id) {
21
- if (fileRegex.test(id)) {
22
- id = id.split("?")[0];
23
- const catalogRelativePath = path_1.default.relative(config.rootDir, id);
24
- const fileCatalog = (0, api_1.getCatalogForFile)(catalogRelativePath, (0, api_1.getCatalogs)(config));
25
- if (!fileCatalog) {
26
- throw new Error(`Requested resource ${catalogRelativePath} is not matched to any of your catalogs paths specified in "lingui.config".
27
-
28
- Resource: ${id}
29
-
30
- Your catalogs:
31
- ${config.catalogs.map((c) => c.path).join("\n")}
32
- Please check that catalogs.path is filled properly.\n`);
33
- }
34
- const { locale, catalog } = fileCatalog;
35
- const messages = await catalog.getTranslations(locale, {
36
- fallbackLocales: config.fallbackLocales,
37
- sourceLocale: config.sourceLocale,
38
- });
39
- const compiled = (0, api_1.createCompiledCatalog)(locale, messages, {
40
- strict: false,
41
- namespace: "es",
42
- pseudoLocale: config.pseudoLocale,
43
- });
44
- return {
45
- code: compiled,
46
- map: null, // provide source map if available
47
- };
48
- }
49
- },
50
- };
51
- }
52
- exports.lingui = lingui;
53
- exports.default = lingui;
54
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,uCAAwC;AACxC,yCAIwB;AACxB,gDAAuB;AAGvB,MAAM,SAAS,GAAG,kBAAkB,CAAA;AAQpC,SAAgB,MAAM,CAAC,eAAiC,EAAE;IACxD,MAAM,MAAM,GAAG,IAAA,gBAAS,EAAC,YAAY,CAAC,CAAA;IAEtC,OAAO;QACL,IAAI,EAAE,oBAAoB;QAE1B,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE;YACjB,kDAAkD;YAClD,MAAM,CAAC,YAAY,CAAC,OAAO,GAAG,MAAM,CAAC,YAAY,CAAC,OAAO,IAAI,EAAE,CAAA;YAC/D,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;QACnD,CAAC;QAED,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE;YACrB,IAAI,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE;gBACtB,EA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