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

sbt-less seems to be using an old version of less #136

Closed
bwbecker opened this issue Apr 30, 2024 · 11 comments
Closed

sbt-less seems to be using an old version of less #136

bwbecker opened this issue Apr 30, 2024 · 11 comments

Comments

@bwbecker
Copy link

sbt-less and lessc are producing different output. In particular, lessc (v4.2.0) compiles

  top: calc(-@li-vspace + @icon-size / 2 - 5px);

to

  top: calc(-1.7rem + 2rem / 2 - 5px);

while sbt-less compiles the same code to

  top: calc(-5.7rem);

This is consistent with what I've read about OLD versions of less. The less documentation describes a calc exception beginning with the v3.0.0 release that "For CSS compatibility, calc() does not evaluate math expressions, but will evaluate variables and math in nested functions." This is what I need but am not getting with sbt-less!

This is a Play! project. I have addSbtPlugin("com.github.sbt" % "sbt-less" % "2.0.1") (the latest version according to the github sbt-less page)in my plugins.sbt. When I clean the project, find . -name "main.css" doesn't find any files. After compiling the running the project, they are found and match what I see in the browser.

There is a file in my project, project/target/less/lessc.js that matches a file in the sbt-less repo. It contains less = requireIfExists("less/4.2.0", "less"). I take the 4.2.0 to be a version (good sign! That's recent!). But I don't think that's the version I'm actually getting.

@mkurz
Copy link
Member

mkurz commented May 8, 2024

Which node version are you using? Please post the output of node --version, thanks!

Also, can you please check if there is a less folder in project/target/node-modules/webjars? If so, what is it contents - like running:

tree -L 1 ./project/target/node-modules/webjars/less

?
Thanks!

@mkurz
Copy link
Member

mkurz commented May 8, 2024

@bwbecker I just merged #138 which adds the same calc code you show above in a scripted test.

Please try following:

  1. Clone this repo (or update to latest main branch if you cloned this repo before)
  2. Go to the scripted test folder:
cd src/sbt-test/sbt-less-plugin/less-same-webjars-different-version/
  1. Generate the css file:
sbt --sbt-version 1.10.0 -Dproject.version=2.0.1 assets
  1. You should now get the correct result:
cat target/web/public/main/css/main.css
h1 {
  color: blue;
  top: calc(-1.7rem + 2rem / 2 - 5px);
}
  1. Also look what is in the webjars folder:
$ tree -L 1 ./project/target/node-modules/webjars/less
./project/target/node-modules/webjars/less
├── 3.8.1
└── 4.2.0

3 directories, 0 files

Maybe we can figure out what is going on here...

@bwbecker
Copy link
Author

bwbecker commented May 8, 2024

Which node version are you using? Please post the output of node --version, thanks!

bwbecker@beta oat-degreeAudit3 % node --version
v21.7.0
bwbecker@beta oat-degreeAudit3 %

Also, can you please check if there is a less folder in project/target/node-modules/webjars? If so, what is it contents - like running:

tree -L 1 ./project/target/node-modules/webjars/less
bwbecker@bwbmac oat3 % tree -L 1 project/target/node-modules/webjars/less
project/target/node-modules/webjars/less
├── Gruntfile.js
├── LICENSE
├── README.md
├── bin
├── bower.json
├── dist
├── index.js
├── lib
├── package.json
├── test
├── tsconfig.build.json
└── tsconfig.json

5 directories, 8 files
bwbecker@bwbmac oat3 % 

@bwbecker
Copy link
Author

bwbecker commented May 8, 2024

@bwbecker I just merged #138 which adds the same calc code you show above in a scripted test.

Please try following:

Just tried the above and got the same results that you expected :)

@mkurz
Copy link
Member

mkurz commented May 8, 2024

@bwbecker ok thanks.

In your project, please run sbt and then within sbt:

> reload plugins
sbt:project> dependencyTree

and please post the dependency tree here.

@mkurz
Copy link
Member

mkurz commented May 8, 2024

Actually, also what does the version property in project/target/node-modules/webjars/less/package.json say?

@bwbecker
Copy link
Author

bwbecker commented May 8, 2024

[oat] $ reload plugins
[info] welcome to sbt 1.9.8 (Homebrew Java 17.0.9)
[info] loading settings for project global-plugins from plugins.sbt ...
[info] loading global plugins from /Users/bwbecker/.sbt/1.0/plugins
[info] loading settings for project project from plugins.sbt ...
[info] loading project definition from /Users/bwbecker/oat/src/oat3/project
sbt:project> dependencyTree
[success] Total time: 0 s, completed May 8, 2024, 1:04:04 p.m.
sbt:project> 

The above seemed unexpected; I expected some output from dependencyTree. So I re-ran it as follows:

bwbecker@bwbmac oat3 % echo "dependencyTree; reload plugins; dependencyTree; exit " | sbt > dependencyTree.txt

See the attached file. The tree from the first command is huge -- nearly 20,000 lines. That has always struck me as strange, but I've never investigated.

Finally, the version in package.json:

bwbecker@bwbmac oat3 % grep version project/target/node-modules/webjars/less/package.json
	"version": "4.2.0",
		"parse-node-version": "^1.0.1",
bwbecker@bwbmac oat3 % 

dependencyTree.txt

@mkurz
Copy link
Member

mkurz commented May 8, 2024

I am a bit lost, I tried lots of stuff now. It actually does look like you are using less 4.2.0...
Are you 100% sure that when using latest sbt-less (2.0.1) that you end up with top: calc(-5.7rem); Can you please check that again?

Anyway... lets gets a bit more "intense" now...
I published a new (unoffical and temporary) release: 2.0.2-M1 that contains some debug messages, see 321505d

Can you please update to this temporary sbt-less 2.0.2-M1 version and make sure to clean your target folders and then start sbt and run assets and then post your output?
It should display which less webjar and also which lessc.js get used...

@bwbecker
Copy link
Author

bwbecker commented May 9, 2024

@mkurz -- I have meetings today that prevent me from working on this. I should be able to get to it tomorrow.

@bwbecker
Copy link
Author

@mkurz -- Matthias, I apologize for apparently wasting your time. I thought I was extremely careful to verify this, but today I reverted my work-around and the original less code does indeed compile as expected.

In reviewing my commit logs, my best theory is that I updated sbt-less from 1.1.2 to 2.0.1 and did a reload within SBT, forgetting that doesn't reload plugins. I'm finding it hard to believe that I went for several hours of debugging and writing up the bug report without restarting SBT, but that's the only theory I have.

Again, my apologies.

@mkurz
Copy link
Member

mkurz commented May 10, 2024

No problem, happy it works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants