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

Thunkify homeDirectory lookup #32

Merged
merged 2 commits into from
Dec 20, 2022
Merged

Conversation

neezer
Copy link
Contributor

@neezer neezer commented Dec 15, 2022

If pretty === false, do not invoke os.homedir().

I reason calls to os.* should only occur when the user configures behavior provided by this library that require them.

@@ -270,3 +272,8 @@ test('handle undefined', t => {
const expected = undefined;
t.is(cleanStack(stack, {pretty: true}), expected);
});

test('exports for home-directory files match', t => {
Copy link
Owner

Choose a reason for hiding this comment

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

I don't really see the point of this test.

Copy link
Contributor Author

@neezer neezer Dec 19, 2022

Choose a reason for hiding this comment

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

Initially I didn't update home-directory-browser.js with the same change, which would've broken browser behavior. I figured it would be nice to have a test to help ensure the return type from both files is symmetric.

index.js Outdated
@@ -40,7 +40,7 @@ export default function cleanStack(stack, {pretty = false, basePath} = {}) {
}

if (pretty) {
line = line.replace(extractPathRegex, (m, p1) => m.replace(p1, p1.replace(homeDirectory, '~')));
line = line.replace(extractPathRegex, (m, p1) => m.replace(p1, p1.replace(getHomeDirectory(), '~')));
Copy link
Owner

Choose a reason for hiding this comment

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

This is super inefficient. It will fetch os.homedir() for every line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sindresorhus sindresorhus merged commit 2b03532 into sindresorhus:main Dec 20, 2022
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.

2 participants