loki icon indicating copy to clipboard operation
loki copied to clipboard

Update wait-on dependency

Open felabr opened this issue 1 year ago • 3 comments

Update the wait-on dependency to ^7.2.0. Earlier versions use an older version of axios with a security issue. This should solve https://github.com/oblador/loki/issues/493

felabr avatar Dec 21 '23 17:12 felabr

Hi @oblador, not sure how things proceed from here on ... could you have a look at this tiny PR?

felabr avatar Dec 22 '23 10:12 felabr

Hello @felabr I was aiming to propose the same update.

I think loki is still a commonjs project, while wait-on or axios have moved into ESM and that's making your test fail.

In loki/packages/target-chrome-docker/src/create-chrome-docker-target.js it will need to use a dynamic import, instead of require to import wait-on. Luckily for us it's already used within a promise, so the asyncronous nature of the dynamic import shouldn't affect anything else.

Instead of

waitOn = require('wait-on');

Promise(...
  waitOn(...)

needs to be something like

Promise(...
  import('wait-on').then(module => module.default).then(waitOn => waitOn(...))

From the docs: https://nodejs.org/api/esm.html#import-expressions

Dynamic import() is supported in both CommonJS and ES modules. In CommonJS modules it can be used to load ES modules.

Let me know your thoughts.

gatsbimantico avatar Jan 10 '24 23:01 gatsbimantico

Yes, that would be great! I tried a lot, Promises and async/await, but didn't get it to work (yet). Whenever there's a dynamic import for wait-on it keeps running for ever. It even stops working when I just add this line:

import('wait-on').then((module) => console.log(module));

and change the test command in package.json like so:

"test": "yarn node --experimental-vm-modules $(yarn bin jest)",

The leanest thing I came up with (in my own opinion) is this:

const waitOnCDPAvailable = async (host, port) => {
  const { default: waitOn } = await import('wait-on');
  await waitOn({.....});
};

Anyway, if anybody has an idea how to make the wait-on ESM and the dynamic import work here, please let me know.

felabr avatar Jan 16 '24 14:01 felabr

I also get this problem with loki and people that install our npm package are getting the vulnerability warning for that reason. Would be great if this can be fixed

flieks avatar Jan 25 '24 12:01 flieks

Fixed in 0.34.0

oblador avatar Jan 25 '24 21:01 oblador