@open-xchange/vite-plugin-po2json 1.0.0-pre1 → 1.0.0-pre2

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.
Files changed (2) hide show
  1. package/dist/index.js +18 -11
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -58,23 +58,27 @@ export default function gettextPlugin(options) {
58
58
  }
59
59
  },
60
60
  resolveId(id) {
61
- if (/^gettext$/.test(id)) {
61
+ // Strip \0 prefix for matching (Rolldown convention for virtual modules)
62
+ const cleanId = id.startsWith('\0') ? id.slice(1) : id;
63
+ if (/^(virtual:)?gettext$/.test(cleanId)) {
62
64
  const meta = { gettext: { dictionary: true } };
63
- return { id: `${defaultDictionary}.js`, meta };
65
+ return { id: `\0${defaultDictionary}.js`, meta };
64
66
  }
65
- const gettextModuleMatch = id.match(/gettext\?.*dictionary=([^&]+)/);
67
+ const gettextModuleMatch = cleanId.match(/(virtual:)?gettext\?.*dictionary=([^&]+)/);
66
68
  if (gettextModuleMatch) {
67
- dictionaries.add(gettextModuleMatch[1].replace(/\.js$/, ''));
69
+ dictionaries.add(gettextModuleMatch[2].replace(/\.js$/, ''));
68
70
  const meta = { gettext: { dictionary: true } };
69
- return { id: gettextModuleMatch[1].replace(/(\.js)?$/, '.js'), meta };
71
+ return { id: `\0${gettextModuleMatch[2].replace(/(\.js)?$/, '.js')}`, meta };
70
72
  }
71
- if (dictionaries.has(id.replace(/\.js$/, ''))) {
73
+ if (dictionaries.has(cleanId.replace(/\.js$/, ''))) {
72
74
  const meta = { gettext: { dictionary: true } };
73
- return { id, meta };
75
+ return { id: id.startsWith('\0') ? id : `\0${id}`, meta };
74
76
  }
75
- const match = id.match(/(.*)\.([a-zA-Z]{2}_[a-zA-Z]{2})(\.js)?$/);
77
+ const match = cleanId.match(/(.*)\.([a-zA-Z]{2}_[a-zA-Z]{2})(\.js)?$/);
76
78
  const [, namespace, language] = match || [];
77
- return (namespace && language) ? id : null;
79
+ if (namespace && language)
80
+ return id.startsWith('\0') ? id : `\0${id}`;
81
+ return null;
78
82
  },
79
83
  transform: {
80
84
  order: 'pre',
@@ -83,7 +87,9 @@ export default function gettextPlugin(options) {
83
87
  }
84
88
  },
85
89
  async load(id) {
86
- const dictionary = id.replace(/\\/g, '/').replace(/^\.?\//, '').replace(/\.js$/, '');
90
+ if (!id.startsWith('\0'))
91
+ return;
92
+ const dictionary = id.slice(1).replace(/\\/g, '/').replace(/^\.?\//, '').replace(/\.js$/, '');
87
93
  if (dictionaries.has(dictionary)) {
88
94
  const poDir = path.dirname(poFiles);
89
95
  const languages = (await readdir(poDir)).map(f => (f.match(/([^/]+).po$/) || [])[1]).filter(a => Boolean(a));
@@ -94,7 +100,8 @@ export default function gettextPlugin(options) {
94
100
  .replaceAll(/['"]{{languages}}['"]/g, languages.map(lang => `'${lang}'`).join(', '));
95
101
  return { meta: { gettext: { dictionary: true } }, code };
96
102
  }
97
- const match = id.match(/\.?\/?(.*)\.([a-zA-Z]{2}_[a-zA-Z]{2})(\.js)?$/);
103
+ const cleanId = id.slice(1);
104
+ const match = cleanId.match(/\.?\/?(.*)\.([a-zA-Z]{2}_[a-zA-Z]{2})(\.js)?$/);
98
105
  const [, namespace, language] = match || [];
99
106
  if (!namespace || !language || !dictionaries.has(namespace))
100
107
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-xchange/vite-plugin-po2json",
3
- "version": "1.0.0-pre1",
3
+ "version": "1.0.0-pre2",
4
4
  "description": "A Vite plugin to load po files into our gettext based dictionary implementation.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",