@intlayer/chokidar 5.2.9 → 5.3.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.
@@ -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
- ...loadContentDeclaration(path),
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 { runInNewContext } from 'vm';\nimport { ESMxCJSRequire, getSandBoxContext } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { type BuildOptions, buildSync, type BuildResult } from 'esbuild';\nimport { processContentDeclaration } from '../transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration';\n\nconst transformationOption: BuildOptions = {\n loader: {\n '.js': 'js',\n '.jsx': 'jsx',\n '.mjs': 'js',\n '.ts': 'ts',\n '.tsx': 'tsx',\n '.cjs': 'js',\n '.json': 'json',\n },\n format: 'cjs', // Output format as commonjs\n target: 'es2017',\n packages: 'external',\n write: false,\n bundle: true,\n};\n\n/**\n * Load the content declaration from the given path\n *\n * Accepts JSON, JS, MJS and TS files as configuration\n */\nconst loadContentDeclaration = (\n contentDeclarationFilePath: string\n): Dictionary | undefined => {\n let contentDeclaration: Dictionary | undefined = undefined;\n\n const fileExtension = contentDeclarationFilePath.split('.').pop() ?? '';\n\n try {\n if (fileExtension === 'json') {\n // Assume JSON\n return ESMxCJSRequire(contentDeclarationFilePath);\n }\n\n // Rest is JS, MJS or TS\n\n const moduleResult: BuildResult = buildSync({\n entryPoints: [contentDeclarationFilePath],\n\n ...transformationOption,\n });\n\n const moduleResultString = moduleResult.outputFiles?.[0].text;\n\n if (!moduleResultString) {\n console.error('Configuration file could not be loaded.');\n return undefined;\n }\n\n const sandboxContext = getSandBoxContext();\n\n runInNewContext(moduleResultString, sandboxContext);\n\n if (\n sandboxContext.exports.default &&\n Object.keys(sandboxContext.exports.default).length > 0\n ) {\n // ES Module\n contentDeclaration = sandboxContext.exports.default;\n } else if (\n sandboxContext.module.exports.defaults &&\n Object.keys(sandboxContext.module.exports.defaults).length > 0\n ) {\n // CommonJS\n contentDeclaration = sandboxContext.module.exports.default;\n } else if (\n sandboxContext.module.exports.default &&\n Object.keys(sandboxContext.module.exports.default).length > 0\n ) {\n // ES Module\n contentDeclaration = sandboxContext.module.exports.default;\n } else if (\n sandboxContext.module.exports &&\n Object.keys(sandboxContext.module.exports).length > 0\n ) {\n // Other\n contentDeclaration = sandboxContext.module.exports;\n }\n\n if (typeof contentDeclaration === 'undefined') {\n console.error('Configuration file could not be loaded.');\n return undefined;\n }\n\n return contentDeclaration;\n } catch (error) {\n console.error('Error:', error);\n }\n};\n\nexport const loadContentDeclarations = async (\n contentDeclarationFilePath: string[]\n): Promise<Dictionary[]> => {\n const contentDeclarations = contentDeclarationFilePath.map((path) => ({\n ...loadContentDeclaration(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,gBAAgC;AAChC,oBAAkD;AAElD,qBAA+D;AAC/D,uCAA0C;AAE1C,MAAM,uBAAqC;AAAA,EACzC,QAAQ;AAAA,IACN,OAAO;AAA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,MAAM,yCAAyC;AACvD,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT,SAAS,OAAO;AACd,YAAQ,MAAM,UAAU,KAAK;AAAA,EAC/B;AACF;AAEO,MAAM,0BAA0B,OACrC,+BAC0B;AAC1B,QAAM,sBAAsB,2BAA2B,IAAI,CAAC,UAAU;AAAA,IACpE,GAAG,uBAAuB,IAAI;AAAA,IAC9B,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":[]}
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":[]}
@@ -22,19 +22,18 @@ __export(processContentDeclaration_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(processContentDeclaration_exports);
24
24
  var import_client = require("@intlayer/config/client");
25
- const awaitFunction = async (fn) => {
26
- if (fn && typeof fn.then === "function") {
27
- await fn;
28
- }
29
- };
30
25
  const processFunctionResults = async (entry) => {
26
+ if (entry && typeof entry.then === "function") {
27
+ const awaited = await entry;
28
+ return processFunctionResults(awaited);
29
+ }
31
30
  if (typeof entry === "function") {
32
- const result = await awaitFunction(entry());
33
- return await processFunctionResults(result);
31
+ const result = entry();
32
+ return processFunctionResults(result);
34
33
  }
35
34
  if (Array.isArray(entry)) {
36
35
  return Promise.all(
37
- entry.map(async (item) => await processFunctionResults(item))
36
+ entry.map(async (item) => processFunctionResults(item))
38
37
  );
39
38
  }
40
39
  if (entry && typeof entry === "object") {
@@ -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 * Helper that awaits either a synchronous or asynchronous value.\n */\nconst awaitFunction = async (fn: any) => {\n // Check if result is a Promise (Thenable)\n\n if (fn && typeof fn.then === 'function') {\n // It's a Promise, so wait for it to resolve\n await fn;\n }\n // If not a Promise, it will just execute without awaiting\n};\n\n/**\n * A more \"unified\" approach where each type (function, array, object, primitive)\n * is handled inside the main recursive body.\n */\nconst processFunctionResults = async <T = unknown>(entry: any): Promise<T> => {\n // If entry is a function, invoke it and process the result\n if (typeof entry === 'function') {\n const result = await awaitFunction(entry());\n // Recursively process the result in case it contains nested arrays/objects/functions\n return await processFunctionResults(result);\n }\n\n // If entry is an array, recursively process each item\n if (Array.isArray(entry)) {\n return Promise.all(\n entry.map(async (item) => await processFunctionResults(item))\n ) as unknown as T;\n }\n\n // If entry is an object, recursively process each property\n if (entry && typeof entry === 'object') {\n const result: Record<string, any> = {};\n // Use Promise.all to handle any async resolution for the properties\n const keys = Object.keys(entry);\n await Promise.all(\n keys.map(async (key) => {\n result[key] = await processFunctionResults(entry[key]);\n })\n );\n return result as T;\n }\n\n // Otherwise, it's a primitive value—just return as is\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 processFunctionResults(\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,oBAAuB;AAMvB,MAAM,gBAAgB,OAAO,OAAY;AAGvC,MAAI,MAAM,OAAO,GAAG,SAAS,YAAY;AAEvC,UAAM;AAAA,EACR;AAEF;AAMA,MAAM,yBAAyB,OAAoB,UAA2B;AAE5E,MAAI,OAAO,UAAU,YAAY;AAC/B,UAAM,SAAS,MAAM,cAAc,MAAM,CAAC;AAE1C,WAAO,MAAM,uBAAuB,MAAM;AAAA,EAC5C;AAGA,MAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,WAAO,QAAQ;AAAA,MACb,MAAM,IAAI,OAAO,SAAS,MAAM,uBAAuB,IAAI,CAAC;AAAA,IAC9D;AAAA,EACF;AAGA,MAAI,SAAS,OAAO,UAAU,UAAU;AACtC,UAAM,SAA8B,CAAC;AAErC,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;AAGA,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":[]}
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 */\nconst processFunctionResults = async <T = unknown>(entry: any): Promise<T> => {\n // Check if entry is a Promise (Thenable)\n if (entry && typeof entry.then === 'function') {\n const awaited = await entry;\n return processFunctionResults(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 processFunctionResults(result);\n }\n\n if (Array.isArray(entry)) {\n return Promise.all(\n entry.map(async (item) => processFunctionResults(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 processFunctionResults(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 processFunctionResults(\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,oBAAuB;AAOvB,MAAM,yBAAyB,OAAoB,UAA2B;AAE5E,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":[]}
@@ -1,63 +1,8 @@
1
- import { runInNewContext } from "vm";
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
- ...loadContentDeclaration(path),
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 { runInNewContext } from 'vm';\nimport { ESMxCJSRequire, getSandBoxContext } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { type BuildOptions, buildSync, type BuildResult } from 'esbuild';\nimport { processContentDeclaration } from '../transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration';\n\nconst transformationOption: BuildOptions = {\n loader: {\n '.js': 'js',\n '.jsx': 'jsx',\n '.mjs': 'js',\n '.ts': 'ts',\n '.tsx': 'tsx',\n '.cjs': 'js',\n '.json': 'json',\n },\n format: 'cjs', // Output format as commonjs\n target: 'es2017',\n packages: 'external',\n write: false,\n bundle: true,\n};\n\n/**\n * Load the content declaration from the given path\n *\n * Accepts JSON, JS, MJS and TS files as configuration\n */\nconst loadContentDeclaration = (\n contentDeclarationFilePath: string\n): Dictionary | undefined => {\n let contentDeclaration: Dictionary | undefined = undefined;\n\n const fileExtension = contentDeclarationFilePath.split('.').pop() ?? '';\n\n try {\n if (fileExtension === 'json') {\n // Assume JSON\n return ESMxCJSRequire(contentDeclarationFilePath);\n }\n\n // Rest is JS, MJS or TS\n\n const moduleResult: BuildResult = buildSync({\n entryPoints: [contentDeclarationFilePath],\n\n ...transformationOption,\n });\n\n const moduleResultString = moduleResult.outputFiles?.[0].text;\n\n if (!moduleResultString) {\n console.error('Configuration file could not be loaded.');\n return undefined;\n }\n\n const sandboxContext = getSandBoxContext();\n\n runInNewContext(moduleResultString, sandboxContext);\n\n if (\n sandboxContext.exports.default &&\n Object.keys(sandboxContext.exports.default).length > 0\n ) {\n // ES Module\n contentDeclaration = sandboxContext.exports.default;\n } else if (\n sandboxContext.module.exports.defaults &&\n Object.keys(sandboxContext.module.exports.defaults).length > 0\n ) {\n // CommonJS\n contentDeclaration = sandboxContext.module.exports.default;\n } else if (\n sandboxContext.module.exports.default &&\n Object.keys(sandboxContext.module.exports.default).length > 0\n ) {\n // ES Module\n contentDeclaration = sandboxContext.module.exports.default;\n } else if (\n sandboxContext.module.exports &&\n Object.keys(sandboxContext.module.exports).length > 0\n ) {\n // Other\n contentDeclaration = sandboxContext.module.exports;\n }\n\n if (typeof contentDeclaration === 'undefined') {\n console.error('Configuration file could not be loaded.');\n return undefined;\n }\n\n return contentDeclaration;\n } catch (error) {\n console.error('Error:', error);\n }\n};\n\nexport const loadContentDeclarations = async (\n contentDeclarationFilePath: string[]\n): Promise<Dictionary[]> => {\n const contentDeclarations = contentDeclarationFilePath.map((path) => ({\n ...loadContentDeclaration(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,uBAAuB;AAChC,SAAS,gBAAgB,yBAAyB;AAElD,SAA4B,iBAAmC;AAC/D,SAAS,iCAAiC;AAE1C,MAAM,uBAAqC;AAAA,EACzC,QAAQ;AAAA,IACN,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,SAAS;AAAA,EACX;AAAA,EACA,QAAQ;AAAA;AAAA,EACR,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,OAAO;AAAA,EACP,QAAQ;AACV;AAOA,MAAM,yBAAyB,CAC7B,+BAC2B;AAC3B,MAAI,qBAA6C;AAEjD,QAAM,gBAAgB,2BAA2B,MAAM,GAAG,EAAE,IAAI,KAAK;AAErE,MAAI;AACF,QAAI,kBAAkB,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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
+ {"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 awaitFunction = async (fn) => {
3
- if (fn && typeof fn.then === "function") {
4
- await fn;
5
- }
6
- };
7
2
  const processFunctionResults = async (entry) => {
3
+ if (entry && typeof entry.then === "function") {
4
+ const awaited = await entry;
5
+ return processFunctionResults(awaited);
6
+ }
8
7
  if (typeof entry === "function") {
9
- const result = await awaitFunction(entry());
10
- return await processFunctionResults(result);
8
+ const result = entry();
9
+ return processFunctionResults(result);
11
10
  }
12
11
  if (Array.isArray(entry)) {
13
12
  return Promise.all(
14
- entry.map(async (item) => await processFunctionResults(item))
13
+ entry.map(async (item) => processFunctionResults(item))
15
14
  );
16
15
  }
17
16
  if (entry && typeof entry === "object") {
@@ -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 * Helper that awaits either a synchronous or asynchronous value.\n */\nconst awaitFunction = async (fn: any) => {\n // Check if result is a Promise (Thenable)\n\n if (fn && typeof fn.then === 'function') {\n // It's a Promise, so wait for it to resolve\n await fn;\n }\n // If not a Promise, it will just execute without awaiting\n};\n\n/**\n * A more \"unified\" approach where each type (function, array, object, primitive)\n * is handled inside the main recursive body.\n */\nconst processFunctionResults = async <T = unknown>(entry: any): Promise<T> => {\n // If entry is a function, invoke it and process the result\n if (typeof entry === 'function') {\n const result = await awaitFunction(entry());\n // Recursively process the result in case it contains nested arrays/objects/functions\n return await processFunctionResults(result);\n }\n\n // If entry is an array, recursively process each item\n if (Array.isArray(entry)) {\n return Promise.all(\n entry.map(async (item) => await processFunctionResults(item))\n ) as unknown as T;\n }\n\n // If entry is an object, recursively process each property\n if (entry && typeof entry === 'object') {\n const result: Record<string, any> = {};\n // Use Promise.all to handle any async resolution for the properties\n const keys = Object.keys(entry);\n await Promise.all(\n keys.map(async (key) => {\n result[key] = await processFunctionResults(entry[key]);\n })\n );\n return result as T;\n }\n\n // Otherwise, it's a primitive value—just return as is\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 processFunctionResults(\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;AAMvB,MAAM,gBAAgB,OAAO,OAAY;AAGvC,MAAI,MAAM,OAAO,GAAG,SAAS,YAAY;AAEvC,UAAM;AAAA,EACR;AAEF;AAMA,MAAM,yBAAyB,OAAoB,UAA2B;AAE5E,MAAI,OAAO,UAAU,YAAY;AAC/B,UAAM,SAAS,MAAM,cAAc,MAAM,CAAC;AAE1C,WAAO,MAAM,uBAAuB,MAAM;AAAA,EAC5C;AAGA,MAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,WAAO,QAAQ;AAAA,MACb,MAAM,IAAI,OAAO,SAAS,MAAM,uBAAuB,IAAI,CAAC;AAAA,IAC9D;AAAA,EACF;AAGA,MAAI,SAAS,OAAO,UAAU,UAAU;AACtC,UAAM,SAA8B,CAAC;AAErC,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;AAGA,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
+ {"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 */\nconst processFunctionResults = async <T = unknown>(entry: any): Promise<T> => {\n // Check if entry is a Promise (Thenable)\n if (entry && typeof entry.then === 'function') {\n const awaited = await entry;\n return processFunctionResults(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 processFunctionResults(result);\n }\n\n if (Array.isArray(entry)) {\n return Promise.all(\n entry.map(async (item) => processFunctionResults(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 processFunctionResults(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 processFunctionResults(\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;AAOvB,MAAM,yBAAyB,OAAoB,UAA2B;AAE5E,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":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AA+FjD,eAAO,MAAM,uBAAuB,GAClC,4BAA4B,MAAM,EAAE,KACnC,OAAO,CAAC,UAAU,EAAE,CAwBtB,CAAC"}
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 +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;AAmDjD;;GAEG;AACH,eAAO,MAAM,yBAAyB,GACpC,oBAAoB,UAAU,KAC7B,OAAO,CAAC,UAAU,GAAG,SAAS,CAehC,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;AAuCjD;;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.2.9",
3
+ "version": "5.3.0",
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/api": "5.2.9",
66
- "@intlayer/core": "5.2.9",
67
- "@intlayer/config": "5.2.9",
68
- "intlayer": "5.2.9"
65
+ "@intlayer/api": "5.3.0",
66
+ "@intlayer/config": "5.3.0",
67
+ "@intlayer/core": "5.3.0",
68
+ "intlayer": "5.3.0"
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.0",
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/config": "5.2.9",
92
- "@intlayer/api": "5.2.9",
93
- "@intlayer/core": "5.2.9",
94
- "intlayer": "5.2.9"
91
+ "@intlayer/api": "5.3.0",
92
+ "@intlayer/config": "5.3.0",
93
+ "@intlayer/core": "5.3.0",
94
+ "intlayer": "5.3.0"
95
95
  },
96
96
  "engines": {
97
97
  "node": ">=14.18"