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 within on Windows #1804

Merged
merged 2 commits into from
Nov 7, 2024
Merged

fix within on Windows #1804

merged 2 commits into from
Nov 7, 2024

Conversation

mbostock
Copy link
Member

@mbostock mbostock commented Nov 7, 2024

Ref. #1792

@mbostock mbostock changed the title within tests fix within on Windows Nov 7, 2024
Comment on lines +10 to +11
export const toOsPath = sep === op.sep ? (path: string) => path : (path: string) => path.split(sep).join(op.sep);
export const fromOsPath = sep === op.sep ? (path: string) => path : (path: string) => path.split(op.sep).join(sep);
Copy link
Member Author

Choose a reason for hiding this comment

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

This doesn’t change functionality; just trivial optimization.

@mbostock mbostock marked this pull request as ready for review November 7, 2024 06:05
@mbostock mbostock requested a review from Fil November 7, 2024 06:05
@mbostock mbostock enabled auto-merge (squash) November 7, 2024 06:05
@@ -86,6 +87,7 @@ export function parseRelativeUrl(url: string): {pathname: string; search: string
}

export function within(root: string, path: string): boolean {
const {relative, normalize, resolve, isAbsolute} = op;
path = relative(normalize(resolve(root)), normalize(resolve(path)));
Copy link
Member Author

Choose a reason for hiding this comment

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

The main issue was that process.cwd() returns a “namespaced” absolute path starting with e.g. D:\, whereas resolve(path) returns a non-namespaced absolute path. See these logs for reference:

https://github.com/observablehq/framework/actions/runs/11717337869/job/32636834499

@mbostock mbostock merged commit 324c7eb into main Nov 7, 2024
4 checks passed
@mbostock mbostock deleted the mbostock/windows-within branch November 7, 2024 06:29
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