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

Common way of using pkg-dir #16

Open
rauschma opened this issue Jul 24, 2022 · 3 comments
Open

Common way of using pkg-dir #16

rauschma opened this issue Jul 24, 2022 · 3 comments

Comments

@rauschma
Copy link

rauschma commented Jul 24, 2022

One common way of using this package is as follows. Maybe mention that in the readme?

import {packageDirectorySync} from 'pkg-dir';
console.log(packageDirectorySync({cwd: import.meta.url}));
  • URLs in strings seem to work, I didn’t have to use {cwd: new URL(import.meta.url)}.
  • If I’m not mistaken, using the default value process.cwd() for cwd can produce incorrect results for modules.
@sindresorhus
Copy link
Owner

One common way of using this package is as follows. Maybe mention that in the readme?

Yes. Good idea. Although, I prefer to just add official URL support. I'm slowly adding URL support to places that accept paths.

If I’m not mistaken, using the default value process.cwd() for cwd can produce incorrect results for modules.

It really depends on your use-case.

@rauschma
Copy link
Author

rauschma commented Jul 24, 2022

I prefer to just add official URL support

So the safe way to make the call will eventually be the following code(?)

packageDirectorySync({cwd: new URL(import.meta.url)})

It really depends on your use-case.

True!

@sindresorhus
Copy link
Owner

So the safe way to make the call will eventually be the following code(?)

Correct. Hopefully, Node.js will eventually get a nicer API to get the current file and directory.

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

No branches or pull requests

2 participants