@intlayer/config 9.6.0 → 9.7.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.
@@ -0,0 +1,62 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ //#region src/configFile/editorServerOverride.ts
3
+ /**
4
+ * Port of the `intlayer-editor` server, set by `intlayer-editor start --with`
5
+ * on the application it starts. Turns the editor on for that application and
6
+ * points `editor.editorURL` at the server, without touching the configuration
7
+ * file.
8
+ */
9
+ const EDITOR_SERVER_PORT_ENV_VAR = "INTLAYER_EDITOR_SERVER_PORT";
10
+ /** Hostnames `editor.editorURL` may name the local editor server with. */
11
+ const LOCAL_HOSTNAMES = /* @__PURE__ */ new Set([
12
+ "localhost",
13
+ "127.0.0.1",
14
+ "0.0.0.0",
15
+ "[::1]"
16
+ ]);
17
+ /**
18
+ * `editor.editorURL` adapted to the port the local editor server listens on,
19
+ * which differs from `editor.port` when that one is taken.
20
+ *
21
+ * @returns The adapted URL, or `undefined` when the URL already targets that
22
+ * port or names another host (e.g. a proxy) that cannot be adapted.
23
+ */
24
+ const getEditorURLForPort = (editorURL, port) => {
25
+ const localEditorURL = `http://localhost:${port}`;
26
+ if (!editorURL) return localEditorURL;
27
+ let parsedEditorURL;
28
+ try {
29
+ parsedEditorURL = new URL(editorURL);
30
+ } catch {
31
+ return localEditorURL;
32
+ }
33
+ if (!LOCAL_HOSTNAMES.has(parsedEditorURL.hostname)) return void 0;
34
+ if ((parsedEditorURL.port || (parsedEditorURL.protocol === "https:" ? "443" : "80")) === String(port)) return void 0;
35
+ parsedEditorURL.port = String(port);
36
+ return editorURL.endsWith("/") ? parsedEditorURL.href : parsedEditorURL.href.replace(/\/$/, "");
37
+ };
38
+ /**
39
+ * Applies {@link EDITOR_SERVER_PORT_ENV_VAR}: enables the editor and adapts
40
+ * its URL and port to the running editor server.
41
+ *
42
+ * @returns The configuration unchanged when the variable is not set.
43
+ */
44
+ const applyEditorServerOverride = (configuration, environment = process.env) => {
45
+ const editorServerPort = Number(environment[EDITOR_SERVER_PORT_ENV_VAR]);
46
+ if (!Number.isInteger(editorServerPort) || editorServerPort <= 0) return configuration;
47
+ return {
48
+ ...configuration,
49
+ editor: {
50
+ ...configuration.editor,
51
+ enabled: true,
52
+ port: editorServerPort,
53
+ editorURL: getEditorURLForPort(configuration.editor.editorURL, editorServerPort) ?? configuration.editor.editorURL
54
+ }
55
+ };
56
+ };
57
+
58
+ //#endregion
59
+ exports.EDITOR_SERVER_PORT_ENV_VAR = EDITOR_SERVER_PORT_ENV_VAR;
60
+ exports.applyEditorServerOverride = applyEditorServerOverride;
61
+ exports.getEditorURLForPort = getEditorURLForPort;
62
+ //# sourceMappingURL=editorServerOverride.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"editorServerOverride.cjs","names":[],"sources":["../../../src/configFile/editorServerOverride.ts"],"sourcesContent":["import type { IntlayerConfig } from '@intlayer/types/config';\n\n/**\n * Port of the `intlayer-editor` server, set by `intlayer-editor start --with`\n * on the application it starts. Turns the editor on for that application and\n * points `editor.editorURL` at the server, without touching the configuration\n * file.\n */\nexport const EDITOR_SERVER_PORT_ENV_VAR = 'INTLAYER_EDITOR_SERVER_PORT';\n\n/** Hostnames `editor.editorURL` may name the local editor server with. */\nconst LOCAL_HOSTNAMES = new Set(['localhost', '127.0.0.1', '0.0.0.0', '[::1]']);\n\n/**\n * `editor.editorURL` adapted to the port the local editor server listens on,\n * which differs from `editor.port` when that one is taken.\n *\n * @returns The adapted URL, or `undefined` when the URL already targets that\n * port or names another host (e.g. a proxy) that cannot be adapted.\n */\nexport const getEditorURLForPort = (\n editorURL: string | undefined,\n port: number\n): string | undefined => {\n const localEditorURL = `http://localhost:${port}`;\n\n if (!editorURL) return localEditorURL;\n\n let parsedEditorURL: URL;\n\n try {\n parsedEditorURL = new URL(editorURL);\n } catch {\n return localEditorURL;\n }\n\n if (!LOCAL_HOSTNAMES.has(parsedEditorURL.hostname)) return undefined;\n\n const editorPort =\n parsedEditorURL.port ||\n (parsedEditorURL.protocol === 'https:' ? '443' : '80');\n\n if (editorPort === String(port)) return undefined;\n\n parsedEditorURL.port = String(port);\n\n // `URL` adds a trailing slash to a bare origin\n return editorURL.endsWith('/')\n ? parsedEditorURL.href\n : parsedEditorURL.href.replace(/\\/$/, '');\n};\n\n/**\n * Applies {@link EDITOR_SERVER_PORT_ENV_VAR}: enables the editor and adapts\n * its URL and port to the running editor server.\n *\n * @returns The configuration unchanged when the variable is not set.\n */\nexport const applyEditorServerOverride = (\n configuration: IntlayerConfig,\n environment: NodeJS.ProcessEnv = process.env\n): IntlayerConfig => {\n const editorServerPort = Number(environment[EDITOR_SERVER_PORT_ENV_VAR]);\n\n if (!Number.isInteger(editorServerPort) || editorServerPort <= 0) {\n return configuration;\n }\n\n return {\n ...configuration,\n editor: {\n ...configuration.editor,\n enabled: true,\n port: editorServerPort,\n editorURL:\n getEditorURLForPort(configuration.editor.editorURL, editorServerPort) ??\n configuration.editor.editorURL,\n },\n };\n};\n"],"mappings":";;;;;;;;AAQA,MAAa,6BAA6B;;AAG1C,MAAM,kCAAkB,IAAI,IAAI;CAAC;CAAa;CAAa;CAAW;AAAO,CAAC;;;;;;;;AAS9E,MAAa,uBACX,WACA,SACuB;CACvB,MAAM,iBAAiB,oBAAoB;CAE3C,IAAI,CAAC,WAAW,OAAO;CAEvB,IAAI;CAEJ,IAAI;EACF,kBAAkB,IAAI,IAAI,SAAS;CACrC,QAAQ;EACN,OAAO;CACT;CAEA,IAAI,CAAC,gBAAgB,IAAI,gBAAgB,QAAQ,GAAG,OAAO;CAM3D,KAHE,gBAAgB,SACf,gBAAgB,aAAa,WAAW,QAAQ,WAEhC,OAAO,IAAI,GAAG,OAAO;CAExC,gBAAgB,OAAO,OAAO,IAAI;CAGlC,OAAO,UAAU,SAAS,GAAG,IACzB,gBAAgB,OAChB,gBAAgB,KAAK,QAAQ,OAAO,EAAE;AAC5C;;;;;;;AAQA,MAAa,6BACX,eACA,cAAiC,QAAQ,QACtB;CACnB,MAAM,mBAAmB,OAAO,YAAY,2BAA2B;CAEvE,IAAI,CAAC,OAAO,UAAU,gBAAgB,KAAK,oBAAoB,GAC7D,OAAO;CAGT,OAAO;EACL,GAAG;EACH,QAAQ;GACN,GAAG,cAAc;GACjB,SAAS;GACT,MAAM;GACN,WACE,oBAAoB,cAAc,OAAO,WAAW,gBAAgB,KACpE,cAAc,OAAO;EACzB;CACF;AACF"}
@@ -2,12 +2,24 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_utils_cacheMemory = require('../utils/cacheMemory.cjs');
3
3
  const require_utils_getPackageJsonPath = require('../utils/getPackageJsonPath.cjs');
4
4
  const require_configFile_buildConfigurationFields = require('./buildConfigurationFields.cjs');
5
+ const require_configFile_editorServerOverride = require('./editorServerOverride.cjs');
5
6
  const require_configFile_loadConfigurationFile = require('./loadConfigurationFile.cjs');
6
7
  const require_configFile_searchConfigurationFile = require('./searchConfigurationFile.cjs');
7
8
  let defu = require("defu");
8
9
 
9
10
  //#region src/configFile/getConfiguration.ts
