Code Monkey home page Code Monkey logo

Comments (7)

guillaumervls avatar guillaumervls commented on August 31, 2024 1

Nice catch ! Here is a fix #106 using the cwd option

from mongodb-memory-server.

AJRdev avatar AJRdev commented on August 31, 2024 1

@guillaumervls Nice fix ;)

from mongodb-memory-server.

AJRdev avatar AJRdev commented on August 31, 2024

@akateiva The binaries are downloaded in the same directory in the post_install script and at runtime, both of them in the directory /node_modules/.cache/mongodb-memory-server/mongodb-binaries, they both pass through the getPath method of the MongoBinary class.

When the download is done, a folder corresponding to the version of mongodb used is created in that directory, in your case that folder is /latest/mongod containing the binary.

So if you downloaded the binary in the post install script and you then use the module it should not download it again since the binary is already present in the right directory.

In which context are you using the module ? In different CI jobs ?
On your trace I cannot see the new download of the binary.

from mongodb-memory-server.

akateiva avatar akateiva commented on August 31, 2024

@AJRdev I'm using the module for tests in a CI job.

In my trace I show the result of path.resolve(findCacheDir({ name: 'mongodb-memory-server' }), 'mongodb-binaries');, which is taken from MongoBinary.js line 33 . You can see that the directory to which the binaries were downloaded during post-install is the .cache folder under mongodb-memory-server package, while at run-time the binary path is downloaded to the root package's .cache folder.

Anyway, I added const mongod = new mongoms.MongoMemoryServer({debug: true}); to the trace so you can see the download dir.

docker run -it --rm node:11 /bin/bash
root@3971eceabc15:/# npm init --yes
Wrote to /package.json:

{
  "name": "",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "directories": {
    "lib": "lib"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}


root@3971eceabc15:/# npm install --save mongodb mongodb-memory-server

> [email protected] postinstall /node_modules/mongodb-memory-server
> node ./postinstall.js

mongodb-memory-server: checking MongoDB binaries cache...
mongodb-memory-server: binary path is /node_modules/mongodb-memory-server/node_modules/.cache/mongodb-memory-server/mongodb-binaries/latest/mongod
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN @1.0.0 No description
npm WARN @1.0.0 No repository field.

+ [email protected]
+ [email protected]
added 90 packages from 52 contributors and audited 177 packages in 33.606s
found 0 vulnerabilities

root@3971eceabc15:/# node
> const mongoms = require('mongodb-memory-server');
undefined
> const mongod = new mongoms.MongoMemoryServer({debug: true});
Autostarting MongoDB instance...
undefined
>   Mongo[33809] Starting MongoDB instance with following options: {"port":33809,"dbName":"25fe9f79-3061-43e0-931c-73e502341f3b","uri":"mongodb://127.0.0.1:33809/25fe9f79-3061-43e0-931c-73e502341f3b","storageEngine":"ephemeralForTest","dbPath":"/tmp/mongo-mem-42KwwXQYlN1Sfm"} +0ms
  Mongo[33809] MongoBinary options: {"downloadDir":"/node_modules/.cache/mongodb-memory-server/mongodb-binaries","platform":"linux","arch":"x64","version":"latest"} +7ms
  Mongo[33809] Downloading: https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian92-latest.tgz +38ms
Downloading MongoDB latest: 53.7 % (44.7mb / 83.3mb)
(To exit, press ^C again or type .exit)
> Downloading MongoDB latest: 69 % (57.5mb / 83.3mb)

from mongodb-memory-server.

AJRdev avatar AJRdev commented on August 31, 2024

@akateiva Oh my bad, I misread the two paths..
Yes so there is a real problem that we didn't saw by running our CI jobs on the project where the post_install script path and the runtime path for the binary download were the same because the post_install script is at the root level of the project.

In your case and for everyone installing this module, the post_install script is at the root of the mongodb-memory-server npm package in the node_module directory not a the root of the project..

So this line :

path.resolve(findCacheDir({ name: 'mongodb-memory-server' }), 'mongodb-binaries'))

is searching for the binary in the node_modules directory of the npm package (/node_modules/mongodb-memory-server/node_modules/.cache/mongodb-memory-server/) in the post_install script and not at the root of the project like at runtime (/node_modules/.cache/mongodb-memory-server/).

The is quite an issue, because I can't see how we could detect in the post_install script that we should download the binary in the node_modules of the project and not the node_modules of the package itself, we didn't had this problem before because the default path was :

path.resolve(os.homedir(), '.mongodb-binaries');

@nodkz Any thoughts on this ?

from mongodb-memory-server.

nodkz avatar nodkz commented on August 31, 2024

Need to fix somehow. 😈

@guillaumervls have you bandwidth for taking care about this problem?

Related: #99

from mongodb-memory-server.

nodkz avatar nodkz commented on August 31, 2024

🎉 This issue has been resolved in version 2.7.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

from mongodb-memory-server.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.