@intlayer/config 7.5.12 → 7.5.13
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/configFile/searchConfigurationFile.cjs +2 -0
- package/dist/cjs/configFile/searchConfigurationFile.cjs.map +1 -1
- package/dist/cjs/defaultValues/content.cjs +2 -0
- package/dist/cjs/defaultValues/content.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/loadExternalFile/loadExternalFile.cjs +10 -14
- package/dist/cjs/loadExternalFile/loadExternalFile.cjs.map +1 -1
- package/dist/cjs/loadExternalFile/parseFileContent.cjs +1 -1
- package/dist/cjs/loadExternalFile/{transpileTSToMJS.cjs → transpileTSToCJS.cjs} +6 -6
- package/dist/cjs/loadExternalFile/{transpileTSToMJS.cjs.map → transpileTSToCJS.cjs.map} +1 -1
- package/dist/esm/configFile/searchConfigurationFile.mjs +2 -0
- package/dist/esm/configFile/searchConfigurationFile.mjs.map +1 -1
- package/dist/esm/defaultValues/content.mjs +2 -0
- package/dist/esm/defaultValues/content.mjs.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/loadExternalFile/loadExternalFile.mjs +9 -14
- package/dist/esm/loadExternalFile/loadExternalFile.mjs.map +1 -1
- package/dist/esm/loadExternalFile/parseFileContent.mjs +1 -1
- package/dist/esm/loadExternalFile/{transpileTSToMJS.mjs → transpileTSToCJS.mjs} +5 -5
- package/dist/esm/loadExternalFile/{transpileTSToMJS.mjs.map → transpileTSToCJS.mjs.map} +1 -1
- package/dist/types/configFile/searchConfigurationFile.d.ts +1 -1
- package/dist/types/configFile/searchConfigurationFile.d.ts.map +1 -1
- package/dist/types/defaultValues/content.d.ts.map +1 -1
- package/dist/types/loadExternalFile/loadExternalFile.d.ts.map +1 -1
- package/dist/types/loadExternalFile/transpileTSToCJS.d.ts +9 -0
- package/dist/types/loadExternalFile/transpileTSToCJS.d.ts.map +1 -0
- package/package.json +5 -4
- package/dist/types/loadExternalFile/transpileTSToMJS.d.ts +0 -9
- package/dist/types/loadExternalFile/transpileTSToMJS.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"searchConfigurationFile.cjs","names":["configurationFilePath: string | undefined","getPackageJsonPath"],"sources":["../../../src/configFile/searchConfigurationFile.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport { logger } from '../logger';\nimport { getPackageJsonPath } from '../utils/getPackageJsonPath';\n\nexport const configurationFilesCandidates = [\n 'intlayer.config.ts',\n 'intlayer.config.js',\n 'intlayer.config.json',\n 'intlayer.config.cjs',\n 'intlayer.config.mjs',\n '.intlayerrc',\n] as const;\n\ntype SearchConfigurationFileResult = {\n configurationFilePath?: string;\n numCustomConfiguration: number;\n};\n\n/**\n * Search for the configuration file in the given path\n *\n * List of detected configuration files:\n * - intlayer.config.ts\n * - intlayer.config.js\n * - intlayer.config.json\n * - intlayer.config.cjs\n * - intlayer.config.mjs\n * - .intlayerrc\n */\nexport const searchConfigurationFile = (\n startDir: string\n): SearchConfigurationFileResult => {\n let configurationFilePath: string | undefined;\n let numCustomConfiguration = 0;\n\n const { baseDir } = getPackageJsonPath(startDir);\n\n for (const fileName of configurationFilesCandidates) {\n try {\n const filePath = resolve(baseDir, fileName);\n\n // Check if the file exists\n if (!existsSync(filePath)) {\n } else {\n numCustomConfiguration += 1;\n\n if (!configurationFilePath) {\n configurationFilePath = filePath;\n }\n }\n } catch (error) {\n // Return \"Cannot use import statement outside a module\"\n logger(`${fileName}: ${error as string}`, { level: 'error' });\n }\n }\n\n return { configurationFilePath, numCustomConfiguration };\n};\n"],"mappings":";;;;;;;AAKA,MAAa,+BAA+B;CAC1C;CACA;CACA;CACA;CACA;CACA;CACD;;;;;;;;;;;;AAkBD,MAAa,2BACX,aACkC;CAClC,IAAIA;CACJ,IAAI,yBAAyB;CAE7B,MAAM,EAAE,YAAYC,oDAAmB,SAAS;AAEhD,MAAK,MAAM,YAAY,6BACrB,KAAI;EACF,MAAM,kCAAmB,SAAS,SAAS;AAG3C,MAAI,yBAAY,SAAS,EAAE,QACpB;AACL,6BAA0B;AAE1B,OAAI,CAAC,sBACH,yBAAwB;;UAGrB,OAAO;AAEd,wBAAO,GAAG,SAAS,IAAI,SAAmB,EAAE,OAAO,SAAS,CAAC;;AAIjE,QAAO;EAAE;EAAuB;EAAwB"}
|
|
1
|
+
{"version":3,"file":"searchConfigurationFile.cjs","names":["configurationFilePath: string | undefined","getPackageJsonPath"],"sources":["../../../src/configFile/searchConfigurationFile.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport { logger } from '../logger';\nimport { getPackageJsonPath } from '../utils/getPackageJsonPath';\n\nexport const configurationFilesCandidates = [\n 'intlayer.config.ts',\n 'intlayer.config.js',\n 'intlayer.config.json',\n 'intlayer.config.json5',\n 'intlayer.config.jsonc',\n 'intlayer.config.cjs',\n 'intlayer.config.mjs',\n '.intlayerrc',\n] as const;\n\ntype SearchConfigurationFileResult = {\n configurationFilePath?: string;\n numCustomConfiguration: number;\n};\n\n/**\n * Search for the configuration file in the given path\n *\n * List of detected configuration files:\n * - intlayer.config.ts\n * - intlayer.config.js\n * - intlayer.config.json\n * - intlayer.config.cjs\n * - intlayer.config.mjs\n * - .intlayerrc\n */\nexport const searchConfigurationFile = (\n startDir: string\n): SearchConfigurationFileResult => {\n let configurationFilePath: string | undefined;\n let numCustomConfiguration = 0;\n\n const { baseDir } = getPackageJsonPath(startDir);\n\n for (const fileName of configurationFilesCandidates) {\n try {\n const filePath = resolve(baseDir, fileName);\n\n // Check if the file exists\n if (!existsSync(filePath)) {\n } else {\n numCustomConfiguration += 1;\n\n if (!configurationFilePath) {\n configurationFilePath = filePath;\n }\n }\n } catch (error) {\n // Return \"Cannot use import statement outside a module\"\n logger(`${fileName}: ${error as string}`, { level: 'error' });\n }\n }\n\n return { configurationFilePath, numCustomConfiguration };\n};\n"],"mappings":";;;;;;;AAKA,MAAa,+BAA+B;CAC1C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;;;;;;;;;;;AAkBD,MAAa,2BACX,aACkC;CAClC,IAAIA;CACJ,IAAI,yBAAyB;CAE7B,MAAM,EAAE,YAAYC,oDAAmB,SAAS;AAEhD,MAAK,MAAM,YAAY,6BACrB,KAAI;EACF,MAAM,kCAAmB,SAAS,SAAS;AAG3C,MAAI,yBAAY,SAAS,EAAE,QACpB;AACL,6BAA0B;AAE1B,OAAI,CAAC,sBACH,yBAAwB;;UAGrB,OAAO;AAEd,wBAAO,GAAG,SAAS,IAAI,SAAmB,EAAE,OAAO,SAAS,CAAC;;AAIjE,QAAO;EAAE;EAAuB;EAAwB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content.cjs","names":[],"sources":["../../../src/defaultValues/content.ts"],"sourcesContent":["export const FILE_EXTENSIONS = [\n '.content.ts',\n '.content.js',\n '.content.cjs',\n '.content.cjx',\n '.content.mjs',\n '.content.mjx',\n '.content.json',\n '.content.tsx',\n '.content.jsx',\n];\nexport const EXCLUDED_PATHS = [\n '**/node_modules/**',\n '**/dist/**',\n '**/build/**',\n '**/.intlayer/**',\n '**/.next/**',\n '**/.nuxt/**',\n '**/.expo/**',\n '**/.vercel/**',\n '**/.turbo/**',\n '**/.tanstack/**',\n];\n\nexport const CONTENT_DIR = ['.'];\n\nexport const MAIN_DIR = '.intlayer/main';\n\nexport const DICTIONARIES_DIR = '.intlayer/dictionary';\n\nexport const MASKS_DIR = '.intlayer/mask';\n\nexport const REMOTE_DICTIONARIES_DIR = '.intlayer/remote_dictionary';\n\nexport const UNMERGED_DICTIONARIES_DIR = '.intlayer/unmerged_dictionary';\n\nexport const DYNAMIC_DICTIONARIES_DIR = '.intlayer/dynamic_dictionary';\n\nexport const FETCH_DICTIONARIES_DIR = '.intlayer/fetch_dictionary';\n\nexport const TYPES_DIR = '.intlayer/types';\n\nexport const MODULE_AUGMENTATION_DIR = '.intlayer/types';\n\nexport const I18NEXT_DICTIONARIES_DIR = 'i18next_resources';\n\nexport const REACT_INTL_MESSAGES_DIR = 'intl_messages';\n\nexport const CONFIG_DIR = '.intlayer/config';\n\nexport const CACHE_DIR = '.intlayer/cache';\n\nexport const WATCH = process.env.NODE_ENV === 'development';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,MAAa,kBAAkB;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AACD,MAAa,iBAAiB;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,MAAa,cAAc,CAAC,IAAI;AAEhC,MAAa,WAAW;AAExB,MAAa,mBAAmB;AAEhC,MAAa,YAAY;AAEzB,MAAa,0BAA0B;AAEvC,MAAa,4BAA4B;AAEzC,MAAa,2BAA2B;AAExC,MAAa,yBAAyB;AAEtC,MAAa,YAAY;AAEzB,MAAa,0BAA0B;AAEvC,MAAa,2BAA2B;AAExC,MAAa,0BAA0B;AAEvC,MAAa,aAAa;AAE1B,MAAa,YAAY;AAEzB,MAAa,QAAQ,QAAQ,IAAI,aAAa"}
|
|
1
|
+
{"version":3,"file":"content.cjs","names":[],"sources":["../../../src/defaultValues/content.ts"],"sourcesContent":["export const FILE_EXTENSIONS = [\n '.content.ts',\n '.content.js',\n '.content.cjs',\n '.content.cjx',\n '.content.mjs',\n '.content.mjx',\n '.content.json',\n '.content.json5',\n '.content.jsonc',\n '.content.tsx',\n '.content.jsx',\n];\nexport const EXCLUDED_PATHS = [\n '**/node_modules/**',\n '**/dist/**',\n '**/build/**',\n '**/.intlayer/**',\n '**/.next/**',\n '**/.nuxt/**',\n '**/.expo/**',\n '**/.vercel/**',\n '**/.turbo/**',\n '**/.tanstack/**',\n];\n\nexport const CONTENT_DIR = ['.'];\n\nexport const MAIN_DIR = '.intlayer/main';\n\nexport const DICTIONARIES_DIR = '.intlayer/dictionary';\n\nexport const MASKS_DIR = '.intlayer/mask';\n\nexport const REMOTE_DICTIONARIES_DIR = '.intlayer/remote_dictionary';\n\nexport const UNMERGED_DICTIONARIES_DIR = '.intlayer/unmerged_dictionary';\n\nexport const DYNAMIC_DICTIONARIES_DIR = '.intlayer/dynamic_dictionary';\n\nexport const FETCH_DICTIONARIES_DIR = '.intlayer/fetch_dictionary';\n\nexport const TYPES_DIR = '.intlayer/types';\n\nexport const MODULE_AUGMENTATION_DIR = '.intlayer/types';\n\nexport const I18NEXT_DICTIONARIES_DIR = 'i18next_resources';\n\nexport const REACT_INTL_MESSAGES_DIR = 'intl_messages';\n\nexport const CONFIG_DIR = '.intlayer/config';\n\nexport const CACHE_DIR = '.intlayer/cache';\n\nexport const WATCH = process.env.NODE_ENV === 'development';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,MAAa,kBAAkB;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AACD,MAAa,iBAAiB;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,MAAa,cAAc,CAAC,IAAI;AAEhC,MAAa,WAAW;AAExB,MAAa,mBAAmB;AAEhC,MAAa,YAAY;AAEzB,MAAa,0BAA0B;AAEvC,MAAa,4BAA4B;AAEzC,MAAa,2BAA2B;AAExC,MAAa,yBAAyB;AAEtC,MAAa,YAAY;AAEzB,MAAa,0BAA0B;AAEvC,MAAa,2BAA2B;AAExC,MAAa,0BAA0B;AAEvC,MAAa,aAAa;AAE1B,MAAa,YAAY;AAEzB,MAAa,QAAQ,QAAQ,IAAI,aAAa"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -5,8 +5,8 @@ const require_logger = require('./logger.cjs');
|
|
|
5
5
|
const require_utils_cacheMemory = require('./utils/cacheMemory.cjs');
|
|
6
6
|
const require_utils_getPackageJsonPath = require('./utils/getPackageJsonPath.cjs');
|
|
7
7
|
const require_configFile_buildConfigurationFields = require('./configFile/buildConfigurationFields.cjs');
|
|
8
|
-
const require_utils_ESMxCJSHelpers = require('./utils/ESMxCJSHelpers.cjs');
|
|
9
8
|
const require_loadEnvFile = require('./loadEnvFile.cjs');
|
|
9
|
+
const require_utils_ESMxCJSHelpers = require('./utils/ESMxCJSHelpers.cjs');
|
|
10
10
|
const require_loadExternalFile_parseFileContent = require('./loadExternalFile/parseFileContent.cjs');
|
|
11
11
|
const require_bundleJSFile = require('./bundleJSFile.cjs');
|
|
12
12
|
const require_configFile_searchConfigurationFile = require('./configFile/searchConfigurationFile.cjs');
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_logger = require('../logger.cjs');
|
|
3
|
-
const require_utils_ESMxCJSHelpers = require('../utils/ESMxCJSHelpers.cjs');
|
|
4
3
|
const require_loadExternalFile_parseFileContent = require('./parseFileContent.cjs');
|
|
5
|
-
const
|
|
4
|
+
const require_loadExternalFile_transpileTSToCJS = require('./transpileTSToCJS.cjs');
|
|
6
5
|
let node_path = require("node:path");
|
|
7
6
|
let node_fs = require("node:fs");
|
|
8
7
|
let node_fs_promises = require("node:fs/promises");
|
|
8
|
+
let json5 = require("json5");
|
|
9
|
+
json5 = require_rolldown_runtime.__toESM(json5);
|
|
9
10
|
|
|
10
11
|
//#region src/loadExternalFile/loadExternalFile.ts
|
|
11
12
|
/**
|
|
@@ -14,14 +15,10 @@ let node_fs_promises = require("node:fs/promises");
|
|
|
14
15
|
* Accepts JSON, JS, MJS and TS files as configuration
|
|
15
16
|
*/
|
|
16
17
|
const loadExternalFileSync = (filePath, options) => {
|
|
17
|
-
const fileExtension = (0, node_path.extname)(filePath);
|
|
18
|
-
const safeProjectRequire = options?.projectRequire ?? require_utils_ESMxCJSHelpers.getProjectRequire();
|
|
18
|
+
const fileExtension = (0, node_path.extname)(filePath) || ".json";
|
|
19
19
|
try {
|
|
20
|
-
if (fileExtension === "json")
|
|
21
|
-
|
|
22
|
-
return safeProjectRequire(filePath);
|
|
23
|
-
}
|
|
24
|
-
const moduleResultString = require_loadExternalFile_transpileTSToMJS.transpileTSToMJSSync((0, node_fs.readFileSync)(filePath, "utf-8"), filePath);
|
|
20
|
+
if (fileExtension === ".json" || fileExtension === ".json5" || fileExtension === ".jsonc") return json5.default.parse((0, node_fs.readFileSync)(filePath, "utf-8"));
|
|
21
|
+
const moduleResultString = require_loadExternalFile_transpileTSToCJS.transpileTSToCJSSync((0, node_fs.readFileSync)(filePath, "utf-8"), filePath);
|
|
25
22
|
if (!moduleResultString) {
|
|
26
23
|
require_logger.logger("File could not be loaded.", { level: "error" });
|
|
27
24
|
return;
|
|
@@ -49,13 +46,12 @@ const loadExternalFileSync = (filePath, options) => {
|
|
|
49
46
|
*/
|
|
50
47
|
const loadExternalFile = async (filePath, options) => {
|
|
51
48
|
const fileExtension = (0, node_path.extname)(filePath);
|
|
52
|
-
const safeProjectRequire = options?.projectRequire ?? require_utils_ESMxCJSHelpers.getProjectRequire();
|
|
53
49
|
try {
|
|
54
|
-
if (fileExtension === ".json") {
|
|
55
|
-
|
|
56
|
-
return
|
|
50
|
+
if (fileExtension === ".json" || fileExtension === ".json5" || fileExtension === ".jsonc") {
|
|
51
|
+
const fileContent$1 = await (0, node_fs_promises.readFile)(filePath, "utf-8");
|
|
52
|
+
return json5.default.parse(fileContent$1);
|
|
57
53
|
}
|
|
58
|
-
const moduleResultString = await
|
|
54
|
+
const moduleResultString = await require_loadExternalFile_transpileTSToCJS.transpileTSToCJS(await (0, node_fs_promises.readFile)(filePath, "utf-8"), filePath, options?.buildOptions);
|
|
59
55
|
if (!moduleResultString) {
|
|
60
56
|
require_logger.logger("File could not be loaded.", { level: "error" });
|
|
61
57
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadExternalFile.cjs","names":["
|
|
1
|
+
{"version":3,"file":"loadExternalFile.cjs","names":["JSON5","moduleResultString: string | undefined","transpileTSToCJSSync","parseFileContent","fileContent","transpileTSToCJS","colorizePath"],"sources":["../../../src/loadExternalFile/loadExternalFile.ts"],"sourcesContent":["import { readFileSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport { extname } from 'node:path';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport type { BuildOptions, Plugin } from 'esbuild';\nimport JSON5 from 'json5';\nimport { colorizePath, logger } from '../logger';\nimport {\n parseFileContent,\n type SandBoxContextOptions,\n} from './parseFileContent';\nimport { transpileTSToCJS, transpileTSToCJSSync } from './transpileTSToCJS';\n\nexport type ESBuildPlugin = Plugin;\n\nexport type LoadExternalFileOptions = {\n configuration?: IntlayerConfig;\n buildOptions?: BuildOptions;\n} & SandBoxContextOptions;\n\n/**\n * Load the content declaration from the given path\n *\n * Accepts JSON, JS, MJS and TS files as configuration\n */\nexport const loadExternalFileSync = (\n filePath: string,\n options?: LoadExternalFileOptions\n): any | undefined => {\n const fileExtension = extname(filePath) || '.json';\n\n try {\n if (\n fileExtension === '.json' ||\n fileExtension === '.json5' ||\n fileExtension === '.jsonc'\n ) {\n // Assume JSON\n return JSON5.parse(readFileSync(filePath, 'utf-8'));\n }\n\n // Rest is JS, MJS or TS\n const code = readFileSync(filePath, 'utf-8');\n\n const moduleResultString: string | undefined = transpileTSToCJSSync(\n code,\n filePath\n );\n\n if (!moduleResultString) {\n logger('File could not be loaded.', { level: 'error' });\n return undefined;\n }\n\n const fileContent = parseFileContent(moduleResultString, {\n projectRequire: options?.projectRequire,\n envVarOptions: options?.envVarOptions,\n additionalEnvVars: options?.additionalEnvVars,\n mocks: options?.mocks,\n aliases: options?.aliases,\n });\n\n if (typeof fileContent === 'undefined') {\n logger(`File could not be loaded. Path : ${filePath}`);\n return undefined;\n }\n\n return fileContent;\n } catch (error) {\n logger(\n [\n `Error: ${(error as Error).message} - `,\n JSON.stringify((error as Error).stack, null, 2),\n ],\n {\n level: 'error',\n }\n );\n }\n};\n\n/**\n * Load the content declaration from the given path\n *\n * Accepts JSON, JS, MJS and TS files as configuration\n */\nexport const loadExternalFile = async (\n filePath: string,\n options?: LoadExternalFileOptions\n): Promise<any | undefined> => {\n const fileExtension = extname(filePath);\n\n try {\n if (\n fileExtension === '.json' ||\n fileExtension === '.json5' ||\n fileExtension === '.jsonc'\n ) {\n // Remove cache to force getting fresh content\n const fileContent = await readFile(filePath, 'utf-8');\n return JSON5.parse(fileContent);\n }\n\n // Rest is JS, MJS or TS\n const code = await readFile(filePath, 'utf-8');\n\n const moduleResultString: string | undefined = await transpileTSToCJS(\n code,\n filePath,\n options?.buildOptions\n );\n\n if (!moduleResultString) {\n logger('File could not be loaded.', { level: 'error' });\n return undefined;\n }\n\n const fileContent = parseFileContent(moduleResultString, {\n projectRequire: options?.projectRequire,\n envVarOptions: options?.envVarOptions,\n additionalEnvVars: options?.additionalEnvVars,\n mocks: options?.mocks,\n aliases: options?.aliases,\n });\n\n if (typeof fileContent === 'undefined') {\n logger(`File could not be loaded. Path : ${colorizePath(filePath)}`);\n return undefined;\n }\n\n return fileContent;\n } catch (error) {\n logger(\n [\n `Error: ${(error as Error).message} - `,\n JSON.stringify((error as Error).stack, null, 2),\n ],\n {\n level: 'error',\n }\n );\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAyBA,MAAa,wBACX,UACA,YACoB;CACpB,MAAM,uCAAwB,SAAS,IAAI;AAE3C,KAAI;AACF,MACE,kBAAkB,WAClB,kBAAkB,YAClB,kBAAkB,SAGlB,QAAOA,cAAM,gCAAmB,UAAU,QAAQ,CAAC;EAMrD,MAAMC,qBAAyCC,yFAFrB,UAAU,QAAQ,EAI1C,SACD;AAED,MAAI,CAAC,oBAAoB;AACvB,yBAAO,6BAA6B,EAAE,OAAO,SAAS,CAAC;AACvD;;EAGF,MAAM,cAAcC,2DAAiB,oBAAoB;GACvD,gBAAgB,SAAS;GACzB,eAAe,SAAS;GACxB,mBAAmB,SAAS;GAC5B,OAAO,SAAS;GAChB,SAAS,SAAS;GACnB,CAAC;AAEF,MAAI,OAAO,gBAAgB,aAAa;AACtC,yBAAO,oCAAoC,WAAW;AACtD;;AAGF,SAAO;UACA,OAAO;AACd,wBACE,CACE,UAAW,MAAgB,QAAQ,MACnC,KAAK,UAAW,MAAgB,OAAO,MAAM,EAAE,CAChD,EACD,EACE,OAAO,SACR,CACF;;;;;;;;AASL,MAAa,mBAAmB,OAC9B,UACA,YAC6B;CAC7B,MAAM,uCAAwB,SAAS;AAEvC,KAAI;AACF,MACE,kBAAkB,WAClB,kBAAkB,YAClB,kBAAkB,UAClB;GAEA,MAAMC,gBAAc,qCAAe,UAAU,QAAQ;AACrD,UAAOJ,cAAM,MAAMI,cAAY;;EAMjC,MAAMH,qBAAyC,MAAMI,2DAFxC,qCAAe,UAAU,QAAQ,EAI5C,UACA,SAAS,aACV;AAED,MAAI,CAAC,oBAAoB;AACvB,yBAAO,6BAA6B,EAAE,OAAO,SAAS,CAAC;AACvD;;EAGF,MAAM,cAAcF,2DAAiB,oBAAoB;GACvD,gBAAgB,SAAS;GACzB,eAAe,SAAS;GACxB,mBAAmB,SAAS;GAC5B,OAAO,SAAS;GAChB,SAAS,SAAS;GACnB,CAAC;AAEF,MAAI,OAAO,gBAAgB,aAAa;AACtC,yBAAO,oCAAoCG,4BAAa,SAAS,GAAG;AACpE;;AAGF,SAAO;UACA,OAAO;AACd,wBACE,CACE,UAAW,MAAgB,QAAQ,MACnC,KAAK,UAAW,MAAgB,OAAO,MAAM,EAAE,CAChD,EACD,EACE,OAAO,SACR,CACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
const require_utils_ESMxCJSHelpers = require('../utils/ESMxCJSHelpers.cjs');
|
|
3
2
|
const require_loadEnvFile = require('../loadEnvFile.cjs');
|
|
3
|
+
const require_utils_ESMxCJSHelpers = require('../utils/ESMxCJSHelpers.cjs');
|
|
4
4
|
let node_vm = require("node:vm");
|
|
5
5
|
let esbuild = require("esbuild");
|
|
6
6
|
esbuild = require_rolldown_runtime.__toESM(esbuild);
|
|
@@ -6,7 +6,7 @@ let node_fs = require("node:fs");
|
|
|
6
6
|
let esbuild = require("esbuild");
|
|
7
7
|
let node_url = require("node:url");
|
|
8
8
|
|
|
9
|
-
//#region src/loadExternalFile/
|
|
9
|
+
//#region src/loadExternalFile/transpileTSToCJS.ts
|
|
10
10
|
const getTsConfigPath = (filePath) => {
|
|
11
11
|
const tsconfigPath = (0, node_path.join)(require_utils_getPackageJsonPath.getPackageJsonPath((0, node_path.dirname)(filePath)).baseDir, "tsconfig.json");
|
|
12
12
|
return (0, node_fs.existsSync)(tsconfigPath) ? tsconfigPath : void 0;
|
|
@@ -32,7 +32,7 @@ const getTransformationOptions = (filePath) => ({
|
|
|
32
32
|
tsconfig: getTsConfigPath(filePath),
|
|
33
33
|
define: { "import.meta.url": JSON.stringify((0, node_url.pathToFileURL)(filePath).href) }
|
|
34
34
|
});
|
|
35
|
-
const
|
|
35
|
+
const transpileTSToCJSSync = (code, filePath, options) => {
|
|
36
36
|
return (0, esbuild.buildSync)({
|
|
37
37
|
stdin: {
|
|
38
38
|
contents: code,
|
|
@@ -44,7 +44,7 @@ const transpileTSToMJSSync = (code, filePath, options) => {
|
|
|
44
44
|
...options
|
|
45
45
|
}).outputFiles?.[0].text;
|
|
46
46
|
};
|
|
47
|
-
const
|
|
47
|
+
const transpileTSToCJS = async (code, filePath, options) => {
|
|
48
48
|
return (await (0, esbuild.build)({
|
|
49
49
|
stdin: {
|
|
50
50
|
contents: code,
|
|
@@ -58,6 +58,6 @@ const transpileTSToMJS = async (code, filePath, options) => {
|
|
|
58
58
|
};
|
|
59
59
|
|
|
60
60
|
//#endregion
|
|
61
|
-
exports.
|
|
62
|
-
exports.
|
|
63
|
-
//# sourceMappingURL=
|
|
61
|
+
exports.transpileTSToCJS = transpileTSToCJS;
|
|
62
|
+
exports.transpileTSToCJSSync = transpileTSToCJSSync;
|
|
63
|
+
//# sourceMappingURL=transpileTSToCJS.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"transpileTSToCJS.cjs","names":["getPackageJsonPath","getLoader"],"sources":["../../../src/loadExternalFile/transpileTSToCJS.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { dirname, extname, join } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport {\n type BuildOptions,\n type BuildResult,\n build,\n buildSync,\n type Plugin,\n} from 'esbuild';\nimport { getPackageJsonPath } from '..';\nimport { getLoader } from './bundleFile';\n\nexport type ESBuildPlugin = Plugin;\n\nconst getTsConfigPath = (filePath: string): string | undefined => {\n const tsconfigPath = join(\n getPackageJsonPath(dirname(filePath)).baseDir,\n 'tsconfig.json'\n );\n\n // Only return the tsconfig path if it exists\n return existsSync(tsconfigPath) ? tsconfigPath : undefined;\n};\n\nconst getTransformationOptions = (filePath: string): 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 '.md': 'text',\n '.mdx': 'text',\n },\n format: 'cjs',\n target: 'node20',\n platform: 'node',\n write: false,\n packages: 'external',\n bundle: true,\n tsconfig: getTsConfigPath(filePath),\n define: {\n 'import.meta.url': JSON.stringify(pathToFileURL(filePath).href),\n },\n});\n\nexport const transpileTSToCJSSync = (\n code: string,\n filePath: string,\n options?: BuildOptions\n): string | undefined => {\n const extension = extname(filePath);\n const loader = getLoader(extension);\n\n const moduleResult: BuildResult = buildSync({\n stdin: {\n contents: code,\n loader,\n resolveDir: dirname(filePath), // Add resolveDir to resolve imports relative to the file's location\n sourcefile: filePath, // Add sourcefile for better error messages\n },\n ...getTransformationOptions(filePath),\n ...options,\n });\n\n const moduleResultString = moduleResult.outputFiles?.[0].text;\n\n return moduleResultString;\n};\n\nexport const transpileTSToCJS = async (\n code: string,\n filePath: string,\n options?: BuildOptions\n): Promise<string | undefined> => {\n const extension = extname(filePath);\n const loader = getLoader(extension);\n\n const moduleResult: BuildResult = await build({\n stdin: {\n contents: code,\n loader,\n resolveDir: dirname(filePath), // Add resolveDir to resolve imports relative to the file's location\n sourcefile: filePath, // Add sourcefile for better error messages\n },\n ...getTransformationOptions(filePath),\n ...options,\n });\n\n const moduleResultString = moduleResult.outputFiles?.[0].text;\n\n return moduleResultString;\n};\n"],"mappings":";;;;;;;;;AAeA,MAAM,mBAAmB,aAAyC;CAChE,MAAM,mCACJA,2EAA2B,SAAS,CAAC,CAAC,SACtC,gBACD;AAGD,gCAAkB,aAAa,GAAG,eAAe;;AAGnD,MAAM,4BAA4B,cAAoC;CACpE,QAAQ;EACN,OAAO;EACP,QAAQ;EACR,QAAQ;EACR,OAAO;EACP,QAAQ;EACR,QAAQ;EACR,SAAS;EACT,OAAO;EACP,QAAQ;EACT;CACD,QAAQ;CACR,QAAQ;CACR,UAAU;CACV,OAAO;CACP,UAAU;CACV,QAAQ;CACR,UAAU,gBAAgB,SAAS;CACnC,QAAQ,EACN,mBAAmB,KAAK,sCAAwB,SAAS,CAAC,KAAK,EAChE;CACF;AAED,MAAa,wBACX,MACA,UACA,YACuB;AAiBvB,+BAb4C;EAC1C,OAAO;GACL,UAAU;GACV,QALWC,qEADW,SAAS,CACA;GAM/B,mCAAoB,SAAS;GAC7B,YAAY;GACb;EACD,GAAG,yBAAyB,SAAS;EACrC,GAAG;EACJ,CAAC,CAEsC,cAAc,GAAG;;AAK3D,MAAa,mBAAmB,OAC9B,MACA,UACA,YACgC;AAiBhC,SAbkC,yBAAY;EAC5C,OAAO;GACL,UAAU;GACV,QALWA,qEADW,SAAS,CACA;GAM/B,mCAAoB,SAAS;GAC7B,YAAY;GACb;EACD,GAAG,yBAAyB,SAAS;EACrC,GAAG;EACJ,CAAC,EAEsC,cAAc,GAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"searchConfigurationFile.mjs","names":["configurationFilePath: string | undefined"],"sources":["../../../src/configFile/searchConfigurationFile.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport { logger } from '../logger';\nimport { getPackageJsonPath } from '../utils/getPackageJsonPath';\n\nexport const configurationFilesCandidates = [\n 'intlayer.config.ts',\n 'intlayer.config.js',\n 'intlayer.config.json',\n 'intlayer.config.cjs',\n 'intlayer.config.mjs',\n '.intlayerrc',\n] as const;\n\ntype SearchConfigurationFileResult = {\n configurationFilePath?: string;\n numCustomConfiguration: number;\n};\n\n/**\n * Search for the configuration file in the given path\n *\n * List of detected configuration files:\n * - intlayer.config.ts\n * - intlayer.config.js\n * - intlayer.config.json\n * - intlayer.config.cjs\n * - intlayer.config.mjs\n * - .intlayerrc\n */\nexport const searchConfigurationFile = (\n startDir: string\n): SearchConfigurationFileResult => {\n let configurationFilePath: string | undefined;\n let numCustomConfiguration = 0;\n\n const { baseDir } = getPackageJsonPath(startDir);\n\n for (const fileName of configurationFilesCandidates) {\n try {\n const filePath = resolve(baseDir, fileName);\n\n // Check if the file exists\n if (!existsSync(filePath)) {\n } else {\n numCustomConfiguration += 1;\n\n if (!configurationFilePath) {\n configurationFilePath = filePath;\n }\n }\n } catch (error) {\n // Return \"Cannot use import statement outside a module\"\n logger(`${fileName}: ${error as string}`, { level: 'error' });\n }\n }\n\n return { configurationFilePath, numCustomConfiguration };\n};\n"],"mappings":";;;;;;AAKA,MAAa,+BAA+B;CAC1C;CACA;CACA;CACA;CACA;CACA;CACD;;;;;;;;;;;;AAkBD,MAAa,2BACX,aACkC;CAClC,IAAIA;CACJ,IAAI,yBAAyB;CAE7B,MAAM,EAAE,YAAY,mBAAmB,SAAS;AAEhD,MAAK,MAAM,YAAY,6BACrB,KAAI;EACF,MAAM,WAAW,QAAQ,SAAS,SAAS;AAG3C,MAAI,CAAC,WAAW,SAAS,EAAE,QACpB;AACL,6BAA0B;AAE1B,OAAI,CAAC,sBACH,yBAAwB;;UAGrB,OAAO;AAEd,SAAO,GAAG,SAAS,IAAI,SAAmB,EAAE,OAAO,SAAS,CAAC;;AAIjE,QAAO;EAAE;EAAuB;EAAwB"}
|
|
1
|
+
{"version":3,"file":"searchConfigurationFile.mjs","names":["configurationFilePath: string | undefined"],"sources":["../../../src/configFile/searchConfigurationFile.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport { logger } from '../logger';\nimport { getPackageJsonPath } from '../utils/getPackageJsonPath';\n\nexport const configurationFilesCandidates = [\n 'intlayer.config.ts',\n 'intlayer.config.js',\n 'intlayer.config.json',\n 'intlayer.config.json5',\n 'intlayer.config.jsonc',\n 'intlayer.config.cjs',\n 'intlayer.config.mjs',\n '.intlayerrc',\n] as const;\n\ntype SearchConfigurationFileResult = {\n configurationFilePath?: string;\n numCustomConfiguration: number;\n};\n\n/**\n * Search for the configuration file in the given path\n *\n * List of detected configuration files:\n * - intlayer.config.ts\n * - intlayer.config.js\n * - intlayer.config.json\n * - intlayer.config.cjs\n * - intlayer.config.mjs\n * - .intlayerrc\n */\nexport const searchConfigurationFile = (\n startDir: string\n): SearchConfigurationFileResult => {\n let configurationFilePath: string | undefined;\n let numCustomConfiguration = 0;\n\n const { baseDir } = getPackageJsonPath(startDir);\n\n for (const fileName of configurationFilesCandidates) {\n try {\n const filePath = resolve(baseDir, fileName);\n\n // Check if the file exists\n if (!existsSync(filePath)) {\n } else {\n numCustomConfiguration += 1;\n\n if (!configurationFilePath) {\n configurationFilePath = filePath;\n }\n }\n } catch (error) {\n // Return \"Cannot use import statement outside a module\"\n logger(`${fileName}: ${error as string}`, { level: 'error' });\n }\n }\n\n return { configurationFilePath, numCustomConfiguration };\n};\n"],"mappings":";;;;;;AAKA,MAAa,+BAA+B;CAC1C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;;;;;;;;;;;AAkBD,MAAa,2BACX,aACkC;CAClC,IAAIA;CACJ,IAAI,yBAAyB;CAE7B,MAAM,EAAE,YAAY,mBAAmB,SAAS;AAEhD,MAAK,MAAM,YAAY,6BACrB,KAAI;EACF,MAAM,WAAW,QAAQ,SAAS,SAAS;AAG3C,MAAI,CAAC,WAAW,SAAS,EAAE,QACpB;AACL,6BAA0B;AAE1B,OAAI,CAAC,sBACH,yBAAwB;;UAGrB,OAAO;AAEd,SAAO,GAAG,SAAS,IAAI,SAAmB,EAAE,OAAO,SAAS,CAAC;;AAIjE,QAAO;EAAE;EAAuB;EAAwB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content.mjs","names":[],"sources":["../../../src/defaultValues/content.ts"],"sourcesContent":["export const FILE_EXTENSIONS = [\n '.content.ts',\n '.content.js',\n '.content.cjs',\n '.content.cjx',\n '.content.mjs',\n '.content.mjx',\n '.content.json',\n '.content.tsx',\n '.content.jsx',\n];\nexport const EXCLUDED_PATHS = [\n '**/node_modules/**',\n '**/dist/**',\n '**/build/**',\n '**/.intlayer/**',\n '**/.next/**',\n '**/.nuxt/**',\n '**/.expo/**',\n '**/.vercel/**',\n '**/.turbo/**',\n '**/.tanstack/**',\n];\n\nexport const CONTENT_DIR = ['.'];\n\nexport const MAIN_DIR = '.intlayer/main';\n\nexport const DICTIONARIES_DIR = '.intlayer/dictionary';\n\nexport const MASKS_DIR = '.intlayer/mask';\n\nexport const REMOTE_DICTIONARIES_DIR = '.intlayer/remote_dictionary';\n\nexport const UNMERGED_DICTIONARIES_DIR = '.intlayer/unmerged_dictionary';\n\nexport const DYNAMIC_DICTIONARIES_DIR = '.intlayer/dynamic_dictionary';\n\nexport const FETCH_DICTIONARIES_DIR = '.intlayer/fetch_dictionary';\n\nexport const TYPES_DIR = '.intlayer/types';\n\nexport const MODULE_AUGMENTATION_DIR = '.intlayer/types';\n\nexport const I18NEXT_DICTIONARIES_DIR = 'i18next_resources';\n\nexport const REACT_INTL_MESSAGES_DIR = 'intl_messages';\n\nexport const CONFIG_DIR = '.intlayer/config';\n\nexport const CACHE_DIR = '.intlayer/cache';\n\nexport const WATCH = process.env.NODE_ENV === 'development';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,MAAa,kBAAkB;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AACD,MAAa,iBAAiB;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,MAAa,cAAc,CAAC,IAAI;AAEhC,MAAa,WAAW;AAExB,MAAa,mBAAmB;AAEhC,MAAa,YAAY;AAEzB,MAAa,0BAA0B;AAEvC,MAAa,4BAA4B;AAEzC,MAAa,2BAA2B;AAExC,MAAa,yBAAyB;AAEtC,MAAa,YAAY;AAEzB,MAAa,0BAA0B;AAEvC,MAAa,2BAA2B;AAExC,MAAa,0BAA0B;AAEvC,MAAa,aAAa;AAE1B,MAAa,YAAY;AAEzB,MAAa,QAAQ"}
|
|
1
|
+
{"version":3,"file":"content.mjs","names":[],"sources":["../../../src/defaultValues/content.ts"],"sourcesContent":["export const FILE_EXTENSIONS = [\n '.content.ts',\n '.content.js',\n '.content.cjs',\n '.content.cjx',\n '.content.mjs',\n '.content.mjx',\n '.content.json',\n '.content.json5',\n '.content.jsonc',\n '.content.tsx',\n '.content.jsx',\n];\nexport const EXCLUDED_PATHS = [\n '**/node_modules/**',\n '**/dist/**',\n '**/build/**',\n '**/.intlayer/**',\n '**/.next/**',\n '**/.nuxt/**',\n '**/.expo/**',\n '**/.vercel/**',\n '**/.turbo/**',\n '**/.tanstack/**',\n];\n\nexport const CONTENT_DIR = ['.'];\n\nexport const MAIN_DIR = '.intlayer/main';\n\nexport const DICTIONARIES_DIR = '.intlayer/dictionary';\n\nexport const MASKS_DIR = '.intlayer/mask';\n\nexport const REMOTE_DICTIONARIES_DIR = '.intlayer/remote_dictionary';\n\nexport const UNMERGED_DICTIONARIES_DIR = '.intlayer/unmerged_dictionary';\n\nexport const DYNAMIC_DICTIONARIES_DIR = '.intlayer/dynamic_dictionary';\n\nexport const FETCH_DICTIONARIES_DIR = '.intlayer/fetch_dictionary';\n\nexport const TYPES_DIR = '.intlayer/types';\n\nexport const MODULE_AUGMENTATION_DIR = '.intlayer/types';\n\nexport const I18NEXT_DICTIONARIES_DIR = 'i18next_resources';\n\nexport const REACT_INTL_MESSAGES_DIR = 'intl_messages';\n\nexport const CONFIG_DIR = '.intlayer/config';\n\nexport const CACHE_DIR = '.intlayer/cache';\n\nexport const WATCH = process.env.NODE_ENV === 'development';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,MAAa,kBAAkB;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AACD,MAAa,iBAAiB;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,MAAa,cAAc,CAAC,IAAI;AAEhC,MAAa,WAAW;AAExB,MAAa,mBAAmB;AAEhC,MAAa,YAAY;AAEzB,MAAa,0BAA0B;AAEvC,MAAa,4BAA4B;AAEzC,MAAa,2BAA2B;AAExC,MAAa,yBAAyB;AAEtC,MAAa,YAAY;AAEzB,MAAa,0BAA0B;AAEvC,MAAa,2BAA2B;AAExC,MAAa,0BAA0B;AAEvC,MAAa,aAAa;AAE1B,MAAa,YAAY;AAEzB,MAAa,QAAQ"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -5,8 +5,8 @@ import { ANSIColors, clock, colon, colorize, colorizeKey, colorizeLocales, color
|
|
|
5
5
|
import { cacheMemory } from "./utils/cacheMemory.mjs";
|
|
6
6
|
import { getPackageJsonPath } from "./utils/getPackageJsonPath.mjs";
|
|
7
7
|
import { buildConfigurationFields } from "./configFile/buildConfigurationFields.mjs";
|
|
8
|
-
import { configESMxCJSRequire, getProjectRequire, isESModule } from "./utils/ESMxCJSHelpers.mjs";
|
|
9
8
|
import { getEnvFilePath, loadEnvFile } from "./loadEnvFile.mjs";
|
|
9
|
+
import { configESMxCJSRequire, getProjectRequire, isESModule } from "./utils/ESMxCJSHelpers.mjs";
|
|
10
10
|
import { parseFileContent } from "./loadExternalFile/parseFileContent.mjs";
|
|
11
11
|
import { bundleJSFile } from "./bundleJSFile.mjs";
|
|
12
12
|
import { configurationFilesCandidates, searchConfigurationFile } from "./configFile/searchConfigurationFile.mjs";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { colorizePath, logger } from "../logger.mjs";
|
|
2
|
-
import { getProjectRequire } from "../utils/ESMxCJSHelpers.mjs";
|
|
3
2
|
import { parseFileContent } from "./parseFileContent.mjs";
|
|
4
|
-
import {
|
|
3
|
+
import { transpileTSToCJS, transpileTSToCJSSync } from "./transpileTSToCJS.mjs";
|
|
5
4
|
import { extname } from "node:path";
|
|
6
5
|
import { readFileSync } from "node:fs";
|
|
7
6
|
import { readFile } from "node:fs/promises";
|
|
7
|
+
import JSON5 from "json5";
|
|
8
8
|
|
|
9
9
|
//#region src/loadExternalFile/loadExternalFile.ts
|
|
10
10
|
/**
|
|
@@ -13,14 +13,10 @@ import { readFile } from "node:fs/promises";
|
|
|
13
13
|
* Accepts JSON, JS, MJS and TS files as configuration
|
|
14
14
|
*/
|
|
15
15
|
const loadExternalFileSync = (filePath, options) => {
|
|
16
|
-
const fileExtension = extname(filePath);
|
|
17
|
-
const safeProjectRequire = options?.projectRequire ?? getProjectRequire();
|
|
16
|
+
const fileExtension = extname(filePath) || ".json";
|
|
18
17
|
try {
|
|
19
|
-
if (fileExtension === "json")
|
|
20
|
-
|
|
21
|
-
return safeProjectRequire(filePath);
|
|
22
|
-
}
|
|
23
|
-
const moduleResultString = transpileTSToMJSSync(readFileSync(filePath, "utf-8"), filePath);
|
|
18
|
+
if (fileExtension === ".json" || fileExtension === ".json5" || fileExtension === ".jsonc") return JSON5.parse(readFileSync(filePath, "utf-8"));
|
|
19
|
+
const moduleResultString = transpileTSToCJSSync(readFileSync(filePath, "utf-8"), filePath);
|
|
24
20
|
if (!moduleResultString) {
|
|
25
21
|
logger("File could not be loaded.", { level: "error" });
|
|
26
22
|
return;
|
|
@@ -48,13 +44,12 @@ const loadExternalFileSync = (filePath, options) => {
|
|
|
48
44
|
*/
|
|
49
45
|
const loadExternalFile = async (filePath, options) => {
|
|
50
46
|
const fileExtension = extname(filePath);
|
|
51
|
-
const safeProjectRequire = options?.projectRequire ?? getProjectRequire();
|
|
52
47
|
try {
|
|
53
|
-
if (fileExtension === ".json") {
|
|
54
|
-
|
|
55
|
-
return
|
|
48
|
+
if (fileExtension === ".json" || fileExtension === ".json5" || fileExtension === ".jsonc") {
|
|
49
|
+
const fileContent$1 = await readFile(filePath, "utf-8");
|
|
50
|
+
return JSON5.parse(fileContent$1);
|
|
56
51
|
}
|
|
57
|
-
const moduleResultString = await
|
|
52
|
+
const moduleResultString = await transpileTSToCJS(await readFile(filePath, "utf-8"), filePath, options?.buildOptions);
|
|
58
53
|
if (!moduleResultString) {
|
|
59
54
|
logger("File could not be loaded.", { level: "error" });
|
|
60
55
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadExternalFile.mjs","names":["moduleResultString: string | undefined"],"sources":["../../../src/loadExternalFile/loadExternalFile.ts"],"sourcesContent":["import { readFileSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport { extname } from 'node:path';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport type { BuildOptions, Plugin } from 'esbuild';\nimport
|
|
1
|
+
{"version":3,"file":"loadExternalFile.mjs","names":["moduleResultString: string | undefined","fileContent"],"sources":["../../../src/loadExternalFile/loadExternalFile.ts"],"sourcesContent":["import { readFileSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport { extname } from 'node:path';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport type { BuildOptions, Plugin } from 'esbuild';\nimport JSON5 from 'json5';\nimport { colorizePath, logger } from '../logger';\nimport {\n parseFileContent,\n type SandBoxContextOptions,\n} from './parseFileContent';\nimport { transpileTSToCJS, transpileTSToCJSSync } from './transpileTSToCJS';\n\nexport type ESBuildPlugin = Plugin;\n\nexport type LoadExternalFileOptions = {\n configuration?: IntlayerConfig;\n buildOptions?: BuildOptions;\n} & SandBoxContextOptions;\n\n/**\n * Load the content declaration from the given path\n *\n * Accepts JSON, JS, MJS and TS files as configuration\n */\nexport const loadExternalFileSync = (\n filePath: string,\n options?: LoadExternalFileOptions\n): any | undefined => {\n const fileExtension = extname(filePath) || '.json';\n\n try {\n if (\n fileExtension === '.json' ||\n fileExtension === '.json5' ||\n fileExtension === '.jsonc'\n ) {\n // Assume JSON\n return JSON5.parse(readFileSync(filePath, 'utf-8'));\n }\n\n // Rest is JS, MJS or TS\n const code = readFileSync(filePath, 'utf-8');\n\n const moduleResultString: string | undefined = transpileTSToCJSSync(\n code,\n filePath\n );\n\n if (!moduleResultString) {\n logger('File could not be loaded.', { level: 'error' });\n return undefined;\n }\n\n const fileContent = parseFileContent(moduleResultString, {\n projectRequire: options?.projectRequire,\n envVarOptions: options?.envVarOptions,\n additionalEnvVars: options?.additionalEnvVars,\n mocks: options?.mocks,\n aliases: options?.aliases,\n });\n\n if (typeof fileContent === 'undefined') {\n logger(`File could not be loaded. Path : ${filePath}`);\n return undefined;\n }\n\n return fileContent;\n } catch (error) {\n logger(\n [\n `Error: ${(error as Error).message} - `,\n JSON.stringify((error as Error).stack, null, 2),\n ],\n {\n level: 'error',\n }\n );\n }\n};\n\n/**\n * Load the content declaration from the given path\n *\n * Accepts JSON, JS, MJS and TS files as configuration\n */\nexport const loadExternalFile = async (\n filePath: string,\n options?: LoadExternalFileOptions\n): Promise<any | undefined> => {\n const fileExtension = extname(filePath);\n\n try {\n if (\n fileExtension === '.json' ||\n fileExtension === '.json5' ||\n fileExtension === '.jsonc'\n ) {\n // Remove cache to force getting fresh content\n const fileContent = await readFile(filePath, 'utf-8');\n return JSON5.parse(fileContent);\n }\n\n // Rest is JS, MJS or TS\n const code = await readFile(filePath, 'utf-8');\n\n const moduleResultString: string | undefined = await transpileTSToCJS(\n code,\n filePath,\n options?.buildOptions\n );\n\n if (!moduleResultString) {\n logger('File could not be loaded.', { level: 'error' });\n return undefined;\n }\n\n const fileContent = parseFileContent(moduleResultString, {\n projectRequire: options?.projectRequire,\n envVarOptions: options?.envVarOptions,\n additionalEnvVars: options?.additionalEnvVars,\n mocks: options?.mocks,\n aliases: options?.aliases,\n });\n\n if (typeof fileContent === 'undefined') {\n logger(`File could not be loaded. Path : ${colorizePath(filePath)}`);\n return undefined;\n }\n\n return fileContent;\n } catch (error) {\n logger(\n [\n `Error: ${(error as Error).message} - `,\n JSON.stringify((error as Error).stack, null, 2),\n ],\n {\n level: 'error',\n }\n );\n }\n};\n"],"mappings":";;;;;;;;;;;;;;AAyBA,MAAa,wBACX,UACA,YACoB;CACpB,MAAM,gBAAgB,QAAQ,SAAS,IAAI;AAE3C,KAAI;AACF,MACE,kBAAkB,WAClB,kBAAkB,YAClB,kBAAkB,SAGlB,QAAO,MAAM,MAAM,aAAa,UAAU,QAAQ,CAAC;EAMrD,MAAMA,qBAAyC,qBAFlC,aAAa,UAAU,QAAQ,EAI1C,SACD;AAED,MAAI,CAAC,oBAAoB;AACvB,UAAO,6BAA6B,EAAE,OAAO,SAAS,CAAC;AACvD;;EAGF,MAAM,cAAc,iBAAiB,oBAAoB;GACvD,gBAAgB,SAAS;GACzB,eAAe,SAAS;GACxB,mBAAmB,SAAS;GAC5B,OAAO,SAAS;GAChB,SAAS,SAAS;GACnB,CAAC;AAEF,MAAI,OAAO,gBAAgB,aAAa;AACtC,UAAO,oCAAoC,WAAW;AACtD;;AAGF,SAAO;UACA,OAAO;AACd,SACE,CACE,UAAW,MAAgB,QAAQ,MACnC,KAAK,UAAW,MAAgB,OAAO,MAAM,EAAE,CAChD,EACD,EACE,OAAO,SACR,CACF;;;;;;;;AASL,MAAa,mBAAmB,OAC9B,UACA,YAC6B;CAC7B,MAAM,gBAAgB,QAAQ,SAAS;AAEvC,KAAI;AACF,MACE,kBAAkB,WAClB,kBAAkB,YAClB,kBAAkB,UAClB;GAEA,MAAMC,gBAAc,MAAM,SAAS,UAAU,QAAQ;AACrD,UAAO,MAAM,MAAMA,cAAY;;EAMjC,MAAMD,qBAAyC,MAAM,iBAFxC,MAAM,SAAS,UAAU,QAAQ,EAI5C,UACA,SAAS,aACV;AAED,MAAI,CAAC,oBAAoB;AACvB,UAAO,6BAA6B,EAAE,OAAO,SAAS,CAAC;AACvD;;EAGF,MAAM,cAAc,iBAAiB,oBAAoB;GACvD,gBAAgB,SAAS;GACzB,eAAe,SAAS;GACxB,mBAAmB,SAAS;GAC5B,OAAO,SAAS;GAChB,SAAS,SAAS;GACnB,CAAC;AAEF,MAAI,OAAO,gBAAgB,aAAa;AACtC,UAAO,oCAAoC,aAAa,SAAS,GAAG;AACpE;;AAGF,SAAO;UACA,OAAO;AACd,SACE,CACE,UAAW,MAAgB,QAAQ,MACnC,KAAK,UAAW,MAAgB,OAAO,MAAM,EAAE,CAChD,EACD,EACE,OAAO,SACR,CACF"}
|
|
@@ -5,7 +5,7 @@ import { existsSync } from "node:fs";
|
|
|
5
5
|
import { build, buildSync } from "esbuild";
|
|
6
6
|
import { pathToFileURL } from "node:url";
|
|
7
7
|
|
|
8
|
-
//#region src/loadExternalFile/
|
|
8
|
+
//#region src/loadExternalFile/transpileTSToCJS.ts
|
|
9
9
|
const getTsConfigPath = (filePath) => {
|
|
10
10
|
const tsconfigPath = join(getPackageJsonPath(dirname(filePath)).baseDir, "tsconfig.json");
|
|
11
11
|
return existsSync(tsconfigPath) ? tsconfigPath : void 0;
|
|
@@ -31,7 +31,7 @@ const getTransformationOptions = (filePath) => ({
|
|
|
31
31
|
tsconfig: getTsConfigPath(filePath),
|
|
32
32
|
define: { "import.meta.url": JSON.stringify(pathToFileURL(filePath).href) }
|
|
33
33
|
});
|
|
34
|
-
const
|
|
34
|
+
const transpileTSToCJSSync = (code, filePath, options) => {
|
|
35
35
|
return buildSync({
|
|
36
36
|
stdin: {
|
|
37
37
|
contents: code,
|
|
@@ -43,7 +43,7 @@ const transpileTSToMJSSync = (code, filePath, options) => {
|
|
|
43
43
|
...options
|
|
44
44
|
}).outputFiles?.[0].text;
|
|
45
45
|
};
|
|
46
|
-
const
|
|
46
|
+
const transpileTSToCJS = async (code, filePath, options) => {
|
|
47
47
|
return (await build({
|
|
48
48
|
stdin: {
|
|
49
49
|
contents: code,
|
|
@@ -57,5 +57,5 @@ const transpileTSToMJS = async (code, filePath, options) => {
|
|
|
57
57
|
};
|
|
58
58
|
|
|
59
59
|
//#endregion
|
|
60
|
-
export {
|
|
61
|
-
//# sourceMappingURL=
|
|
60
|
+
export { transpileTSToCJS, transpileTSToCJSSync };
|
|
61
|
+
//# sourceMappingURL=transpileTSToCJS.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"transpileTSToCJS.mjs","names":[],"sources":["../../../src/loadExternalFile/transpileTSToCJS.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { dirname, extname, join } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport {\n type BuildOptions,\n type BuildResult,\n build,\n buildSync,\n type Plugin,\n} from 'esbuild';\nimport { getPackageJsonPath } from '..';\nimport { getLoader } from './bundleFile';\n\nexport type ESBuildPlugin = Plugin;\n\nconst getTsConfigPath = (filePath: string): string | undefined => {\n const tsconfigPath = join(\n getPackageJsonPath(dirname(filePath)).baseDir,\n 'tsconfig.json'\n );\n\n // Only return the tsconfig path if it exists\n return existsSync(tsconfigPath) ? tsconfigPath : undefined;\n};\n\nconst getTransformationOptions = (filePath: string): 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 '.md': 'text',\n '.mdx': 'text',\n },\n format: 'cjs',\n target: 'node20',\n platform: 'node',\n write: false,\n packages: 'external',\n bundle: true,\n tsconfig: getTsConfigPath(filePath),\n define: {\n 'import.meta.url': JSON.stringify(pathToFileURL(filePath).href),\n },\n});\n\nexport const transpileTSToCJSSync = (\n code: string,\n filePath: string,\n options?: BuildOptions\n): string | undefined => {\n const extension = extname(filePath);\n const loader = getLoader(extension);\n\n const moduleResult: BuildResult = buildSync({\n stdin: {\n contents: code,\n loader,\n resolveDir: dirname(filePath), // Add resolveDir to resolve imports relative to the file's location\n sourcefile: filePath, // Add sourcefile for better error messages\n },\n ...getTransformationOptions(filePath),\n ...options,\n });\n\n const moduleResultString = moduleResult.outputFiles?.[0].text;\n\n return moduleResultString;\n};\n\nexport const transpileTSToCJS = async (\n code: string,\n filePath: string,\n options?: BuildOptions\n): Promise<string | undefined> => {\n const extension = extname(filePath);\n const loader = getLoader(extension);\n\n const moduleResult: BuildResult = await build({\n stdin: {\n contents: code,\n loader,\n resolveDir: dirname(filePath), // Add resolveDir to resolve imports relative to the file's location\n sourcefile: filePath, // Add sourcefile for better error messages\n },\n ...getTransformationOptions(filePath),\n ...options,\n });\n\n const moduleResultString = moduleResult.outputFiles?.[0].text;\n\n return moduleResultString;\n};\n"],"mappings":";;;;;;;;AAeA,MAAM,mBAAmB,aAAyC;CAChE,MAAM,eAAe,KACnB,mBAAmB,QAAQ,SAAS,CAAC,CAAC,SACtC,gBACD;AAGD,QAAO,WAAW,aAAa,GAAG,eAAe;;AAGnD,MAAM,4BAA4B,cAAoC;CACpE,QAAQ;EACN,OAAO;EACP,QAAQ;EACR,QAAQ;EACR,OAAO;EACP,QAAQ;EACR,QAAQ;EACR,SAAS;EACT,OAAO;EACP,QAAQ;EACT;CACD,QAAQ;CACR,QAAQ;CACR,UAAU;CACV,OAAO;CACP,UAAU;CACV,QAAQ;CACR,UAAU,gBAAgB,SAAS;CACnC,QAAQ,EACN,mBAAmB,KAAK,UAAU,cAAc,SAAS,CAAC,KAAK,EAChE;CACF;AAED,MAAa,wBACX,MACA,UACA,YACuB;AAiBvB,QAbkC,UAAU;EAC1C,OAAO;GACL,UAAU;GACV,QALW,UADG,QAAQ,SAAS,CACA;GAM/B,YAAY,QAAQ,SAAS;GAC7B,YAAY;GACb;EACD,GAAG,yBAAyB,SAAS;EACrC,GAAG;EACJ,CAAC,CAEsC,cAAc,GAAG;;AAK3D,MAAa,mBAAmB,OAC9B,MACA,UACA,YACgC;AAiBhC,SAbkC,MAAM,MAAM;EAC5C,OAAO;GACL,UAAU;GACV,QALW,UADG,QAAQ,SAAS,CACA;GAM/B,YAAY,QAAQ,SAAS;GAC7B,YAAY;GACb;EACD,GAAG,yBAAyB,SAAS;EACrC,GAAG;EACJ,CAAC,EAEsC,cAAc,GAAG"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//#region src/configFile/searchConfigurationFile.d.ts
|
|
2
|
-
declare const configurationFilesCandidates: readonly ["intlayer.config.ts", "intlayer.config.js", "intlayer.config.json", "intlayer.config.cjs", "intlayer.config.mjs", ".intlayerrc"];
|
|
2
|
+
declare const configurationFilesCandidates: readonly ["intlayer.config.ts", "intlayer.config.js", "intlayer.config.json", "intlayer.config.json5", "intlayer.config.jsonc", "intlayer.config.cjs", "intlayer.config.mjs", ".intlayerrc"];
|
|
3
3
|
type SearchConfigurationFileResult = {
|
|
4
4
|
configurationFilePath?: string;
|
|
5
5
|
numCustomConfiguration: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"searchConfigurationFile.d.ts","names":[],"sources":["../../../src/configFile/searchConfigurationFile.ts"],"sourcesContent":[],"mappings":";cAKa;AAAb,
|
|
1
|
+
{"version":3,"file":"searchConfigurationFile.d.ts","names":[],"sources":["../../../src/configFile/searchConfigurationFile.ts"],"sourcesContent":[],"mappings":";cAKa;AAAb,KAWK,6BAAA,GAFK;EAEL,qBAAA,CAAA,EAAA,MAAA;EAgBQ,sBAAA,EAAA,MA4BZ;;;;;;;;;;;;;cA5BY,+CAEV"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content.d.ts","names":[],"sources":["../../../src/defaultValues/content.ts"],"sourcesContent":[],"mappings":";;;cAAa;
|
|
1
|
+
{"version":3,"file":"content.d.ts","names":[],"sources":["../../../src/defaultValues/content.ts"],"sourcesContent":[],"mappings":";;;cAAa;cAaA;cAaA;cAEA,QAAA;cAEA,gBAAA;cAEA,SAAA;cAEA,uBAAA;cAEA,yBAAA;cAEA,wBAAA;cAEA,sBAAA;cAEA,SAAA;cAEA,uBAAA;cAEA,wBAAA;cAEA,uBAAA;cAEA,UAAA;cAEA,SAAA;cAEA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadExternalFile.d.ts","names":[],"sources":["../../../src/loadExternalFile/loadExternalFile.ts"],"sourcesContent":[],"mappings":";;;;;KAaY,aAAA,GAAgB;KAEhB,uBAAA;EAFA,aAAA,CAAA,EAGM,cAHU;EAEhB,YAAA,CAAA,EAEK,YAFkB;CACjB,GAEd,qBAFc;;;;AASlB;
|
|
1
|
+
{"version":3,"file":"loadExternalFile.d.ts","names":[],"sources":["../../../src/loadExternalFile/loadExternalFile.ts"],"sourcesContent":[],"mappings":";;;;;KAaY,aAAA,GAAgB;KAEhB,uBAAA;EAFA,aAAA,CAAA,EAGM,cAHU;EAEhB,YAAA,CAAA,EAEK,YAFkB;CACjB,GAEd,qBAFc;;;;AASlB;AA6DA;cA7Da,mDAED;;;;;;cA2DC,+CAED,4BACT"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BuildOptions, Plugin } from "esbuild";
|
|
2
|
+
|
|
3
|
+
//#region src/loadExternalFile/transpileTSToCJS.d.ts
|
|
4
|
+
type ESBuildPlugin = Plugin;
|
|
5
|
+
declare const transpileTSToCJSSync: (code: string, filePath: string, options?: BuildOptions) => string | undefined;
|
|
6
|
+
declare const transpileTSToCJS: (code: string, filePath: string, options?: BuildOptions) => Promise<string | undefined>;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { ESBuildPlugin, transpileTSToCJS, transpileTSToCJSSync };
|
|
9
|
+
//# sourceMappingURL=transpileTSToCJS.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transpileTSToCJS.d.ts","names":[],"sources":["../../../src/loadExternalFile/transpileTSToCJS.ts"],"sourcesContent":[],"mappings":";;;KAaY,aAAA,GAAgB;cAoCf,iEAGD;AAvCA,cA4DC,gBA5De,EAAA,CAAM,IAAA,EAAA,MAAA,EAAA,QAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EA+DtB,YA/DsB,EAAA,GAgE/B,OAhE+B,CAAA,MAAA,GAAA,SAAA,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/config",
|
|
3
|
-
"version": "7.5.
|
|
3
|
+
"version": "7.5.13",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Retrieve Intlayer configurations and manage environment variables for both server-side and client-side environments.",
|
|
6
6
|
"keywords": [
|
|
@@ -96,10 +96,11 @@
|
|
|
96
96
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
97
97
|
},
|
|
98
98
|
"dependencies": {
|
|
99
|
-
"@intlayer/types": "7.5.
|
|
99
|
+
"@intlayer/types": "7.5.13",
|
|
100
100
|
"defu": "6.1.4",
|
|
101
101
|
"dotenv": "16.6.1",
|
|
102
|
-
"esbuild": "0.27.2"
|
|
102
|
+
"esbuild": "0.27.2",
|
|
103
|
+
"json5": "^2.2.3"
|
|
103
104
|
},
|
|
104
105
|
"devDependencies": {
|
|
105
106
|
"@types/node": "25.0.3",
|
|
@@ -112,7 +113,7 @@
|
|
|
112
113
|
"vitest": "4.0.16"
|
|
113
114
|
},
|
|
114
115
|
"peerDependencies": {
|
|
115
|
-
"intlayer": "7.5.
|
|
116
|
+
"intlayer": "7.5.13",
|
|
116
117
|
"react": ">=16.0.0"
|
|
117
118
|
},
|
|
118
119
|
"peerDependenciesMeta": {
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { BuildOptions, Plugin } from "esbuild";
|
|
2
|
-
|
|
3
|
-
//#region src/loadExternalFile/transpileTSToMJS.d.ts
|
|
4
|
-
type ESBuildPlugin = Plugin;
|
|
5
|
-
declare const transpileTSToMJSSync: (code: string, filePath: string, options?: BuildOptions) => string | undefined;
|
|
6
|
-
declare const transpileTSToMJS: (code: string, filePath: string, options?: BuildOptions) => Promise<string | undefined>;
|
|
7
|
-
//#endregion
|
|
8
|
-
export { ESBuildPlugin, transpileTSToMJS, transpileTSToMJSSync };
|
|
9
|
-
//# sourceMappingURL=transpileTSToMJS.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transpileTSToMJS.d.ts","names":[],"sources":["../../../src/loadExternalFile/transpileTSToMJS.ts"],"sourcesContent":[],"mappings":";;;KAaY,aAAA,GAAgB;cAoCf,iEAGD;AAvCA,cA4DC,gBA5De,EAAM,CAAA,IAAA,EAAA,MAAA,EAAA,QAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EA+DtB,YA/DsB,EAAA,GAgE/B,OAhE+B,CAAA,MAAA,GAAA,SAAA,CAAA"}
|