From 88095d27544d33e1d879869e0781da39b53c44f9 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Wed, 6 Mar 2024 14:03:19 +0100 Subject: [PATCH] feat: support `auth` shortcut for layer config (resolves #142) --- README.md | 10 ++++++---- src/loader.ts | 1 + src/types.ts | 27 +++++++++++++++++++++++++-- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index cf3af8b..e349f30 100644 --- a/README.md +++ b/README.md @@ -245,7 +245,7 @@ Layers: ] ``` -## Extending Config Layer from Remote Sources +## Extending config layer from remote sources You can also extend configuration from remote sources such as npm or github. @@ -269,15 +269,17 @@ export default { }; ``` -**Example:** Extend with clone configuration +**Example:** Extend a private repository and install dependencies: ```js // config.ts export default { - extends: ["gh:user/repo", { giget: { auth: process.env.GITHUB_TOKEN } }], + extends: ["gh:user/repo", { auth: process.env.GITHUB_TOKEN, install: true }], }; ``` +You can pass more options to `giget: {}` in layer config. + Refer to [unjs/giget](https://giget.unjs.io) for more information. ## Environment-specific configuration @@ -310,7 +312,7 @@ c12 tries to match [`envName`](#envname) and override environment config if spec } ``` -## Watching Configuration +## 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. diff --git a/src/loader.ts b/src/loader.ts index 11bd234..e6a1484 100644 --- a/src/loader.ts +++ b/src/loader.ts @@ -303,6 +303,7 @@ async function resolveConfig< dir: cloneDir, install: sourceOptions.install, force: sourceOptions.install, + auth: sourceOptions.auth, ...options.giget, ...sourceOptions.giget, }); diff --git a/src/types.ts b/src/types.ts index e8fdc28..abf48be 100644 --- a/src/types.ts +++ b/src/types.ts @@ -30,11 +30,34 @@ export interface SourceOptions< T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta, > { + /** Custom meta for layer */ meta?: MT; - giget?: DownloadTemplateOptions; - install?: boolean; + + /** 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; } export interface ConfigLayer<