@intlayer/config 4.1.11 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/configFile/loadConfigurationFile.cjs +8 -29
- package/dist/cjs/configFile/loadConfigurationFile.cjs.map +1 -1
- package/dist/cjs/getSandboxContext.cjs +56 -0
- package/dist/cjs/getSandboxContext.cjs.map +1 -0
- package/dist/cjs/index.cjs +3 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/configFile/loadConfigurationFile.mjs +7 -20
- package/dist/esm/configFile/loadConfigurationFile.mjs.map +1 -1
- package/dist/esm/getSandboxContext.mjs +22 -0
- package/dist/esm/getSandboxContext.mjs.map +1 -0
- package/dist/esm/index.mjs +2 -0
- package/dist/esm/index.mjs.map +1 -1
- package/dist/types/configFile/loadConfigurationFile.d.ts.map +1 -1
- package/dist/types/getSandboxContext.d.ts +4 -0
- package/dist/types/getSandboxContext.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +3 -3
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
var loadConfigurationFile_exports = {};
|
|
30
20
|
__export(loadConfigurationFile_exports, {
|
|
@@ -33,25 +23,9 @@ __export(loadConfigurationFile_exports, {
|
|
|
33
23
|
module.exports = __toCommonJS(loadConfigurationFile_exports);
|
|
34
24
|
var import_vm = require("vm");
|
|
35
25
|
var import_esbuild = require("esbuild");
|
|
36
|
-
var import_react = __toESM(require("react"));
|
|
37
|
-
var import_loadEnvFile = require('../envVariables/loadEnvFile.cjs');
|
|
38
26
|
var import_logger = require('../logger.cjs');
|
|
39
27
|
var import_ESMxCJSRequire = require('../utils/ESMxCJSRequire.cjs');
|
|
40
|
-
|
|
41
|
-
const sandboxContext = {
|
|
42
|
-
exports: {
|
|
43
|
-
default: {}
|
|
44
|
-
},
|
|
45
|
-
module: {
|
|
46
|
-
exports: {}
|
|
47
|
-
},
|
|
48
|
-
React: import_react.default,
|
|
49
|
-
process: { ...process, env: (0, import_loadEnvFile.loadEnvFile)(envVarOptions) },
|
|
50
|
-
console,
|
|
51
|
-
require: import_ESMxCJSRequire.ESMxCJSRequire
|
|
52
|
-
};
|
|
53
|
-
return sandboxContext;
|
|
54
|
-
};
|
|
28
|
+
var import_getSandboxContext = require('../getSandboxContext.cjs');
|
|
55
29
|
const getTransformationOptions = () => {
|
|
56
30
|
const define = {};
|
|
57
31
|
for (const k in process.env) {
|
|
@@ -87,7 +61,7 @@ const loadConfigurationFile = (configFilePath, envVarOptions) => {
|
|
|
87
61
|
if (configFileExtension === "json") {
|
|
88
62
|
return (0, import_ESMxCJSRequire.ESMxCJSRequire)(configFilePath);
|
|
89
63
|
}
|
|
90
|
-
const sandboxContext = getSandBoxContext(envVarOptions);
|
|
64
|
+
const sandboxContext = (0, import_getSandboxContext.getSandBoxContext)(envVarOptions);
|
|
91
65
|
const moduleResult = (0, import_esbuild.buildSync)({
|
|
92
66
|
entryPoints: [configFilePath],
|
|
93
67
|
...getTransformationOptions()
|
|
@@ -113,7 +87,12 @@ const loadConfigurationFile = (configFilePath, envVarOptions) => {
|
|
|
113
87
|
}
|
|
114
88
|
return filterValidConfiguration(customConfiguration);
|
|
115
89
|
} catch (error) {
|
|
116
|
-
(0, import_logger.logger)(
|
|
90
|
+
(0, import_logger.logger)(
|
|
91
|
+
`Error: ${error} ${JSON.stringify(error.stack, null, 2)}`,
|
|
92
|
+
{
|
|
93
|
+
level: "error"
|
|
94
|
+
}
|
|
95
|
+
);
|
|
117
96
|
}
|
|
118
97
|
};
|
|
119
98
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/configFile/loadConfigurationFile.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../src/configFile/loadConfigurationFile.ts"],"sourcesContent":["import { runInNewContext } from 'vm';\nimport { type BuildOptions, buildSync, type BuildResult } from 'esbuild';\nimport { type LoadEnvFileOptions } from '../envVariables/loadEnvFile';\nimport { logger } from '../logger';\nimport type { CustomIntlayerConfig } from '../types/config';\nimport { ESMxCJSRequire } from '../utils/ESMxCJSRequire';\nimport { getSandBoxContext } from '../getSandboxContext';\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 },\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\nconst filterValidConfiguration = (\n configuration: CustomIntlayerConfig\n): CustomIntlayerConfig => {\n // @TODO Implement filtering of valid configuration\n return configuration;\n};\n\n/**\n * Load the configuration file from the given path\n * Example of configuration file: intlayer.config.js\n *\n * Accepts JSON, JS, MJS and TS files as configuration\n */\nexport const loadConfigurationFile = (\n configFilePath: string,\n envVarOptions?: LoadEnvFileOptions\n): CustomIntlayerConfig | undefined => {\n let customConfiguration: CustomIntlayerConfig | undefined = undefined;\n\n const configFileExtension = configFilePath.split('.').pop() ?? '';\n\n try {\n if (configFileExtension === 'json') {\n // Assume JSON\n\n return ESMxCJSRequire(configFilePath);\n }\n\n const sandboxContext = getSandBoxContext(envVarOptions);\n\n // Rest is JS, MJS or TS\n\n const moduleResult: BuildResult = buildSync({\n entryPoints: [configFilePath],\n ...getTransformationOptions(),\n });\n\n const moduleResultString = moduleResult.outputFiles?.[0].text;\n\n if (!moduleResultString) {\n logger('Configuration file could not be loaded.', { level: 'error' });\n return undefined;\n }\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 customConfiguration = sandboxContext.exports.default;\n } else if (\n sandboxContext.module.exports.defaults &&\n Object.keys(sandboxContext.module.exports.defaults).length > 0\n ) {\n // CommonJS\n customConfiguration = 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 customConfiguration = sandboxContext.module.exports.default;\n } else if (\n sandboxContext.module.exports &&\n Object.keys(sandboxContext.module.exports).length > 0\n ) {\n // Other\n customConfiguration = sandboxContext.module.exports;\n }\n\n if (typeof customConfiguration === 'undefined') {\n logger('Configuration file could not be loaded.');\n return undefined;\n }\n\n return filterValidConfiguration(customConfiguration);\n } catch (error) {\n logger(\n `Error: ${error} ${JSON.stringify((error as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eAAe,QAAQ,WACvB,OAAO,KAAK,eAAe,QAAQ,OAAO,EAAE,SAAS,GACrD;AAEA,4BAAsB,eAAe,QAAQ;AAAA,IAC/C,WACE,eAAe,OAAO,QAAQ,YAC9B,OAAO,KAAK,eAAe,OAAO,QAAQ,QAAQ,EAAE,SAAS,GAC7D;AAEA,4BAAsB,eAAe,OAAO,QAAQ;AAAA,IACtD,WACE,eAAe,OAAO,QAAQ,WAC9B,OAAO,KAAK,eAAe,OAAO,QAAQ,OAAO,EAAE,SAAS,GAC5D;AAEA,4BAAsB,eAAe,OAAO,QAAQ;AAAA,IACtD,WACE,eAAe,OAAO,WACtB,OAAO,KAAK,eAAe,OAAO,OAAO,EAAE,SAAS,GACpD;AAEA,4BAAsB,eAAe,OAAO;AAAA,IAC9C;AAEA,QAAI,OAAO,wBAAwB,aAAa;AAC9C,gCAAO,yCAAyC;AAChD,aAAO;AAAA,IACT;AAEA,WAAO,yBAAyB,mBAAmB;AAAA,EACrD,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":[]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var getSandboxContext_exports = {};
|
|
30
|
+
__export(getSandboxContext_exports, {
|
|
31
|
+
getSandBoxContext: () => getSandBoxContext
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(getSandboxContext_exports);
|
|
34
|
+
var import_loadEnvFile = require('./envVariables/loadEnvFile.cjs');
|
|
35
|
+
var import_ESMxCJSRequire = require('./utils/ESMxCJSRequire.cjs');
|
|
36
|
+
var import_react = __toESM(require("react"));
|
|
37
|
+
const getSandBoxContext = (envVarOptions) => {
|
|
38
|
+
const sandboxContext = {
|
|
39
|
+
exports: {
|
|
40
|
+
default: {}
|
|
41
|
+
},
|
|
42
|
+
module: {
|
|
43
|
+
exports: {}
|
|
44
|
+
},
|
|
45
|
+
React: import_react.default,
|
|
46
|
+
process: { ...process, env: (0, import_loadEnvFile.loadEnvFile)(envVarOptions) },
|
|
47
|
+
console,
|
|
48
|
+
require: import_ESMxCJSRequire.ESMxCJSRequire
|
|
49
|
+
};
|
|
50
|
+
return sandboxContext;
|
|
51
|
+
};
|
|
52
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
53
|
+
0 && (module.exports = {
|
|
54
|
+
getSandBoxContext
|
|
55
|
+
});
|
|
56
|
+
//# sourceMappingURL=getSandboxContext.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/getSandboxContext.ts"],"sourcesContent":["import { Context } from 'vm';\nimport { loadEnvFile, LoadEnvFileOptions } from './envVariables/loadEnvFile';\nimport { ESMxCJSRequire } from './utils/ESMxCJSRequire';\nimport React from 'react';\n\nexport const getSandBoxContext = (\n envVarOptions?: LoadEnvFileOptions\n): Context => {\n const sandboxContext: Context = {\n exports: {\n default: {},\n },\n module: {\n exports: {},\n },\n React,\n process: { ...process, env: loadEnvFile(envVarOptions) },\n console,\n require: ESMxCJSRequire,\n };\n\n return sandboxContext;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,yBAAgD;AAChD,4BAA+B;AAC/B,mBAAkB;AAEX,MAAM,oBAAoB,CAC/B,kBACY;AACZ,QAAM,iBAA0B;AAAA,IAC9B,SAAS;AAAA,MACP,SAAS,CAAC;AAAA,IACZ;AAAA,IACA,QAAQ;AAAA,MACN,SAAS,CAAC;AAAA,IACZ;AAAA,IACA,oBAAAA;AAAA,IACA,SAAS,EAAE,GAAG,SAAS,SAAK,gCAAY,aAAa,EAAE;AAAA,IACvD;AAAA,IACA,SAAS;AAAA,EACX;AAEA,SAAO;AACT;","names":["React"]}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -25,6 +25,7 @@ __export(index_exports, {
|
|
|
25
25
|
getClientConfiguration: () => import_envVariables.getConfiguration,
|
|
26
26
|
getConfiguration: () => import_getConfiguration.getConfiguration,
|
|
27
27
|
getPlatform: () => import_envVariables.getPlatform,
|
|
28
|
+
getSandBoxContext: () => import_getSandboxContext.getSandBoxContext,
|
|
28
29
|
loadEnvFile: () => import_envVariables.loadEnvFile,
|
|
29
30
|
logger: () => import_logger.logger
|
|
30
31
|
});
|
|
@@ -35,6 +36,7 @@ var import_envVariables = require('./envVariables/index.cjs');
|
|
|
35
36
|
var import_ESMxCJSRequire = require('./utils/ESMxCJSRequire.cjs');
|
|
36
37
|
var import_logger = require('./logger.cjs');
|
|
37
38
|
var import_appLoggerServer = require('./appLoggerServer.cjs');
|
|
39
|
+
var import_getSandboxContext = require('./getSandboxContext.cjs');
|
|
38
40
|
// Annotate the CommonJS export names for ESM import in node:
|
|
39
41
|
0 && (module.exports = {
|
|
40
42
|
ESMxCJSRequire,
|
|
@@ -44,6 +46,7 @@ var import_appLoggerServer = require('./appLoggerServer.cjs');
|
|
|
44
46
|
getClientConfiguration,
|
|
45
47
|
getConfiguration,
|
|
46
48
|
getPlatform,
|
|
49
|
+
getSandBoxContext,
|
|
47
50
|
loadEnvFile,
|
|
48
51
|
logger
|
|
49
52
|
});
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export {\n getConfiguration,\n type GetConfigurationOptions,\n} from './configFile/getConfiguration';\n\nexport type {\n InternationalizationConfig,\n ServerSetCookieRule,\n MiddlewareConfig,\n CustomIntlayerConfig,\n BaseContentConfig,\n BaseDerivedConfig,\n ResultDirDerivedConfig,\n PatternsContentConfig,\n ContentConfig,\n LogConfig,\n StrictMode,\n IntlayerConfig,\n} from './types/config';\nexport type { LocalesValues } from './types/locales';\nexport { Locales } from './types/locales';\nexport {\n formatEnvVariable,\n getConfiguration as getClientConfiguration,\n loadEnvFile,\n getPlatform,\n} from './envVariables/index';\nexport { ESMxCJSRequire } from './utils/ESMxCJSRequire';\nexport { logger } from './logger';\nexport { appLogger } from './appLoggerServer';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAGO;AAiBP,qBAAwB;AACxB,0BAKO;AACP,4BAA+B;AAC/B,oBAAuB;AACvB,6BAA0B;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export {\n getConfiguration,\n type GetConfigurationOptions,\n} from './configFile/getConfiguration';\n\nexport type {\n InternationalizationConfig,\n ServerSetCookieRule,\n MiddlewareConfig,\n CustomIntlayerConfig,\n BaseContentConfig,\n BaseDerivedConfig,\n ResultDirDerivedConfig,\n PatternsContentConfig,\n ContentConfig,\n LogConfig,\n StrictMode,\n IntlayerConfig,\n} from './types/config';\nexport type { LocalesValues } from './types/locales';\nexport { Locales } from './types/locales';\nexport {\n formatEnvVariable,\n getConfiguration as getClientConfiguration,\n loadEnvFile,\n getPlatform,\n} from './envVariables/index';\nexport { ESMxCJSRequire } from './utils/ESMxCJSRequire';\nexport { logger } from './logger';\nexport { appLogger } from './appLoggerServer';\nexport { getSandBoxContext } from './getSandboxContext';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAGO;AAiBP,qBAAwB;AACxB,0BAKO;AACP,4BAA+B;AAC/B,oBAAuB;AACvB,6BAA0B;AAC1B,+BAAkC;","names":[]}
|
|
@@ -1,26 +1,8 @@
|
|
|
1
1
|
import { runInNewContext } from "vm";
|
|
2
2
|
import { buildSync } from "esbuild";
|
|
3
|
-
import React from "react";
|
|
4
|
-
import {
|
|
5
|
-
loadEnvFile
|
|
6
|
-
} from "../envVariables/loadEnvFile.mjs";
|
|
7
3
|
import { logger } from "../logger.mjs";
|
|
8
4
|
import { ESMxCJSRequire } from "../utils/ESMxCJSRequire.mjs";
|
|
9
|
-
|
|
10
|
-
const sandboxContext = {
|
|
11
|
-
exports: {
|
|
12
|
-
default: {}
|
|
13
|
-
},
|
|
14
|
-
module: {
|
|
15
|
-
exports: {}
|
|
16
|
-
},
|
|
17
|
-
React,
|
|
18
|
-
process: { ...process, env: loadEnvFile(envVarOptions) },
|
|
19
|
-
console,
|
|
20
|
-
require: ESMxCJSRequire
|
|
21
|
-
};
|
|
22
|
-
return sandboxContext;
|
|
23
|
-
};
|
|
5
|
+
import { getSandBoxContext } from "../getSandboxContext.mjs";
|
|
24
6
|
const getTransformationOptions = () => {
|
|
25
7
|
const define = {};
|
|
26
8
|
for (const k in process.env) {
|
|
@@ -82,7 +64,12 @@ const loadConfigurationFile = (configFilePath, envVarOptions) => {
|
|
|
82
64
|
}
|
|
83
65
|
return filterValidConfiguration(customConfiguration);
|
|
84
66
|
} catch (error) {
|
|
85
|
-
logger(
|
|
67
|
+
logger(
|
|
68
|
+
`Error: ${error} ${JSON.stringify(error.stack, null, 2)}`,
|
|
69
|
+
{
|
|
70
|
+
level: "error"
|
|
71
|
+
}
|
|
72
|
+
);
|
|
86
73
|
}
|
|
87
74
|
};
|
|
88
75
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/configFile/loadConfigurationFile.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../src/configFile/loadConfigurationFile.ts"],"sourcesContent":["import { runInNewContext } from 'vm';\nimport { type BuildOptions, buildSync, type BuildResult } from 'esbuild';\nimport { type LoadEnvFileOptions } from '../envVariables/loadEnvFile';\nimport { logger } from '../logger';\nimport type { CustomIntlayerConfig } from '../types/config';\nimport { ESMxCJSRequire } from '../utils/ESMxCJSRequire';\nimport { getSandBoxContext } from '../getSandboxContext';\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 },\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\nconst filterValidConfiguration = (\n configuration: CustomIntlayerConfig\n): CustomIntlayerConfig => {\n // @TODO Implement filtering of valid configuration\n return configuration;\n};\n\n/**\n * Load the configuration file from the given path\n * Example of configuration file: intlayer.config.js\n *\n * Accepts JSON, JS, MJS and TS files as configuration\n */\nexport const loadConfigurationFile = (\n configFilePath: string,\n envVarOptions?: LoadEnvFileOptions\n): CustomIntlayerConfig | undefined => {\n let customConfiguration: CustomIntlayerConfig | undefined = undefined;\n\n const configFileExtension = configFilePath.split('.').pop() ?? '';\n\n try {\n if (configFileExtension === 'json') {\n // Assume JSON\n\n return ESMxCJSRequire(configFilePath);\n }\n\n const sandboxContext = getSandBoxContext(envVarOptions);\n\n // Rest is JS, MJS or TS\n\n const moduleResult: BuildResult = buildSync({\n entryPoints: [configFilePath],\n ...getTransformationOptions(),\n });\n\n const moduleResultString = moduleResult.outputFiles?.[0].text;\n\n if (!moduleResultString) {\n logger('Configuration file could not be loaded.', { level: 'error' });\n return undefined;\n }\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 customConfiguration = sandboxContext.exports.default;\n } else if (\n sandboxContext.module.exports.defaults &&\n Object.keys(sandboxContext.module.exports.defaults).length > 0\n ) {\n // CommonJS\n customConfiguration = 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 customConfiguration = sandboxContext.module.exports.default;\n } else if (\n sandboxContext.module.exports &&\n Object.keys(sandboxContext.module.exports).length > 0\n ) {\n // Other\n customConfiguration = sandboxContext.module.exports;\n }\n\n if (typeof customConfiguration === 'undefined') {\n logger('Configuration file could not be loaded.');\n return undefined;\n }\n\n return filterValidConfiguration(customConfiguration);\n } catch (error) {\n logger(\n `Error: ${error} ${JSON.stringify((error as Error).stack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Ae,QAAQ,OAAO,EAAE,SAAS,GACrD;AAEA,4BAAsB,eAAe,QAAQ;AAAA,IAC/C,WACE,eAAe,OAAO,QAAQ,YAC9B,OAAO,KAAK,eAAe,OAAO,QAAQ,QAAQ,EAAE,SAAS,GAC7D;AAEA,4BAAsB,eAAe,OAAO,QAAQ;AAAA,IACtD,WACE,eAAe,OAAO,QAAQ,WAC9B,OAAO,KAAK,eAAe,OAAO,QAAQ,OAAO,EAAE,SAAS,GAC5D;AAEA,4BAAsB,eAAe,OAAO,QAAQ;AAAA,IACtD,WACE,eAAe,OAAO,WACtB,OAAO,KAAK,eAAe,OAAO,OAAO,EAAE,SAAS,GACpD;AAEA,4BAAsB,eAAe,OAAO;AAAA,IAC9C;AAEA,QAAI,OAAO,wBAAwB,aAAa;AAC9C,aAAO,yCAAyC;AAChD,aAAO;AAAA,IACT;AAEA,WAAO,yBAAyB,mBAAmB;AAAA,EACrD,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":[]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { loadEnvFile } from "./envVariables/loadEnvFile.mjs";
|
|
2
|
+
import { ESMxCJSRequire } from "./utils/ESMxCJSRequire.mjs";
|
|
3
|
+
import React from "react";
|
|
4
|
+
const getSandBoxContext = (envVarOptions) => {
|
|
5
|
+
const sandboxContext = {
|
|
6
|
+
exports: {
|
|
7
|
+
default: {}
|
|
8
|
+
},
|
|
9
|
+
module: {
|
|
10
|
+
exports: {}
|
|
11
|
+
},
|
|
12
|
+
React,
|
|
13
|
+
process: { ...process, env: loadEnvFile(envVarOptions) },
|
|
14
|
+
console,
|
|
15
|
+
require: ESMxCJSRequire
|
|
16
|
+
};
|
|
17
|
+
return sandboxContext;
|
|
18
|
+
};
|
|
19
|
+
export {
|
|
20
|
+
getSandBoxContext
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=getSandboxContext.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/getSandboxContext.ts"],"sourcesContent":["import { Context } from 'vm';\nimport { loadEnvFile, LoadEnvFileOptions } from './envVariables/loadEnvFile';\nimport { ESMxCJSRequire } from './utils/ESMxCJSRequire';\nimport React from 'react';\n\nexport const getSandBoxContext = (\n envVarOptions?: LoadEnvFileOptions\n): Context => {\n const sandboxContext: Context = {\n exports: {\n default: {},\n },\n module: {\n exports: {},\n },\n React,\n process: { ...process, env: loadEnvFile(envVarOptions) },\n console,\n require: ESMxCJSRequire,\n };\n\n return sandboxContext;\n};\n"],"mappings":"AACA,SAAS,mBAAuC;AAChD,SAAS,sBAAsB;AAC/B,OAAO,WAAW;AAEX,MAAM,oBAAoB,CAC/B,kBACY;AACZ,QAAM,iBAA0B;AAAA,IAC9B,SAAS;AAAA,MACP,SAAS,CAAC;AAAA,IACZ;AAAA,IACA,QAAQ;AAAA,MACN,SAAS,CAAC;AAAA,IACZ;AAAA,IACA;AAAA,IACA,SAAS,EAAE,GAAG,SAAS,KAAK,YAAY,aAAa,EAAE;AAAA,IACvD;AAAA,IACA,SAAS;AAAA,EACX;AAEA,SAAO;AACT;","names":[]}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
import { ESMxCJSRequire } from "./utils/ESMxCJSRequire.mjs";
|
|
12
12
|
import { logger } from "./logger.mjs";
|
|
13
13
|
import { appLogger } from "./appLoggerServer.mjs";
|
|
14
|
+
import { getSandBoxContext } from "./getSandboxContext.mjs";
|
|
14
15
|
export {
|
|
15
16
|
ESMxCJSRequire,
|
|
16
17
|
Locales,
|
|
@@ -19,6 +20,7 @@ export {
|
|
|
19
20
|
getConfiguration2 as getClientConfiguration,
|
|
20
21
|
getConfiguration,
|
|
21
22
|
getPlatform,
|
|
23
|
+
getSandBoxContext,
|
|
22
24
|
loadEnvFile,
|
|
23
25
|
logger
|
|
24
26
|
};
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export {\n getConfiguration,\n type GetConfigurationOptions,\n} from './configFile/getConfiguration';\n\nexport type {\n InternationalizationConfig,\n ServerSetCookieRule,\n MiddlewareConfig,\n CustomIntlayerConfig,\n BaseContentConfig,\n BaseDerivedConfig,\n ResultDirDerivedConfig,\n PatternsContentConfig,\n ContentConfig,\n LogConfig,\n StrictMode,\n IntlayerConfig,\n} from './types/config';\nexport type { LocalesValues } from './types/locales';\nexport { Locales } from './types/locales';\nexport {\n formatEnvVariable,\n getConfiguration as getClientConfiguration,\n loadEnvFile,\n getPlatform,\n} from './envVariables/index';\nexport { ESMxCJSRequire } from './utils/ESMxCJSRequire';\nexport { logger } from './logger';\nexport { appLogger } from './appLoggerServer';\n"],"mappings":"AAAA;AAAA,EACE;AAAA,OAEK;AAiBP,SAAS,eAAe;AACxB;AAAA,EACE;AAAA,EACoB,oBAApBA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;AAC/B,SAAS,cAAc;AACvB,SAAS,iBAAiB;","names":["getConfiguration"]}
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export {\n getConfiguration,\n type GetConfigurationOptions,\n} from './configFile/getConfiguration';\n\nexport type {\n InternationalizationConfig,\n ServerSetCookieRule,\n MiddlewareConfig,\n CustomIntlayerConfig,\n BaseContentConfig,\n BaseDerivedConfig,\n ResultDirDerivedConfig,\n PatternsContentConfig,\n ContentConfig,\n LogConfig,\n StrictMode,\n IntlayerConfig,\n} from './types/config';\nexport type { LocalesValues } from './types/locales';\nexport { Locales } from './types/locales';\nexport {\n formatEnvVariable,\n getConfiguration as getClientConfiguration,\n loadEnvFile,\n getPlatform,\n} from './envVariables/index';\nexport { ESMxCJSRequire } from './utils/ESMxCJSRequire';\nexport { logger } from './logger';\nexport { appLogger } from './appLoggerServer';\nexport { getSandBoxContext } from './getSandboxContext';\n"],"mappings":"AAAA;AAAA,EACE;AAAA,OAEK;AAiBP,SAAS,eAAe;AACxB;AAAA,EACE;AAAA,EACoB,oBAApBA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;AAC/B,SAAS,cAAc;AACvB,SAAS,iBAAiB;AAC1B,SAAS,yBAAyB;","names":["getConfiguration"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadConfigurationFile.d.ts","sourceRoot":"","sources":["../../../src/configFile/loadConfigurationFile.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"loadConfigurationFile.d.ts","sourceRoot":"","sources":["../../../src/configFile/loadConfigurationFile.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAEtE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAuC5D;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,mBAChB,MAAM,kBACN,kBAAkB,KACjC,oBAAoB,GAAG,SAsEzB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getSandboxContext.d.ts","sourceRoot":"","sources":["../../src/getSandboxContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAC7B,OAAO,EAAe,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAI7E,eAAO,MAAM,iBAAiB,mBACZ,kBAAkB,KACjC,OAeF,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -6,4 +6,5 @@ export { formatEnvVariable, getConfiguration as getClientConfiguration, loadEnvF
|
|
|
6
6
|
export { ESMxCJSRequire } from './utils/ESMxCJSRequire';
|
|
7
7
|
export { logger } from './logger';
|
|
8
8
|
export { appLogger } from './appLoggerServer';
|
|
9
|
+
export { getSandBoxContext } from './getSandboxContext';
|
|
9
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,KAAK,uBAAuB,GAC7B,MAAM,+BAA+B,CAAC;AAEvC,YAAY,EACV,0BAA0B,EAC1B,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,sBAAsB,EACtB,qBAAqB,EACrB,aAAa,EACb,SAAS,EACT,UAAU,EACV,cAAc,GACf,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EACL,iBAAiB,EACjB,gBAAgB,IAAI,sBAAsB,EAC1C,WAAW,EACX,WAAW,GACZ,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,KAAK,uBAAuB,GAC7B,MAAM,+BAA+B,CAAC;AAEvC,YAAY,EACV,0BAA0B,EAC1B,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,sBAAsB,EACtB,qBAAqB,EACrB,aAAa,EACb,SAAS,EACT,UAAU,EACV,cAAc,GACf,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EACL,iBAAiB,EACjB,gBAAgB,IAAI,sBAAsB,EAC1C,WAAW,EACX,WAAW,GACZ,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/config",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
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": [
|
|
@@ -78,13 +78,13 @@
|
|
|
78
78
|
"tsup": "^8.3.5",
|
|
79
79
|
"typescript": "^5.7.3",
|
|
80
80
|
"@utils/eslint-config": "1.0.4",
|
|
81
|
-
"@utils/ts-config-types": "1.0.4",
|
|
82
81
|
"@utils/ts-config": "1.0.4",
|
|
82
|
+
"@utils/ts-config-types": "1.0.4",
|
|
83
83
|
"@utils/tsup-config": "1.0.4"
|
|
84
84
|
},
|
|
85
85
|
"peerDependencies": {
|
|
86
86
|
"react": ">=16.0.0",
|
|
87
|
-
"intlayer": "
|
|
87
|
+
"intlayer": "5.0.0"
|
|
88
88
|
},
|
|
89
89
|
"engines": {
|
|
90
90
|
"node": ">=14.18"
|