friendly-errors-webpack-plugin icon indicating copy to clipboard operation
friendly-errors-webpack-plugin copied to clipboard

Check if yarn.lock exists to recommend yarn add instead of npm install

Open geowarin opened this issue 7 years ago • 7 comments

See #30

geowarin avatar Feb 28 '17 13:02 geowarin

working on this one, anybody knows of a way to get the webpack.config.js path in a plugin?

geoffreydhuyvetters avatar Aug 09 '17 06:08 geoffreydhuyvetters

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 avatar Aug 09 '17 07:08 christophehurpeau

@christophehurpeau wouldn't both options return the plugin path instead of the folder where webpack is invoked?

geoffreydhuyvetters avatar Aug 09 '17 20:08 geoffreydhuyvetters

path.resolve uses process.cwd(), and process.cwd should return the project path the user is in

christophehurpeau avatar Aug 10 '17 09:08 christophehurpeau

@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' ?

geoffreydhuyvetters avatar Aug 12 '17 06:08 geoffreydhuyvetters

@duivvv yes

christophehurpeau avatar Aug 12 '17 09:08 christophehurpeau

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);
  ...
}

christophehurpeau avatar Aug 12 '17 10:08 christophehurpeau