Skip to content

[Feature] Add .pklignore Support to Exclude Files from Swift Code Generation #59

@N3v1

Description

@N3v1

[Feature] Add .pklignore Support to Exclude Files from Swift Code Generation

Quick proposal for the project,

I’d like to suggest adding support for a .pklignore file to enable developers to explicitly exclude certain .pkl files or directories from processing by pkl-gen-swift. Adopting a .gitignore-style syntax would provide a familiar and flexible mechanism.

In larger projects, not all .pkl files are intended for code generation. Some serve as templates, test data, or partial configurations. Currently, there isn’t a straightforward way to opt out of processing these files, which can lead to unnecessary complexity or workarounds.

By supporting a .pklignore file at the package root, with glob patterns, negation (!), and comments (#), we can offer a clean, maintainable solution that integrates naturally with existing workflows. This filtering would apply during recursive file discovery both in the CLI tool (pkl-gen-swift) and the Swift Package plugin (PklGenSwiftPlugin).

Proposed Layout

# Ignore all experimental schema files
Schemas/experimental/*.pkl

# Ignore all templates except CommonTypes.pkl
Templates/
!Templates/CommonTypes.pkl

# Ignore all test pkl files anywhere
Tests/**/*.pkl

# Ignore any hidden .pkl files (starting with a dot)
.*.pkl

# Re-include a specific config file deep in the folder structure
!Configs/Release/ImportantConfig.pkl

Proposed Design

  • loadPklIgnorePatterns(from:) — reads and parses the .pklignore file.
  • shouldIgnore(path:patterns:) — checks if a given path matches ignore patterns.
  • filteredPklFiles(in:) — enumerates .pkl files applying the ignore filter.

Proposed Behavior

During file enumeration, PklSwiftGenerator would call filteredPklFiles(in:) instead of enumerating all .pkl files, allowing it to respect ignore patterns loaded by loadPklIgnorePatterns(from:).

This behavior would apply consistently in both the standalone CLI usage of pkl-gen-swift and when invoked via the Swift Package plugin, ensuring that ignored files are excluded regardless of how code generation is triggered.

Note

This feature is currently blocked by issue #19, which introduces the Swift Package plugin. Once that is merged, implementation of .pklignore support can proceed.


I would be glad to contribute this enhancement if it aligns with the project’s goals.

Thank you for considering this suggestion. Looking forward to your thoughts!

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