Skip to content

fix: handle drive-relative paths on windows#197

Merged
SuperchupuDev merged 4 commits intoSuperchupuDev:mainfrom
Andrej730:fix-windows-drive-rel-paths
Apr 12, 2026
Merged

fix: handle drive-relative paths on windows#197
SuperchupuDev merged 4 commits intoSuperchupuDev:mainfrom
Andrej730:fix-windows-drive-rel-paths

Conversation

@Andrej730
Copy link
Copy Markdown
Contributor

Resolves #196

Just when I thought I learned all Windows quirks, I've found one more...

Turned out, on Windows L: is not the same thing as L:\. It's called drive-relative path (see https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats#apply-the-current-directory) and L: ends up being replace with cwd.

import { resolve } from "node:path";

// cwd: L:\oblivion\tinyglobby
console.log("cwd:", resolve("."));
// resolve("L:"): L:\oblivion\tinyglobby
console.log('resolve("L:"):', resolve("L:"));
// resolve("L:/"): L:\
console.log('resolve("L:/"):', resolve("L:/"));
// resolve("L:\\"): L:\
console.log('resolve("L:\\"):', resolve("L:\\"));

In my case I've stumbled upon, I had L:\test1\repro.js running L:\test\*.py pattern while being in L:\test1 as cwd.
So naturally, glob have found a common root to start from - L:, but when absolute is set to true.

The call chain goes like this

glob calls .withPromise

return crawler ? formatPaths(await crawler.withPromise(), relative) : [];

Which constructs a Walker.

https://github.com/thecodrr/fdir/blob/790c182eb54809ea7bc14f1bcb40acce89506bb4/src/api/async.ts#L21

Which calls normalizePath.

https://github.com/thecodrr/fdir/blob/790c182eb54809ea7bc14f1bcb40acce89506bb4/src/api/walker.ts#L40

Which calls resolve on root, but only in case if resolvePaths is set.

https://github.com/thecodrr/fdir/blob/790c182eb54809ea7bc14f1bcb40acce89506bb4/src/utils.ts#L33-L39

Which is set, when constructing options for a crawler, from absolute option:

resolvePaths: absolute,

Since L: root comes from normalizePattern call, I've added a check to ensure it appends / in case it's drive-relative path to make it just abs path at drive root and added a test.

I've created a workflow to reproduce the issue before and after the fix https://github.com/Andrej730/tinyglobby/actions/runs/24131845264/job/70410134306

image

@SuperchupuDev can you please take a look?

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 11, 2026

Open in StackBlitz

npm i https://pkg.pr.new/tinyglobby@197

commit: f8c72fc

Copy link
Copy Markdown
Owner

@SuperchupuDev SuperchupuDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in addition to my comments, also remember to run biome so that ci is green 👍

Copy link
Copy Markdown
Owner

@SuperchupuDev SuperchupuDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for reporting the issue and sending a fix!!!! 👍

@SuperchupuDev SuperchupuDev merged commit 678c5bf into SuperchupuDev:main Apr 12, 2026
8 checks passed
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.

glob fails to return absolute paths on Windows in some cases

2 participants