10
11
  /**
12
+ * Applies the editor server override outside the cache: the editor server
13
+ * sets it once listening, after its configuration was first read.
14
+ */
15
+ const withEditorServerOverride = (result) => {
16
+ const configuration = require_configFile_editorServerOverride.applyEditorServerOverride(result.configuration);
17
+ return configuration === result.configuration ? result : {
18
+ ...result,
19
+ configuration
20
+ };
21
+ };
22
+ /**
11
23
  * Get the configuration for the intlayer by reading the configuration file (e.g. intlayer.config.js)
12
24
  */
13
25
  const getConfigurationAndFilePath = (options) => {
@@ -23,7 +35,7 @@ const getConfigurationAndFilePath = (options) => {
23
35
  };
24
36
  }
25
37
  const cachedConfiguration = require_utils_cacheMemory.cacheMemory.get(options);
26
- if (cachedConfiguration) return cachedConfiguration;
38
+ if (cachedConfiguration) return withEditorServerOverride(cachedConfiguration);
27
39
  const { configurationFilePath, numCustomConfiguration } = require_configFile_searchConfigurationFile.searchConfigurationFile(baseDir);
28
40
  let storedConfiguration;
29
41
  let customConfiguration;
@@ -52,12 +64,12 @@ const getConfigurationAndFilePath = (options) => {
52
64
  numCustomConfiguration,
53
65
  configurationFilePath
54
66
  });
55
- return {
67
+ return withEditorServerOverride({
56
68
  configuration,
57
69
  customConfiguration,
58
70
  numCustomConfiguration,
59
71
  configurationFilePath
60
- };
72
+ });
61
73
  };
