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

Use require.resolve() instead of string concatenation #21

Closed
priver opened this issue Feb 11, 2019 · 1 comment
Closed

Use require.resolve() instead of string concatenation #21

priver opened this issue Feb 11, 2019 · 1 comment

Comments

@priver
Copy link

priver commented Feb 11, 2019

This package uses string concatenation to locate README.md file:

const target = `stylelint/lib/rules/${ruleName}/README.md`;
const filePath = path.resolve(process.cwd(), 'node_modules', target);

But node_modules directory can be anyware else, e.g. if you are using yarn workspaces it is hoisted to project root.

You should use require.resolve() function to locate files:

const target = `stylelint/lib/rules/${ruleName}/README.md`;
const filePath = require.resolve(target)
@alexilyaev
Copy link
Owner

Thanks for the feedback.

That looks like a good idea, I'll definitely give it a try.

Would it also work for globally installed packages like npm i -g stylelint?

I remember trying it out as part of #17 and didn't manage to make it work with yarn global add stylelint.

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