Skip to content

feat(cli): add --placeholder and --select-* flags - #30

Merged
dangreen merged 1 commit into
mainfrom
feat/cli-placeholder-select-flags
Sep 1, 2026
Merged

feat(cli): add --placeholder and --select-* flags#30
dangreen merged 1 commit into
mainfrom
feat/cli-placeholder-select-flags

Conversation

@dangreen

@dangreen dangreen commented Sep 1, 2026

Copy link
Copy Markdown
Member

The placeholder and the module's default export could only be configured from srcset.config.js. They are arguments now, so a run needs no config file at all:

srcset "src/images/**/*.jpg" -d src/baked --module ts -w 1,0.5 -f jpg,webp \
  --placeholder --placeholder-width 24 --select-format webp
Flag
--placeholder Adds the placeholder export. --no-placeholder switches off one enabled in the config.
--placeholder-width, --placeholder-format 16 and webp by default, webp or jpg. Either one implies --placeholder.
--select-id, --select-format, --select-width Which variant the default export points at.

An unknown placeholder format is rejected the way --module is: Unknown placeholder format: "png". Use webp or jpg.

args.ts stays a plain argv reader — the assembly and the validation live in toCliOptions, next to toModuleFormat, which is where the merge with the config file happens. Like rules, the arguments replace the config value rather than merging into it.

What still needs a config file

Only what an argument cannot carry: more than one rule, and the options that are functions or nested objects — resourceId, optimization, processing, and postfix as a formatter. A string postfix is deliberately left out: it is applied verbatim to every variant, so with several widths they would all resolve to one output path and the run would stop on the collision guard.

Verified end to end: --placeholder emits a webp data-url, --placeholder-width 8 --placeholder-format jpg a jpeg one, --select-format webp makes the module's url the webp variant, and --no-placeholder beats placeholder: true from the config. The cli suite goes from 46 to 56.

Everything a value can express is an argument now, so a run needs no
config file: `--placeholder`, `--placeholder-width` and
`--placeholder-format` shape the placeholder export, and `--select-id`,
`--select-format` and `--select-width` pick the variant the default
export points at. A width or a format switches the placeholder on by
itself, and `--no-placeholder` turns off one enabled in the config. The
config file stays necessary for what an argument cannot carry: more than one rule, and the options that are functions or nested objects.
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 33515237877

Coverage increased (+0.2%) to 93.871%

Details

  • Coverage increased (+0.2%) from the base build.
  • Patch coverage: 15 of 15 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 890
Covered Lines: 843
Line Coverage: 94.72%
Relevant Branches: 660
Covered Branches: 612
Branch Coverage: 92.73%
Branches in Coverage %: Yes
Coverage Strength: 79355.96 hits per line

💛 - Coveralls

@dangreen
dangreen merged commit 60c1430 into main Sep 1, 2026
7 checks passed
@dangreen
dangreen deleted the feat/cli-placeholder-select-flags branch September 1, 2026 13:54
@github-actions github-actions Bot mentioned this pull request Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants