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

Prevent babelrc package import failure on relative current path #3723

Merged
merged 1 commit into from
Jun 6, 2017
Merged

Prevent babelrc package import failure on relative current path #3723

merged 1 commit into from
Jun 6, 2017

Conversation

kwonoj
Copy link
Contributor

@kwonoj kwonoj commented Jun 2, 2017

Summary

Relates to danger/danger-js#261 .

This PR attempts to fix cases of reading babelrc via package.json. Using current code path, below case is possible:

//directory is '.', relative current
const packageJsonFilePath = path.join(directory, PACKAGE_JSON); 
//now packageJsonFilePath === PACKAGE_JSON, plain filename only as 'package.json'
//fs can check file exists
if (fs.existsSync(packageJsonFilePath)) { 
  //node module resolution failure cause it doesn't have paths, 
  //node try to resolve it as node_modules -> exception thrown
  const packageJsonFileContents = require(packageJsonFilePath);
...

I thought of using different mechanics to detect relative current (i.e path.relative(directory, '.'), path.resolve(directory, __dirname)..) but took simplest comparison instead.

Test plan
I've verified by replacing this module uses it as dependency (danger/danger-js#261)

@codecov-io
Copy link

Codecov Report

Merging #3723 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3723   +/-   ##
=======================================
  Coverage   62.64%   62.64%           
=======================================
  Files         183      183           
  Lines        6709     6709           
  Branches        6        6           
=======================================
  Hits         4203     4203           
  Misses       2503     2503           
  Partials        3        3

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a79ab07...aa9c67f. Read the comment docs.

@cpojer cpojer merged commit a5dac8c into jestjs:master Jun 6, 2017
@cpojer
Copy link
Member

cpojer commented Jun 6, 2017

Thanks!

@kwonoj kwonoj deleted the fix-babelrc-package branch June 6, 2017 14:19
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants