# JS Dependencies: In Practice

**URL:** https://clojureverse.org/t/js-dependencies-in-practice/691
**Category:** shadow-cljs
**Created:** [November 10, 2017, 11:04am UTC](https://clojureverse.org/t/js-dependencies-in-practice/691 "2017-11-10T11:04:16Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![thheller](https://clojureverse.org/user_avatar/clojureverse.org/thheller/32/534_2.png) [@thheller](https://clojureverse.org/u/thheller)
#### Post date: [November 10, 2017, 11:04am UTC](https://clojureverse.org/t/js-dependencies-in-practice/691/1 "2017-11-10T11:04:16Z")

</div>

I just published the next post related to dealing with JS Dependencies in [shadow-cljs](https://github.com/thheller/shadow-cljs).

[JS Dependencies: In Practice](https://code.thheller.com/blog/shadow-cljs/2017/11/10/js-dependencies-in-practice.html)

Please discuss.

---

<div class="post-metadata">

### Author: ![martinklepsch](https://clojureverse.org/user_avatar/clojureverse.org/martinklepsch/32/80_2.png) [@martinklepsch](https://clojureverse.org/u/martinklepsch)
#### Post date: [November 10, 2017, 5:31pm UTC](https://clojureverse.org/t/js-dependencies-in-practice/691/2 "2017-11-10T17:31:31Z")

</div>

Hey Thomas,

I’m really excited about shadow-cljs, it seems to be an opinionated clean-slate approach that leaves some of the old baggage behind. CLJSJS has always been meant to be deprecated eventually and I’m excited to see it being used less with improving JS module support.

I’m not 100% sure I’m onboard with fully deprecating `:foreign-libs` but I guess it remains to be seen if that becomes a real problem.

I haven’t yet had a chance to try it but I’m hoping I get to it soon and then maybe I’ll also write a Boot task. 🙂

---

<div class="post-metadata">

### Author: ![thheller](https://clojureverse.org/user_avatar/clojureverse.org/thheller/32/534_2.png) [@thheller](https://clojureverse.org/u/thheller)
#### Post date: [November 10, 2017, 5:52pm UTC](https://clojureverse.org/t/js-dependencies-in-practice/691/3 "2017-11-10T17:52:19Z")

</div>

I really tried to find a way to make `:foreign-libs` work in a way that does not conflict with using code from `npm`. It can work if you update every CLJSJS package to also support the “new” require style and does not rely on a global js var. The [`react` package](https://github.com/cljsjs/packages/blob/master/react/build.boot#L56-L61) was already updated to do this.

The process however has never been perfect IMHO. Not every npm package is available and keeping everything in sync is a ton of work. Is it really required if we can just use `npm` directly?

I thought about adding `:foreign-libs` as an alternate `:js-provider` so we can work without `npm` as well. We can’t mix it though so removing it seemed like the better option for now. We need to get away from the globals style so we can at least try using the Closure Compiler as `:npm-deps` intended.

---

<div class="post-metadata">

### Author: ![jiyinyiyong](https://clojureverse.org/user_avatar/clojureverse.org/jiyinyiyong/32/85_2.png) [@jiyinyiyong](https://clojureverse.org/u/jiyinyiyong)
#### Post date: [November 10, 2017, 6:32pm UTC](https://clojureverse.org/t/js-dependencies-in-practice/691/4 "2017-11-10T18:32:04Z")

</div>

Added a very rough Chinese translation [https://segmentfault.com/a/1190000011954645](https://segmentfault.com/a/1190000011954645)

I have a question: after so many things, does it mean we can use shadow-cljs to compile JavaScript-only projects now?

---

<div class="post-metadata">

### Author: ![orestis](https://clojureverse.org/user_avatar/clojureverse.org/orestis/32/279_2.png) [@orestis](https://clojureverse.org/u/orestis)
#### Post date: [November 10, 2017, 7:18pm UTC](https://clojureverse.org/t/js-dependencies-in-practice/691/5 "2017-11-10T19:18:23Z")

</div>

As a relative newcomer to JS-land, I was hoping to use CLJSJS as an indicator of “libraries that are vetted by the ClojureScript” community, not only compatibility wise, but as a curated collection out of the half a million libraries out there. I hope I can keep using it that way 🙂

---

<div class="post-metadata">

### Author: ![jiyinyiyong](https://clojureverse.org/user_avatar/clojureverse.org/jiyinyiyong/32/85_2.png) [@jiyinyiyong](https://clojureverse.org/u/jiyinyiyong)
#### Post date: [November 11, 2017, 2:57am UTC](https://clojureverse.org/t/js-dependencies-in-practice/691/6 "2017-11-11T02:57:46Z")

</div>

Welcome to JavaScript world, there’s not standard library. We have to deal with a lot of situations. Pick what you want on GitHub!

---

<div class="post-metadata">

### Author: ![thheller](https://clojureverse.org/user_avatar/clojureverse.org/thheller/32/534_2.png) [@thheller](https://clojureverse.org/u/thheller)
#### Post date: [November 11, 2017, 8:14am UTC](https://clojureverse.org/t/js-dependencies-in-practice/691/7 "2017-11-11T08:14:12Z")

</div>

> [@jiyinyiyong](#):
>
> does it mean we can use shadow-cljs to compile JavaScript-only projects now?

Yes, but it is not optimized for that and never will be.

---

<div class="post-metadata">

### Author: ![martinklepsch](https://clojureverse.org/user_avatar/clojureverse.org/martinklepsch/32/80_2.png) [@martinklepsch](https://clojureverse.org/u/martinklepsch)
#### Post date: [November 11, 2017, 9:23am UTC](https://clojureverse.org/t/js-dependencies-in-practice/691/8 "2017-11-11T09:23:04Z")

</div>

> [@orestis](#):
>
> As a relative newcomer to JS-land, I was hoping to use CLJSJS as an indicator of “libraries that are vetted by the ClojureScript” community, not only compatibility wise, but as a curated collection out of the half a million libraries out there. I hope I can keep using it that way 🙂

Maybe that could be a future direction for the project once the module packaging is no longer needed as much. A community maintained set of library recommendations that work well with ClojureScript and Closure.

---

<div class="post-metadata">

### Author: ![shaunlebron](https://clojureverse.org/user_avatar/clojureverse.org/shaunlebron/32/193_2.png) [@shaunlebron](https://clojureverse.org/u/shaunlebron)
#### Post date: [November 11, 2017, 1:51pm UTC](https://clojureverse.org/t/js-dependencies-in-practice/691/9 "2017-11-11T13:51:51Z")

</div>

Love the new `:resolve` option for all the intricacies of importing JS for various targets!

One thing this doesn’t mention is how a ClojureScript project `foo` can specify its own JS dependencies when required by another ClojureScript project `bar`. In other words, when `foo` requires `bar`, how are `foo`'s JS dependencies expected to be resolved?

This information is already specified by `foo`'s `package.json`, but for the purpose of transitivity I believe it must also be redundantly specified in `foo`'s `src/deps.cljs` file, containing a map with an `:npm-deps` key.

Did I correctly describe this?

---

<div class="post-metadata">

### Author: ![thheller](https://clojureverse.org/user_avatar/clojureverse.org/thheller/32/534_2.png) [@thheller](https://clojureverse.org/u/thheller)
#### Post date: [November 11, 2017, 8:04pm UTC](https://clojureverse.org/t/js-dependencies-in-practice/691/10 "2017-11-11T20:04:42Z")

</div>

Yes, that is correct. Any library can add a `deps.cljs` to the published `.jar` and express JS dependencies this way.

```auto
{:npm-deps {"react" "^16.0.0"}}

```

Keyword keys (eg. `:react`) is also allowed.

`shadow-cljs` will install them automatically (or by calling `shadow-cljs npm-deps`). For CLJS itself I believe you must set `:install-deps` in the compiler options for these to be installed.

---

<div class="post-metadata">

### Author: ![jiyinyiyong](https://clojureverse.org/user_avatar/clojureverse.org/jiyinyiyong/32/85_2.png) [@jiyinyiyong](https://clojureverse.org/u/jiyinyiyong)
#### Post date: [November 12, 2017, 3:23am UTC](https://clojureverse.org/t/js-dependencies-in-practice/691/11 "2017-11-12T03:23:28Z")

</div>

Random ideas:

- shadow-cljs add supports to npm scripts and calling `shadow-cljs run x` to replace `yarn run x`
- shadow-cljs becomes a package manager with a command called `shadow-cljs publish`
- in the command-line it got as short as npm and called `sdc`

than I can remove `yarn` and `package.json` from my project template 😆

---

<div class="post-metadata">

### Author: ![thheller](https://clojureverse.org/user_avatar/clojureverse.org/thheller/32/534_2.png) [@thheller](https://clojureverse.org/u/thheller)
#### Post date: [November 12, 2017, 9:34am UTC](https://clojureverse.org/t/js-dependencies-in-practice/691/12 "2017-11-12T09:34:39Z")

</div>

```auto
alias sdc="npx shadow-cljs"

```

I’m personally not interested in writing a package manager.

I recently added `clj-eval` which can eval Clojure (not CLJS) code from the command line in the `shadow.user` namespace. The intent here is to be able to run things in a scripted way. `cat script.clj | shadow-cljs clj-eval -` with `script.clj`

```auto
(shadow/release :build)
(sync-files-with-server)
(reload-server)

```

Or just simply `shadow-cljs clj-eval "(shadow/release :build)" "(+ 1 2)"`.

I will also add `run` or `clj-run` similar to `lein run -m some.ns/fn and more args` to directly calling a clojure fn. I hope that someone wants to write a `shadow-cljs run some.lib/deploy-to-clojars` fn. Since the code will be executed in the context of the `shadow-cljs` process it has full access to its API. I hope to extend this API to support more tooling needs. It will probably mirror exactly what the new `clojure` tool does. It might even just use that.

---

<div class="post-metadata">

### Author: ![system](https://clojureverse.org/uploads/default/original/2X/5/51079bf9e4b7d9466242c06cf1e43b9f8bd6da14.png) [@system](https://clojureverse.org/u/system)
#### Post date: [October 5, 2018, 12:50pm UTC](https://clojureverse.org/t/js-dependencies-in-practice/691/13 "2018-10-05T12:50:28Z")

</div>


