# @bluwy/giget-core 中文文档

规范地址：https://npmcn.com/package/%40bluwy/giget-core/

版本：0\.1\.7
npm 元数据更新时间：2026-03-18T02:57:23.488Z
中文译文更新时间：2026-11-08T09:09:45.490Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40bluwy/giget-core
原文对照：https://npmcn.com/package/%40bluwy/giget-core/?lang=original
项目主页：https://github.com/bluwy/giget-core#readme
源码仓库：https://github.com/bluwy/giget-core

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：27.7 kB，10 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- Node.js 要求：\>=18
- 运行依赖：1 个
- 首次发布：2024-10-07T08:26:21.560Z
- 最新版本发布：2026-03-18T02:57:23.376Z
- 近 30 天下载量：282217（2026-10-09 至 2026-11-07，npm 官方下载统计）
- 已发布版本数：8（近 12 个月 1 个）

## 中文简介

从 git repo 或 tarball URL 下载模板

## 安装

```sh
npm install @bluwy/giget-core
```

也可以使用：`pnpm add @bluwy/giget-core`、`yarn add @bluwy/giget-core`、`bun add @bluwy/giget-core`

## README

# @ bluwy/ giget- core (英语)

一个 JavaScript API 从 git 仓库或 URL 下载模板. 该代码主要基于 [吉娃娃](https://github.com/unjs/giget) (并包括其许可证),但有以下差异:

-   只有JavaScript API. (简体中文). CLI和无关的API被剥去.
-   依赖性减少到只有1个([现代塔尔](https://github.com/ayuhito/modern-tar)) (中文(简体) ).
-   减少了输入和输出 API 表面.
-   已删除自定义注册和 JSON 模板支持 .
-   删除 `GIGET_` 特殊环境变量支持.
-   删除自动获取代理支持 .
-   支持获取寄存器的默认分支 .
-   额外的API公用事业.
-   节点18和无害环境管理.

见 [从巨头移走](https://npmcn.com/package/%40bluwy/giget-core/#readme-migrate-from-giget) 如何迁移到 `@bluwy/giget-core`。 。 。 .

## 使用量

API 有大量文献记载于 [./src/index.d.ts (中文(简体) )](https://npmcn.com/package/%40bluwy/giget-core/src/index.d.ts)下面是使用这些工具的一些例子:

### `downloadTemplate`

用给定的输入字符串下载模板 .

```js
import { downloadTemplate } from '@bluwy/giget-core'

// Basic usage. Download from github repo.
const result = await downloadTemplate('unjs/template')
// info: { ... } - The template information parsed by providers
// dir: '...' - The directory where the template is downloaded to
// source: '...' - The source URL of the template (Prefix like `gh:` is stripped)

// Other input syntaxes
await downloadTemplate('unjs/template/subdir')
await downloadTemplate('unjs/template#main')
await downloadTemplate('gh:unjs/template')
await downloadTemplate('gitlab:unjs/template')
await downloadTemplate('bitbucket:unjs/template')
await downloadTemplate(
  'https://api.github.com/repos/unjs/template/tarball/main',
)

// Download to a specific directory (relative to cwd)
await downloadTemplate('unjs/template', { dir: 'my-project' })

// Download to a directory even if it has existing content
// (merges directories and replaces matching files)
await downloadTemplate('unjs/template', { force: true })

// Clean directory before downloading to it
await downloadTemplate('unjs/template', { force: 'clean' })

// Use offline cache only
await downloadTemplate('unjs/template', { offline: true })

// Use offline cache if available, otherwise download
await downloadTemplate('unjs/template', { offline: 'prefer' })

// Specify provider explicitly (if input has a provider prefix, it'll
// take precedence instead)
await downloadTemplate('unjs/template', { provider: 'gitlab' })

// Pass authentication token to access private repositories
// (handled by providers to pass as headers when downloading the tarball)
await downloadTemplate('unjs/template', { providerOptions: { auth: 'xxx' } })
```

### `verifyTemplate`

检查模板是否有效 。 需要网络访问.

```js
import { verifyTemplate } from '@bluwy/giget-core'

await verifyTemplate('unjs/template') // true
await verifyTemplate('unjs/template/subdir') // true
await verifyTemplate('unjs/template#main') // true
await verifyTemplate('gh:unjs/template') // true
await verifyTemplate('gitlab:unjs/template') // true
await verifyTemplate('bitbucket:unjs/template') // true
await verifyTemplate('https://api.github.com/repos/unjs/template/tarball/main') // true

await verifyTemplate('unjs/non-existent-repo') // false
await verifyTemplate('unjs/template/not-existent-subdir') // false
await verifyTemplate('unjs/template#not-existent-branch') // false
```

### `parseGitURI`

分析一个输入( 例如 ). `'owner/repo/templates/foo#main'`改为a `GitInfo` 对象。 对需要解析给定输入的自定义提供者有用 .

```js
import { parseGitURI } from '@bluwy/giget-core'

parseGitURI('owner/repo') // { repo: 'owner/repo', subdir: '/' }
parseGitURI('owner/repo/subdir') // { repo: 'owner/repo', subdir: '/subdir' }
parseGitURI('owner/repo#main') // { repo: 'owner/repo', subdir: '/', ref: 'main' }
parseGitURI('owner/repo/subdir#main') // { repo: 'owner/repo', subdir: '/subdir', ref: 'main' }
```

## 从巨头移走

`giget` 出口a `downloadTemplate` (a) 方案辅助规划。 如果设置了任何选项,可能需要调整如下:

-   这个 `forceClean` 选项合并为 `force: 'clean'`。 。 。 .
-   这个 `preferOffline` 选项合并为 `offline: 'prefer'`。 。 。 .
-   这个 `registry` 选项将删除。 您不能再下载主机的模板 [千兆重现](https://github.com/unjs/giget/tree/main/templates)。通过直接沥青球 URL 或 git repo 代替.
-   这个 `install` 财务报告和审定财务报表 `silent` 删除用于安装依赖关系的选项。 您应该自己手动安装依赖性 . `giget` 用途 [yp](https://github.com/unjs/nypm) 在引擎盖下.
-   这个 `auth` 选项已移动到 `providerOptions.auth`。 。 。 .
-   这个 `TemplateProvider` 财务报告和审定财务报表 `TemplateInfo` 接口 `providers` 选项将略作修改.
    -   `TemplateProvider`: 函数必须返回 a `TemplateInfo` 而不是无效。 如果它不能处理某事,它应该尝试一个有用的错误.
    -   `TemplateInfo`:它不再允许返回对象中的任意键.
-   返回的对象有: `TemplateInfo` 编辑 `info` 属性而不是在返回对象上展开.
-   `GIGET_` 环境变量支持被删除。 相反,它们应作为明确的选择予以通过.
-   自动获取代理支持被删除 。 要重新启用,请使用Node.js [页:1](https://nodejs.org/en/blog/release/v22.21.0) 及以上,并设定 `NODE_USE_ENV_PROXY=1` 在环境变量中。 见 [节点.js 文件](https://nodejs.org/api/http.html#built-in-proxy-support) 更多信息.

## 归属

如上所述,该项目在很大程度上基于 [吉娃娃](https://github.com/unjs/giget)谢谢 [@ pi0 (韩语)](https://github.com/pi0) 原作和战斗测试.

将来,我希望这里的代码可以合并到 `giget`,也许作为一个 `giget-core` 图书馆,并拥有 `giget` CLI作为包装库.

## 许可证

麻省理工学院

## 常见问题

### @bluwy/giget-core 是什么？

从 git repo 或 tarball URL 下载模板

### 如何安装 @bluwy/giget-core？

在项目目录运行 npm install @bluwy/giget-core，或使用 pnpm add / yarn add / bun add。

### @bluwy/giget-core 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @bluwy/giget-core 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @bluwy/giget-core 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=18。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @bluwy/giget-core 可以商用吗？

@bluwy/giget-core 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @bluwy/giget-core 的下载量有多少？

根据 npm 官方下载统计，@bluwy/giget-core 在 2026/10/09 – 2026/11/07 这 30 天内被下载 282,217 次，日均约 9,407 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @bluwy/giget-core 还在维护吗？

最新版本 0\.1\.7 发布于 2026/03/18（7 个月前）；至今共发布 8 个版本，其中过去 12 个月发布了 1 个；首次发布于 2024/10/07。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

