-
Notifications
You must be signed in to change notification settings - Fork 200
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
chore: normalize file path #910
Conversation
@ylmin Can you please provide more information? What is the problem that you are trying to fix? How does this change fix the problem? |
Absolute paths vs Relative paths: path.resolve(__dirname, './file.js') returns the absolute path of 'file.js', while './file.js' returns a relative path relative to the current working directory. Ensuring Reliable File Positioning: path.resolve(__dirname, './file.js') ensures that the position of the file is relative to the current module file, which is not affected by the startup path of the Node.js application. On the other hand, directly using './file.js' as a relative path might be affected by the startup path. Therefore, using path.resolve(__dirname, './file.js') can more reliably obtain the absolute path of a file. |
Understood! Here's the difference between using path.resolve with and without __dirname: When using path.resolve without __dirname, the function will resolve the path based on the current working directory (CWD) of the Node.js process. In other words, if you provide a relative path without __dirname, the function will assume that the path is relative to the CWD. On the other hand, when using path.resolve with __dirname, the function will resolve the path based on the directory where the current module file is located. In other words, if you provide a relative path with __dirname, the function will assume that the path is relative to the directory where the module file is located. The difference lies in how the function interprets the relative path. Without __dirname, the function assumes that the path is relative to the CWD, which may not be the desired behavior in some cases. For example, if you have a folder structure like this: my_project/ In summary, using path.resolve with __dirname can help you write more predictable and robust code by ensuring that the relative path is resolved based on the correct directory. |
@ylmin Can you suggest how I can test this to make sure it doesn't break anything? Sorry, I'm not much of a JS dev. |
c424331
into
starknet-io:ylmin/normalize_file_path
* refactor: normalize File Path (#910) Merging this to a new PR to force generating a preview. Co-authored-by: Steve Goodman <[email protected]> * Update js/algolia-index.js * Update js/algolia-index.js --------- Co-authored-by: Jack <[email protected]>
Description of the Changes
PR Preview URL
No
Check List
<docs/feat/fix/chore>(optional scope): <description>
, e.g:fix: minor typos in code
This change is