@discord/intl-loader-core 0.11.2 → 0.11.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@discord/intl-loader-core",
3
- "version": "0.11.2",
3
+ "version": "0.11.3",
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.2"
31
+ "@discord/intl-message-database": "0.11.3"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/debug": "^4.1.12",
package/src/watcher.js CHANGED
@@ -37,14 +37,33 @@ const DEFAULT_LOCALE = 'en-US';
37
37
  * ignore?: string[],
38
38
  * skipInitial?: boolean,
39
39
  * persistent?: boolean,
40
+ * once?: boolean,
40
41
  * }} options
42
+ * @returns {Promise<{
43
+ * on(event: string, callback: (event: string, path: string) => void): void
44
+ * }>}
41
45
  */
42
46
  async function watchMessagesFiles(
43
47
  watchedFolders,
44
- { ignore = [], skipInitial = false, persistent = true } = {},
48
+ { ignore = [], skipInitial = false, once = true } = {},
45
49
  ) {
46
50
  debug('Pre-initializing database with all discoverable messages files');
47
- processAllMessagesFiles(findAllMessagesFiles(watchedFolders));
51
+ const files = findAllMessagesFiles(watchedFolders);
52
+ processAllMessagesFiles(files);
53
+ if (once) {
54
+ debug('Performing one-shot watch because `once` was true');
55
+ // This is a weird hack around file watching just not working well on
56
+ // containers/CI. `add` events won't fire consistently from chokidar when
57
+ // it's not set to be persistent. So for a `once` run, we can just manually
58
+ // invoke the event for every file that was discovered on the initial scan.
59
+ return {
60
+ on(_, callback) {
61
+ for (const file of files) {
62
+ callback('add', file.filePath);
63
+ }
64
+ },
65
+ };
66
+ }
48
67
 
49
68
  const ignoredPatterns = ignore.concat(ALWAYS_IGNORE_PATTERNS);
50
69
  const globs = watchedFolders.flatMap((folder) =>
@@ -55,7 +74,7 @@ async function watchMessagesFiles(
55
74
  const watcher = chokidar.watch(globs, {
56
75
  ignored: ignoredPatterns,
57
76
  ignoreInitial: skipInitial,
58
- persistent,
77
+ persistent: !once,
59
78
  });
60
79
  watcher.on('all', (event, path) => {
61
80
  processAllMessagesFiles(filterAllMessagesFiles([path]));
@@ -7,13 +7,20 @@
7
7
  * ignore?: string[],
8
8
  * skipInitial?: boolean,
9
9
  * persistent?: boolean,
10
+ * once?: boolean,
10
11
  * }} options
12
+ * @returns {Promise<{
13
+ * on(event: string, callback: (event: string, path: string) => void): void
14
+ * }>}
11
15
  */
12
- export function watchMessagesFiles(watchedFolders: string[], { ignore, skipInitial, persistent }?: {
16
+ export function watchMessagesFiles(watchedFolders: string[], { ignore, skipInitial, once }?: {
13
17
  ignore?: string[];
14
18
  skipInitial?: boolean;
15
19
  persistent?: boolean;
16
- }): Promise<chokidar.FSWatcher>;
20
+ once?: boolean;
21
+ }): Promise<{
22
+ on(event: string, callback: (event: string, path: string) => void): void;
23
+ }>;
17
24
  /**
18
25
  * Watch the file system for changes to message _definitions_ files, and pre-process them into
19
26
  * compiled assets (with the extension `.compiled.messages.${assetExtension}`).