Skip to content

Commit

Permalink
feat: support auth shortcut for layer config (resolves #142)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Mar 6, 2024
1 parent 11fb78c commit 88095d2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
10 changes: 6 additions & 4 deletions README.md
Expand Up @@ -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.

Expand All @@ -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
Expand Down Expand Up @@ -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.

Expand Down
1 change: 1 addition & 0 deletions src/loader.ts
Expand Up @@ -303,6 +303,7 @@ async function resolveConfig<
dir: cloneDir,
install: sourceOptions.install,
force: sourceOptions.install,
auth: sourceOptions.auth,
...options.giget,
...sourceOptions.giget,
});
Expand Down
27 changes: 25 additions & 2 deletions src/types.ts
Expand Up @@ -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<
Expand Down

0 comments on commit 88095d2

Please sign in to comment.