@intlayer/config 5.3.5 → 5.3.6
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/getSandboxContext.cjs +7 -7
- package/dist/cjs/getSandboxContext.cjs.map +1 -1
- package/dist/cjs/loadExternalFile.cjs +2 -2
- package/dist/cjs/loadExternalFile.cjs.map +1 -1
- package/dist/esm/getSandboxContext.mjs +7 -7
- package/dist/esm/getSandboxContext.mjs.map +1 -1
- package/dist/esm/loadExternalFile.mjs +2 -2
- package/dist/esm/loadExternalFile.mjs.map +1 -1
- package/dist/types/getSandboxContext.d.ts +1 -1
- package/dist/types/getSandboxContext.d.ts.map +1 -1
- package/dist/types/loadExternalFile.d.ts +1 -1
- package/dist/types/loadExternalFile.d.ts.map +1 -1
- package/package.json +3 -3
|
@@ -23,12 +23,13 @@ __export(getSandboxContext_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(getSandboxContext_exports);
|
|
24
24
|
var import_loadEnvFile = require('./envVariables/loadEnvFile.cjs');
|
|
25
25
|
var import_ESMxCJSRequire = require('./utils/ESMxCJSRequire.cjs');
|
|
26
|
-
const getSandBoxContext = (envVarOptions) => {
|
|
27
|
-
let
|
|
26
|
+
const getSandBoxContext = (envVarOptions, projectRequire = import_ESMxCJSRequire.ESMxCJSRequire) => {
|
|
27
|
+
let additionalGlobalVar = {};
|
|
28
28
|
try {
|
|
29
|
-
|
|
29
|
+
additionalGlobalVar = {
|
|
30
|
+
React: projectRequire("react")
|
|
31
|
+
};
|
|
30
32
|
} catch (err) {
|
|
31
|
-
ReactModule = void 0;
|
|
32
33
|
}
|
|
33
34
|
const sandboxContext = {
|
|
34
35
|
exports: {
|
|
@@ -45,9 +46,8 @@ const getSandBoxContext = (envVarOptions) => {
|
|
|
45
46
|
}
|
|
46
47
|
},
|
|
47
48
|
console,
|
|
48
|
-
require:
|
|
49
|
-
...
|
|
50
|
-
// Only inject React if found
|
|
49
|
+
require: projectRequire,
|
|
50
|
+
...additionalGlobalVar
|
|
51
51
|
};
|
|
52
52
|
Object.getOwnPropertyNames(globalThis).forEach((key) => {
|
|
53
53
|
if (!(key in sandboxContext)) {
|
|
@@ -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
|
|
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 projectRequire = ESMxCJSRequire\n): Context => {\n let additionalGlobalVar = {};\n\n try {\n // Dynamically try to require React if it's installed in the project\n additionalGlobalVar = {\n React: projectRequire('react'),\n };\n } catch (err) {\n // React is not installed, so we don't inject it\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: projectRequire,\n ...additionalGlobalVar,\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,eACA,iBAAiB,yCACL;AACZ,MAAI,sBAAsB,CAAC;AAE3B,MAAI;AAEF,0BAAsB;AAAA,MACpB,OAAO,eAAe,OAAO;AAAA,IAC/B;AAAA,EACF,SAAS,KAAK;AAAA,EAEd;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,GAAG;AAAA,EACL;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":[]}
|
|
@@ -52,7 +52,7 @@ const getTransformationOptions = (filePath) => ({
|
|
|
52
52
|
`
|
|
53
53
|
}
|
|
54
54
|
});
|
|
55
|
-
const loadExternalFile = (filePath, envVarOptions) => {
|
|
55
|
+
const loadExternalFile = (filePath, envVarOptions, projectRequire = import_ESMxCJSRequire.ESMxCJSRequire) => {
|
|
56
56
|
let fileContent = void 0;
|
|
57
57
|
const fileExtension = filePath.split(".").pop() ?? "";
|
|
58
58
|
try {
|
|
@@ -69,7 +69,7 @@ const loadExternalFile = (filePath, envVarOptions) => {
|
|
|
69
69
|
(0, import_logger.logger)("File could not be loaded.", { level: "error" });
|
|
70
70
|
return void 0;
|
|
71
71
|
}
|
|
72
|
-
const sandboxContext = (0, import_getSandboxContext.getSandBoxContext)(envVarOptions);
|
|
72
|
+
const sandboxContext = (0, import_getSandboxContext.getSandBoxContext)(envVarOptions, projectRequire);
|
|
73
73
|
(0, import_vm.runInNewContext)(moduleResultString, sandboxContext);
|
|
74
74
|
if (sandboxContext.exports.default && Object.keys(sandboxContext.exports.default).length > 0) {
|
|
75
75
|
fileContent = sandboxContext.exports.default;
|
|
@@ -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';\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 // Remove cache to force reloading\n delete ESMxCJSRequire.cache[ESMxCJSRequire.resolve(filePath)];\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;AAAA,IACR,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,OAAO;AAAA,IACP,QAAQ;AAAA,EACV;AAAA,EACA,QAAQ;AAAA;AAAA,EACR,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,QAAQ;AAAA,IACN,IAAI;AAAA,sCAC8B,KAAK,UAAU,QAAQ,CAAC;AAAA,qCACzB,KAAK,cAAU,qBAAQ,QAAQ,CAAC,CAAC;AAAA;AAAA,EAEpE;AACF;AAOO,MAAM,mBAAmB,CAC9B,UACA,
|
|
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 projectRequire = ESMxCJSRequire\n): any | undefined => {\n let fileContent: any | undefined = undefined;\n\n const fileExtension = filePath.split('.').pop() ?? '';\n\n try {\n if (fileExtension === 'json') {\n // Remove cache to force reloading\n delete ESMxCJSRequire.cache[ESMxCJSRequire.resolve(filePath)];\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, projectRequire);\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;AAAA,IACR,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,OAAO;AAAA,IACP,QAAQ;AAAA,EACV;AAAA,EACA,QAAQ;AAAA;AAAA,EACR,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,QAAQ;AAAA,IACN,IAAI;AAAA,sCAC8B,KAAK,UAAU,QAAQ,CAAC;AAAA,qCACzB,KAAK,cAAU,qBAAQ,QAAQ,CAAC,CAAC;AAAA;AAAA,EAEpE;AACF;AAOO,MAAM,mBAAmB,CAC9B,UACA,eACA,iBAAiB,yCACG;AACpB,MAAI,cAA+B;AAEnC,QAAM,gBAAgB,SAAS,MAAM,GAAG,EAAE,IAAI,KAAK;AAEnD,MAAI;AACF,QAAI,kBAAkB,QAAQ;AAE5B,aAAO,qCAAe,MAAM,qCAAe,QAAQ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vFile.mjs";
|
|
4
4
|
import { ESMxCJSRequire } from "./utils/ESMxCJSRequire.mjs";
|
|
5
|
-
const getSandBoxContext = (envVarOptions) => {
|
|
6
|
-
let
|
|
5
|
+
const getSandBoxContext = (envVarOptions, projectRequire = ESMxCJSRequire) => {
|
|
6
|
+
let additionalGlobalVar = {};
|
|
7
7
|
try {
|
|
8
|
-
|
|
8
|
+
additionalGlobalVar = {
|
|
9
|
+
React: projectRequire("react")
|
|
10
|
+
};
|
|
9
11
|
} catch (err) {
|
|
10
|
-
ReactModule = void 0;
|
|
11
12
|
}
|
|
12
13
|
const sandboxContext = {
|
|
13
14
|
exports: {
|
|
@@ -24,9 +25,8 @@ const getSandBoxContext = (envVarOptions) => {
|
|
|
24
25
|
}
|
|
25
26
|
},
|
|
26
27
|
console,
|
|
27
|
-
require:
|
|
28
|
-
...
|
|
29
|
-
// Only inject React if found
|
|
28
|
+
require: projectRequire,
|
|
29
|
+
...additionalGlobalVar
|
|
30
30
|
};
|
|
31
31
|
Object.getOwnPropertyNames(globalThis).forEach((key) => {
|
|
32
32
|
if (!(key in sandboxContext)) {
|
|
@@ -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
|
|
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 projectRequire = ESMxCJSRequire\n): Context => {\n let additionalGlobalVar = {};\n\n try {\n // Dynamically try to require React if it's installed in the project\n additionalGlobalVar = {\n React: projectRequire('react'),\n };\n } catch (err) {\n // React is not installed, so we don't inject it\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: projectRequire,\n ...additionalGlobalVar,\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,eACA,iBAAiB,mBACL;AACZ,MAAI,sBAAsB,CAAC;AAE3B,MAAI;AAEF,0BAAsB;AAAA,MACpB,OAAO,eAAe,OAAO;AAAA,IAC/B;AAAA,EACF,SAAS,KAAK;AAAA,EAEd;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,GAAG;AAAA,EACL;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":[]}
|
|
@@ -29,7 +29,7 @@ const getTransformationOptions = (filePath) => ({
|
|
|
29
29
|
`
|
|
30
30
|
}
|
|
31
31
|
});
|
|
32
|
-
const loadExternalFile = (filePath, envVarOptions) => {
|
|
32
|
+
const loadExternalFile = (filePath, envVarOptions, projectRequire = ESMxCJSRequire) => {
|
|
33
33
|
let fileContent = void 0;
|
|
34
34
|
const fileExtension = filePath.split(".").pop() ?? "";
|
|
35
35
|
try {
|
|
@@ -46,7 +46,7 @@ const loadExternalFile = (filePath, envVarOptions) => {
|
|
|
46
46
|
logger("File could not be loaded.", { level: "error" });
|
|
47
47
|
return void 0;
|
|
48
48
|
}
|
|
49
|
-
const sandboxContext = getSandBoxContext(envVarOptions);
|
|
49
|
+
const sandboxContext = getSandBoxContext(envVarOptions, projectRequire);
|
|
50
50
|
runInNewContext(moduleResultString, sandboxContext);
|
|
51
51
|
if (sandboxContext.exports.default && Object.keys(sandboxContext.exports.default).length > 0) {
|
|
52
52
|
fileContent = sandboxContext.exports.default;
|
|
@@ -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';\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 // Remove cache to force reloading\n delete ESMxCJSRequire.cache[ESMxCJSRequire.resolve(filePath)];\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;AAClC,SAAS,sBAAsB;AAC/B,SAAS,cAAc;AAEvB,SAAS,eAAe;AAExB,MAAM,2BAA2B,CAAC,cAAoC;AAAA,EACpE,QAAQ;AAAA,IACN,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,OAAO;AAAA,IACP,QAAQ;AAAA,EACV;AAAA,EACA,QAAQ;AAAA;AAAA,EACR,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,QAAQ;AAAA,IACN,IAAI;AAAA,sCAC8B,KAAK,UAAU,QAAQ,CAAC;AAAA,qCACzB,KAAK,UAAU,QAAQ,QAAQ,CAAC,CAAC;AAAA;AAAA,EAEpE;AACF;AAOO,MAAM,mBAAmB,CAC9B,UACA,
|
|
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 projectRequire = ESMxCJSRequire\n): any | undefined => {\n let fileContent: any | undefined = undefined;\n\n const fileExtension = filePath.split('.').pop() ?? '';\n\n try {\n if (fileExtension === 'json') {\n // Remove cache to force reloading\n delete ESMxCJSRequire.cache[ESMxCJSRequire.resolve(filePath)];\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, projectRequire);\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;AAClC,SAAS,sBAAsB;AAC/B,SAAS,cAAc;AAEvB,SAAS,eAAe;AAExB,MAAM,2BAA2B,CAAC,cAAoC;AAAA,EACpE,QAAQ;AAAA,IACN,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,OAAO;AAAA,IACP,QAAQ;AAAA,EACV;AAAA,EACA,QAAQ;A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AAO,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,4 +1,4 @@
|
|
|
1
1
|
import type { Context } from 'vm';
|
|
2
2
|
import { type LoadEnvFileOptions } from './envVariables/loadEnvFile';
|
|
3
|
-
export declare const getSandBoxContext: (envVarOptions?: LoadEnvFileOptions) => Context;
|
|
3
|
+
export declare const getSandBoxContext: (envVarOptions?: LoadEnvFileOptions, projectRequire?: NodeJS.Require) => Context;
|
|
4
4
|
//# sourceMappingURL=getSandboxContext.d.ts.map
|
|
@@ -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,
|
|
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,EAClC,+BAA+B,KAC9B,OAuCF,CAAC"}
|
|
@@ -4,5 +4,5 @@ import { LoadEnvFileOptions } from './envVariables/loadEnvFile';
|
|
|
4
4
|
*
|
|
5
5
|
* Accepts JSON, JS, MJS and TS files as configuration
|
|
6
6
|
*/
|
|
7
|
-
export declare const loadExternalFile: (filePath: string, envVarOptions?: LoadEnvFileOptions) => any | undefined;
|
|
7
|
+
export declare const loadExternalFile: (filePath: string, envVarOptions?: LoadEnvFileOptions, projectRequire?: NodeJS.Require) => any | undefined;
|
|
8
8
|
//# sourceMappingURL=loadExternalFile.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,EAClC,+BAA+B,KAC9B,GAAG,GAAG,SAuER,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/config",
|
|
3
|
-
"version": "5.3.
|
|
3
|
+
"version": "5.3.6",
|
|
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": [
|
|
@@ -82,13 +82,13 @@
|
|
|
82
82
|
"tsc-alias": "^1.8.10",
|
|
83
83
|
"tsup": "^8.3.5",
|
|
84
84
|
"typescript": "^5.7.3",
|
|
85
|
-
"@utils/ts-config": "1.0.4",
|
|
86
85
|
"@utils/eslint-config": "1.0.4",
|
|
86
|
+
"@utils/ts-config": "1.0.4",
|
|
87
87
|
"@utils/ts-config-types": "1.0.4",
|
|
88
88
|
"@utils/tsup-config": "1.0.4"
|
|
89
89
|
},
|
|
90
90
|
"peerDependencies": {
|
|
91
|
-
"intlayer": "5.3.
|
|
91
|
+
"intlayer": "5.3.6"
|
|
92
92
|
},
|
|
93
93
|
"engines": {
|
|
94
94
|
"node": ">=14.18"
|