Fork me on GitHub
#shadow-cljs
<
2022-05-25
>
pinkfrog01:05:13

I’ve multiple node scripts file. Is it possible to define one build target instead for all of them? https://shadow-cljs.github.io/docs/UsersGuide.html#target-node-script

pinkfrog01:05:45

My use case I don’t care about the final output of the script files. I just want to play with the scripts in a repl. And I’d like to define only one build target for all of the scripts.

sansarip01:05:26

Hmm :thinking_face: unless I’m misunderstanding, does specifying multiple build profiles to shadow-cljs not work for you? e.g. npx shadow-cljs watch :lib/dev :test 👆 this allows me to connect to a repl that allows me to play around in namespaces in both builds Though, my builds are of node-library targets and I’m using Calva to automate the repl-jack-in process https://github.com/sansarip/owlbear/blob/main/shadow-cljs.edn

sansarip01:05:35

Are you just trying to avoid specifying multiple builds?

pinkfrog01:05:12

> Are you just trying to avoid specifying multiple builds? Yes.

pinkfrog01:05:34

I have several cljs files, and I just want to play with it.

pinkfrog01:05:46

I don’t care about the generated js files.

pinkfrog01:05:58

What’s the most suitable node target?

pinkfrog01:05:26

It would be desired that I am able to not specify the cljs file names in the build target.

sansarip01:05:27

Just specify your :source-paths e.g. ["dev" "src/cljc" "src/cljs"] and then you should be able to just specify a build with either :node-library or :node-script as the target. Doesn’t really matter, because you don’t care about the output file. Then, npx shadow-cljs watch :<your build name> which will start an nrepl you’ll be able to remotely connect to. Once your cljs files have finished compiling, you’ll also [probably need] to run node -e "require('<path to your output file>')" which will give your repl a Node environment to execute in

thanks3 1
pinkfrog03:05:51

For example, for taget :node-script, I have to specify the :main key, which points to a single script. Thus, for every script, I have to have a build target separately.

pinkfrog03:05:37

I feel like nbb might be more suitable here.

pinkfrog05:05:24

Hi @U022T96EFV3 Where you are developing your vscode extension, do you get any code completion support (assume you are using calva)?

thheller06:05:35

@UGC0NEP4Y npx shadow-cljs node-repl just gives you a node REPL. not tied to any build, you can load any namespace you want in there?

thanks3 1
👆 1
sansarip12:05:57

> Hi @U022T96EFV3 Where you are developing your vscode extension, do you get any code completion support (assume you are using calva)? Yup, I do get code completion support from Calva!

pinkfrog12:05:38

Completion with node_module code or cljs code?

sansarip12:05:07

Oh! As far as I know, just cljs

zonotope12:05:20

