@discord/intl-loader-core 0.11.5 → 0.12.0

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/index.js CHANGED
@@ -7,7 +7,9 @@ const {
7
7
 
8
8
  const { database } = require('./src/database');
9
9
  const {
10
+ findAllDefinitionsFilesForTranslations,
10
11
  findAllMessagesFiles,
12
+ filterAllMessagesFiles,
11
13
  processAllMessagesFiles,
12
14
  generateTypeDefinitions,
13
15
  processDefinitionsFile,
@@ -25,6 +27,7 @@ module.exports = {
25
27
  MessageDefinitionsTransformer,
26
28
  database,
27
29
  findAllTranslationFiles,
30
+ findAllDefinitionsFilesForTranslations,
28
31
  getLocaleFromTranslationsFileName,
29
32
  generateTypeDefinitions,
30
33
  hashMessageKey,
@@ -34,6 +37,7 @@ module.exports = {
34
37
  processTranslationsFile,
35
38
  precompileFileForLocale,
36
39
  findAllMessagesFiles,
40
+ filterAllMessagesFiles,
37
41
  processAllMessagesFiles,
38
42
  watcher,
39
43
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@discord/intl-loader-core",
3
- "version": "0.11.5",
3
+ "version": "0.12.0",
4
4
  "license": "MIT",
5
5
  "description": "Core utilities for writing loaders and transformers using @discord/intl",
6
6
  "author": "Jon Egeland",
@@ -28,7 +28,7 @@
28
28
  "dependencies": {
29
29
  "chokidar": "^3.6.0",
30
30
  "debug": "^4.3.6",
31
- "@discord/intl-message-database": "0.11.5"
31
+ "@discord/intl-message-database": "0.12.0"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/debug": "^4.1.12",
package/src/processing.js CHANGED
@@ -43,6 +43,33 @@ function buildTranslationsLocaleMap(sourcePath, sourceFile, translationsPath) {
43
43
  return map;
44
44
  }
45
45
 
46
+ /**
47
+ * Return file paths for all definitions files with a translations path meta value that would
48
+ * include the given `translationPath`. This can be used to add reverse dependencies, and safely
49
+ * cache translations files with appropriate change detection.
50
+ *
51
+ * Note that this process is _only_ accurate if the database has full knowledge of all messages
52
+ * files that exist in the project, which can be guaranteed by running `findAllMessagesFiles` and
53
+ * `processAllMessagesFiles` beforehand. In most cases, this is suitable to do only once when a
54
+ * loader process is initializing.
55
+ *
56
+ * @param {string} filePath
57
+ * @returns {string[]}
58
+ */
59
+ function findAllDefinitionsFilesForTranslations(filePath) {
60
+ const expectedTranslationsPath = path.dirname(filePath);
61
+ const sourceFiles = database.getAllSourceFilePaths();
62
+ const relevantPaths = [];
63
+ for (const file of sourceFiles) {
64
+ const source = database.getSourceFile(file);
65
+ if (source.type === 'definition' && source.meta.translationsPath === expectedTranslationsPath) {
66
+ console.log(file, source.meta);
67
+ relevantPaths.push(source.file);
68
+ }
69
+ }
70
+ return relevantPaths;
71
+ }
72
+
46
73
  /**
47
74
  * Scan the entire file system within the given `directories` to find all files that can be treated
48
75
  * as messages definitions _or_ translations.
@@ -54,6 +81,7 @@ function buildTranslationsLocaleMap(sourcePath, sourceFile, translationsPath) {
54
81
  function findAllMessagesFiles(directories, defaultLocale = 'en-US') {
55
82
  return database.findAllMessagesFiles(directories, defaultLocale);
56
83
  }
84
+
57
85
  /**
58
86
  * Given an arbitrary list of `files`, keep only those that can be treated as messages files, either
59
87
  * definitions or translations. The returned list is a set of descriptors that can be processed by
@@ -228,6 +256,7 @@ function generateTypeDefinitions(sourcePath, outputFile, allowNullability = fals
228
256
  }
229
257
 
230
258
  module.exports = {
259
+ findAllDefinitionsFilesForTranslations,
231
260
  findAllMessagesFiles,
232
261
  filterAllMessagesFiles,
233
262
  processAllMessagesFiles,
package/types/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import { IntlCompiledMessageFormat } from "@discord/intl-message-database";
2
2
  import { MessageDefinitionsTransformer } from "./src/transformer";
3
3
  import { database } from "./src/database";
4
4
  import { findAllTranslationFiles } from "./src/util";
5
+ import { findAllDefinitionsFilesForTranslations } from "./src/processing";
5
6
  import { getLocaleFromTranslationsFileName } from "./src/util";
6
7
  import { generateTypeDefinitions } from "./src/processing";
7
8
  import { hashMessageKey } from "@discord/intl-message-database";
@@ -11,6 +12,7 @@ import { processDefinitionsFile } from "./src/processing";
11
12
  import { processTranslationsFile } from "./src/processing";
12
13
  import { precompileFileForLocale } from "./src/processing";
13
14
  import { findAllMessagesFiles } from "./src/processing";
15
+ import { filterAllMessagesFiles } from "./src/processing";
14
16
  import { processAllMessagesFiles } from "./src/processing";
15
17
  import watcher = require("./src/watcher");
16
- export { IntlCompiledMessageFormat, MessageDefinitionsTransformer, database, findAllTranslationFiles, getLocaleFromTranslationsFileName, generateTypeDefinitions, hashMessageKey, isMessageDefinitionsFile, isMessageTranslationsFile, processDefinitionsFile, processTranslationsFile, precompileFileForLocale, findAllMessagesFiles, processAllMessagesFiles, watcher };
18
+ export { IntlCompiledMessageFormat, MessageDefinitionsTransformer, database, findAllTranslationFiles, findAllDefinitionsFilesForTranslations, getLocaleFromTranslationsFileName, generateTypeDefinitions, hashMessageKey, isMessageDefinitionsFile, isMessageTranslationsFile, processDefinitionsFile, processTranslationsFile, precompileFileForLocale, findAllMessagesFiles, filterAllMessagesFiles, processAllMessagesFiles, watcher };
@@ -2,6 +2,20 @@ export type IntlPrecompileOptions = {
2
2
  format?: IntlCompiledMessageFormat;
3
3
  bundleSecrets?: boolean;
4
4
  };
5
+ /**
6
+ * Return file paths for all definitions files with a translations path meta value that would
7
+ * include the given `translationPath`. This can be used to add reverse dependencies, and safely
8
+ * cache translations files with appropriate change detection.
9
+ *
10
+ * Note that this process is _only_ accurate if the database has full knowledge of all messages
11
+ * files that exist in the project, which can be guaranteed by running `findAllMessagesFiles` and
12
+ * `processAllMessagesFiles` beforehand. In most cases, this is suitable to do only once when a
13
+ * loader process is initializing.
14
+ *
15
+ * @param {string} filePath
16
+ * @returns {string[]}
17
+ */
18
+ export function findAllDefinitionsFilesForTranslations(filePath: string): string[];
5
19
  /**
6
20
  * Scan the entire file system within the given `directories` to find all files that can be treated
7
21
  * as messages definitions _or_ translations.