feat: init
This commit is contained in:
21
node_modules/c12/LICENSE
generated
vendored
Normal file
21
node_modules/c12/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Pooya Parsa <pooya@pi0.io>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
493
node_modules/c12/README.md
generated
vendored
Normal file
493
node_modules/c12/README.md
generated
vendored
Normal file
@@ -0,0 +1,493 @@
|
||||
# ⚙️ c12
|
||||
|
||||
<!-- automd:badges color=yellow codecov -->
|
||||
|
||||
[](https://npmjs.com/package/c12)
|
||||
[](https://npm.chart.dev/c12)
|
||||
[](https://codecov.io/gh/unjs/c12)
|
||||
|
||||
<!-- /automd -->
|
||||
|
||||
c12 (pronounced as /siːtwelv/, like c-twelve) is a smart configuration loader.
|
||||
|
||||
## ✅ Features
|
||||
|
||||
- `.js`, `.ts`, `.mjs`, `.cjs`, `.mts`, `.cts` `.json` config loader with [unjs/jiti](https://jiti.unjs.io)
|
||||
- `.jsonc`, `.json5`, `.yaml`, `.yml`, `.toml` config loader with [unjs/confbox](https://confbox.unjs.io)
|
||||
- `.config/` directory support ([config dir proposal](https://github.com/pi0/config-dir))
|
||||
- `.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)
|
||||
- Reads config from the nearest `package.json` file
|
||||
- [Extends configurations](https://github.com/unjs/c12#extending-configuration) from multiple local or git sources
|
||||
- Overwrite with [environment-specific configuration](#environment-specific-configuration)
|
||||
- Config watcher with auto-reload and HMR support
|
||||
- Create or update configuration files with [magicast](https://github.com/unjs/magicast)
|
||||
|
||||
## 🦴 Used by
|
||||
|
||||
- [Hey API](https://github.com/hey-api/openapi-ts)
|
||||
- [Kysely](https://github.com/kysely-org/kysely-ctl)
|
||||
- [Nitro](https://nitro.build/)
|
||||
- [Nuxt](https://nuxt.com/)
|
||||
- [Prisma](https://github.com/prisma/prisma)
|
||||
- [Trigger.dev](https://github.com/triggerdotdev/trigger.dev)
|
||||
- [UnJS](https://github.com/unjs)
|
||||
- [WXT](https://github.com/wxt-dev/wxt)
|
||||
|
||||
## Usage
|
||||
|
||||
Install package:
|
||||
|
||||
```sh
|
||||
# ✨ Auto-detect
|
||||
npx nypm install c12
|
||||
```
|
||||
|
||||
Import:
|
||||
|
||||
```js
|
||||
// ESM import
|
||||
import { loadConfig, watchConfig } from "c12";
|
||||
|
||||
// or using dynamic import
|
||||
const { loadConfig, watchConfig } = await import("c12");
|
||||
```
|
||||
|
||||
Load configuration:
|
||||
|
||||
```js
|
||||
// Get loaded config
|
||||
const { config } = await loadConfig({});
|
||||
|
||||
// Get resolved config and extended layers
|
||||
const { config, configFile, layers } = await loadConfig({});
|
||||
```
|
||||
|
||||
## Loading priority
|
||||
|
||||
c12 merged config sources with [unjs/defu](https://github.com/unjs/defu) by below order:
|
||||
|
||||
1. Config overrides passed by options
|
||||
2. Config file in CWD
|
||||
3. RC file in CWD
|
||||
4. Global RC file in the user's home directory
|
||||
5. Config from `package.json`
|
||||
6. Default config passed by options
|
||||
7. Extended config layers
|
||||
|
||||
## Options
|
||||
|
||||
### `cwd`
|
||||
|
||||
Resolve configuration from this working directory. The default is `process.cwd()`
|
||||
|
||||
### `name`
|
||||
|
||||
Configuration base name. The default is `config`.
|
||||
|
||||
### `configFile`
|
||||
|
||||
Configuration file name without extension. Default is generated from `name` (f.e., if `name` is `foo`, the config file will be => `foo.config`).
|
||||
|
||||
### `rcFile`
|
||||
|
||||
RC Config file name. Default is generated from `name` (name=foo => `.foorc`).
|
||||
|
||||
Set to `false` to disable loading RC config.
|
||||
|
||||
### `globalRc`
|
||||
|
||||
Load RC config from the workspace directory and the user's home directory. Only enabled when `rcFile` is provided. Set to `false` to disable this functionality.
|
||||
|
||||
### `dotenv`
|
||||
|
||||
Loads `.env` file when `true` or an options object is passed. It is disabled by default.
|
||||
|
||||
Supports loading multiple files that extend eachother in left-to-right order when a `fileName`s array of relative/absolute paths is passed in the options object.
|
||||
|
||||
**Example:**
|
||||
|
||||
```ini
|
||||
# .env
|
||||
CONNECTION_POOL_MAX="10"
|
||||
DATABASE_URL="<...rds...>"
|
||||
```
|
||||
|
||||
```ini
|
||||
# .env.local
|
||||
DATABASE_URL="<...localhost...>"
|
||||
```
|
||||
|
||||
```js
|
||||
export default {
|
||||
connectionPoolMax: process.env.CONNECTION_POOL_MAX,
|
||||
databaseURL: process.env.DATABASE_URL,
|
||||
};
|
||||
```
|
||||
|
||||
```ts
|
||||
import { loadConfig } from "c12";
|
||||
|
||||
const config = await loadConfig({
|
||||
dotenv: {
|
||||
fileName: [".env", ".env.local"],
|
||||
},
|
||||
});
|
||||
|
||||
console.log(config.config.connectionPoolMax); // "10"
|
||||
console.log(config.config.databaseURL); // "<...localhost...>"
|
||||
```
|
||||
|
||||
### `packageJson`
|
||||
|
||||
Loads config from nearest `package.json` file. It is disabled by default.
|
||||
|
||||
If `true` value is passed, c12 uses `name` field from `package.json`.
|
||||
|
||||
You can also pass either a string or an array of strings as a value to use those fields.
|
||||
|
||||
### `defaults`
|
||||
|
||||
Specify default configuration. It has the **lowest** priority and is applied **after extending** config.
|
||||
|
||||
### `defaultConfig`
|
||||
|
||||
Specify default configuration. It is applied **before** extending config.
|
||||
|
||||
### `overrides`
|
||||
|
||||
Specify override configuration. It has the **highest** priority and is applied **before extending** config.
|
||||
|
||||
### `omit$Keys`
|
||||
|
||||
Exclude environment-specific and built-in keys start with `$` in the resolved config. The default is `false`.
|
||||
|
||||
### `jiti`
|
||||
|
||||
Custom [unjs/jiti](https://github.com/unjs/jiti) instance used to import configuration files.
|
||||
|
||||
### `jitiOptions`
|
||||
|
||||
Custom [unjs/jiti](https://github.com/unjs/jiti) options to import configuration files.
|
||||
|
||||
### `giget`
|
||||
|
||||
Options passed to [unjs/giget](https://github.com/unjs/giget) when extending layer from git source.
|
||||
|
||||
### `merger`
|
||||
|
||||
Custom options merger function. Default is [defu](https://github.com/unjs/defu).
|
||||
|
||||
**Note:** Custom merge function should deeply merge options with arguments high -> low priority.
|
||||
|
||||
### `envName`
|
||||
|
||||
Environment name used for [environment specific configuration](#environment-specific-configuration).
|
||||
|
||||
The default is `process.env.NODE_ENV`. You can set `envName` to `false` or an empty string to disable the feature.
|
||||
|
||||
### `context`
|
||||
|
||||
Context object passed to dynamic config functions.
|
||||
|
||||
### `resolve`
|
||||
|
||||
You can define a custom function that resolves the config.
|
||||
|
||||
### `configFileRequired`
|
||||
|
||||
If this option is set to `true`, loader fails if the main config file does not exists.
|
||||
|
||||
## Extending configuration
|
||||
|
||||
If resolved config contains a `extends` key, it will be used to extend the configuration.
|
||||
|
||||
Extending can be nested and each layer can extend from one base or more.
|
||||
|
||||
The final config is merged result of extended options and user options with [unjs/defu](https://github.com/unjs/defu).
|
||||
|
||||
Each item in extends is a string that can be either an absolute or relative path to the current config file pointing to a config file for extending or the directory containing the config file.
|
||||
If it starts with either `github:`, `gitlab:`, `bitbucket:`, or `https:`, c12 automatically clones it.
|
||||
|
||||
For custom merging strategies, you can directly access each layer with `layers` property.
|
||||
|
||||
**Example:**
|
||||
|
||||
```js
|
||||
// config.ts
|
||||
export default {
|
||||
colors: {
|
||||
primary: "user_primary",
|
||||
},
|
||||
extends: ["./theme"],
|
||||
};
|
||||
```
|
||||
|
||||
```js
|
||||
// config.dev.ts
|
||||
export default {
|
||||
dev: true,
|
||||
};
|
||||
```
|
||||
|
||||
```js
|
||||
// theme/config.ts
|
||||
export default {
|
||||
extends: "../base",
|
||||
colors: {
|
||||
primary: "theme_primary",
|
||||
secondary: "theme_secondary",
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
```js
|
||||
// base/config.ts
|
||||
export default {
|
||||
colors: {
|
||||
primary: "base_primary",
|
||||
text: "base_text",
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
The loaded configuration would look like this:
|
||||
|
||||
```js
|
||||
const config = {
|
||||
dev: true,
|
||||
colors: {
|
||||
primary: "user_primary",
|
||||
secondary: "theme_secondary",
|
||||
text: "base_text",
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
Layers:
|
||||
|
||||
```js
|
||||
[
|
||||
{
|
||||
config: {
|
||||
/* theme config */
|
||||
},
|
||||
configFile: "/path/to/theme/config.ts",
|
||||
cwd: "/path/to/theme ",
|
||||
},
|
||||
{
|
||||
config: {
|
||||
/* base config */
|
||||
},
|
||||
configFile: "/path/to/base/config.ts",
|
||||
cwd: "/path/to/base",
|
||||
},
|
||||
{
|
||||
config: {
|
||||
/* dev config */
|
||||
},
|
||||
configFile: "/path/to/config.dev.ts",
|
||||
cwd: "/path/",
|
||||
},
|
||||
];
|
||||
```
|
||||
|
||||
## Extending config layer from remote sources
|
||||
|
||||
You can also extend configuration from remote sources such as npm or github.
|
||||
|
||||
In the repo, there should be a `config.ts` (or `config.{name}.ts`) file to be considered as a valid config layer.
|
||||
|
||||
**Example:** Extend from a github repository
|
||||
|
||||
```js
|
||||
// config.ts
|
||||
export default {
|
||||
extends: "gh:user/repo",
|
||||
};
|
||||
```
|
||||
|
||||
**Example:** Extend from a github repository with branch and subpath
|
||||
|
||||
```js
|
||||
// config.ts
|
||||
export default {
|
||||
extends: "gh:user/repo/theme#dev",
|
||||
};
|
||||
```
|
||||
|
||||
**Example:** Extend a private repository and install dependencies:
|
||||
|
||||
```js
|
||||
// config.ts
|
||||
export default {
|
||||
extends: ["gh:user/repo", { auth: process.env.GITHUB_TOKEN, install: true }],
|
||||
};
|
||||
```
|
||||
|
||||
You can pass more options to `giget: {}` in layer config or disable it by setting it to `false`.
|
||||
|
||||
Refer to [unjs/giget](https://giget.unjs.io) for more information.
|
||||
|
||||
## Environment-specific configuration
|
||||
|
||||
Users can define environment-specific configuration using these config keys:
|
||||
|
||||
- `$test: {...}`
|
||||
- `$development: {...}`
|
||||
- `$production: {...}`
|
||||
- `$env: { [env]: {...} }`
|
||||
|
||||
c12 tries to match [`envName`](#envname) and override environment config if specified.
|
||||
|
||||
**Note:** Environment will be applied when extending each configuration layer. This way layers can provide environment-specific configuration.
|
||||
|
||||
**Example:**
|
||||
|
||||
```js
|
||||
export default {
|
||||
// Default configuration
|
||||
logLevel: "info",
|
||||
|
||||
// Environment overrides
|
||||
$test: { logLevel: "silent" },
|
||||
$development: { logLevel: "warning" },
|
||||
$production: { logLevel: "error" },
|
||||
$env: {
|
||||
staging: { logLevel: "debug" },
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
## Watching configuration
|
||||
|
||||
you can use `watchConfig` instead of `loadConfig` to load config and watch for changes, add and removals in all expected configuration paths and auto reload with new config.
|
||||
|
||||
### Lifecycle hooks
|
||||
|
||||
- `onWatch`: This function is always called when config is updated, added, or removed before attempting to reload the config.
|
||||
- `acceptHMR`: By implementing this function, you can compare old and new functions and return `true` if a full reload is not needed.
|
||||
- `onUpdate`: This function is always called after the new config is updated. If `acceptHMR` returns true, it will be skipped.
|
||||
|
||||
```ts
|
||||
import { watchConfig } from "c12";
|
||||
|
||||
const config = watchConfig({
|
||||
cwd: ".",
|
||||
// chokidarOptions: {}, // Default is { ignoreInitial: true }
|
||||
// debounce: 200 // Default is 100. You can set it to false to disable debounced watcher
|
||||
onWatch: (event) => {
|
||||
console.log("[watcher]", event.type, event.path);
|
||||
},
|
||||
acceptHMR({ oldConfig, newConfig, getDiff }) {
|
||||
const diff = getDiff();
|
||||
if (diff.length === 0) {
|
||||
console.log("No config changed detected!");
|
||||
return true; // No changes!
|
||||
}
|
||||
},
|
||||
onUpdate({ oldConfig, newConfig, getDiff }) {
|
||||
const diff = getDiff();
|
||||
console.log("Config updated:\n" + diff.map((i) => i.toJSON()).join("\n"));
|
||||
},
|
||||
});
|
||||
|
||||
console.log("watching config files:", config.watchingFiles);
|
||||
console.log("initial config", config.config);
|
||||
|
||||
// Stop watcher when not needed anymore
|
||||
// await config.unwatch();
|
||||
```
|
||||
|
||||
## Updating config
|
||||
|
||||
> [!NOTE]
|
||||
> This feature is experimental
|
||||
|
||||
Update or create a new configuration files.
|
||||
|
||||
Add `magicast` peer dependency:
|
||||
|
||||
```sh
|
||||
# ✨ Auto-detect
|
||||
npx nypm install -D magicast
|
||||
```
|
||||
|
||||
Import util from `c12/update`
|
||||
|
||||
```js
|
||||
const { configFile, created } = await updateConfig({
|
||||
cwd: ".",
|
||||
configFile: "foo.config",
|
||||
onCreate: ({ configFile }) => {
|
||||
// You can prompt user if wants to create a new config file and return false to cancel
|
||||
console.log(`Creating new config file in ${configFile}...`);
|
||||
return "export default { test: true }";
|
||||
},
|
||||
onUpdate: (config) => {
|
||||
// You can update the config contents just like an object
|
||||
config.test2 = false;
|
||||
},
|
||||
});
|
||||
|
||||
console.log(`Config file ${created ? "created" : "updated"} in ${configFile}`);
|
||||
```
|
||||
|
||||
## Configuration functions
|
||||
|
||||
You can use a function to define your configuration dynamically based on context.
|
||||
|
||||
```ts
|
||||
// config.ts
|
||||
export default (ctx) => {
|
||||
return {
|
||||
apiUrl: ctx?.dev ? "http://localhost:3000" : "https://api.example.com",
|
||||
};
|
||||
};
|
||||
```
|
||||
|
||||
```ts
|
||||
// Usage
|
||||
import { loadConfig } from "c12";
|
||||
|
||||
const config = await loadConfig({
|
||||
context: { dev: true },
|
||||
});
|
||||
```
|
||||
|
||||
## Contribution
|
||||
|
||||
<details>
|
||||
<summary>Local development</summary>
|
||||
|
||||
- Clone this repository
|
||||
- Install the latest LTS version of [Node.js](https://nodejs.org/en/)
|
||||
- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable`
|
||||
- Install dependencies using `pnpm install`
|
||||
- Run tests using `pnpm dev` or `pnpm test`
|
||||
|
||||
</details>
|
||||
|
||||
<!-- /automd -->
|
||||
|
||||
## License
|
||||
|
||||
<!-- automd:contributors license=MIT author="pi0" -->
|
||||
|
||||
Published under the [MIT](https://github.com/unjs/c12/blob/main/LICENSE) license.
|
||||
Made by [@pi0](https://github.com/pi0) and [community](https://github.com/unjs/c12/graphs/contributors) 💛
|
||||
<br><br>
|
||||
<a href="https://github.com/unjs/c12/graphs/contributors">
|
||||
<img src="https://contrib.rocks/image?repo=unjs/c12" />
|
||||
</a>
|
||||
|
||||
<!-- /automd -->
|
||||
|
||||
<!-- automd:with-automd -->
|
||||
|
||||
---
|
||||
|
||||
_🤖 auto updated with [automd](https://automd.unjs.io)_
|
||||
|
||||
<!-- /automd -->
|
||||
170
node_modules/c12/dist/index.d.mts
generated
vendored
Normal file
170
node_modules/c12/dist/index.d.mts
generated
vendored
Normal file
@@ -0,0 +1,170 @@
|
||||
import { Jiti, JitiOptions } from "jiti";
|
||||
import { ChokidarOptions } from "chokidar";
|
||||
import { DownloadTemplateOptions } from "giget";
|
||||
import { diff } from "ohash/utils";
|
||||
|
||||
//#region src/dotenv.d.ts
|
||||
interface DotenvOptions {
|
||||
/**
|
||||
* The project root directory (either absolute or relative to the current working directory).
|
||||
*
|
||||
* Defaults to `options.cwd` in `loadConfig` context, or `process.cwd()` when used as standalone.
|
||||
*/
|
||||
cwd?: string;
|
||||
/**
|
||||
* What file or files to look in for environment variables (either absolute or relative
|
||||
* to the current working directory). For example, `.env`.
|
||||
* With the array type, the order enforce the env loading priority (last one overrides).
|
||||
*/
|
||||
fileName?: string | string[];
|
||||
/**
|
||||
* Whether to interpolate variables within .env.
|
||||
*
|
||||
* @example
|
||||
* ```env
|
||||
* BASE_DIR="/test"
|
||||
* # resolves to "/test/further"
|
||||
* ANOTHER_DIR="${BASE_DIR}/further"
|
||||
* ```
|
||||
*/
|
||||
interpolate?: boolean;
|
||||
/**
|
||||
* An object describing environment variables (key, value pairs).
|
||||
*/
|
||||
env?: NodeJS.ProcessEnv;
|
||||
}
|
||||
type Env = typeof process.env;
|
||||
/**
|
||||
* Load and interpolate environment variables into `process.env`.
|
||||
* If you need more control (or access to the values), consider using `loadDotenv` instead
|
||||
*
|
||||
*/
|
||||
declare function setupDotenv(options: DotenvOptions): Promise<Env>;
|
||||
/** Load environment variables into an object. */
|
||||
declare function loadDotenv(options: DotenvOptions): Promise<Env>;
|
||||
declare global {
|
||||
var __c12_dotenv_vars__: Map<Record<string, any>, Set<string>>;
|
||||
}
|
||||
//#endregion
|
||||
//#region src/types.d.ts
|
||||
interface ConfigLayerMeta {
|
||||
name?: string;
|
||||
[key: string]: any;
|
||||
}
|
||||
type UserInputConfig = Record<string, any>;
|
||||
interface C12InputConfig<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> {
|
||||
$test?: T;
|
||||
$development?: T;
|
||||
$production?: T;
|
||||
$env?: Record<string, T>;
|
||||
$meta?: MT;
|
||||
}
|
||||
type InputConfig<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> = C12InputConfig<T, MT> & T;
|
||||
interface SourceOptions<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> {
|
||||
/** Custom meta for layer */
|
||||
meta?: MT;
|
||||
/** Layer config overrides */
|
||||
overrides?: T;
|
||||
[key: string]: any;
|
||||
/**
|
||||
* Options for cloning remote sources
|
||||
*
|
||||
* @see https://giget.unjs.io
|
||||
*/
|
||||
giget?: DownloadTemplateOptions;
|
||||
/**
|
||||
* Install dependencies after cloning
|
||||
*
|
||||
* @see https://nypm.unjs.io
|
||||
*/
|
||||
install?: boolean;
|
||||
/**
|
||||
* Token for cloning private sources
|
||||
*
|
||||
* @see https://giget.unjs.io#providing-token-for-private-repositories
|
||||
*/
|
||||
auth?: string;
|
||||
}
|
||||
interface ConfigLayer<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> {
|
||||
config: T | null;
|
||||
source?: string;
|
||||
sourceOptions?: SourceOptions<T, MT>;
|
||||
meta?: MT;
|
||||
cwd?: string;
|
||||
configFile?: string;
|
||||
}
|
||||
interface ResolvedConfig<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> extends ConfigLayer<T, MT> {
|
||||
config: T;
|
||||
layers?: ConfigLayer<T, MT>[];
|
||||
cwd?: string;
|
||||
_configFile?: string;
|
||||
}
|
||||
type ConfigSource = "overrides" | "main" | "rc" | "packageJson" | "defaultConfig";
|
||||
interface ConfigFunctionContext {
|
||||
[key: string]: any;
|
||||
}
|
||||
interface ResolvableConfigContext<T extends UserInputConfig = UserInputConfig> {
|
||||
configs: Record<ConfigSource, T | null | undefined>;
|
||||
rawConfigs: Record<ConfigSource, ResolvableConfig<T> | null | undefined>;
|
||||
}
|
||||
type MaybePromise<T> = T | Promise<T>;
|
||||
type ResolvableConfig<T extends UserInputConfig = UserInputConfig> = MaybePromise<T | null | undefined> | ((ctx: ResolvableConfigContext<T>) => MaybePromise<T | null | undefined>);
|
||||
interface LoadConfigOptions<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> {
|
||||
name?: string;
|
||||
cwd?: string;
|
||||
configFile?: string;
|
||||
rcFile?: false | string;
|
||||
globalRc?: boolean;
|
||||
dotenv?: boolean | DotenvOptions;
|
||||
envName?: string | false;
|
||||
packageJson?: boolean | string | string[];
|
||||
defaults?: T;
|
||||
defaultConfig?: ResolvableConfig<T>;
|
||||
overrides?: ResolvableConfig<T>;
|
||||
omit$Keys?: boolean;
|
||||
/** Context passed to config functions */
|
||||
context?: ConfigFunctionContext;
|
||||
resolve?: (id: string, options: LoadConfigOptions<T, MT>) => null | undefined | ResolvedConfig<T, MT> | Promise<ResolvedConfig<T, MT> | undefined | null>;
|
||||
jiti?: Jiti;
|
||||
jitiOptions?: JitiOptions;
|
||||
giget?: false | DownloadTemplateOptions;
|
||||
merger?: (...sources: Array<T | null | undefined>) => T;
|
||||
extend?: false | {
|
||||
extendKey?: string | string[];
|
||||
};
|
||||
configFileRequired?: boolean;
|
||||
}
|
||||
type DefineConfig<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> = (input: InputConfig<T, MT>) => InputConfig<T, MT>;
|
||||
declare function createDefineConfig<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta>(): DefineConfig<T, MT>;
|
||||
//#endregion
|
||||
//#region src/loader.d.ts
|
||||
declare const SUPPORTED_EXTENSIONS: string[];
|
||||
declare function loadConfig<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta>(options: LoadConfigOptions<T, MT>): Promise<ResolvedConfig<T, MT>>;
|
||||
//#endregion
|
||||
//#region src/watch.d.ts
|
||||
type DiffEntries = ReturnType<typeof diff>;
|
||||
type ConfigWatcher<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> = ResolvedConfig<T, MT> & {
|
||||
watchingFiles: string[];
|
||||
unwatch: () => Promise<void>;
|
||||
};
|
||||
interface WatchConfigOptions<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> extends LoadConfigOptions<T, MT> {
|
||||
chokidarOptions?: ChokidarOptions;
|
||||
debounce?: false | number;
|
||||
onWatch?: (event: {
|
||||
type: "created" | "updated" | "removed";
|
||||
path: string;
|
||||
}) => void | Promise<void>;
|
||||
acceptHMR?: (context: {
|
||||
getDiff: () => DiffEntries;
|
||||
newConfig: ResolvedConfig<T, MT>;
|
||||
oldConfig: ResolvedConfig<T, MT>;
|
||||
}) => void | boolean | Promise<void | boolean>;
|
||||
onUpdate?: (context: {
|
||||
getDiff: () => ReturnType<typeof diff>;
|
||||
newConfig: ResolvedConfig<T, MT>;
|
||||
oldConfig: ResolvedConfig<T, MT>;
|
||||
}) => void | Promise<void>;
|
||||
}
|
||||
declare function watchConfig<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta>(options: WatchConfigOptions<T, MT>): Promise<ConfigWatcher<T, MT>>;
|
||||
//#endregion
|
||||
export { C12InputConfig, ConfigFunctionContext, ConfigLayer, ConfigLayerMeta, ConfigSource, ConfigWatcher, DefineConfig, DotenvOptions, Env, InputConfig, LoadConfigOptions, ResolvableConfig, ResolvableConfigContext, ResolvedConfig, SUPPORTED_EXTENSIONS, SourceOptions, UserInputConfig, WatchConfigOptions, createDefineConfig, loadConfig, loadDotenv, setupDotenv, watchConfig };
|
||||
419
node_modules/c12/dist/index.mjs
generated
vendored
Normal file
419
node_modules/c12/dist/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,419 @@
|
||||
import { existsSync, promises, statSync } from "node:fs";
|
||||
import { basename, dirname, extname, join, normalize, resolve } from "pathe";
|
||||
import * as dotenv from "dotenv";
|
||||
import { readFile, rm } from "node:fs/promises";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { homedir } from "node:os";
|
||||
import { resolveModulePath } from "exsolve";
|
||||
import { createJiti } from "jiti";
|
||||
import * as rc9 from "rc9";
|
||||
import { defu } from "defu";
|
||||
import { findWorkspaceDir, readPackageJSON } from "pkg-types";
|
||||
import { debounce } from "perfect-debounce";
|
||||
|
||||
//#region src/dotenv.ts
|
||||
/**
|
||||
* Load and interpolate environment variables into `process.env`.
|
||||
* If you need more control (or access to the values), consider using `loadDotenv` instead
|
||||
*
|
||||
*/
|
||||
async function setupDotenv(options) {
|
||||
const targetEnvironment = options.env ?? process.env;
|
||||
const environment = await loadDotenv({
|
||||
cwd: options.cwd,
|
||||
fileName: options.fileName ?? ".env",
|
||||
env: targetEnvironment,
|
||||
interpolate: options.interpolate ?? true
|
||||
});
|
||||
const dotenvVars = getDotEnvVars(targetEnvironment);
|
||||
for (const key in environment) {
|
||||
if (key.startsWith("_")) continue;
|
||||
if (targetEnvironment[key] === void 0 || dotenvVars.has(key)) targetEnvironment[key] = environment[key];
|
||||
}
|
||||
return environment;
|
||||
}
|
||||
/** Load environment variables into an object. */
|
||||
async function loadDotenv(options) {
|
||||
const environment = Object.create(null);
|
||||
const cwd = resolve(options.cwd || ".");
|
||||
const _fileName = options.fileName || ".env";
|
||||
const dotenvFiles = typeof _fileName === "string" ? [_fileName] : _fileName;
|
||||
const dotenvVars = getDotEnvVars(options.env || {});
|
||||
Object.assign(environment, options.env);
|
||||
for (const file of dotenvFiles) {
|
||||
const dotenvFile = resolve(cwd, file);
|
||||
if (!statSync(dotenvFile, { throwIfNoEntry: false })?.isFile()) continue;
|
||||
const parsed = dotenv.parse(await promises.readFile(dotenvFile, "utf8"));
|
||||
for (const key in parsed) {
|
||||
if (key in environment && !dotenvVars.has(key)) continue;
|
||||
environment[key] = parsed[key];
|
||||
dotenvVars.add(key);
|
||||
}
|
||||
}
|
||||
if (options.interpolate) interpolate(environment);
|
||||
return environment;
|
||||
}
|
||||
function interpolate(target, source = {}, parse = (v) => v) {
|
||||
function getValue(key) {
|
||||
return source[key] === void 0 ? target[key] : source[key];
|
||||
}
|
||||
function interpolate$1(value, parents = []) {
|
||||
if (typeof value !== "string") return value;
|
||||
return parse((value.match(/(.?\${?(?:[\w:]+)?}?)/g) || []).reduce((newValue, match) => {
|
||||
const parts = /(.?)\${?([\w:]+)?}?/g.exec(match) || [];
|
||||
const prefix = parts[1];
|
||||
let value$1, replacePart;
|
||||
if (prefix === "\\") {
|
||||
replacePart = parts[0] || "";
|
||||
value$1 = replacePart.replace(String.raw`\$`, "$");
|
||||
} else {
|
||||
const key = parts[2];
|
||||
replacePart = (parts[0] || "").slice(prefix.length);
|
||||
if (parents.includes(key)) {
|
||||
console.warn(`Please avoid recursive environment variables ( loop: ${parents.join(" > ")} > ${key} )`);
|
||||
return "";
|
||||
}
|
||||
value$1 = getValue(key);
|
||||
value$1 = interpolate$1(value$1, [...parents, key]);
|
||||
}
|
||||
return value$1 === void 0 ? newValue : newValue.replace(replacePart, value$1);
|
||||
}, value));
|
||||
}
|
||||
for (const key in target) target[key] = interpolate$1(getValue(key));
|
||||
}
|
||||
function getDotEnvVars(targetEnvironment) {
|
||||
const globalRegistry = globalThis.__c12_dotenv_vars__ ||= /* @__PURE__ */ new Map();
|
||||
if (!globalRegistry.has(targetEnvironment)) globalRegistry.set(targetEnvironment, /* @__PURE__ */ new Set());
|
||||
return globalRegistry.get(targetEnvironment);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/loader.ts
|
||||
const _normalize = (p) => p?.replace(/\\/g, "/");
|
||||
const ASYNC_LOADERS = {
|
||||
".yaml": () => import("confbox/yaml").then((r) => r.parseYAML),
|
||||
".yml": () => import("confbox/yaml").then((r) => r.parseYAML),
|
||||
".jsonc": () => import("confbox/jsonc").then((r) => r.parseJSONC),
|
||||
".json5": () => import("confbox/json5").then((r) => r.parseJSON5),
|
||||
".toml": () => import("confbox/toml").then((r) => r.parseTOML)
|
||||
};
|
||||
const SUPPORTED_EXTENSIONS = Object.freeze([
|
||||
".js",
|
||||
".ts",
|
||||
".mjs",
|
||||
".cjs",
|
||||
".mts",
|
||||
".cts",
|
||||
".json",
|
||||
".jsonc",
|
||||
".json5",
|
||||
".yaml",
|
||||
".yml",
|
||||
".toml"
|
||||
]);
|
||||
async function loadConfig(options) {
|
||||
options.cwd = resolve(process.cwd(), options.cwd || ".");
|
||||
options.name = options.name || "config";
|
||||
options.envName = options.envName ?? process.env.NODE_ENV;
|
||||
options.configFile = options.configFile ?? (options.name === "config" ? "config" : `${options.name}.config`);
|
||||
options.rcFile = options.rcFile ?? `.${options.name}rc`;
|
||||
if (options.extend !== false) options.extend = {
|
||||
extendKey: "extends",
|
||||
...options.extend
|
||||
};
|
||||
const _merger = options.merger || defu;
|
||||
options.jiti = options.jiti || createJiti(join(options.cwd, options.configFile), {
|
||||
interopDefault: true,
|
||||
moduleCache: false,
|
||||
extensions: [...SUPPORTED_EXTENSIONS],
|
||||
...options.jitiOptions
|
||||
});
|
||||
const r = {
|
||||
config: {},
|
||||
cwd: options.cwd,
|
||||
configFile: resolve(options.cwd, options.configFile),
|
||||
layers: [],
|
||||
_configFile: void 0
|
||||
};
|
||||
const rawConfigs = {
|
||||
overrides: options.overrides,
|
||||
main: void 0,
|
||||
rc: void 0,
|
||||
packageJson: void 0,
|
||||
defaultConfig: options.defaultConfig
|
||||
};
|
||||
if (options.dotenv) await setupDotenv({
|
||||
cwd: options.cwd,
|
||||
...options.dotenv === true ? {} : options.dotenv
|
||||
});
|
||||
const _mainConfig = await resolveConfig(".", options);
|
||||
if (_mainConfig.configFile) {
|
||||
rawConfigs.main = _mainConfig.config;
|
||||
r.configFile = _mainConfig.configFile;
|
||||
r._configFile = _mainConfig._configFile;
|
||||
}
|
||||
if (_mainConfig.meta) r.meta = _mainConfig.meta;
|
||||
if (options.rcFile) {
|
||||
const rcSources = [];
|
||||
rcSources.push(rc9.read({
|
||||
name: options.rcFile,
|
||||
dir: options.cwd
|
||||
}));
|
||||
if (options.globalRc) {
|
||||
const workspaceDir = await findWorkspaceDir(options.cwd).catch(() => {});
|
||||
if (workspaceDir) rcSources.push(rc9.read({
|
||||
name: options.rcFile,
|
||||
dir: workspaceDir
|
||||
}));
|
||||
rcSources.push(rc9.readUser({
|
||||
name: options.rcFile,
|
||||
dir: options.cwd
|
||||
}));
|
||||
}
|
||||
rawConfigs.rc = _merger({}, ...rcSources);
|
||||
}
|
||||
if (options.packageJson) {
|
||||
const keys = (Array.isArray(options.packageJson) ? options.packageJson : [typeof options.packageJson === "string" ? options.packageJson : options.name]).filter((t) => t && typeof t === "string");
|
||||
const pkgJsonFile = await readPackageJSON(options.cwd).catch(() => {});
|
||||
rawConfigs.packageJson = _merger({}, ...keys.map((key) => pkgJsonFile?.[key]));
|
||||
}
|
||||
const configs = {};
|
||||
for (const key in rawConfigs) {
|
||||
const value = rawConfigs[key];
|
||||
configs[key] = await (typeof value === "function" ? value({
|
||||
configs,
|
||||
rawConfigs
|
||||
}) : value);
|
||||
}
|
||||
if (Array.isArray(configs.main)) r.config = configs.main;
|
||||
else {
|
||||
r.config = _merger(configs.overrides, configs.main, configs.rc, configs.packageJson, configs.defaultConfig);
|
||||
if (options.extend) {
|
||||
await extendConfig(r.config, options);
|
||||
r.layers = r.config._layers;
|
||||
delete r.config._layers;
|
||||
r.config = _merger(r.config, ...r.layers.map((e) => e.config));
|
||||
}
|
||||
}
|
||||
r.layers = [...[
|
||||
configs.overrides && {
|
||||
config: configs.overrides,
|
||||
configFile: void 0,
|
||||
cwd: void 0
|
||||
},
|
||||
{
|
||||
config: configs.main,
|
||||
configFile: options.configFile,
|
||||
cwd: options.cwd
|
||||
},
|
||||
configs.rc && {
|
||||
config: configs.rc,
|
||||
configFile: options.rcFile
|
||||
},
|
||||
configs.packageJson && {
|
||||
config: configs.packageJson,
|
||||
configFile: "package.json"
|
||||
}
|
||||
].filter((l) => l && l.config), ...r.layers];
|
||||
if (options.defaults) r.config = _merger(r.config, options.defaults);
|
||||
if (options.omit$Keys) {
|
||||
for (const key in r.config) if (key.startsWith("$")) delete r.config[key];
|
||||
}
|
||||
if (options.configFileRequired && !r._configFile) throw new Error(`Required config (${r.configFile}) cannot be resolved.`);
|
||||
return r;
|
||||
}
|
||||
async function extendConfig(config, options) {
|
||||
config._layers = config._layers || [];
|
||||
if (!options.extend) return;
|
||||
let keys = options.extend.extendKey;
|
||||
if (typeof keys === "string") keys = [keys];
|
||||
const extendSources = [];
|
||||
for (const key of keys) {
|
||||
extendSources.push(...(Array.isArray(config[key]) ? config[key] : [config[key]]).filter(Boolean));
|
||||
delete config[key];
|
||||
}
|
||||
for (let extendSource of extendSources) {
|
||||
const originalExtendSource = extendSource;
|
||||
let sourceOptions = {};
|
||||
if (extendSource.source) {
|
||||
sourceOptions = extendSource.options || {};
|
||||
extendSource = extendSource.source;
|
||||
}
|
||||
if (Array.isArray(extendSource)) {
|
||||
sourceOptions = extendSource[1] || {};
|
||||
extendSource = extendSource[0];
|
||||
}
|
||||
if (typeof extendSource !== "string") {
|
||||
console.warn(`Cannot extend config from \`${JSON.stringify(originalExtendSource)}\` in ${options.cwd}`);
|
||||
continue;
|
||||
}
|
||||
const _config = await resolveConfig(extendSource, options, sourceOptions);
|
||||
if (!_config.config) {
|
||||
console.warn(`Cannot extend config from \`${extendSource}\` in ${options.cwd}`);
|
||||
continue;
|
||||
}
|
||||
await extendConfig(_config.config, {
|
||||
...options,
|
||||
cwd: _config.cwd
|
||||
});
|
||||
config._layers.push(_config);
|
||||
if (_config.config._layers) {
|
||||
config._layers.push(..._config.config._layers);
|
||||
delete _config.config._layers;
|
||||
}
|
||||
}
|
||||
}
|
||||
const GIGET_PREFIXES = [
|
||||
"gh:",
|
||||
"github:",
|
||||
"gitlab:",
|
||||
"bitbucket:",
|
||||
"https://",
|
||||
"http://"
|
||||
];
|
||||
const NPM_PACKAGE_RE = /^(@[\da-z~-][\d._a-z~-]*\/)?[\da-z~-][\d._a-z~-]*($|\/.*)/;
|
||||
async function resolveConfig(source, options, sourceOptions = {}) {
|
||||
if (options.resolve) {
|
||||
const res$1 = await options.resolve(source, options);
|
||||
if (res$1) return res$1;
|
||||
}
|
||||
const _merger = options.merger || defu;
|
||||
const customProviderKeys = Object.keys(sourceOptions.giget?.providers || {}).map((key) => `${key}:`);
|
||||
const gigetPrefixes = customProviderKeys.length > 0 ? [...new Set([...customProviderKeys, ...GIGET_PREFIXES])] : GIGET_PREFIXES;
|
||||
if (options.giget !== false && gigetPrefixes.some((prefix) => source.startsWith(prefix))) {
|
||||
const { downloadTemplate } = await import("giget");
|
||||
const { digest } = await import("ohash");
|
||||
const cloneName = source.replace(/\W+/g, "_").split("_").splice(0, 3).join("_") + "_" + digest(source).slice(0, 10).replace(/[-_]/g, "");
|
||||
let cloneDir;
|
||||
const localNodeModules = resolve(options.cwd, "node_modules");
|
||||
const parentDir = dirname(options.cwd);
|
||||
if (basename(parentDir) === ".c12") cloneDir = join(parentDir, cloneName);
|
||||
else if (existsSync(localNodeModules)) cloneDir = join(localNodeModules, ".c12", cloneName);
|
||||
else cloneDir = process.env.XDG_CACHE_HOME ? resolve(process.env.XDG_CACHE_HOME, "c12", cloneName) : resolve(homedir(), ".cache/c12", cloneName);
|
||||
if (existsSync(cloneDir) && !sourceOptions.install) await rm(cloneDir, { recursive: true });
|
||||
source = (await downloadTemplate(source, {
|
||||
dir: cloneDir,
|
||||
install: sourceOptions.install,
|
||||
force: sourceOptions.install,
|
||||
auth: sourceOptions.auth,
|
||||
...options.giget,
|
||||
...sourceOptions.giget
|
||||
})).dir;
|
||||
}
|
||||
if (NPM_PACKAGE_RE.test(source)) source = tryResolve(source, options) || source;
|
||||
const ext = extname(source);
|
||||
const isDir = !ext || ext === basename(source);
|
||||
const cwd = resolve(options.cwd, isDir ? source : dirname(source));
|
||||
if (isDir) source = options.configFile;
|
||||
const res = {
|
||||
config: void 0,
|
||||
configFile: void 0,
|
||||
cwd,
|
||||
source,
|
||||
sourceOptions
|
||||
};
|
||||
res.configFile = tryResolve(resolve(cwd, source), options) || tryResolve(resolve(cwd, ".config", source.replace(/\.config$/, "")), options) || tryResolve(resolve(cwd, ".config", source), options) || source;
|
||||
if (!existsSync(res.configFile)) return res;
|
||||
res._configFile = res.configFile;
|
||||
const configFileExt = extname(res.configFile) || "";
|
||||
if (configFileExt in ASYNC_LOADERS) res.config = (await ASYNC_LOADERS[configFileExt]())(await readFile(res.configFile, "utf8"));
|
||||
else res.config = await options.jiti.import(res.configFile, { default: true });
|
||||
if (typeof res.config === "function") res.config = await res.config(options.context);
|
||||
if (options.envName) {
|
||||
const envConfig = {
|
||||
...res.config["$" + options.envName],
|
||||
...res.config.$env?.[options.envName]
|
||||
};
|
||||
if (Object.keys(envConfig).length > 0) res.config = _merger(envConfig, res.config);
|
||||
}
|
||||
res.meta = defu(res.sourceOptions.meta, res.config.$meta);
|
||||
delete res.config.$meta;
|
||||
if (res.sourceOptions.overrides) res.config = _merger(res.sourceOptions.overrides, res.config);
|
||||
res.configFile = _normalize(res.configFile);
|
||||
res.source = _normalize(res.source);
|
||||
return res;
|
||||
}
|
||||
function tryResolve(id, options) {
|
||||
const res = resolveModulePath(id, {
|
||||
try: true,
|
||||
from: pathToFileURL(join(options.cwd || ".", options.configFile || "/")),
|
||||
suffixes: ["", "/index"],
|
||||
extensions: SUPPORTED_EXTENSIONS,
|
||||
cache: false
|
||||
});
|
||||
return res ? normalize(res) : void 0;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/types.ts
|
||||
function createDefineConfig() {
|
||||
return (input) => input;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/watch.ts
|
||||
const eventMap = {
|
||||
add: "created",
|
||||
change: "updated",
|
||||
unlink: "removed"
|
||||
};
|
||||
async function watchConfig(options) {
|
||||
let config = await loadConfig(options);
|
||||
const configName = options.name || "config";
|
||||
const configFileName = options.configFile ?? (options.name === "config" ? "config" : `${options.name}.config`);
|
||||
const watchingFiles = [...new Set((config.layers || []).filter((l) => l.cwd).flatMap((l) => [
|
||||
...SUPPORTED_EXTENSIONS.flatMap((ext) => [
|
||||
resolve(l.cwd, configFileName + ext),
|
||||
resolve(l.cwd, ".config", configFileName + ext),
|
||||
resolve(l.cwd, ".config", configFileName.replace(/\.config$/, "") + ext)
|
||||
]),
|
||||
l.source && resolve(l.cwd, l.source),
|
||||
options.rcFile && resolve(l.cwd, typeof options.rcFile === "string" ? options.rcFile : `.${configName}rc`),
|
||||
options.packageJson && resolve(l.cwd, "package.json")
|
||||
]).filter(Boolean))];
|
||||
const watch = await import("chokidar").then((r) => r.watch || r.default || r);
|
||||
const { diff } = await import("ohash/utils");
|
||||
const _fswatcher = watch(watchingFiles, {
|
||||
ignoreInitial: true,
|
||||
...options.chokidarOptions
|
||||
});
|
||||
const onChange = async (event, path) => {
|
||||
const type = eventMap[event];
|
||||
if (!type) return;
|
||||
if (options.onWatch) await options.onWatch({
|
||||
type,
|
||||
path
|
||||
});
|
||||
const oldConfig = config;
|
||||
try {
|
||||
config = await loadConfig(options);
|
||||
} catch (error) {
|
||||
console.warn(`Failed to load config ${path}\n${error}`);
|
||||
return;
|
||||
}
|
||||
const changeCtx = {
|
||||
newConfig: config,
|
||||
oldConfig,
|
||||
getDiff: () => diff(oldConfig.config, config.config)
|
||||
};
|
||||
if (options.acceptHMR) {
|
||||
if (await options.acceptHMR(changeCtx)) return;
|
||||
}
|
||||
if (options.onUpdate) await options.onUpdate(changeCtx);
|
||||
};
|
||||
if (options.debounce === false) _fswatcher.on("all", onChange);
|
||||
else _fswatcher.on("all", debounce(onChange, options.debounce ?? 100));
|
||||
const utils = {
|
||||
watchingFiles,
|
||||
unwatch: async () => {
|
||||
await _fswatcher.close();
|
||||
}
|
||||
};
|
||||
return new Proxy(utils, { get(_, prop) {
|
||||
if (prop in utils) return utils[prop];
|
||||
return config[prop];
|
||||
} });
|
||||
}
|
||||
|
||||
//#endregion
|
||||
export { SUPPORTED_EXTENSIONS, createDefineConfig, loadConfig, loadDotenv, setupDotenv, watchConfig };
|
||||
53
node_modules/c12/dist/update.d.mts
generated
vendored
Normal file
53
node_modules/c12/dist/update.d.mts
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
import * as magicast0 from "magicast";
|
||||
|
||||
//#region src/update.d.ts
|
||||
/**
|
||||
* @experimental Update a config file or create a new one.
|
||||
*/
|
||||
declare function updateConfig(opts: UpdateConfigOptions): Promise<UpdateConfigResult>;
|
||||
interface UpdateConfigResult {
|
||||
configFile?: string;
|
||||
created?: boolean;
|
||||
}
|
||||
type MaybePromise<T> = T | Promise<T>;
|
||||
type MagicAstOptions = Exclude<Parameters<(typeof magicast0)["parseModule"]>[1], undefined>;
|
||||
interface UpdateConfigOptions {
|
||||
/**
|
||||
* Current working directory
|
||||
*/
|
||||
cwd: string;
|
||||
/**
|
||||
* Config file name
|
||||
*/
|
||||
configFile: string;
|
||||
/**
|
||||
* Extension used for new config file.
|
||||
*/
|
||||
createExtension?: string;
|
||||
/**
|
||||
* Magicast options
|
||||
*/
|
||||
magicast?: MagicAstOptions;
|
||||
/**
|
||||
* Update function.
|
||||
*/
|
||||
onUpdate?: (config: any) => MaybePromise<void>;
|
||||
/**
|
||||
* Handle default config creation.
|
||||
*
|
||||
* Tip: you can use this option as a hook to prompt users about config creation.
|
||||
*
|
||||
* Context object:
|
||||
* - path: determined full path to the config file
|
||||
*
|
||||
* Returns types:
|
||||
* - string: custom config template
|
||||
* - true: write the template
|
||||
* - false: abort the operation
|
||||
*/
|
||||
onCreate?: (ctx: {
|
||||
configFile: string;
|
||||
}) => MaybePromise<string | boolean>;
|
||||
}
|
||||
//#endregion
|
||||
export { UpdateConfigOptions, UpdateConfigResult, updateConfig };
|
||||
80
node_modules/c12/dist/update.mjs
generated
vendored
Normal file
80
node_modules/c12/dist/update.mjs
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
import { resolveModulePath } from "exsolve";
|
||||
import "node:fs";
|
||||
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
||||
import "node:url";
|
||||
import "node:os";
|
||||
import { join, normalize } from "pathe";
|
||||
import "jiti";
|
||||
import "rc9";
|
||||
import "defu";
|
||||
import "pkg-types";
|
||||
import { dirname, extname } from "node:path";
|
||||
|
||||
//#region src/loader.ts
|
||||
const SUPPORTED_EXTENSIONS = Object.freeze([
|
||||
".js",
|
||||
".ts",
|
||||
".mjs",
|
||||
".cjs",
|
||||
".mts",
|
||||
".cts",
|
||||
".json",
|
||||
".jsonc",
|
||||
".json5",
|
||||
".yaml",
|
||||
".yml",
|
||||
".toml"
|
||||
]);
|
||||
|
||||
//#endregion
|
||||
//#region src/update.ts
|
||||
const UPDATABLE_EXTS = [
|
||||
".js",
|
||||
".ts",
|
||||
".mjs",
|
||||
".cjs",
|
||||
".mts",
|
||||
".cts"
|
||||
];
|
||||
/**
|
||||
* @experimental Update a config file or create a new one.
|
||||
*/
|
||||
async function updateConfig(opts) {
|
||||
const { parseModule } = await import("magicast");
|
||||
let configFile = tryResolve(`./${opts.configFile}`, opts.cwd, SUPPORTED_EXTENSIONS) || tryResolve(`./.config/${opts.configFile}`, opts.cwd, SUPPORTED_EXTENSIONS) || tryResolve(`./.config/${opts.configFile.split(".")[0]}`, opts.cwd, SUPPORTED_EXTENSIONS);
|
||||
let created = false;
|
||||
if (!configFile) {
|
||||
configFile = join(opts.cwd, opts.configFile + (opts.createExtension || ".ts"));
|
||||
const createResult = await opts.onCreate?.({ configFile }) ?? true;
|
||||
if (!createResult) throw new Error("Config file creation aborted.");
|
||||
const content = typeof createResult === "string" ? createResult : `export default {}\n`;
|
||||
await mkdir(dirname(configFile), { recursive: true });
|
||||
await writeFile(configFile, content, "utf8");
|
||||
created = true;
|
||||
}
|
||||
const ext = extname(configFile);
|
||||
if (!UPDATABLE_EXTS.includes(ext)) throw new Error(`Unsupported config file extension: ${ext} (${configFile}) (supported: ${UPDATABLE_EXTS.join(", ")})`);
|
||||
const _module = parseModule(await readFile(configFile, "utf8"), opts.magicast);
|
||||
const defaultExport = _module.exports.default;
|
||||
if (!defaultExport) throw new Error("Default export is missing in the config file!");
|
||||
const configObj = defaultExport.$type === "function-call" ? defaultExport.$args[0] : defaultExport;
|
||||
await opts.onUpdate?.(configObj);
|
||||
await writeFile(configFile, _module.generate().code);
|
||||
return {
|
||||
configFile,
|
||||
created
|
||||
};
|
||||
}
|
||||
function tryResolve(path, cwd, extensions) {
|
||||
const res = resolveModulePath(path, {
|
||||
try: true,
|
||||
from: join(cwd, "/"),
|
||||
extensions,
|
||||
suffixes: ["", "/index"],
|
||||
cache: false
|
||||
});
|
||||
return res ? normalize(res) : void 0;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
export { updateConfig };
|
||||
70
node_modules/c12/node_modules/pathe/LICENSE
generated
vendored
Normal file
70
node_modules/c12/node_modules/pathe/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Pooya Parsa <pooya@pi0.io> - Daniel Roe <daniel@roe.dev>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
---
|
||||
|
||||
Copyright Joyent, Inc. and other Node contributors.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to permit
|
||||
persons to whom the Software is furnished to do so, subject to the
|
||||
following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
||||
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||
USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
---
|
||||
|
||||
Bundled zeptomatch (https://github.com/fabiospampinato/zeptomatch)
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2023-present Fabio Spampinato
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
73
node_modules/c12/node_modules/pathe/README.md
generated
vendored
Normal file
73
node_modules/c12/node_modules/pathe/README.md
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
# 🛣️ pathe
|
||||
|
||||
> Universal filesystem path utils
|
||||
|
||||
[![version][npm-v-src]][npm-v-href]
|
||||
[![downloads][npm-d-src]][npm-d-href]
|
||||
[![size][size-src]][size-href]
|
||||
|
||||
## ❓ Why
|
||||
|
||||
For [historical reasons](https://docs.microsoft.com/en-us/archive/blogs/larryosterman/why-is-the-dos-path-character), windows followed MS-DOS and used backslash for separating paths rather than slash used for macOS, Linux, and other Posix operating systems. Nowadays, [Windows](https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file?redirectedfrom=MSDN) supports both Slash and Backslash for paths. [Node.js's built-in `path` module](https://nodejs.org/api/path.html) in the default operation of the path module varies based on the operating system on which a Node.js application is running. Specifically, when running on a Windows operating system, the path module will assume that Windows-style paths are being used. **This makes inconsistent code behavior between Windows and POSIX.**
|
||||
|
||||
Compared to popular [upath](https://github.com/anodynos/upath), pathe provides **identical exports** of Node.js with normalization on **all operations** and is written in modern **ESM/TypeScript** and has **no dependency on Node.js**!
|
||||
|
||||
This package is a drop-in replacement of the Node.js's [path module](https://nodejs.org/api/path.html) module and ensures paths are normalized with slash `/` and work in environments including Node.js.
|
||||
|
||||
## 💿 Usage
|
||||
|
||||
Install using npm or yarn:
|
||||
|
||||
```bash
|
||||
# npm
|
||||
npm i pathe
|
||||
|
||||
# yarn
|
||||
yarn add pathe
|
||||
|
||||
# pnpm
|
||||
pnpm i pathe
|
||||
```
|
||||
|
||||
Import:
|
||||
|
||||
```js
|
||||
// ESM / Typescript
|
||||
import { resolve, matchesGlob } from "pathe";
|
||||
|
||||
// CommonJS
|
||||
const { resolve, matchesGlob } = require("pathe");
|
||||
```
|
||||
|
||||
Read more about path utils from [Node.js documentation](https://nodejs.org/api/path.html) and rest assured behavior is consistently like POSIX regardless of your input paths format and running platform (the only exception is `delimiter` constant export, it will be set to `;` on windows platform).
|
||||
|
||||
### Extra utilities
|
||||
|
||||
Pathe exports some extra utilities that do not exist in standard Node.js [path module](https://nodejs.org/api/path.html).
|
||||
In order to use them, you can import from `pathe/utils` subpath:
|
||||
|
||||
```js
|
||||
import {
|
||||
filename,
|
||||
normalizeAliases,
|
||||
resolveAlias,
|
||||
reverseResolveAlias,
|
||||
} from "pathe/utils";
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
Made with 💛 Published under the [MIT](./LICENSE) license.
|
||||
|
||||
Some code was used from the Node.js project. Glob supported is powered by [zeptomatch](https://github.com/fabiospampinato/zeptomatch).
|
||||
|
||||
<!-- Refs -->
|
||||
|
||||
[npm-v-src]: https://img.shields.io/npm/v/pathe?style=flat-square
|
||||
[npm-v-href]: https://npmjs.com/package/pathe
|
||||
[npm-d-src]: https://img.shields.io/npm/dm/pathe?style=flat-square
|
||||
[npm-d-href]: https://npmjs.com/package/pathe
|
||||
[github-actions-src]: https://img.shields.io/github/workflow/status/unjs/pathe/ci/main?style=flat-square
|
||||
[github-actions-href]: https://github.com/unjs/pathe/actions?query=workflow%3Aci
|
||||
[size-src]: https://packagephobia.now.sh/badge?p=pathe
|
||||
[size-href]: https://packagephobia.now.sh/result?p=pathe
|
||||
39
node_modules/c12/node_modules/pathe/dist/index.cjs
generated
vendored
Normal file
39
node_modules/c12/node_modules/pathe/dist/index.cjs
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
const _path = require('./shared/pathe.BSlhyZSM.cjs');
|
||||
|
||||
const delimiter = /* @__PURE__ */ (() => globalThis.process?.platform === "win32" ? ";" : ":")();
|
||||
const _platforms = { posix: void 0, win32: void 0 };
|
||||
const mix = (del = delimiter) => {
|
||||
return new Proxy(_path._path, {
|
||||
get(_, prop) {
|
||||
if (prop === "delimiter") return del;
|
||||
if (prop === "posix") return posix;
|
||||
if (prop === "win32") return win32;
|
||||
return _platforms[prop] || _path._path[prop];
|
||||
}
|
||||
});
|
||||
};
|
||||
const posix = /* @__PURE__ */ mix(":");
|
||||
const win32 = /* @__PURE__ */ mix(";");
|
||||
|
||||
exports.basename = _path.basename;
|
||||
exports.dirname = _path.dirname;
|
||||
exports.extname = _path.extname;
|
||||
exports.format = _path.format;
|
||||
exports.isAbsolute = _path.isAbsolute;
|
||||
exports.join = _path.join;
|
||||
exports.matchesGlob = _path.matchesGlob;
|
||||
exports.normalize = _path.normalize;
|
||||
exports.normalizeString = _path.normalizeString;
|
||||
exports.parse = _path.parse;
|
||||
exports.relative = _path.relative;
|
||||
exports.resolve = _path.resolve;
|
||||
exports.sep = _path.sep;
|
||||
exports.toNamespacedPath = _path.toNamespacedPath;
|
||||
exports.default = posix;
|
||||
exports.delimiter = delimiter;
|
||||
exports.posix = posix;
|
||||
exports.win32 = win32;
|
||||
47
node_modules/c12/node_modules/pathe/dist/index.d.cts
generated
vendored
Normal file
47
node_modules/c12/node_modules/pathe/dist/index.d.cts
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
import * as path from 'node:path';
|
||||
import path__default from 'node:path';
|
||||
|
||||
/**
|
||||
* Constant for path separator.
|
||||
*
|
||||
* Always equals to `"/"`.
|
||||
*/
|
||||
declare const sep = "/";
|
||||
declare const normalize: typeof path__default.normalize;
|
||||
declare const join: typeof path__default.join;
|
||||
declare const resolve: typeof path__default.resolve;
|
||||
/**
|
||||
* Resolves a string path, resolving '.' and '.' segments and allowing paths above the root.
|
||||
*
|
||||
* @param path - The path to normalise.
|
||||
* @param allowAboveRoot - Whether to allow the resulting path to be above the root directory.
|
||||
* @returns the normalised path string.
|
||||
*/
|
||||
declare function normalizeString(path: string, allowAboveRoot: boolean): string;
|
||||
declare const isAbsolute: typeof path__default.isAbsolute;
|
||||
declare const toNamespacedPath: typeof path__default.toNamespacedPath;
|
||||
declare const extname: typeof path__default.extname;
|
||||
declare const relative: typeof path__default.relative;
|
||||
declare const dirname: typeof path__default.dirname;
|
||||
declare const format: typeof path__default.format;
|
||||
declare const basename: typeof path__default.basename;
|
||||
declare const parse: typeof path__default.parse;
|
||||
/**
|
||||
* The `path.matchesGlob()` method determines if `path` matches the `pattern`.
|
||||
* @param path The path to glob-match against.
|
||||
* @param pattern The glob to check the path against.
|
||||
*/
|
||||
declare const matchesGlob: (path: string, pattern: string | string[]) => boolean;
|
||||
|
||||
type NodePath = typeof path;
|
||||
/**
|
||||
* The platform-specific file delimiter.
|
||||
*
|
||||
* Equals to `";"` in windows and `":"` in all other platforms.
|
||||
*/
|
||||
declare const delimiter: ";" | ":";
|
||||
declare const posix: NodePath["posix"];
|
||||
declare const win32: NodePath["win32"];
|
||||
declare const _default: NodePath;
|
||||
|
||||
export { basename, _default as default, delimiter, dirname, extname, format, isAbsolute, join, matchesGlob, normalize, normalizeString, parse, posix, relative, resolve, sep, toNamespacedPath, win32 };
|
||||
47
node_modules/c12/node_modules/pathe/dist/index.d.mts
generated
vendored
Normal file
47
node_modules/c12/node_modules/pathe/dist/index.d.mts
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
import * as path from 'node:path';
|
||||
import path__default from 'node:path';
|
||||
|
||||
/**
|
||||
* Constant for path separator.
|
||||
*
|
||||
* Always equals to `"/"`.
|
||||
*/
|
||||
declare const sep = "/";
|
||||
declare const normalize: typeof path__default.normalize;
|
||||
declare const join: typeof path__default.join;
|
||||
declare const resolve: typeof path__default.resolve;
|
||||
/**
|
||||
* Resolves a string path, resolving '.' and '.' segments and allowing paths above the root.
|
||||
*
|
||||
* @param path - The path to normalise.
|
||||
* @param allowAboveRoot - Whether to allow the resulting path to be above the root directory.
|
||||
* @returns the normalised path string.
|
||||
*/
|
||||
declare function normalizeString(path: string, allowAboveRoot: boolean): string;
|
||||
declare const isAbsolute: typeof path__default.isAbsolute;
|
||||
declare const toNamespacedPath: typeof path__default.toNamespacedPath;
|
||||
declare const extname: typeof path__default.extname;
|
||||
declare const relative: typeof path__default.relative;
|
||||
declare const dirname: typeof path__default.dirname;
|
||||
declare const format: typeof path__default.format;
|
||||
declare const basename: typeof path__default.basename;
|
||||
declare const parse: typeof path__default.parse;
|
||||
/**
|
||||
* The `path.matchesGlob()` method determines if `path` matches the `pattern`.
|
||||
* @param path The path to glob-match against.
|
||||
* @param pattern The glob to check the path against.
|
||||
*/
|
||||
declare const matchesGlob: (path: string, pattern: string | string[]) => boolean;
|
||||
|
||||
type NodePath = typeof path;
|
||||
/**
|
||||
* The platform-specific file delimiter.
|
||||
*
|
||||
* Equals to `";"` in windows and `":"` in all other platforms.
|
||||
*/
|
||||
declare const delimiter: ";" | ":";
|
||||
declare const posix: NodePath["posix"];
|
||||
declare const win32: NodePath["win32"];
|
||||
declare const _default: NodePath;
|
||||
|
||||
export { basename, _default as default, delimiter, dirname, extname, format, isAbsolute, join, matchesGlob, normalize, normalizeString, parse, posix, relative, resolve, sep, toNamespacedPath, win32 };
|
||||
47
node_modules/c12/node_modules/pathe/dist/index.d.ts
generated
vendored
Normal file
47
node_modules/c12/node_modules/pathe/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
import * as path from 'node:path';
|
||||
import path__default from 'node:path';
|
||||
|
||||
/**
|
||||
* Constant for path separator.
|
||||
*
|
||||
* Always equals to `"/"`.
|
||||
*/
|
||||
declare const sep = "/";
|
||||
declare const normalize: typeof path__default.normalize;
|
||||
declare const join: typeof path__default.join;
|
||||
declare const resolve: typeof path__default.resolve;
|
||||
/**
|
||||
* Resolves a string path, resolving '.' and '.' segments and allowing paths above the root.
|
||||
*
|
||||
* @param path - The path to normalise.
|
||||
* @param allowAboveRoot - Whether to allow the resulting path to be above the root directory.
|
||||
* @returns the normalised path string.
|
||||
*/
|
||||
declare function normalizeString(path: string, allowAboveRoot: boolean): string;
|
||||
declare const isAbsolute: typeof path__default.isAbsolute;
|
||||
declare const toNamespacedPath: typeof path__default.toNamespacedPath;
|
||||
declare const extname: typeof path__default.extname;
|
||||
declare const relative: typeof path__default.relative;
|
||||
declare const dirname: typeof path__default.dirname;
|
||||
declare const format: typeof path__default.format;
|
||||
declare const basename: typeof path__default.basename;
|
||||
declare const parse: typeof path__default.parse;
|
||||
/**
|
||||
* The `path.matchesGlob()` method determines if `path` matches the `pattern`.
|
||||
* @param path The path to glob-match against.
|
||||
* @param pattern The glob to check the path against.
|
||||
*/
|
||||
declare const matchesGlob: (path: string, pattern: string | string[]) => boolean;
|
||||
|
||||
type NodePath = typeof path;
|
||||
/**
|
||||
* The platform-specific file delimiter.
|
||||
*
|
||||
* Equals to `";"` in windows and `":"` in all other platforms.
|
||||
*/
|
||||
declare const delimiter: ";" | ":";
|
||||
declare const posix: NodePath["posix"];
|
||||
declare const win32: NodePath["win32"];
|
||||
declare const _default: NodePath;
|
||||
|
||||
export { basename, _default as default, delimiter, dirname, extname, format, isAbsolute, join, matchesGlob, normalize, normalizeString, parse, posix, relative, resolve, sep, toNamespacedPath, win32 };
|
||||
19
node_modules/c12/node_modules/pathe/dist/index.mjs
generated
vendored
Normal file
19
node_modules/c12/node_modules/pathe/dist/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
import { _ as _path } from './shared/pathe.M-eThtNZ.mjs';
|
||||
export { c as basename, d as dirname, e as extname, f as format, i as isAbsolute, j as join, m as matchesGlob, n as normalize, a as normalizeString, p as parse, b as relative, r as resolve, s as sep, t as toNamespacedPath } from './shared/pathe.M-eThtNZ.mjs';
|
||||
|
||||
const delimiter = /* @__PURE__ */ (() => globalThis.process?.platform === "win32" ? ";" : ":")();
|
||||
const _platforms = { posix: void 0, win32: void 0 };
|
||||
const mix = (del = delimiter) => {
|
||||
return new Proxy(_path, {
|
||||
get(_, prop) {
|
||||
if (prop === "delimiter") return del;
|
||||
if (prop === "posix") return posix;
|
||||
if (prop === "win32") return win32;
|
||||
return _platforms[prop] || _path[prop];
|
||||
}
|
||||
});
|
||||
};
|
||||
const posix = /* @__PURE__ */ mix(":");
|
||||
const win32 = /* @__PURE__ */ mix(";");
|
||||
|
||||
export { posix as default, delimiter, posix, win32 };
|
||||
266
node_modules/c12/node_modules/pathe/dist/shared/pathe.BSlhyZSM.cjs
generated
vendored
Normal file
266
node_modules/c12/node_modules/pathe/dist/shared/pathe.BSlhyZSM.cjs
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
249
node_modules/c12/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
generated
vendored
Normal file
249
node_modules/c12/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
82
node_modules/c12/node_modules/pathe/dist/utils.cjs
generated
vendored
Normal file
82
node_modules/c12/node_modules/pathe/dist/utils.cjs
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
'use strict';
|
||||
|
||||
const _path = require('./shared/pathe.BSlhyZSM.cjs');
|
||||
|
||||
const pathSeparators = /* @__PURE__ */ new Set(["/", "\\", void 0]);
|
||||
const normalizedAliasSymbol = Symbol.for("pathe:normalizedAlias");
|
||||
const SLASH_RE = /[/\\]/;
|
||||
function normalizeAliases(_aliases) {
|
||||
if (_aliases[normalizedAliasSymbol]) {
|
||||
return _aliases;
|
||||
}
|
||||
const aliases = Object.fromEntries(
|
||||
Object.entries(_aliases).sort(([a], [b]) => _compareAliases(a, b))
|
||||
);
|
||||
for (const key in aliases) {
|
||||
for (const alias in aliases) {
|
||||
if (alias === key || key.startsWith(alias)) {
|
||||
continue;
|
||||
}
|
||||
if (aliases[key]?.startsWith(alias) && pathSeparators.has(aliases[key][alias.length])) {
|
||||
aliases[key] = aliases[alias] + aliases[key].slice(alias.length);
|
||||
}
|
||||
}
|
||||
}
|
||||
Object.defineProperty(aliases, normalizedAliasSymbol, {
|
||||
value: true,
|
||||
enumerable: false
|
||||
});
|
||||
return aliases;
|
||||
}
|
||||
function resolveAlias(path, aliases) {
|
||||
const _path$1 = _path.normalizeWindowsPath(path);
|
||||
aliases = normalizeAliases(aliases);
|
||||
for (const [alias, to] of Object.entries(aliases)) {
|
||||
if (!_path$1.startsWith(alias)) {
|
||||
continue;
|
||||
}
|
||||
const _alias = hasTrailingSlash(alias) ? alias.slice(0, -1) : alias;
|
||||
if (hasTrailingSlash(_path$1[_alias.length])) {
|
||||
return _path.join(to, _path$1.slice(alias.length));
|
||||
}
|
||||
}
|
||||
return _path$1;
|
||||
}
|
||||
function reverseResolveAlias(path, aliases) {
|
||||
const _path$1 = _path.normalizeWindowsPath(path);
|
||||
aliases = normalizeAliases(aliases);
|
||||
const matches = [];
|
||||
for (const [to, alias] of Object.entries(aliases)) {
|
||||
if (!_path$1.startsWith(alias)) {
|
||||
continue;
|
||||
}
|
||||
const _alias = hasTrailingSlash(alias) ? alias.slice(0, -1) : alias;
|
||||
if (hasTrailingSlash(_path$1[_alias.length])) {
|
||||
matches.push(_path.join(to, _path$1.slice(alias.length)));
|
||||
}
|
||||
}
|
||||
return matches.sort((a, b) => b.length - a.length);
|
||||
}
|
||||
function filename(path) {
|
||||
const base = path.split(SLASH_RE).pop();
|
||||
if (!base) {
|
||||
return void 0;
|
||||
}
|
||||
const separatorIndex = base.lastIndexOf(".");
|
||||
if (separatorIndex <= 0) {
|
||||
return base;
|
||||
}
|
||||
return base.slice(0, separatorIndex);
|
||||
}
|
||||
function _compareAliases(a, b) {
|
||||
return b.split("/").length - a.split("/").length;
|
||||
}
|
||||
function hasTrailingSlash(path = "/") {
|
||||
const lastChar = path[path.length - 1];
|
||||
return lastChar === "/" || lastChar === "\\";
|
||||
}
|
||||
|
||||
exports.filename = filename;
|
||||
exports.normalizeAliases = normalizeAliases;
|
||||
exports.resolveAlias = resolveAlias;
|
||||
exports.reverseResolveAlias = reverseResolveAlias;
|
||||
32
node_modules/c12/node_modules/pathe/dist/utils.d.cts
generated
vendored
Normal file
32
node_modules/c12/node_modules/pathe/dist/utils.d.cts
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Normalises alias mappings, ensuring that more specific aliases are resolved before less specific ones.
|
||||
* This function also ensures that aliases do not resolve to themselves cyclically.
|
||||
*
|
||||
* @param _aliases - A set of alias mappings where each key is an alias and its value is the actual path it points to.
|
||||
* @returns a set of normalised alias mappings.
|
||||
*/
|
||||
declare function normalizeAliases(_aliases: Record<string, string>): Record<string, string>;
|
||||
/**
|
||||
* Resolves a path string to its alias if applicable, otherwise returns the original path.
|
||||
* This function normalises the path, resolves the alias and then joins it to the alias target if necessary.
|
||||
*
|
||||
* @param path - The path string to resolve.
|
||||
* @param aliases - A set of alias mappings to use for resolution.
|
||||
* @returns the resolved path as a string.
|
||||
*/
|
||||
declare function resolveAlias(path: string, aliases: Record<string, string>): string;
|
||||
/**
|
||||
* Resolves a path string to its possible alias.
|
||||
*
|
||||
* Returns an array of possible alias resolutions (could be empty), sorted by specificity (longest first).
|
||||
*/
|
||||
declare function reverseResolveAlias(path: string, aliases: Record<string, string>): string[];
|
||||
/**
|
||||
* Extracts the filename from a given path, excluding any directory paths and the file extension.
|
||||
*
|
||||
* @param path - The full path of the file from which to extract the filename.
|
||||
* @returns the filename without the extension, or `undefined` if the filename cannot be extracted.
|
||||
*/
|
||||
declare function filename(path: string): string | undefined;
|
||||
|
||||
export { filename, normalizeAliases, resolveAlias, reverseResolveAlias };
|
||||
32
node_modules/c12/node_modules/pathe/dist/utils.d.mts
generated
vendored
Normal file
32
node_modules/c12/node_modules/pathe/dist/utils.d.mts
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Normalises alias mappings, ensuring that more specific aliases are resolved before less specific ones.
|
||||
* This function also ensures that aliases do not resolve to themselves cyclically.
|
||||
*
|
||||
* @param _aliases - A set of alias mappings where each key is an alias and its value is the actual path it points to.
|
||||
* @returns a set of normalised alias mappings.
|
||||
*/
|
||||
declare function normalizeAliases(_aliases: Record<string, string>): Record<string, string>;
|
||||
/**
|
||||
* Resolves a path string to its alias if applicable, otherwise returns the original path.
|
||||
* This function normalises the path, resolves the alias and then joins it to the alias target if necessary.
|
||||
*
|
||||
* @param path - The path string to resolve.
|
||||
* @param aliases - A set of alias mappings to use for resolution.
|
||||
* @returns the resolved path as a string.
|
||||
*/
|
||||
declare function resolveAlias(path: string, aliases: Record<string, string>): string;
|
||||
/**
|
||||
* Resolves a path string to its possible alias.
|
||||
*
|
||||
* Returns an array of possible alias resolutions (could be empty), sorted by specificity (longest first).
|
||||
*/
|
||||
declare function reverseResolveAlias(path: string, aliases: Record<string, string>): string[];
|
||||
/**
|
||||
* Extracts the filename from a given path, excluding any directory paths and the file extension.
|
||||
*
|
||||
* @param path - The full path of the file from which to extract the filename.
|
||||
* @returns the filename without the extension, or `undefined` if the filename cannot be extracted.
|
||||
*/
|
||||
declare function filename(path: string): string | undefined;
|
||||
|
||||
export { filename, normalizeAliases, resolveAlias, reverseResolveAlias };
|
||||
32
node_modules/c12/node_modules/pathe/dist/utils.d.ts
generated
vendored
Normal file
32
node_modules/c12/node_modules/pathe/dist/utils.d.ts
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Normalises alias mappings, ensuring that more specific aliases are resolved before less specific ones.
|
||||
* This function also ensures that aliases do not resolve to themselves cyclically.
|
||||
*
|
||||
* @param _aliases - A set of alias mappings where each key is an alias and its value is the actual path it points to.
|
||||
* @returns a set of normalised alias mappings.
|
||||
*/
|
||||
declare function normalizeAliases(_aliases: Record<string, string>): Record<string, string>;
|
||||
/**
|
||||
* Resolves a path string to its alias if applicable, otherwise returns the original path.
|
||||
* This function normalises the path, resolves the alias and then joins it to the alias target if necessary.
|
||||
*
|
||||
* @param path - The path string to resolve.
|
||||
* @param aliases - A set of alias mappings to use for resolution.
|
||||
* @returns the resolved path as a string.
|
||||
*/
|
||||
declare function resolveAlias(path: string, aliases: Record<string, string>): string;
|
||||
/**
|
||||
* Resolves a path string to its possible alias.
|
||||
*
|
||||
* Returns an array of possible alias resolutions (could be empty), sorted by specificity (longest first).
|
||||
*/
|
||||
declare function reverseResolveAlias(path: string, aliases: Record<string, string>): string[];
|
||||
/**
|
||||
* Extracts the filename from a given path, excluding any directory paths and the file extension.
|
||||
*
|
||||
* @param path - The full path of the file from which to extract the filename.
|
||||
* @returns the filename without the extension, or `undefined` if the filename cannot be extracted.
|
||||
*/
|
||||
declare function filename(path: string): string | undefined;
|
||||
|
||||
export { filename, normalizeAliases, resolveAlias, reverseResolveAlias };
|
||||
77
node_modules/c12/node_modules/pathe/dist/utils.mjs
generated
vendored
Normal file
77
node_modules/c12/node_modules/pathe/dist/utils.mjs
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
import { g as normalizeWindowsPath, j as join } from './shared/pathe.M-eThtNZ.mjs';
|
||||
|
||||
const pathSeparators = /* @__PURE__ */ new Set(["/", "\\", void 0]);
|
||||
const normalizedAliasSymbol = Symbol.for("pathe:normalizedAlias");
|
||||
const SLASH_RE = /[/\\]/;
|
||||
function normalizeAliases(_aliases) {
|
||||
if (_aliases[normalizedAliasSymbol]) {
|
||||
return _aliases;
|
||||
}
|
||||
const aliases = Object.fromEntries(
|
||||
Object.entries(_aliases).sort(([a], [b]) => _compareAliases(a, b))
|
||||
);
|
||||
for (const key in aliases) {
|
||||
for (const alias in aliases) {
|
||||
if (alias === key || key.startsWith(alias)) {
|
||||
continue;
|
||||
}
|
||||
if (aliases[key]?.startsWith(alias) && pathSeparators.has(aliases[key][alias.length])) {
|
||||
aliases[key] = aliases[alias] + aliases[key].slice(alias.length);
|
||||
}
|
||||
}
|
||||
}
|
||||
Object.defineProperty(aliases, normalizedAliasSymbol, {
|
||||
value: true,
|
||||
enumerable: false
|
||||
});
|
||||
return aliases;
|
||||
}
|
||||
function resolveAlias(path, aliases) {
|
||||
const _path = normalizeWindowsPath(path);
|
||||
aliases = normalizeAliases(aliases);
|
||||
for (const [alias, to] of Object.entries(aliases)) {
|
||||
if (!_path.startsWith(alias)) {
|
||||
continue;
|
||||
}
|
||||
const _alias = hasTrailingSlash(alias) ? alias.slice(0, -1) : alias;
|
||||
if (hasTrailingSlash(_path[_alias.length])) {
|
||||
return join(to, _path.slice(alias.length));
|
||||
}
|
||||
}
|
||||
return _path;
|
||||
}
|
||||
function reverseResolveAlias(path, aliases) {
|
||||
const _path = normalizeWindowsPath(path);
|
||||
aliases = normalizeAliases(aliases);
|
||||
const matches = [];
|
||||
for (const [to, alias] of Object.entries(aliases)) {
|
||||
if (!_path.startsWith(alias)) {
|
||||
continue;
|
||||
}
|
||||
const _alias = hasTrailingSlash(alias) ? alias.slice(0, -1) : alias;
|
||||
if (hasTrailingSlash(_path[_alias.length])) {
|
||||
matches.push(join(to, _path.slice(alias.length)));
|
||||
}
|
||||
}
|
||||
return matches.sort((a, b) => b.length - a.length);
|
||||
}
|
||||
function filename(path) {
|
||||
const base = path.split(SLASH_RE).pop();
|
||||
if (!base) {
|
||||
return void 0;
|
||||
}
|
||||
const separatorIndex = base.lastIndexOf(".");
|
||||
if (separatorIndex <= 0) {
|
||||
return base;
|
||||
}
|
||||
return base.slice(0, separatorIndex);
|
||||
}
|
||||
function _compareAliases(a, b) {
|
||||
return b.split("/").length - a.split("/").length;
|
||||
}
|
||||
function hasTrailingSlash(path = "/") {
|
||||
const lastChar = path[path.length - 1];
|
||||
return lastChar === "/" || lastChar === "\\";
|
||||
}
|
||||
|
||||
export { filename, normalizeAliases, resolveAlias, reverseResolveAlias };
|
||||
61
node_modules/c12/node_modules/pathe/package.json
generated
vendored
Normal file
61
node_modules/c12/node_modules/pathe/package.json
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
{
|
||||
"name": "pathe",
|
||||
"version": "2.0.3",
|
||||
"description": "Universal filesystem path utils",
|
||||
"repository": "unjs/pathe",
|
||||
"license": "MIT",
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": {
|
||||
"types": "./dist/index.d.mts",
|
||||
"default": "./dist/index.mjs"
|
||||
},
|
||||
"require": {
|
||||
"types": "./dist/index.d.cts",
|
||||
"default": "./dist/index.cjs"
|
||||
}
|
||||
},
|
||||
"./utils": {
|
||||
"import": {
|
||||
"types": "./dist/utils.d.mts",
|
||||
"default": "./dist/utils.mjs"
|
||||
},
|
||||
"require": {
|
||||
"types": "./dist/utils.d.cts",
|
||||
"default": "./dist/utils.cjs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"files": [
|
||||
"dist",
|
||||
"utils.d.ts"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.13.1",
|
||||
"@vitest/coverage-v8": "^3.0.5",
|
||||
"changelogen": "^0.5.7",
|
||||
"esbuild": "^0.25.0",
|
||||
"eslint": "^9.20.1",
|
||||
"eslint-config-unjs": "^0.4.2",
|
||||
"jiti": "^2.4.2",
|
||||
"prettier": "^3.5.0",
|
||||
"typescript": "^5.7.3",
|
||||
"unbuild": "^3.3.1",
|
||||
"vitest": "^3.0.5",
|
||||
"zeptomatch": "^2.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "unbuild",
|
||||
"dev": "vitest",
|
||||
"lint": "eslint . && prettier -c src test",
|
||||
"lint:fix": "eslint . --fix && prettier -w src test",
|
||||
"release": "pnpm test && pnpm build && changelogen --release && pnpm publish && git push --follow-tags",
|
||||
"test": "pnpm lint && vitest run --coverage",
|
||||
"test:types": "tsc --noEmit"
|
||||
}
|
||||
}
|
||||
1
node_modules/c12/node_modules/pathe/utils.d.ts
generated
vendored
Normal file
1
node_modules/c12/node_modules/pathe/utils.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./dist/utils";
|
||||
39
node_modules/c12/node_modules/rc9/LICENSE
generated
vendored
Normal file
39
node_modules/c12/node_modules/rc9/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Pooya Parsa <pooya@pi0.io>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
|
||||
-----
|
||||
|
||||
Bundled with https://github.com/hughsk/flat
|
||||
|
||||
Copyright (c) 2014, Hugh Kennedy
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
201
node_modules/c12/node_modules/rc9/README.md
generated
vendored
Normal file
201
node_modules/c12/node_modules/rc9/README.md
generated
vendored
Normal file
@@ -0,0 +1,201 @@
|
||||
# RC9
|
||||
|
||||
<!-- automd:badges color=yellow codecov bundlejs -->
|
||||
|
||||
[](https://npmjs.com/package/rc9)
|
||||
[](https://npmjs.com/package/rc9)
|
||||
[](https://bundlejs.com/?q=rc9)
|
||||
[](https://codecov.io/gh/unjs/rc9)
|
||||
|
||||
<!-- /automd -->
|
||||
|
||||
Read/Write RC configs couldn't be easier!
|
||||
|
||||
## Install
|
||||
|
||||
Install dependencies:
|
||||
|
||||
<!-- automd:pm-i -->
|
||||
|
||||
```sh
|
||||
# ✨ Auto-detect
|
||||
npx nypm install rc9
|
||||
|
||||
# npm
|
||||
npm install rc9
|
||||
|
||||
# yarn
|
||||
yarn add rc9
|
||||
|
||||
# pnpm
|
||||
pnpm install rc9
|
||||
|
||||
# bun
|
||||
bun install rc9
|
||||
```
|
||||
|
||||
<!-- /automd -->
|
||||
|
||||
Import utils:
|
||||
|
||||
<!-- automd:jsimport cjs src="./src/index.ts"-->
|
||||
|
||||
**ESM** (Node.js, Bun)
|
||||
|
||||
```js
|
||||
import {
|
||||
defaults,
|
||||
parse,
|
||||
parseFile,
|
||||
read,
|
||||
readUser,
|
||||
serialize,
|
||||
write,
|
||||
writeUser,
|
||||
update,
|
||||
updateUser,
|
||||
} from "rc9";
|
||||
```
|
||||
|
||||
**CommonJS** (Legacy Node.js)
|
||||
|
||||
```js
|
||||
const {
|
||||
defaults,
|
||||
parse,
|
||||
parseFile,
|
||||
read,
|
||||
readUser,
|
||||
serialize,
|
||||
write,
|
||||
writeUser,
|
||||
update,
|
||||
updateUser,
|
||||
} = require("rc9");
|
||||
```
|
||||
|
||||
<!-- /automd -->
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
`.conf`:
|
||||
|
||||
```ini
|
||||
db.username=username
|
||||
db.password=multi word password
|
||||
db.enabled=true
|
||||
```
|
||||
|
||||
**Update config:**
|
||||
|
||||
```ts
|
||||
update({ 'db.enabled': false }) // or update(..., { name: '.conf' })
|
||||
```
|
||||
|
||||
Push to an array:
|
||||
|
||||
```ts
|
||||
update({ 'modules[]': 'test' })
|
||||
```
|
||||
|
||||
**Read/Write config:**
|
||||
|
||||
```ts
|
||||
const config = read() // or read('.conf')
|
||||
|
||||
// config = {
|
||||
// db: {
|
||||
// username: 'username',
|
||||
// password: 'multi word password',
|
||||
// enabled: true
|
||||
// }
|
||||
// }
|
||||
|
||||
config.enabled = false
|
||||
write(config) // or write(config, '.conf')
|
||||
```
|
||||
|
||||
**User Config:**
|
||||
|
||||
It is common to keep config in user home directory (MacOS: `/Users/{name}`, Linux: `/home/{name}`, Windows: `C:\users\{name}`)
|
||||
|
||||
you can use `readUser`/`writeuser`/`updateUser` shortcuts to quickly do this:
|
||||
|
||||
```js
|
||||
writeUser({ token: 123 }, '.zoorc') // Will be saved in {home}/.zoorc
|
||||
|
||||
const conf = readUser('.zoorc') // { token: 123 }
|
||||
```
|
||||
|
||||
## Unflatten
|
||||
|
||||
RC uses [flat](https://www.npmjs.com/package/flat) to automatically flat/unflat when writing and reading rcfile.
|
||||
|
||||
It means that you can use `.` for keys to define objects. Some examples:
|
||||
|
||||
- `hello.world = true` <=> `{ hello: { world: true }`
|
||||
- `test.0 = A` <=> `tags: [ 'A' ]`
|
||||
|
||||
**Note:** If you use keys that can override like `x=` and `x.y=`, you can disable this feature by passing `flat: true` option.
|
||||
|
||||
**Tip:** You can use keys ending with `[]` to push to an array like `test[]=A`
|
||||
|
||||
## Native Values
|
||||
|
||||
RC uses [destr](https://www.npmjs.com/package/destr) to convert values into native javascript values.
|
||||
|
||||
So reading `count=123` results `{ count: 123 }` (instead of `{ count: "123" }`) if you want to preserve strings as is, can use `count="123"`.
|
||||
|
||||
## Exports
|
||||
|
||||
```ts
|
||||
const defaults: RCOptions;
|
||||
function parse(contents: string, options?: RCOptions): RC
|
||||
function parseFile(path: string, options?: RCOptions): RC
|
||||
function read(options?: RCOptions | string): RC;
|
||||
function readUser(options?: RCOptions | string): RC;
|
||||
function serialize(config: RC): string;
|
||||
function write(config: RC, options?: RCOptions | string): void;
|
||||
function writeUser(config: RC, options?: RCOptions | string): void;
|
||||
function update(config: RC, options?: RCOptions | string): RC;
|
||||
function updateUser(config: RC, options?: RCOptions | string): RC;
|
||||
```
|
||||
|
||||
**Types:**
|
||||
|
||||
```ts
|
||||
type RC = Record<string, any>;
|
||||
interface RCOptions {
|
||||
name?: string;
|
||||
dir?: string;
|
||||
flat?: boolean;
|
||||
}
|
||||
```
|
||||
|
||||
**Defaults:**
|
||||
|
||||
```ini
|
||||
{
|
||||
name: '.conf',
|
||||
dir: process.cwd(),
|
||||
flat: false
|
||||
}
|
||||
```
|
||||
|
||||
### Why RC9?
|
||||
|
||||
Be the first one to guess 🐇 <!-- Hint: do research about rc files history -->
|
||||
|
||||
## License
|
||||
|
||||
<!-- automd:contributors license=MIT -->
|
||||
|
||||
Published under the [MIT](https://github.com/unjs/rc9/blob/main/LICENSE) license.
|
||||
Made by [community](https://github.com/unjs/rc9/graphs/contributors) 💛
|
||||
<br><br>
|
||||
<a href="https://github.com/unjs/rc9/graphs/contributors">
|
||||
<img src="https://contrib.rocks/image?repo=unjs/rc9" />
|
||||
</a>
|
||||
|
||||
<!-- /automd -->
|
||||
262
node_modules/c12/node_modules/rc9/dist/index.cjs
generated
vendored
Normal file
262
node_modules/c12/node_modules/rc9/dist/index.cjs
generated
vendored
Normal file
@@ -0,0 +1,262 @@
|
||||
'use strict';
|
||||
|
||||
const node_fs = require('node:fs');
|
||||
const node_path = require('node:path');
|
||||
const node_os = require('node:os');
|
||||
const destr = require('destr');
|
||||
const defu = require('defu');
|
||||
|
||||
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
||||
|
||||
const destr__default = /*#__PURE__*/_interopDefaultCompat(destr);
|
||||
|
||||
function isBuffer (obj) {
|
||||
return obj &&
|
||||
obj.constructor &&
|
||||
(typeof obj.constructor.isBuffer === 'function') &&
|
||||
obj.constructor.isBuffer(obj)
|
||||
}
|
||||
|
||||
function keyIdentity (key) {
|
||||
return key
|
||||
}
|
||||
|
||||
function flatten (target, opts) {
|
||||
opts = opts || {};
|
||||
|
||||
const delimiter = opts.delimiter || '.';
|
||||
const maxDepth = opts.maxDepth;
|
||||
const transformKey = opts.transformKey || keyIdentity;
|
||||
const output = {};
|
||||
|
||||
function step (object, prev, currentDepth) {
|
||||
currentDepth = currentDepth || 1;
|
||||
Object.keys(object).forEach(function (key) {
|
||||
const value = object[key];
|
||||
const isarray = opts.safe && Array.isArray(value);
|
||||
const type = Object.prototype.toString.call(value);
|
||||
const isbuffer = isBuffer(value);
|
||||
const isobject = (
|
||||
type === '[object Object]' ||
|
||||
type === '[object Array]'
|
||||
);
|
||||
|
||||
const newKey = prev
|
||||
? prev + delimiter + transformKey(key)
|
||||
: transformKey(key);
|
||||
|
||||
if (!isarray && !isbuffer && isobject && Object.keys(value).length &&
|
||||
(!opts.maxDepth || currentDepth < maxDepth)) {
|
||||
return step(value, newKey, currentDepth + 1)
|
||||
}
|
||||
|
||||
output[newKey] = value;
|
||||
});
|
||||
}
|
||||
|
||||
step(target);
|
||||
|
||||
return output
|
||||
}
|
||||
|
||||
function unflatten (target, opts) {
|
||||
opts = opts || {};
|
||||
|
||||
const delimiter = opts.delimiter || '.';
|
||||
const overwrite = opts.overwrite || false;
|
||||
const transformKey = opts.transformKey || keyIdentity;
|
||||
const result = {};
|
||||
|
||||
const isbuffer = isBuffer(target);
|
||||
if (isbuffer || Object.prototype.toString.call(target) !== '[object Object]') {
|
||||
return target
|
||||
}
|
||||
|
||||
// safely ensure that the key is
|
||||
// an integer.
|
||||
function getkey (key) {
|
||||
const parsedKey = Number(key);
|
||||
|
||||
return (
|
||||
isNaN(parsedKey) ||
|
||||
key.indexOf('.') !== -1 ||
|
||||
opts.object
|
||||
)
|
||||
? key
|
||||
: parsedKey
|
||||
}
|
||||
|
||||
function addKeys (keyPrefix, recipient, target) {
|
||||
return Object.keys(target).reduce(function (result, key) {
|
||||
result[keyPrefix + delimiter + key] = target[key];
|
||||
|
||||
return result
|
||||
}, recipient)
|
||||
}
|
||||
|
||||
function isEmpty (val) {
|
||||
const type = Object.prototype.toString.call(val);
|
||||
const isArray = type === '[object Array]';
|
||||
const isObject = type === '[object Object]';
|
||||
|
||||
if (!val) {
|
||||
return true
|
||||
} else if (isArray) {
|
||||
return !val.length
|
||||
} else if (isObject) {
|
||||
return !Object.keys(val).length
|
||||
}
|
||||
}
|
||||
|
||||
target = Object.keys(target).reduce(function (result, key) {
|
||||
const type = Object.prototype.toString.call(target[key]);
|
||||
const isObject = (type === '[object Object]' || type === '[object Array]');
|
||||
if (!isObject || isEmpty(target[key])) {
|
||||
result[key] = target[key];
|
||||
return result
|
||||
} else {
|
||||
return addKeys(
|
||||
key,
|
||||
result,
|
||||
flatten(target[key], opts)
|
||||
)
|
||||
}
|
||||
}, {});
|
||||
|
||||
Object.keys(target).forEach(function (key) {
|
||||
const split = key.split(delimiter).map(transformKey);
|
||||
let key1 = getkey(split.shift());
|
||||
let key2 = getkey(split[0]);
|
||||
let recipient = result;
|
||||
|
||||
while (key2 !== undefined) {
|
||||
if (key1 === '__proto__') {
|
||||
return
|
||||
}
|
||||
|
||||
const type = Object.prototype.toString.call(recipient[key1]);
|
||||
const isobject = (
|
||||
type === '[object Object]' ||
|
||||
type === '[object Array]'
|
||||
);
|
||||
|
||||
// do not write over falsey, non-undefined values if overwrite is false
|
||||
if (!overwrite && !isobject && typeof recipient[key1] !== 'undefined') {
|
||||
return
|
||||
}
|
||||
|
||||
if ((overwrite && !isobject) || (!overwrite && recipient[key1] == null)) {
|
||||
recipient[key1] = (
|
||||
typeof key2 === 'number' &&
|
||||
!opts.object
|
||||
? []
|
||||
: {}
|
||||
);
|
||||
}
|
||||
|
||||
recipient = recipient[key1];
|
||||
if (split.length > 0) {
|
||||
key1 = getkey(split.shift());
|
||||
key2 = getkey(split[0]);
|
||||
}
|
||||
}
|
||||
|
||||
// unflatten again for 'messy objects'
|
||||
recipient[key1] = unflatten(target[key], opts);
|
||||
});
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
const RE_KEY_VAL = /^\s*([^\s=]+)\s*=\s*(.*)?\s*$/;
|
||||
const RE_LINES = /\n|\r|\r\n/;
|
||||
const defaults = {
|
||||
name: ".conf",
|
||||
dir: process.cwd(),
|
||||
flat: false
|
||||
};
|
||||
function withDefaults(options) {
|
||||
if (typeof options === "string") {
|
||||
options = { name: options };
|
||||
}
|
||||
return { ...defaults, ...options };
|
||||
}
|
||||
function parse(contents, options = {}) {
|
||||
const config = {};
|
||||
const lines = contents.split(RE_LINES);
|
||||
for (const line of lines) {
|
||||
const match = line.match(RE_KEY_VAL);
|
||||
if (!match) {
|
||||
continue;
|
||||
}
|
||||
const key = match[1];
|
||||
if (!key || key === "__proto__" || key === "constructor") {
|
||||
continue;
|
||||
}
|
||||
const value = destr__default(
|
||||
(match[2] || "").trim()
|
||||
/* val */
|
||||
);
|
||||
if (key.endsWith("[]")) {
|
||||
const nkey = key.slice(0, Math.max(0, key.length - 2));
|
||||
config[nkey] = (config[nkey] || []).concat(value);
|
||||
continue;
|
||||
}
|
||||
config[key] = value;
|
||||
}
|
||||
return options.flat ? config : unflatten(config, { overwrite: true });
|
||||
}
|
||||
function parseFile(path, options) {
|
||||
if (!node_fs.existsSync(path)) {
|
||||
return {};
|
||||
}
|
||||
return parse(node_fs.readFileSync(path, "utf8"), options);
|
||||
}
|
||||
function read(options) {
|
||||
options = withDefaults(options);
|
||||
return parseFile(node_path.resolve(options.dir, options.name), options);
|
||||
}
|
||||
function readUser(options) {
|
||||
options = withDefaults(options);
|
||||
options.dir = process.env.XDG_CONFIG_HOME || node_os.homedir();
|
||||
return read(options);
|
||||
}
|
||||
function serialize(config) {
|
||||
return Object.entries(flatten(config)).map(([key, value]) => `${key}=${JSON.stringify(value)}`).join("\n");
|
||||
}
|
||||
function write(config, options) {
|
||||
options = withDefaults(options);
|
||||
node_fs.writeFileSync(node_path.resolve(options.dir, options.name), serialize(config), {
|
||||
encoding: "utf8"
|
||||
});
|
||||
}
|
||||
function writeUser(config, options) {
|
||||
options = withDefaults(options);
|
||||
options.dir = process.env.XDG_CONFIG_HOME || node_os.homedir();
|
||||
write(config, options);
|
||||
}
|
||||
function update(config, options) {
|
||||
options = withDefaults(options);
|
||||
if (!options.flat) {
|
||||
config = unflatten(config, { overwrite: true });
|
||||
}
|
||||
const newConfig = defu.defu(config, read(options));
|
||||
write(newConfig, options);
|
||||
return newConfig;
|
||||
}
|
||||
function updateUser(config, options) {
|
||||
options = withDefaults(options);
|
||||
options.dir = process.env.XDG_CONFIG_HOME || node_os.homedir();
|
||||
return update(config, options);
|
||||
}
|
||||
|
||||
exports.defaults = defaults;
|
||||
exports.parse = parse;
|
||||
exports.parseFile = parseFile;
|
||||
exports.read = read;
|
||||
exports.readUser = readUser;
|
||||
exports.serialize = serialize;
|
||||
exports.update = update;
|
||||
exports.updateUser = updateUser;
|
||||
exports.write = write;
|
||||
exports.writeUser = writeUser;
|
||||
18
node_modules/c12/node_modules/rc9/dist/index.d.cts
generated
vendored
Normal file
18
node_modules/c12/node_modules/rc9/dist/index.d.cts
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
type RC = Record<string, any>;
|
||||
interface RCOptions {
|
||||
name?: string;
|
||||
dir?: string;
|
||||
flat?: boolean;
|
||||
}
|
||||
declare const defaults: RCOptions;
|
||||
declare function parse<T extends RC = RC>(contents: string, options?: RCOptions): T;
|
||||
declare function parseFile<T extends RC = RC>(path: string, options?: RCOptions): T;
|
||||
declare function read<T extends RC = RC>(options?: RCOptions | string): T;
|
||||
declare function readUser<T extends RC = RC>(options?: RCOptions | string): T;
|
||||
declare function serialize<T extends RC = RC>(config: T): string;
|
||||
declare function write<T extends RC = RC>(config: T, options?: RCOptions | string): void;
|
||||
declare function writeUser<T extends RC = RC>(config: T, options?: RCOptions | string): void;
|
||||
declare function update<T extends RC = RC>(config: T, options?: RCOptions | string): T;
|
||||
declare function updateUser<T extends RC = RC>(config: T, options?: RCOptions | string): T;
|
||||
|
||||
export { defaults, parse, parseFile, read, readUser, serialize, update, updateUser, write, writeUser };
|
||||
18
node_modules/c12/node_modules/rc9/dist/index.d.mts
generated
vendored
Normal file
18
node_modules/c12/node_modules/rc9/dist/index.d.mts
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
type RC = Record<string, any>;
|
||||
interface RCOptions {
|
||||
name?: string;
|
||||
dir?: string;
|
||||
flat?: boolean;
|
||||
}
|
||||
declare const defaults: RCOptions;
|
||||
declare function parse<T extends RC = RC>(contents: string, options?: RCOptions): T;
|
||||
declare function parseFile<T extends RC = RC>(path: string, options?: RCOptions): T;
|
||||
declare function read<T extends RC = RC>(options?: RCOptions | string): T;
|
||||
declare function readUser<T extends RC = RC>(options?: RCOptions | string): T;
|
||||
declare function serialize<T extends RC = RC>(config: T): string;
|
||||
declare function write<T extends RC = RC>(config: T, options?: RCOptions | string): void;
|
||||
declare function writeUser<T extends RC = RC>(config: T, options?: RCOptions | string): void;
|
||||
declare function update<T extends RC = RC>(config: T, options?: RCOptions | string): T;
|
||||
declare function updateUser<T extends RC = RC>(config: T, options?: RCOptions | string): T;
|
||||
|
||||
export { defaults, parse, parseFile, read, readUser, serialize, update, updateUser, write, writeUser };
|
||||
18
node_modules/c12/node_modules/rc9/dist/index.d.ts
generated
vendored
Normal file
18
node_modules/c12/node_modules/rc9/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
type RC = Record<string, any>;
|
||||
interface RCOptions {
|
||||
name?: string;
|
||||
dir?: string;
|
||||
flat?: boolean;
|
||||
}
|
||||
declare const defaults: RCOptions;
|
||||
declare function parse<T extends RC = RC>(contents: string, options?: RCOptions): T;
|
||||
declare function parseFile<T extends RC = RC>(path: string, options?: RCOptions): T;
|
||||
declare function read<T extends RC = RC>(options?: RCOptions | string): T;
|
||||
declare function readUser<T extends RC = RC>(options?: RCOptions | string): T;
|
||||
declare function serialize<T extends RC = RC>(config: T): string;
|
||||
declare function write<T extends RC = RC>(config: T, options?: RCOptions | string): void;
|
||||
declare function writeUser<T extends RC = RC>(config: T, options?: RCOptions | string): void;
|
||||
declare function update<T extends RC = RC>(config: T, options?: RCOptions | string): T;
|
||||
declare function updateUser<T extends RC = RC>(config: T, options?: RCOptions | string): T;
|
||||
|
||||
export { defaults, parse, parseFile, read, readUser, serialize, update, updateUser, write, writeUser };
|
||||
247
node_modules/c12/node_modules/rc9/dist/index.mjs
generated
vendored
Normal file
247
node_modules/c12/node_modules/rc9/dist/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,247 @@
|
||||
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
||||
import { resolve } from 'node:path';
|
||||
import { homedir } from 'node:os';
|
||||
import destr from 'destr';
|
||||
import { defu } from 'defu';
|
||||
|
||||
function isBuffer (obj) {
|
||||
return obj &&
|
||||
obj.constructor &&
|
||||
(typeof obj.constructor.isBuffer === 'function') &&
|
||||
obj.constructor.isBuffer(obj)
|
||||
}
|
||||
|
||||
function keyIdentity (key) {
|
||||
return key
|
||||
}
|
||||
|
||||
function flatten (target, opts) {
|
||||
opts = opts || {};
|
||||
|
||||
const delimiter = opts.delimiter || '.';
|
||||
const maxDepth = opts.maxDepth;
|
||||
const transformKey = opts.transformKey || keyIdentity;
|
||||
const output = {};
|
||||
|
||||
function step (object, prev, currentDepth) {
|
||||
currentDepth = currentDepth || 1;
|
||||
Object.keys(object).forEach(function (key) {
|
||||
const value = object[key];
|
||||
const isarray = opts.safe && Array.isArray(value);
|
||||
const type = Object.prototype.toString.call(value);
|
||||
const isbuffer = isBuffer(value);
|
||||
const isobject = (
|
||||
type === '[object Object]' ||
|
||||
type === '[object Array]'
|
||||
);
|
||||
|
||||
const newKey = prev
|
||||
? prev + delimiter + transformKey(key)
|
||||
: transformKey(key);
|
||||
|
||||
if (!isarray && !isbuffer && isobject && Object.keys(value).length &&
|
||||
(!opts.maxDepth || currentDepth < maxDepth)) {
|
||||
return step(value, newKey, currentDepth + 1)
|
||||
}
|
||||
|
||||
output[newKey] = value;
|
||||
});
|
||||
}
|
||||
|
||||
step(target);
|
||||
|
||||
return output
|
||||
}
|
||||
|
||||
function unflatten (target, opts) {
|
||||
opts = opts || {};
|
||||
|
||||
const delimiter = opts.delimiter || '.';
|
||||
const overwrite = opts.overwrite || false;
|
||||
const transformKey = opts.transformKey || keyIdentity;
|
||||
const result = {};
|
||||
|
||||
const isbuffer = isBuffer(target);
|
||||
if (isbuffer || Object.prototype.toString.call(target) !== '[object Object]') {
|
||||
return target
|
||||
}
|
||||
|
||||
// safely ensure that the key is
|
||||
// an integer.
|
||||
function getkey (key) {
|
||||
const parsedKey = Number(key);
|
||||
|
||||
return (
|
||||
isNaN(parsedKey) ||
|
||||
key.indexOf('.') !== -1 ||
|
||||
opts.object
|
||||
)
|
||||
? key
|
||||
: parsedKey
|
||||
}
|
||||
|
||||
function addKeys (keyPrefix, recipient, target) {
|
||||
return Object.keys(target).reduce(function (result, key) {
|
||||
result[keyPrefix + delimiter + key] = target[key];
|
||||
|
||||
return result
|
||||
}, recipient)
|
||||
}
|
||||
|
||||
function isEmpty (val) {
|
||||
const type = Object.prototype.toString.call(val);
|
||||
const isArray = type === '[object Array]';
|
||||
const isObject = type === '[object Object]';
|
||||
|
||||
if (!val) {
|
||||
return true
|
||||
} else if (isArray) {
|
||||
return !val.length
|
||||
} else if (isObject) {
|
||||
return !Object.keys(val).length
|
||||
}
|
||||
}
|
||||
|
||||
target = Object.keys(target).reduce(function (result, key) {
|
||||
const type = Object.prototype.toString.call(target[key]);
|
||||
const isObject = (type === '[object Object]' || type === '[object Array]');
|
||||
if (!isObject || isEmpty(target[key])) {
|
||||
result[key] = target[key];
|
||||
return result
|
||||
} else {
|
||||
return addKeys(
|
||||
key,
|
||||
result,
|
||||
flatten(target[key], opts)
|
||||
)
|
||||
}
|
||||
}, {});
|
||||
|
||||
Object.keys(target).forEach(function (key) {
|
||||
const split = key.split(delimiter).map(transformKey);
|
||||
let key1 = getkey(split.shift());
|
||||
let key2 = getkey(split[0]);
|
||||
let recipient = result;
|
||||
|
||||
while (key2 !== undefined) {
|
||||
if (key1 === '__proto__') {
|
||||
return
|
||||
}
|
||||
|
||||
const type = Object.prototype.toString.call(recipient[key1]);
|
||||
const isobject = (
|
||||
type === '[object Object]' ||
|
||||
type === '[object Array]'
|
||||
);
|
||||
|
||||
// do not write over falsey, non-undefined values if overwrite is false
|
||||
if (!overwrite && !isobject && typeof recipient[key1] !== 'undefined') {
|
||||
return
|
||||
}
|
||||
|
||||
if ((overwrite && !isobject) || (!overwrite && recipient[key1] == null)) {
|
||||
recipient[key1] = (
|
||||
typeof key2 === 'number' &&
|
||||
!opts.object
|
||||
? []
|
||||
: {}
|
||||
);
|
||||
}
|
||||
|
||||
recipient = recipient[key1];
|
||||
if (split.length > 0) {
|
||||
key1 = getkey(split.shift());
|
||||
key2 = getkey(split[0]);
|
||||
}
|
||||
}
|
||||
|
||||
// unflatten again for 'messy objects'
|
||||
recipient[key1] = unflatten(target[key], opts);
|
||||
});
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
const RE_KEY_VAL = /^\s*([^\s=]+)\s*=\s*(.*)?\s*$/;
|
||||
const RE_LINES = /\n|\r|\r\n/;
|
||||
const defaults = {
|
||||
name: ".conf",
|
||||
dir: process.cwd(),
|
||||
flat: false
|
||||
};
|
||||
function withDefaults(options) {
|
||||
if (typeof options === "string") {
|
||||
options = { name: options };
|
||||
}
|
||||
return { ...defaults, ...options };
|
||||
}
|
||||
function parse(contents, options = {}) {
|
||||
const config = {};
|
||||
const lines = contents.split(RE_LINES);
|
||||
for (const line of lines) {
|
||||
const match = line.match(RE_KEY_VAL);
|
||||
if (!match) {
|
||||
continue;
|
||||
}
|
||||
const key = match[1];
|
||||
if (!key || key === "__proto__" || key === "constructor") {
|
||||
continue;
|
||||
}
|
||||
const value = destr(
|
||||
(match[2] || "").trim()
|
||||
/* val */
|
||||
);
|
||||
if (key.endsWith("[]")) {
|
||||
const nkey = key.slice(0, Math.max(0, key.length - 2));
|
||||
config[nkey] = (config[nkey] || []).concat(value);
|
||||
continue;
|
||||
}
|
||||
config[key] = value;
|
||||
}
|
||||
return options.flat ? config : unflatten(config, { overwrite: true });
|
||||
}
|
||||
function parseFile(path, options) {
|
||||
if (!existsSync(path)) {
|
||||
return {};
|
||||
}
|
||||
return parse(readFileSync(path, "utf8"), options);
|
||||
}
|
||||
function read(options) {
|
||||
options = withDefaults(options);
|
||||
return parseFile(resolve(options.dir, options.name), options);
|
||||
}
|
||||
function readUser(options) {
|
||||
options = withDefaults(options);
|
||||
options.dir = process.env.XDG_CONFIG_HOME || homedir();
|
||||
return read(options);
|
||||
}
|
||||
function serialize(config) {
|
||||
return Object.entries(flatten(config)).map(([key, value]) => `${key}=${JSON.stringify(value)}`).join("\n");
|
||||
}
|
||||
function write(config, options) {
|
||||
options = withDefaults(options);
|
||||
writeFileSync(resolve(options.dir, options.name), serialize(config), {
|
||||
encoding: "utf8"
|
||||
});
|
||||
}
|
||||
function writeUser(config, options) {
|
||||
options = withDefaults(options);
|
||||
options.dir = process.env.XDG_CONFIG_HOME || homedir();
|
||||
write(config, options);
|
||||
}
|
||||
function update(config, options) {
|
||||
options = withDefaults(options);
|
||||
if (!options.flat) {
|
||||
config = unflatten(config, { overwrite: true });
|
||||
}
|
||||
const newConfig = defu(config, read(options));
|
||||
write(newConfig, options);
|
||||
return newConfig;
|
||||
}
|
||||
function updateUser(config, options) {
|
||||
options = withDefaults(options);
|
||||
options.dir = process.env.XDG_CONFIG_HOME || homedir();
|
||||
return update(config, options);
|
||||
}
|
||||
|
||||
export { defaults, parse, parseFile, read, readUser, serialize, update, updateUser, write, writeUser };
|
||||
46
node_modules/c12/node_modules/rc9/package.json
generated
vendored
Normal file
46
node_modules/c12/node_modules/rc9/package.json
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"name": "rc9",
|
||||
"version": "2.1.2",
|
||||
"description": "Read/Write config couldn't be easier!",
|
||||
"repository": "unjs/rc9",
|
||||
"license": "MIT",
|
||||
"sideEffects": false,
|
||||
"exports": {
|
||||
".": {
|
||||
"require": "./dist/index.cjs",
|
||||
"import": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts"
|
||||
}
|
||||
},
|
||||
"main": "./dist/index.cjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "unbuild",
|
||||
"dev": "vitest",
|
||||
"lint": "eslint . && prettier -c src test",
|
||||
"lint:fix": "eslint . --fix && prettier -w src test",
|
||||
"release": "pnpm test && pnpm build && changelogen --release --push && npm publish",
|
||||
"test": "pnpm lint && vitest run --coverage"
|
||||
},
|
||||
"dependencies": {
|
||||
"defu": "^6.1.4",
|
||||
"destr": "^2.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.12.6",
|
||||
"@vitest/coverage-v8": "^1.4.0",
|
||||
"automd": "^0.3.7",
|
||||
"changelogen": "^0.5.5",
|
||||
"eslint": "^9.0.0",
|
||||
"eslint-config-unjs": "^0.3.0-rc.5",
|
||||
"flat": "^6.0.1",
|
||||
"prettier": "^3.2.5",
|
||||
"typescript": "^5.4.4",
|
||||
"unbuild": "^2.0.0",
|
||||
"vitest": "^1.4.0"
|
||||
},
|
||||
"packageManager": "pnpm@8.15.6"
|
||||
}
|
||||
69
node_modules/c12/package.json
generated
vendored
Normal file
69
node_modules/c12/package.json
generated
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
{
|
||||
"name": "c12",
|
||||
"version": "3.3.3",
|
||||
"description": "Smart Config Loader",
|
||||
"repository": "unjs/c12",
|
||||
"license": "MIT",
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.mts",
|
||||
"default": "./dist/index.mjs"
|
||||
},
|
||||
"./update": {
|
||||
"types": "./dist/update.d.mts",
|
||||
"default": "./dist/update.mjs"
|
||||
}
|
||||
},
|
||||
"types": "./dist/index.d.mts",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "obuild",
|
||||
"dev": "vitest dev",
|
||||
"lint": "eslint . && prettier -c src test",
|
||||
"lint:fix": "automd && eslint . --fix && prettier -w src test",
|
||||
"release": "pnpm build && pnpm test && changelogen --release --push --publish",
|
||||
"test": "pnpm lint && vitest run --coverage && pnpm test:types",
|
||||
"test:types": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"chokidar": "^5.0.0",
|
||||
"confbox": "^0.2.2",
|
||||
"defu": "^6.1.4",
|
||||
"dotenv": "^17.2.3",
|
||||
"exsolve": "^1.0.8",
|
||||
"giget": "^2.0.0",
|
||||
"jiti": "^2.6.1",
|
||||
"ohash": "^2.0.11",
|
||||
"pathe": "^2.0.3",
|
||||
"perfect-debounce": "^2.0.0",
|
||||
"pkg-types": "^2.3.0",
|
||||
"rc9": "^2.1.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^25.0.2",
|
||||
"@vitest/coverage-v8": "^4.0.15",
|
||||
"automd": "^0.4.2",
|
||||
"changelogen": "^0.6.2",
|
||||
"eslint": "^9.39.2",
|
||||
"eslint-config-unjs": "^0.5.0",
|
||||
"expect-type": "^1.3.0",
|
||||
"magicast": "^0.5.1",
|
||||
"obuild": "^0.4.8",
|
||||
"prettier": "^3.7.4",
|
||||
"typescript": "^5.9.3",
|
||||
"vitest": "^4.0.15"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"magicast": "*"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"magicast": {
|
||||
"optional": true
|
||||
}
|
||||
},
|
||||
"packageManager": "pnpm@10.26.0"
|
||||
}
|
||||
Reference in New Issue
Block a user