import type { InlangConfigModule } from "../config/schema.js" import { setupConfig } from "../config/setupConfig.js" import type { InlangEnvironment } from "../environment/types.js" import type { Result } from "../utilities/result.js" import { parseConfig, ParseConfigException } from "../config/parseConfig.js" /** * Validates the inlang.config.js file. * * If you only want to validate the config object, * use the `testConfig` function instead. * * @example * const [success, error] = await testConfigFile(args) */ export async function testConfigFile(args: { file: string env: InlangEnvironment }): Promise> { try { const [, importKeywordUsedException] = importKeywordUsed(args.file) if (importKeywordUsedException) { return [undefined, importKeywordUsedException] } const module: InlangConfigModule = await import( "data:application/javascript;base64," + btoa(args.file) ) const config = await setupConfig({ module, env: args.env }) const [, exception] = await parseConfig({ config }) if (exception) { return [undefined, exception] } return [true, undefined] } catch (e) { return [undefined, new ParseConfigException((e as Error).message)] } } /** * Detects if the import keyword is used in the config file. */ function importKeywordUsed(configFile: string): Result { // This regex uses a negative lookbehind assertion (?