@vocab/core 1.6.2 → 1.6.3

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/README.md CHANGED
@@ -39,8 +39,8 @@ This is the language Vocab will assume when it sees a `translation.json` file wi
39
39
  ```js
40
40
  // vocab.config.js
41
41
  module.exports = {
42
- languages: [{ name: 'en' }, { name: 'fr' }]
43
- devLanguage: 'en',
42
+ languages: [{ name: 'en' }, { name: 'fr' }],
43
+ devLanguage: 'en'
44
44
  };
45
45
  ```
46
46
 
@@ -3,4 +3,4 @@ export { validate } from "./validate/index.js";
3
3
  export { resolveConfig, resolveConfigSync, validateConfig } from "./config.js";
4
4
  export { getAltLanguages, getAltLanguageFilePath, getDevLanguageFileFromTsFile, } from "./utils.js";
5
5
  export { getUniqueKey, loadAllTranslations, loadTranslation, } from "./load-translations.js";
6
- export * from "./types.js";
6
+ export type * from "./types.js";
@@ -4,7 +4,7 @@ export declare function getUniqueKey(key: string, namespace: string): string;
4
4
  export declare function mergeWithDevLanguageTranslation({ translation, devTranslation, }: {
5
5
  translation: TranslationsByKey;
6
6
  devTranslation: TranslationsByKey;
7
- }): TranslationsByKey<string>;
7
+ }): TranslationsByKey;
8
8
  export declare function getLanguageHierarchy({ languages, }: {
9
9
  languages: LanguageTarget[];
10
10
  }): Map<string, string[]>;
