Fork me on GitHub
#shadow-cljs
<
2018-06-22
>
Jon02:06:11

@thheller It works by using express/static. Thanks.

Jon02:06:02

It's an extra feature I barely test in development but checked before releasing on npm.

Jon02:06:35

=>> cat externs.shadow.js
/** @constructor */
function ShadowJS() {};

ShadowJS.prototype.NEGATIVE_INFINITY;
ShadowJS.prototype.NaN;
ShadowJS.prototype.POSITIVE_INFINITY;
ShadowJS.prototype.Server;
ShadowJS.prototype.ceilingEntry;
ShadowJS.prototype.cleanup;
ShadowJS.prototype.client;
ShadowJS.prototype.createConnection;
ShadowJS.prototype.createServer;
ShadowJS.prototype.dirname;
ShadowJS.prototype.env;
ShadowJS.prototype.execSync;
ShadowJS.prototype.existsSync;
ShadowJS.prototype.exit;
ShadowJS.prototype.floorEntry;
ShadowJS.prototype.fromCharCode;
ShadowJS.prototype.generate;
ShadowJS.prototype.gray;
ShadowJS.prototype.join;
ShadowJS.prototype.listen;
ShadowJS.prototype.on;
ShadowJS.prototype.readFileSync;
ShadowJS.prototype.static$;
ShadowJS.prototype.unbounded_unshift;
ShadowJS.prototype.writeFileSync;
ShadowJS.prototype.yellow;=>>

Jon02:06:13

no externs for static if I use (.static express). found $static

Jon02:06:33

it works in 2.4.7 now.

pez12:06:17

I get

1 | (ns calva.fmt.formatter
-------^------------------------------------------------------------------------
Invalid :refer, var ysera.test/is= does not exist
--------------------------------------------------------------------------------
   2 |   (:require
   3 |    [ysera.test :refer [is= is is-not]]
   4 |    [cljfmt.core :as cljfmt]))
It is a cljc file and seems to work fine in the clj-repl. I’m trying to use Ysera 1.2.0: https://github.com/tomas81508/ysera/blob/master/src/ysera/test.cljc

pez12:06:10

^ shadow-cljs 2.4.8 ^

thheller12:06:07

@pez is= is a macro and the file does not have :require-macros so you need to [ysera.test :include-macros true :refer [is= is is-not]]

thheller12:06:50

this lib doesn't look very CLJS compatible at all

pez12:06:33

@thheller thanks! It now compiles. I am using it so that I can embed tests with function definitions w/o conditional readers and such.

thheller12:06:42

