@open-xchange/rolldown-plugin-i18next-gettext 0.0.1 → 1.0.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## `1.0.1` – 2026-Apr-14
4
+
5
+ - fixed: removed debug output
6
+
7
+ ## `1.0.0` – 2026-Apr-13
8
+
9
+ - added: hook filters for improved performance
10
+
3
11
  ## `0.0.1` – 2026-Apr-10
4
12
 
5
13
  - initial release
package/README.md CHANGED
@@ -14,7 +14,6 @@ Add the plugin to your rolldown configuration (or compatible configurations like
14
14
 
15
15
  ```ts
16
16
  // rolldown.config.ts
17
-
18
17
  import { defineConfig } from 'rolldown'
19
18
  import i18nextPlugin from '@open-xchange/rolldown-plugin-i18next-gettext'
20
19
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;AAaA;UAAiB,mCAAA;;;;;;;;EASf,OAAA;EA8Ba;AASf;;;EAjCE,QAAA;IAiCuB;AAMzB;;;;;IA/BI,QAAA;IA6DgD;;;;;;;;IAnDhD,UAAA;;;;;IAMA,WAAA;EAAA;AAAA;;;;cASS,YAAA;;;;;cAMA,iBAAA;;;;;;;;;;iBA8BW,4BAAA,CAA6B,OAAA,EAAS,mCAAA,GAAsC,MAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;AAaA;UAAiB,mCAAA;;;;;;;;EASf,OAAA;EA8Ba;AASf;;;EAjCE,QAAA;IAiCuB;AAMzB;;;;;IA/BI,QAAA;IA4CgD;;;;;;;;IAlChD,UAAA;;;;;IAMA,WAAA;EAAA;AAAA;;;;cASS,YAAA;;;;;cAMA,iBAAA;;;;;;;;;;iBAaW,4BAAA,CAA6B,OAAA,EAAS,mCAAA,GAAsC,MAAA"}
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as path from "node:path";
2
- import pm from "picomatch";
2
+ import { createJsonModule, exactRegex, wrapArray } from "@open-xchange/rolldown-utils";
3
3
  import { glob } from "tinyglobby";
4
4
  import { parsePoFile, parseSourceFiles } from "@open-xchange/i18next-po-parser";
5
5
  //#region src/index.ts
@@ -13,22 +13,6 @@ const PROJECT_NAME = "@open-xchange/rolldown-plugin-i18next-gettext";
13
13
  */
14
14
  const VIRTUAL_MODULE_ID = "virtual:i18next-po-catalogs";
15
15
  /**
16
- * Creates the source code of a module with a default export with the passed
17
- * stringified JSON data.
18
- *
19
- * @param json
20
- * The JSON data to be exported from the generated source file.
21
- *
22
- * @returns
23
- * The generated source file.
24
- */
25
- function createModule(json) {
26
- return {
27
- code: `export default ${JSON.stringify(json)}`,
28
- map: { mappings: "" }
29
- };
30
- }
31
- /**
32
16
  * Rolldown plugin for using i18next with gettext `.po` files under the hood.
33
17
  *
34
18
  * @param options
@@ -41,21 +25,23 @@ function rolldownPluginI18nextGettext(options) {
41
25
  const RESOLVED_MODULE_ID = `\0${VIRTUAL_MODULE_ID}`;
42
26
  return {
43
27
  name: PROJECT_NAME,
44
- resolveId(id) {
45
- return id === "virtual:i18next-po-catalogs" ? RESOLVED_MODULE_ID : null;
28
+ resolveId: {
29
+ filter: { id: exactRegex(VIRTUAL_MODULE_ID) },
30
+ handler: () => RESOLVED_MODULE_ID
46
31
  },
47
- async load(id) {
48
- if (id === RESOLVED_MODULE_ID) {
49
- const map = {};
50
- for (const entry of await glob(options.poFiles)) {
51
- const basename = path.parse(entry).name;
52
- map[basename] = await parsePoFile(entry);
32
+ load: {
33
+ filter: { id: [exactRegex(RESOLVED_MODULE_ID), ...wrapArray(options.poFiles)] },
34
+ async handler(id) {
35
+ if (id === RESOLVED_MODULE_ID) {
36
+ const map = {};
37
+ for (const entry of await glob(options.poFiles)) {
38
+ const basename = path.parse(entry).name;
39
+ map[basename] = await parsePoFile(entry);
40
+ }
41
+ return createJsonModule(map);
53
42
  }
54
- return createModule(map);
43
+ return createJsonModule(await parsePoFile(id));
55
44
  }
56
- const relPath = path.relative(process.cwd(), id).replaceAll(path.sep, path.posix.sep);
57
- if (!pm.isMatch(relPath, options.poFiles)) return;
58
- return createModule(await parsePoFile(id));
59
45
  },
60
46
  async generateBundle() {
61
47
  if (!options.potFiles) return;
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["\nimport * as path from 'node:path'\n\nimport type { LoadResult, Plugin } from 'rolldown'\nimport pm from 'picomatch'\nimport { glob } from 'tinyglobby'\nimport { parsePoFile, parseSourceFiles } from '@open-xchange/i18next-po-parser'\n\n// types ======================================================================\n\n/**\n * Configuration options for the plugin '@open-xchange/rolldown-plugin-i18next-gettext'.\n */\nexport interface RolldownPluginI18nextGettextOptions {\n\n /**\n * Glob pattern(s) for all PO files containing the translations. Matching PO\n * files will be converted to i18next translation catalogs when imported in\n * source code directly, and will be included in the virtual module providing\n * a dictionary of all translation catalogs, mapped by the base names of the\n * PO files.\n */\n poFiles: string | readonly string[]\n\n /**\n * Configuration for the source code scanner and POT file generator. If\n * omitted, no POT files will be generated.\n */\n potFiles?: {\n\n /**\n * Glob pattern(s) for all source files to be scanned for UI strings.\n *\n * @default\n * 'src/**\\/*.{js,jsx,ts,tsx}'\n */\n srcFiles?: string | readonly string[]\n\n /**\n * Path to and filename of the generated POT files, relative to the build\n * output directory. Should contain the placeholder `[NAMESPACE]` if the\n * project contains translation strings in different i18next namespaces.\n *\n * @default\n * '[NAMESPACE].pot'\n */\n outputPath?: string\n\n /**\n * The project name to be inserted into the POT files under the key\n * 'Project-Id-Version'. May contain the placeholder `[NAMESPACE]`.\n */\n projectName: string\n }\n}\n\n// constants ==================================================================\n\n/**\n * Identifier of this plugin.\n */\nexport const PROJECT_NAME = '@open-xchange/rolldown-plugin-i18next-gettext'\n\n/**\n * Identifier of the virtual module providing all translation catalogs in a\n * single object.\n */\nexport const VIRTUAL_MODULE_ID = 'virtual:i18next-po-catalogs'\n\n// functions ==================================================================\n\n/**\n * Creates the source code of a module with a default export with the passed\n * stringified JSON data.\n *\n * @param json\n * The JSON data to be exported from the generated source file.\n *\n * @returns\n * The generated source file.\n */\nfunction createModule(json: unknown): LoadResult {\n const code = `export default ${JSON.stringify(json)}`\n return { code, map: { mappings: '' } }\n}\n\n// plugin =====================================================================\n\n/**\n * Rolldown plugin for using i18next with gettext `.po` files under the hood.\n *\n * @param options\n * Plugin configuration.\n *\n * @returns\n * The rolldown plugin object.\n */\nexport default function rolldownPluginI18nextGettext(options: RolldownPluginI18nextGettextOptions): Plugin {\n\n const RESOLVED_MODULE_ID = `\\0${VIRTUAL_MODULE_ID}`\n\n return {\n name: PROJECT_NAME,\n\n // recognize virtual module identifier\n resolveId(id) {\n return (id === VIRTUAL_MODULE_ID) ? RESOLVED_MODULE_ID : null\n },\n\n // convert PO files to i18next JSON v4\n async load(id) {\n\n // virtual module: build single dictionary with all languages from PO files\n if (id === RESOLVED_MODULE_ID) {\n const map = {} as Record<string, unknown>\n for (const entry of await glob(options.poFiles)) {\n const basename = path.parse(entry).name\n map[basename] = await parsePoFile(entry)\n }\n return createModule(map)\n }\n\n // try to find a matching PO file\n const relPath = path.relative(process.cwd(), id).replaceAll(path.sep, path.posix.sep)\n if (!pm.isMatch(relPath, options.poFiles as pm.Glob)) { return }\n\n // read the PO file and convert it to i18next JSON\n return createModule(await parsePoFile(id))\n },\n\n // parse source files and create POT files per namespace\n async generateBundle() {\n\n // early exit if no POT files will be generated\n if (!options.potFiles) return\n const { srcFiles = 'src/**/*.{js,jsx,ts,tsx}', outputPath = '[NAMESPACE].pot', projectName } = options.potFiles\n\n // parse all source files and extract translations\n const catalogs = await parseSourceFiles({ files: srcFiles as pm.Glob, project: projectName })\n\n // warn when writing multiple POT files to same file location\n if ((catalogs.size > 1) && !outputPath.includes('[NAMESPACE]')) {\n this.error('multiple POT files written to same file location (missing placeholder `[NAMESPACE]` in option potFile)')\n }\n\n // add all POT files as assets to the bundle\n for (const [namespace, source] of catalogs) {\n const fileName = outputPath.replaceAll('[NAMESPACE]', namespace)\n this.emitFile({ type: 'asset', fileName, source })\n }\n },\n }\n}\n"],"mappings":";;;;;;;;AA6DA,MAAa,eAAe;;;;;AAM5B,MAAa,oBAAoB;;;;;;;;;;;AAcjC,SAAS,aAAa,MAA2B;AAE/C,QAAO;EAAE,MADI,kBAAkB,KAAK,UAAU,KAAK;EACpC,KAAK,EAAE,UAAU,IAAI;EAAE;;;;;;;;;;;AAcxC,SAAwB,6BAA6B,SAAsD;CAEzG,MAAM,qBAAqB,KAAK;AAEhC,QAAO;EACL,MAAM;EAGN,UAAU,IAAI;AACZ,UAAQ,OAAA,gCAA4B,qBAAqB;;EAI3D,MAAM,KAAK,IAAI;AAGb,OAAI,OAAO,oBAAoB;IAC7B,MAAM,MAAM,EAAE;AACd,SAAK,MAAM,SAAS,MAAM,KAAK,QAAQ,QAAQ,EAAE;KAC/C,MAAM,WAAW,KAAK,MAAM,MAAM,CAAC;AACnC,SAAI,YAAY,MAAM,YAAY,MAAM;;AAE1C,WAAO,aAAa,IAAI;;GAI1B,MAAM,UAAU,KAAK,SAAS,QAAQ,KAAK,EAAE,GAAG,CAAC,WAAW,KAAK,KAAK,KAAK,MAAM,IAAI;AACrF,OAAI,CAAC,GAAG,QAAQ,SAAS,QAAQ,QAAmB,CAAI;AAGxD,UAAO,aAAa,MAAM,YAAY,GAAG,CAAC;;EAI5C,MAAM,iBAAiB;AAGrB,OAAI,CAAC,QAAQ,SAAU;GACvB,MAAM,EAAE,WAAW,4BAA4B,aAAa,mBAAmB,gBAAgB,QAAQ;GAGvG,MAAM,WAAW,MAAM,iBAAiB;IAAE,OAAO;IAAqB,SAAS;IAAa,CAAC;AAG7F,OAAK,SAAS,OAAO,KAAM,CAAC,WAAW,SAAS,cAAc,CAC5D,MAAK,MAAM,yGAAyG;AAItH,QAAK,MAAM,CAAC,WAAW,WAAW,UAAU;IAC1C,MAAM,WAAW,WAAW,WAAW,eAAe,UAAU;AAChE,SAAK,SAAS;KAAE,MAAM;KAAS;KAAU;KAAQ,CAAC;;;EAGvD"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["\nimport * as path from 'node:path'\n\nimport type { Plugin } from 'rolldown'\nimport { exactRegex, wrapArray, createJsonModule } from '@open-xchange/rolldown-utils'\nimport { glob } from 'tinyglobby'\nimport { parsePoFile, parseSourceFiles } from '@open-xchange/i18next-po-parser'\n\n// types ======================================================================\n\n/**\n * Configuration options for the plugin '@open-xchange/rolldown-plugin-i18next-gettext'.\n */\nexport interface RolldownPluginI18nextGettextOptions {\n\n /**\n * Glob pattern(s) for all PO files containing the translations. Matching PO\n * files will be converted to i18next translation catalogs when imported in\n * source code directly, and will be included in the virtual module providing\n * a dictionary of all translation catalogs, mapped by the base names of the\n * PO files.\n */\n poFiles: string | readonly string[]\n\n /**\n * Configuration for the source code scanner and POT file generator. If\n * omitted, no POT files will be generated.\n */\n potFiles?: {\n\n /**\n * Glob pattern(s) for all source files to be scanned for UI strings.\n *\n * @default\n * 'src/**\\/*.{js,jsx,ts,tsx}'\n */\n srcFiles?: string | readonly string[]\n\n /**\n * Path to and filename of the generated POT files, relative to the build\n * output directory. Should contain the placeholder `[NAMESPACE]` if the\n * project contains translation strings in different i18next namespaces.\n *\n * @default\n * '[NAMESPACE].pot'\n */\n outputPath?: string\n\n /**\n * The project name to be inserted into the POT files under the key\n * 'Project-Id-Version'. May contain the placeholder `[NAMESPACE]`.\n */\n projectName: string\n }\n}\n\n// constants ==================================================================\n\n/**\n * Identifier of this plugin.\n */\nexport const PROJECT_NAME = '@open-xchange/rolldown-plugin-i18next-gettext'\n\n/**\n * Identifier of the virtual module providing all translation catalogs in a\n * single object.\n */\nexport const VIRTUAL_MODULE_ID = 'virtual:i18next-po-catalogs'\n\n// plugin =====================================================================\n\n/**\n * Rolldown plugin for using i18next with gettext `.po` files under the hood.\n *\n * @param options\n * Plugin configuration.\n *\n * @returns\n * The rolldown plugin object.\n */\nexport default function rolldownPluginI18nextGettext(options: RolldownPluginI18nextGettextOptions): Plugin {\n\n const RESOLVED_MODULE_ID = `\\0${VIRTUAL_MODULE_ID}`\n\n return {\n name: PROJECT_NAME,\n\n // recognize virtual module identifier\n resolveId: {\n filter: { id: exactRegex(VIRTUAL_MODULE_ID) },\n handler: () => RESOLVED_MODULE_ID,\n },\n\n // convert PO files to i18next JSON v4\n load: {\n filter: {\n id: [\n exactRegex(RESOLVED_MODULE_ID),\n ...wrapArray(options.poFiles),\n ],\n },\n async handler(id) {\n\n // virtual module: build single dictionary with all languages from PO files\n if (id === RESOLVED_MODULE_ID) {\n const map = {} as Record<string, Record<string, string>>\n for (const entry of await glob(options.poFiles)) {\n const basename = path.parse(entry).name\n map[basename] = await parsePoFile(entry)\n }\n return createJsonModule(map)\n }\n\n // read the PO file and convert it to i18next JSON\n return createJsonModule(await parsePoFile(id))\n },\n },\n\n // parse source files and create POT files per namespace\n async generateBundle() {\n\n // early exit if no POT files will be generated\n if (!options.potFiles) return\n const { srcFiles = 'src/**/*.{js,jsx,ts,tsx}', outputPath = '[NAMESPACE].pot', projectName } = options.potFiles\n\n // parse all source files and extract translations\n const catalogs = await parseSourceFiles({ files: srcFiles, project: projectName })\n\n // warn when writing multiple POT files to same file location\n if ((catalogs.size > 1) && !outputPath.includes('[NAMESPACE]')) {\n this.error('multiple POT files written to same file location (missing placeholder `[NAMESPACE]` in option potFile)')\n }\n\n // add all POT files as assets to the bundle\n for (const [namespace, source] of catalogs) {\n const fileName = outputPath.replaceAll('[NAMESPACE]', namespace)\n this.emitFile({ type: 'asset', fileName, source })\n }\n },\n }\n}\n"],"mappings":";;;;;;;;AA6DA,MAAa,eAAe;;;;;AAM5B,MAAa,oBAAoB;;;;;;;;;;AAajC,SAAwB,6BAA6B,SAAsD;CAEzG,MAAM,qBAAqB,KAAK;AAEhC,QAAO;EACL,MAAM;EAGN,WAAW;GACT,QAAQ,EAAE,IAAI,WAAW,kBAAkB,EAAE;GAC7C,eAAe;GAChB;EAGD,MAAM;GACJ,QAAQ,EACN,IAAI,CACF,WAAW,mBAAmB,EAC9B,GAAG,UAAU,QAAQ,QAAQ,CAC9B,EACF;GACD,MAAM,QAAQ,IAAI;AAGhB,QAAI,OAAO,oBAAoB;KAC7B,MAAM,MAAM,EAAE;AACd,UAAK,MAAM,SAAS,MAAM,KAAK,QAAQ,QAAQ,EAAE;MAC/C,MAAM,WAAW,KAAK,MAAM,MAAM,CAAC;AACnC,UAAI,YAAY,MAAM,YAAY,MAAM;;AAE1C,YAAO,iBAAiB,IAAI;;AAI9B,WAAO,iBAAiB,MAAM,YAAY,GAAG,CAAC;;GAEjD;EAGD,MAAM,iBAAiB;AAGrB,OAAI,CAAC,QAAQ,SAAU;GACvB,MAAM,EAAE,WAAW,4BAA4B,aAAa,mBAAmB,gBAAgB,QAAQ;GAGvG,MAAM,WAAW,MAAM,iBAAiB;IAAE,OAAO;IAAU,SAAS;IAAa,CAAC;AAGlF,OAAK,SAAS,OAAO,KAAM,CAAC,WAAW,SAAS,cAAc,CAC5D,MAAK,MAAM,yGAAyG;AAItH,QAAK,MAAM,CAAC,WAAW,WAAW,UAAU;IAC1C,MAAM,WAAW,WAAW,WAAW,eAAe,UAAU;AAChE,SAAK,SAAS;KAAE,MAAM;KAAS;KAAU;KAAQ,CAAC;;;EAGvD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-xchange/rolldown-plugin-i18next-gettext",
3
- "version": "0.0.1",
3
+ "version": "1.0.1",
4
4
  "description": "Rolldown integration of i18next using gettext",
5
5
  "repository": {
6
6
  "type": "git",
@@ -25,20 +25,19 @@
25
25
  ],
26
26
  "dependencies": {
27
27
  "@open-xchange/i18next-po-parser": "^1.4.0",
28
- "picomatch": "^4.0.4",
29
- "tinyglobby": "^0.2.16"
28
+ "tinyglobby": "^0.2.16",
29
+ "@open-xchange/rolldown-utils": "^1.0.0"
30
30
  },
31
31
  "devDependencies": {
32
- "@types/picomatch": "^4.0.3",
33
32
  "@vitest/coverage-v8": "^4.1.3",
34
33
  "i18next": "^26.0.4",
35
- "rolldown": "1.0.0-rc.15",
34
+ "rolldown": "^1.0.0-rc.15",
36
35
  "tsdown": "^0.21.7",
37
36
  "vitest": "^4.1.3",
38
- "@open-xchange/linter-presets": "^1.22.0",
39
- "@open-xchange/vitest-plugin-extended": "^1.6.0",
37
+ "@open-xchange/vitest-plugin-utils": "^0.0.3",
40
38
  "@open-xchange/tsconfig": "^0.0.3",
41
- "@open-xchange/vitest-plugin-utils": "^0.0.3"
39
+ "@open-xchange/linter-presets": "^1.22.0",
40
+ "@open-xchange/vitest-plugin-extended": "^1.6.0"
42
41
  },
43
42
  "peerDependencies": {
44
43
  "rolldown": "*"