shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
neilyio 2020-08-26T00:00:51.266300Z

Instead of "../out/**/*_story.js" , I've added "../out/**/stories.*.js" to the module.exports list in main.js and it seems to be working.

lilactown 2020-08-26T00:01:21.266500Z

hmm I don’t think we actually need stories.core to be included in the storybook build

lilactown 2020-08-26T00:02:06.266700Z

I suppose you can organize how you want

neilyio 2020-08-26T00:02:48.266900Z

Oh, really? I thought that would be the only way to do it. Where are the *_story.js files coming from?

lilactown 2020-08-26T00:03:18.267100Z

the part I left out is creating a corp.design.button-story namespace

neilyio 2020-08-26T00:04:14.267500Z

Ooooh I see now. I couldn't think of why else there might be *_story.js files, so I assumed it was a typo.

lilactown 2020-08-26T00:05:38.267800Z

yeah. what I’m doing is a bit weird. basically, I enumerate each story namespace in two places: • stories.core so that shadow-cljs knows to build it • in the storybook config using the glob pattern, so that the built file gets picked up by storybook’s CLI

neilyio 2020-08-26T00:06:13.268Z

Either way, you've gotten me much farther than I thought I would get with this!

lilactown 2020-08-26T00:06:23.268200Z

I suppose another way you could do it is to configure storybook to just statically include stories.core.js

neilyio 2020-08-26T00:06:33.268400Z

How did you find out the .babelrc was necessary? I would never have thought of that.

lilactown 2020-08-26T00:08:54.268600Z

years of experience working with JS bundlers 😂

lilactown 2020-08-26T00:09:05.268800Z

I can’t remember now why it was necessary tbh

neilyio 2020-08-26T00:15:24.269Z

Also, how are you getting away without using the storiesOf API?

neilyio 2020-08-26T00:15:57.269200Z

Oh wait, I see, it seems like you're basically using the new CSF style.

neilyio 2020-08-26T00:18:08.269400Z

Where they depend on default exports etc. I'm actually trying to avoid that, it seems to rely on having one file per React component. Reagent components are so small that I tend to have multiple per file. I'm thinking the older storiesOf API will be more accommodating to that, let me know if you have another idea!

souenzzo 2020-08-26T02:36:03.271Z

Hey I'm trying to load react-vega and I'm getting this issue

[:zubi] Build failure:
The required JS dependency "buffer" is not available, it was required by "node_modules/vega-loader/build/vega-loader.js".

Dependency Trace:
	zubi/dev.cljs
	zubi/client.cljs
	node_modules/react-vega/lib/index.js
	node_modules/react-vega/lib/Vega.js
	node_modules/react-vega/lib/utils/updateMultipleDatasetsInView.js
	node_modules/react-vega/lib/utils/updateSingleDatasetInView.js
	node_modules/vega-embed/build/vega-embed.js
	node_modules/vega/build/vega-node.js
	node_modules/vega-dataflow/build/vega-dataflow.js
	node_modules/vega-loader/build/vega-loader.js

Searched for npm packages in:
	/home/souenzzo/src/zubi/node_modules

See: <https://shadow-cljs.github.io/docs/UsersGuide.html#npm-install>
I think that somehow vega-loader thinks that it's running on nodejs (maybe ssr) and tryies to import a buffer.

thheller 2020-08-26T08:34:14.273100Z

you need to npm install shadow-cljs in your project ...

👍 1
thheller 2020-08-26T08:34:31.273300Z

which you should be getting a big fat warning about

souenzzo 2020-08-26T14:06:26.283600Z

npm install --save-dev shadow-cljs and it do the hot-reoload even before I checkout logs/output Tnks for shadow-cljs ❤️

👍 1
souenzzo 2020-08-26T02:38:27.271100Z

I'm on thheller/shadow-cljs {:mvn/version "2.11.0"} Using "deps" both JVM8 and JVM14 do the same error.

