@bluwy/giget-core

中文文档
0.1.7发布于 2026/03/18MITTypeScriptES Module近 30 天下载 28.2万

Download template from a git repo or tarball URL

原始使用文档
文档目录7 节
  1. Usage
  2. downloadTemplate
  3. verifyTemplate
  4. parseGitURI
  5. Migrate from giget
  6. Attribution
  7. License

@bluwy/giget-core

A JavaScript API to download a template from a git repository or URL. The code is largely based on giget (and includes its license), but with the following differences:

  • Only the JavaScript API. The CLI and unrelated APIs are stripped off.
  • Reduced dependencies to only 1 (modern-tar).
  • Reduced input and output API surface.
  • Removed custom registries and JSON template support.
  • Removed GIGET_ special environment variables support.
  • Removed automatic fetch proxy support.
  • Supports fetching the default branch of a repository.
  • Additional API utilities.
  • Node >=18 and ESM only.

See Migrate from giget for how to migrate to @bluwy/giget-core.

Usage

The API is heavily documented in ./src/index.d.ts. Below shows some examples of using them:

downloadTemplate

Download a template with a given input string.

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

Check whether the template is valid. Requires network access.

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

Parse an input (e.g. 'owner/repo/templates/foo#main') into a GitInfo object. Useful for custom providers that need to parse the given input.

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' }

Migrate from giget

giget exports a downloadTemplate programmatic API as well. If you have set any options, you may need to adjust them as below:

  • The forceClean option is merged as force: 'clean'.
  • The preferOffline option is merged as offline: 'prefer'.
  • The registry option is removed. You can no longer download templates hosted from the giget repo. Pass the direct tarball URL or git repo instead.
  • The install and silent options used for installing dependencies is removed. You should manually install the dependencies yourself. giget uses nypm under the hood.
  • The auth option is moved to providerOptions.auth.
  • The TemplateProvider and TemplateInfo interfaces used by the providers option is slightly changed.
    • TemplateProvider: The function must return a TemplateInfo instead of null. If it fails to handle something, it should try a helpful error.
    • TemplateInfo: It no longer allows returning arbitrary keys in the object.
  • The returned object has the TemplateInfo on the info property instead of spreading on the returned object.
  • GIGET_ environment variables support is removed. They should be passed as explicit options instead.
  • Automatic fetch proxy support is removed. To re-enable, use Node.js v22.21.0 and above, and set NODE_USE_ENV_PROXY=1 in your environment variables. See the Node.js docs for more information.

Attribution

As mentioned above, this project is based heavily on giget! Thanks @pi0 for the original work and battle-testing it.

In the future, I hope the code here can be merged back to giget, perhaps as a giget-core library, and have the giget CLI as a wrapper library.

License

MIT

版本与发布记录

@bluwy/giget-core 共发布 8 个版本,首次发布于 2024/10/07;过去 12 个月发布了 1 个版本。

版本发布日期距今
0.1.7latest2026/03/187 个月前
0.1.62025/10/021.1 年前
0.1.52025/10/011.1 年前
0.1.42025/09/301.1 年前
0.1.32025/07/011.4 年前
0.1.22024/11/271.9 年前

关于 @bluwy/giget-core 的常见问题

@bluwy/giget-core 是什么?

Download template from a git repo or 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 和提交记录判断。