Fork me on GitHub
#shadow-cljs
<
2021-09-03
>
thheller05:09:38

FWIW I strongly recommend NOT running secondary tools in hooks. especially not something that starts processes that keep running

thheller05:09:24

prefer setups like this one https://github.com/jacekschae/shadow-cljs-tailwindcss/blob/main/package.json#L8 using npm-run-all to run multiple things but in separate processes

thheller05:09:50

running separate processes is not what build-hooks are made for and should be avoided

borkdude07:09:10

hmm, I see. this is actually what bb tasks is made for as well. (https://book.babashka.org/#tasks), similar to Make, Just, etc.

borkdude07:09:04

I'll leave your feedback on the ClojureVerse post as well.

ingesol07:09:00

I’m seeing [BABEL] Note: The code generator has deoptimised the styling of mydev/node_modules/somelib.js as it exceeds the max of 500KB. in my builds recently. It is not always printed, but sometimes. Does not seem to affect my build times. Normally appears along with Browserslist: caniuse-lite is outdated. Please run next command npm update . Switching between shadow 2.12.x and 2.15.x seems to not make a difference. Is this something that needs configuration, or is it not a problem?

kirill.salykin08:09:23

Hi, morning is there a way to speed up compilation on ci by maybe reusing some caches from prev builds?

Pepijn de Vos09:09:07

How do I install a local dependency?

kirill.salykin09:09:49

is it clj dependency?

kirill.salykin09:09:45

probably you need to use tools.deps machinery for this

kirill.salykin09:09:51

dunno if there is shadow.edn support for this

2
borkdude09:09:49

@pepijndevos with deps.edn you can just use :local/root

2
Karol Wójcik10:09:48

I'm trying to configure i18n with shadow-cljs. As a glue code I'm using the following js code:

import React from "react";
import ReactDOM from "react-dom";
import i18n from "i18next";
import { initReactI18next } from "react-i18next";
import LanguageDetector from "i18next-browser-languagedetector";
import { resources } from "./translations";

export function init({onMissingKey}) {
  i18n
  // passes i18n down to react-i18next
    .use(LanguageDetector)
    .use(initReactI18next)
    .on('missingKey', onMissingKey)
    .init({
      // order and from where user language should be detected
      order: ['querystring', 'cookie', 'localStorage', 'sessionStorage', 'navigator', 'path', 'subdomain'],
      defaultNS: ['General'],
      // keys or params to lookup language from
      lookupQuerystring: 'lng',
      lookupCookie: 'i18next',
      lookupLocalStorage: 'i18nextLng',
      lookupSessionStorage: 'i18nextLng',
      lookupFromPathIndex: 0,
      lookupFromSubdomainIndex: 0,

      // cache user language on
      caches: ['localStorage', 'cookie'],
      excludeCacheFor: ['cimode'], // languages to not persist (cookie, localStorage)

      // optional expire and domain for set cookie
      cookieMinutes: 10,

      // optional htmlTag with lang attribute, the default is:
      htmlTag: document.documentElement,

      // optional set cookie options, reference:[MDN Set-Cookie docs]()
      cookieOptions: { path: '/', sameSite: 'strict' },
      // the translations
      // (tip move them in a JSON file and import them,
      // or even better, manage them via a UI: )
      saveMissing: true,
      resources,
      fallbackLng: "pl",
      interpolation: {
        // react already safes from xss => 
        escapeValue: false
      }
    });
}

export function refresh({ onSuccess, onFailure }) {
  return i18n.reloadResources().then(onSuccess).catch(onFailure);
}

export function language() {
  return i18n.language;
}

export function changeLanguage(lang, {onSuccess, onFailure} ) {
  return i18n.changeLanguage(lang).then(onSuccess).catch(onFailure);
}

export function t(key, opts) {
  return i18n.t(key, opts);
}
This works perfectly for optimizations: none. However with shadow-cljs release changeLanguage and reloadResources are removed from the prototype 😮 Any hints what potentially I'm doing wrong?

2
Karol Wójcik10:09:27

The first thing that comes to my mind is: externs?!

Karol Wójcik11:09:50

Suprisingly shadow renames the resources as well. 😮

const pl = {

};

const en = {

};

export const resources = {pl, en};
After advanced en becomes M1

Karol Wójcik11:09:22

Yep it's about externs. Thank you @U05224H0W for making shadow-cljs predictable! In other tools I would: 1. Don't know what is happening 2. Have trouble with creating the externs. Externs simple rocks

Karol Wójcik11:09:08

This fixed the issue:

# -----------------------------------------------
# [start] i18n externs [start]
i18n.resources.en
i18n.resources.pl
i18n.changeLanguage
i18n.reloadResources
i18n.appendNamespaceToCIMode
i18n.appendNamespaceToMissingKey
i18n.htmlTag
i18n.excludeCacheFor
i18n.cookieOptions
i18n.cookieMinutes
i18n.lookupFromPathIndex
i18n.lookupFromSubdomainIndex
i18n.t
# [end] i18n externs [end]
# -----------------------------------------------

thheller14:09:51

yeah there is no externs inference when using JS code (since the cljs compiler does that)

thheller14:09:59

so externs are required if you don't want things to be renamed

huygn13:09:42

hi, how can I define a global js/ReactDOMServer variable? I'm trying to do

(:require ["react-dom/server" :as ReactDOMServer])

(set! js/ReactDOMServer ReactDOMServer)
I'm using esm target with Deno and above code throw this error:
error: Uncaught (in promise) ReferenceError: ReactDOMServer is not defined
(ReactDOMServer = module$node_modules$react_dom$server_browser);
the reason why I had to do this is because uix tries to use js/ReactDOMServer here: https://github.com/roman01la/uix/blob/0da33eef38a7122be226b9b9a8ae0b5431b6b5d3/dom/src/uix/dom/alpha.cljc#L69

Karol Wójcik14:09:35

Probably better to path the library

Karol Wójcik14:09:56

Btw what is the output of (println ReactDOMServer)

thheller14:09:03

(set! js/goog.global.ReactDOMServer ReactDOMServer) will make it global

clojure-spin 2
thheller15:09:29

(js/goog.exportSymbol "ReactDOMServer" ReactDOMServer) also works. might be safer if you are going for :advanced

bubblebobble 2
huygn16:09:17

worked, thanks!