Skip to content

Commit e811f32

Browse files
committed
feat: Support CVE_CONFIG environment variable
1 parent 57c0ed2 commit e811f32

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

.changeset/tasty-maps-draw.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"css-var-extract": minor
3+
---
4+
5+
Support `CVE_CONFIG` environment variable

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,17 @@ cve watch
200200
You can create `cve.config.json` and change settings.
201201
If you are using a plugin, it also supports inline configuration.
202202

203-
### cve.config.json
203+
You can also override the settings by the `CVE_CONFIG` environment variable.
204+
205+
### Priority
206+
207+
The lower the number, the higher the priority.
208+
209+
1. Environment variable: `CVE_CONFIG`
210+
2. Inline config
211+
3. File config `cve.config.json`
212+
213+
### JSON
204214

205215
```json
206216
{

packages/css-var-extract/src/config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,21 @@ export const getConfig = (
3434
"cve.config.json",
3535
);
3636
const exists = fs.existsSync(configFilePathJson);
37+
const env = process.env.CVE_CONFIG;
38+
const envConfig = env ? JSON.parse(env) : {};
3739

3840
let config: Config;
3941
if (exists) {
4042
config = configSchema.parse({
4143
...JSON.parse(fs.readFileSync(configFilePathJson, "utf-8")),
4244
...inlineConfig,
45+
...envConfig,
4346
});
4447
} else {
45-
config = configSchema.parse(inlineConfig);
48+
config = configSchema.parse({
49+
...inlineConfig,
50+
...envConfig,
51+
});
4652
if (!noCreate) {
4753
fs.writeFileSync(
4854
configFilePathJson,

0 commit comments

Comments
 (0)