laravel/chisel 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

laravel/chisel

Composer 安装命令:

composer require laravel/chisel

包简介

Toolkit for building scripts that remove unwanted code, files, and dependencies.

README 文档

README

Build Status Total Downloads Latest Stable Version License

Introduction

Laravel Chisel provides primitives for building post-install scripts that remove unwanted features from Laravel starter kits. Compatible starter kits include a chisel.php script that defines the optional features and the file mutations needed to remove them.

Installation

composer require laravel/chisel

Usage

An example chisel.php script for optional email verification might look like this:

<?php

require getenv('LARAVEL_INSTALLER_AUTOLOADER');

use Laravel\Chisel\Chisel;
use Laravel\Chisel\Question;

return Chisel::script(dirname(__DIR__))
    ->questions([
        Question::multiselect(
            name: 'auth_features',
            label: 'Which authentication features would you like to enable?',
            options: [
                'email-verification' => 'Email verification',
            ],
            hint: 'Use space to select, enter to confirm.',
        ),
    ])
    ->selected('auth_features', 'email-verification',
        then: function (Chisel $c) {
            $c->files(
                'resources/js/pages/settings/profile.tsx',
                'app/Providers/FortifyServiceProvider.php',
            )->removeSectionMarkers('email-verification');
        },
        else: function (Chisel $c) {
            $c->php('app/Models/User.php')
                ->removeImport('Illuminate\Contracts\Auth\MustVerifyEmail')
                ->removeInterface('MustVerifyEmail');

            $c->file('config/fortify.php')->removeLinesContaining('Features::emailVerification()');

            $c->files(
                'app/Providers/FortifyServiceProvider.php',
                'resources/js/pages/settings/profile.tsx',
            )->removeSection('email-verification');

            $c->files(
                'resources/js/components/email-verification-notice.tsx',
                'resources/js/pages/auth/verify-email.tsx',
                'tests/Feature/Auth/EmailVerificationTest.php',
                'tests/Feature/Auth/VerificationNotificationTest.php',
            )->delete();
        },
    );

Although the questions are defined in the chisel.php file, an external process such as an Artisan command is responsible for rendering them and passing the answers to Chisel's chisel() method. An example Artisan command using Laravel Prompts might look like this:

use Illuminate\Console\Command;
use Laravel\Chisel\Chisel;
use Laravel\Chisel\Question;
use RuntimeException;

use function Laravel\Prompts\multiselect;

class InstallFeatures extends Command
{
    protected $signature = 'install:features
        {--answers= : JSON string of answers to skip interactive prompts}';

    public function handle(): void
    {
        $script = require base_path('chisel.php');

        $providedAnswers = $this->option('answers') === null
            ? []
            : json_decode((string) $this->option('answers'), true, 512, JSON_THROW_ON_ERROR);

        $answers = $script
            ->collectAnswers()
            ->onQuestion(fn (Question $question) => match ($question->type) {
                'multiselect' => multiselect(
                    label: $question->label,
                    options: $question->options,
                    default: $question->default ?? [],
                    required: $question->required,
                    hint: $question->hint,
                ),
                default => throw new RuntimeException("Unsupported question type [{$question->type}]."),
            })
            ->interactive($this->input->isInteractive())
            ->withAnswers($providedAnswers);

        $script->chisel($answers);

        $chisel = Chisel::in(base_path());

        $chisel->npm()->install();
        $chisel->npm()->run('build');
    }
}

Script Definitions

Method Purpose
Chisel::script($directory) Create a script definition
Question::multiselect(...) Define a multiselect question
questions([...]) Set the script's questions
questions() Retrieve the registered questions
collectAnswers() Begin collecting answers for registered questions
apply($callback) Register an unconditional mutation step
selected($key, $value, then:, else:) Branch on a multiselect answer
selectedAny($key, $values, then:, else:) Branch when any of the given values are selected
selectedAll($key, $values, then:, else:) Branch when all of the given values are selected
chisel($answers) Execute the registered mutations

Answer Collection

collectAnswers() returns a pending answer collector. All methods are fluent and can be called in any order. Answers are resolved when the object is used as an array or toArray() is called. When non-interactive, defaults are used automatically.

Method Purpose
onQuestion($callback) Handle question prompts
interactive($interactive) Configure whether missing answers are prompted interactively
withAnswers($answers) Provide pre-collected answers to skip prompting

File Mutations

file($path) targets a single file. files(...$paths) targets multiple files.

Method Purpose
replace($search, $replace) Replace a string
removeLinesContaining($content) Remove lines containing a string
removeSectionMarkers($tag) Strip section markers, keep the content
removeSection($tag) Remove section markers and the content inside them
delete() Delete the targeted files

PHP File Mutations

php($path) provides AST-based edits. Changes are saved automatically when the object is destroyed.

Method Purpose
removeImport($class) Remove a use statement
removeTrait($trait) Remove a trait usage from the class
removeInterface($interface) Remove an implemented interface

npm

Method Purpose
npm()->install() Install dependencies using the detected package manager
npm()->run($script, ...$arguments) Run a package manager script
npm()->remove(...$packages) Remove packages using the detected package manager

The npm() method detects npm, yarn, pnpm, and bun automatically.

Section Markers

Wrap optional code in comment pairs:

/* @chisel-passkeys */
Fortify::authenticateUsingPasskeys();
/* @end-chisel-passkeys */

JSX files may use block comments with braces:

{
    /* @chisel-passkeys */
}
<PasskeyButton />;
{
    /* @end-chisel-passkeys */
}

removeSectionMarkers('passkeys') keeps the code and removes the markers. removeSection('passkeys') removes both. The chisel- marker prefix is added automatically.

Contributing

Thank you for considering contributing to Chisel! The contribution guide can be found in the Laravel documentation.

Code of Conduct

In order to ensure that the Laravel community is welcoming to all, please review and abide by the Code of Conduct.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

License

Laravel Chisel is open-sourced software licensed under the MIT license.

laravel/chisel 适用场景与选型建议

laravel/chisel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 446.47k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2026 年 05 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「chisel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 laravel/chisel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 laravel/chisel 我们能提供哪些服务?
定制开发 / 二次开发

基于 laravel/chisel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 446.47k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 53
  • 依赖项目数: 20
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-13