@open-xchange/rolldown-plugin-i18next-gettext 1.0.0 → 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,9 @@
1
1
  # Changelog
2
2
 
3
+ ## `1.0.1` – 2026-Apr-14
4
+
5
+ - fixed: removed debug output
6
+
3
7
  ## `1.0.0` – 2026-Apr-13
4
8
 
5
9
  - added: hook filters for improved performance
package/dist/index.mjs CHANGED
@@ -32,7 +32,6 @@ function rolldownPluginI18nextGettext(options) {
32
32
  load: {
33
33
  filter: { id: [exactRegex(RESOLVED_MODULE_ID), ...wrapArray(options.poFiles)] },
34
34
  async handler(id) {
35
- console.log(id);
36
35
  if (id === RESOLVED_MODULE_ID) {
37
36
  const map = {};
38
37
  for (const entry of await glob(options.poFiles)) {
@@ -1 +1 @@
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 console.log(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;AAChB,YAAQ,IAAI,GAAG;AAGf,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"}
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": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Rolldown integration of i18next using gettext",
5
5
  "repository": {
6
6
  "type": "git",
@@ -34,10 +34,10 @@
34
34
  "rolldown": "^1.0.0-rc.15",
35
35
  "tsdown": "^0.21.7",
36
36
  "vitest": "^4.1.3",
37
- "@open-xchange/linter-presets": "^1.22.0",
37
+ "@open-xchange/vitest-plugin-utils": "^0.0.3",
38
38
  "@open-xchange/tsconfig": "^0.0.3",
39
- "@open-xchange/vitest-plugin-extended": "^1.6.0",
40
- "@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"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "rolldown": "*"