Skip to content

Commit

Permalink
feat: use giget to clone github urls
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Dec 6, 2022
1 parent 4f66630 commit 4c7590a
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 58 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -30,7 +30,7 @@
"dependencies": {
"defu": "^6.1.1",
"dotenv": "^16.0.3",
"gittar": "^0.1.1",
"giget": "^1.0.0",
"jiti": "^1.16.0",
"mlly": "^1.0.0",
"pathe": "^1.0.0",
Expand Down
119 changes: 71 additions & 48 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions src/loader.ts
@@ -1,5 +1,5 @@
import { existsSync, promises as fsp } from "node:fs";
import os from "node:os";
import { existsSync } from "node:fs";
import { homedir } from "node:os";
import { resolve, extname, dirname } from "pathe";
import createJiti, { JITI } from "jiti";
import * as rc9 from "rc9";
Expand Down Expand Up @@ -194,15 +194,15 @@ async function resolveConfig (source: string, options: LoadConfigOptions): Promi

// Download git URLs and resolve to local path
if (GIT_PREFIXES.some(prefix => source.startsWith(prefix))) {
const { downloadTemplate } = await import("giget");
const url = new URL(source);
const subPath = url.pathname.split("/").slice(2).join("/");
const gitRepo = url.protocol + url.pathname.split("/").slice(0, 2).join("/");
const tmpdir = resolve(os.tmpdir(), "c12/", gitRepo.replace(/[#/:@\\]/g, "_"));
await fsp.rm(tmpdir, { recursive: true }).catch(() => {});
const gittar = await import("gittar").then(r => r.default || r);
const tarFile = await gittar.fetch(gitRepo);
await gittar.extract(tarFile, tmpdir);
source = resolve(tmpdir, subPath);
const name = gitRepo.replace(/[#/:@\\]/g, "_");
const tmpDir = process.env.XDG_CACHE_HOME
? resolve(process.env.XDG_CACHE_HOME, "c12", name)
: resolve(homedir(), ".cache/c12", name);
const clonned = await downloadTemplate(source, { dir: tmpDir });
source = clonned.dir;
}

// Try resolving as npm package
Expand Down

0 comments on commit 4c7590a

Please sign in to comment.