Skip to content

Commit f5fbaf2

Browse files
committed
use jiti to load configs
1 parent 80951be commit f5fbaf2

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

package-lock.json

Lines changed: 22 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"@bluecadet/launchpad-utils": "~2.0.0",
5656
"chalk": "^5.0.0",
5757
"dotenv": "^16.4.5",
58+
"jiti": "^2.4.2",
5859
"neverthrow": "^8.1.1",
5960
"yargs": "^17.7.2",
6061
"zod": "^3.23.8"

packages/cli/src/utils/config.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@ import fs from "node:fs";
22
import path from "node:path";
33
import url from "node:url";
44
import chalk from "chalk";
5+
import { createJiti } from "jiti";
56

6-
const DEFAULT_CONFIG_PATHS = ["launchpad.config.js", "launchpad.config.mjs"];
7+
const DEFAULT_CONFIG_PATHS = [
8+
"launchpad.config.js",
9+
"launchpad.config.mjs",
10+
"launchpad.config.ts",
11+
"launchpad.config.cjs",
12+
"launchpad.config.mts",
13+
"launchpad.config.cts",
14+
];
715

816
/**
917
* Searches for a config file in the current and parent directories, up to a max depth of 64.
@@ -63,11 +71,13 @@ export async function loadConfigFromFile<T>(configPath: string): Promise<Partial
6371
if (!configPath) {
6472
return {};
6573
}
74+
75+
const jiti = createJiti(import.meta.url);
6676

6777
try {
6878
// need to use fileURLToPath here for windows support (prefixes with file://)
6979
const fileUrl = url.pathToFileURL(configPath);
70-
return (await import(fileUrl.toString())).default;
80+
return (await jiti.import(fileUrl.toString(), { default: true}));
7181
} catch (err) {
7282
throw new Error(`Unable to load config file '${chalk.white(configPath)}'`, { cause: err });
7383
}

0 commit comments

Comments
 (0)