Fork me on GitHub
#cljs-dev
<
2022-12-16
>
lread03:12:22

Is migrating canary to GitHub Actions viable and of interest? I can take a look if you like.

βž• 1
borkdude14:12:32

I have received a clj-kondo report in which clj-kondo marks Foo.Bar as unused in this example:

(ns script
  (:require ["./foo" :refer [Foo Foo.Bar]]))

(prn Foo)
(prn Foo.Bar)
Is :refer [Foo.Bar] even supported? I would have expected this example to have worked without referring Foo.Bar since in JS you can write this as:
import { Foo } from './foo.js';

console.log(Foo);
console.log(Foo.Bar);
and import { Foo, Foo.Bar } from "./foo.js" doesn't even work.

thheller14:12:35

no, this is not supported. purely happens to work by accident

thheller14:12:46

since a . is just passed through, and isn't validated beyond that

thheller14:12:40

also the "./foo" style require isn't even supported by CLJS only shadow-cljs

borkdude14:12:42

yes, I was just going to say I only tested this with shadow-cljs since I didn't even know how to import a local JS file with vanilla CLJS, but this isn't very relevant here, the original report did this with a normal npm lib:

(ns headless-ui
  (:require ["@headlessui/react" :refer [Dialog Dialog.Overlay]]))

(defn modal-overlay [_]
  (into [:> Dialog.Overlay {:class-name "fixed"}]))

thheller14:12:40

yeah :refer is just declared as sequence of symbols

thheller14:12:48

not sequence of symbols without dots πŸ˜‰

thheller14:12:59

thus is passes validation and is never checked again

thheller14:12:21

(at least in shadow-cljs, no clue about regular CLJS)

thheller14:12:01

technically the Dialog refer already covers Dialog.Overlay, as such cljkondo is correct

borkdude14:12:38

but without Foo.Bar in :refer you get this in shadow-cljs:

file:///private/tmp/dudejs/out/cljs-runtime/script.js:4
cljs.core.prn.cljs$core$IFn$_invoke$arity$variadic(cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([Foo.Bar], 0));
                                                                                                     ^

ReferenceError: Foo is not defined

thheller14:12:28

hmm. well technically Dialog.Overlay should be (.-Overlay Dialog)

thheller14:12:55

not sure why it doesn't like it though. no warning during compilation?

thheller14:12:19

definitely shouldn't shouldn't be runtime error only

borkdude14:12:38

yes, there is a warning during compilation:

------ WARNING #1 - :undeclared-var --------------------------------------------
 File: /private/tmp/dudejs/src/script.cljs:5:6