Hi. I'm trying to build a cljs app targeting expo wrapped react-native with shadow-cljs. I was able to follow the instructions in the guide to stand up an app scaffold that renders a basic view on the phone using cljs and the Rum react wrapper, but I'm having trouble accessing some js dependencies I have installed. I added the "react-native-vision-camera" library with the expo install react-native-vision-camera command, and I've verified that the library was both added to the package.json and yarn.lock, and that there is a directory corresponding to that library within node_modules. I can't seem to require this library at all from cljs land though. I get null pointer errors during app startup when I try to add the dependency to the ns :require clause. When I also try to require it from the repl like this (require '["react-native-vision-camera" :as vision]), the vision object is nil always. I have also tried to install another dependency, "react-native-gifted-chat", in the same way to verify it wasn't something wrong with that particular dependency, and that also doesn't seem to work. I can require dependencies that were already in package.json after generating the app scaffold like "react" and "react-native" however, so I can load things in node_modules; it just doesn't seem like shadow has access to js/expo dependencies I have added after the fact. There must be something I'm missing about the dependency install process, and that there's more to do besides expo install react-native-vision-camera or yarn add react-native-vision-camera from the shell, but I can't seem to pinpoint what I've done wrong or what I'm missing from the guides. Does anyone have any hints on how to add an external js/react-native/expo dependency to a shadow app targeting react-native so that it can be accessed from cljs code?

thheller15:05:07

@zonotope JS dependencies in a react-native REPL cannot be required dynamically in the REPL if they haven't been included in the build otherwise before. JS dependencies are processed by metro which only sees the regular build output not the REPL.

zonotope14:05:16

Thanks for your help, and sorry for the late reply, but I was focused on my day job for a bit there 😉. I think this has something to do with errors from the camera library that prevented the rest of the app from loading. Those errors are because this library must be natively built.

zonotope14:05:53

It looks like the only native compilation option here is expo's eas build tool. I'm running into another configuration issue there because eas generates an android working directory to compile for that platform with gradle, and it isn't copying over my app directory or app/index js where it should be relative to the android working directory.

zonotope14:05:03

error The resource `/tmp/zonotope/eas-build-local-nodejs/5e63e06b-13cb-49a3-a597-aa44d97d5090/build/android/app/index.js` was not found.
`

zonotope14:05:05

and i think i figured out that error at least. my app/ directory was in my .gitignore, and eas doesn't transfer any files in .gitignore. i'll bet there's a build hook i can add in to eas to generate the app directory with shadow instead of copying it, but i'll figure that out later since this works for now.

thheller15:05:15

as part of the regular build it should be fine though

thheller15:05:37

how did you require it in your code? and do you have an example of how you are supposed to include it in JS?

Tiago Dall'Oca16:05:47

------------------------------------------------------------------------------

   WARNING: shadow-cljs not installed in project.
   See 

------------------------------------------------------------------------------
any way to get rid of this warning?

thheller16:05:49

npm install shadow-cljs?

Tiago Dall'Oca16:05:31

I just want the warning to go away

Tiago Dall'Oca16:05:39

there's really no need in my use case

Tiago Dall'Oca16:05:09

(multiple projects in a mono-repo with pnpm)

thheller16:05:11

what do you mean? if you are using it it should be installed in the project?

thheller16:05:26

not sure how that changes anything?

Tiago Dall'Oca16:05:21

because shadow-cljs is installed in the parent project

Tiago Dall'Oca16:05:33

doesn't need to be installed in the sub-project

Tiago Dall'Oca16:05:39

pnpm works differently

Tiago Dall'Oca16:05:51

it reuses node_module

thheller16:05:42

not sure how that works

thheller16:05:29

the reason it is warning is that the shadow-cljs dependency also brings in other stay that may be required. eg. for node builds ws or for browser build node-libs-browser

thheller16:05:51

so if its not installed wherever it is running those may not be found

Tiago Dall'Oca16:05:33

is there a way to shut the warning?

thheller16:05:09

not currently

thheller16:05:34

too many people didn't install it in the project and kept asking questions why things fail 😛

Tiago Dall'Oca16:05:01

it's not a problem per se, just a bit annoying in my case

thheller16:05:17

still don't understand what your setup is though. where do you control which shadow-cljs version is used?

thheller16:05:35

I hope you are not relying on a global install?

thheller16:05:52

all it is looking for is shadow-cljs installed in the package.json in the dir shadow-cljs is run in

thheller16:05:22

it doesn't care at all about node_modules or pnpm?

Tiago Dall'Oca17:05:20

I installed it in the sub-project too

Tiago Dall'Oca17:05:25

no more warning 🙂

Tiago Dall'Oca17:05:34

thanks for your generosity

Benjamin16:05:18

I pulled the example todo https://github.com/markokocic/rn-native-base-example-todo and have the shadow dev build running. It seems currently like I make changes, shadow updates it instant and then react native automatically refresh the app afterwards - and this auto refreshing I want to disable obviously

thheller17:05:02

sorry I don't use react-native. don't know how you turn it off, but it needs to be turned off on the react-native/metro side. nothing in shadow-cljs can control this.

Benjamin17:05:57

yea I'm sure there is a setting :thumbsup: