Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: onCheckCode hook not working for windows #12730

Merged
merged 13 commits into from
Nov 14, 2024
6 changes: 5 additions & 1 deletion packages/preset-umi/src/features/check/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ export default (api: IApi) => {
});

function isAbsolutePath(path: string) {
return path.startsWith('/') || path.startsWith('@fs/');
return (
path.startsWith('/') ||
path.startsWith('@fs/') ||
/^[A-Za-z]:\//.test(path) // fix windows path after transform by winPath method
);
}
};
8 changes: 4 additions & 4 deletions packages/preset-umi/src/features/transform/babelPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export default function () {
) {
opts.onCheckCode({
args: {
...cache.get(state.opts.filename),
file: state.opts.filename,
isFromTmp: state.opts.filename.startsWith(opts.absTmpPath),
...cache.get(filename),
file: filename,
isFromTmp: filename.startsWith(opts.absTmpPath),
},
});
}
Expand All @@ -48,7 +48,7 @@ export default function () {
enter(path: Babel.NodePath<t.Program>, state: any) {
opts = state.opts;
// @ts-ignore
const file = path?.hub.file.opts.filename;
const file = winPath(path?.hub.file.opts.filename);
// @ts-ignore
const cache = this.cache;
// reset cache
Expand Down
Loading