Comparing version 0.1.4 to 0.2.0
@@ -39,8 +39,11 @@ interface DotenvOptions { | ||
} | ||
interface ResolvedConfig<T extends InputConfig = InputConfig> { | ||
interface ConfigLayer<T extends InputConfig = InputConfig> { | ||
config: T; | ||
cwd?: string; | ||
configFile?: string; | ||
layers?: ResolvedConfig<T>[]; | ||
} | ||
interface ResolvedConfig<T extends InputConfig = InputConfig> extends ConfigLayer<T> { | ||
layers?: ConfigLayer<T>[]; | ||
cwd?: string; | ||
} | ||
interface ResolveConfigOptions { | ||
@@ -65,2 +68,2 @@ cwd: string; | ||
export { DotenvOptions, Env, InputConfig, LoadConfigOptions, ResolveConfigOptions, ResolvedConfig, loadConfig, loadDotenv, setupDotenv }; | ||
export { ConfigLayer, DotenvOptions, Env, InputConfig, LoadConfigOptions, ResolveConfigOptions, ResolvedConfig, loadConfig, loadDotenv, setupDotenv }; |
{ | ||
"name": "c12", | ||
"version": "0.1.4", | ||
"version": "0.2.0", | ||
"description": "Smart Config Loader", | ||
@@ -21,10 +21,2 @@ "repository": "unjs/c12", | ||
], | ||
"scripts": { | ||
"build": "unbuild", | ||
"dev": "vitest dev", | ||
"lint": "eslint --ext .ts,.js,.mjs,.cjs .", | ||
"prepack": "unbuild", | ||
"release": "yarn test && standard-version && git push --follow-tags && npm publish", | ||
"test": "vitest run --coverage" | ||
}, | ||
"dependencies": { | ||
@@ -47,3 +39,12 @@ "defu": "^5.0.1", | ||
"vitest": "latest" | ||
} | ||
} | ||
}, | ||
"packageManager": "pnpm@6.32.3", | ||
"scripts": { | ||
"build": "unbuild", | ||
"dev": "vitest dev", | ||
"lint": "eslint --ext .ts,.js,.mjs,.cjs .", | ||
"release": "pnpm test && standard-version && git push --follow-tags && pnpm publish", | ||
"test": "vitest run --coverage" | ||
}, | ||
"readme": "# c12\n\n[![npm version][npm-version-src]][npm-version-href]\n[![npm downloads][npm-downloads-src]][npm-downloads-href]\n[![Github Actions][github-actions-src]][github-actions-href]\n[![Codecov][codecov-src]][codecov-href]\n\n> Smart Configuration Loader\n\n## Features\n\n- JSON, CJS, Typescript and ESM config loader with [unjs/jiti](https://github.com/unjs/jiti)\n- RC config support with [unjs/rc9](https://github.com/unjs/rc9)\n- Multiple sources merged with [unjs/defu](https://github.com/unjs/defu)\n- `.env` support with [dotenv](https://www.npmjs.com/package/dotenv)\n- Support extending nested configurations from multiple local or git sources\n\n## Usage\n\nInstall package:\n\n```sh\n# npm\nnpm install c12\n\n# yarn\nyarn install c12\n\n# pnpm\npnpm install c12\n```\n\nImport:\n\n```js\n// ESM\nimport { loadConfig } from 'c12'\n\n// CommonJS\nconst { loadConfig } = require('c12')\n```\n\nLoad configuration:\n\n```js\n// Get loaded config\nconst { config } = await loadConfig({})\n\n// Get resolved config and extended layers\nconst { config, configFile, layers } = await loadConfig({})\n```\n\n## Loading priority\n\nc12 merged config sources with [unjs/defu](https://github.com/unjs/defu) by below order:\n\n1. config overrides passed by options\n2. config file in CWD\n3. RC file in CWD\n4. global RC file in user's home directory\n5. default config passed by options\n6. Extended config layers\n\n## Options\n\n### `cwd`\n\nResolve configuration from this working directory. Default is `process.cwd()`\n\n### `name`\n\nConfiguration base name. Default is `config`.\n\n### `configName`\n\nConfiguration file name without extension . Default is generated from `name` (name=foo => `foo.config`).\n\nSet to `false` to avoid loading config file.\n\n### `rcFile`\n\nRC Config file name. Default is generated from `name` (name=foo => `.foorc`).\n\nSet to `false` to disable loading RC config.\n\n### `globalRC`\n\nLoad RC config from the user's home directory. Only enabled when `rcFile` is provided. Set to `false` to disable this functionality.\n\n### `dotenv`\n\nLoads `.env` file if enabled. It is disabled by default.\n\n### `defaults`\n\nSpecify default configuration. It has the **lowest** priority.\n\n### `overides`\n\nSpecify override configuration. It has the **highest** priority.\n\n## Extending configuration\n\nIf resolved config contains a `extends` key, it will be used to extend configuration.\n\nExtending can be nested and each layer can extend from one base or more.\n\nFinal config is merged result of extended options and user options with [unjs/defu](https://github.com/unjs/defu).\n\nEach item in extends, is a string that can be either an absolute or relative path to current config file pointing to a config file for extending or directory containing config file.\nIf it starts with either of `github:`, `gitlab:`, `bitbucket:` or `https:`, c12 autmatically clones it.\n\nFor custom merging strategies, you can directly access each layer with `layers` property.\n\n**Example:**\n\n```js\n// config.ts\nexport default {\n colors: {\n primary: 'user_primary'\n },\n extends: [\n './theme',\n './config.dev.ts'\n ]\n}\n```\n\n```js\n// config.dev.ts\nexport default {\n dev: true\n}\n```\n\n```js\n// theme/config.ts\nexport default {\n extends: '../base',\n colors: {\n primary: 'theme_primary',\n secondary: 'theme_secondary'\n }\n}\n```\n\n```js\n// base/config.ts\nexport default {\n colors: {\n primary: 'base_primary'\n text: 'base_text'\n }\n}\n```\n\nLoaded configuration would look like this:\n\n```js\n{\n dev: true,\n colors: {\n primary: 'user_primary',\n secondary: 'theme_secondary',\n text: 'base_text'\n }\n}\n```\n\nLayers:\n\n```js\n[\n { config: /* theme config */, configFile: /* path/to/theme/config.ts */, cwd: /* path/to/theme */ },\n { config: /* base config */, configFile: /* path/to/base/config.ts */, cwd: /* path/to/base */ },\n { config: /* dev config */, configFile: /* path/to/config.dev.ts */, cwd: /* path/ */ },\n]\n```\n\n## 💻 Development\n\n- Clone this repository\n- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable` (use `npm i -g corepack` for Node.js < 16.10)\n- Install dependencies using `pnpm install`\n- Run interactive tests using `pnpm dev`\n\n## License\n\nMade with 💛 Published under [MIT License](./LICENSE).\n\n<!-- Badges -->\n[npm-version-src]: https://img.shields.io/npm/v/c12?style=flat-square\n[npm-version-href]: https://npmjs.com/package/c12\n\n[npm-downloads-src]: https://img.shields.io/npm/dm/c12?style=flat-square\n[npm-downloads-href]: https://npmjs.com/package/c12\n\n[github-actions-src]: https://img.shields.io/github/workflow/status/unjs/c12/ci/main?style=flat-square\n[github-actions-href]: https://github.com/unjs/c12/actions?query=workflow%3Aci\n\n[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/c12/main?style=flat-square\n[codecov-href]: https://codecov.io/gh/unjs/c12\n" | ||
} |
@@ -185,4 +185,4 @@ # c12 | ||
- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable` (use `npm i -g corepack` for Node.js < 16.10) | ||
- Install dependencies using `yarn install` | ||
- Run interactive tests using `yarn dev` | ||
- Install dependencies using `pnpm install` | ||
- Run interactive tests using `pnpm dev` | ||
@@ -189,0 +189,0 @@ ## License |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27172
460