fix(site-import): resolve assets below exporter archive roots - #405
fix(site-import): resolve assets below exporter archive roots#405tommy230 wants to merge 1 commit into
Conversation
DavidBabinec
left a comment
There was a problem hiding this comment.
Thanks for tracking this down; a WordPress export that stores files under passthrough/ while the HTML references them root-relative is a real gap, and the two tests describe it well.
Two things need changing before this can land:
-
The branch predates #349, which replaced the single exact lookup with
resolveFileMapKey(punctuation-insensitive matching plus theunresolved-assetwarning). The PR now conflicts withmain, and the fallback belongs inside that resolver chain rather than in front of it. -
passthrough/is not an Instatic convention (nothing in the repo produces or documents it), so a hardcoded prefix bakes one exporter's private layout into core. A general fallback covers it without the magic string: after the exact and normalised misses, match the resolved path as a unique suffix of a FileMap key (sowp-content/uploads/x.pngfindspassthrough/wp-content/uploads/x.png, and any other storage prefix, while an ambiguous suffix stays unresolved and warns, matching the uniqueness rule #349 already applies). The "exact key wins" test still holds under that shape.
If you rebase onto main and move the fallback into resolveFileMapKey as a suffix match, this is an easy merge. Happy to review again quickly.
7d0464a to
6d5235f
Compare
|
Rebased onto current main and moved the fallback into resolveFileMapKey after exact and punctuation-insensitive lookup. The hardcoded passthrough/ retry is gone; the resolver now uses a cached unique path-segment suffix index, while ambiguous suffixes stay unresolved and emit the existing warning. I kept the reported WordPress regression and exact-key precedence coverage, and added tests for suffix ambiguity and segment boundaries. Verification is clean: bun run build, bun run lint, and bun test with 6,831 pass and 0 fail. @DavidBabinec ready for another look when you have a moment. |
Summary
A WordPress export can store media below an extra archive directory while its HTML references the same files from the archive root. The import uploaded those unreferenced files during its media sweep, but resolveFileMapKey could not connect the HTML references to their bytes, so the published page kept broken image URLs.
resolveFileMapKey now tries a unique path-segment suffix after exact and punctuation-insensitive lookup. The suffix index is built lazily once per import. Exact keys still win, and suffix collisions remain unresolved and emit the existing unresolved-asset warning instead of choosing a file.
Coverage keeps the reported passthrough/wp-content case and adds exact-key precedence, ambiguous suffixes, and path-segment boundary behavior. The site-import pipeline documentation now describes exporter-specific archive directories rather than treating passthrough/ as an Instatic convention.
Verification
The reported root-relative asset test fails on current main before the resolver change and passes on this branch.
Checklist