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

Config paths from package.json are relative to the working directory instead of package.json #440

Closed
mhassan1 opened this issue Feb 19, 2021 · 5 comments
Labels
bug released on @beta released Pull Request released | Issue is fixed
Milestone

Comments

@mhassan1
Copy link
Contributor

Versions

  • NodeJS: 14.15.1
  • mongodb-memory-server-*: 6.9.3
  • mongodb: 4.4.1
  • mongoose: 5.11.15
  • system: MacOS

package: mongodb-memory-server-core

What is the Problem?

When findPackageJson grabs configuration from a package.json, it sets downloadDir and systemBinary to the relative paths it finds in package.json. When MongoBinary is looking for the binary, it will look in those locations relative to the current working directory; however, it's possible that the current working directory will vary depending where the initial command was run. For example, I may run a test from the root of my project, or I may run it from the test directory. If I have configuration in package.json in the root, the binary will be resolved differently in those scenarios.

Code Example

We could add code to findPackageJson that resolves downloadDir and systemBinary to absolute paths (based on the location of the package.json):

const ourConfig = value?.config?.mongodbMemoryServer || {};

// resolve relative paths
for (const relativePathProp of ['downloadDir', 'systemBinary']) {
  if (ourConfig[relativePathProp]) {
    ourConfig[relativePathProp] = path.resolve(path.dirname(filename), ourConfig[relativePathProp]);
  }
}
packageJsonConfig = ourConfig;

Do you know why it happenes?

Once a relative downloadDir is provided to mongoBinaryDownload, it is resolved relative to the current working directory, for example:

@hasezoey
Copy link
Collaborator

commit 0bec0bf should resolve this, could you confirm? (version 7.0.0-beta.17)

@github-actions
Copy link

🎉 This issue has been resolved in version 7.0.0-beta.17 🎉

The release is available on:

Your semantic-release bot 📦🚀

@mhassan1
Copy link
Contributor Author

LGTM, thank you!

@mhassan1
Copy link
Contributor Author

mhassan1 commented May 6, 2021

@hasezoey I've been doing more testing of this, and I'm noticing that the fix in 0bec0bf is incomplete. The packageJsonConfig[ccDownloadDir] value passed to path.resolve() should be resolved relative to the found package.json file. Instead, it is relative to the current working directory.

This should be resolved by #469.

@github-actions
Copy link

github-actions bot commented Jul 1, 2021

@github-actions github-actions bot added the released Pull Request released | Issue is fixed label Jul 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug released on @beta released Pull Request released | Issue is fixed
Projects
None yet
Development

No branches or pull requests

2 participants