Skip to content

Commit 068f600

Browse files
committed
feat(chokidar): add listDictionariesWithStats function and update imports in prepareIntlayer
1 parent 0ae6441 commit 068f600

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

packages/@intlayer/chokidar/src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ export { getContentDeclarationFileTemplate } from './getContentDeclarationFileTe
1717
export { handleAdditionalContentDeclarationFile } from './handleAdditionalContentDeclarationFile';
1818
export { handleContentDeclarationFileChange } from './handleContentDeclarationFileChange';
1919
export { handleUnlinkedContentDeclarationFile } from './handleUnlinkedContentDeclarationFile';
20-
export { listDictionaries } from './listDictionariesPath';
20+
export {
21+
listDictionaries,
22+
listDictionariesWithStats,
23+
} from './listDictionariesPath';
2124
export {
2225
type DiffMode,
2326
type ListGitFilesOptions,

packages/@intlayer/chokidar/src/listDictionariesPath.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { stat } from 'node:fs/promises';
12
import type { IntlayerConfig } from '@intlayer/types';
23
import fg from 'fast-glob';
34

@@ -18,3 +19,13 @@ export const listDictionaries = async (
1819

1920
return files;
2021
};
22+
23+
export const listDictionariesWithStats = async (
24+
configuration: IntlayerConfig
25+
) => {
26+
const files = await listDictionaries(configuration);
27+
28+
return Promise.all(
29+
files.map(async (file) => ({ path: file, stats: await stat(file) }))
30+
);
31+
};

packages/@intlayer/chokidar/src/prepareIntlayer.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { stat } from 'node:fs/promises';
12
import { join } from 'node:path';
23
import {
34
ANSIColors,
@@ -13,7 +14,7 @@ import { writeRemoteDictionary } from './buildIntlayerDictionary/writeRemoteDict
1314
import { cleanOutputDir } from './cleanOutputDir';
1415
import { createDictionaryEntryPoint } from './createDictionaryEntryPoint/createDictionaryEntryPoint';
1516
import { createModuleAugmentation, createTypes } from './createType/index';
16-
import { listDictionaries } from './listDictionariesPath';
17+
import { listDictionariesWithStats } from './listDictionariesPath';
1718
import { loadDictionaries } from './loadDictionaries/loadDictionaries';
1819
import { runOnce } from './utils/runOnce';
1920
import {
@@ -54,9 +55,17 @@ export const prepareIntlayer = async (
5455

5556
const isConfigSimilar = await isCachedConfigurationUpToDate(configuration);
5657

58+
const dictionariesWithStats = await listDictionariesWithStats(configuration);
59+
60+
const sentinelStats = await stat(sentinelPath);
61+
const isDictionaryChanged = dictionariesWithStats.some(
62+
(dictionary) =>
63+
dictionary.stats.mtime.getTime() > sentinelStats.mtime.getTime()
64+
);
65+
5766
const { clean, format, forceRun, onIsCached, cacheTimeoutMs } = {
5867
...DEFAULT_PREPARE_INTLAYER_OPTIONS,
59-
forceRun: !isCorrectVersion || !isConfigSimilar,
68+
forceRun: !isCorrectVersion || !isConfigSimilar || isDictionaryChanged,
6069
...(options ?? {}),
6170
};
6271

@@ -97,9 +106,14 @@ export const prepareIntlayer = async (
97106
}
98107
);
99108

100-
const files: string[] = await listDictionaries(configuration);
109+
const contentDeclarationPaths = dictionariesWithStats.map(
110+
(dictionary) => dictionary.path
111+
);
101112

102-
const dictionaries = await loadDictionaries(files, configuration);
113+
const dictionaries = await loadDictionaries(
114+
contentDeclarationPaths,
115+
configuration
116+
);
103117

104118
const dictionariesLoadedTime = Date.now();
105119

0 commit comments

Comments
 (0)