i18next-cli 1.39.2 → 1.39.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/cjs/cli.js +1 -1
- package/dist/cjs/rename-key.js +34 -0
- package/dist/esm/cli.js +1 -1
- package/dist/esm/rename-key.js +34 -0
- package/package.json +1 -1
package/dist/cjs/cli.js
CHANGED
|
@@ -28,7 +28,7 @@ const program = new commander.Command();
|
|
|
28
28
|
program
|
|
29
29
|
.name('i18next-cli')
|
|
30
30
|
.description('A unified, high-performance i18next CLI.')
|
|
31
|
-
.version('1.39.
|
|
31
|
+
.version('1.39.4'); // This string is replaced with the actual version at build time by rollup
|
|
32
32
|
// new: global config override option
|
|
33
33
|
program.option('-c, --config <path>', 'Path to i18next-cli config file (overrides detection)');
|
|
34
34
|
program
|
package/dist/cjs/rename-key.js
CHANGED
|
@@ -230,12 +230,46 @@ function replaceKeyWithRegex(code, oldParts, newParts, config) {
|
|
|
230
230
|
changes++;
|
|
231
231
|
return match.replace(new RegExp(`(['"\`])${escapeRegex(oldParts.key)}\\1\\s*\\)`), `${quote}${newParts.key}${quote}, { ns: '${newParts.namespace}' })`);
|
|
232
232
|
}
|
|
233
|
+
else if (oldParts.namespace && newParts.namespace &&
|
|
234
|
+
oldParts.namespace !== newParts.namespace &&
|
|
235
|
+
config.extract.defaultNS === newParts.namespace) {
|
|
236
|
+
// If moving from a namespaced key to defaultNS, update t('key', { ns: 'oldNs' }) to t('key')
|
|
237
|
+
// Remove the ns option if it matches the defaultNS
|
|
238
|
+
// This is handled below in the ns option replacement
|
|
239
|
+
// But also handle t('key', { ns: 'defaultNS' }) -> t('key')
|
|
240
|
+
// See below for explicit ns option removal
|
|
241
|
+
// No action here, handled below
|
|
242
|
+
return match;
|
|
243
|
+
}
|
|
233
244
|
else {
|
|
234
245
|
changes++;
|
|
235
246
|
const replacementKey = newParts.key;
|
|
236
247
|
return match.replace(new RegExp(escapeRegex(oldParts.key)), replacementKey);
|
|
237
248
|
}
|
|
238
249
|
});
|
|
250
|
+
// Remove ns option if moving to defaultNS
|
|
251
|
+
if (oldParts.namespace && newParts.namespace &&
|
|
252
|
+
oldParts.namespace !== newParts.namespace &&
|
|
253
|
+
config.extract.defaultNS === newParts.namespace) {
|
|
254
|
+
// t('key', { ns: 'oldNs' }) -> t('key')
|
|
255
|
+
const nsRegexToDefault = new RegExp(`${prefix}\\s*\\(\\s*(['"\`])${escapeRegex(oldParts.key)}\\1\\s*,\\s*\\{([^}]*)\\bns\\s*:\\s*(['"\`])${escapeRegex(oldParts.namespace)}\\3([^}]*)\\}\\s*\\)`, 'g');
|
|
256
|
+
newCode = newCode.replace(nsRegexToDefault, (match, keyQ, beforeNs, nsQ, afterNs) => {
|
|
257
|
+
changes++;
|
|
258
|
+
// Build remaining object props (everything except the ns property)
|
|
259
|
+
const obj = (beforeNs + afterNs).replace(/,?\s*$/, '').replace(/^\s*,?/, '').trim();
|
|
260
|
+
// Start by replacing the key string itself, preserving the original quote style
|
|
261
|
+
let updated = match.replace(new RegExp(`(['"\`])${escapeRegex(oldParts.key)}\\1`), `${keyQ}${newParts.key}${keyQ}`);
|
|
262
|
+
if (obj) {
|
|
263
|
+
// If other properties remain, replace the whole object content with the cleaned props
|
|
264
|
+
updated = updated.replace(/\{\s*([^}]*)\s*\}/, `{${obj}}`);
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
// No other props — remove the whole options object (", { ... }") leaving "fn('key')"
|
|
268
|
+
updated = updated.replace(/\s*,\s*\{[^}]*\}\s*\)/, ')');
|
|
269
|
+
}
|
|
270
|
+
return updated;
|
|
271
|
+
});
|
|
272
|
+
}
|
|
239
273
|
// Handle ns option in options object: fn('key', { ns: 'oldNs', ... })
|
|
240
274
|
if (oldParts.namespace && newParts.namespace && oldParts.namespace !== newParts.namespace) {
|
|
241
275
|
// We want to change only when key matches and ns value equals oldParts.namespace
|
package/dist/esm/cli.js
CHANGED
|
@@ -26,7 +26,7 @@ const program = new Command();
|
|
|
26
26
|
program
|
|
27
27
|
.name('i18next-cli')
|
|
28
28
|
.description('A unified, high-performance i18next CLI.')
|
|
29
|
-
.version('1.39.
|
|
29
|
+
.version('1.39.4'); // This string is replaced with the actual version at build time by rollup
|
|
30
30
|
// new: global config override option
|
|
31
31
|
program.option('-c, --config <path>', 'Path to i18next-cli config file (overrides detection)');
|
|
32
32
|
program
|
package/dist/esm/rename-key.js
CHANGED
|
@@ -228,12 +228,46 @@ function replaceKeyWithRegex(code, oldParts, newParts, config) {
|
|
|
228
228
|
changes++;
|
|
229
229
|
return match.replace(new RegExp(`(['"\`])${escapeRegex(oldParts.key)}\\1\\s*\\)`), `${quote}${newParts.key}${quote}, { ns: '${newParts.namespace}' })`);
|
|
230
230
|
}
|
|
231
|
+
else if (oldParts.namespace && newParts.namespace &&
|
|
232
|
+
oldParts.namespace !== newParts.namespace &&
|
|
233
|
+
config.extract.defaultNS === newParts.namespace) {
|
|
234
|
+
// If moving from a namespaced key to defaultNS, update t('key', { ns: 'oldNs' }) to t('key')
|
|
235
|
+
// Remove the ns option if it matches the defaultNS
|
|
236
|
+
// This is handled below in the ns option replacement
|
|
237
|
+
// But also handle t('key', { ns: 'defaultNS' }) -> t('key')
|
|
238
|
+
// See below for explicit ns option removal
|
|
239
|
+
// No action here, handled below
|
|
240
|
+
return match;
|
|
241
|
+
}
|
|
231
242
|
else {
|
|
232
243
|
changes++;
|
|
233
244
|
const replacementKey = newParts.key;
|
|
234
245
|
return match.replace(new RegExp(escapeRegex(oldParts.key)), replacementKey);
|
|
235
246
|
}
|
|
236
247
|
});
|
|
248
|
+
// Remove ns option if moving to defaultNS
|
|
249
|
+
if (oldParts.namespace && newParts.namespace &&
|
|
250
|
+
oldParts.namespace !== newParts.namespace &&
|
|
251
|
+
config.extract.defaultNS === newParts.namespace) {
|
|
252
|
+
// t('key', { ns: 'oldNs' }) -> t('key')
|
|
253
|
+
const nsRegexToDefault = new RegExp(`${prefix}\\s*\\(\\s*(['"\`])${escapeRegex(oldParts.key)}\\1\\s*,\\s*\\{([^}]*)\\bns\\s*:\\s*(['"\`])${escapeRegex(oldParts.namespace)}\\3([^}]*)\\}\\s*\\)`, 'g');
|
|
254
|
+
newCode = newCode.replace(nsRegexToDefault, (match, keyQ, beforeNs, nsQ, afterNs) => {
|
|
255
|
+
changes++;
|
|
256
|
+
// Build remaining object props (everything except the ns property)
|
|
257
|
+
const obj = (beforeNs + afterNs).replace(/,?\s*$/, '').replace(/^\s*,?/, '').trim();
|
|
258
|
+
// Start by replacing the key string itself, preserving the original quote style
|
|
259
|
+
let updated = match.replace(new RegExp(`(['"\`])${escapeRegex(oldParts.key)}\\1`), `${keyQ}${newParts.key}${keyQ}`);
|
|
260
|
+
if (obj) {
|
|
261
|
+
// If other properties remain, replace the whole object content with the cleaned props
|
|
262
|
+
updated = updated.replace(/\{\s*([^}]*)\s*\}/, `{${obj}}`);
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
// No other props — remove the whole options object (", { ... }") leaving "fn('key')"
|
|
266
|
+
updated = updated.replace(/\s*,\s*\{[^}]*\}\s*\)/, ')');
|
|
267
|
+
}
|
|
268
|
+
return updated;
|
|
269
|
+
});
|
|
270
|
+
}
|
|
237
271
|
// Handle ns option in options object: fn('key', { ns: 'oldNs', ... })
|
|
238
272
|
if (oldParts.namespace && newParts.namespace && oldParts.namespace !== newParts.namespace) {
|
|
239
273
|
// We want to change only when key matches and ns value equals oldParts.namespace
|