Skip to content

Commit c28b776

Browse files
authored
feat: allow setting giget clone options (#112)
1 parent a8b73c2 commit c28b776

File tree

5 files changed

+51
-11
lines changed

5 files changed

+51
-11
lines changed

README.md

+37
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ Custom [unjs/jiti](https://github.com/unjs/jiti) instance used to import configu
123123

124124
Custom [unjs/jiti](https://github.com/unjs/jiti) options to import configuration files.
125125

126+
### `giget`
127+
128+
Options passed to [unjs/giget](https://github.com/unjs/giget) when extending layer from git source.
129+
126130
### `envName`
127131

128132
Environment name used for [environment specific configuration](#environment-specific-configuration).
@@ -205,6 +209,39 @@ Layers:
205209
]
206210
```
207211

212+
## Extending Config Layer from Remote Sources
213+
214+
You can also extend configuration from remote sources such as npm or github.
215+
216+
In the repo, there should be a `config.ts` (or `config.{name}.ts`) file to be considered as a valid config layer.
217+
218+
**Example:** Extend from a github repository
219+
220+
```js
221+
// config.ts
222+
export default {
223+
extends: "gh:repo/owner",
224+
};
225+
```
226+
227+
**Example:** Extend from a github repository with branch and subpath
228+
229+
```js
230+
// config.ts
231+
export default {
232+
extends: "gh:repo/owner/theme#dev",
233+
};
234+
```
235+
236+
**Example:** Extend with custom configuration ([giget](https://github.com/unjs/giget) options)
237+
238+
```js
239+
// config.ts
240+
export default {
241+
extends: ["gh:repo/owner", { giget: { auth: process.env.GITHUB_TOKEN } }],
242+
};
243+
```
244+
208245
## Environment-specific configuration
209246

210247
Users can define environment-specific configuration using these config keys:

src/loader.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,11 @@ async function resolveConfig<
255255
if (existsSync(cloneDir)) {
256256
await rm(cloneDir, { recursive: true });
257257
}
258-
const cloned = await downloadTemplate(source, { dir: cloneDir });
258+
const cloned = await downloadTemplate(source, {
259+
dir: cloneDir,
260+
...options.giget,
261+
...sourceOptions.giget,
262+
});
259263
source = cloned.dir;
260264
}
261265

src/types.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { JITI } from "jiti";
22
import type { JITIOptions } from "jiti/dist/types";
3+
import type { DownloadTemplateOptions } from "giget";
34
import type { DotenvOptions } from "./dotenv";
45

56
export interface ConfigLayerMeta {
@@ -30,6 +31,7 @@ export interface SourceOptions<
3031
MT extends ConfigLayerMeta = ConfigLayerMeta,
3132
> {
3233
meta?: MT;
34+
giget?: DownloadTemplateOptions;
3335
overrides?: T;
3436
[key: string]: any;
3537
}
@@ -88,6 +90,8 @@ export interface LoadConfigOptions<
8890
jiti?: JITI;
8991
jitiOptions?: JITIOptions;
9092

93+
giget?: DownloadTemplateOptions;
94+
9195
extend?:
9296
| false
9397
| {

test/fixture/config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
export default {
22
theme: "./theme",
33
extends: [
4-
["c12-npm-test", { userMeta: 123 }],
5-
["gh:unjs/c12/test/fixture/_github#main", { userMeta: 123 }],
4+
["c12-npm-test"],
5+
["gh:unjs/c12/test/fixture/_github#main", { giget: {} }],
66
],
77
$test: {
88
extends: ["./config.dev"],

test/index.test.ts

+3-8
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,11 @@ describe("c12", () => {
105105
"./config.dev",
106106
[
107107
"c12-npm-test",
108-
{
109-
"userMeta": 123,
110-
},
111108
],
112109
[
113110
"gh:unjs/c12/test/fixture/_github#main",
114111
{
115-
"userMeta": 123,
112+
"giget": {},
116113
},
117114
],
118115
],
@@ -193,9 +190,7 @@ describe("c12", () => {
193190
"cwd": "<path>/fixture/node_modules/c12-npm-test",
194191
"meta": {},
195192
"source": "<path>/fixture/node_modules/c12-npm-test/config.ts",
196-
"sourceOptions": {
197-
"userMeta": 123,
198-
},
193+
"sourceOptions": {},
199194
},
200195
{
201196
"config": {
@@ -206,7 +201,7 @@ describe("c12", () => {
206201
"meta": {},
207202
"source": "config",
208203
"sourceOptions": {
209-
"userMeta": 123,
204+
"giget": {},
210205
},
211206
},
212207
{

0 commit comments

Comments
 (0)