friendly-errors-webpack-plugin
friendly-errors-webpack-plugin copied to clipboard
Check if yarn.lock exists to recommend yarn add instead of npm install
See #30
working on this one, anybody knows of a way to get the webpack.config.js path in a plugin?
There's not always a webpack.config.js, because some create the config via the JS API.
I think the easiest way is to check for path.resolve('yarn.lock'). Another way is to use https://www.npmjs.com/package/pkg-dir and then look for the yarn.lock in to it, based on the pwd. This should work most of the time
@christophehurpeau wouldn't both options return the plugin path instead of the folder where webpack is invoked?
path.resolve
uses process.cwd(), and process.cwd
should return the project path the user is in
@christophehurpeau it logs the path to plugin when I run the tests; is it because i ran 'npm test' so process.cwd() is the location where I ran 'npm test' ?
@duivvv yes
maybe you can use https://nodejs.org/api/process.html#process_process_chdir_directory
to go to the right test path ?
const previousPwd = process.pwd();
process.chdir(path.dirname(fixture));
try {
...
await webpackPromise(require(fixture), globalPlugins);
...
} finally {
process.chdir(previousPwd);
...
}