@adonisjs/presets

中文文档
3.0.0发布于 2026/02/25MITES Module零依赖构建来源已验证近 30 天下载 64.1万

A collection of presets to configure AdonisJS packages

原始使用文档

AdonisJS presets

These presets are a collection of functions you can execute to configure an AdonisJS package. This repo contains presets only for those packages that can be configured from multiple user interactions.

For example: When you create a new AdonisJS application, you can configure Lucid and also you can create a new app without Lucid and configure it later.

So, instead of duplicating the code in multiple places, we create re-usable presets and use them with individual packages and the create-adonisjs initializer.

[!NOTE] Presets do not trigger any prompts and exposes a coding interface.

Auth preset

The auth presets configures the @adonisjs/auth package. The package must be installed to run this preset.

import { Kernel } from '@adonisjs/core/ace'
import { Application } from '@adonisjs/core/app'
import { presetAuth } from '@adonisjs/presets/auth'
import { Codemods } from '@adonisjs/core/ace/codemods'

/**
 * Create application instance. Inside an Ace command, you
 * get access to it using `this.app` property.
 */
const app = new Application(baseURL, {
  importer: () => {},
})

/**
 * Create Ace kernel instance to get CLI logger reference.
 * Inside an Ace command you can access it using this.logger
 * property.
 */
const cliLogger = new Kernel(app).ui.logger

/**
 * Create codemods instance. Codemods are needed to modify
 * source files.
 */
const codemods = new Codemods(app, cliLogger)

/**
 * Apply preset
 */
await presetAuth(codemods, app, {
  guard: 'session',
  userProvider: 'lucid',
})

Lucid preset

The auth presets configures the @adonisjs/lucid package. The package must be installed to run this preset.

import { Kernel } from '@adonisjs/core/ace'
import { Application } from '@adonisjs/core/app'
import { presetLucid } from '@adonisjs/presets/lucid'
import { Codemods } from '@adonisjs/core/ace/codemods'

/**
 * Create application instance. Inside an Ace command, you
 * get access to it using `this.app` property.
 */
const app = new Application(baseURL, {
  importer: () => {},
})

/**
 * Create Ace kernel instance to get CLI logger reference.
 * Inside an Ace command you can access it using this.logger
 * property.
 */
const cliLogger = new Kernel(app).ui.logger

/**
 * Create codemods instance. Codemods are needed to modify
 * source files.
 */
const codemods = new Codemods(app, cliLogger)

/**
 * Apply preset
 */
await presetLucid(codemods, app, {
  dialect: 'sqlite',
  installPackages: true,
})

版本与发布记录

@adonisjs/presets 共发布 25 个版本,首次发布于 2023/12/24;过去 12 个月发布了 2 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
3.0.0latest2026/02/258 个月前
3.0.0-next.1next2026/01/159 个月前
3.0.0-next.02025/09/221.1 年前
2.6.42024/12/191.9 年前
2.6.32024/09/112 年前
2.6.22024/09/092 年前

关于 @adonisjs/presets 的常见问题

@adonisjs/presets 是什么?

A collection of presets to configure AdonisJS packages

如何安装 @adonisjs/presets?

在项目目录运行 npm install @adonisjs/presets,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@adonisjs/core(^7.0.0-next.1 || ^7.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@adonisjs/presets 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/adonisjs__presets 是否存在。

@adonisjs/presets 支持 ESM 还是 CommonJS?

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

@adonisjs/presets 需要什么版本的 Node.js?

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

@adonisjs/presets 可以商用吗?

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

@adonisjs/presets 的下载量有多少?

根据 npm 官方下载统计,@adonisjs/presets 在 2026/10/05 – 2026/11/03 这 30 天内被下载 641,238 次,日均约 21,375 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@adonisjs/presets 还在维护吗?

最新版本 3.0.0 发布于 2026/02/25(8 个月前);至今共发布 25 个版本,其中过去 12 个月发布了 2 个;首次发布于 2023/12/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。