Skip to content

fix: normalize config context loaded by jiti - #7

Closed
stormslowly wants to merge 1 commit into
rstackjs:mainfrom
stormslowly:fix/jiti__dirname_workaround
Closed

fix: normalize config context loaded by jiti#7
stormslowly wants to merge 1 commit into
rstackjs:mainfrom
stormslowly:fix/jiti__dirname_workaround

Conversation

@stormslowly

Copy link
Copy Markdown

Why

jiti rewrites __dirname to a POSIX-style path on Windows (D:/a/project), so a config written as context: __dirname reaches the bundler with forward slashes. rspack keeps that value as the resolver base and emits mixed-separator dependency paths, while watchpack rebuilds incoming OS event paths with path.join:

registered: d:/a\project\src\app.tsx   (mixed, from a forward-slash context)
fs event  : d:\a\project\src\app.tsx   (path.join => all backslash)
=> mismatch => the change is ignored

That is web-infra-dev/rspack#14446: on Windows, file watching stops after the first change.

What

Normalize the context field of the loaded config — every entry when the config is an array — to the native separator, and only when the config went through jiti. A natively loaded config already sees a native __dirname, so it is left untouched.

normalizeContext lives in src/jiti.ts so the whole workaround can be dropped in one place once jiti stops rewriting __dirname.

loader context: 'D:/a/project' on Windows
jiti D:\a\project
native D:/a/project (unchanged)

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