-
-
Notifications
You must be signed in to change notification settings - Fork 18
Description
Hello, thank you first of all for creating such a great open-source project.
I have a question regarding plugins. I am currently using a plugin to read configuration files.
export function config(filePath: string): Plugin {
let loadedConfig: Record<string, unknown> = {};
return plugin<
Record<string, unknown>,
'gunshi:config',
[],
{ getConfig: () => Record<string, unknown> }
>({
id: 'gunshi:config',
dependencies: [],
setup: async (ctx) => {
const fullPath = path.resolve(filePath);
const buf = await fs.promises.readFile(fullPath, 'utf-8');
loadedConfig = JSON.parse(buf) as Record<string, unknown>;
},
extension: (ctx) => {
for (const [key, value] of Object.entries(loadedConfig)) {
if (ctx.values[key] == null) {
(ctx.values as any)[key] = value;
}
}
return {
getConfig: () => loadedConfig,
};
},
});
}In our setup, the plugin reads a config file, stores the values, and then the extension mutates those values.
In tools related to Babel or Vite, when a config file is used, the resolution order usually works as follows:
1. process.argv
2. config file
3. default values
However, the config plugin here seems to work in the following order:
1. process.argv
2. default values
3. config file
Is there a way to change this order, or is there any guideline or documentation that explains how to handle this?
The plugin itself is excellent, but based on what is defined in the documentation
(https://gunshi.dev/guide/plugin/lifecycle),
it seems that reading and applying values from a config file happens relatively late in the execution lifecycle.
Thank you.