Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,23 @@
"citty": "^0.1.6",
"consola": "^3.4.2",
"defu": "^6.1.4",
"nanotar": "^0.1.1",
"node-fetch-native": "^1.6.7",
"nypm": "^0.6.1",
"pathe": "^2.0.3"
},
"devDependencies": {
"@types/node": "^24.4.0",
"@types/tar": "^6.1.13",
"@vitest/coverage-v8": "^3.2.4",
"changelogen": "^0.6.2",
"esbuild": "^0.25.9",
"eslint": "^9.35.0",
"eslint-config-unjs": "^0.5.0",
"jiti": "^2.5.1",
"prettier": "^3.6.2",
"tar": "^6.2.1",
"typescript": "^5.9.2",
"unbuild": "^3.6.1",
"vitest": "^3.2.4"
},
"packageManager": "pnpm@10.16.1",
"pnpm": {
"patchedDependencies": {
"tar": "patches/tar.patch"
}
}
"packageManager": "pnpm@10.16.1"
}
13 changes: 0 additions & 13 deletions patches/tar.patch

This file was deleted.

95 changes: 8 additions & 87 deletions pnpm-lock.yaml

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

52 changes: 31 additions & 21 deletions src/giget.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { mkdir, rm } from "node:fs/promises";
import { mkdir, rm, readFile, writeFile } from "node:fs/promises";
import { existsSync, readdirSync } from "node:fs";
// @ts-ignore
import tarExtract from "tar/lib/extract.js";
import type { ExtractOptions } from "tar";
import { resolve, dirname } from "pathe";
import { parseTarGzip } from "nanotar";
import { resolve, dirname, join } from "pathe";
import { defu } from "defu";
import { installDependencies } from "nypm";
import { cacheDirectory, download, debug, normalizeHeaders } from "./_utils";
Expand Down Expand Up @@ -143,23 +141,35 @@ export async function downloadTemplate(

const s = Date.now();
const subdir = template.subdir?.replace(/^\//, "") || "";
await tarExtract(<ExtractOptions>{
file: tarPath,
cwd: extractPath,
onentry(entry) {
entry.path = entry.path.split("/").splice(1).join("/");
if (subdir) {
// eslint-disable-next-line unicorn/prefer-ternary
if (entry.path.startsWith(subdir + "/")) {
// Rewrite path
entry.path = entry.path.slice(subdir.length);
} else {
// Skip
entry.path = "";
}

const tarData = await readFile(tarPath);
const files = await parseTarGzip(tarData);

for (const file of files) {
let filePath = file.name.split("/").splice(1).join("/");

if (subdir) {
if (filePath.startsWith(subdir + "/")) {
filePath = filePath.slice(subdir.length);
} else {
continue;
}
},
});
}

if (!filePath) {
continue;
}

const fullPath = join(extractPath, filePath);
await mkdir(dirname(fullPath), { recursive: true });

if (file.type === "file" && file.data) {
await writeFile(fullPath, file.data, {
mode: Number.parseInt(file.attrs?.mode || "644", 8),
});
}
}

debug(`Extracted to ${extractPath} in ${Date.now() - s}ms`);

if (options.install) {
Expand Down