Fork me on GitHub
#shadow-cljs
<
2017-10-12
>
Jon10:10:31

goog.require('shadow.js.shim.module$fs');

Jon10:10:45

["fs" :as fs])

Jon11:10:09

=>> node target/main.js
SHADOW import error /Users/chen/repo/cumulo/cumulo-workflow/server/target/shadow-cljs/builds/app/dev/out/cljs-runtime/server.main.js

/Users/chen/repo/cumulo/cumulo-workflow/server/target/shadow-cljs/builds/app/dev/out/cljs-runtime/server.main.js:19
})());
  ^
ReferenceError: fs is not defined
    at /Users/chen/repo/cumulo/cumulo-workflow/server/target/shadow-cljs/builds/app/dev/out/cljs-runtime/server/main.cljs:14:10
    at Object.<anonymous> (/Users/chen/repo/cumulo/cumulo-workflow/server/target/shadow-cljs/builds/app/dev/out/cljs-runtime/server.main.js

Jon11:10:33

looks strange. I thought it's compiled to require('fs')

thheller11:10:17

check /Users/chen/repo/cumulo/cumulo-workflow/server/target/shadow-cljs/builds/app/dev/out/cljs-runtime/shadow.js.shim.module$fs.js

thheller11:10:28

I might have broken that accidentally

thheller11:10:56

it should contain shadow.js.shim.module$fs = require("fs");

thheller11:10:04

+ goog.provide

thheller11:10:12

server/main.cljs:14:10 whats there?

thheller11:10:25

maybe you do (js/fs.something ...)?

thheller12:10:43

should be (fs/something ...)

thheller12:10:57

tested, not broken

thheller12:10:33

yes, fs.existsSync is not valid .. use (fs/existsSync ...) (and the others)

thheller12:10:40

does that not produce a warning?

mhuebert12:10:11

I don’t think we have covered this before.. I need to debug a javascript library that is included in my build. Is there a way to include a js file/package that is not in node_modules, but have it otherwise be treated the same? (somehow I need to include my own fork of Keypress.js with a minimum of fuss)

Jon12:10:41

goog.provide("shadow.js.shim.module$fs");
shadow.js.shim.module$fs = require("fs");

Jon12:10:41

code is there..

Jon13:10:15

... my code was using fs.x...

Jon13:10:33

working now.. so it's fs/existsSync

Jon13:10:31

shadow-eval?

mhuebert13:10:21

@jiyinyiyong it’s just a sample project using the latest :bootstrap build ability of shadow-cljs

Jon13:10:52

now shadow-cljs bootstraps?

mhuebert13:10:16

yes 🙂 it’s great. just working out the final bugs/limitations but it is already quite capable

Jon13:10:35

not see docs XD

mhuebert13:10:17

I just added a readme to that repo

mhuebert13:10:38

& updated the readme again.. I am not entirely sure if it will ‘just work’ but you can have a try

mhuebert13:10:33

if you can follow the above directions & then see the same thing as the screenshot I posted, then it is working the same as on my machine

Jon13:10:23

sounds cool anyway

Jon13:10:20

(defn eval-str [source cb]
  (cljs/eval-str
    c-state
    source
    "[test]"
    {:eval cljs/js-eval
     :load (partial boot/load c-state)
     :ns   (symbol "shadow-eval.user")}
    cb))

Jon13:10:32

what does "[test]" mean in this example?

mhuebert13:10:29

the cljs compiler just needs some string provided as a ‘name’ for the current thing being evaluated. in normal builds this would be the filename. in self-host, there is no “file” so you can specify this to be whatever you want. it will show up in stacktraces etc.

Jon13:10:53

oh, a fake file name

thheller14:10:08

@mhuebert :resolve {"keypress.js {:target :file :file "path/to/file/from/project-root.js"}}

thheller14:10:35

will look into the other issue

mhuebert14:10:17

@thheller oh great, that’s simple. Just had a friend test a fresh install (never had shadow-cljs installed before) using the new instructions in the shadow-eval readme. It all works exactly like on my machine 🙂 including the errors in the first two blocks.

mhuebert14:10:16

if shadow-cljs is installed globally, and not run using yarn run shadow-cljs .., does it still use the version specified in package.json?

mhuebert14:10:31

or does one always have to use yarn run ... to get the specified version

thheller14:10:31

`------ ERROR -------------------------------------------------------------------
 File: /Users/zilence/code/tmp/shadow-eval/src/shadow_eval/user.cljs:1:1
--------------------------------------------------------------------------------

   1 | (ns shadow-eval.user
-------^------------------------------------------------------------------------
   2 |   (:require re-view-hiccup.core
   3 |             [cells.cell :refer [cell]]
   4 |             [cells.lib :as cell
   5 |              :refer [interval timeout fetch geo-location with-view]
   6 |              :refer-macros [wait]]
--------------------------------------------------------------------------------
Invalid :refer, var shapes.core/fish does not exist

thheller14:10:02

shadow-cljs will use the version from the project IF installed, otherwise global

thheller14:10:18

it prints the version when starting

thheller14:10:15

ok, I can just remove the fish then it compiles with the cljs.js errors at runtime

thheller14:10:18

investigating

mhuebert14:10:01

oh i think i just pushed an update for that

mhuebert14:10:05

maybe a minute after you tried

mhuebert14:10:25

fish was removed

mhuebert14:10:33

from shadow-eval.user

thheller14:10:49

why do you require cljs.js in the first place?

thheller14:10:18

the issue is that cljs/js.clj can never be loaded

thheller14:10:12

but it seems like require tries to load it no matter what

thheller14:10:19

not sure why

mhuebert14:10:44

i require cljs.js just because i want to use shadow-eval to sort out all these issues that are also present in maria, without all the complexity of maria at hand

mhuebert14:10:45

and it is very useful to be able to use all the stuff in cljs.js

thheller14:10:51

but why does maria need the require? the shadow-eval.user already ensures that it is loaded?

thheller14:10:10

that works, its only the eval require that doesn’t work

mhuebert14:10:11

the user might create a namespace and want to refer it

mhuebert14:10:37

(require '[cljs.js :as cljsjs]) (cljsjs/eval-str ...)

mhuebert14:10:49

or whatever

mhuebert14:10:34

and i think this will happen with any namespace that requires macros which don’t work in self-host. but we still want to be able to use those namespaces.

thheller14:10:35

so bootstrap within boostrap, my head hurts already 😉

thheller14:10:58

so the only thing I can think of is to ignore the load request

thheller14:10:08

and just pretend that its loaded

thheller14:10:24

but that just delays the problem until the user tries to use a macro from that namespace

mhuebert14:10:44

hehe yeah. i think this all comes down to functioning :exclude or :no-follow or :ana-only or whatever options, ways of somehow saying “i have these namespaces which are preloaded and i just want to load the cache”

mhuebert14:10:03

but that’s a transitive dep

mhuebert14:10:31

it’s not (require-macros cljs.js)

thheller14:10:53

doesn’t matter, its asks for the macros since it has a self require

mhuebert14:10:23

i think the point of :no-follow or whatever is that the user doesn’t need transitive macro deps if cljs.js is already compiled?

mhuebert14:10:45

it was compiled using those macros, but we don’t need those macros to use its compiled fns

mhuebert14:10:23

just like we should be able to use other compiled namespaces which used other non-selfhost-friendly macros at compile time?

thheller14:10:49

yes, :exclude is ignored in this case. I can fix that

thheller14:10:01

however .. if the user directly tries to use a macro

thheller14:10:05

that will lead to an error

mhuebert14:10:08

am wondering what exactly :exclude does or if that is the right name

thheller14:10:35

:exclude excludes a macro namespace from compilation

thheller14:10:50

it does NOT exclude it from loading (currently)

thheller14:10:03

it does exclude it when loading via transitive deps

thheller14:10:11

it does not exclude when loading directly

thheller14:10:15

and thats the issue here

mhuebert14:10:20

i think in cljs-live :exclude had the effect of only loading the analysis cache for the thing

thheller14:10:33

it has no problem with shadow-eval.user loading the cljs.js, it does the correct thing here

thheller14:10:52

the issue is who tries to load

mhuebert14:10:59

but it does have a problem with (ns my.app (:require [cljs.js :as cljs]))

thheller14:10:41

yes, but that again is the self-host compiler trying to directly load it

thheller14:10:09

shadow-eval.user is loaded by shadow.cljs.bootstrap.browser which is aware of the exclude

thheller14:10:36

long story short. I can work around this easily

thheller14:10:52

but it WILL fail if the user tries to use a macro

mhuebert14:10:06

that is unavoidable

thheller14:10:14

well not unavoidable

thheller14:10:21

we could just fix cljs/js.clj 😉

mhuebert14:10:29

oh i mean for all the other use cases 🙂

mhuebert14:10:38

i should set up an example of a namespace that uses the go macro

mhuebert14:10:54

with the right exclude, it should be usable

thheller14:10:05

no, that will never work

mhuebert14:10:09

(the precompiled namespace, not go in self-host)

thheller14:10:35

right ok, precompiled yes

thheller14:10:53

let me fix the exclude issue

thheller15:10:10

fixed in 2.0.11

mhuebert15:10:51

fantastic 🎉

mhuebert15:10:45

works for me

mhuebert16:10:31

@thheller re: webserver w/ ring handler - that would be great. i used that functionality of figwheel like so: https://github.com/mhuebert/figwheel-pushstate-server

mhuebert17:10:48

one thing, with bootstrap’s release mode, i think it may need to be combined with a clean command of some kind. otherwise the bootstrap directory can’t really be deployed without deleting it / rebuilding manually, because it fills up with multiple versions

thheller19:10:42

in my experience thats not always a bad thing

thheller19:10:12

I used to delete all old versions too but sometimes someone would access my site with a badly implement cache

thheller19:10:22

that had cached html but not cached js

thheller19:10:39

so they would attempt to download “old” js which had been deleted

thheller19:10:16

never figured out how that was caused but it happened often enough to make me keep old version forever

thheller19:10:39

granted forever is a bit extreme

thheller19:10:04

but yeah some type of clean should probably exist

thheller19:10:26

I’m always hesitant to delete user files though

mhuebert19:10:07

yeah I should probably just deploy these files on a different system than the main app. then it makes sense to be ‘additive’

thheller20:10:32

@mhuebert 2.0.12 -> :devtools {:http-root ... :http-handler shadow.http.push-state/handle} always returns index.html if files don’t exist

thheller20:10:12

or point it to any other clojure fn you like

thheller20:10:25

feels a bit rushed but maybe it works for you

thheller20:10:35

off to bed, gn8

mhuebert20:10:56

@thheller wow that was fast! 🙂 i think content-type headers need to be set to html, if i navigate to something like localhost:8702/intro it downloads as a file instead of opening