62
74
  /**
63
75
  * Get the configuration for the intlayer by reading the configuration file (e.g. intlayer.config.js)
@@ -1 +1 @@
1
- {"version":3,"file":"getConfiguration.cjs","names":["getPackageJsonPath","buildConfigurationFields","cacheMemory","searchConfigurationFile","loadConfigurationFile"],"sources":["../../../src/configFile/getConfiguration.ts"],"sourcesContent":["import type {\n CustomIntlayerConfig,\n IntlayerConfig,\n LogFunctions,\n} from '@intlayer/types/config';\nimport { defu } from 'defu';\nimport type { LoadExternalFileOptions } from '../loadExternalFile/loadExternalFile';\nimport type { SandBoxContextOptions } from '../loadExternalFile/parseFileContent';\nimport { cacheMemory } from '../utils/cacheMemory';\nimport { getPackageJsonPath } from '../utils/getPackageJsonPath';\nimport { buildConfigurationFields } from './buildConfigurationFields';\nimport { loadConfigurationFile } from './loadConfigurationFile';\nimport { searchConfigurationFile } from './searchConfigurationFile';\n\nexport type GetConfigurationOptions = {\n baseDir?: string;\n override?: CustomIntlayerConfig;\n // Dotenv options\n env?: string;\n envFile?: string;\n // Log functions\n logFunctions?: LogFunctions;\n // Require function\n require?: NodeJS.Require;\n // cache\n cache?: boolean;\n // Build options for TypeScript transpilation (e.g. custom esbuild instance)\n buildOptions?: LoadExternalFileOptions['buildOptions'];\n} & Omit<SandBoxContextOptions, 'projectRequire'>;\n\nexport type GetConfigurationAndFilePathResult = {\n configuration: IntlayerConfig;\n customConfiguration: CustomIntlayerConfig | undefined;\n numCustomConfiguration: number;\n configurationFilePath: string | undefined;\n};\n\n/**\n * Get the configuration for the intlayer by reading the configuration file (e.g. intlayer.config.js)\n */\nexport const getConfigurationAndFilePath = (\n options?: GetConfigurationOptions\n): GetConfigurationAndFilePathResult => {\n let baseDir: string | undefined;\n\n try {\n // Can fail in some environments (e.g. MCP server, VScode extension)\n baseDir = options?.baseDir ?? getPackageJsonPath().baseDir;\n } catch (_err) {\n // Return default config if the package.json is not found\n return {\n configuration: buildConfigurationFields(\n {},\n options?.baseDir,\n options?.logFunctions\n ),\n customConfiguration: undefined,\n numCustomConfiguration: 0,\n configurationFilePath: undefined,\n };\n }\n\n const cachedConfiguration =\n cacheMemory.get<GetConfigurationAndFilePathResult>(options);\n\n if (cachedConfiguration) return cachedConfiguration;\n\n // Search for configuration files\n const { configurationFilePath, numCustomConfiguration } =\n searchConfigurationFile(baseDir);\n\n let storedConfiguration: IntlayerConfig;\n let customConfiguration: CustomIntlayerConfig | undefined;\n\n if (configurationFilePath) {\n // Load the custom configuration\n customConfiguration = loadConfigurationFile(configurationFilePath, {\n projectRequire: options?.require,\n // Dotenv options\n envVarOptions: {\n env: options?.env,\n envFile: options?.envFile,\n },\n // Sandbox context additional variables\n additionalEnvVars: options?.additionalEnvVars,\n aliases: options?.aliases,\n // Build options for TypeScript transpilation (e.g. custom esbuild instance)\n buildOptions: options?.buildOptions,\n });\n\n // Save the configuration to avoid reading the file again\n storedConfiguration = buildConfigurationFields(\n customConfiguration,\n options?.baseDir,\n options?.logFunctions\n );\n } else {\n // No configuration file found, use default configuration\n storedConfiguration = buildConfigurationFields(\n {},\n options?.baseDir,\n options?.logFunctions\n );\n }\n\n // Log warning if multiple configuration files are found\n const projectRequireConfig: CustomIntlayerConfig = options?.require\n ? {\n build: {\n require: options?.require,\n cache: options?.cache,\n },\n }\n : {};\n\n const configWithProjectRequire = defu(\n projectRequireConfig,\n storedConfiguration\n ) as IntlayerConfig;\n\n const configuration = defu(\n options?.override ?? {},\n configWithProjectRequire\n ) as IntlayerConfig;\n\n cacheMemory.set(options, {\n configuration,\n customConfiguration,\n numCustomConfiguration,\n configurationFilePath,\n });\n\n return {\n configuration,\n customConfiguration,\n numCustomConfiguration,\n configurationFilePath,\n };\n};\n\n/**\n * Get the configuration for the intlayer by reading the configuration file (e.g. intlayer.config.js)\n */\nexport const getConfiguration = (\n options?: GetConfigurationOptions\n): IntlayerConfig => getConfigurationAndFilePath(options).configuration;\n"],"mappings":";;;;;;;;;;;;AAwCA,MAAa,+BACX,YACsC;CACtC,IAAI;CAEJ,IAAI;EAEF,UAAU,SAAS,WAAWA,oDAAmB,CAAC,CAAC;CACrD,SAAS,MAAM;EAEb,OAAO;GACL,eAAeC,qEACb,CAAC,GACD,SAAS,SACT,SAAS,YACX;GACA,qBAAqB;GACrB,wBAAwB;GACxB,uBAAuB;EACzB;CACF;CAEA,MAAM,sBACJC,sCAAY,IAAuC,OAAO;CAE5D,IAAI,qBAAqB,OAAO;CAGhC,MAAM,EAAE,uBAAuB,2BAC7BC,mEAAwB,OAAO;CAEjC,IAAI;CACJ,IAAI;CAEJ,IAAI,uBAAuB;EAEzB,sBAAsBC,+DAAsB,uBAAuB;GACjE,gBAAgB,SAAS;GAEzB,eAAe;IACb,KAAK,SAAS;IACd,SAAS,SAAS;GACpB;GAEA,mBAAmB,SAAS;GAC5B,SAAS,SAAS;GAElB,cAAc,SAAS;EACzB,CAAC;EAGD,sBAAsBH,qEACpB,qBACA,SAAS,SACT,SAAS,YACX;CACF,OAEE,sBAAsBA,qEACpB,CAAC,GACD,SAAS,SACT,SAAS,YACX;CAIF,MAAM,uBAA6C,SAAS,UACxD,EACE,OAAO;EACL,SAAS,SAAS;EAClB,OAAO,SAAS;CAClB,EACF,IACA,CAAC;CAEL,MAAM,+BAA2B,WAC/B,sBACA,mBACF;CAEA,MAAM,oBAAgB,WACpB,SAAS,YAAY,CAAC,GACtB,wBACF;CAEA,sCAAY,IAAI,SAAS;EACvB;EACA;EACA;EACA;CACF,CAAC;CAED,OAAO;EACL;EACA;EACA;EACA;CACF;AACF;;;;AAKA,MAAa,oBACX,YACmB,4BAA4B,OAAO,CAAC,CAAC"}
1
+ {"version":3,"file":"getConfiguration.cjs","names":["applyEditorServerOverride","getPackageJsonPath","buildConfigurationFields","cacheMemory","searchConfigurationFile","loadConfigurationFile"],"sources":["../../../src/configFile/getConfiguration.ts"],"sourcesContent":["import type {\n CustomIntlayerConfig,\n IntlayerConfig,\n LogFunctions,\n} from '@intlayer/types/config';\nimport { defu } from 'defu';\nimport type { LoadExternalFileOptions } from '../loadExternalFile/loadExternalFile';\nimport type { SandBoxContextOptions } from '../loadExternalFile/parseFileContent';\nimport { cacheMemory } from '../utils/cacheMemory';\nimport { getPackageJsonPath } from '../utils/getPackageJsonPath';\nimport { buildConfigurationFields } from './buildConfigurationFields';\nimport { applyEditorServerOverride } from './editorServerOverride';\nimport { loadConfigurationFile } from './loadConfigurationFile';\nimport { searchConfigurationFile } from './searchConfigurationFile';\n\nexport type GetConfigurationOptions = {\n baseDir?: string;\n override?: CustomIntlayerConfig;\n // Dotenv options\n env?: string;\n envFile?: string;\n // Log functions\n logFunctions?: LogFunctions;\n // Require function\n require?: NodeJS.Require;\n // cache\n cache?: boolean;\n // Build options for TypeScript transpilation (e.g. custom esbuild instance)\n buildOptions?: LoadExternalFileOptions['buildOptions'];\n} & Omit<SandBoxContextOptions, 'projectRequire'>;\n\nexport type GetConfigurationAndFilePathResult = {\n configuration: IntlayerConfig;\n customConfiguration: CustomIntlayerConfig | undefined;\n numCustomConfiguration: number;\n configurationFilePath: string | undefined;\n};\n\n/**\n * Applies the editor server override outside the cache: the editor server\n * sets it once listening, after its configuration was first read.\n */\nconst withEditorServerOverride = (\n result: GetConfigurationAndFilePathResult\n): GetConfigurationAndFilePathResult => {\n const configuration = applyEditorServerOverride(result.configuration);\n\n return configuration === result.configuration\n ? result\n : { ...result, configuration };\n};\n\n/**\n * Get the configuration for the intlayer by reading the configuration file (e.g. intlayer.config.js)\n */\nexport const getConfigurationAndFilePath = (\n options?: GetConfigurationOptions\n): GetConfigurationAndFilePathResult => {\n let baseDir: string | undefined;\n\n try {\n // Can fail in some environments (e.g. MCP server, VScode extension)\n baseDir = options?.baseDir ?? getPackageJsonPath().baseDir;\n } catch (_err) {\n // Return default config if the package.json is not found\n return {\n configuration: buildConfigurationFields(\n {},\n options?.baseDir,\n options?.logFunctions\n ),\n customConfiguration: undefined,\n numCustomConfiguration: 0,\n configurationFilePath: undefined,\n };\n }\n\n const cachedConfiguration =\n cacheMemory.get<GetConfigurationAndFilePathResult>(options);\n\n if (cachedConfiguration) return withEditorServerOverride(cachedConfiguration);\n\n // Search for configuration files\n const { configurationFilePath, numCustomConfiguration } =\n searchConfigurationFile(baseDir);\n\n let storedConfiguration: IntlayerConfig;\n let customConfiguration: CustomIntlayerConfig | undefined;\n\n if (configurationFilePath) {\n // Load the custom configuration\n customConfiguration = loadConfigurationFile(configurationFilePath, {\n projectRequire: options?.require,\n // Dotenv options\n envVarOptions: {\n env: options?.env,\n envFile: options?.envFile,\n },\n // Sandbox context additional variables\n additionalEnvVars: options?.additionalEnvVars,\n aliases: options?.aliases,\n // Build options for TypeScript transpilation (e.g. custom esbuild instance)\n buildOptions: options?.buildOptions,\n });\n\n // Save the configuration to avoid reading the file again\n storedConfiguration = buildConfigurationFields(\n customConfiguration,\n options?.baseDir,\n options?.logFunctions\n );\n } else {\n // No configuration file found, use default configuration\n storedConfiguration = buildConfigurationFields(\n {},\n options?.baseDir,\n options?.logFunctions\n );\n }\n\n // Log warning if multiple configuration files are found\n const projectRequireConfig: CustomIntlayerConfig = options?.require\n ? {\n build: {\n require: options?.require,\n cache: options?.cache,\n },\n }\n : {};\n\n const configWithProjectRequire = defu(\n projectRequireConfig,\n storedConfiguration\n ) as IntlayerConfig;\n\n const configuration = defu(\n options?.override ?? {},\n configWithProjectRequire\n ) as IntlayerConfig;\n\n cacheMemory.set(options, {\n configuration,\n customConfiguration,\n numCustomConfiguration,\n configurationFilePath,\n });\n\n return withEditorServerOverride({\n configuration,\n customConfiguration,\n numCustomConfiguration,\n configurationFilePath,\n });\n};\n\n/**\n * Get the configuration for the intlayer by reading the configuration file (e.g. intlayer.config.js)\n */\nexport const getConfiguration = (\n options?: GetConfigurationOptions\n): IntlayerConfig => getConfigurationAndFilePath(options).configuration;\n"],"mappings":";;;;;;;;;;;;;;AA0CA,MAAM,4BACJ,WACsC;CACtC,MAAM,gBAAgBA,kEAA0B,OAAO,aAAa;CAEpE,OAAO,kBAAkB,OAAO,gBAC5B,SACA;EAAE,GAAG;EAAQ;CAAc;AACjC;;;;AAKA,MAAa,+BACX,YACsC;CACtC,IAAI;CAEJ,IAAI;EAEF,UAAU,SAAS,WAAWC,oDAAmB,CAAC,CAAC;CACrD,SAAS,MAAM;EAEb,OAAO;GACL,eAAeC,qEACb,CAAC,GACD,SAAS,SACT,SAAS,YACX;GACA,qBAAqB;GACrB,wBAAwB;GACxB,uBAAuB;EACzB;CACF;CAEA,MAAM,sBACJC,sCAAY,IAAuC,OAAO;CAE5D,IAAI,qBAAqB,OAAO,yBAAyB,mBAAmB;CAG5E,MAAM,EAAE,uBAAuB,2BAC7BC,mEAAwB,OAAO;CAEjC,IAAI;CACJ,IAAI;CAEJ,IAAI,uBAAuB;EAEzB,sBAAsBC,+DAAsB,uBAAuB;GACjE,gBAAgB,SAAS;GAEzB,eAAe;IACb,KAAK,SAAS;IACd,SAAS,SAAS;GACpB;GAEA,mBAAmB,SAAS;GAC5B,SAAS,SAAS;GAElB,cAAc,SAAS;EACzB,CAAC;EAGD,sBAAsBH,qEACpB,qBACA,SAAS,SACT,SAAS,YACX;CACF,OAEE,sBAAsBA,qEACpB,CAAC,GACD,SAAS,SACT,SAAS,YACX;CAIF,MAAM,uBAA6C,SAAS,UACxD,EACE,OAAO;EACL,SAAS,SAAS;EAClB,OAAO,SAAS;CAClB,EACF,IACA,CAAC;CAEL,MAAM,+BAA2B,WAC/B,sBACA,mBACF;CAEA,MAAM,oBAAgB,WACpB,SAAS,YAAY,CAAC,GACtB,wBACF;CAEA,sCAAY,IAAI,SAAS;EACvB;EACA;EACA;EACA;CACF,CAAC;CAED,OAAO,yBAAyB;EAC9B;EACA;EACA;EACA;CACF,CAAC;AACH;;;;AAKA,MAAa,oBACX,YACmB,4BAA4B,OAAO,CAAC,CAAC"}
@@ -2,11 +2,14 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_configFile_buildBrowserConfiguration = require('./buildBrowserConfiguration.cjs');
3
3
  const require_configFile_configurationSchema = require('./configurationSchema.cjs');
4
4
  const require_configFile_buildConfigurationFields = require('./buildConfigurationFields.cjs');
5
+ const require_configFile_editorServerOverride = require('./editorServerOverride.cjs');
5
6
  const require_configFile_searchConfigurationFile = require('./searchConfigurationFile.cjs');
6
7
  const require_configFile_getConfiguration = require('./getConfiguration.cjs');
7
8
 
9
+ exports.EDITOR_SERVER_PORT_ENV_VAR = require_configFile_editorServerOverride.EDITOR_SERVER_PORT_ENV_VAR;
8
10
  exports.aiSchema = require_configFile_configurationSchema.aiSchema;
9
11
  exports.analyticsSchema = require_configFile_configurationSchema.analyticsSchema;
12
+ exports.applyEditorServerOverride = require_configFile_editorServerOverride.applyEditorServerOverride;
10
13
  exports.buildAnalyticsFields = require_configFile_buildBrowserConfiguration.buildAnalyticsFields;
11
14
  exports.buildBrowserConfiguration = require_configFile_buildBrowserConfiguration.buildBrowserConfiguration;
12
15
  exports.buildConfigurationFields = require_configFile_buildConfigurationFields.buildConfigurationFields;
@@ -24,6 +27,7 @@ exports.editorSchema = require_configFile_configurationSchema.editorSchema;
24
27
  exports.extractBrowserConfiguration = require_configFile_buildBrowserConfiguration.extractBrowserConfiguration;
25
28
  exports.getConfiguration = require_configFile_getConfiguration.getConfiguration;
26
29
  exports.getConfigurationAndFilePath = require_configFile_getConfiguration.getConfigurationAndFilePath;
30
+ exports.getEditorURLForPort = require_configFile_editorServerOverride.getEditorURLForPort;
27
31
  exports.internationalizationSchema = require_configFile_configurationSchema.internationalizationSchema;
28
32
  exports.intlayerConfigSchema = require_configFile_configurationSchema.intlayerConfigSchema;
29
33
  exports.intlayerConfigSchemaParseContext = require_configFile_configurationSchema.intlayerConfigSchemaParseContext;
package/dist/cjs/node.cjs CHANGED
@@ -2,11 +2,14 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_configFile_buildBrowserConfiguration = require('./configFile/buildBrowserConfiguration.cjs');
3
3
  const require_configFile_configurationSchema = require('./configFile/configurationSchema.cjs');
4
4
  const require_configFile_buildConfigurationFields = require('./configFile/buildConfigurationFields.cjs');
5
+ const require_configFile_editorServerOverride = require('./configFile/editorServerOverride.cjs');
5
6
  const require_configFile_searchConfigurationFile = require('./configFile/searchConfigurationFile.cjs');
6
7
  const require_configFile_getConfiguration = require('./configFile/getConfiguration.cjs');
7
8
 
9
+ exports.EDITOR_SERVER_PORT_ENV_VAR = require_configFile_editorServerOverride.EDITOR_SERVER_PORT_ENV_VAR;
8
10
  exports.aiSchema = require_configFile_configurationSchema.aiSchema;
9
11
  exports.analyticsSchema = require_configFile_configurationSchema.analyticsSchema;
12
+ exports.applyEditorServerOverride = require_configFile_editorServerOverride.applyEditorServerOverride;
10
13
  exports.buildAnalyticsFields = require_configFile_buildBrowserConfiguration.buildAnalyticsFields;
11
14
  exports.buildBrowserConfiguration = require_configFile_buildBrowserConfiguration.buildBrowserConfiguration;
12
15
  exports.buildConfigurationFields = require_configFile_buildConfigurationFields.buildConfigurationFields;
@@ -24,6 +27,7 @@ exports.editorSchema = require_configFile_configurationSchema.editorSchema;
24
27
  exports.extractBrowserConfiguration = require_configFile_buildBrowserConfiguration.extractBrowserConfiguration;
25
28
  exports.getConfiguration = require_configFile_getConfiguration.getConfiguration;
26
29
  exports.getConfigurationAndFilePath = require_configFile_getConfiguration.getConfigurationAndFilePath;
30
+ exports.getEditorURLForPort = require_configFile_editorServerOverride.getEditorURLForPort;
27
31
  exports.internationalizationSchema = require_configFile_configurationSchema.internationalizationSchema;
28
32
  exports.intlayerConfigSchema = require_configFile_configurationSchema.intlayerConfigSchema;
29
33
  exports.intlayerConfigSchemaParseContext = require_configFile_configurationSchema.intlayerConfigSchemaParseContext;
@@ -0,0 +1,59 @@
1
+ //#region src/configFile/editorServerOverride.ts
2
+ /**
3
+ * Port of the `intlayer-editor` server, set by `intlayer-editor start --with`
4
+ * on the application it starts. Turns the editor on for that application and
5
+ * points `editor.editorURL` at the server, without touching the configuration
6
+ * file.
7
+ */
8
+ const EDITOR_SERVER_PORT_ENV_VAR = "INTLAYER_EDITOR_SERVER_PORT";
9
+ /** Hostnames `editor.editorURL` may name the local editor server with. */
10
+ const LOCAL_HOSTNAMES = /* @__PURE__ */ new Set([
11
+ "localhost",
12
+ "127.0.0.1",
13
+ "0.0.0.0",
14
+ "[::1]"
15
+ ]);
16
+ /**
17
+ * `editor.editorURL` adapted to the port the local editor server listens on,
18
+ * which differs from `editor.port` when that one is taken.
19
+ *
20
+ * @returns The adapted URL, or `undefined` when the URL already targets that
21
+ * port or names another host (e.g. a proxy) that cannot be adapted.
22
+ */
23
+ const getEditorURLForPort = (editorURL, port) => {
24
+ const localEditorURL = `http://localhost:${port}`;
25
+ if (!editorURL) return localEditorURL;
26
+ let parsedEditorURL;
27
+ try {
28
+ parsedEditorURL = new URL(editorURL);
29
+ } catch {
30
+ return localEditorURL;
31
+ }
32
+ if (!LOCAL_HOSTNAMES.has(parsedEditorURL.hostname)) return void 0;
33
+ if ((parsedEditorURL.port || (parsedEditorURL.protocol === "https:" ? "443" : "80")) === String(port)) return void 0;
34
+ parsedEditorURL.port = String(port);
35
+ return editorURL.endsWith("/") ? parsedEditorURL.href : parsedEditorURL.href.replace(/\/$/, "");
36
+ };
37
+ /**
38
+ * Applies {@link EDITOR_SERVER_PORT_ENV_VAR}: enables the editor and adapts
39
+ * its URL and port to the running editor server.
40
+ *
41
+ * @returns The configuration unchanged when the variable is not set.
42
+ */
43
+ const applyEditorServerOverride = (configuration, environment = process.env) => {
44
+ const editorServerPort = Number(environment[EDITOR_SERVER_PORT_ENV_VAR]);
45
+ if (!Number.isInteger(editorServerPort) || editorServerPort <= 0) return configuration;
46
+ return {
47
+ ...configuration,
48
+ editor: {
49
+ ...configuration.editor,
50
+ enabled: true,
51
+ port: editorServerPort,
52
+ editorURL: getEditorURLForPort(configuration.editor.editorURL, editorServerPort) ?? configuration.editor.editorURL
53
+ }
54
+ };
55
+ };
56
+
57
+ //#endregion
58
+ export { EDITOR_SERVER_PORT_ENV_VAR, applyEditorServerOverride, getEditorURLForPort };
59
+ //# sourceMappingURL=editorServerOverride.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"editorServerOverride.mjs","names":[],"sources":["../../../src/configFile/editorServerOverride.ts"],"sourcesContent":["import type { IntlayerConfig } from '@intlayer/types/config';\n\n/**\n * Port of the `intlayer-editor` server, set by `intlayer-editor start --with`\n * on the application it starts. Turns the editor on for that application and\n * points `editor.editorURL` at the server, without touching the configuration\n * file.\n */\nexport const EDITOR_SERVER_PORT_ENV_VAR = 'INTLAYER_EDITOR_SERVER_PORT';\n\n/** Hostnames `editor.editorURL` may name the local editor server with. */\nconst LOCAL_HOSTNAMES = new Set(['localhost', '127.0.0.1', '0.0.0.0', '[::1]']);\n\n/**\n * `editor.editorURL` adapted to the port the local editor server listens on,\n * which differs from `editor.port` when that one is taken.\n *\n * @returns The adapted URL, or `undefined` when the URL already targets that\n * port or names another host (e.g. a proxy) that cannot be adapted.\n */\nexport const getEditorURLForPort = (\n editorURL: string | undefined,\n port: number\n): string | undefined => {\n const localEditorURL = `http://localhost:${port}`;\n\n if (!editorURL) return localEditorURL;\n\n let parsedEditorURL: URL;\n\n try {\n parsedEditorURL = new URL(editorURL);\n } catch {\n return localEditorURL;\n }\n\n if (!LOCAL_HOSTNAMES.has(parsedEditorURL.hostname)) return undefined;\n\n const editorPort =\n parsedEditorURL.port ||\n (parsedEditorURL.protocol === 'https:' ? '443' : '80');\n\n if (editorPort === String(port)) return undefined;\n\n parsedEditorURL.port = String(port);\n\n // `URL` adds a trailing slash to a bare origin\n return editorURL.endsWith('/')\n ? parsedEditorURL.href\n : parsedEditorURL.href.replace(/\\/$/, '');\n};\n\n/**\n * Applies {@link EDITOR_SERVER_PORT_ENV_VAR}: enables the editor and adapts\n * its URL and port to the running editor server.\n *\n * @returns The configuration unchanged when the variable is not set.\n */\nexport const applyEditorServerOverride = (\n configuration: IntlayerConfig,\n environment: NodeJS.ProcessEnv = process.env\n): IntlayerConfig => {\n const editorServerPort = Number(environment[EDITOR_SERVER_PORT_ENV_VAR]);\n\n if (!Number.isInteger(editorServerPort) || editorServerPort <= 0) {\n return configuration;\n }\n\n return {\n ...configuration,\n editor: {\n ...configuration.editor,\n enabled: true,\n port: editorServerPort,\n editorURL:\n getEditorURLForPort(configuration.editor.editorURL, editorServerPort) ??\n configuration.editor.editorURL,\n },\n };\n};\n"],"mappings":";;;;;;;AAQA,MAAa,6BAA6B;;AAG1C,MAAM,kCAAkB,IAAI,IAAI;CAAC;CAAa;CAAa;CAAW;AAAO,CAAC;;;;;;;;AAS9E,MAAa,uBACX,WACA,SACuB;CACvB,MAAM,iBAAiB,oBAAoB;CAE3C,IAAI,CAAC,WAAW,OAAO;CAEvB,IAAI;CAEJ,IAAI;EACF,kBAAkB,IAAI,IAAI,SAAS;CACrC,QAAQ;EACN,OAAO;CACT;CAEA,IAAI,CAAC,gBAAgB,IAAI,gBAAgB,QAAQ,GAAG,OAAO;CAM3D,KAHE,gBAAgB,SACf,gBAAgB,aAAa,WAAW,QAAQ,WAEhC,OAAO,IAAI,GAAG,OAAO;CAExC,gBAAgB,OAAO,OAAO,IAAI;CAGlC,OAAO,UAAU,SAAS,GAAG,IACzB,gBAAgB,OAChB,gBAAgB,KAAK,QAAQ,OAAO,EAAE;AAC5C;;;;;;;AAQA,MAAa,6BACX,eACA,cAAiC,QAAQ,QACtB;CACnB,MAAM,mBAAmB,OAAO,YAAY,2BAA2B;CAEvE,IAAI,CAAC,OAAO,UAAU,gBAAgB,KAAK,oBAAoB,GAC7D,OAAO;CAGT,OAAO;EACL,GAAG;EACH,QAAQ;GACN,GAAG,cAAc;GACjB,SAAS;GACT,MAAM;GACN,WACE,oBAAoB,cAAc,OAAO,WAAW,gBAAgB,KACpE,cAAc,OAAO;EACzB;CACF;AACF"}
@@ -1,12 +1,24 @@
1
1
  import { cacheMemory } from "../utils/cacheMemory.mjs";
2
2
  import { getPackageJsonPath } from "../utils/getPackageJsonPath.mjs";
3
3
  import { buildConfigurationFields } from "./buildConfigurationFields.mjs";
4
+ import { applyEditorServerOverride } from "./editorServerOverride.mjs";
4
5
  import { loadConfigurationFile } from "./loadConfigurationFile.mjs";
5
6
  import { searchConfigurationFile } from "./searchConfigurationFile.mjs";
6
7
  import { defu } from "defu";
7
8
 
8
9
  //#region src/configFile/getConfiguration.ts
9
10
  /**
11
+ * Applies the editor server override outside the cache: the editor server
12
+ * sets it once listening, after its configuration was first read.
13
+ */
14
+ const withEditorServerOverride = (result) => {
15
+ const configuration = applyEditorServerOverride(result.configuration);
16
+ return configuration === result.configuration ? result : {
17
+ ...result,
18
+ configuration
19
+ };
20
+ };
21
+ /**
10
22
  * Get the configuration for the intlayer by reading the configuration file (e.g. intlayer.config.js)
11
23
  */
12
24
  const getConfigurationAndFilePath = (options) => {
@@ -22,7 +34,7 @@ const getConfigurationAndFilePath = (options) => {
22
34
  };
23
35
  }
24
36
  const cachedConfiguration = cacheMemory.get(options);
25
- if (cachedConfiguration) return cachedConfiguration;
37
+ if (cachedConfiguration) return withEditorServerOverride(cachedConfiguration);
26
38
  const { configurationFilePath, numCustomConfiguration } = searchConfigurationFile(baseDir);
27
39
  let storedConfiguration;
28
40
  let customConfiguration;
@@ -51,12 +63,12 @@ const getConfigurationAndFilePath = (options) => {
51
63
  numCustomConfiguration,
52
64
  configurationFilePath
53
65
  });
54
- return {
66
+ return withEditorServerOverride({
55
67
  configuration,
56
68
  customConfiguration,
57
69
  numCustomConfiguration,
58
70
  configurationFilePath
59
- };
71
+ });
60
72
  };
