Skip to content

Commit d188df1

Browse files
feat: Add config_file_path option to Vite plugin
1 parent 07f9f4d commit d188df1

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

packages/vite-plugin-tempest/src/config.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
import type { TempestViteConfiguration } from './types'
22
import { exec, php } from './utils'
3+
import { readFileSync } from 'node:fs';
4+
import { resolve } from 'node:path';
35

46
const TEMPEST_BIN = 'tempest'
57
const VITE_CONFIG_COMMAND = 'vite:config'
68

7-
export async function loadTempestConfiguration(): Promise<TempestViteConfiguration> {
9+
export async function loadTempestConfiguration(
10+
options: { config_file_path?: string } = {}
11+
): Promise<TempestViteConfiguration> {
12+
if (options.config_file_path) {
13+
try {
14+
const filePath = resolve(process.cwd(), options.config_file_path);
15+
const fileContent = readFileSync(filePath, 'utf-8');
16+
return JSON.parse(fileContent);
17+
} catch (e) {
18+
console.error(`[vite-plugin-tempest] Error: Failed to read or parse the file at [${options.config_file_path}].`);
19+
throw e;
20+
}
21+
}
22+
823
try {
924
const override = process.env.TEMPEST_PLUGIN_CONFIGURATION_OVERRIDE
1025
if (override) {

packages/vite-plugin-tempest/src/plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const TEMPEST_ORIGIN_PLACEHOLDER = 'http://__tempest_placeholder__.test'
1515

1616
let exitHandlersBound = false
1717

18-
export default function tempest(): Plugin {
18+
export default function tempest(options: { config_file_path?: string } = {}): Plugin {
1919
let viteDevServerUrl: DevelopmentServerUrl
2020
let bridgeFilePath: string
2121
let resolvedConfig: ResolvedConfig
@@ -30,7 +30,7 @@ export default function tempest(): Plugin {
3030
name: 'tempest',
3131
enforce: 'post',
3232
config: async (config, { command, mode }) => {
33-
tempestConfig = await loadTempestConfiguration()
33+
tempestConfig = await loadTempestConfiguration(options)
3434
userConfig = config
3535

3636
const ssr = !!userConfig.build?.ssr

0 commit comments

Comments
 (0)