Skip to content

Conversation

kleisauke
Copy link
Collaborator

@kleisauke kleisauke commented Sep 14, 2022

Ensures that absolute paths are handled correctly on Windows as well. Using these helpers should be safe, since binaries linked with -sNODERAWFS can only be used on Node.js, see:

throw new Error("NODERAWFS is currently only supported on Node.js environment.")

Context: #16296 (comment).

Resolves: #17360.
Resolves: #17819.
Supersedes: #17821.

(If preferred, I can split the last 32 non-functional changes)

isAbs: (path) => nodePath['isAbsolute'](path),
normalize: (path) => nodePath['normalize'](path),
dirname: (path) => nodePath['dirname'](path),
basename: (path) => nodePath['basename'](path),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm curious why closure wouldn't know how to deal with nodePath without the extra quoting here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, it's currently used this way throughout the codebase. Perhaps nodePath should be placed within src/closure-externs/closure-externs.js?

basename: (path) => nodePath['basename'](path),
join: function () {
return nodePath['join'].apply(null, arguments);
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this just be join: nodePath['join']? (same with above)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I tried that initially, but it caused the acorn-optimizer to fail.

@rchiodo
Copy link

rchiodo commented Sep 14, 2022

Tested it with the scenarios I had in #17821- works great. Thanks.

I had added some window specific tests in that PR, @kleisauke do you think they would be appropriate here?

@kleisauke
Copy link
Collaborator Author

@rchiodo Great, thanks for testing! I just added a simple test that previously failed on Windows.

Ensures that absolute paths are handled correctly on Windows
as well. Using these helpers should be safe, since binaries
linked with -sNODERAWFS can only be used on Node.js.
It already resolves to `FS.cwd()` by default, so there's no need to
pass it as first argument.
The `PATH_FS.resolve` invocation above already made the path
absolute.
@kleisauke
Copy link
Collaborator Author

Rebased now that PR #17851 has been merged.

@kleisauke
Copy link
Collaborator Author

Is there anything I can do to make this land? AFAIK, -sNODERAWFS will eventually be replaced by WasmFS, but in the meantime, this seems useful to me.

* Copyright 2022 The Emscripten Authors
* SPDX-License-Identifier: MIT
*/

Copy link
Member

Choose a reason for hiding this comment

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

Maybe add a comment in this file explaining the motivation for it? (which IIUC from the discussion is windows?) lgtm with that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added a comment with 37b6dd0. I also removed the "This has mostly been tested on Linux so far"-phrase from NODERAWFS settings description with 9115052, since using Node.js operations should be cross-platform (+ AFAIK, CI also test the NODERAWFS setting on OSes other than Linux).

Copy link
Member

Choose a reason for hiding this comment

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

Thanks!

kleisauke referenced this pull request in kleisauke/emscripten Nov 5, 2022
Ensures that absolute paths are handled correctly on Windows
as well. Using these helpers should be safe, since binaries
linked with -sNODERAWFS can only be used on Node.js.
@kripken kripken merged commit febd44b into emscripten-core:main Nov 7, 2022
@kleisauke kleisauke deleted the issue-17360 branch November 8, 2022 08:41
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.

opendir is not portable to windows for NODERAWFS Windows file paths causes ENOENT errors starting with Emscripten v3.1.8
4 participants