61
73
  /**
62
74
  * Get the configuration for the intlayer by reading the configuration file (e.g. intlayer.config.js)
@@ -1 +1 @@
1
- {"version":3,"file":"getConfiguration.mjs","names":[],"sources":["../../../src/configFile/getConfiguration.ts"],"sourcesContent":["import type {\n CustomIntlayerConfig,\n IntlayerConfig,\n LogFunctions,\n} from '@intlayer/types/config';\nimport { defu } from 'defu';\nimport type { LoadExternalFileOptions } from '../loadExternalFile/loadExternalFile';\nimport type { SandBoxContextOptions } from '../loadExternalFile/parseFileContent';\nimport { cacheMemory } from '../utils/cacheMemory';\nimport { getPackageJsonPath } from '../utils/getPackageJsonPath';\nimport { buildConfigurationFields } from './buildConfigurationFields';\nimport { loadConfigurationFile } from './loadConfigurationFile';\nimport { searchConfigurationFile } from './searchConfigurationFile';\n\nexport type GetConfigurationOptions = {\n baseDir?: string;\n override?: CustomIntlayerConfig;\n // Dotenv options\n env?: string;\n envFile?: string;\n // Log functions\n logFunctions?: LogFunctions;\n // Require function\n require?: NodeJS.Require;\n // cache\n cache?: boolean;\n // Build options for TypeScript transpilation (e.g. custom esbuild instance)\n buildOptions?: LoadExternalFileOptions['buildOptions'];\n} & Omit<SandBoxContextOptions, 'projectRequire'>;\n\nexport type GetConfigurationAndFilePathResult = {\n configuration: IntlayerConfig;\n customConfiguration: CustomIntlayerConfig | undefined;\n numCustomConfiguration: number;\n configurationFilePath: string | undefined;\n};\n\n/**\n * Get the configuration for the intlayer by reading the configuration file (e.g. intlayer.config.js)\n */\nexport const getConfigurationAndFilePath = (\n options?: GetConfigurationOptions\n): GetConfigurationAndFilePathResult => {\n let baseDir: string | undefined;\n\n try {\n // Can fail in some environments (e.g. MCP server, VScode extension)\n baseDir = options?.baseDir ?? getPackageJsonPath().baseDir;\n } catch (_err) {\n // Return default config if the package.json is not found\n return {\n configuration: buildConfigurationFields(\n {},\n options?.baseDir,\n options?.logFunctions\n ),\n customConfiguration: undefined,\n numCustomConfiguration: 0,\n configurationFilePath: undefined,\n };\n }\n\n const cachedConfiguration =\n cacheMemory.get<GetConfigurationAndFilePathResult>(options);\n\n if (cachedConfiguration) return cachedConfiguration;\n\n // Search for configuration files\n const { configurationFilePath, numCustomConfiguration } =\n searchConfigurationFile(baseDir);\n\n let storedConfiguration: IntlayerConfig;\n let customConfiguration: CustomIntlayerConfig | undefined;\n\n if (configurationFilePath) {\n // Load the custom configuration\n customConfiguration = loadConfigurationFile(configurationFilePath, {\n projectRequire: options?.require,\n // Dotenv options\n envVarOptions: {\n env: options?.env,\n envFile: options?.envFile,\n },\n // Sandbox context additional variables\n additionalEnvVars: options?.additionalEnvVars,\n aliases: options?.aliases,\n // Build options for TypeScript transpilation (e.g. custom esbuild instance)\n buildOptions: options?.buildOptions,\n });\n\n // Save the configuration to avoid reading the file again\n storedConfiguration = buildConfigurationFields(\n customConfiguration,\n options?.baseDir,\n options?.logFunctions\n );\n } else {\n // No configuration file found, use default configuration\n storedConfiguration = buildConfigurationFields(\n {},\n options?.baseDir,\n options?.logFunctions\n );\n }\n\n // Log warning if multiple configuration files are found\n const projectRequireConfig: CustomIntlayerConfig = options?.require\n ? {\n build: {\n require: options?.require,\n cache: options?.cache,\n },\n }\n : {};\n\n const configWithProjectRequire = defu(\n projectRequireConfig,\n storedConfiguration\n ) as IntlayerConfig;\n\n const configuration = defu(\n options?.override ?? {},\n configWithProjectRequire\n ) as IntlayerConfig;\n\n cacheMemory.set(options, {\n configuration,\n customConfiguration,\n numCustomConfiguration,\n configurationFilePath,\n });\n\n return {\n configuration,\n customConfiguration,\n numCustomConfiguration,\n configurationFilePath,\n };\n};\n\n/**\n * Get the configuration for the intlayer by reading the configuration file (e.g. intlayer.config.js)\n */\nexport const getConfiguration = (\n options?: GetConfigurationOptions\n): IntlayerConfig => getConfigurationAndFilePath(options).configuration;\n"],"mappings":";;;;;;;;;;;AAwCA,MAAa,+BACX,YACsC;CACtC,IAAI;CAEJ,IAAI;EAEF,UAAU,SAAS,WAAW,mBAAmB,CAAC,CAAC;CACrD,SAAS,MAAM;EAEb,OAAO;GACL,eAAe,yBACb,CAAC,GACD,SAAS,SACT,SAAS,YACX;GACA,qBAAqB;GACrB,wBAAwB;GACxB,uBAAuB;EACzB;CACF;CAEA,MAAM,sBACJ,YAAY,IAAuC,OAAO;CAE5D,IAAI,qBAAqB,OAAO;CAGhC,MAAM,EAAE,uBAAuB,2BAC7B,wBAAwB,OAAO;CAEjC,IAAI;CACJ,IAAI;CAEJ,IAAI,uBAAuB;EAEzB,sBAAsB,sBAAsB,uBAAuB;GACjE,gBAAgB,SAAS;GAEzB,eAAe;IACb,KAAK,SAAS;IACd,SAAS,SAAS;GACpB;GAEA,mBAAmB,SAAS;GAC5B,SAAS,SAAS;GAElB,cAAc,SAAS;EACzB,CAAC;EAGD,sBAAsB,yBACpB,qBACA,SAAS,SACT,SAAS,YACX;CACF,OAEE,sBAAsB,yBACpB,CAAC,GACD,SAAS,SACT,SAAS,YACX;CAIF,MAAM,uBAA6C,SAAS,UACxD,EACE,OAAO;EACL,SAAS,SAAS;EAClB,OAAO,SAAS;CAClB,EACF,IACA,CAAC;CAEL,MAAM,2BAA2B,KAC/B,sBACA,mBACF;CAEA,MAAM,gBAAgB,KACpB,SAAS,YAAY,CAAC,GACtB,wBACF;CAEA,YAAY,IAAI,SAAS;EACvB;EACA;EACA;EACA;CACF,CAAC;CAED,OAAO;EACL;EACA;EACA;EACA;CACF;AACF;;;;AAKA,MAAa,oBACX,YACmB,4BAA4B,OAAO,CAAC,CAAC"}
1
+ {"version":3,"file":"getConfiguration.mjs","names":[],"sources":["../../../src/configFile/getConfiguration.ts"],"sourcesContent":["import type {\n CustomIntlayerConfig,\n IntlayerConfig,\n LogFunctions,\n} from '@intlayer/types/config';\nimport { defu } from 'defu';\nimport type { LoadExternalFileOptions } from '../loadExternalFile/loadExternalFile';\nimport type { SandBoxContextOptions } from '../loadExternalFile/parseFileContent';\nimport { cacheMemory } from '../utils/cacheMemory';\nimport { getPackageJsonPath } from '../utils/getPackageJsonPath';\nimport { buildConfigurationFields } from './buildConfigurationFields';\nimport { applyEditorServerOverride } from './editorServerOverride';\nimport { loadConfigurationFile } from './loadConfigurationFile';\nimport { searchConfigurationFile } from './searchConfigurationFile';\n\nexport type GetConfigurationOptions = {\n baseDir?: string;\n override?: CustomIntlayerConfig;\n // Dotenv options\n env?: string;\n envFile?: string;\n // Log functions\n logFunctions?: LogFunctions;\n // Require function\n require?: NodeJS.Require;\n // cache\n cache?: boolean;\n // Build options for TypeScript transpilation (e.g. custom esbuild instance)\n buildOptions?: LoadExternalFileOptions['buildOptions'];\n} & Omit<SandBoxContextOptions, 'projectRequire'>;\n\nexport type GetConfigurationAndFilePathResult = {\n configuration: IntlayerConfig;\n customConfiguration: CustomIntlayerConfig | undefined;\n numCustomConfiguration: number;\n configurationFilePath: string | undefined;\n};\n\n/**\n * Applies the editor server override outside the cache: the editor server\n * sets it once listening, after its configuration was first read.\n */\nconst withEditorServerOverride = (\n result: GetConfigurationAndFilePathResult\n): GetConfigurationAndFilePathResult => {\n const configuration = applyEditorServerOverride(result.configuration);\n\n return configuration === result.configuration\n ? result\n : { ...result, configuration };\n};\n\n/**\n * Get the configuration for the intlayer by reading the configuration file (e.g. intlayer.config.js)\n */\nexport const getConfigurationAndFilePath = (\n options?: GetConfigurationOptions\n): GetConfigurationAndFilePathResult => {\n let baseDir: string | undefined;\n\n try {\n // Can fail in some environments (e.g. MCP server, VScode extension)\n baseDir = options?.baseDir ?? getPackageJsonPath().baseDir;\n } catch (_err) {\n // Return default config if the package.json is not found\n return {\n configuration: buildConfigurationFields(\n {},\n options?.baseDir,\n options?.logFunctions\n ),\n customConfiguration: undefined,\n numCustomConfiguration: 0,\n configurationFilePath: undefined,\n };\n }\n\n const cachedConfiguration =\n cacheMemory.get<GetConfigurationAndFilePathResult>(options);\n\n if (cachedConfiguration) return withEditorServerOverride(cachedConfiguration);\n\n // Search for configuration files\n const { configurationFilePath, numCustomConfiguration } =\n searchConfigurationFile(baseDir);\n\n let storedConfiguration: IntlayerConfig;\n let customConfiguration: CustomIntlayerConfig | undefined;\n\n if (configurationFilePath) {\n // Load the custom configuration\n customConfiguration = loadConfigurationFile(configurationFilePath, {\n projectRequire: options?.require,\n // Dotenv options\n envVarOptions: {\n env: options?.env,\n envFile: options?.envFile,\n },\n // Sandbox context additional variables\n additionalEnvVars: options?.additionalEnvVars,\n aliases: options?.aliases,\n // Build options for TypeScript transpilation (e.g. custom esbuild instance)\n buildOptions: options?.buildOptions,\n });\n\n // Save the configuration to avoid reading the file again\n storedConfiguration = buildConfigurationFields(\n customConfiguration,\n options?.baseDir,\n options?.logFunctions\n );\n } else {\n // No configuration file found, use default configuration\n storedConfiguration = buildConfigurationFields(\n {},\n options?.baseDir,\n options?.logFunctions\n );\n }\n\n // Log warning if multiple configuration files are found\n const projectRequireConfig: CustomIntlayerConfig = options?.require\n ? {\n build: {\n require: options?.require,\n cache: options?.cache,\n },\n }\n : {};\n\n const configWithProjectRequire = defu(\n projectRequireConfig,\n storedConfiguration\n ) as IntlayerConfig;\n\n const configuration = defu(\n options?.override ?? {},\n configWithProjectRequire\n ) as IntlayerConfig;\n\n cacheMemory.set(options, {\n configuration,\n customConfiguration,\n numCustomConfiguration,\n configurationFilePath,\n });\n\n return withEditorServerOverride({\n configuration,\n customConfiguration,\n numCustomConfiguration,\n configurationFilePath,\n });\n};\n\n/**\n * Get the configuration for the intlayer by reading the configuration file (e.g. intlayer.config.js)\n */\nexport const getConfiguration = (\n options?: GetConfigurationOptions\n): IntlayerConfig => getConfigurationAndFilePath(options).configuration;\n"],"mappings":";;;;;;;;;;;;;AA0CA,MAAM,4BACJ,WACsC;CACtC,MAAM,gBAAgB,0BAA0B,OAAO,aAAa;CAEpE,OAAO,kBAAkB,OAAO,gBAC5B,SACA;EAAE,GAAG;EAAQ;CAAc;AACjC;;;;AAKA,MAAa,+BACX,YACsC;CACtC,IAAI;CAEJ,IAAI;EAEF,UAAU,SAAS,WAAW,mBAAmB,CAAC,CAAC;CACrD,SAAS,MAAM;EAEb,OAAO;GACL,eAAe,yBACb,CAAC,GACD,SAAS,SACT,SAAS,YACX;GACA,qBAAqB;GACrB,wBAAwB;GACxB,uBAAuB;EACzB;CACF;CAEA,MAAM,sBACJ,YAAY,IAAuC,OAAO;CAE5D,IAAI,qBAAqB,OAAO,yBAAyB,mBAAmB;CAG5E,MAAM,EAAE,uBAAuB,2BAC7B,wBAAwB,OAAO;CAEjC,IAAI;CACJ,IAAI;CAEJ,IAAI,uBAAuB;EAEzB,sBAAsB,sBAAsB,uBAAuB;GACjE,gBAAgB,SAAS;GAEzB,eAAe;IACb,KAAK,SAAS;IACd,SAAS,SAAS;GACpB;GAEA,mBAAmB,SAAS;GAC5B,SAAS,SAAS;GAElB,cAAc,SAAS;EACzB,CAAC;EAGD,sBAAsB,yBACpB,qBACA,SAAS,SACT,SAAS,YACX;CACF,OAEE,sBAAsB,yBACpB,CAAC,GACD,SAAS,SACT,SAAS,YACX;CAIF,MAAM,uBAA6C,SAAS,UACxD,EACE,OAAO;EACL,SAAS,SAAS;EAClB,OAAO,SAAS;CAClB,EACF,IACA,CAAC;CAEL,MAAM,2BAA2B,KAC/B,sBACA,mBACF;CAEA,MAAM,gBAAgB,KACpB,SAAS,YAAY,CAAC,GACtB,wBACF;CAEA,YAAY,IAAI,SAAS;EACvB;EACA;EACA;EACA;CACF,CAAC;CAED,OAAO,yBAAyB;EAC9B;EACA;EACA;EACA;CACF,CAAC;AACH;;;;AAKA,MAAa,oBACX,YACmB,4BAA4B,OAAO,CAAC,CAAC"}
@@ -1,7 +1,8 @@
1
1
  import { buildAnalyticsFields, buildBrowserConfiguration, buildEditorFields, buildInternationalizationFields, buildLogFields, buildRoutingFields, extractBrowserConfiguration } from "./buildBrowserConfiguration.mjs";
2
2
  import { aiSchema, analyticsSchema, buildSchema, compilerSchema, contentSchema, cookiesAttributesSchema, dictionarySchema, editorSchema, internationalizationSchema, intlayerConfigSchema, intlayerConfigSchemaParseContext, logSchema, rewriteObjectSchema, rewriteRuleSchema, rewriteRulesSchema, routingSchema, storageAttributesSchema, storageSchema, systemSchema } from "./configurationSchema.mjs";
3
3
  import { buildConfigurationFields } from "./buildConfigurationFields.mjs";
4
+ import { EDITOR_SERVER_PORT_ENV_VAR, applyEditorServerOverride, getEditorURLForPort } from "./editorServerOverride.mjs";
4
5
  import { configurationFilesCandidates, searchConfigurationFile } from "./searchConfigurationFile.mjs";
5
6
  import { getConfiguration, getConfigurationAndFilePath } from "./getConfiguration.mjs";
6
7
 
7
- export { aiSchema, analyticsSchema, buildAnalyticsFields, buildBrowserConfiguration, buildConfigurationFields, buildEditorFields, buildInternationalizationFields, buildLogFields, buildRoutingFields, buildSchema, compilerSchema, configurationFilesCandidates, contentSchema, cookiesAttributesSchema, dictionarySchema, editorSchema, extractBrowserConfiguration, getConfiguration, getConfigurationAndFilePath, internationalizationSchema, intlayerConfigSchema, intlayerConfigSchemaParseContext, logSchema, rewriteObjectSchema, rewriteRuleSchema, rewriteRulesSchema, routingSchema, searchConfigurationFile, storageAttributesSchema, storageSchema, systemSchema };
8
+ export { EDITOR_SERVER_PORT_ENV_VAR, aiSchema, analyticsSchema, applyEditorServerOverride, buildAnalyticsFields, buildBrowserConfiguration, buildConfigurationFields, buildEditorFields, buildInternationalizationFields, buildLogFields, buildRoutingFields, buildSchema, compilerSchema, configurationFilesCandidates, contentSchema, cookiesAttributesSchema, dictionarySchema, editorSchema, extractBrowserConfiguration, getConfiguration, getConfigurationAndFilePath, getEditorURLForPort, internationalizationSchema, intlayerConfigSchema, intlayerConfigSchemaParseContext, logSchema, rewriteObjectSchema, rewriteRuleSchema, rewriteRulesSchema, routingSchema, searchConfigurationFile, storageAttributesSchema, storageSchema, systemSchema };
package/dist/esm/node.mjs CHANGED
@@ -1,7 +1,8 @@
1
1
  import { buildAnalyticsFields, buildBrowserConfiguration, buildEditorFields, buildInternationalizationFields, buildLogFields, buildRoutingFields, extractBrowserConfiguration } from "./configFile/buildBrowserConfiguration.mjs";
2
2
  import { aiSchema, analyticsSchema, buildSchema, compilerSchema, contentSchema, cookiesAttributesSchema, dictionarySchema, editorSchema, internationalizationSchema, intlayerConfigSchema, intlayerConfigSchemaParseContext, logSchema, rewriteObjectSchema, rewriteRuleSchema, rewriteRulesSchema, routingSchema, storageAttributesSchema, storageSchema, systemSchema } from "./configFile/configurationSchema.mjs";
3
3
  import { buildConfigurationFields } from "./configFile/buildConfigurationFields.mjs";
4
+ import { EDITOR_SERVER_PORT_ENV_VAR, applyEditorServerOverride, getEditorURLForPort } from "./configFile/editorServerOverride.mjs";
4
5
  import { configurationFilesCandidates, searchConfigurationFile } from "./configFile/searchConfigurationFile.mjs";
5
6
  import { getConfiguration, getConfigurationAndFilePath } from "./configFile/getConfiguration.mjs";
6
7
 
7
- export { aiSchema, analyticsSchema, buildAnalyticsFields, buildBrowserConfiguration, buildConfigurationFields, buildEditorFields, buildInternationalizationFields, buildLogFields, buildRoutingFields, buildSchema, compilerSchema, configurationFilesCandidates, contentSchema, cookiesAttributesSchema, dictionarySchema, editorSchema, extractBrowserConfiguration, getConfiguration, getConfigurationAndFilePath, internationalizationSchema, intlayerConfigSchema, intlayerConfigSchemaParseContext, logSchema, rewriteObjectSchema, rewriteRuleSchema, rewriteRulesSchema, routingSchema, searchConfigurationFile, storageAttributesSchema, storageSchema, systemSchema };
8
+ export { EDITOR_SERVER_PORT_ENV_VAR, aiSchema, analyticsSchema, applyEditorServerOverride, buildAnalyticsFields, buildBrowserConfiguration, buildConfigurationFields, buildEditorFields, buildInternationalizationFields, buildLogFields, buildRoutingFields, buildSchema, compilerSchema, configurationFilesCandidates, contentSchema, cookiesAttributesSchema, dictionarySchema, editorSchema, extractBrowserConfiguration, getConfiguration, getConfigurationAndFilePath, getEditorURLForPort, internationalizationSchema, intlayerConfigSchema, intlayerConfigSchemaParseContext, logSchema, rewriteObjectSchema, rewriteRuleSchema, rewriteRulesSchema, routingSchema, searchConfigurationFile, storageAttributesSchema, storageSchema, systemSchema };
@@ -0,0 +1,26 @@
1
+ import { IntlayerConfig } from "@intlayer/types/config";
2
+ //#region src/configFile/editorServerOverride.d.ts
3
+ /**
4
+ * Port of the `intlayer-editor` server, set by `intlayer-editor start --with`
5
+ * on the application it starts. Turns the editor on for that application and
6
+ * points `editor.editorURL` at the server, without touching the configuration
7
+ * file.
8
+ */
9
+ export declare const EDITOR_SERVER_PORT_ENV_VAR = "INTLAYER_EDITOR_SERVER_PORT";
10
+ /**
11
+ * `editor.editorURL` adapted to the port the local editor server listens on,
12
+ * which differs from `editor.port` when that one is taken.
13
+ *
14
+ * @returns The adapted URL, or `undefined` when the URL already targets that
15
+ * port or names another host (e.g. a proxy) that cannot be adapted.
16
+ */
17
+ export declare const getEditorURLForPort: (editorURL: string | undefined, port: number) => string | undefined;
18
+ /**
19
+ * Applies {@link EDITOR_SERVER_PORT_ENV_VAR}: enables the editor and adapts
20
+ * its URL and port to the running editor server.
21
+ *
22
+ * @returns The configuration unchanged when the variable is not set.
23
+ */
24
+ export declare const applyEditorServerOverride: (configuration: IntlayerConfig, environment?: NodeJS.ProcessEnv) => IntlayerConfig;
25
+ //#endregion
26
+ //# sourceMappingURL=editorServerOverride.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"editorServerOverride.d.ts","names":[],"sources":["../../../src/configFile/editorServerOverride.ts"],"mappings":";;;;;;;;qBAQa;;;;;;;;qBAYA,sBAAmB,+BACD;;;;;;;qBAqClB,4BAAyB,eACrB,gBAAc,cAChB,OAAO,eACnB"}
@@ -1 +1 @@
1
- {"version":3,"file":"getConfiguration.d.ts","names":[],"sources":["../../../src/configFile/getConfiguration.ts"],"mappings":";;;;YAcY;EACV;EACA,WAAW;EAEX;EACA;EAEA,eAAe;EAEf,UAAU,OAAO;EAEjB;EAEA,eAAe;IACb,KAAK;YAEG;EACV,eAAe;EACf,qBAAqB;EACrB;EACA;;;;;qBAMW,8BAA2B,UAC5B,4BACT;;;;qBAqGU,mBAAgB,UACjB,4BACT"}
1
+ {"version":3,"file":"getConfiguration.d.ts","names":[],"sources":["../../../src/configFile/getConfiguration.ts"],"mappings":";;;;YAeY;EACV;EACA,WAAW;EAEX;EACA;EAEA,eAAe;EAEf,UAAU,OAAO;EAEjB;EAEA,eAAe;IACb,KAAK;YAEG;EACV,eAAe;EACf,qBAAqB;EACrB;EACA;;;;;qBAoBW,8BAA2B,UAC5B,4BACT;;;;qBAqGU,mBAAgB,UACjB,4BACT"}
@@ -2,5 +2,6 @@ import { GetConfigurationAndFilePathResult, GetConfigurationOptions, getConfigur
2
2
  import { BrowserIntlayerConfig, buildAnalyticsFields, buildBrowserConfiguration, buildEditorFields, buildInternationalizationFields, buildLogFields, buildRoutingFields, extractBrowserConfiguration } from "./buildBrowserConfiguration.js";
3
3
  import { buildConfigurationFields } from "./buildConfigurationFields.js";
4
4
  import { aiSchema, analyticsSchema, buildSchema, compilerSchema, contentSchema, cookiesAttributesSchema, dictionarySchema, editorSchema, internationalizationSchema, intlayerConfigSchema, intlayerConfigSchemaParseContext, logSchema, rewriteObjectSchema, rewriteRuleSchema, rewriteRulesSchema, routingSchema, storageAttributesSchema, storageSchema, systemSchema } from "./configurationSchema.js";
5
+ import { EDITOR_SERVER_PORT_ENV_VAR, applyEditorServerOverride, getEditorURLForPort } from "./editorServerOverride.js";
5
6
  import { configurationFilesCandidates, searchConfigurationFile } from "./searchConfigurationFile.js";
6
- export { type BrowserIntlayerConfig, GetConfigurationAndFilePathResult, GetConfigurationOptions, aiSchema, analyticsSchema, buildAnalyticsFields, buildBrowserConfiguration, buildConfigurationFields, buildEditorFields, buildInternationalizationFields, buildLogFields, buildRoutingFields, buildSchema, compilerSchema, configurationFilesCandidates, contentSchema, cookiesAttributesSchema, dictionarySchema, editorSchema, extractBrowserConfiguration, getConfiguration, getConfigurationAndFilePath, internationalizationSchema, intlayerConfigSchema, intlayerConfigSchemaParseContext, logSchema, rewriteObjectSchema, rewriteRuleSchema, rewriteRulesSchema, routingSchema, searchConfigurationFile, storageAttributesSchema, storageSchema, systemSchema };
7
+ export { type BrowserIntlayerConfig, EDITOR_SERVER_PORT_ENV_VAR, GetConfigurationAndFilePathResult, GetConfigurationOptions, aiSchema, analyticsSchema, applyEditorServerOverride, buildAnalyticsFields, buildBrowserConfiguration, buildConfigurationFields, buildEditorFields, buildInternationalizationFields, buildLogFields, buildRoutingFields, buildSchema, compilerSchema, configurationFilesCandidates, contentSchema, cookiesAttributesSchema, dictionarySchema, editorSchema, extractBrowserConfiguration, getConfiguration, getConfigurationAndFilePath, getEditorURLForPort, internationalizationSchema, intlayerConfigSchema, intlayerConfigSchemaParseContext, logSchema, rewriteObjectSchema, rewriteRuleSchema, rewriteRulesSchema, routingSchema, searchConfigurationFile, storageAttributesSchema, storageSchema, systemSchema };
@@ -2,5 +2,6 @@ import { GetConfigurationAndFilePathResult, GetConfigurationOptions, getConfigur
2
2
  import { BrowserIntlayerConfig, buildAnalyticsFields, buildBrowserConfiguration, buildEditorFields, buildInternationalizationFields, buildLogFields, buildRoutingFields, extractBrowserConfiguration } from "./configFile/buildBrowserConfiguration.js";
3
3
  import { buildConfigurationFields } from "./configFile/buildConfigurationFields.js";
4
4
  import { aiSchema, analyticsSchema, buildSchema, compilerSchema, contentSchema, cookiesAttributesSchema, dictionarySchema, editorSchema, internationalizationSchema, intlayerConfigSchema, intlayerConfigSchemaParseContext, logSchema, rewriteObjectSchema, rewriteRuleSchema, rewriteRulesSchema, routingSchema, storageAttributesSchema, storageSchema, systemSchema } from "./configFile/configurationSchema.js";
5
+ import { EDITOR_SERVER_PORT_ENV_VAR, applyEditorServerOverride, getEditorURLForPort } from "./configFile/editorServerOverride.js";
5
6
  import { configurationFilesCandidates, searchConfigurationFile } from "./configFile/searchConfigurationFile.js";
6
- export { type BrowserIntlayerConfig, GetConfigurationAndFilePathResult, GetConfigurationOptions, aiSchema, analyticsSchema, buildAnalyticsFields, buildBrowserConfiguration, buildConfigurationFields, buildEditorFields, buildInternationalizationFields, buildLogFields, buildRoutingFields, buildSchema, compilerSchema, configurationFilesCandidates, contentSchema, cookiesAttributesSchema, dictionarySchema, editorSchema, extractBrowserConfiguration, getConfiguration, getConfigurationAndFilePath, internationalizationSchema, intlayerConfigSchema, intlayerConfigSchemaParseContext, logSchema, rewriteObjectSchema, rewriteRuleSchema, rewriteRulesSchema, routingSchema, searchConfigurationFile, storageAttributesSchema, storageSchema, systemSchema };
7
+ export { type BrowserIntlayerConfig, EDITOR_SERVER_PORT_ENV_VAR, GetConfigurationAndFilePathResult, GetConfigurationOptions, aiSchema, analyticsSchema, applyEditorServerOverride, buildAnalyticsFields, buildBrowserConfiguration, buildConfigurationFields, buildEditorFields, buildInternationalizationFields, buildLogFields, buildRoutingFields, buildSchema, compilerSchema, configurationFilesCandidates, contentSchema, cookiesAttributesSchema, dictionarySchema, editorSchema, extractBrowserConfiguration, getConfiguration, getConfigurationAndFilePath, getEditorURLForPort, internationalizationSchema, intlayerConfigSchema, intlayerConfigSchemaParseContext, logSchema, rewriteObjectSchema, rewriteRuleSchema, rewriteRulesSchema, routingSchema, searchConfigurationFile, storageAttributesSchema, storageSchema, systemSchema };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlayer/config",
3
- "version": "9.6.0",
3
+ "version": "9.7.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": [
@@ -190,15 +190,15 @@
190
190
  "typecheck": "tsc --noEmit --project tsconfig.types.json"
191
191
  },
192
192
  "dependencies": {
193
- "@intlayer/types": "9.6.0",
193
+ "@intlayer/types": "9.7.0",
194
194
  "defu": "6.1.7",
195
- "dotenv": "18.0.5",
195
+ "dotenv": "18.0.6",
196
196
  "esbuild": "0.28.2",
197
197
  "json5": "2.2.3",
198
198
  "zod": "4.6.5"
199
199
  },
200
200
  "devDependencies": {
201
- "@types/node": "^22",
201
+ "@types/node": "^26",
202
202
  "@utils/ts-config": "1.0.4",
203
203
  "@utils/ts-config-types": "1.0.4",
204
204
  "@utils/tsdown-config": "1.0.4",