Skip to content

Commit

Permalink
feat: add .js and .mjs support to loader
Browse files Browse the repository at this point in the history
  • Loading branch information
nnmrts committed Nov 21, 2021
1 parent 971b7db commit cc03e3b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/load_config.ts
Expand Up @@ -2,7 +2,9 @@ import { existsSync, parseYaml, path } from "../deps.ts";
import { ScriptsConfiguration } from "./scripts_config.ts";

const CONFIG_FILE_NAMES = ["scripts", "velociraptor"];
const CONFIG_FILE_EXTENSIONS = ["yaml", "yml", "json", "ts"];
const STATIC_CONFIG_FILE_EXTENSIONS = ["yaml", "yml", "json"];
const DYNAMIC_CONFIG_FILE_EXTENSIONS = ["ts", "js", "mjs"];
const CONFIG_FILE_EXTENSIONS = [...STATIC_CONFIG_FILE_EXTENSIONS, ...DYNAMIC_CONFIG_FILE_EXTENSIONS];

export interface ConfigData {
cwd: string;
Expand All @@ -18,7 +20,7 @@ export async function loadConfig(): Promise<ConfigData | null> {
if (existsSync(p)) {
return {
cwd: dir,
config: await parseConfig(p, ext == "ts"),
config: await parseConfig(p, DYNAMIC_CONFIG_FILE_EXTENSIONS.includes(ext)),
};
}
}
Expand All @@ -34,9 +36,9 @@ function parent(dir: string) {

async function parseConfig(
configPath: string,
isTypescript: boolean,
isDynamic: boolean,
): Promise<ScriptsConfiguration> {
if (isTypescript) {
if (isDynamic) {
return (await import(`file://${configPath}`))
.default as ScriptsConfiguration;
}
Expand Down

0 comments on commit cc03e3b

Please sign in to comment.