forked from rolldown/rolldown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.ts
27 lines (24 loc) · 736 Bytes
/
utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import path from 'node:path'
import { ERR_UNSUPPORTED_CONFIG_FORMAT } from './errors.js'
import { RolldownConfigExport } from '../types/rolldown-config-export.js'
/**
* @typedef {import('../rollup').RollupOptions} RollupOptions
*/
/**
* Load a rolldown configuration file
*/
export async function loadConfig(
configPath: string,
): Promise<RolldownConfigExport | undefined> {
if (!isSupportedFormat(configPath)) {
throw new Error(ERR_UNSUPPORTED_CONFIG_FORMAT)
}
return import(configPath).then((config) => config.default)
}
/**
* Check whether the configuration file is supported
*/
function isSupportedFormat(configPath: string): boolean {
const ext = path.extname(configPath)
return /\.(js|mjs)$/.test(ext)
}