Skip to content

ziggy:generate --types=<nested path> fails unless the target directory already exists #883

@ruttydm

Description

@ruttydm

I found a CLI issue in tighten/ziggy v2.6.1.

When using a custom nested path for --types, the command writes the file directly but does not ensure the target directory exists.

Repro

php artisan ziggy:generate --types=tmp/ziggy-audit/nested/ziggy.d.ts --types-only

This fails with:

file_put_contents(.../tmp/ziggy-audit/nested/ziggy.d.ts): Failed to open stream: No such file or directory

Why it happens

CommandRouteGenerator ensures the directory for the main JS output path exists, but the custom types path is written later with no corresponding ensureDirectoryExists() call.

Expected

If a custom --types path is provided, Ziggy should create its parent directory before writing the file, just like it already does for the main output path.

Actual

The command fails unless the directory was pre-created manually.

Relevant code

  • src/CommandRouteGenerator.php
  • main output path setup around the initial ensureDirectoryExists() call
  • custom --types write path later in the command

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions