@discord/intl-loader-core 0.11.2 → 0.11.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/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.4",
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.4"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/debug": "^4.1.12",
package/src/watcher.js CHANGED
@@ -28,6 +28,12 @@ const ALWAYS_IGNORE_PATTERNS = [
28
28
  const MESSAGES_FILE_PATTERNS = ['**/*.messages.*'];
29
29
  const DEFAULT_LOCALE = 'en-US';
30
30
 
31
+ /**
32
+ * @typedef {{
33
+ * on(event: string, callback: (event: string, path: string) => void): void
34
+ * }} BasicWatcher
35
+ */
36
+
31
37
  /**
32
38
  * Start a new filesystem watcher to discover and monitor messages files, allowing consumers to
33
39
  * react to changes in a single, consistent way.
@@ -37,14 +43,31 @@ const DEFAULT_LOCALE = 'en-US';
37
43
  * ignore?: string[],
38
44
  * skipInitial?: boolean,
39
45
  * persistent?: boolean,
46
+ * once?: boolean,
40
47
  * }} options
48
+ * @returns {Promise<BasicWatcher>}
41
49
  */
42
50
  async function watchMessagesFiles(
43
51
  watchedFolders,
44
- { ignore = [], skipInitial = false, persistent = true } = {},
52
+ { ignore = [], skipInitial = false, once = true } = {},
45
53
  ) {
46
54
  debug('Pre-initializing database with all discoverable messages files');
47
- processAllMessagesFiles(findAllMessagesFiles(watchedFolders));
55
+ const files = findAllMessagesFiles(watchedFolders);
56
+ processAllMessagesFiles(files);
57
+ if (once) {
58
+ debug('Performing one-shot watch because `once` was true');
59
+ // This is a weird hack around file watching just not working well on
60
+ // containers/CI. `add` events won't fire consistently from chokidar when
61
+ // it's not set to be persistent. So for a `once` run, we can just manually
62
+ // invoke the event for every file that was discovered on the initial scan.
63
+ return {
64
+ on(_, callback) {
65
+ for (const file of files) {
66
+ callback('add', file.filePath);
67
+ }
68
+ },
69
+ };
70
+ }
48
71
 
49
72
  const ignoredPatterns = ignore.concat(ALWAYS_IGNORE_PATTERNS);
50
73
  const globs = watchedFolders.flatMap((folder) =>
@@ -55,7 +78,7 @@ async function watchMessagesFiles(
55
78
  const watcher = chokidar.watch(globs, {
56
79
  ignored: ignoredPatterns,
57
80
  ignoreInitial: skipInitial,
58
- persistent,
81
+ persistent: !once,
59
82
  });
60
83
  watcher.on('all', (event, path) => {
61
84
  processAllMessagesFiles(filterAllMessagesFiles([path]));
@@ -75,7 +98,7 @@ async function watchMessagesFiles(
75
98
  /**
76
99
  * Watch the file system for any changes to message files and regenerate their types.
77
100
  *
78
- * @param {chokidar.FSWatcher} watcher
101
+ * @param {BasicWatcher} watcher
79
102
  * @param {{
80
103
  * allowNullability?: boolean
81
104
  * }} options
@@ -92,7 +115,7 @@ async function generateMessageTypes(watcher, { allowNullability }) {
92
115
  * Watch the file system for changes to message _definitions_ files, and pre-process them into
93
116
  * compiled assets (with the extension `.compiled.messages.${assetExtension}`).
94
117
  *
95
- * @param {chokidar.FSWatcher} watcher
118
+ * @param {BasicWatcher} watcher
96
119
  * @param {{
97
120
  * ignore?: string[],
98
121
  * assetExtension?: string
@@ -1,3 +1,11 @@
1
+ export type BasicWatcher = {
2
+ on(event: string, callback: (event: string, path: string) => void): void;
3
+ };
4
+ /**
5
+ * @typedef {{
6
+ * on(event: string, callback: (event: string, path: string) => void): void
7
+ * }} BasicWatcher
8
+ */
1
9
  /**
2
10
  * Start a new filesystem watcher to discover and monitor messages files, allowing consumers to
3
11
  * react to changes in a single, consistent way.
@@ -7,25 +15,28 @@
7
15
  * ignore?: string[],
8
16
  * skipInitial?: boolean,
9
17
  * persistent?: boolean,
18
+ * once?: boolean,
10
19
  * }} options
20
+ * @returns {Promise<BasicWatcher>}
11
21
  */
12
- export function watchMessagesFiles(watchedFolders: string[], { ignore, skipInitial, persistent }?: {
22
+ export function watchMessagesFiles(watchedFolders: string[], { ignore, skipInitial, once }?: {
13
23
  ignore?: string[];
14
24
  skipInitial?: boolean;
15
25
  persistent?: boolean;
16
- }): Promise<chokidar.FSWatcher>;
26
+ once?: boolean;
27
+ }): Promise<BasicWatcher>;
17
28
  /**
18
29
  * Watch the file system for changes to message _definitions_ files, and pre-process them into
19
30
  * compiled assets (with the extension `.compiled.messages.${assetExtension}`).
20
31
  *
21
- * @param {chokidar.FSWatcher} watcher
32
+ * @param {BasicWatcher} watcher
22
33
  * @param {{
23
34
  * ignore?: string[],
24
35
  * assetExtension?: string
25
36
  * precompileOptions?: import('./processing').IntlPrecompileOptions,
26
37
  * }} options
27
38
  */
28
- export function precompileMessageDefinitionsFiles(watcher: chokidar.FSWatcher, { assetExtension, precompileOptions }?: {
39
+ export function precompileMessageDefinitionsFiles(watcher: BasicWatcher, { assetExtension, precompileOptions }?: {
29
40
  ignore?: string[];
30
41
  assetExtension?: string;
31
42
  precompileOptions?: import("./processing").IntlPrecompileOptions;
@@ -33,13 +44,12 @@ export function precompileMessageDefinitionsFiles(watcher: chokidar.FSWatcher, {
33
44
  /**
34
45
  * Watch the file system for any changes to message files and regenerate their types.
35
46
  *
36
- * @param {chokidar.FSWatcher} watcher
47
+ * @param {BasicWatcher} watcher
37
48
  * @param {{
38
49
  * allowNullability?: boolean
39
50
  * }} options
40
51
  */
41
- export function generateMessageTypes(watcher: chokidar.FSWatcher, { allowNullability }: {
52
+ export function generateMessageTypes(watcher: BasicWatcher, { allowNullability }: {
42
53
  allowNullability?: boolean;
43
54
  }): Promise<void>;
44
55
  export const ALWAYS_IGNORE_PATTERNS: string[];
45
- import chokidar = require("chokidar");