Skip to content

fix(image-imports): normalize meta specifier separators on Windows - #1791

Merged
james-elicx merged 1 commit into
cloudflare:mainfrom
shulaoda:06-06-fix_image-imports_normalize_meta_specifier_separators_on_windows
Jun 6, 2026
Merged

fix(image-imports): normalize meta specifier separators on Windows#1791
james-elicx merged 1 commit into
cloudflare:mainfrom
shulaoda:06-06-fix_image-imports_normalize_meta_specifier_separators_on_windows

Conversation

@shulaoda

@shulaoda shulaoda commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Normalize the resolved image path with normalizePathSeparators before embedding it in the ?vinext-meta import specifier.
  • Update the image-imports test to assert the forward-slash specifier, using the same helper.

Background

The vinext:image-imports transform rewrites import hero from './x.png' into a URL import plus a ?vinext-meta import that carries the image dimensions. The meta import embeds the resolved absolute path:

import __vinext_img_meta_hero from "E:\\...\\x.png?vinext-meta"; // Windows, before
import __vinext_img_meta_hero from "E:/.../x.png?vinext-meta"; // after

On Windows path.resolve produces backslashes, so the generated specifier used backslashes — inconsistent with POSIX output and against the ESM convention that module specifiers use forward slashes.

Note

This is a consistency/robustness fix, not a crash fix. Verified against a real Vite build: a backslash specifier is passed to resolveId unchanged (Vite does not normalize it), and the plugin's slash-agnostic resolveId/load plus Node's fs (which accepts forward slashes on Windows) handle it either way. Normalizing keeps generated output identical across platforms and avoids relying on tools tolerating non-standard backslash specifiers.

Test plan

  • pnpm test tests/image-imports.test.ts — 18 pass (6 previously failed on Windows due to the assertion expecting native separators)
  • Linux/macOS: no behavior change (normalizePathSeparators is a no-op on POSIX)

@pkg-pr-new

pkg-pr-new Bot commented Jun 6, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@vinext/cloudflare@1791
npm i https://pkg.pr.new/vinext@1791

commit: 9989592

@james-elicx
james-elicx merged commit a75ae51 into cloudflare:main Jun 6, 2026
29 checks passed
@github-actions github-actions Bot mentioned this pull request Jun 6, 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