@@ -324,6 +324,8 @@ function loadAltLanguageFile({
324
324
  try {
325
325
  const altFilePath = getAltLanguageFilePath(filePath, fallbackLanguage);
326
326
  delete require.cache[altFilePath];
327
+
328
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
327
329
  const translationFile = require(altFilePath);
328
330
  const {
329
331
  keys: fallbackLanguageTranslation
@@ -335,7 +337,7 @@ function loadAltLanguageFile({
335
337
  translation: fallbackLanguageTranslation,
336
338
  devTranslation
337
339
  }));
338
- } catch (e) {
340
+ } catch {
339
341
  trace(`Missing alt language file ${getAltLanguageFilePath(filePath, fallbackLanguage)}
340
342
  `);
341
343
  }
@@ -359,6 +361,7 @@ function loadTranslation({
359
361
  trace(`Loading translation file in "${fallbacks}" fallback mode: "${filePath}"`);
360
362
  const languageSet = {};
361
363
  delete require.cache[filePath];
364
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
362
365
  const translationContent = require(filePath);
363
366
  const relativePath = path__default["default"].relative(userConfig.projectRoot || process.cwd(), filePath);
364
367
  const {
@@ -419,13 +422,15 @@ async function loadAllTranslations({
419
422
  cwd: projectRoot
420
423
  });
421
424
  trace(`Found ${translationFiles.length} translation files`);
422
- const result = await Promise.all(translationFiles.map(filePath => loadTranslation({
423
- filePath,
424
- fallbacks,
425
- withTags
426
- }, config)));
425
+ const loadedTranslations = [];
427
426
  const keys = new Set();
428
- for (const loadedTranslation of result) {
427
+ for (const translationFile of translationFiles) {
428
+ const loadedTranslation = loadTranslation({
429
+ filePath: translationFile,
430
+ fallbacks,
431
+ withTags
432
+ }, config);
433
+ loadedTranslations.push(loadedTranslation);
429
434
  for (const key of loadedTranslation.keys) {
430
435
  const uniqueKey = getUniqueKey(key, loadedTranslation.namespace);
431
436
  if (keys.has(uniqueKey)) {
@@ -442,7 +447,7 @@ async function loadAllTranslations({
442
447
  }
443
448
  }
444
449
  }
445
- return result;
450
+ return loadedTranslations;
446
451
  }
447
452
 
448
453
  function extractHasTags(ast) {
@@ -659,7 +664,7 @@ async function writeIfChanged(filepath, contents) {
659
664
  encoding: 'utf-8'
660
665
  });
661
666
  hasChanged = existingContents !== contents;
662
- } catch (e) {
667
+ } catch {
663
668
  // ignore error, likely a file doesn't exist error so we want to write anyway
664
669
  }
665
670
  if (hasChanged) {
@@ -851,6 +856,7 @@ function createConfig(configFilePath) {
851
856
  const cwd = path__default["default"].dirname(configFilePath);
852
857
  return {
853
858
  projectRoot: cwd,
859
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
854
860
  ...require(configFilePath)
855
861
  };
856
862
  }
@@ -324,6 +324,8 @@ function loadAltLanguageFile({
324
324
  try {
325
325
  const altFilePath = getAltLanguageFilePath(filePath, fallbackLanguage);
326
326
  delete require.cache[altFilePath];
327
+
328
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
327
329
  const translationFile = require(altFilePath);
328
330
  const {
329
331
  keys: fallbackLanguageTranslation
@@ -335,7 +337,7 @@ function loadAltLanguageFile({
335
337
  translation: fallbackLanguageTranslation,
336
338
  devTranslation
337
339
  }));
338
- } catch (e) {
340
+ } catch {
339
341
  trace(`Missing alt language file ${getAltLanguageFilePath(filePath, fallbackLanguage)}
340
342
  `);
341
343
  }
@@ -359,6 +361,7 @@ function loadTranslation({
359
361
  trace(`Loading translation file in "${fallbacks}" fallback mode: "${filePath}"`);
360
362
  const languageSet = {};
361
363
  delete require.cache[filePath];
364
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
362
365
  const translationContent = require(filePath);
363
366
  const relativePath = path__default["default"].relative(userConfig.projectRoot || process.cwd(), filePath);
364
367
  const {
@@ -419,13 +422,15 @@ async function loadAllTranslations({
419
422
  cwd: projectRoot
420
423
  });
421
424
  trace(`Found ${translationFiles.length} translation files`);
422
- const result = await Promise.all(translationFiles.map(filePath => loadTranslation({
423
- filePath,
424
- fallbacks,
425
- withTags
426
- }, config)));
425
+ const loadedTranslations = [];
427
426
  const keys = new Set();
428
- for (const loadedTranslation of result) {
427
+ for (const translationFile of translationFiles) {
428
+ const loadedTranslation = loadTranslation({
429
+ filePath: translationFile,
430
+ fallbacks,
431
+ withTags
432
+ }, config);
433
+ loadedTranslations.push(loadedTranslation);
429
434
  for (const key of loadedTranslation.keys) {
430
435
  const uniqueKey = getUniqueKey(key, loadedTranslation.namespace);
431
436
  if (keys.has(uniqueKey)) {
@@ -442,7 +447,7 @@ async function loadAllTranslations({
442
447
  }
443
448
  }
444
449
  }
445
- return result;
450
+ return loadedTranslations;
446
451
  }
447
452
 
448
453
  function extractHasTags(ast) {
@@ -659,7 +664,7 @@ async function writeIfChanged(filepath, contents) {
659
664
  encoding: 'utf-8'
660
665
  });
661
666
  hasChanged = existingContents !== contents;
662
- } catch (e) {
667
+ } catch {
663
668
  // ignore error, likely a file doesn't exist error so we want to write anyway
664
669
  }
665
670
  if (hasChanged) {
@@ -851,6 +856,7 @@ function createConfig(configFilePath) {
851
856
  const cwd = path__default["default"].dirname(configFilePath);
852
857
  return {
853
858
  projectRoot: cwd,
859
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
854
860
  ...require(configFilePath)
855
861
  };
856
862
  }
@@ -308,6 +308,8 @@ function loadAltLanguageFile({
308
308
  try {
309
309
  const altFilePath = getAltLanguageFilePath(filePath, fallbackLanguage);
310
310
  delete require.cache[altFilePath];
311
+
312
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
311
313
  const translationFile = require(altFilePath);
312
314
  const {
313
315
  keys: fallbackLanguageTranslation
@@ -319,7 +321,7 @@ function loadAltLanguageFile({
319
321
  translation: fallbackLanguageTranslation,
320
322
  devTranslation
321
323
  }));
322
- } catch (e) {
324
+ } catch {
323
325
  trace(`Missing alt language file ${getAltLanguageFilePath(filePath, fallbackLanguage)}
324
326
  `);
325
327
  }
@@ -343,6 +345,7 @@ function loadTranslation({
343
345
  trace(`Loading translation file in "${fallbacks}" fallback mode: "${filePath}"`);
344
346
  const languageSet = {};
345
347
  delete require.cache[filePath];
348
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
346
349
  const translationContent = require(filePath);
347
350
  const relativePath = path.relative(userConfig.projectRoot || process.cwd(), filePath);
348
351
  const {
@@ -403,13 +406,15 @@ async function loadAllTranslations({
403
406
  cwd: projectRoot
404
407
  });
405
408
  trace(`Found ${translationFiles.length} translation files`);
406
- const result = await Promise.all(translationFiles.map(filePath => loadTranslation({
407
- filePath,
408
- fallbacks,
409
- withTags
410
- }, config)));
409
+ const loadedTranslations = [];
411
410
  const keys = new Set();
412
- for (const loadedTranslation of result) {
411
+ for (const translationFile of translationFiles) {
412
+ const loadedTranslation = loadTranslation({
413
+ filePath: translationFile,
414
+ fallbacks,
415
+ withTags
416
+ }, config);
417
+ loadedTranslations.push(loadedTranslation);
413
418
  for (const key of loadedTranslation.keys) {
414
419
  const uniqueKey = getUniqueKey(key, loadedTranslation.namespace);
415
420
  if (keys.has(uniqueKey)) {
@@ -426,7 +431,7 @@ async function loadAllTranslations({
426
431
  }
427
432
  }
428
433
  }
429
- return result;
434
+ return loadedTranslations;
430
435
  }
431
436
 
432
437
  function extractHasTags(ast) {
@@ -643,7 +648,7 @@ async function writeIfChanged(filepath, contents) {
643
648
  encoding: 'utf-8'
644
649
  });
645
650
  hasChanged = existingContents !== contents;
646
- } catch (e) {
651
+ } catch {
647
652
  // ignore error, likely a file doesn't exist error so we want to write anyway
648
653
  }
649
654
  if (hasChanged) {
@@ -835,6 +840,7 @@ function createConfig(configFilePath) {
835
840
  const cwd = path.dirname(configFilePath);
836
841
  return {
837
842
  projectRoot: cwd,
843
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
838
844
  ...require(configFilePath)
839
845
  };
840
846
  }
package/package.json CHANGED
@@ -1,6 +1,11 @@
1
1
  {
2
2
  "name": "@vocab/core",
3
- "version": "1.6.2",
3
+ "version": "1.6.3",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "https://github.com/seek-oss/vocab.git",
7
+ "directory": "packages/core"
8
+ },
4
9
  "main": "dist/vocab-core.cjs.js",
5
10
  "module": "dist/vocab-core.esm.js",
6
11
  "exports": {