Skip to content

Conditional generation is skipped for nested template paths on Windows #2224

Description

@rajanpanth

Describe the bug

conditionalGeneration (and the deprecated conditionalFiles) keys are written with POSIX separators in a template's config, for example conditionalFolder2/input.txt. The lookups in apps/generator/lib/generator.js build their key with path.relative, which returns backslashes on Windows, so a nested key never matches and the condition is silently ignored.

Executed on win32:

path.relative gives : "conditionalFolder2\input.txt"
config key is       : "conditionalFolder2/input.txt"
lookup matches?     : false

Because the lookup misses, shouldGenerate stays true and the file is generated even when its condition fails. An end-to-end run against the repository's own test template, with singleFile: 'true' (which fails the enum: ["false"] validation), shows the top-level cases behaving correctly while the nested one does not:

conditionalFile.txt exists          (expected false): false
conditionalFolder exists            (expected false): false
conditionalFolder2/input.txt exists (expected false): true   <-- bug

The existing nested-path test only asserts the "should generate" direction, so it passes either way and the regression is invisible on the Windows CI leg.

There is a second, platform-independent part. When a conditionalFiles entry matches, the code sets conditionalPath to the top-level directory rather than the file key:

conditionalPath = relativeSourceDirectory;

so isGenerationConditionMet finds no config for that path and returns undefined. On POSIX that means a file whose condition is met gets skipped. The documented example in configuration-file.md uses a nested key, so documented usage is affected.

Expected behavior

A nested conditionalGeneration or conditionalFiles key is matched on every platform, and a matching conditionalFiles entry is evaluated against its own key.

How to Reproduce

Run the generator on Windows with a template whose config has a nested conditionalGeneration key and a parameter that fails the condition; the file is generated anyway. Output above is from executed runs.


I have a fix with regression tests ready and would like to open a PR for this.

Generated-by: Claude Code 2.x

AI assisted in investigating this bug and drafting this issue. I have reviewed and verified the analysis and the reproduction output myself.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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