Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: .json5 support #133

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ c12 (pronounced as /siːtwelv/, like c-twelve) is a smart configuration loader.

## Features

- `.json`, `.js`, `.ts`, and `.mjs` config loader with [unjs/jiti](https://github.com/unjs/jiti)
- `.jsonc` config support with [jsonc-parser](https://github.com/microsoft/node-jsonc-parser)
- `.js`, `.ts`, `.cjs`, `.mjs` config loader with [unjs/jiti](https://github.com/unjs/jiti)
- `.json`, `.json5` and `.jsonc` config support.
- `.rc` config support with [unjs/rc9](https://github.com/unjs/rc9)
- `.env` support with [dotenv](https://www.npmjs.com/package/dotenv)
- Multiple sources merged with [unjs/defu](https://github.com/unjs/defu)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"dotenv": "^16.3.2",
"giget": "^1.2.1",
"jiti": "^1.21.0",
"json5": "^2.2.3",
"jsonc-parser": "^3.2.1",
"mlly": "^1.5.0",
"ohash": "^1.1.3",
Expand Down
4 changes: 3 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export async function loadConfig<
".cts",
".json",
".jsonc",
".json5",
],
...options.jitiOptions,
});
Expand Down Expand Up @@ -329,6 +330,9 @@ async function resolveConfig<
if (res.configFile!.endsWith(".jsonc")) {
const { parse } = await import("jsonc-parser");
res.config = parse(await readFile(res.configFile!, "utf8"));
} else if (res.configFile!.endsWith(".json5")) {
const { parse } = await import("json5");
res.config = parse(await readFile(res.configFile!, "utf8"));
} else {
res.config = options.jiti!(res.configFile!);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default {
{
extends: "../.base",
colors: {
primary: "theme_primary",
secondary: "theme_secondary",
},
};
}
2 changes: 1 addition & 1 deletion test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ describe("c12", () => {
"secondary": "theme_secondary",
},
},
"configFile": "<path>/fixture/theme/config.ts",
"configFile": "<path>/fixture/theme/config.json5",
"cwd": "<path>/fixture/theme",
"meta": {},
"source": "config",
Expand Down
Loading