Skip to content

Conversation

@MoLow
Copy link
Member

@MoLow MoLow commented Aug 20, 2022

Fixes: #41521

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. path Issues and PRs related to the path subsystem. labels Aug 20, 2022
@MoLow
Copy link
Member Author

MoLow commented Aug 20, 2022

CC @nodejs/path

@MoLow MoLow force-pushed the add-path-from-url branch 2 times, most recently from 400a742 to 7628fdd Compare August 20, 2022 22:26
@tniessen
Copy link
Member

Is my understanding correct that this API is essentially just typeof arg === 'string' ? arg : url.fileURLToPath(arg)?

Copy link
Contributor

@aduh95 aduh95 left a comment

Choose a reason for hiding this comment

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

Can we add tests for when the passed argument is not a string nor a URL instance?

@MoLow
Copy link
Member Author

MoLow commented Aug 21, 2022

Is my understanding correct that this API is essentially just typeof arg === 'string' ? arg : url.fileURLToPath(arg)?

correct. see #41521 (comment)

@MoLow MoLow force-pushed the add-path-from-url branch from 7628fdd to 430991e Compare August 21, 2022 16:22
@benjamingr
Copy link
Member

cc @sindresorhus

@MoLow MoLow force-pushed the add-path-from-url branch from 430991e to e23b518 Compare August 21, 2022 18:39
Copy link
Contributor

@aduh95 aduh95 left a comment

Choose a reason for hiding this comment

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

Can you add a test case with the empty string?

@MoLow MoLow force-pushed the add-path-from-url branch from e23b518 to 0841725 Compare August 22, 2022 09:16
@MoLow MoLow added the commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. label Aug 23, 2022
@MoLow MoLow requested review from benjamingr and tniessen August 23, 2022 12:47
Copy link
Member

@tniessen tniessen left a comment

Choose a reason for hiding this comment

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

I don't have a strong opinion on this PR; this already seems to be a one-liner in userland.

// Returns: 'C:\\path\\dir\\file.txt'
```

## `path.fromURL(pathOrUrl)`
Copy link
Member

Choose a reason for hiding this comment

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

Isn't the name misleading, given that the input is not necessarily a URL? In fact, URL strings of the form file:///home are ignored and not treated as URLs.

Copy link
Member Author

Choose a reason for hiding this comment

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

what would you consider to be a better name?

Copy link
Contributor

Choose a reason for hiding this comment

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

What about url.toPathIfFileURL?

Copy link
Contributor

Choose a reason for hiding this comment

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

Or maybe path.fromURLInstance?

// Returns: 'file:///Users/node/dev'

path.fromURL(new URL('file:///c:/foo.txt'));
// Returns On Windows: 'c:\\foo.txt'
Copy link
Member

Choose a reason for hiding this comment

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

I am still unsure if I like the fact that fromURL(URL) normalizes the path in an OS-specific manner while fromURL(string) does not. I would assume that

path.fromURL(url.pathToFileURL(absolutePath)) === path.fromURL(absolutePath)

but that does not seem to be true in all cases.

On the other hand, this seems to be what @sindresorhus expects.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree this makes more sence:
path.fromURL('file:///Users/node/dev') === '/Users/node/dev' and not 'file:///Users/node/dev'
@sindresorhus WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

How do you decide if the user refers to a file: URL or to a relative path inside a directory named file:?

Copy link
Member

Choose a reason for hiding this comment

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

I agree this makes more sence:
path.fromURL('file:///Users/node/dev') === '/Users/node/dev' and not 'file:///Users/node/dev'

I think that's orthogonal to my concern regarding OS-specific path normalization, and not what this comment is about.

Copy link
Member Author

Choose a reason for hiding this comment

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

I am actually less concerned about that since you can be explicit and use path.win32/path.posix, like we do in our tests

Copy link
Member

Choose a reason for hiding this comment

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

Again, that's also not what my comment is about. My concern is the fact that fromURL appears to sometimes -- but not always -- normalize the 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.

@tniessen do you think we should change the behavior even if the name of the method is changed to one of the names suggested here (toPathIfFileURL/fromURLInstance)?

posix: null
};


Copy link
Member

Choose a reason for hiding this comment

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

Nit: unrelated change.

Copy link
Member

@targos targos left a comment

Choose a reason for hiding this comment

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

Just making sure #44315 (comment) is resolved before this can land.

@Dustin4444
Copy link

Fixes: #41521

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. needs-ci PRs that need a full CI run. path Issues and PRs related to the path subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a utility to convert file URL or path to one of them?

7 participants