scalajs-bundler icon indicating copy to clipboard operation
scalajs-bundler copied to clipboard

yarn.lock different in compile and test

Open fdietze opened this issue 6 years ago • 6 comments

Did anyone else notice that yarn.lock changes after running test or fastOptJS::webpack?

I couldn't figure out what exactly is changing, but my guess is that we may need two different lock-files. One for compile and one for test.

fdietze avatar Aug 07 '18 13:08 fdietze

@fdietze it will be different if you define npmDependencies in Test. Two lock files will also mean two node-modules, which can be a problem. The workaround for us is to commit the lock file for Test and make sure to use frozen-lockfile by default. It works out pretty well for us

ngbinh avatar Aug 07 '18 14:08 ngbinh

@ngbinh I'm trying your approach right now. So basically I add this to my build.sbt:

yarnExtraArgs in Compile := Seq("--frozen-lockfile")

Then I delete my lock-file, run the tests and commit the newly generated lockfile.

When adding a new dependency, I delete the lockfile and run the tests again. Are you doing the same?

fdietze avatar Aug 27 '18 14:08 fdietze

Yes. We have a script to do exactly what you've described.

ngbinh avatar Aug 27 '18 15:08 ngbinh

@ngbinh It's not really working for me...

How do you trigger the creation of a lockfile after deletion? The yarn docs say for --frozen-lockfile:

Don’t generate a yarn.lock lockfile and fail if an update is needed.

This is what I see. When no lockfile exists and I run fastOptJS::webpack, no lockfile is written.

On the other hand test creates a lockfile. But it only contains the jsdom dependency (and transitive dependencies). Running fastOptJS::webpack afterwards fails because of --frozen-lockfile.

Also, when having a lockfile generated by fastOptJS::webpack, the tests fail with the --frozen-lockfile error.

What am I doing wrong?

fdietze avatar Aug 27 '18 16:08 fdietze

What we did is fully clean the scala.js bundler projects and then run npmUpdate again. It is a bit slow but only happens once you change npmDependencies.

ngbinh avatar Aug 28 '18 03:08 ngbinh

Same package-lock.json file is also used when scalajs-bundler installs jsdom for requireJsdom := true. In this case package-lock.json will only contains jsdom dependency, so most of locked dependencies for compile/test will be lost.

I think we should aggregate all dependencies needed for compile/test (incl. jsdom) and put into single package.json and package-lock.json file, if we follow JavaScript manner.

unarist avatar Dec 06 '23 18:12 unarist