@intlayer/config 5.3.0 → 5.3.2

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.
@@ -39,7 +39,10 @@ const getSandBoxContext = (envVarOptions) => {
39
39
  },
40
40
  process: {
41
41
  ...process,
42
- env: { ...process.env, ...(0, import_loadEnvFile.loadEnvFile)(envVarOptions) }
42
+ env: {
43
+ ...process.env,
44
+ ...(0, import_loadEnvFile.loadEnvFile)(envVarOptions)
45
+ }
43
46
  },
44
47
  console,
45
48
  require: import_ESMxCJSRequire.ESMxCJSRequire,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/getSandboxContext.ts"],"sourcesContent":["import type { Context } from 'vm';\nimport {\n type LoadEnvFileOptions,\n loadEnvFile,\n} from './envVariables/loadEnvFile';\nimport { ESMxCJSRequire } from './utils/ESMxCJSRequire';\n\nexport const getSandBoxContext = (\n envVarOptions?: LoadEnvFileOptions\n): Context => {\n let ReactModule;\n\n try {\n // Dynamically try to require React if it's installed in the project\n ReactModule = ESMxCJSRequire('react');\n } catch (err) {\n // React is not installed, so we don't inject it\n ReactModule = undefined;\n }\n\n const sandboxContext: Context = {\n exports: {\n default: {},\n },\n module: {\n exports: {},\n },\n process: {\n ...process,\n env: { ...process.env, ...loadEnvFile(envVarOptions) },\n },\n console,\n require: ESMxCJSRequire,\n ...(ReactModule ? { React: ReactModule } : {}), // Only inject React if found\n };\n\n // Dynamically inject all global variables\n Object.getOwnPropertyNames(globalThis).forEach((key) => {\n if (!(key in sandboxContext)) {\n sandboxContext[key] = globalThis[key as keyof typeof globalThis];\n }\n });\n\n return sandboxContext;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,yBAGO;AACP,4BAA+B;AAExB,MAAM,oBAAoB,CAC/B,kBACY;AACZ,MAAI;AAEJ,MAAI;AAEF,sBAAc,sCAAe,OAAO;AAAA,EACtC,SAAS,KAAK;AAEZ,kBAAc;AAAA,EAChB;AAEA,QAAM,iBAA0B;AAAA,IAC9B,SAAS;AAAA,MACP,SAAS,CAAC;AAAA,IACZ;AAAA,IACA,QAAQ;AAAA,MACN,SAAS,CAAC;AAAA,IACZ;AAAA,IACA,SAAS;AAAA,MACP,GAAG;AAAA,MACH,KAAK,EAAE,GAAG,QAAQ,KAAK,OAAG,gCAAY,aAAa,EAAE;AAAA,IACvD;AAAA,IACA;AAAA,IACA,SAAS;AAAA,IACT,GAAI,cAAc,EAAE,OAAO,YAAY,IAAI,CAAC;AAAA;AAAA,EAC9C;AAGA,SAAO,oBAAoB,UAAU,EAAE,QAAQ,CAAC,QAAQ;AACtD,QAAI,EAAE,OAAO,iBAAiB;AAC5B,qBAAe,GAAG,IAAI,WAAW,GAA8B;AAAA,IACjE;AAAA,EACF,CAAC;AAED,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/getSandboxContext.ts"],"sourcesContent":["import type { Context } from 'vm';\nimport {\n type LoadEnvFileOptions,\n loadEnvFile,\n} from './envVariables/loadEnvFile';\nimport { ESMxCJSRequire } from './utils/ESMxCJSRequire';\n\nexport const getSandBoxContext = (\n envVarOptions?: LoadEnvFileOptions\n): Context => {\n let ReactModule;\n\n try {\n // Dynamically try to require React if it's installed in the project\n ReactModule = ESMxCJSRequire('react');\n } catch (err) {\n // React is not installed, so we don't inject it\n ReactModule = undefined;\n }\n\n const sandboxContext: Context = {\n exports: {\n default: {},\n },\n module: {\n exports: {},\n },\n process: {\n ...process,\n env: {\n ...process.env,\n ...loadEnvFile(envVarOptions),\n },\n },\n console,\n require: ESMxCJSRequire,\n ...(ReactModule ? { React: ReactModule } : {}), // Only inject React if found\n };\n\n // Dynamically inject all global variables\n Object.getOwnPropertyNames(globalThis).forEach((key) => {\n if (!(key in sandboxContext)) {\n sandboxContext[key] = globalThis[key as keyof typeof globalThis];\n }\n });\n\n return sandboxContext;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,yBAGO;AACP,4BAA+B;AAExB,MAAM,oBAAoB,CAC/B,kBACY;AACZ,MAAI;AAEJ,MAAI;AAEF,sBAAc,sCAAe,OAAO;AAAA,EACtC,SAAS,KAAK;AAEZ,kBAAc;AAAA,EAChB;AAEA,QAAM,iBAA0B;AAAA,IAC9B,SAAS;AAAA,MACP,SAAS,CAAC;AAAA,IACZ;AAAA,IACA,QAAQ;AAAA,MACN,SAAS,CAAC;AAAA,IACZ;AAAA,IACA,SAAS;AAAA,MACP,GAAG;AAAA,MACH,KAAK;AAAA,QACH,GAAG,QAAQ;AAAA,QACX,OAAG,gCAAY,aAAa;AAAA,MAC9B;AAAA,IACF;AAAA,IACA;AAAA,IACA,SAAS;AAAA,IACT,GAAI,cAAc,EAAE,OAAO,YAAY,IAAI,CAAC;AAAA;AAAA,EAC9C;AAGA,SAAO,oBAAoB,UAAU,EAAE,QAAQ,CAAC,QAAQ;AACtD,QAAI,EAAE,OAAO,iBAAiB;AAC5B,qBAAe,GAAG,IAAI,WAAW,GAA8B;AAAA,IACjE;AAAA,EACF,CAAC;AAED,SAAO;AACT;","names":[]}
@@ -26,33 +26,32 @@ var import_esbuild = require("esbuild");
26
26
  var import_getSandboxContext = require('./getSandboxContext.cjs');
27
27
  var import_ESMxCJSRequire = require('./utils/ESMxCJSRequire.cjs');
28
28
  var import_logger = require('./logger.cjs');
29
- const getTransformationOptions = () => {
30
- const define = {};
31
- for (const k in process.env) {
32
- define[`process.env.${k}`] = JSON.stringify(process.env[k]);
29
+ var import_path = require("path");
30
+ const getTransformationOptions = (filePath) => ({
31
+ loader: {
32
+ ".js": "js",
33
+ ".jsx": "jsx",
34
+ ".mjs": "js",
35
+ ".ts": "ts",
36
+ ".tsx": "tsx",
37
+ ".cjs": "js",
38
+ ".json": "json",
39
+ ".md": "text",
40
+ ".mdx": "text"
41
+ },
42
+ format: "cjs",
43
+ // Output format as commonjs
44
+ target: "es2017",
45
+ packages: "external",
46
+ write: false,
47
+ bundle: true,
48
+ banner: {
49
+ js: `
50
+ globalThis.intlayer_file_path = ${JSON.stringify(filePath)};
51
+ globalThis.intlayer_file_dir = ${JSON.stringify((0, import_path.dirname)(filePath))};
52
+ `
33
53
  }
34
- const transformationOption = {
35
- loader: {
36
- ".js": "js",
37
- ".jsx": "jsx",
38
- ".mjs": "js",
39
- ".ts": "ts",
40
- ".tsx": "tsx",
41
- ".cjs": "js",
42
- ".json": "json",
43
- ".md": "text",
44
- ".mdx": "text"
45
- },
46
- format: "cjs",
47
- // Output format as commonjs
48
- target: "es2017",
49
- packages: "external",
50
- write: false,
51
- bundle: true,
52
- define
53
- };
54
- return transformationOption;
55
- };
54
+ });
56
55
  const loadExternalFile = (filePath, envVarOptions) => {
57
56
  let fileContent = void 0;
58
57
  const fileExtension = filePath.split(".").pop() ?? "";
@@ -62,7 +61,7 @@ const loadExternalFile = (filePath, envVarOptions) => {
62
61
  }
63
62
  const moduleResult = (0, import_esbuild.buildSync)({
64
63
  entryPoints: [filePath],
65
- ...getTransformationOptions()
64
+ ...getTransformationOptions(filePath)
66
65
  });
67
66
  const moduleResultString = moduleResult.outputFiles?.[0].text;
68
67
  if (!moduleResultString) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/loadExternalFile.ts"],"sourcesContent":["import { runInNewContext } from 'vm';\nimport { type BuildOptions, buildSync, type BuildResult } from 'esbuild';\nimport { getSandBoxContext } from './getSandboxContext';\nimport { ESMxCJSRequire } from './utils/ESMxCJSRequire';\nimport { logger } from './logger';\nimport { LoadEnvFileOptions } from './envVariables/loadEnvFile';\n\nconst getTransformationOptions = (): BuildOptions => {\n const define: Record<string, string> = {};\n\n for (const k in process.env) {\n define[`process.env.${k}`] = JSON.stringify(process.env[k]);\n }\n\n const 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 '.md': 'text',\n '.mdx': 'text',\n },\n format: 'cjs', // Output format as commonjs\n target: 'es2017',\n packages: 'external',\n write: false,\n bundle: true,\n define,\n };\n\n return transformationOption;\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 = (\n filePath: string,\n envVarOptions?: LoadEnvFileOptions\n): any | undefined => {\n let fileContent: any | undefined = undefined;\n\n const fileExtension = filePath.split('.').pop() ?? '';\n\n try {\n if (fileExtension === 'json') {\n // Assume JSON\n return ESMxCJSRequire(filePath);\n }\n\n // Rest is JS, MJS or TS\n\n const moduleResult: BuildResult = buildSync({\n entryPoints: [filePath],\n ...getTransformationOptions(),\n });\n\n const moduleResultString = moduleResult.outputFiles?.[0].text;\n\n if (!moduleResultString) {\n logger('File could not be loaded.', { level: 'error' });\n return undefined;\n }\n\n const sandboxContext = getSandBoxContext(envVarOptions);\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 fileContent = sandboxContext.exports.default;\n } else if (\n sandboxContext.module.exports.defaults &&\n Object.keys(sandboxContext.module.exports.defaults).length > 0\n ) {\n // CommonJS\n fileContent = 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 fileContent = sandboxContext.module.exports.default;\n } else if (\n sandboxContext.module.exports &&\n Object.keys(sandboxContext.module.exports).length > 0\n ) {\n // Other\n fileContent = sandboxContext.module.exports;\n }\n\n if (typeof fileContent === 'undefined') {\n logger(`File file could not be loaded. Path : ${filePath}`);\n return undefined;\n }\n\n return fileContent;\n } catch (error) {\n logger(\n `Error: ${error} ${JSON.stringify((error as Error).stack, null, 2)}`,\n {\n level: 'error',\n }\n );\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAgC;AAChC,qBAA+D;AAC/D,+BAA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AQ,QAAQ,EAAE,SAAS,GAC7D;AAEA,oBAAc,eAAe,OAAO,QAAQ;AAAA,IAC9C,WACE,eAAe,OAAO,QAAQ,WAC9B,OAAO,KAAK,eAAe,OAAO,QAAQ,OAAO,EAAE,SAAS,GAC5D;AAEA,oBAAc,eAAe,OAAO,QAAQ;AAAA,IAC9C,WACE,eAAe,OAAO,WACtB,OAAO,KAAK,eAAe,OAAO,OAAO,EAAE,SAAS,GACpD;AAEA,oBAAc,eAAe,OAAO;AAAA,IACtC;AAEA,QAAI,OAAO,gBAAgB,aAAa;AACtC,gCAAO,yCAAyC,QAAQ,EAAE;AAC1D,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT,SAAS,OAAO;AACd;AAAA,MACE,UAAU,KAAK,IAAI,KAAK,UAAW,MAAgB,OAAO,MAAM,CAAC,CAAC;AAAA,MAClE;AAAA,QACE,OAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/loadExternalFile.ts"],"sourcesContent":["import { runInNewContext } from 'vm';\nimport { type BuildOptions, buildSync, type BuildResult } from 'esbuild';\nimport { getSandBoxContext } from './getSandboxContext';\nimport { ESMxCJSRequire } from './utils/ESMxCJSRequire';\nimport { logger } from './logger';\nimport { LoadEnvFileOptions } from './envVariables/loadEnvFile';\nimport { dirname } from 'path';\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', // Output format as commonjs\n target: 'es2017',\n packages: 'external',\n write: false,\n bundle: true,\n banner: {\n js: `\n globalThis.intlayer_file_path = ${JSON.stringify(filePath)};\n globalThis.intlayer_file_dir = ${JSON.stringify(dirname(filePath))};\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 = (\n filePath: string,\n envVarOptions?: LoadEnvFileOptions\n): any | undefined => {\n let fileContent: any | undefined = undefined;\n\n const fileExtension = filePath.split('.').pop() ?? '';\n\n try {\n if (fileExtension === 'json') {\n // Assume JSON\n return ESMxCJSRequire(filePath);\n }\n\n // Rest is JS, MJS or TS\n\n const moduleResult: BuildResult = buildSync({\n entryPoints: [filePath],\n ...getTransformationOptions(filePath),\n });\n\n const moduleResultString = moduleResult.outputFiles?.[0].text;\n\n if (!moduleResultString) {\n logger('File could not be loaded.', { level: 'error' });\n return undefined;\n }\n\n const sandboxContext = getSandBoxContext(envVarOptions);\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 fileContent = sandboxContext.exports.default;\n } else if (\n sandboxContext.module.exports.defaults &&\n Object.keys(sandboxContext.module.exports.defaults).length > 0\n ) {\n // CommonJS\n fileContent = 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 fileContent = sandboxContext.module.exports.default;\n } else if (\n sandboxContext.module.exports &&\n Object.keys(sandboxContext.module.exports).length > 0\n ) {\n // Other\n fileContent = sandboxContext.module.exports;\n }\n\n if (typeof fileContent === 'undefined') {\n logger(`File file could not be loaded. Path : ${filePath}`);\n return undefined;\n }\n\n return fileContent;\n } catch (error) {\n logger(\n `Error: ${error} ${JSON.stringify((error as Error).stack, null, 2)}`,\n {\n level: 'error',\n }\n );\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAgC;AAChC,qBAA+D;AAC/D,+BAAkC;AAClC,4BAA+B;AAC/B,oBAAuB;AAEvB,kBAAwB;AAExB,MAAM,2BAA2B,CAAC,cAAoC;AAAA,EACpE,QAAQ;AAAA,IACN,OAAO;AAAA,IACP,QAAQ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C5D;AAEA,oBAAc,eAAe,OAAO,QAAQ;AAAA,IAC9C,WACE,eAAe,OAAO,WACtB,OAAO,KAAK,eAAe,OAAO,OAAO,EAAE,SAAS,GACpD;AAEA,oBAAc,eAAe,OAAO;AAAA,IACtC;AAEA,QAAI,OAAO,gBAAgB,aAAa;AACtC,gCAAO,yCAAyC,QAAQ,EAAE;AAC1D,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT,SAAS,OAAO;AACd;AAAA,MACE,UAAU,KAAK,IAAI,KAAK,UAAW,MAAgB,OAAO,MAAM,CAAC,CAAC;AAAA,MAClE;AAAA,QACE,OAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -18,7 +18,10 @@ const getSandBoxContext = (envVarOptions) => {
18
18
  },
19
19
  process: {
20
20
  ...process,
21
- env: { ...process.env, ...loadEnvFile(envVarOptions) }
21
+ env: {
22
+ ...process.env,
23
+ ...loadEnvFile(envVarOptions)
24
+ }
22
25
  },
23
26
  console,
24
27
  require: ESMxCJSRequire,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/getSandboxContext.ts"],"sourcesContent":["import type { Context } from 'vm';\nimport {\n type LoadEnvFileOptions,\n loadEnvFile,\n} from './envVariables/loadEnvFile';\nimport { ESMxCJSRequire } from './utils/ESMxCJSRequire';\n\nexport const getSandBoxContext = (\n envVarOptions?: LoadEnvFileOptions\n): Context => {\n let ReactModule;\n\n try {\n // Dynamically try to require React if it's installed in the project\n ReactModule = ESMxCJSRequire('react');\n } catch (err) {\n // React is not installed, so we don't inject it\n ReactModule = undefined;\n }\n\n const sandboxContext: Context = {\n exports: {\n default: {},\n },\n module: {\n exports: {},\n },\n process: {\n ...process,\n env: { ...process.env, ...loadEnvFile(envVarOptions) },\n },\n console,\n require: ESMxCJSRequire,\n ...(ReactModule ? { React: ReactModule } : {}), // Only inject React if found\n };\n\n // Dynamically inject all global variables\n Object.getOwnPropertyNames(globalThis).forEach((key) => {\n if (!(key in sandboxContext)) {\n sandboxContext[key] = globalThis[key as keyof typeof globalThis];\n }\n });\n\n return sandboxContext;\n};\n"],"mappings":"AACA;AAAA,EAEE;AAAA,OACK;AACP,SAAS,sBAAsB;AAExB,MAAM,oBAAoB,CAC/B,kBACY;AACZ,MAAI;AAEJ,MAAI;AAEF,kBAAc,eAAe,OAAO;AAAA,EACtC,SAAS,KAAK;AAEZ,kBAAc;AAAA,EAChB;AAEA,QAAM,iBAA0B;AAAA,IAC9B,SAAS;AAAA,MACP,SAAS,CAAC;AAAA,IACZ;AAAA,IACA,QAAQ;AAAA,MACN,SAAS,CAAC;AAAA,IACZ;AAAA,IACA,SAAS;AAAA,MACP,GAAG;AAAA,MACH,KAAK,EAAE,GAAG,QAAQ,KAAK,GAAG,YAAY,aAAa,EAAE;AAAA,IACvD;AAAA,IACA;AAAA,IACA,SAAS;AAAA,IACT,GAAI,cAAc,EAAE,OAAO,YAAY,IAAI,CAAC;AAAA;AAAA,EAC9C;AAGA,SAAO,oBAAoB,UAAU,EAAE,QAAQ,CAAC,QAAQ;AACtD,QAAI,EAAE,OAAO,iBAAiB;AAC5B,qBAAe,GAAG,IAAI,WAAW,GAA8B;AAAA,IACjE;AAAA,EACF,CAAC;AAED,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/getSandboxContext.ts"],"sourcesContent":["import type { Context } from 'vm';\nimport {\n type LoadEnvFileOptions,\n loadEnvFile,\n} from './envVariables/loadEnvFile';\nimport { ESMxCJSRequire } from './utils/ESMxCJSRequire';\n\nexport const getSandBoxContext = (\n envVarOptions?: LoadEnvFileOptions\n): Context => {\n let ReactModule;\n\n try {\n // Dynamically try to require React if it's installed in the project\n ReactModule = ESMxCJSRequire('react');\n } catch (err) {\n // React is not installed, so we don't inject it\n ReactModule = undefined;\n }\n\n const sandboxContext: Context = {\n exports: {\n default: {},\n },\n module: {\n exports: {},\n },\n process: {\n ...process,\n env: {\n ...process.env,\n ...loadEnvFile(envVarOptions),\n },\n },\n console,\n require: ESMxCJSRequire,\n ...(ReactModule ? { React: ReactModule } : {}), // Only inject React if found\n };\n\n // Dynamically inject all global variables\n Object.getOwnPropertyNames(globalThis).forEach((key) => {\n if (!(key in sandboxContext)) {\n sandboxContext[key] = globalThis[key as keyof typeof globalThis];\n }\n });\n\n return sandboxContext;\n};\n"],"mappings":"AACA;AAAA,EAEE;AAAA,OACK;AACP,SAAS,sBAAsB;AAExB,MAAM,oBAAoB,CAC/B,kBACY;AACZ,MAAI;AAEJ,MAAI;AAEF,kBAAc,eAAe,OAAO;AAAA,EACtC,SAAS,KAAK;AAEZ,kBAAc;AAAA,EAChB;AAEA,QAAM,iBAA0B;AAAA,IAC9B,SAAS;AAAA,MACP,SAAS,CAAC;AAAA,IACZ;AAAA,IACA,QAAQ;AAAA,MACN,SAAS,CAAC;AAAA,IACZ;AAAA,IACA,SAAS;AAAA,MACP,GAAG;AAAA,MACH,KAAK;AAAA,QACH,GAAG,QAAQ;AAAA,QACX,GAAG,YAAY,aAAa;AAAA,MAC9B;AAAA,IACF;AAAA,IACA;AAAA,IACA,SAAS;AAAA,IACT,GAAI,cAAc,EAAE,OAAO,YAAY,IAAI,CAAC;AAAA;AAAA,EAC9C;AAGA,SAAO,oBAAoB,UAAU,EAAE,QAAQ,CAAC,QAAQ;AACtD,QAAI,EAAE,OAAO,iBAAiB;AAC5B,qBAAe,GAAG,IAAI,WAAW,GAA8B;AAAA,IACjE;AAAA,EACF,CAAC;AAED,SAAO;AACT;","names":[]}
@@ -3,33 +3,32 @@ import { buildSync } from "esbuild";
3
3
  import { getSandBoxContext } from "./getSandboxContext.mjs";
4
4
  import { ESMxCJSRequire } from "./utils/ESMxCJSRequire.mjs";
5
5
  import { logger } from "./logger.mjs";
6
- const getTransformationOptions = () => {
7
- const define = {};
8
- for (const k in process.env) {
9
- define[`process.env.${k}`] = JSON.stringify(process.env[k]);
6
+ import { dirname } from "path";
7
+ const getTransformationOptions = (filePath) => ({
8
+ loader: {
9
+ ".js": "js",
10
+ ".jsx": "jsx",
11
+ ".mjs": "js",
12
+ ".ts": "ts",
13
+ ".tsx": "tsx",
14
+ ".cjs": "js",
15
+ ".json": "json",
16
+ ".md": "text",
17
+ ".mdx": "text"
18
+ },
19
+ format: "cjs",
20
+ // Output format as commonjs
21
+ target: "es2017",
22
+ packages: "external",
23
+ write: false,
24
+ bundle: true,
25
+ banner: {
26
+ js: `
27
+ globalThis.intlayer_file_path = ${JSON.stringify(filePath)};
28
+ globalThis.intlayer_file_dir = ${JSON.stringify(dirname(filePath))};
29
+ `
10
30
  }
11
- const transformationOption = {
12
- loader: {
13
- ".js": "js",
14
- ".jsx": "jsx",
15
- ".mjs": "js",
16
- ".ts": "ts",
17
- ".tsx": "tsx",
18
- ".cjs": "js",
19
- ".json": "json",
20
- ".md": "text",
21
- ".mdx": "text"
22
- },
23
- format: "cjs",
24
- // Output format as commonjs
25
- target: "es2017",
26
- packages: "external",
27
- write: false,
28
- bundle: true,
29
- define
30
- };
31
- return transformationOption;
32
- };
31
+ });
33
32
  const loadExternalFile = (filePath, envVarOptions) => {
34
33
  let fileContent = void 0;
35
34
  const fileExtension = filePath.split(".").pop() ?? "";
@@ -39,7 +38,7 @@ const loadExternalFile = (filePath, envVarOptions) => {
39
38
  }
40
39
  const moduleResult = buildSync({
41
40
  entryPoints: [filePath],
42
- ...getTransformationOptions()
41
+ ...getTransformationOptions(filePath)
43
42
  });
44
43
  const moduleResultString = moduleResult.outputFiles?.[0].text;
45
44
  if (!moduleResultString) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/loadExternalFile.ts"],"sourcesContent":["import { runInNewContext } from 'vm';\nimport { type BuildOptions, buildSync, type BuildResult } from 'esbuild';\nimport { getSandBoxContext } from './getSandboxContext';\nimport { ESMxCJSRequire } from './utils/ESMxCJSRequire';\nimport { logger } from './logger';\nimport { LoadEnvFileOptions } from './envVariables/loadEnvFile';\n\nconst getTransformationOptions = (): BuildOptions => {\n const define: Record<string, string> = {};\n\n for (const k in process.env) {\n define[`process.env.${k}`] = JSON.stringify(process.env[k]);\n }\n\n const 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 '.md': 'text',\n '.mdx': 'text',\n },\n format: 'cjs', // Output format as commonjs\n target: 'es2017',\n packages: 'external',\n write: false,\n bundle: true,\n define,\n };\n\n return transformationOption;\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 = (\n filePath: string,\n envVarOptions?: LoadEnvFileOptions\n): any | undefined => {\n let fileContent: any | undefined = undefined;\n\n const fileExtension = filePath.split('.').pop() ?? '';\n\n try {\n if (fileExtension === 'json') {\n // Assume JSON\n return ESMxCJSRequire(filePath);\n }\n\n // Rest is JS, MJS or TS\n\n const moduleResult: BuildResult = buildSync({\n entryPoints: [filePath],\n ...getTransformationOptions(),\n });\n\n const moduleResultString = moduleResult.outputFiles?.[0].text;\n\n if (!moduleResultString) {\n logger('File could not be loaded.', { level: 'error' });\n return undefined;\n }\n\n const sandboxContext = getSandBoxContext(envVarOptions);\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 fileContent = sandboxContext.exports.default;\n } else if (\n sandboxContext.module.exports.defaults &&\n Object.keys(sandboxContext.module.exports.defaults).length > 0\n ) {\n // CommonJS\n fileContent = 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 fileContent = sandboxContext.module.exports.default;\n } else if (\n sandboxContext.module.exports &&\n Object.keys(sandboxContext.module.exports).length > 0\n ) {\n // Other\n fileContent = sandboxContext.module.exports;\n }\n\n if (typeof fileContent === 'undefined') {\n logger(`File file could not be loaded. Path : ${filePath}`);\n return undefined;\n }\n\n return fileContent;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AAe,QAAQ,WACvB,OAAO,KAAK,eAAe,QAAQ,OAAO,EAAE,SAAS,GACrD;AAEA,oBAAc,eAAe,QAAQ;AAAA,IACvC,WACE,eAAe,OAAO,QAAQ,YAC9B,OAAO,KAAK,eAAe,OAAO,QAAQ,QAAQ,EAAE,SAAS,GAC7D;AAEA,oBAAc,eAAe,OAAO,QAAQ;AAAA,IAC9C,WACE,eAAe,OAAO,QAAQ,WAC9B,OAAO,KAAK,eAAe,OAAO,QAAQ,OAAO,EAAE,SAAS,GAC5D;AAEA,oBAAc,eAAe,OAAO,QAAQ;AAAA,IAC9C,WACE,eAAe,OAAO,WACtB,OAAO,KAAK,eAAe,OAAO,OAAO,EAAE,SAAS,GACpD;AAEA,oBAAc,eAAe,OAAO;AAAA,IACtC;AAEA,QAAI,OAAO,gBAAgB,aAAa;AACtC,aAAO,yCAAyC,QAAQ,EAAE;AAC1D,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT,SAAS,OAAO;AACd;AAAA,MACE,UAAU,KAAK,IAAI,KAAK,UAAW,MAAgB,OAAO,MAAM,CAAC,CAAC;AAAA,MAClE;AAAA,QACE,OAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/loadExternalFile.ts"],"sourcesContent":["import { runInNewContext } from 'vm';\nimport { type BuildOptions, buildSync, type BuildResult } from 'esbuild';\nimport { getSandBoxContext } from './getSandboxContext';\nimport { ESMxCJSRequire } from './utils/ESMxCJSRequire';\nimport { logger } from './logger';\nimport { LoadEnvFileOptions } from './envVariables/loadEnvFile';\nimport { dirname } from 'path';\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', // Output format as commonjs\n target: 'es2017',\n packages: 'external',\n write: false,\n bundle: true,\n banner: {\n js: `\n globalThis.intlayer_file_path = ${JSON.stringify(filePath)};\n globalThis.intlayer_file_dir = ${JSON.stringify(dirname(filePath))};\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 = (\n filePath: string,\n envVarOptions?: LoadEnvFileOptions\n): any | undefined => {\n let fileContent: any | undefined = undefined;\n\n const fileExtension = filePath.split('.').pop() ?? '';\n\n try {\n if (fileExtension === 'json') {\n // Assume JSON\n return ESMxCJSRequire(filePath);\n }\n\n // Rest is JS, MJS or TS\n\n const moduleResult: BuildResult = buildSync({\n entryPoints: [filePath],\n ...getTransformationOptions(filePath),\n });\n\n const moduleResultString = moduleResult.outputFiles?.[0].text;\n\n if (!moduleResultString) {\n logger('File could not be loaded.', { level: 'error' });\n return undefined;\n }\n\n const sandboxContext = getSandBoxContext(envVarOptions);\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 fileContent = sandboxContext.exports.default;\n } else if (\n sandboxContext.module.exports.defaults &&\n Object.keys(sandboxContext.module.exports.defaults).length > 0\n ) {\n // CommonJS\n fileContent = 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 fileContent = sandboxContext.module.exports.default;\n } else if (\n sandboxContext.module.exports &&\n Object.keys(sandboxContext.module.exports).length > 0\n ) {\n // Other\n fileContent = sandboxContext.module.exports;\n }\n\n if (typeof fileContent === 'undefined') {\n logger(`File file could not be loaded. Path : ${filePath}`);\n return undefined;\n }\n\n return fileContent;\n } catch (error) {\n logger(\n `Error: ${error} ${JSON.stringify((error as Error).stack, null, 2)}`,\n {\n level: 'error',\n }\n );\n }\n};\n"],"mappings":"AAAA,SAAS,uBAAuB;AAChC,SAA4B,iBAAmC;AAC/D,SAAS,yBAAyB;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,GAC7D;AAEA,oBAAc,eAAe,OAAO,QAAQ;AAAA,IAC9C,WACE,eAAe,OAAO,QAAQ,WAC9B,OAAO,KAAK,eAAe,OAAO,QAAQ,OAAO,EAAE,SAAS,GAC5D;AAEA,oBAAc,eAAe,OAAO,QAAQ;AAAA,IAC9C,WACE,eAAe,OAAO,WACtB,OAAO,KAAK,eAAe,OAAO,OAAO,EAAE,SAAS,GACpD;AAEA,oBAAc,eAAe,OAAO;AAAA,IACtC;AAEA,QAAI,OAAO,gBAAgB,aAAa;AACtC,aAAO,yCAAyC,QAAQ,EAAE;AAC1D,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT,SAAS,OAAO;AACd;AAAA,MACE,UAAU,KAAK,IAAI,KAAK,UAAW,MAAgB,OAAO,MAAM,CAAC,CAAC;AAAA,MAClE;AAAA,QACE,OAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"getSandboxContext.d.ts","sourceRoot":"","sources":["../../src/getSandboxContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAClC,OAAO,EACL,KAAK,kBAAkB,EAExB,MAAM,4BAA4B,CAAC;AAGpC,eAAO,MAAM,iBAAiB,GAC5B,gBAAgB,kBAAkB,KACjC,OAmCF,CAAC"}
1
+ {"version":3,"file":"getSandboxContext.d.ts","sourceRoot":"","sources":["../../src/getSandboxContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAClC,OAAO,EACL,KAAK,kBAAkB,EAExB,MAAM,4BAA4B,CAAC;AAGpC,eAAO,MAAM,iBAAiB,GAC5B,gBAAgB,kBAAkB,KACjC,OAsCF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"loadExternalFile.d.ts","sourceRoot":"","sources":["../../src/loadExternalFile.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAgChE;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAC3B,UAAU,MAAM,EAChB,gBAAgB,kBAAkB,KACjC,GAAG,GAAG,SAqER,CAAC"}
1
+ {"version":3,"file":"loadExternalFile.d.ts","sourceRoot":"","sources":["../../src/loadExternalFile.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AA4BhE;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAC3B,UAAU,MAAM,EAChB,gBAAgB,kBAAkB,KACjC,GAAG,GAAG,SAqER,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlayer/config",
3
- "version": "5.3.0",
3
+ "version": "5.3.2",
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": [
@@ -83,12 +83,12 @@
83
83
  "tsup": "^8.3.5",
84
84
  "typescript": "^5.7.3",
85
85
  "@utils/eslint-config": "1.0.4",
86
- "@utils/ts-config": "1.0.4",
87
86
  "@utils/tsup-config": "1.0.4",
88
- "@utils/ts-config-types": "1.0.4"
87
+ "@utils/ts-config-types": "1.0.4",
88
+ "@utils/ts-config": "1.0.4"
89
89
  },
90
90
  "peerDependencies": {
91
- "intlayer": "5.3.0"
91
+ "intlayer": "5.3.2"
92
92
  },
93
93
  "engines": {
94
94
  "node": ">=14.18"