(defmacro deftest [name & body]
  `(if-cljs
     (println "Not implemented.")
     (clojure.test/deftest ~name [email protected])))

thheller12:06:47

says not implemented 😉

pez12:06:02

As for CLJS compatibility, I know that the devs behind Ysera are using it in a rather large CLJS project, but probably also there it is mostly used in order to embed tests.

pez12:06:42

Yes, I run tests in CLJ, guess that is how it is meant to be used.

haywood15:06:26

this might be a question for the beginner's channel, but is there a way to include a namespace's functions globally for use in the repl? For context I want to use debux's functions without requiring the macros in each file

haywood15:06:50

I'm connected to a browser-repl via shadow

richiardiandrea16:06:30

I am receiving this today from a node-test build:

========= Running Tests =======================
Error: ENOENT: no such file or directory, open '/home/arichiardi/git/laputa/lambda-cqrs/.cljs-tests/cljs-runtime/goog.debug.error.js'
    at Object.fs.openSync (fs.js:646:18)
    at Object.fs.readFileSync (fs.js:551:33)
    at global.SHADOW_IMPORT (/home/arichiardi/git/laputa/lambda-cqrs/out/tests.js:46:15)
    at /home/arichiardi/git/laputa/lambda-cqrs/out/tests.js:3005:1
    at Object.<anonymous> (/home/arichiardi/git/laputa/lambda-cqrs/out/tests.js:3146:3)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
===============================================
[:test] Build completed. (141 files, 81 compiled, 0 warnings, 16.27s)

thheller16:06:08

pretty clear error message no?

thheller16:06:27

does the file exist or not?

richiardiandrea16:06:35

@thheller it seems to exist no, before it did not, I have a different error now

richiardiandrea16:06:47

========= Running Tests =======================
SHADOW import error /home/arichiardi/git/laputa/lambda-cqrs/.cljs-tests/cljs-runtime/ep_cloud.commit_event.js

richiardiandrea16:06:05

can it be a compilation error not displayed?

richiardiandrea16:06:09

let me try to compile

thheller16:06:29

look further down. that just means that it failed to load that file

thheller16:06:37

which can happen if it throws an exception while loading

richiardiandrea16:06:55

========= Running Tests =======================
SHADOW import error /home/arichiardi/git/laputa/lambda-cqrs/.cljs-tests/cljs-runtime/ep_cloud.commit_event.js
===============================================
[:test] Build completed. (141 files, 9 compiled, 0 warnings, 6.17s)

thheller16:06:28

dont autorun and run manually

thheller17:06:58

wonder where the rest of the error is though

richiardiandrea17:06:18

yeah I do know I am not executing with node

richiardiandrea17:06:20

node .cljs-tests/tests.js 
SHADOW import error /home/arichiardi/git/laputa/lambda-cqrs/.shadow-cljs/builds/test/dev/out/cljs-runtime/ep_cloud.commit_event.js

thheller17:06:02

try node --inspect-brk .cljs-tests/tests.js and open with chrome debugger via

brown13117:06:05

I'm looking at the doc for shadow.repl and when I try to do the "(require 'shadow.repl-demo)" it cannot find that namespace. Where is that? It does not appear to be in the shadow-cljs-2.4.8.jar.

thheller17:06:38

there is supposed to be more output. no idea why its not there

thheller17:06:16

@brown131 what do you want with shadow.repl? thats an old thing which isn't really relevant anymore

brown13117:06:17

What I'm trying to do is start a REPL in Cursive so I can debug CLJS.

thheller17:06:59

you cant debug CLJS with cursive?

brown13117:06:44

Was that a question or a statement?

thheller17:06:47

or do you mean just eval code? not actually using the debugger?

brown13117:06:39

I would like to be able to set breakpoints in functions in the code and then call the functions in the repl and have them hit those breakpoints, analogous to what can be done with Clojure.

thheller17:06:03

Cursive does not support that for CLJS

brown13117:06:47

Ah. What are my options with Cursive then?

richiardiandrea17:06:05

@thheller I see the error in the catch, and it is some runtime error

richiardiandrea17:06:21

now, the catch shows "import error" then throws

richiardiandrea17:06:02

but I only see the result of console.error("SHADOW import error", filePath);

richiardiandrea17:06:07

definitely weird I don't see the error, something must be wrapping it

richiardiandrea17:06:39

this prints:

// the comment is for source-map-support which unfortunately shows the wrong piece of code but the stack is correct
  try {
  /* ignore this, look at stacktrace */ fn.call(global, require, module, __filename, __dirname);
  } catch (e) {
    console.error("SHADOW import error", filePath);
    console.error(e);
    throw e;
  }

brown13117:06:59

Trying to answer my own question, it appears that I should start a shadow watch then run a remote nREPL to connect.

thheller17:06:38

@richiardiandrea wonder where the throw e ends up? or the console.error(e)?

richiardiandrea17:06:20

@thheller me too 😄 but the throw is top level...there a couple of FFE on the top

richiardiandrea17:06:46

@thheller there is no console.error(e), I added it

richiardiandrea17:06:52

should I PR that? I know not nice, but cannot understand where the exception ends up, after`throw` the debugger just exits

thheller17:06:41

rather find out where the throw ends up

wilkerlucio17:06:25

@thheller I just realized now, but I'm not seeing the error HUD anymore, when the compilation fails it just prints something weird in the console and the HUD loader goes away, I remember now that there was a big error display covering the screen before

wilkerlucio17:06:57

now that I notice, it seems like it was this way for some time, I'm talking about errors like compilation failures (missing parentesis or something)

wilkerlucio17:06:24

error example:

wilkerlucio17:06:27

failed to parse websocket message {:type :build-failure, :build-config {:target :browser, :output-dir "resources/public/js/workspaces", :asset-path "/js/workspaces", :compiler-options {:closure-output-charset "US-ASCII"}, :dev {:closure-defines {common-cljs.config/dev? true}}, :devtools {:preloads [devtools.preload fulcro.inspect.preload], :before-load nubank.cljs.workspaces.core/before-load, :after-load nubank.cljs.workspaces.core/after-load}, :modules {:main {:entries [nubank.shuffle.workspaces]}}, :build-id :workspaces}, :report "------ ERROR -------------------------------------------------------------------\n File: /Users/wilkerlucio/Development/nubank/shuffle/workspaces/nubank/shuffle/common/logic/misc_ws.cljs:9:40\n--------------------------------------------------------------------------------\n   6 | (ws/deftest test-capitalize-words\n   7 |   (assertions\n   8 |     (misc/capitalize-words \"hello world\") => \"Hello World\"\n   9 |     (misc/capitalize-words \"\") => \"\")))\n----------------------------------------------^---------------------------------\nnubank/shuffle/common/logic/misc_ws.cljs [line 9, col 40] Unmatched delimiter ).\n\n--------------------------------------------------------------------------------\n  10 | \n  11 | (ws/deftest test-index-of\n  12 |   (assertions\n  13 |     (misc/index-of #{:b} [:a :b :c]) => 1\n--------------------------------------------------------------------------------\n", :e clojure.lang.ExceptionInfo: failed to compile resource: [:shadow.build.classpath/resource "nubank/shuffle/common/logic/misc_ws.cljs"] {:ex-kind :reader-error, :source-excerpt {:start-idx 5, :before ["(ws/deftest test-capitalize-words" "  (assertions" "    (misc/capitalize-words \"hello world\") => \"Hello World\""], :line "    (misc/capitalize-words \"\") => \"\")))", :after ["" "(ws/deftest test-index-of" "  (assertions" "    (misc/index-of #{:b} [:a :b :c]) => 1"]}, :file #object[java.io.File 0x6178a54c "/Users/wilkerlucio/Development/nubank/shuffle/workspaces/nubank/shuffle/common/logic/misc_ws.cljs"], :resource-id [:shadow.build.classpath/resource "nubank/shuffle/common/logic/misc_ws.cljs"], :ex-type :reader-exception, :column 40, :line 9, :url #object[java.net.URL 0x6fbf5713 "file:/Users/wilkerlucio/Development/nubank/shuffle/workspaces/nubank/shuffle/common/logic/misc_ws.cljs"], :source-id [:shadow.build.classpath/resource "nubank/shuffle/common/logic/misc_ws.cljs"], :tag :shadow.build.compiler/compile-cljs}} #error {:message "Invalid symbol: cloj … lang.ExceptionInfo:.", :data {:type :reader-exception, :ex-kind :reader-error}}
shadow$cljs$devtools$client$env$process_ws_msg @ env.cljs:150
(anonymous) @ browser.cljs:318

wilkerlucio17:06:43

(logged as warn in console)

richiardiandrea17:06:33

@thheller I am an idiot, I forgot I had an uncaught exception handler registered

thheller18:06:44

@wilkerlucio hmm weird. thought I fixed that. it fails reading the :file and :url #object literals

wilkerlucio18:06:10

the fix was after that?

thheller18:06:24

no. thought I fixed that a long time ago

thheller18:06:59

please open an issue. don't have time to look into it now

richiardiandrea18:06:42

question, I have a server running, and I do watch :test in another terminal, is it expected that I see the console logs in the server terminal?

thheller18:06:17

depends on the output. some output yes

richiardiandrea19:06:42

what do you think about adding these helpers to node-test? It is even more important to have them in shadow because of the different classpath approach

-n, --namespace SYMBOL                             Symbol indicating a specific namespace to test.
  -r, --namespace-regex REGEX  .*\-test$             Regex for namespaces to test. Only namespaces ending in '-test' are evaluated by default.
  -v, --var SYMBOL                                   Symbol indicating the fully qualified name of a specific test.
  -i, --include SYMBOL                               Run only tests that have this metadata keyword.
  -e, --exclude SYMBOL                               Exclude tests with this metadata keyword.

richiardiandrea19:06:15

say I have integration tests, I don't have an easy way to exclude them in "normal" tests cause :ns-regexp is only inclusive

thheller19:06:45

pretty simple to write more sophisticated filtering

richiardiandrea19:06:54

will open an issue for now- yep I was checking that

ClashTheBunny21:06:57

Hey folks, has anybody gotten @material design react components working with shadow-cljs?

thheller21:06:34

the file contains JSX code

thheller21:06:43

return (
      <button
        className={classes}
        ref={initRipple}
        {...otherProps}
      >
        {icon ? this.renderIcon() : null}
        {children}
      </button>
    );

ClashTheBunny21:06:04

Aaah. Any way to do that?

thheller21:06:16

not currently no

thheller21:06:37

very unusual for code on npm to contain jsx code

thheller21:06:42

usually only the converted kind

thheller21:06:46

guess someone forgot to do that

ClashTheBunny21:06:54

How about with the non-react version: I get ExceptionInfo: module without entry or suffix: @material/button

ClashTheBunny21:06:21

Nevermind, no javascript in that...

ClashTheBunny21:06:04

Is there a way to load sass into the app, possibly with sass4clj?

thheller21:06:20

not ouf of the box but can do something with build hooks for clj-run

ClashTheBunny21:06:01

It does seem like the examples/babel project does the jsx stuff, but it may be broken. I get errors about the default on the export default MyDefaultComponent

ClashTheBunny21:06:54

and then it gets stuck on react's default statement.

thheller21:06:33

the babel example is meant for project code outside node_modules since that is treated differently

steveb8n23:06:36

is there an example anywhere that shows building a cljs/node AWS lambda artifact using shadow?

richiardiandrea23:06:57

@steveb8n not doing exactly that, but you would build the JS with :node-script and then zip everything up (`node_modules` included)

steveb8n23:06:40

thanks. I’ll give that a try