@intlayer/chokidar 5.2.9 → 5.3.1
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/dist/cjs/chokidar/watcher.cjs +1 -1
- package/dist/cjs/chokidar/watcher.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs +1 -56
- package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs.map +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.cjs +13 -12
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.cjs.map +1 -1
- package/dist/esm/chokidar/watcher.mjs +1 -1
- package/dist/esm/chokidar/watcher.mjs.map +1 -1
- package/dist/esm/loadDictionaries/loadContentDeclaration.mjs +2 -57
- package/dist/esm/loadDictionaries/loadContentDeclaration.mjs.map +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.mjs +11 -11
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.mjs.map +1 -1
- package/dist/types/loadDictionaries/loadContentDeclaration.d.ts.map +1 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.d.ts +5 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.d.ts.map +1 -1
- package/package.json +11 -11
|
@@ -109,7 +109,7 @@ const watch = (options) => {
|
|
|
109
109
|
const buildAndWatchIntlayer = async (options) => {
|
|
110
110
|
const configuration = options?.configuration ?? (0, import_config.getConfiguration)();
|
|
111
111
|
await (0, import_prepareIntlayer.prepareIntlayer)(configuration);
|
|
112
|
-
if (configuration.content.watch) {
|
|
112
|
+
if (configuration.content.watch | options.persistent) {
|
|
113
113
|
watch({ ...options, configuration });
|
|
114
114
|
}
|
|
115
115
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/chokidar/watcher.ts"],"sourcesContent":["import { relative } from 'path';\nimport {\n type IntlayerConfig,\n appLogger,\n getConfiguration,\n} from '@intlayer/config';\n/** @ts-ignore remove error Module '\"chokidar\"' has no exported member 'ChokidarOptions' */\nimport { type ChokidarOptions, watch as chokidarWatch } from 'chokidar';\nimport { getDictionariesPath } from '../getDictionariesPath';\nimport { loadLocalDictionaries } from '../loadDictionaries/loadLocalDictionaries';\nimport { buildDictionary } from '../transpiler/declaration_file_to_dictionary/index';\nimport { createDictionaryEntryPoint } from '../transpiler/dictionary_to_main/createDictionaryEntryPoint';\nimport {\n createTypes,\n createModuleAugmentation,\n} from '../transpiler/dictionary_to_type/index';\nimport { prepareIntlayer } from '../prepareIntlayer';\n\nexport const handleAdditionalContentDeclarationFile = async (\n filePath: string,\n configuration?: IntlayerConfig\n) => {\n const { content } =\n configuration ??\n getConfiguration({\n verbose: true,\n });\n\n // Process the file with the functionToRun\n appLogger(\n `Additional file detected: ${relative(content.baseDir, filePath)}`,\n {\n isVerbose: true,\n }\n );\n\n const localeDictionaries = await loadLocalDictionaries(filePath);\n\n const dictionariesPaths = await buildDictionary(localeDictionaries);\n\n createTypes(dictionariesPaths);\n\n createDictionaryEntryPoint();\n\n appLogger('Dictionaries built', {\n isVerbose: true,\n });\n\n createModuleAugmentation();\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n};\n\nexport const handleContentDeclarationFileChange = async (\n filePath: string,\n configuration?: IntlayerConfig\n) => {\n const { content } =\n configuration ??\n getConfiguration({\n verbose: true,\n });\n\n // Process the file with the functionToRun\n appLogger(`Change detected: ${relative(content.baseDir, filePath)}`, {\n isVerbose: true,\n });\n\n const localeDictionaries = await loadLocalDictionaries(filePath);\n const updatedDictionariesPaths = await buildDictionary(localeDictionaries);\n const allDictionariesPaths: string[] = getDictionariesPath();\n\n createTypes(updatedDictionariesPaths);\n appLogger('TypeScript types built', {\n isVerbose: true,\n });\n\n if (\n updatedDictionariesPaths.some((updatedDictionaryPath) =>\n allDictionariesPaths.includes(updatedDictionaryPath)\n )\n ) {\n createDictionaryEntryPoint();\n\n appLogger('Dictionary list built', {\n isVerbose: true,\n });\n\n createModuleAugmentation();\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n }\n};\n\ntype WatchOptions = ChokidarOptions & {\n configuration?: IntlayerConfig;\n};\n\n// Initialize chokidar watcher (non-persistent)\nexport const watch = (options?: WatchOptions) => {\n const configuration =\n options?.configuration ??\n getConfiguration({\n verbose: true,\n });\n\n const { watch: isWatchMode, watchedFilesPatternWithPath } =\n configuration.content;\n\n /** @ts-ignore remove error Expected 0-1 arguments, but got 2. */\n return chokidarWatch(watchedFilesPatternWithPath, {\n persistent: isWatchMode, // Make the watcher persistent\n ignoreInitial: true, // Process existing files\n ...options,\n })\n .on(\n 'add',\n async (filePath) =>\n await handleAdditionalContentDeclarationFile(filePath, configuration)\n )\n .on(\n 'change',\n async (filePath) =>\n await handleContentDeclarationFileChange(filePath, configuration)\n )\n .on('error', (error) =>\n appLogger('Watcher error: ' + error, {\n level: 'error',\n })\n );\n};\n\nexport const buildAndWatchIntlayer = async (options?: WatchOptions) => {\n const configuration = options?.configuration ?? getConfiguration();\n\n await prepareIntlayer(configuration);\n\n if (configuration.content.watch) {\n // Start watching (assuming watch is also async)\n watch({ ...options, configuration });\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAyB;AACzB,oBAIO;AAEP,sBAA6D;AAC7D,iCAAoC;AACpC,mCAAsC;AACtC,4CAAgC;AAChC,wCAA2C;AAC3C,gCAGO;AACP,6BAAgC;AAEzB,MAAM,yCAAyC,OACpD,UACA,kBACG;AACH,QAAM,EAAE,QAAQ,IACd,qBACA,gCAAiB;AAAA,IACf,SAAS;AAAA,EACX,CAAC;AAGH;AAAA,IACE,iCAA6B,sBAAS,QAAQ,SAAS,QAAQ,CAAC;AAAA,IAChE;AAAA,MACE,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A,OAAO,aACL,MAAM,uCAAuC,UAAU,aAAa;AAAA,EACxE,EACC;AAAA,IACC;AAAA,IACA,OAAO,aACL,MAAM,mCAAmC,UAAU,aAAa;AAAA,EACpE,EACC;AAAA,IAAG;AAAA,IAAS,CAAC,cACZ,yBAAU,oBAAoB,OAAO;AAAA,MACnC,OAAO;AAAA,IACT,CAAC;AAAA,EACH;AACJ;AAEO,MAAM,wBAAwB,OAAO,YAA2B;AACrE,QAAM,gBAAgB,SAAS,qBAAiB,gCAAiB;AAEjE,YAAM,wCAAgB,aAAa;AAEnC,MAAI,cAAc,QAAQ,
|
|
1
|
+
{"version":3,"sources":["../../../src/chokidar/watcher.ts"],"sourcesContent":["import { relative } from 'path';\nimport {\n type IntlayerConfig,\n appLogger,\n getConfiguration,\n} from '@intlayer/config';\n/** @ts-ignore remove error Module '\"chokidar\"' has no exported member 'ChokidarOptions' */\nimport { type ChokidarOptions, watch as chokidarWatch } from 'chokidar';\nimport { getDictionariesPath } from '../getDictionariesPath';\nimport { loadLocalDictionaries } from '../loadDictionaries/loadLocalDictionaries';\nimport { buildDictionary } from '../transpiler/declaration_file_to_dictionary/index';\nimport { createDictionaryEntryPoint } from '../transpiler/dictionary_to_main/createDictionaryEntryPoint';\nimport {\n createTypes,\n createModuleAugmentation,\n} from '../transpiler/dictionary_to_type/index';\nimport { prepareIntlayer } from '../prepareIntlayer';\n\nexport const handleAdditionalContentDeclarationFile = async (\n filePath: string,\n configuration?: IntlayerConfig\n) => {\n const { content } =\n configuration ??\n getConfiguration({\n verbose: true,\n });\n\n // Process the file with the functionToRun\n appLogger(\n `Additional file detected: ${relative(content.baseDir, filePath)}`,\n {\n isVerbose: true,\n }\n );\n\n const localeDictionaries = await loadLocalDictionaries(filePath);\n\n const dictionariesPaths = await buildDictionary(localeDictionaries);\n\n createTypes(dictionariesPaths);\n\n createDictionaryEntryPoint();\n\n appLogger('Dictionaries built', {\n isVerbose: true,\n });\n\n createModuleAugmentation();\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n};\n\nexport const handleContentDeclarationFileChange = async (\n filePath: string,\n configuration?: IntlayerConfig\n) => {\n const { content } =\n configuration ??\n getConfiguration({\n verbose: true,\n });\n\n // Process the file with the functionToRun\n appLogger(`Change detected: ${relative(content.baseDir, filePath)}`, {\n isVerbose: true,\n });\n\n const localeDictionaries = await loadLocalDictionaries(filePath);\n const updatedDictionariesPaths = await buildDictionary(localeDictionaries);\n const allDictionariesPaths: string[] = getDictionariesPath();\n\n createTypes(updatedDictionariesPaths);\n appLogger('TypeScript types built', {\n isVerbose: true,\n });\n\n if (\n updatedDictionariesPaths.some((updatedDictionaryPath) =>\n allDictionariesPaths.includes(updatedDictionaryPath)\n )\n ) {\n createDictionaryEntryPoint();\n\n appLogger('Dictionary list built', {\n isVerbose: true,\n });\n\n createModuleAugmentation();\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n }\n};\n\ntype WatchOptions = ChokidarOptions & {\n configuration?: IntlayerConfig;\n};\n\n// Initialize chokidar watcher (non-persistent)\nexport const watch = (options?: WatchOptions) => {\n const configuration =\n options?.configuration ??\n getConfiguration({\n verbose: true,\n });\n\n const { watch: isWatchMode, watchedFilesPatternWithPath } =\n configuration.content;\n\n /** @ts-ignore remove error Expected 0-1 arguments, but got 2. */\n return chokidarWatch(watchedFilesPatternWithPath, {\n persistent: isWatchMode, // Make the watcher persistent\n ignoreInitial: true, // Process existing files\n ...options,\n })\n .on(\n 'add',\n async (filePath) =>\n await handleAdditionalContentDeclarationFile(filePath, configuration)\n )\n .on(\n 'change',\n async (filePath) =>\n await handleContentDeclarationFileChange(filePath, configuration)\n )\n .on('error', (error) =>\n appLogger('Watcher error: ' + error, {\n level: 'error',\n })\n );\n};\n\nexport const buildAndWatchIntlayer = async (options?: WatchOptions) => {\n const configuration = options?.configuration ?? getConfiguration();\n\n await prepareIntlayer(configuration);\n\n if (configuration.content.watch | options.persistent) {\n // Start watching (assuming watch is also async)\n watch({ ...options, configuration });\n }\n};\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W;AAAA,IACb,CAAC;AAED,4DAAyB;AAEzB,iCAAU,6BAA6B;AAAA,MACrC,WAAW;AAAA,IACb,CAAC;AAAA,EACH;AACF;AAOO,MAAM,QAAQ,CAAC,YAA2B;AAC/C,QAAM,gBACJ,SAAS,qBACT,gCAAiB;AAAA,IACf,SAAS;AAAA,EACX,CAAC;AAEH,QAAM,EAAE,OAAO,aAAa,4BAA4B,IACtD,cAAc;AAGhB,aAAO,gBAAAA,OAAc,6BAA6B;AAAA,IAChD,YAAY;AAAA;AAAA,IACZ,eAAe;AAAA;AAAA,IACf,GAAG;AAAA,EACL,CAAC,EACE;AAAA,IACC;AAAA,IACA,OAAO,aACL,MAAM,uCAAuC,UAAU,aAAa;AAAA,EACxE,EACC;AAAA,IACC;AAAA,IACA,OAAO,aACL,MAAM,mCAAmC,UAAU,aAAa;AAAA,EACpE,EACC;AAAA,IAAG;AAAA,IAAS,CAAC,cACZ,yBAAU,oBAAoB,OAAO;AAAA,MACnC,OAAO;AAAA,IACT,CAAC;AAAA,EACH;AACJ;AAEO,MAAM,wBAAwB,OAAO,YAA2B;AACrE,QAAM,gBAAgB,SAAS,qBAAiB,gCAAiB;AAEjE,YAAM,wCAAgB,aAAa;AAEnC,MAAI,cAAc,QAAQ,QAAQ,QAAQ,YAAY;AAEpD,UAAM,EAAE,GAAG,SAAS,cAAc,CAAC;AAAA,EACrC;AACF;","names":["chokidarWatch"]}
|
|
@@ -21,66 +21,11 @@ __export(loadContentDeclaration_exports, {
|
|
|
21
21
|
loadContentDeclarations: () => loadContentDeclarations
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(loadContentDeclaration_exports);
|
|
24
|
-
var import_vm = require("vm");
|
|
25
24
|
var import_config = require("@intlayer/config");
|
|
26
|
-
var import_esbuild = require("esbuild");
|
|
27
25
|
var import_processContentDeclaration = require('../transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.cjs');
|
|
28
|
-
const transformationOption = {
|
|
29
|
-
loader: {
|
|
30
|
-
".js": "js",
|
|
31
|
-
".jsx": "jsx",
|
|
32
|
-
".mjs": "js",
|
|
33
|
-
".ts": "ts",
|
|
34
|
-
".tsx": "tsx",
|
|
35
|
-
".cjs": "js",
|
|
36
|
-
".json": "json"
|
|
37
|
-
},
|
|
38
|
-
format: "cjs",
|
|
39
|
-
// Output format as commonjs
|
|
40
|
-
target: "es2017",
|
|
41
|
-
packages: "external",
|
|
42
|
-
write: false,
|
|
43
|
-
bundle: true
|
|
44
|
-
};
|
|
45
|
-
const loadContentDeclaration = (contentDeclarationFilePath) => {
|
|
46
|
-
let contentDeclaration = void 0;
|
|
47
|
-
const fileExtension = contentDeclarationFilePath.split(".").pop() ?? "";
|
|
48
|
-
try {
|
|
49
|
-
if (fileExtension === "json") {
|
|
50
|
-
return (0, import_config.ESMxCJSRequire)(contentDeclarationFilePath);
|
|
51
|
-
}
|
|
52
|
-
const moduleResult = (0, import_esbuild.buildSync)({
|
|
53
|
-
entryPoints: [contentDeclarationFilePath],
|
|
54
|
-
...transformationOption
|
|
55
|
-
});
|
|
56
|
-
const moduleResultString = moduleResult.outputFiles?.[0].text;
|
|
57
|
-
if (!moduleResultString) {
|
|
58
|
-
console.error("Configuration file could not be loaded.");
|
|
59
|
-
return void 0;
|
|
60
|
-
}
|
|
61
|
-
const sandboxContext = (0, import_config.getSandBoxContext)();
|
|
62
|
-
(0, import_vm.runInNewContext)(moduleResultString, sandboxContext);
|
|
63
|
-
if (sandboxContext.exports.default && Object.keys(sandboxContext.exports.default).length > 0) {
|
|
64
|
-
contentDeclaration = sandboxContext.exports.default;
|
|
65
|
-
} else if (sandboxContext.module.exports.defaults && Object.keys(sandboxContext.module.exports.defaults).length > 0) {
|
|
66
|
-
contentDeclaration = sandboxContext.module.exports.default;
|
|
67
|
-
} else if (sandboxContext.module.exports.default && Object.keys(sandboxContext.module.exports.default).length > 0) {
|
|
68
|
-
contentDeclaration = sandboxContext.module.exports.default;
|
|
69
|
-
} else if (sandboxContext.module.exports && Object.keys(sandboxContext.module.exports).length > 0) {
|
|
70
|
-
contentDeclaration = sandboxContext.module.exports;
|
|
71
|
-
}
|
|
72
|
-
if (typeof contentDeclaration === "undefined") {
|
|
73
|
-
console.error("Configuration file could not be loaded.");
|
|
74
|
-
return void 0;
|
|
75
|
-
}
|
|
76
|
-
return contentDeclaration;
|
|
77
|
-
} catch (error) {
|
|
78
|
-
console.error("Error:", error);
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
26
|
const loadContentDeclarations = async (contentDeclarationFilePath) => {
|
|
82
27
|
const contentDeclarations = contentDeclarationFilePath.map((path) => ({
|
|
83
|
-
...
|
|
28
|
+
...(0, import_config.loadExternalFile)(path),
|
|
84
29
|
filePath: path
|
|
85
30
|
}));
|
|
86
31
|
const resultDictionariesPaths = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/loadDictionaries/loadContentDeclaration.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../src/loadDictionaries/loadContentDeclaration.ts"],"sourcesContent":["import { loadExternalFile } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { processContentDeclaration } from '../transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration';\n\nexport const loadContentDeclarations = async (\n contentDeclarationFilePath: string[]\n): Promise<Dictionary[]> => {\n const contentDeclarations = contentDeclarationFilePath.map((path) => ({\n ...loadExternalFile(path),\n filePath: path,\n }));\n const resultDictionariesPaths: Dictionary[] = [];\n\n for await (const contentDeclaration of contentDeclarations) {\n if (!contentDeclaration) {\n continue;\n }\n\n const processedContentDeclaration = await processContentDeclaration(\n contentDeclaration as Dictionary\n );\n\n if (!processedContentDeclaration) {\n continue;\n }\n\n resultDictionariesPaths.push(processedContentDeclaration);\n }\n\n return resultDictionariesPaths;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAiC;AAEjC,uCAA0C;AAEnC,MAAM,0BAA0B,OACrC,+BAC0B;AAC1B,QAAM,sBAAsB,2BAA2B,IAAI,CAAC,UAAU;AAAA,IACpE,OAAG,gCAAiB,IAAI;AAAA,IACxB,UAAU;AAAA,EACZ,EAAE;AACF,QAAM,0BAAwC,CAAC;AAE/C,mBAAiB,sBAAsB,qBAAqB;AAC1D,QAAI,CAAC,oBAAoB;AACvB;AAAA,IACF;AAEA,UAAM,8BAA8B,UAAM;AAAA,MACxC;AAAA,IACF;AAEA,QAAI,CAAC,6BAA6B;AAChC;AAAA,IACF;AAEA,4BAAwB,KAAK,2BAA2B;AAAA,EAC1D;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -18,23 +18,23 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var processContentDeclaration_exports = {};
|
|
20
20
|
__export(processContentDeclaration_exports, {
|
|
21
|
-
processContentDeclaration: () => processContentDeclaration
|
|
21
|
+
processContentDeclaration: () => processContentDeclaration,
|
|
22
|
+
resolveContentPromises: () => resolveContentPromises
|
|
22
23
|
});
|
|
23
24
|
module.exports = __toCommonJS(processContentDeclaration_exports);
|
|
24
25
|
var import_client = require("@intlayer/config/client");
|
|
25
|
-
const
|
|
26
|
-
if (
|
|
27
|
-
await
|
|
26
|
+
const resolveContentPromises = async (entry) => {
|
|
27
|
+
if (entry && typeof entry.then === "function") {
|
|
28
|
+
const awaited = await entry;
|
|
29
|
+
return resolveContentPromises(awaited);
|
|
28
30
|
}
|
|
29
|
-
};
|
|
30
|
-
const processFunctionResults = async (entry) => {
|
|
31
31
|
if (typeof entry === "function") {
|
|
32
|
-
const result =
|
|
33
|
-
return
|
|
32
|
+
const result = entry();
|
|
33
|
+
return resolveContentPromises(result);
|
|
34
34
|
}
|
|
35
35
|
if (Array.isArray(entry)) {
|
|
36
36
|
return Promise.all(
|
|
37
|
-
entry.map(async (item) =>
|
|
37
|
+
entry.map(async (item) => resolveContentPromises(item))
|
|
38
38
|
);
|
|
39
39
|
}
|
|
40
40
|
if (entry && typeof entry === "object") {
|
|
@@ -42,7 +42,7 @@ const processFunctionResults = async (entry) => {
|
|
|
42
42
|
const keys = Object.keys(entry);
|
|
43
43
|
await Promise.all(
|
|
44
44
|
keys.map(async (key) => {
|
|
45
|
-
result[key] = await
|
|
45
|
+
result[key] = await resolveContentPromises(entry[key]);
|
|
46
46
|
})
|
|
47
47
|
);
|
|
48
48
|
return result;
|
|
@@ -51,7 +51,7 @@ const processFunctionResults = async (entry) => {
|
|
|
51
51
|
};
|
|
52
52
|
const processContentDeclaration = async (contentDeclaration) => {
|
|
53
53
|
try {
|
|
54
|
-
const content = await
|
|
54
|
+
const content = await resolveContentPromises(
|
|
55
55
|
contentDeclaration.content
|
|
56
56
|
);
|
|
57
57
|
return {
|
|
@@ -66,6 +66,7 @@ const processContentDeclaration = async (contentDeclaration) => {
|
|
|
66
66
|
};
|
|
67
67
|
// Annotate the CommonJS export names for ESM import in node:
|
|
68
68
|
0 && (module.exports = {
|
|
69
|
-
processContentDeclaration
|
|
69
|
+
processContentDeclaration,
|
|
70
|
+
resolveContentPromises
|
|
70
71
|
});
|
|
71
72
|
//# sourceMappingURL=processContentDeclaration.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.ts"],"sourcesContent":["import { logger } from '@intlayer/config/client';\nimport type { Dictionary } from '@intlayer/core';\n\n/**\n *
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.ts"],"sourcesContent":["import { logger } from '@intlayer/config/client';\nimport type { Dictionary } from '@intlayer/core';\n\n/**\n * A more \"unified\" approach where each type (function, array, object, primitive)\n * is handled inside the main recursive body.\n */\nexport const resolveContentPromises = async <T = unknown>(\n entry: any\n): Promise<T> => {\n // Check if entry is a Promise (Thenable)\n if (entry && typeof entry.then === 'function') {\n const awaited = await entry;\n return resolveContentPromises(awaited);\n }\n\n // If entry is a function, invoke it and process the result\n if (typeof entry === 'function') {\n const result = entry();\n return resolveContentPromises(result);\n }\n\n if (Array.isArray(entry)) {\n return Promise.all(\n entry.map(async (item) => resolveContentPromises(item))\n ) as unknown as T;\n }\n\n if (entry && typeof entry === 'object') {\n const result: Record<string, any> = {};\n const keys = Object.keys(entry);\n await Promise.all(\n keys.map(async (key) => {\n result[key] = await resolveContentPromises(entry[key]);\n })\n );\n return result as T;\n }\n\n return entry as T;\n};\n\n/**\n * Function to load, process the module and return the Intlayer Dictionary from the module file\n */\nexport const processContentDeclaration = async (\n contentDeclaration: Dictionary\n): Promise<Dictionary | undefined> => {\n try {\n const content = (await resolveContentPromises(\n contentDeclaration.content\n )) as Dictionary['content'];\n\n return {\n ...contentDeclaration,\n content,\n } as Dictionary;\n } catch (error) {\n logger(error, {\n level: 'error',\n });\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAuB;AAOhB,MAAM,yBAAyB,OACpC,UACe;AAEf,MAAI,SAAS,OAAO,MAAM,SAAS,YAAY;AAC7C,UAAM,UAAU,MAAM;AACtB,WAAO,uBAAuB,OAAO;AAAA,EACvC;AAGA,MAAI,OAAO,UAAU,YAAY;AAC/B,UAAM,SAAS,MAAM;AACrB,WAAO,uBAAuB,MAAM;AAAA,EACtC;AAEA,MAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,WAAO,QAAQ;AAAA,MACb,MAAM,IAAI,OAAO,SAAS,uBAAuB,IAAI,CAAC;AAAA,IACxD;AAAA,EACF;AAEA,MAAI,SAAS,OAAO,UAAU,UAAU;AACtC,UAAM,SAA8B,CAAC;AACrC,UAAM,OAAO,OAAO,KAAK,KAAK;AAC9B,UAAM,QAAQ;AAAA,MACZ,KAAK,IAAI,OAAO,QAAQ;AACtB,eAAO,GAAG,IAAI,MAAM,uBAAuB,MAAM,GAAG,CAAC;AAAA,MACvD,CAAC;AAAA,IACH;AACA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAKO,MAAM,4BAA4B,OACvC,uBACoC;AACpC,MAAI;AACF,UAAM,UAAW,MAAM;AAAA,MACrB,mBAAmB;AAAA,IACrB;AAEA,WAAO;AAAA,MACL,GAAG;AAAA,MACH;AAAA,IACF;AAAA,EACF,SAAS,OAAO;AACd,8BAAO,OAAO;AAAA,MACZ,OAAO;AAAA,IACT,CAAC;AAAA,EACH;AACF;","names":[]}
|
|
@@ -89,7 +89,7 @@ const watch = (options) => {
|
|
|
89
89
|
const buildAndWatchIntlayer = async (options) => {
|
|
90
90
|
const configuration = options?.configuration ?? getConfiguration();
|
|
91
91
|
await prepareIntlayer(configuration);
|
|
92
|
-
if (configuration.content.watch) {
|
|
92
|
+
if (configuration.content.watch | options.persistent) {
|
|
93
93
|
watch({ ...options, configuration });
|
|
94
94
|
}
|
|
95
95
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/chokidar/watcher.ts"],"sourcesContent":["import { relative } from 'path';\nimport {\n type IntlayerConfig,\n appLogger,\n getConfiguration,\n} from '@intlayer/config';\n/** @ts-ignore remove error Module '\"chokidar\"' has no exported member 'ChokidarOptions' */\nimport { type ChokidarOptions, watch as chokidarWatch } from 'chokidar';\nimport { getDictionariesPath } from '../getDictionariesPath';\nimport { loadLocalDictionaries } from '../loadDictionaries/loadLocalDictionaries';\nimport { buildDictionary } from '../transpiler/declaration_file_to_dictionary/index';\nimport { createDictionaryEntryPoint } from '../transpiler/dictionary_to_main/createDictionaryEntryPoint';\nimport {\n createTypes,\n createModuleAugmentation,\n} from '../transpiler/dictionary_to_type/index';\nimport { prepareIntlayer } from '../prepareIntlayer';\n\nexport const handleAdditionalContentDeclarationFile = async (\n filePath: string,\n configuration?: IntlayerConfig\n) => {\n const { content } =\n configuration ??\n getConfiguration({\n verbose: true,\n });\n\n // Process the file with the functionToRun\n appLogger(\n `Additional file detected: ${relative(content.baseDir, filePath)}`,\n {\n isVerbose: true,\n }\n );\n\n const localeDictionaries = await loadLocalDictionaries(filePath);\n\n const dictionariesPaths = await buildDictionary(localeDictionaries);\n\n createTypes(dictionariesPaths);\n\n createDictionaryEntryPoint();\n\n appLogger('Dictionaries built', {\n isVerbose: true,\n });\n\n createModuleAugmentation();\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n};\n\nexport const handleContentDeclarationFileChange = async (\n filePath: string,\n configuration?: IntlayerConfig\n) => {\n const { content } =\n configuration ??\n getConfiguration({\n verbose: true,\n });\n\n // Process the file with the functionToRun\n appLogger(`Change detected: ${relative(content.baseDir, filePath)}`, {\n isVerbose: true,\n });\n\n const localeDictionaries = await loadLocalDictionaries(filePath);\n const updatedDictionariesPaths = await buildDictionary(localeDictionaries);\n const allDictionariesPaths: string[] = getDictionariesPath();\n\n createTypes(updatedDictionariesPaths);\n appLogger('TypeScript types built', {\n isVerbose: true,\n });\n\n if (\n updatedDictionariesPaths.some((updatedDictionaryPath) =>\n allDictionariesPaths.includes(updatedDictionaryPath)\n )\n ) {\n createDictionaryEntryPoint();\n\n appLogger('Dictionary list built', {\n isVerbose: true,\n });\n\n createModuleAugmentation();\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n }\n};\n\ntype WatchOptions = ChokidarOptions & {\n configuration?: IntlayerConfig;\n};\n\n// Initialize chokidar watcher (non-persistent)\nexport const watch = (options?: WatchOptions) => {\n const configuration =\n options?.configuration ??\n getConfiguration({\n verbose: true,\n });\n\n const { watch: isWatchMode, watchedFilesPatternWithPath } =\n configuration.content;\n\n /** @ts-ignore remove error Expected 0-1 arguments, but got 2. */\n return chokidarWatch(watchedFilesPatternWithPath, {\n persistent: isWatchMode, // Make the watcher persistent\n ignoreInitial: true, // Process existing files\n ...options,\n })\n .on(\n 'add',\n async (filePath) =>\n await handleAdditionalContentDeclarationFile(filePath, configuration)\n )\n .on(\n 'change',\n async (filePath) =>\n await handleContentDeclarationFileChange(filePath, configuration)\n )\n .on('error', (error) =>\n appLogger('Watcher error: ' + error, {\n level: 'error',\n })\n );\n};\n\nexport const buildAndWatchIntlayer = async (options?: WatchOptions) => {\n const configuration = options?.configuration ?? getConfiguration();\n\n await prepareIntlayer(configuration);\n\n if (configuration.content.watch) {\n // Start watching (assuming watch is also async)\n watch({ ...options, configuration });\n }\n};\n"],"mappings":"AAAA,SAAS,gBAAgB;AACzB;AAAA,EAEE;AAAA,EACA;AAAA,OACK;AAEP,SAA+B,SAAS,qBAAqB;AAC7D,SAAS,2BAA2B;AACpC,SAAS,6BAA6B;AACtC,SAAS,uBAAuB;AAChC,SAAS,kCAAkC;AAC3C;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,uBAAuB;AAEzB,MAAM,yCAAyC,OACpD,UACA,kBACG;AACH,QAAM,EAAE,QAAQ,IACd,iBACA,iBAAiB;AAAA,IACf,SAAS;AAAA,EACX,CAAC;AAGH;AAAA,IACE,6BAA6B,SAAS,QAAQ,SAAS,QAAQ,CAAC;AAAA,IAChE;AAAA,MACE,WAAW;AAAA,IACb;AAAA,EACF;AAEA,QAAM,qBAAqB,MAAM,sBAAsB,QAAQ;AAE/D,QAAM,oBAAoB,MAAM,gBAAgB,kBAAkB;AAElE,cAAY,iBAAiB;AAE7B,6BAA2B;AAE3B,YAAU,sBAAsB;AAAA,IAC9B,WAAW;AAAA,EACb,CAAC;AAED,2BAAyB;AAEzB,YAAU,6BAA6B;AAAA,IACrC,WAAW;AAAA,EACb,CAAC;AACH;AAEO,MAAM,qCAAqC,OAChD,UACA,kBACG;AACH,QAAM,EAAE,QAAQ,IACd,iBACA,iBAAiB;AAAA,IACf,SAAS;AAAA,EACX,CAAC;AAGH,YAAU,oBAAoB,SAAS,QAAQ,SAAS,QAAQ,CAAC,IAAI;AAAA,IACnE,WAAW;AAAA,EACb,CAAC;AAED,QAAM,qBAAqB,MAAM,sBAAsB,QAAQ;AAC/D,QAAM,2BAA2B,MAAM,gBAAgB,kBAAkB;AACzE,QAAM,uBAAiC,oBAAoB;AAE3D,cAAY,wBAAwB;AACpC,YAAU,0BAA0B;AAAA,IAClC,WAAW;AAAA,EACb,CAAC;AAED,MACE,yBAAyB;AAAA,IAAK,CAAC,0BAC7B,qBAAqB,SAAS,qBAAqB;AAAA,EACrD,GACA;AACA,+BAA2B;AAE3B,cAAU,yBAAyB;AAAA,MACjC,WAAW;AAAA,IACb,CAAC;AAED,6BAAyB;AAEzB,cAAU,6BAA6B;AAAA,MACrC,WAAW;AAAA,IACb,CAAC;AAAA,EACH;AACF;AAOO,MAAM,QAAQ,CAAC,YAA2B;AAC/C,QAAM,gBACJ,SAAS,iBACT,iBAAiB;AAAA,IACf,SAAS;AAAA,EACX,CAAC;AAEH,QAAM,EAAE,OAAO,aAAa,4BAA4B,IACtD,cAAc;AAGhB,SAAO,cAAc,6BAA6B;AAAA,IAChD,YAAY;AAAA;AAAA,IACZ,eAAe;AAAA;AAAA,IACf,GAAG;AAAA,EACL,CAAC,EACE;AAAA,IACC;AAAA,IACA,OAAO,aACL,MAAM,uCAAuC,UAAU,aAAa;AAAA,EACxE,EACC;AAAA,IACC;AAAA,IACA,OAAO,aACL,MAAM,mCAAmC,UAAU,aAAa;AAAA,EACpE,EACC;AAAA,IAAG;AAAA,IAAS,CAAC,UACZ,UAAU,oBAAoB,OAAO;AAAA,MACnC,OAAO;AAAA,IACT,CAAC;AAAA,EACH;AACJ;AAEO,MAAM,wBAAwB,OAAO,YAA2B;AACrE,QAAM,gBAAgB,SAAS,iBAAiB,iBAAiB;AAEjE,QAAM,gBAAgB,aAAa;AAEnC,MAAI,cAAc,QAAQ,
|
|
1
|
+
{"version":3,"sources":["../../../src/chokidar/watcher.ts"],"sourcesContent":["import { relative } from 'path';\nimport {\n type IntlayerConfig,\n appLogger,\n getConfiguration,\n} from '@intlayer/config';\n/** @ts-ignore remove error Module '\"chokidar\"' has no exported member 'ChokidarOptions' */\nimport { type ChokidarOptions, watch as chokidarWatch } from 'chokidar';\nimport { getDictionariesPath } from '../getDictionariesPath';\nimport { loadLocalDictionaries } from '../loadDictionaries/loadLocalDictionaries';\nimport { buildDictionary } from '../transpiler/declaration_file_to_dictionary/index';\nimport { createDictionaryEntryPoint } from '../transpiler/dictionary_to_main/createDictionaryEntryPoint';\nimport {\n createTypes,\n createModuleAugmentation,\n} from '../transpiler/dictionary_to_type/index';\nimport { prepareIntlayer } from '../prepareIntlayer';\n\nexport const handleAdditionalContentDeclarationFile = async (\n filePath: string,\n configuration?: IntlayerConfig\n) => {\n const { content } =\n configuration ??\n getConfiguration({\n verbose: true,\n });\n\n // Process the file with the functionToRun\n appLogger(\n `Additional file detected: ${relative(content.baseDir, filePath)}`,\n {\n isVerbose: true,\n }\n );\n\n const localeDictionaries = await loadLocalDictionaries(filePath);\n\n const dictionariesPaths = await buildDictionary(localeDictionaries);\n\n createTypes(dictionariesPaths);\n\n createDictionaryEntryPoint();\n\n appLogger('Dictionaries built', {\n isVerbose: true,\n });\n\n createModuleAugmentation();\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n};\n\nexport const handleContentDeclarationFileChange = async (\n filePath: string,\n configuration?: IntlayerConfig\n) => {\n const { content } =\n configuration ??\n getConfiguration({\n verbose: true,\n });\n\n // Process the file with the functionToRun\n appLogger(`Change detected: ${relative(content.baseDir, filePath)}`, {\n isVerbose: true,\n });\n\n const localeDictionaries = await loadLocalDictionaries(filePath);\n const updatedDictionariesPaths = await buildDictionary(localeDictionaries);\n const allDictionariesPaths: string[] = getDictionariesPath();\n\n createTypes(updatedDictionariesPaths);\n appLogger('TypeScript types built', {\n isVerbose: true,\n });\n\n if (\n updatedDictionariesPaths.some((updatedDictionaryPath) =>\n allDictionariesPaths.includes(updatedDictionaryPath)\n )\n ) {\n createDictionaryEntryPoint();\n\n appLogger('Dictionary list built', {\n isVerbose: true,\n });\n\n createModuleAugmentation();\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n }\n};\n\ntype WatchOptions = ChokidarOptions & {\n configuration?: IntlayerConfig;\n};\n\n// Initialize chokidar watcher (non-persistent)\nexport const watch = (options?: WatchOptions) => {\n const configuration =\n options?.configuration ??\n getConfiguration({\n verbose: true,\n });\n\n const { watch: isWatchMode, watchedFilesPatternWithPath } =\n configuration.content;\n\n /** @ts-ignore remove error Expected 0-1 arguments, but got 2. */\n return chokidarWatch(watchedFilesPatternWithPath, {\n persistent: isWatchMode, // Make the watcher persistent\n ignoreInitial: true, // Process existing files\n ...options,\n })\n .on(\n 'add',\n async (filePath) =>\n await handleAdditionalContentDeclarationFile(filePath, configuration)\n )\n .on(\n 'change',\n async (filePath) =>\n await handleContentDeclarationFileChange(filePath, configuration)\n )\n .on('error', (error) =>\n appLogger('Watcher error: ' + error, {\n level: 'error',\n })\n );\n};\n\nexport const buildAndWatchIntlayer = async (options?: WatchOptions) => {\n const configuration = options?.configuration ?? getConfiguration();\n\n await prepareIntlayer(configuration);\n\n if (configuration.content.watch | options.persistent) {\n // Start watching (assuming watch is also async)\n watch({ ...options, configuration });\n }\n};\n"],"mappings":"AAAA,SAAS,gBAAgB;AACzB;AAAA,EAEE;AAAA,EACA;AAAA,OACK;AAEP,SAA+B,SAAS,qBAAqB;AAC7D,SAAS,2BAA2B;AACpC,SAAS,6BAA6B;AACtC,SAAS,uBAAuB;AAChC,SAAS,kCAAkC;AAC3C;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,uBAAuB;AAEzB,MAAM,yCAAyC,OACpD,UACA,kBACG;AACH,QAAM,EAAE,QAAQ,IACd,iBACA,iBAAiB;AAAA,IACf,SAAS;AAAA,EACX,CAAC;AAGH;AAAA,IACE,6BAA6B,SAAS,QAAQ,SAAS,QAAQ,CAAC;AAAA,IAChE;AAAA,MACE,WAAW;AAAA,IACb;AAAA,EACF;AAEA,QAAM,qBAAqB,MAAM,sBAAsB,QAAQ;AAE/D,QAAM,oBAAoB,MAAM,gBAAgB,kBAAkB;AAElE,cAAY,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AAA,IAAS,CAAC,UACZ,UAAU,oBAAoB,OAAO;AAAA,MACnC,OAAO;AAAA,IACT,CAAC;AAAA,EACH;AACJ;AAEO,MAAM,wBAAwB,OAAO,YAA2B;AACrE,QAAM,gBAAgB,SAAS,iBAAiB,iBAAiB;AAEjE,QAAM,gBAAgB,aAAa;AAEnC,MAAI,cAAc,QAAQ,QAAQ,QAAQ,YAAY;AAEpD,UAAM,EAAE,GAAG,SAAS,cAAc,CAAC;AAAA,EACrC;AACF;","names":[]}
|
|
@@ -1,63 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ESMxCJSRequire, getSandBoxContext } from "@intlayer/config";
|
|
3
|
-
import { buildSync } from "esbuild";
|
|
1
|
+
import { loadExternalFile } from "@intlayer/config";
|
|
4
2
|
import { processContentDeclaration } from "../transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.mjs";
|
|
5
|
-
const transformationOption = {
|
|
6
|
-
loader: {
|
|
7
|
-
".js": "js",
|
|
8
|
-
".jsx": "jsx",
|
|
9
|
-
".mjs": "js",
|
|
10
|
-
".ts": "ts",
|
|
11
|
-
".tsx": "tsx",
|
|
12
|
-
".cjs": "js",
|
|
13
|
-
".json": "json"
|
|
14
|
-
},
|
|
15
|
-
format: "cjs",
|
|
16
|
-
// Output format as commonjs
|
|
17
|
-
target: "es2017",
|
|
18
|
-
packages: "external",
|
|
19
|
-
write: false,
|
|
20
|
-
bundle: true
|
|
21
|
-
};
|
|
22
|
-
const loadContentDeclaration = (contentDeclarationFilePath) => {
|
|
23
|
-
let contentDeclaration = void 0;
|
|
24
|
-
const fileExtension = contentDeclarationFilePath.split(".").pop() ?? "";
|
|
25
|
-
try {
|
|
26
|
-
if (fileExtension === "json") {
|
|
27
|
-
return ESMxCJSRequire(contentDeclarationFilePath);
|
|
28
|
-
}
|
|
29
|
-
const moduleResult = buildSync({
|
|
30
|
-
entryPoints: [contentDeclarationFilePath],
|
|
31
|
-
...transformationOption
|
|
32
|
-
});
|
|
33
|
-
const moduleResultString = moduleResult.outputFiles?.[0].text;
|
|
34
|
-
if (!moduleResultString) {
|
|
35
|
-
console.error("Configuration file could not be loaded.");
|
|
36
|
-
return void 0;
|
|
37
|
-
}
|
|
38
|
-
const sandboxContext = getSandBoxContext();
|
|
39
|
-
runInNewContext(moduleResultString, sandboxContext);
|
|
40
|
-
if (sandboxContext.exports.default && Object.keys(sandboxContext.exports.default).length > 0) {
|
|
41
|
-
contentDeclaration = sandboxContext.exports.default;
|
|
42
|
-
} else if (sandboxContext.module.exports.defaults && Object.keys(sandboxContext.module.exports.defaults).length > 0) {
|
|
43
|
-
contentDeclaration = sandboxContext.module.exports.default;
|
|
44
|
-
} else if (sandboxContext.module.exports.default && Object.keys(sandboxContext.module.exports.default).length > 0) {
|
|
45
|
-
contentDeclaration = sandboxContext.module.exports.default;
|
|
46
|
-
} else if (sandboxContext.module.exports && Object.keys(sandboxContext.module.exports).length > 0) {
|
|
47
|
-
contentDeclaration = sandboxContext.module.exports;
|
|
48
|
-
}
|
|
49
|
-
if (typeof contentDeclaration === "undefined") {
|
|
50
|
-
console.error("Configuration file could not be loaded.");
|
|
51
|
-
return void 0;
|
|
52
|
-
}
|
|
53
|
-
return contentDeclaration;
|
|
54
|
-
} catch (error) {
|
|
55
|
-
console.error("Error:", error);
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
3
|
const loadContentDeclarations = async (contentDeclarationFilePath) => {
|
|
59
4
|
const contentDeclarations = contentDeclarationFilePath.map((path) => ({
|
|
60
|
-
...
|
|
5
|
+
...loadExternalFile(path),
|
|
61
6
|
filePath: path
|
|
62
7
|
}));
|
|
63
8
|
const resultDictionariesPaths = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/loadDictionaries/loadContentDeclaration.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../src/loadDictionaries/loadContentDeclaration.ts"],"sourcesContent":["import { loadExternalFile } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { processContentDeclaration } from '../transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration';\n\nexport const loadContentDeclarations = async (\n contentDeclarationFilePath: string[]\n): Promise<Dictionary[]> => {\n const contentDeclarations = contentDeclarationFilePath.map((path) => ({\n ...loadExternalFile(path),\n filePath: path,\n }));\n const resultDictionariesPaths: Dictionary[] = [];\n\n for await (const contentDeclaration of contentDeclarations) {\n if (!contentDeclaration) {\n continue;\n }\n\n const processedContentDeclaration = await processContentDeclaration(\n contentDeclaration as Dictionary\n );\n\n if (!processedContentDeclaration) {\n continue;\n }\n\n resultDictionariesPaths.push(processedContentDeclaration);\n }\n\n return resultDictionariesPaths;\n};\n"],"mappings":"AAAA,SAAS,wBAAwB;AAEjC,SAAS,iCAAiC;AAEnC,MAAM,0BAA0B,OACrC,+BAC0B;AAC1B,QAAM,sBAAsB,2BAA2B,IAAI,CAAC,UAAU;AAAA,IACpE,GAAG,iBAAiB,IAAI;AAAA,IACxB,UAAU;AAAA,EACZ,EAAE;AACF,QAAM,0BAAwC,CAAC;AAE/C,mBAAiB,sBAAsB,qBAAqB;AAC1D,QAAI,CAAC,oBAAoB;AACvB;AAAA,IACF;AAEA,UAAM,8BAA8B,MAAM;AAAA,MACxC;AAAA,IACF;AAEA,QAAI,CAAC,6BAA6B;AAChC;AAAA,IACF;AAEA,4BAAwB,KAAK,2BAA2B;AAAA,EAC1D;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { logger } from "@intlayer/config/client";
|
|
2
|
-
const
|
|
3
|
-
if (
|
|
4
|
-
await
|
|
2
|
+
const resolveContentPromises = async (entry) => {
|
|
3
|
+
if (entry && typeof entry.then === "function") {
|
|
4
|
+
const awaited = await entry;
|
|
5
|
+
return resolveContentPromises(awaited);
|
|
5
6
|
}
|
|
6
|
-
};
|
|
7
|
-
const processFunctionResults = async (entry) => {
|
|
8
7
|
if (typeof entry === "function") {
|
|
9
|
-
const result =
|
|
10
|
-
return
|
|
8
|
+
const result = entry();
|
|
9
|
+
return resolveContentPromises(result);
|
|
11
10
|
}
|
|
12
11
|
if (Array.isArray(entry)) {
|
|
13
12
|
return Promise.all(
|
|
14
|
-
entry.map(async (item) =>
|
|
13
|
+
entry.map(async (item) => resolveContentPromises(item))
|
|
15
14
|
);
|
|
16
15
|
}
|
|
17
16
|
if (entry && typeof entry === "object") {
|
|
@@ -19,7 +18,7 @@ const processFunctionResults = async (entry) => {
|
|
|
19
18
|
const keys = Object.keys(entry);
|
|
20
19
|
await Promise.all(
|
|
21
20
|
keys.map(async (key) => {
|
|
22
|
-
result[key] = await
|
|
21
|
+
result[key] = await resolveContentPromises(entry[key]);
|
|
23
22
|
})
|
|
24
23
|
);
|
|
25
24
|
return result;
|
|
@@ -28,7 +27,7 @@ const processFunctionResults = async (entry) => {
|
|
|
28
27
|
};
|
|
29
28
|
const processContentDeclaration = async (contentDeclaration) => {
|
|
30
29
|
try {
|
|
31
|
-
const content = await
|
|
30
|
+
const content = await resolveContentPromises(
|
|
32
31
|
contentDeclaration.content
|
|
33
32
|
);
|
|
34
33
|
return {
|
|
@@ -42,6 +41,7 @@ const processContentDeclaration = async (contentDeclaration) => {
|
|
|
42
41
|
}
|
|
43
42
|
};
|
|
44
43
|
export {
|
|
45
|
-
processContentDeclaration
|
|
44
|
+
processContentDeclaration,
|
|
45
|
+
resolveContentPromises
|
|
46
46
|
};
|
|
47
47
|
//# sourceMappingURL=processContentDeclaration.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.ts"],"sourcesContent":["import { logger } from '@intlayer/config/client';\nimport type { Dictionary } from '@intlayer/core';\n\n/**\n *
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.ts"],"sourcesContent":["import { logger } from '@intlayer/config/client';\nimport type { Dictionary } from '@intlayer/core';\n\n/**\n * A more \"unified\" approach where each type (function, array, object, primitive)\n * is handled inside the main recursive body.\n */\nexport const resolveContentPromises = async <T = unknown>(\n entry: any\n): Promise<T> => {\n // Check if entry is a Promise (Thenable)\n if (entry && typeof entry.then === 'function') {\n const awaited = await entry;\n return resolveContentPromises(awaited);\n }\n\n // If entry is a function, invoke it and process the result\n if (typeof entry === 'function') {\n const result = entry();\n return resolveContentPromises(result);\n }\n\n if (Array.isArray(entry)) {\n return Promise.all(\n entry.map(async (item) => resolveContentPromises(item))\n ) as unknown as T;\n }\n\n if (entry && typeof entry === 'object') {\n const result: Record<string, any> = {};\n const keys = Object.keys(entry);\n await Promise.all(\n keys.map(async (key) => {\n result[key] = await resolveContentPromises(entry[key]);\n })\n );\n return result as T;\n }\n\n return entry as T;\n};\n\n/**\n * Function to load, process the module and return the Intlayer Dictionary from the module file\n */\nexport const processContentDeclaration = async (\n contentDeclaration: Dictionary\n): Promise<Dictionary | undefined> => {\n try {\n const content = (await resolveContentPromises(\n contentDeclaration.content\n )) as Dictionary['content'];\n\n return {\n ...contentDeclaration,\n content,\n } as Dictionary;\n } catch (error) {\n logger(error, {\n level: 'error',\n });\n }\n};\n"],"mappings":"AAAA,SAAS,cAAc;AAOhB,MAAM,yBAAyB,OACpC,UACe;AAEf,MAAI,SAAS,OAAO,MAAM,SAAS,YAAY;AAC7C,UAAM,UAAU,MAAM;AACtB,WAAO,uBAAuB,OAAO;AAAA,EACvC;AAGA,MAAI,OAAO,UAAU,YAAY;AAC/B,UAAM,SAAS,MAAM;AACrB,WAAO,uBAAuB,MAAM;AAAA,EACtC;AAEA,MAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,WAAO,QAAQ;AAAA,MACb,MAAM,IAAI,OAAO,SAAS,uBAAuB,IAAI,CAAC;AAAA,IACxD;AAAA,EACF;AAEA,MAAI,SAAS,OAAO,UAAU,UAAU;AACtC,UAAM,SAA8B,CAAC;AACrC,UAAM,OAAO,OAAO,KAAK,KAAK;AAC9B,UAAM,QAAQ;AAAA,MACZ,KAAK,IAAI,OAAO,QAAQ;AACtB,eAAO,GAAG,IAAI,MAAM,uBAAuB,MAAM,GAAG,CAAC;AAAA,MACvD,CAAC;AAAA,IACH;AACA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAKO,MAAM,4BAA4B,OACvC,uBACoC;AACpC,MAAI;AACF,UAAM,UAAW,MAAM;AAAA,MACrB,mBAAmB;AAAA,IACrB;AAEA,WAAO;AAAA,MACL,GAAG;AAAA,MACH;AAAA,IACF;AAAA,EACF,SAAS,OAAO;AACd,WAAO,OAAO;AAAA,MACZ,OAAO;AAAA,IACT,CAAC;AAAA,EACH;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadContentDeclaration.d.ts","sourceRoot":"","sources":["../../../src/loadDictionaries/loadContentDeclaration.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"loadContentDeclaration.d.ts","sourceRoot":"","sources":["../../../src/loadDictionaries/loadContentDeclaration.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGjD,eAAO,MAAM,uBAAuB,GAClC,4BAA4B,MAAM,EAAE,KACnC,OAAO,CAAC,UAAU,EAAE,CAwBtB,CAAC"}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import type { Dictionary } from '@intlayer/core';
|
|
2
|
+
/**
|
|
3
|
+
* A more "unified" approach where each type (function, array, object, primitive)
|
|
4
|
+
* is handled inside the main recursive body.
|
|
5
|
+
*/
|
|
6
|
+
export declare const resolveContentPromises: <T = unknown>(entry: any) => Promise<T>;
|
|
2
7
|
/**
|
|
3
8
|
* Function to load, process the module and return the Intlayer Dictionary from the module file
|
|
4
9
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processContentDeclaration.d.ts","sourceRoot":"","sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"processContentDeclaration.d.ts","sourceRoot":"","sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD;;;GAGG;AACH,eAAO,MAAM,sBAAsB,GAAU,CAAC,GAAG,OAAO,EACtD,OAAO,GAAG,KACT,OAAO,CAAC,CAAC,CA+BX,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,yBAAyB,GACpC,oBAAoB,UAAU,KAC7B,OAAO,CAAC,UAAU,GAAG,SAAS,CAehC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/chokidar",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Uses chokidar to scan and build Intlayer declaration files into dictionaries based on Intlayer configuration.",
|
|
6
6
|
"keywords": [
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"url": "https://github.com/aymericzip"
|
|
34
34
|
}
|
|
35
35
|
],
|
|
36
|
+
"sideEffects": false,
|
|
36
37
|
"exports": {
|
|
37
38
|
".": {
|
|
38
39
|
"types": "./dist/types/index.d.ts",
|
|
@@ -59,13 +60,12 @@
|
|
|
59
60
|
"chokidar": "^3.6.0",
|
|
60
61
|
"crypto-js": "^4.2.0",
|
|
61
62
|
"deepmerge": "^4.3.1",
|
|
62
|
-
"esbuild": "^0.24.2",
|
|
63
63
|
"fast-glob": "^3.3.3",
|
|
64
64
|
"p-limit": "^3.1.0",
|
|
65
|
-
"@intlayer/
|
|
66
|
-
"@intlayer/
|
|
67
|
-
"@intlayer/
|
|
68
|
-
"intlayer": "5.
|
|
65
|
+
"@intlayer/config": "5.3.1",
|
|
66
|
+
"@intlayer/api": "5.3.1",
|
|
67
|
+
"@intlayer/core": "5.3.1",
|
|
68
|
+
"intlayer": "5.3.1"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@changesets/cli": "2.27.12",
|
|
@@ -79,8 +79,8 @@
|
|
|
79
79
|
"tsc-alias": "^1.8.10",
|
|
80
80
|
"tsup": "^8.3.5",
|
|
81
81
|
"typescript": "^5.7.3",
|
|
82
|
+
"@intlayer/backend": "5.3.1",
|
|
82
83
|
"@utils/eslint-config": "1.0.4",
|
|
83
|
-
"@intlayer/backend": "5.2.9",
|
|
84
84
|
"@utils/ts-config": "1.0.4",
|
|
85
85
|
"@utils/ts-config-types": "1.0.4",
|
|
86
86
|
"@utils/tsup-config": "1.0.4"
|
|
@@ -88,10 +88,10 @@
|
|
|
88
88
|
"peerDependencies": {
|
|
89
89
|
"fast-glob": "^3.3.3",
|
|
90
90
|
"react": ">=16.0.0",
|
|
91
|
-
"@intlayer/
|
|
92
|
-
"
|
|
93
|
-
"@intlayer/
|
|
94
|
-
"intlayer": "5.
|
|
91
|
+
"@intlayer/core": "5.3.1",
|
|
92
|
+
"intlayer": "5.3.1",
|
|
93
|
+
"@intlayer/api": "5.3.1",
|
|
94
|
+
"@intlayer/config": "5.3.1"
|
|
95
95
|
},
|
|
96
96
|
"engines": {
|
|
97
97
|
"node": ">=14.18"
|