2020-08-26T03:24:14.271600Z

@thheller would it be possible to a way to clear shadow-inspect?

2020-08-26T03:24:53.272300Z

Specifically remove any logged taps that are on the page

2020-08-26T03:25:17.272800Z

would be easier to read than (tap&gt; "==================") 😂

thheller 2020-08-26T08:38:08.274Z

@royalaid please open an issue so I don't forgot to add it this time. working on the UI but need to solve something else first 😉

mkarp 2020-08-26T12:47:31.274400Z

Hey there! With the following build config:

:app {:target :browser
      :js-options {:resolve {"foo" {:target :npm :require "foo"}}}}
Eval-ing the following code on the REPL:
(require '["foo" :as foo])
(js/console.log foo)
I get the following:
{__esModule: true, default: ƒ}
So to make an instance of foo, I have to call (foo/default.) Is there a way to specify within the build config that default should be “unwrapped” automatically, so that I can call (foo.)? What I’m trying to solve (and perhaps there’s a better way): There’s a dependency foo which exports a constructor function directly via a UMD. Within tests I need to substitute foo with a mock, so I’m using a separate npm package foo-mock which is an ESM and the constructor is under the default export property. The config in the end might look something like this:
:app {:target :browser
      :js-options {:resolve {"foo" {:target :npm :require "foo"}}}}

:test {:target :browser-test
       :js-options {:resolve {"foo" {:target :npm :require "foo-mock"}}}}
Thanks in advance!

thheller 2020-08-26T13:13:37.274900Z

@me1676 why is the mock different from the actual? seems like a strange way to mock?

thheller 2020-08-26T13:14:15.275500Z

you can try :resolve {"foo" {:target :npm :require "foo-mock$default"}} if you are on a recent version but I'm not sure that'll work

mkarp 2020-08-26T13:14:35.275800Z

Yes, that’s an unfortunate decision by the author of foo-mock. I’ll try your suggestion

mkarp 2020-08-26T13:19:18.277300Z

shadow-cljs 2.10.21 fails:

Build failure:
:resolve override for "foo" to "foo$default" which does not exist
{:tag :shadow.build.resolve/invalid-override, :require-from #object[java.io.File 0x4aa9328a ".../test.cljs"], :require "foo", :other "foo$default"}

thheller 2020-08-26T13:20:24.278Z

hmm yeah didn't expect that to work really 😛

mkarp 2020-08-26T13:20:31.278300Z

😃

thheller 2020-08-26T13:22:01.278700Z

what are the packages?

thheller 2020-08-26T13:28:17.280800Z

to answer your other question you can use (:require ["foo" :default foo]) and direclty use (foo.) or (:require ["foo$default" :as foo]) (new "standard" variant likely coming in next CLJS release)

thheller 2020-08-26T13:29:31.281800Z

the only other suggestion I can make is publishing your own npm package that uses pusher-js-mock but exports the default you want

thheller 2020-08-26T13:30:10.282300Z

module.exports.default = require("pusher-js-mock").Whatever;

thheller 2020-08-26T13:31:04.282900Z

node_modules/pusher-js-mock-default/index.js or so

thheller 2020-08-26T13:31:14.283200Z

then the :require redirect should be fine

mkarp 2020-08-26T13:37:35.283500Z

Thank you @thheller, these are good suggestions!

neilyio 2020-08-26T20:56:46.289100Z

How should I use a CommonJS/ES6 namespace in a ClojureScript macro? I'm following @thheller's https://code.thheller.com/blog/shadow-cljs/2019/10/12/clojurescript-macros.html, which suggests that defmacro within a .`clj` file should use a fully-qualified namespace. But going by the shadow-cljs User Guide's https://shadow-cljs.github.io/docs/UsersGuide.html#_using_npm_packages, I don't see how to use a fully-qualified namespace with CommonJS/ES6 imports, because they are referred to with strings as in (:require ["module-name"]).