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

RFC rethink usage of canonicalization, normalization, cleanup, etc. #21

Open
Charlie-XIAO opened this issue Apr 10, 2024 · 0 comments
Open
Labels
type:maintenance General maintenance

Comments

@Charlie-XIAO
Copy link
Contributor

Charlie-XIAO commented Apr 10, 2024

There are currently three choices that I come up with (they are either from the standard library or are used by SWC which will not increase the size of our binary):

  • canonicalize in the standard library absolutizes relative paths. It requires file system access, resolves symbolic links, and returns verbatim paths (prefixed by \\?\) for Windows.
  • normpath introduces BasePath that is an improved version of Path in the standard library. For instance, join intends to normalize . and .. without requiring file system access. Its normalize method is the same as canonicalize on Unix.
  • path_clean is an extremely small crate that provides only one method: clean. It simply cleans up . and .. without accessing the file system (thus works regardless of whether the path exists). It works for both relative and absolute paths and does not normalize relative paths into absolute (because it performs only lexical processing).

My plan is as follows:

  • Within the bundler: SWC performs canonicalization on Windows in the first place (turning into verbatim path). However, we have access to the absolute base path in the path resolver, so we really just need path_clean to clean up . and ...
  • Other places: I'm not sure if we care about any paths other than app_data_dir. From this Discord discussion it seems that this is the defacto standard, and app_data_dir is given as an absolute path (non-verbatim). Thus, I don't think we ever need to absolutize a path (thus canonicalize and normpath are not needed), and path_clean would be sufficient.

Hence the principle is that we never use canonicalize (otherwise we will mess up verbatim and non-verbatim paths on Windows), and we do not need any external crate other than path_clean: there is no need to absolutize a relative path because we can simply join and clean given access to the absolute base directory, and path_clean will give us consistent paths when we need to make comparison.

Canonicalization may still be used in tests because we have functions that expect absolute paths as inputs.

Looking for opinions from @CSCI-SHU-410-SE-Project/core-dev :)

@Charlie-XIAO Charlie-XIAO added the type:maintenance General maintenance label Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:maintenance General maintenance
Projects
None yet
Development

No branches or pull requests

1 participant