--------------------------------------------------------------------------------
   2 |   (:require ["./foo" :refer [Foo #_Foo.Bar]]))
   3 |
   4 | (prn Foo)
   5 | (prn Foo.Bar)
------------^-------------------------------------------------------------------
 Use of undeclared Var script/Foo

thheller14:12:10

ok. yeah the case of symbols with dots is still a bit sketchy all over the place

borkdude14:12:48

This works though:

(prn Foo)
(prn (.-Bar Foo))

thheller14:12:03

that is expected yes

thheller14:12:23

there is some code that desugars dotted symbols to the proper access

thheller14:12:37

but it doesn't quite cover all cases

borkdude14:12:35

@U05224H0W Do you want an issue for this case?

thheller15:12:04

only if it differs from regular CLJS

thheller15:12:34

the fact that its a local JS require shouldn't matter, behaviour for any require should be the same

borkdude15:12:08

Is the fact that it's a JS library at all relevant? E.g. (:require [foo :refer [foo.bar]) ?

thheller15:12:31

don't think so no

thheller15:12:12

but :refer against cljs namespaces is checked in the analyzer data, so might yield errors

thheller15:12:18

for JS this is not the case

borkdude15:12:22

For a CLJS namespace this already works:

(ns script
  (:require #_["./foo" :refer [Foo #_Foo.Bar]]
            [bar :refer [Foo]]))

(prn Foo)
(prn (.-Bar Foo))
(prn :dude 1)

borkdude15:12:38

where bar is:

(ns bar)

(def Foo #js {:Bar 1})

borkdude15:12:47

eh wait, dotted symbol

borkdude15:12:09

same problem. Now I'll try vanilla CLJS

borkdude15:12:36

vanilla CLJS works

borkdude15:12:49

#js {:Bar 1}
1
:dude 1
nil

thheller15:12:03

please try in a build, not a repl

thheller15:12:23

IIRC the repl discards warnings in some cases

borkdude15:12:54

clj -M:cljs -m cljs.main -t node -c script
complains about window not being defined, how do I do this again

borkdude15:12:14

With:

clj -M:cljs -m cljs.main -t node -m script
it still works, that's not a REPL right?

borkdude15:12:42

don't know if you got the above message, went through an area with bad internet, I'm on a train right now

borkdude15:12:42

With:

clj -M:cljs -m cljs.main -t node -m script
it still works, that's not a REPL right?

thheller15:12:52

just open an issue, I'll look into it when I have some time

mkvlr15:12:57

and thanks Thomas!

πŸ™ 1
thheller08:12:55

should be fine in 2.20.15

mkvlr08:12:19

@U05224H0W thank you πŸ™

dnolen15:12:51

@alexmiller sorry to be clear the matrix would be set up in GH as a Clojure repo, not the Clojure build box - no need to burden you

dnolen15:12:43

but I believe the set of libraries / tools that are popular is relatively stable and we should know that some change isn’t going to affect something a lot of people use

Alex Miller (Clojure team)15:12:34

yeah, definitely open to that - is this a thing that already exists elsewhere I can look at?

dnolen15:12:31

I think it runs in Travis, but I think we can convert the whole thing into GH actions

βž• 1
Alex Miller (Clojure team)15:12:21

I guess one consideration would be what the cost is in github action minutes, but I assume that's probably not a big deal

juhoteperi16:12:04

IIRC The existing canary scripts even work by triggering tests on the library project itself, so the library will cover CI minutes themselves, and the Canary jobs are just used to trigger those jobs and build the reports.

dnolen16:12:21

@juhoteperi I suppose that means the libraries that want to participate have to be setup?

Alex Miller (Clojure team)16:12:15

doesn't that seem potentially bad to be charging people CI minutes?

juhoteperi16:12:07

@dnolen Yes. Though I think there were some forks previously for that purpose (https://github.com/cljs-oss/canary/commit/16de8e6fb1eb1a32b5ec364dbaad2fd1b2d80676) or maybe just non-library-project Travis projects for the libraries. I think the idea is good, if we want to run the same test suite as the library is running itself with the same tools. But is could be simpler and good enough to just clone projects and run some tests, should be possible if the project tests are easy enough to run without specific test runners etc.

juhoteperi16:12:32

@alexmiller It is possible. Depends on the project, e.g., for Reagent the credits Github provides for OS projects is more than enough even if there was double the builds, but some projects are probably using more minutes.

Alex Miller (Clojure team)16:12:10

this seems like a weird way to go about this to me

Alex Miller (Clojure team)16:12:49

given a project, seems like if you know: a) how to force a specific CLJS version b) command to run a test suite c) how to verify test success then the canary process can clone and do a/b/c for every known project

Alex Miller (Clojure team)16:12:16

I've been considering setting up a similar thing for Clojure

juhoteperi16:12:15

Step b) could include installing test runner like lein-doo, kaocha, shadow-cljs and/or npm packages like karma which can be make that part a bit more complicated. But it might be indeed enough to only support some runners.

borkdude17:12:51

FWIW, babashka runs a ton of library test suites (from the wild) on every commit as part of its own CI

borkdude17:12:59

I'm using gitlibs to pull the test code and add it to the classpath, then run the tests within the newly compiled bb

Alex Miller (Clojure team)17:12:40

is that a setup that could be borrowed? :)

borkdude17:12:49

The idea can be borrowed, the code itself probably isn't general enough for this

borkdude17:12:28

This is the central part of that code: https://github.com/babashka/babashka/blob/965c177bca31ae9882c975ef7db448e12f59984e/test-resources/lib_tests/babashka/run_all_libtests.clj#L56-L68 I look at a config file which describes which libraries to run tests for. They are present as git libs, so then I find their test directories (as described in the config file), add them to the classpath, and then run.

Alex Miller (Clojure team)17:12:02

ok, I might take a look at this next week

lread20:12:42

Perhaps also of interest: I do canary testing on each commit to rewrite-clj by running canary libs' tests. Canaries are current official lib releases (bumped manually by me). Fwiw, here's the https://github.com/clj-commons/rewrite-clj/blob/main/script/test_libs.clj. The https://github.com/clj-commons/rewrite-clj/blob/main/.github/workflows/libs-test.yml runs canary libs tests in parallel.

lread14:12:24

Or maybe rewrite-clj head is the canary and the libs I test against are the coal mine, but you get what I mean.