Skip to content

Add a transform hook filter and release 2.0.0 - #43

Open
toeknee-figma wants to merge 1 commit into
fix/transform-correctnessfrom
feat/transform-hook-filter
Open

Add a transform hook filter and release 2.0.0#43
toeknee-figma wants to merge 1 commit into
fix/transform-correctnessfrom
feat/transform-hook-filter

Conversation

@toeknee-figma

@toeknee-figma toeknee-figma commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

Third of three stacked PRs. Based on #42, which is based on #41 — the diff here is just the hook filter, the changelog and the version bump.

Hook filter

Rolldown and Rollup 4.38+ read transform.filter and skip the handler entirely for ids that miss it, so the plugin stops being called for every non-YAML module in the graph. Fixes #37 — thanks @TheAlexLichter for the pointer to the rolldown guidance.

transform: {
  filter: { id: { include: yamlExtension, exclude: specialQuery } },
  handler(code, id) { ... }
}

Older versions ignore filter and call handler as before. I checked that the object hook form itself resolves correctly all the way back to the >=3.2.7 floor in peerDependencies — Vite 3.2.7 already does 'handler' in hook ? hook.handler : hook — so the supported range is unchanged and no peer bump is needed.

The handler keeps its own checks. The filter narrows which ids reach it; it does not replace include/exclude, whose picomatch semantics differ from a hook filter's, and folding one into the other would quietly change which files users' existing patterns match.

2.0.0

Major for two breaking changes, both in #42: the raw option is gone, and a circular anchor now raises an error instead of emitting a {$circularReference:1} placeholder where the data should be.

Worth being clear about the trade-off: in practice nothing that currently works breaks, since raw emitted [object Object] for any mapping and the placeholder was already corrupt data. A major means everyone on ^1.1.1 has to opt in, so the js-yaml advisory fix will not reach them automatically. A 1.1.2 backport would close that gap if wanted.

Disposition of the remaining issues

Each was investigated against a real build or dev server, then put through an independent reviewer whose job was to refute it. All five reviewers dissented on something, and two of those dissents changed the outcome.

#3 sourcemaps — close, no code change. map: { mappings: '' } is the only option that produces no warning and no fabricated positions and no bloat. map: null also silences the warning but projects generated-JS columns onto YAML lines, emitting a knowingly wrong map, and drags the YAML into the bundle sourcemap — measured at 183 KB of map for a 172 KB YAML versus 272 bytes today. Omitting map is the only variant that warns, so PR #9's 2022 fix was right and still is. One correction worth recording: an empty map is a chain terminator, not a neutral no-op — a plugin transforming the same module afterwards has its map discarded. Accepted deliberately, since the output is a single JSON.parse("…") with no original position to point at.

#16 Storybook — close as not reproducible. Built the matrix: Storybook 7.0/7.6/9.1 against Vite 4.1/4.5/5.4/7.3, on both the published 1.1.1 and this branch, build and dev, including a real browser HMR edit. Every combination passed, including on 1.1.1 — so this stack cannot be claimed to fix it. The reporter's exact Parse error @:1:NN was reproduced by a different mechanism: the plugin absent from the config Storybook builds with, where the column is just the length of line 1 and the error only takes that cryptic form when line 1 contains a quote. That matches reporter 1's description precisely. Reporter 2's symptom is genuinely unexplained and needs a repro.

#19 !import — close with an answer, do not build the tag. The reviewer showed the reporter's use case already works with no plugin change: split the file, then a three-line module that imports the parts and spreads them. Verified on a real Vite 7 dev server that editing an imported YAML file propagates correctly through the module graph. It also gets the precedence the reporter actually asked for — later spread wins — whereas the YAML merge key (<<:) gives the opposite, so recommending <<: would have answered the maintainer's duplicate-key question wrongly.

#27 keyof typeof and the runtime half of #18 are still open; see the issues.

🤖 Generated with Claude Code

Rolldown and Rollup 4.38+ read `transform.filter` and skip the handler
entirely for ids that miss it, so the plugin no longer gets called for
every non-YAML module in the graph (#37). Older versions ignore the
field and invoke the handler exactly as before, which Vite has resolved
through the object hook form since well before the 3.2.7 floor in
peerDependencies, so the supported range is unchanged.

The handler keeps its own checks: the filter narrows which ids reach it,
it does not replace the include/exclude options, whose picomatch
semantics differ from a hook filter's.

Releasing as 2.0.0 for the removal of the `raw` option and for the
serializer no longer emitting a placeholder in place of a circular
reference.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@toeknee-figma
toeknee-figma force-pushed the feat/transform-hook-filter branch from 5a3ffe9 to f3e4647 Compare August 2, 2026 00:00
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.

1 participant