Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions boat/api-tester/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { existsSync, mkdirSync, readFileSync } from 'node:fs';
import path, { resolve } from 'node:path';
import { pathToFileURL } from 'node:url';
import { parseEnv } from 'node:util';
import { type AIConfig, type ApiHookFn, type ApiConfig as BaseApiConfig, ConfigMissingError, EXPLORBOT_CONFIG_PATHS, createModel, envConfigRequested, materializeKnowledge, missingConfigMessage, resolveConfigModels, resolveModel, resolveOutputRoot } from '../../../src/config.ts';
import { type SiteRecord, findGlobalConfig, globalEnvPath, isGlobalConfigPath, registerSite, resolveSiteTarget } from '../../../src/global-config.ts';
Expand Down Expand Up @@ -213,18 +214,19 @@ export class ApibotConfigParser {

private async loadConfigModule(configPath: string): Promise<any> {
const ext = configPath.split('.').pop();
const moduleUrl = pathToFileURL(resolve(configPath)).href;

if (ext === 'ts') {
try {
return await import(configPath);
return await import(moduleUrl);
} catch {
const require = (await import('node:module')).createRequire(import.meta.url);
return require(configPath);
}
}

if (ext === 'js' || ext === 'mjs') {
return await import(configPath);
return await import(moduleUrl);
}

const content = readFileSync(configPath, 'utf8');
Expand Down
6 changes: 4 additions & 2 deletions boat/doc-collector/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { existsSync, readFileSync } from 'node:fs';
import path, { resolve } from 'node:path';
import { pathToFileURL } from 'node:url';
import { parseEnv } from 'node:util';
import { ConfigParser } from '../../../src/config.ts';

Expand Down Expand Up @@ -90,18 +91,19 @@ class DocbotConfigParser {

private async loadConfigModule(configPath: string): Promise<any> {
const ext = configPath.split('.').pop();
const moduleUrl = pathToFileURL(resolve(configPath)).href;

if (ext === 'ts') {
try {
return await import(configPath);
return await import(moduleUrl);
} catch {
const require = (await import('node:module')).createRequire(import.meta.url);
return require(configPath);
}
}

if (ext === 'js' || ext === 'mjs') {
return await import(configPath);
return await import(moduleUrl);
}

return JSON.parse(readFileSync(configPath, 'utf8'));
Expand Down
6 changes: 4 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { copyFileSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import path, { basename, dirname, join, resolve } from 'node:path';
import { pathToFileURL } from 'node:url';
import { parseEnv } from 'node:util';
import dedent from 'dedent';
import matter from 'gray-matter';
Expand Down Expand Up @@ -619,17 +620,18 @@ export class ConfigParser {

private async loadConfigModule(configPath: string): Promise<any> {
const ext = configPath.split('.').pop();
const moduleUrl = pathToFileURL(resolve(configPath)).href;

if (ext === 'ts') {
try {
const module = await import(configPath);
const module = await import(moduleUrl);
return module;
} catch (error) {
const require = (await import('node:module')).createRequire(import.meta.url);
return require(configPath);
}
} else if (ext === 'js' || ext === 'mjs') {
const module = await import(configPath);
const module = await import(moduleUrl);
return module;
} else {
const content = readFileSync(configPath, 'utf8');
Expand Down
1 change: 1 addition & 0 deletions tests/unit/explorer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ mock.module('codeceptjs', () => {
};

const container = {
STANDARD_ACTING_HELPERS: ['Playwright', 'WebDriver', 'Puppeteer', 'Appium'],
create: () => {},
helpers: (name: string) => {
if (name === 'Playwright') {
Expand Down
Loading